Bitmex API(PHP),取消一个订单不';行不通
我正在使用PHP。当我尝试通过API取消一个活动订单时,出现错误:Bitmex API(PHP),取消一个订单不';行不通,php,api,bitmex,Php,Api,Bitmex,我正在使用PHP。当我尝试通过API取消一个活动订单时,出现错误: "error" => array:2 [▼ "message" => "orderIDs or clOrdIDs must be sent." "name" => "ValidationError" ] 我将orderID作为数组(这是我的lib方法): 我做错了什么? 类似的问题:晚会迟到了,但我想我会在最终弄明白这一点时回答,并想象它对任何试图将Bitmex API与PHP结合使用的人都有用
"error" => array:2 [▼
"message" => "orderIDs or clOrdIDs must be sent."
"name" => "ValidationError"
]
我将orderID作为数组(这是我的lib方法):
我做错了什么?
类似的问题:晚会迟到了,但我想我会在最终弄明白这一点时回答,并想象它对任何试图将Bitmex API与PHP结合使用的人都有用(特别是如果您在kstka的github上使用Bitmex API PHP包装器) 首先,将订单Id号放入数组中,即使它只是一个:
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
if($method == "GET" || $method == "POST" || $method == "PUT") {
$params = http_build_query($data['params']);
} elseif($method == "DELETE") {
$params = json_encode($data['params']);
}
然后,最重要的是,您需要确保CURL头是json编码的:
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';
}
你应该笑着离开。我花了很长时间才弄明白 我的意思是,我从未使用过API,但它说必须发送orderID或ClordID,而您不发送它们中的任何一个-您的代码只发送单数形式的orderID.orderID-->或Right,而您发送的是
orderID
,而这两个都不是HM。。API文档说明:必须提供orderID或clOrdID。我可以发送1个id或id数组。我发了一个id,有什么问题吗?)我不明白就是这样!我在删除的标题中缺少json。谢谢分享。
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';
}