2

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"
]

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);
}

What I'm doing wrong? https://www.bitmex.com/api/explorer/#!/Order/Order_cancel

Similar Problem: bitmex api php, cancel 1 order not working

user137
  • 629
  • 1
  • 8
  • 20
  • 1
    I mean I've never used the API, but it says *orderIDs or clOrdIDs must be sent*, and you aren't sending either of them - your code just sends orderID in singular. – iainn Oct 02 '18 at 12:39
  • orderIDs -->OR<-- clOrdIDs must be sent – user137 Oct 02 '18 at 12:45
  • Right, and you're sending `orderID`, which isn't either of them – iainn Oct 02 '18 at 12:46
  • Hm.. API docs says: Either an orderID or a clOrdID must be provided. I can send 1 id or array of id's. I sent 1 id, so what is problem?) I can't understand – user137 Oct 02 '18 at 12:58

1 Answers1

4

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).

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);
}

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']);
}

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!

Julian
  • 63
  • 6