Bitmex API (PHP),取消一笔订单不起作用 [英] Bitmex API (PHP), cancel one order doesn't work
问题描述
我正在使用 PHP.当我尝试通过 API 取消一个活动订单时,出现错误:
I'm using PHP. When I try to cancel one active order via API i got error:
"error" => array:2 [▼
"message" => "orderIDs or clOrdIDs must be sent."
"name" => "ValidationError"
]
我把 orderID 作为数组(这是我的 lib 方法):
I put orderID as array (this is my lib method):
public function cancelOrder($orderID) {
$symbol = self::SYMBOL;
$data['method'] = "DELETE";
$data['function'] = "order";
$data['params'] = array(
"orderID" => $orderID, // ['r5ff364da-4243-8ee3-7853-6fb0f9f7e44d']
);
return $this->authQuery($data);
}
我做错了什么?https://www.bitmex.com/api/explorer/#!/订购/订购_取消
类似问题:bitmex api php,取消1个订单不起作用
推荐答案
迟到了,但我想我会回答,因为我终于想通了,并想象这对尝试将 Bitmex API 与 PHP 结合使用的任何人都会有用(特别是如果您在 kstka 的 github 上使用 bitmex-api-php 包装器).
Late to the party, but thought i would answer as I finally figured this out, and imagine it would be useful for anyone else trying to use Bitmex API with PHP (Especially if you're using bitmex-api-php wrapper on kstka's github).
首先,将订单Id号放入一个数组中,即使只有一个:
First, put the order Id number into an array, even if it's just one:
public function cancelOrder($orderId) {
$orderArr = array($orderId);
$symbol = self::SYMBOL;
$data['method'] = "DELETE";
$data['function'] = "order";
$data['params'] = array(
'orderID' => $orderArr,
);
return $this->authQuery($data);
}
然后你需要确保你的参数是json编码的,但仅限于DELETE
Then you need to make sure your params are json encoded, but only for DELETE
if($method == "GET" || $method == "POST" || $method == "PUT") {
$params = http_build_query($data['params']);
} elseif($method == "DELETE") {
$params = json_encode($data['params']);
}
然后,最重要的是,您需要确保 CURL 标头是 json 编码的:
and then, most importantly, you need to ensure the CURL headers are json encoded:
if($data['method'] == "DELETE") {
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
$headers[] = 'X-HTTP-Method-Override: DELETE';
$headers[] = 'Content-Type: application/json';
}
你应该笑着离开.这花了我很长时间才弄明白!
You should be away laughing. This took my forever to figure out!
这篇关于Bitmex API (PHP),取消一笔订单不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!