-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/open/api/v2/order/cancel #5
Comments
It's solved, try again. |
function MEXC_Order_DeleteCancel($db,$key,$secret,$symbol,$order_ids){ }catch (\Exception $e){ |
|
xamp Windows apache |
it has to run under linux. |
I don't understand what the code means. |
default host address |
ok. Is it still authorize failed error? |
|
There is an error |
$mexc=new MxcSpot($key,$secret);
//You can set special needs
$mexc->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,
]);
//Place an Order
try {
$result=$mexc->order()->postPlace([
'symbol'=>'EOS_USDT',
'price'=>'6',
'quantity'=>1,
'trade_type'=>'ASK',//BID=buy,ASK=sell
'order_type'=>'LIMIT_ORDER',//LIMIT_ORDER,POST_ONLY,IMMEDIATE_OR_CANCEL
//'client_order_id'=>''
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
sleep(1);
//Get order details by order ID.
try {
$result=$mexc->order()->getQuery([
'symbol'=>'EOS_USDT',
'order_ids'=>$result['data'],
//'client_order_ids'=>'',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
}
sleep(1);
//Cancelling an unfilled order.
try {
$result=$mexc->order()->deleteCancel([
'symbol'=>'EOS_USDT',
'order_ids'=>$result['data'][0]['id'],
//'client_order_ids'=>'',
]);
print_r($result);
}catch (\Exception $e){
print_r(json_decode($e->getMessage(),true));
} Array
(
[code] => 200
[data] => 41497759ef5749b588efa0523f6dbede
)
Array
(
[code] => 200
[data] => Array
(
[0] => Array
(
[id] => 41497759ef5749b588efa0523f6dbede
[symbol] => EOS_USDT
[price] => 6
[quantity] => 1
[state] => NEW
[type] => ASK
[deal_quantity] => 0
[deal_amount] => 0
[create_time] => 1644915514000
[order_type] => LIMIT_ORDER
)
)
)
Array
(
[code] => 200
[data] => Array
(
[41497759ef5749b588efa0523f6dbede] => success
)
) I tested and found no problems, are you using the latest version? |
|
the code you sent |
very strange question, I'll look it up again |
Should not be a PHP environment problem. You modify the source code and see what the output is. remove comments: |
Updated the last code you posted. Problem is solved . thanks 👍 |
Request.php upload |
* */ namespace Lin\Mxc; use GuzzleHttp\Exception\RequestException; use Lin\Mxc\Exceptions\Exception; class Request { protected $key=''; protected $secret=''; protected $host=''; protected $nonce=''; protected $signature=''; protected $headers=[]; protected $type=''; protected $path=''; protected $data=[]; protected $options=[]; protected $authentication=true; protected $platform=''; protected $version=''; public function __construct(array $data) { $this->key=$data['key'] ?? ''; $this->secret=$data['secret'] ?? ''; $this->host=$data['host'] ?? 'https://www.mexc.com/'; $this->options=$data['options'] ?? []; $this->platform=$data['platform'] ?? []; $this->version=$data['version'] ?? []; } /** * * */ protected function auth(){ $this->nonce(); $this->signature(); $this->headers(); $this->options(); } /** * * */ protected function nonce(){ $this->nonce=time()*1000; } /** * * */ protected function signature(){ if($this->authentication==false) return; if(in_array($this->type,['GET','DELETE'])) { $params= empty($this->data) ? '' : implode('&',$this->sort($this->data)); }else{ $params= empty($this->data) ? '' : json_encode($this->data); } //accessKey+时间戳+获取到的参数字符串 $what = $this->key . $this->nonce . $params; //echo $what.PHP_EOL; $this->signature = hash_hmac("sha256", $what, $this->secret); } /** * * */ protected function headers(){ $this->headers=[ 'Content-Type' => 'application/json', 'ApiKey' => $this->key, 'Request-Time'=>$this->nonce, 'Signature'=>$this->signature, ]; } /** * * */ protected function options(){ if(isset($this->options['headers'])) $this->headers=array_merge($this->headers,$this->options['headers']); $this->options['headers']=$this->headers; $this->options['timeout'] = $this->options['timeout'] ?? 60; } /** * * */ protected function send(){ $client = new \GuzzleHttp\Client(); $url=$this->host.$this->path; if(in_array($this->type,['GET','DELETE'])) $url.= empty($this->data) ? '' : '?'.http_build_query($this->data); else $this->options['body']=json_encode($this->data); // echo $url.PHP_EOL; // print_r($this->options); // die; $response = $client->request($this->type, $url, $this->options); return $response->getBody()->getContents(); } /* * * */ protected function exec(){ $this->auth(); try { return json_decode($this->send(),true); }catch (RequestException $e){ if(method_exists($e->getResponse(),'getBody')){ $contents=$e->getResponse()->getBody()->getContents(); $temp=json_decode($contents,true); if(!empty($temp)) { $temp['_method']=$this->type; $temp['_url']=$this->host.$this->path; }else{ $temp['_message']=$e->getMessage(); } }else{ $temp['_message']=$e->getMessage(); } $temp['_httpcode']=$e->getCode(); throw new Exception(json_encode($temp)); } } /** * * */ protected function sort($param) { $u = []; $sort_rank = []; foreach ($param as $k => $v) { $u[] = $k . "=" . urlencode($v); $sort_rank[] = ord($k); } asort($u); return $u; } } ?> |
[msg] => authorize failed
| [code] => 401
| [_method] => DELETE
| [_url] => https://www.mexc.com//open/api/v2/order/cancel
| [_httpcode] => 400
help me :(
The text was updated successfully, but these errors were encountered: