2

我正在使用 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

4

1 回答 1

4

派对迟到了,但我想我会回答,因为我终于想通了,并想象它对任何尝试将 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';
 }

你应该笑着离开。我花了很长时间才弄清楚!

于 2019-06-13T04:16:23.620 回答