Skip to content

Commit 708aacb

Browse files
authored
feat: methods for canceling algo orders added
1 parent 7645bc9 commit 708aacb

1 file changed

Lines changed: 57 additions & 5 deletions

File tree

php-binance-api.php

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public function cancel(string $symbol, ?string $orderid = null, $params = [])
516516
];
517517
if (!is_null($orderid)) {
518518
$request["orderId"] = $orderid;
519-
} else if (!is_set($params['origClientOrderId'])) {
519+
} else if (!isset($params['origClientOrderId'])) {
520520
throw new Exception("Either orderId or origClientOrderId must be provided");
521521
}
522522
return $this->apiRequest("v3/order", "DELETE", array_merge($request, $params), true);
@@ -545,7 +545,7 @@ public function orderStatus(string $symbol, ?string $orderid = null, array $para
545545
];
546546
if (!is_null($orderid)) {
547547
$request["orderId"] = $orderid;
548-
} else if (!is_set($params['origClientOrderId'])) {
548+
} else if (!isset($params['origClientOrderId'])) {
549549
throw new Exception("Either orderId or origClientOrderId must be provided");
550550
}
551551
return $this->apiRequest("v3/order", "GET", array_merge($request, $params), true);
@@ -5191,6 +5191,32 @@ public function futuresCancel(string $symbol, $orderid, $params = [])
51915191
return $this->fapiRequest("v1/order", 'DELETE', array_merge($request, $params), true);
51925192
}
51935193

5194+
/**
5195+
* futuresAlgoCancel cancels a futures order
5196+
*
5197+
* $algoid = "123456789";
5198+
* $order = $api->futuresCancel($algoid);
5199+
*
5200+
* @param string $algoid (optional) the algoid to cancel (mandatory if $params['clientalgoid'] is not set)
5201+
* @param array $params (optional) additional options
5202+
* - @param string $params['clientalgoid'] original client order id to cancel
5203+
* - @param int $params['recvWindow'] the time in milliseconds to wait for a response
5204+
*
5205+
* @return array with error message or the order details
5206+
* @throws \Exception
5207+
*/
5208+
public function futuresAlgoCancel($algoid, $params = [])
5209+
{
5210+
$request = [];
5211+
if ($algoid) {
5212+
$request['algoId'] = $algoid;
5213+
} else if (!isset($params['clientalgoid'])) {
5214+
throw new \Exception('futuresAlgoCancel(): either algoid or clientalgoid must be set');
5215+
}
5216+
// todo: check camel-case or lower-case!!!!
5217+
return $this->fapiRequest("v1/algoOrder", 'DELETE', array_merge($request, $params), true);
5218+
}
5219+
51945220
/**
51955221
* futuresCancelBatchOrders canceles multiple futures orders
51965222
*
@@ -5229,11 +5255,13 @@ public function futuresCancelBatchOrders(string $symbol, $orderIdList = null, $o
52295255
* futuresCancelOpenOrders cancels all open futures orders for a symbol
52305256
*
52315257
* @link https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Open-Orders
5232-
*
5258+
* @link https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Algo-Open-Orders
52335259
* $orders = $api->futuresCancelOpenOrders("BNBBTC");
52345260
*
52355261
* @param string $symbol (mandatory) market symbol (e.g. ETHUSDT)
5236-
* @param int $recvWindow the time in milliseconds to wait for a response
5262+
* @param array $params (optional) An array of additional parameters that the API endpoint allows
5263+
* - @param bool $params['isAlgo'] true for canceling algo orders
5264+
* - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response
52375265
*
52385266
* @return array with error message or the orders details
52395267
* @throws \Exception
@@ -5243,8 +5271,32 @@ public function futuresCancelOpenOrders(string $symbol, array $params = [])
52435271
$request = [
52445272
'symbol' => $symbol,
52455273
];
5274+
if (isset($params['isAlgo']) && ($params['isAlgo'] === true)) {
5275+
unset($params['isAlgo']);
5276+
return $this->fapiRequest("v1/algoOpenOrders", 'DELETE', array_merge($request, $params), true);
5277+
} else {
5278+
return $this->fapiRequest("v1/allOpenOrders", 'DELETE', array_merge($request, $params), true);
5279+
}
5280+
}
52465281

5247-
return $this->fapiRequest("v1/allOpenOrders", 'DELETE', array_merge($request, $params), true);
5282+
/**
5283+
* futuresCancelOpenAlgoOrders cancels all open futures algo orders for a symbol
5284+
*
5285+
* @link https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Algo-Open-Orders
5286+
*
5287+
* $orders = $api->futuresCancelOpenAlgoOrders("BNBBTC");
5288+
*
5289+
* @param string $symbol (mandatory) market symbol (e.g. ETHUSDT)
5290+
* @param array $params (optional) An array of additional parameters that the API endpoint allows
5291+
* - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response
5292+
*
5293+
* @return array with error message or the orders details
5294+
* @throws \Exception
5295+
*/
5296+
public function futuresCancelOpenAlgoOrders (string $symbol, array $params = [])
5297+
{
5298+
$params['isAlgo'] = true;
5299+
return $this->futuresCancelOpenOrders($symbol, $params);
52485300
}
52495301

52505302
/**

0 commit comments

Comments
 (0)