Bitmex API(PHP),取消一项订单无效

时间:2018-10-02 12:35:46

标签: php api bitmex

我正在使用PHP。当我尝试通过API取消一个有效订单时,出现错误:

"error" => array:2 [▼
   "message" => "orderIDs or clOrdIDs must be sent."
   "name" => "ValidationError"
]

我将orderID作为数组(这是我的lib方法):

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/#!/Order/Order_cancel

类似问题:bitmex api php, cancel 1 order not working

1 个答案:

答案 0 :(得分:0)

晚些时候参加聚会,但是我想我会在最终弄清楚这一点后回答,并想象这对尝试将Bitmex API与PHP结合使用的任何人都是有用的(特别是如果您使用bitmex-api-php包装器kstka的github)。

首先,将订单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';
 }

你应该开怀大笑。这花了我一辈子的时间!