From e84b872f1634f231a273546533365756d16c19b6 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Fri, 18 Apr 2025 11:14:40 +0300 Subject: [PATCH 01/11] httpRequest and params update --- php-binance-api.php | 451 +++++++++++++++++++++++--------------------- 1 file changed, 234 insertions(+), 217 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 79aa3bd..f50e875 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -265,12 +265,12 @@ protected function generateFuturesClientOrderId() * @param $quantity string the quantity required * @param $price string price per unit you want to spend * @param $type string type of order - * @param $flags array addtional options for order type + * @param $params array addtional options for order type * @return array with error message or the order details */ - public function buy(string $symbol, $quantity, $price, string $type = "LIMIT", array $flags = []) + public function buy(string $symbol, $quantity, $price, string $type = "LIMIT", array $params = []) { - return $this->order("BUY", $symbol, $quantity, $price, $type, $flags); + return $this->order("BUY", $symbol, $quantity, $price, $type, $params); } /** @@ -282,12 +282,12 @@ public function buy(string $symbol, $quantity, $price, string $type = "LIMIT", a * @param $quantity string the quantity required * @param $price string price per unit you want to spend * @param $type string config - * @param $flags array config + * @param $params array config * @return array with error message or empty or the order details */ - public function buyTest(string $symbol, $quantity, $price, string $type = "LIMIT", array $flags = []) + public function buyTest(string $symbol, $quantity, $price, string $type = "LIMIT", array $params = []) { - return $this->order("BUY", $symbol, $quantity, $price, $type, $flags, true); + return $this->order("BUY", $symbol, $quantity, $price, $type, $params, true); } /** @@ -312,12 +312,12 @@ public function buyTest(string $symbol, $quantity, $price, string $type = "LIMIT * @param $quantity string the quantity required * @param $price string price per unit you want to spend * @param $type string type of order - * @param $flags array addtional options for order type + * @param $params array addtional options for order type * @return array with error message or the order details */ - public function sell(string $symbol, $quantity, $price, string $type = "LIMIT", array $flags = []) + public function sell(string $symbol, $quantity, $price, string $type = "LIMIT", array $params = []) { - return $this->order("SELL", $symbol, $quantity, $price, $type, $flags); + return $this->order("SELL", $symbol, $quantity, $price, $type, $params); } /** @@ -329,12 +329,12 @@ public function sell(string $symbol, $quantity, $price, string $type = "LIMIT", * @param $quantity string the quantity required * @param $price string price per unit you want to spend * @param $type array config - * @param $flags array config + * @param $params array config * @return array with error message or empty or the order details */ - public function sellTest(string $symbol, $quantity, $price, string $type = "LIMIT", array $flags = []) + public function sellTest(string $symbol, $quantity, $price, string $type = "LIMIT", array $params = []) { - return $this->order("SELL", $symbol, $quantity, $price, $type, $flags, true); + return $this->order("SELL", $symbol, $quantity, $price, $type, $params, true); } /** @@ -345,14 +345,14 @@ public function sellTest(string $symbol, $quantity, $price, string $type = "LIMI * * @param $symbol string the currency symbol * @param $quantity string the quantity of the quote to use - * @param $flags array additional options for order type + * @param $params array additional options for order type * @return array with error message or the order details */ - public function marketQuoteBuy(string $symbol, $quantity, array $flags = []) + public function marketQuoteBuy(string $symbol, $quantity, array $params = []) { - $flags['isQuoteOrder'] = true; + $params['isQuoteOrder'] = true; - return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $flags); + return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $params); } /** @@ -362,14 +362,14 @@ public function marketQuoteBuy(string $symbol, $quantity, array $flags = []) * * @param $symbol string the currency symbol * @param $quantity string the quantity of the quote to use - * @param $flags array additional options for order type + * @param $params array additional options for order type * @return array with error message or the order details */ - public function marketQuoteBuyTest(string $symbol, $quantity, array $flags = []) + public function marketQuoteBuyTest(string $symbol, $quantity, array $params = []) { - $flags['isQuoteOrder'] = true; + $params['isQuoteOrder'] = true; - return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $flags, true); + return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $params, true); } /** @@ -380,12 +380,12 @@ public function marketQuoteBuyTest(string $symbol, $quantity, array $flags = []) * * @param $symbol string the currency symbol * @param $quantity string the quantity required - * @param $flags array addtional options for order type + * @param $params array addtional options for order type * @return array with error message or the order details */ - public function marketBuy(string $symbol, $quantity, array $flags = []) + public function marketBuy(string $symbol, $quantity, array $params = []) { - return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $flags); + return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $params); } /** @@ -395,12 +395,12 @@ public function marketBuy(string $symbol, $quantity, array $flags = []) * * @param $symbol string the currency symbol * @param $quantity string the quantity required - * @param $flags array addtional options for order type + * @param $params array addtional options for order type * @return array with error message or the order details */ - public function marketBuyTest(string $symbol, $quantity, array $flags = []) + public function marketBuyTest(string $symbol, $quantity, array $params = []) { - return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $flags, true); + return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $params, true); } @@ -428,16 +428,16 @@ public function numberOfDecimals($val = 0.00000001) * * @param $symbol string the currency symbol * @param $quantity string the quantity of the quote you want to obtain - * @param $flags array additional options for order type + * @param $params array additional options for order type * @return array with error message or the order details */ - public function marketQuoteSell(string $symbol, $quantity, array $flags = []) + public function marketQuoteSell(string $symbol, $quantity, array $params = []) { - $flags['isQuoteOrder'] = true; + $params['isQuoteOrder'] = true; $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']); $quantity = $this->floorDecimal($quantity, $c); - return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags); + return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $params); } /** @@ -447,14 +447,14 @@ public function marketQuoteSell(string $symbol, $quantity, array $flags = []) * * @param $symbol string the currency symbol * @param $quantity string the quantity of the quote you want to obtain - * @param $flags array additional options for order type + * @param $params array additional options for order type * @return array with error message or the order details */ - public function marketQuoteSellTest(string $symbol, $quantity, array $flags = []) + public function marketQuoteSellTest(string $symbol, $quantity, array $params = []) { - $flags['isQuoteOrder'] = true; + $params['isQuoteOrder'] = true; - return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags, true); + return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $params, true); } /** @@ -465,15 +465,15 @@ public function marketQuoteSellTest(string $symbol, $quantity, array $flags = [] * * @param $symbol string the currency symbol * @param $quantity string the quantity required - * @param $flags array addtional options for order type + * @param $params array addtional options for order type * @return array with error message or the order details */ - public function marketSell(string $symbol, $quantity, array $flags = []) + public function marketSell(string $symbol, $quantity, array $params = []) { $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']); $quantity = $this->floorDecimal($quantity, $c); - return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags); + return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $params); } /** @@ -483,12 +483,12 @@ public function marketSell(string $symbol, $quantity, array $flags = []) * * @param $symbol string the currency symbol * @param $quantity string the quantity required - * @param $flags array addtional options for order type + * @param $params array addtional options for order type * @return array with error message or the order details */ - public function marketSellTest(string $symbol, $quantity, array $flags = []) + public function marketSellTest(string $symbol, $quantity, array $params = []) { - return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags, true); + return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $params, true); } /** @@ -499,17 +499,17 @@ public function marketSellTest(string $symbol, $quantity, array $flags = []) * * @param $symbol string the currency symbol * @param $orderid string the orderid to cancel - * @param $flags array of optional options like ["side"=>"sell"] + * @param $params array of optional options like ["side"=>"sell"] * @return array with error message or the order details * @throws \Exception */ - public function cancel(string $symbol, $orderid, $flags = []) + public function cancel(string $symbol, $orderid, $params = []) { $params = [ "symbol" => $symbol, "orderId" => $orderid, ]; - return $this->httpRequest("v3/order", "DELETE", array_merge($params, $flags), true); + return $this->httpRequest("v3/order", "DELETE", array_merge($params, $params), true); } /** @@ -872,7 +872,7 @@ public function commissionFee($symbol = '') */ public function withdraw(string $asset, string $address, $amount, $addressTag = null, $addressName = "", bool $transactionFeeFlag = false, $network = null, $orderId = null) { - $options = [ + $request = [ "coin" => $asset, "address" => $address, "amount" => $amount, @@ -880,20 +880,20 @@ public function withdraw(string $asset, string $address, $amount, $addressTag = ]; if (is_null($addressName) === false && empty($addressName) === false) { - $options['name'] = str_replace(' ', '%20', $addressName); + $request['name'] = str_replace(' ', '%20', $addressName); } if (is_null($addressTag) === false && empty($addressTag) === false) { - $options['addressTag'] = $addressTag; + $request['addressTag'] = $addressTag; } - if ($transactionFeeFlag) $options['transactionFeeFlag'] = true; + if ($transactionFeeFlag) $request['transactionFeeFlag'] = true; if (is_null($network) === false && empty($network) === false) { - $options['network'] = $network; + $request['network'] = $network; } if (is_null($orderId) === false && empty($orderId) === false) { - $options['withdrawOrderId'] = $orderId; + $request['withdrawOrderId'] = $orderId; } - return $this->httpRequest("v1/capital/withdraw/apply", "POST", $options, true); + return $this->httpRequest("v1/capital/withdraw/apply", "POST", $request, true); } /** @@ -1443,6 +1443,23 @@ protected function curl_set_body($curl, $option, $query) { curl_setopt($curl, $option, $query); } + protected function spotRequest($url, $method = "GET", $params = [], $signed = false) + { + return $this->httpRequest($url, $method, $params, $signed); + } + + protected function spotWalletRequest($url, $method = "GET", $params = [], $signed = false) + { + $params['sapi'] = true; + return $this->httpRequest($url, $method, $params, $signed); + } + + protected function futuresRequest($url, $method = "GET", $params = [], $signed = false) + { + $params['fapi'] = true; + return $this->httpRequest($url, $method, $params, $signed); + } + /** * httpRequest curl wrapper for all http api requests. * You can't call this function directly, use the helper functions @@ -1732,14 +1749,14 @@ public function get_headers_from_curl_response(string $header) * @param $quantity string in the order * @param $price string for the order * @param $type string is determined by the symbol bu typicall LIMIT, STOP_LOSS_LIMIT etc. - * @param $flags array additional transaction options + * @param $params array additional transaction options * @param $test bool whether to test or not, test only validates the query * @return array containing the response * @throws \Exception */ - public function order(string $side, string $symbol, $quantity, $price, string $type = "LIMIT", array $flags = [], bool $test = false) + public function order(string $side, string $symbol, $quantity, $price, string $type = "LIMIT", array $params = [], bool $test = false) { - $opt = [ + $request = [ "symbol" => $symbol, "side" => $side, "type" => $type, @@ -1765,35 +1782,35 @@ public function order(string $side, string $symbol, $quantity, $price, string $t } if ($type === "LIMIT" || $type === "STOP_LOSS_LIMIT" || $type === "TAKE_PROFIT_LIMIT") { - $opt["price"] = $price; - $opt["timeInForce"] = "GTC"; + $request["price"] = $price; + $request["timeInForce"] = "GTC"; } - if ($type === "MARKET" && isset($flags['isQuoteOrder']) && $flags['isQuoteOrder']) { - unset($opt['quantity']); - $opt['quoteOrderQty'] = $quantity; + if ($type === "MARKET" && isset($params['isQuoteOrder']) && $params['isQuoteOrder']) { + unset($request['quantity']); + $request['quoteOrderQty'] = $quantity; } - if (isset($flags['stopPrice'])) { - $opt['stopPrice'] = $flags['stopPrice']; + if (isset($params['stopPrice'])) { + $request['stopPrice'] = $params['stopPrice']; } - if (isset($flags['icebergQty'])) { - $opt['icebergQty'] = $flags['icebergQty']; + if (isset($params['icebergQty'])) { + $request['icebergQty'] = $params['icebergQty']; } - if (isset($flags['newOrderRespType'])) { - $opt['newOrderRespType'] = $flags['newOrderRespType']; + if (isset($params['newOrderRespType'])) { + $request['newOrderRespType'] = $params['newOrderRespType']; } - if (isset($flags['newClientOrderId'])) { - $opt['newClientOrderId'] = $flags['newClientOrderId']; + if (isset($params['newClientOrderId'])) { + $request['newClientOrderId'] = $params['newClientOrderId']; } else { - $opt['newClientOrderId'] = $this->generateSpotClientOrderId(); + $request['newClientOrderId'] = $this->generateSpotClientOrderId(); } $qstring = ($test === false) ? "v3/order" : "v3/order/test"; - return $this->httpRequest($qstring, "POST", $opt, true); + return $this->httpRequest($qstring, "POST", $request, true); } /** @@ -1816,24 +1833,24 @@ public function candlesticks(string $symbol, string $interval = "5m", int $limit $this->charts[$symbol] = []; } - $opt = [ + $request = [ "symbol" => $symbol, "interval" => $interval, ]; if ($limit) { - $opt["limit"] = $limit; + $request["limit"] = $limit; } if ($startTime) { - $opt["startTime"] = $startTime; + $request["startTime"] = $startTime; } if ($endTime) { - $opt["endTime"] = $endTime; + $request["endTime"] = $endTime; } - $response = $this->httpRequest("v1/klines", "GET", $opt); + $response = $this->httpRequest("v1/klines", "GET", $request); if (is_array($response) === false) { return []; @@ -3203,14 +3220,14 @@ public function apiTradingStatus() * @param int $stopprice (mandatory) Stop Price * @param int $stoplimitprice (optional) Stop Limit Price * @param int $stoplimittimeinforce (optional) GTC, FOK or IOC - * @param array $flags (optional) Extra flags/parameters + * @param array $params (optional) Extra flags/parameters * * @return array containing the response * @throws \Exception */ - public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopprice, $stoplimitprice = null, $stoplimittimeinforce = 'GTC', array $flags = []) + public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopprice, $stoplimitprice = null, $stoplimittimeinforce = 'GTC', array $params = []) { - $opt = [ + $request = [ "symbol" => $symbol, "side" => $side, "recvWindow" => 60000, @@ -3220,39 +3237,39 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp $error = "Parameter quantity expected numeric for ' $side . ' ' . $symbol .', got " . gettype($quantity); trigger_error($error, E_USER_ERROR); } else { - $opt['quantity'] = $quantity; + $request['quantity'] = $quantity; } if (is_numeric($price) === false) { $error = "Parameter price expected numeric for ' $side . ' ' . $symbol .', got " . gettype($price); trigger_error($error, E_USER_ERROR); } else { - $opt['price'] = $price; + $request['price'] = $price; } if (is_numeric($stopprice) === false) { $error = "Parameter stopprice expected numeric for ' $side . ' ' . $symbol .', got " . gettype($stopprice); trigger_error($error, E_USER_ERROR); } else { - $opt['stopPrice'] = $stopprice; + $request['stopPrice'] = $stopprice; } if (is_null($stoplimitprice) === false && empty($stoplimitprice) === false) { - $opt['stopLimitPrice'] = $stoplimitprice; + $request['stopLimitPrice'] = $stoplimitprice; if ( ($stoplimittimeinforce == 'FOK') || ($stoplimittimeinforce == 'IOC') ) { - $opt['stopLimitTimeInForce'] = $stoplimittimeinforce; + $request['stopLimitTimeInForce'] = $stoplimittimeinforce; } else { - $opt['stopLimitTimeInForce'] = 'GTC'; // `Good 'till cancel`. Needed if flag `stopLimitPrice` used. + $request['stopLimitTimeInForce'] = 'GTC'; // `Good 'till cancel`. Needed if flag `stopLimitPrice` used. } } // Check other flags foreach (array('icebergQty','stopIcebergQty','listClientOrderId','limitClientOrderId','stopClientOrderId','newOrderRespType') as $flag) { - if ( isset($flags[$flag]) && !empty($flags[$flag]) ) - $opt[$flag] = $flags[$flag]; + if ( isset($params[$flag]) && !empty($params[$flag]) ) + $request[$flag] = $params[$flag]; } - return $this->httpRequest("v3/order/oco", "POST", $opt, true); + return $this->httpRequest("v3/order/oco", "POST", $request, true); } /** @@ -3303,14 +3320,14 @@ public function avgPrice(string $symbol) * @throws \Exception */ public function bswapQuote($baseAsset, $quoteAsset, $quoteQty) { - $opt = [ + $request = [ 'sapi' => true, 'quoteAsset' => $quoteAsset, 'baseAsset' => $baseAsset, 'quoteQty' => $quoteQty, ]; - return $this->httpRequest("v1/bswap/quote", 'GET', $opt, true); + return $this->httpRequest("v1/bswap/quote", 'GET', $request, true); } /********************************************* @@ -4230,8 +4247,8 @@ public function futuresConstituents(string $symbol) * @return array containing the request * @throws \Exception */ - protected function createFuturesOrderRequest(string $side, string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $flags = []) { - $opt = [ + protected function createFuturesOrderRequest(string $side, string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $params = []) { + $request = [ 'symbol' => $symbol, 'side' => $side, 'type' => $type, @@ -4249,11 +4266,11 @@ protected function createFuturesOrderRequest(string $side, string $symbol, $quan // WPCS: XSS OK. echo "warning: quantity expected numeric got " . gettype($quantity) . PHP_EOL; } - if (isset($flags['closePosition']) && $flags['closePosition'] === true) { + if (isset($params['closePosition']) && $params['closePosition'] === true) { // WPCS: XSS OK. echo "warning: closePosition is set to true, quantity will be ignored" . PHP_EOL; } else { - $opt['quantity'] = $quantity; + $request['quantity'] = $quantity; } } @@ -4263,90 +4280,90 @@ protected function createFuturesOrderRequest(string $side, string $symbol, $quan } if ($type === "LIMIT" || $type === "STOP_LOSS_LIMIT" || $type === "TAKE_PROFIT_LIMIT") { - $opt["price"] = $price; - if (!isset($flags['timeInForce'])) { - $opt['timeInForce'] = 'GTC'; + $request["price"] = $price; + if (!isset($params['timeInForce'])) { + $request['timeInForce'] = 'GTC'; } } - if (isset($flags['positionSide'])) { - $opt['positionSide'] = $flags['positionSide']; + if (isset($params['positionSide'])) { + $request['positionSide'] = $params['positionSide']; } - if (isset($flags['timeInForce'])) { - $opt['timeInForce'] = $flags['timeInForce']; + if (isset($params['timeInForce'])) { + $request['timeInForce'] = $params['timeInForce']; } - if (isset($flags['reduceOnly'])) { - $reduceOnly = $flags['reduceOnly']; + if (isset($params['reduceOnly'])) { + $reduceOnly = $params['reduceOnly']; if ($reduceOnly === true) { - $opt['reduceOnly'] = 'true'; + $request['reduceOnly'] = 'true'; } else { - $opt['reduceOnly'] = 'false'; + $request['reduceOnly'] = 'false'; } } - if (isset($flags['newClientOrderId'])) { - $opt['newClientOrderId'] = $flags['newClientOrderId']; + if (isset($params['newClientOrderId'])) { + $request['newClientOrderId'] = $params['newClientOrderId']; } else { - $opt['newClientOrderId'] = $this->generateFuturesClientOrderId(); + $request['newClientOrderId'] = $this->generateFuturesClientOrderId(); } - if (isset($flags['stopPrice'])) { - $opt['stopPrice'] = $flags['stopPrice']; + if (isset($params['stopPrice'])) { + $request['stopPrice'] = $params['stopPrice']; } - if (isset($flags['closePosition'])) { - $closePosition = $flags['closePosition']; + if (isset($params['closePosition'])) { + $closePosition = $params['closePosition']; if ($closePosition === true) { - $opt['closePosition'] = 'true'; + $request['closePosition'] = 'true'; } else { - $opt['closePosition'] = 'false'; + $request['closePosition'] = 'false'; } } - if (isset($flags['activationPrice'])) { - $opt['activationPrice'] = $flags['activationPrice']; + if (isset($params['activationPrice'])) { + $request['activationPrice'] = $params['activationPrice']; } - if (isset($flags['callbackRate'])) { - $opt['callbackRate'] = $flags['callbackRate']; + if (isset($params['callbackRate'])) { + $request['callbackRate'] = $params['callbackRate']; } - if (isset($flags['workingType'])) { - $opt['workingType'] = $flags['workingType']; + if (isset($params['workingType'])) { + $request['workingType'] = $params['workingType']; } - if (isset($flags['priceProtect'])) { - $priceProtect = $flags['priceProtect']; + if (isset($params['priceProtect'])) { + $priceProtect = $params['priceProtect']; if ($priceProtect === true) { - $opt['priceProtect'] = 'TRUE'; + $request['priceProtect'] = 'TRUE'; } else { - $opt['priceProtect'] = 'FALSE'; + $request['priceProtect'] = 'FALSE'; } } - if (isset($flags['newOrderRespType'])) { - $opt['newOrderRespType'] = $flags['newOrderRespType']; + if (isset($params['newOrderRespType'])) { + $request['newOrderRespType'] = $params['newOrderRespType']; } - if (isset($flags['priceMatch'])) { - $opt['priceMatch'] = $flags['priceMatch']; + if (isset($params['priceMatch'])) { + $request['priceMatch'] = $params['priceMatch']; } - if (isset($flags['selfTradePreventionMode'])) { - $opt['selfTradePreventionMode'] = $flags['selfTradePreventionMode']; + if (isset($params['selfTradePreventionMode'])) { + $request['selfTradePreventionMode'] = $params['selfTradePreventionMode']; } - if (isset($flags['goodTillDate'])) { - $opt['goodTillDate'] = $flags['goodTillDate']; + if (isset($params['goodTillDate'])) { + $request['goodTillDate'] = $params['goodTillDate']; } - if (isset($flags['recvWindow'])) { - $opt['recvWindow'] = $flags['recvWindow']; + if (isset($params['recvWindow'])) { + $request['recvWindow'] = $params['recvWindow']; } - return $opt; + return $request; } /** @@ -4365,32 +4382,32 @@ protected function createFuturesOrderRequest(string $side, string $symbol, $quan * @param string $quantity (optional) of the order (Cannot be sent with closePosition=true (Close-All)) * @param string $price (optional) price per unit * @param string $type (mandatory) is determined by the symbol bu typicall LIMIT, STOP_LOSS_LIMIT etc. - * @param array $flags (optional) additional transaction options - * - @param string $flags['positionSide'] position side, "BOTH" for One-way Mode; "LONG" or "SHORT" for Hedge Mode (mandatory for Hedge Mode) - * - @param string $flags['timeInForce'] - * - @param bool $flags['reduceOnly'] default false (Cannot be sent in Hedge Mode; cannot be sent with closePosition=true) - * - @param string $flags['newClientOrderId'] new client order id - * - @param string $flags['stopPrice'] stop price (Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders) - * - @param bool $flags['closePosition'] Close-All (used with STOP_MARKET or TAKE_PROFIT_MARKET orders) - * - @param string $flags['activationPrice'] Used with TRAILING_STOP_MARKET orders, default as the latest price (supporting different workingType) - * - @param string $flags['callbackRate'] Used with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1% - * - @param string $flags['workingType'] stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE" - * - @param bool $flags['priceProtect'] Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders (default false) - * - @param string $flags['newOrderRespType'] response type, default "RESULT", other option is "ACK" - * - @param string $flags['priceMatch'] only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price - * - @param string $flags['selfTradePreventionMode'] EXPIRE_TAKER:expire taker order when STP triggers/ EXPIRE_MAKER:expire taker order when STP triggers/ EXPIRE_BOTH:expire both orders when STP triggers; default NONE - * - @param string $flags['goodTillDate'] order cancel time for timeInForce GTD, mandatory when timeInforce set to GTD; order the timestamp only retains second-level precision, ms part will be ignored; The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000 - * - @param int $flags['recvWindow'] + * @param array $params (optional) additional transaction options + * - @param string $params['positionSide'] position side, "BOTH" for One-way Mode; "LONG" or "SHORT" for Hedge Mode (mandatory for Hedge Mode) + * - @param string $params['timeInForce'] + * - @param bool $params['reduceOnly'] default false (Cannot be sent in Hedge Mode; cannot be sent with closePosition=true) + * - @param string $params['newClientOrderId'] new client order id + * - @param string $params['stopPrice'] stop price (Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders) + * - @param bool $params['closePosition'] Close-All (used with STOP_MARKET or TAKE_PROFIT_MARKET orders) + * - @param string $params['activationPrice'] Used with TRAILING_STOP_MARKET orders, default as the latest price (supporting different workingType) + * - @param string $params['callbackRate'] Used with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1% + * - @param string $params['workingType'] stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE" + * - @param bool $params['priceProtect'] Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders (default false) + * - @param string $params['newOrderRespType'] response type, default "RESULT", other option is "ACK" + * - @param string $params['priceMatch'] only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price + * - @param string $params['selfTradePreventionMode'] EXPIRE_TAKER:expire taker order when STP triggers/ EXPIRE_MAKER:expire taker order when STP triggers/ EXPIRE_BOTH:expire both orders when STP triggers; default NONE + * - @param string $params['goodTillDate'] order cancel time for timeInForce GTD, mandatory when timeInforce set to GTD; order the timestamp only retains second-level precision, ms part will be ignored; The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000 + * - @param int $params['recvWindow'] * @param $test bool whether to test or not, test only validates the query * @return array containing the response * @throws \Exception */ - public function futuresOrder(string $side, string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $flags = [], $test = false) + public function futuresOrder(string $side, string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $params = [], $test = false) { - $opt = $this->createFuturesOrderRequest($side, $symbol, $quantity, $price, $type, $flags); - $opt['fapi'] = true; + $request = $this->createFuturesOrderRequest($side, $symbol, $quantity, $price, $type, $params); + $request['fapi'] = true; $qstring = ($test === false) ? 'v1/order' : 'v1/order/test'; - return $this->httpRequest($qstring, 'POST', $opt, true); + return $this->httpRequest($qstring, 'POST', $request, true); } /** @@ -4417,27 +4434,27 @@ public function futuresOrder(string $side, string $symbol, $quantity = null, $pr * @param string $quantity (optional) the quantity required * @param string $price (optional) price per unit * @param string $type (mandatory) type of order - * @param array $flags (optional) addtional options for order type - * - @param string $flags['positionSide'] position side, "BOTH" for One-way Mode; "LONG" or "SHORT" for Hedge Mode (mandatory for Hedge Mode) - * - @param string $flags['timeInForce'] - * - @param bool $flags['reduceOnly'] default false (Cannot be sent in Hedge Mode; cannot be sent with closePosition=true) - * - @param string $flags['newClientOrderId'] new client order id - * - @param string $flags['stopPrice'] stop price (Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders) - * - @param bool $flags['closePosition'] Close-All (used with STOP_MARKET or TAKE_PROFIT_MARKET orders) - * - @param string $flags['activationPrice'] Used with TRAILING_STOP_MARKET orders, default as the latest price (supporting different workingType) - * - @param string $flags['callbackRate'] Used with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1% - * - @param string $flags['workingType'] stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE" - * - @param bool $flags['priceProtect'] Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders (default false) - * - @param string $flags['newOrderRespType'] response type, default "RESULT", other option is "ACK" - * - @param string $flags['priceMatch'] only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price - * - @param string $flags['selfTradePreventionMode'] EXPIRE_TAKER:expire taker order when STP triggers/ EXPIRE_MAKER:expire taker order when STP triggers/ EXPIRE_BOTH:expire both orders when STP triggers; default NONE - * - @param string $flags['goodTillDate'] order cancel time for timeInForce GTD, mandatory when timeInforce set to GTD; order the timestamp only retains second-level precision, ms part will be ignored; The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000 - * - @param int $flags['recvWindow'] + * @param array $params (optional) addtional options for order type + * - @param string $params['positionSide'] position side, "BOTH" for One-way Mode; "LONG" or "SHORT" for Hedge Mode (mandatory for Hedge Mode) + * - @param string $params['timeInForce'] + * - @param bool $params['reduceOnly'] default false (Cannot be sent in Hedge Mode; cannot be sent with closePosition=true) + * - @param string $params['newClientOrderId'] new client order id + * - @param string $params['stopPrice'] stop price (Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders) + * - @param bool $params['closePosition'] Close-All (used with STOP_MARKET or TAKE_PROFIT_MARKET orders) + * - @param string $params['activationPrice'] Used with TRAILING_STOP_MARKET orders, default as the latest price (supporting different workingType) + * - @param string $params['callbackRate'] Used with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1% + * - @param string $params['workingType'] stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE" + * - @param bool $params['priceProtect'] Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders (default false) + * - @param string $params['newOrderRespType'] response type, default "RESULT", other option is "ACK" + * - @param string $params['priceMatch'] only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price + * - @param string $params['selfTradePreventionMode'] EXPIRE_TAKER:expire taker order when STP triggers/ EXPIRE_MAKER:expire taker order when STP triggers/ EXPIRE_BOTH:expire both orders when STP triggers; default NONE + * - @param string $params['goodTillDate'] order cancel time for timeInForce GTD, mandatory when timeInforce set to GTD; order the timestamp only retains second-level precision, ms part will be ignored; The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000 + * - @param int $params['recvWindow'] * @return array with error message or the order details */ - public function futuresBuy(string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $flags = []) + public function futuresBuy(string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $params = []) { - return $this->futuresOrder('BUY', $symbol, $quantity, $price, $type, $flags); + return $this->futuresOrder('BUY', $symbol, $quantity, $price, $type, $params); } /** @@ -4447,9 +4464,9 @@ public function futuresBuy(string $symbol, $quantity = null, $price = null, stri * * params and return value are the same as @see futuresBuy() */ - public function futuresBuyTest(string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $flags = []) + public function futuresBuyTest(string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $params = []) { - return $this->futuresOrder('BUY', $symbol, $quantity, $price, $type, $flags, true); + return $this->futuresOrder('BUY', $symbol, $quantity, $price, $type, $params, true); } /** @@ -4476,27 +4493,27 @@ public function futuresBuyTest(string $symbol, $quantity = null, $price = null, * @param string $quantity (optional) the quantity required * @param string $price (optional) price per unit * @param string $type (mandatory) type of order - * @param array $flags (optional) addtional options for order type - * - @param string $flags['positionSide'] position side, "BOTH" for One-way Mode; "LONG" or "SHORT" for Hedge Mode (mandatory for Hedge Mode) - * - @param string $flags['timeInForce'] - * - @param bool $flags['reduceOnly'] default false (Cannot be sent in Hedge Mode; cannot be sent with closePosition=true) - * - @param string $flags['newClientOrderId'] new client order id - * - @param string $flags['stopPrice'] stop price (Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders) - * - @param bool $flags['closePosition'] Close-All (used with STOP_MARKET or TAKE_PROFIT_MARKET orders) - * - @param string $flags['activationPrice'] Used with TRAILING_STOP_MARKET orders, default as the latest price (supporting different workingType) - * - @param string $flags['callbackRate'] Used with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1% - * - @param string $flags['workingType'] stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE" - * - @param bool $flags['priceProtect'] Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders (default false) - * - @param string $flags['newOrderRespType'] response type, default "RESULT", other option is "ACK" - * - @param string $flags['priceMatch'] only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price - * - @param string $flags['selfTradePreventionMode'] EXPIRE_TAKER:expire taker order when STP triggers/ EXPIRE_MAKER:expire taker order when STP triggers/ EXPIRE_BOTH:expire both orders when STP triggers; default NONE - * - @param string $flags['goodTillDate'] order cancel time for timeInForce GTD, mandatory when timeInforce set to GTD; order the timestamp only retains second-level precision, ms part will be ignored; The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000 - * - @param int $flags['recvWindow'] + * @param array $params (optional) addtional options for order type + * - @param string $params['positionSide'] position side, "BOTH" for One-way Mode; "LONG" or "SHORT" for Hedge Mode (mandatory for Hedge Mode) + * - @param string $params['timeInForce'] + * - @param bool $params['reduceOnly'] default false (Cannot be sent in Hedge Mode; cannot be sent with closePosition=true) + * - @param string $params['newClientOrderId'] new client order id + * - @param string $params['stopPrice'] stop price (Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders) + * - @param bool $params['closePosition'] Close-All (used with STOP_MARKET or TAKE_PROFIT_MARKET orders) + * - @param string $params['activationPrice'] Used with TRAILING_STOP_MARKET orders, default as the latest price (supporting different workingType) + * - @param string $params['callbackRate'] Used with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1% + * - @param string $params['workingType'] stopPrice triggered by: "MARK_PRICE", "CONTRACT_PRICE". Default "CONTRACT_PRICE" + * - @param bool $params['priceProtect'] Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders (default false) + * - @param string $params['newOrderRespType'] response type, default "RESULT", other option is "ACK" + * - @param string $params['priceMatch'] only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price + * - @param string $params['selfTradePreventionMode'] EXPIRE_TAKER:expire taker order when STP triggers/ EXPIRE_MAKER:expire taker order when STP triggers/ EXPIRE_BOTH:expire both orders when STP triggers; default NONE + * - @param string $params['goodTillDate'] order cancel time for timeInForce GTD, mandatory when timeInforce set to GTD; order the timestamp only retains second-level precision, ms part will be ignored; The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000 + * - @param int $params['recvWindow'] * @return array with error message or the order details */ - public function futuresSell(string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $flags = []) + public function futuresSell(string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $params = []) { - return $this->futuresOrder('SELL', $symbol, $quantity, $price, $type, $flags); + return $this->futuresOrder('SELL', $symbol, $quantity, $price, $type, $params); } /** @@ -4506,12 +4523,12 @@ public function futuresSell(string $symbol, $quantity = null, $price = null, str * * params and return value are the same as @see futuresSell() */ - public function futuresSellTest(string $symbol, $quantity = null, $price = null, $type = null, array $flags = []) + public function futuresSellTest(string $symbol, $quantity = null, $price = null, $type = null, array $params = []) { if ($type === null) { $type = 'LIMIT'; } - return $this->futuresOrder('SELL', $symbol, $quantity, $price, $type, $flags, true); + return $this->futuresOrder('SELL', $symbol, $quantity, $price, $type, $params, true); } /** @@ -4574,7 +4591,7 @@ protected function createBatchOrdersRequest(array $orders, bool $edit = false) * @link https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Place-Multiple-Orders * * @param array $orders (mandatory) array of orders to be placed - * objects in the array should contain literally the same keys as the @see futuresOrder but without the $flags['recvWindow'] + * objects in the array should contain literally the same keys as the @see futuresOrder but without the $params['recvWindow'] * @param string $recvWindow (optional) the time in milliseconds to wait for a response * * @return array containing the response or error message @@ -4608,34 +4625,34 @@ public function futuresBatchOrders(array $orders, int $recvWindow = null) * * @param string $symbol (mandatory) market symbol * @param string $side (mandatory) "BUY" or "SELL" - * @param string $orderId (optional) order id to be modified (mandatory if $flags['origClientOrderId'] is not set) + * @param string $orderId (optional) order id to be modified (mandatory if $params['origClientOrderId'] is not set) * @param string $quantity (optional) of the order (Cannot be sent for orders with closePosition=true (Close-All)) * @param string $price (mandatory) price per unit - * @param array $flags (optional) additional options - * - @param string $flags['priceMatch'] only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price - * - @param int $flags['recvWindow'] - * - @param string $flags['origClientOrderId'] client order id to be modified (mandatory if $orderId is not set) + * @param array $params (optional) additional options + * - @param string $params['priceMatch'] only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price + * - @param int $params['recvWindow'] + * - @param string $params['origClientOrderId'] client order id to be modified (mandatory if $orderId is not set) * @return array containing the response * @throws \Exception */ - public function futuresEditOrder(string $symbol, string $side, string $quantity, string $price, $orderId = null, array $flags = []) + public function futuresEditOrder(string $symbol, string $side, string $quantity, string $price, $orderId = null, array $params = []) { - $opt = $this->createFuturesOrderRequest($side, $symbol, $quantity, $price, 'LIMIT', $flags); + $request = $this->createFuturesOrderRequest($side, $symbol, $quantity, $price, 'LIMIT', $params); $origClientOrderId = null; - if (isset($flags['origClientOrderId'])) { - $origClientOrderId = $flags['origClientOrderId']; - $opt['origClientOrderId'] = $origClientOrderId; + if (isset($params['origClientOrderId'])) { + $origClientOrderId = $params['origClientOrderId']; + $request['origClientOrderId'] = $origClientOrderId; } if (!$origClientOrderId && !$orderId) { throw new \Exception('futuresEditOrder: either orderId or origClientOrderId must be set'); } if ($orderId) { - $opt['orderId'] = $orderId; + $request['orderId'] = $orderId; } - unset($opt['type']); - unset($opt['newClientOrderId']); - $opt['fapi'] = true; - return $this->httpRequest("v1/order", 'PUT', $opt, true); + unset($request['type']); + unset($request['newClientOrderId']); + $request['fapi'] = true; + return $this->httpRequest("v1/order", 'PUT', $request, true); } /** @@ -4644,7 +4661,7 @@ public function futuresEditOrder(string $symbol, string $side, string $quantity, * @link https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Multiple-Orders * * @param array $orders (mandatory) array of orders to be modified - * objects in the array should contain literally the same keys as the @see futuresEditOrder but without the $flags['recvWindow'] + * objects in the array should contain literally the same keys as the @see futuresEditOrder but without the $params['recvWindow'] * @param string $recvWindow (optional) the time in milliseconds to wait for a response * * @return array containing the response or error message @@ -4716,15 +4733,15 @@ public function futuresOrderAmendment(string $symbol, $orderId = null, $origClie * $order = $api->futuresCancel("BNBBTC", $orderid); * * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) - * @param string $orderid (optional) the orderid to cancel (mandatory if $flags['origClientOrderId'] is not set) - * @param array $flags (optional) additional options - * - @param string $flags['origClientOrderId'] original client order id to cancel - * - @param int $flags['recvWindow'] the time in milliseconds to wait for a response + * @param string $orderid (optional) the orderid to cancel (mandatory if $params['origClientOrderId'] is not set) + * @param array $params (optional) additional options + * - @param string $params['origClientOrderId'] original client order id to cancel + * - @param int $params['recvWindow'] the time in milliseconds to wait for a response * * @return array with error message or the order details * @throws \Exception */ - public function futuresCancel(string $symbol, $orderid, $flags = []) + public function futuresCancel(string $symbol, $orderid, $params = []) { $params = [ 'symbol' => $symbol, @@ -4732,10 +4749,10 @@ public function futuresCancel(string $symbol, $orderid, $flags = []) ]; if ($orderid) { $params['orderId'] = $orderid; - } else if (!isset($flags['origClientOrderId'])) { + } else if (!isset($params['origClientOrderId'])) { throw new \Exception('futuresCancel: either orderId or origClientOrderId must be set'); } - return $this->httpRequest("v1/order", 'DELETE', array_merge($params, $flags), true); + return $this->httpRequest("v1/order", 'DELETE', array_merge($params, $params), true); } /** @@ -6151,4 +6168,4 @@ public function convertStatus($orderId = null, $quoteId = null) } return $this->httpRequest("v1/convert/orderStatus", 'GET', $params, true); } -} \ No newline at end of file +} From 7b930c0b1a0f7f9f81ebca0185cb77c144a1f771 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:05:04 +0300 Subject: [PATCH 02/11] Spot methods updated --- php-binance-api.php | 314 +++++++++++++++++++++++--------------------- 1 file changed, 163 insertions(+), 151 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index f50e875..9e5547e 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -503,13 +503,13 @@ public function marketSellTest(string $symbol, $quantity, array $params = []) * @return array with error message or the order details * @throws \Exception */ - public function cancel(string $symbol, $orderid, $params = []) + public function cancel(string $symbol, string $orderid, $params = []) { - $params = [ + $request = [ "symbol" => $symbol, "orderId" => $orderid, ]; - return $this->httpRequest("v3/order", "DELETE", array_merge($params, $params), true); + return $this->spotRequest("v3/order", "DELETE", array_merge($request, $params), true); } /** @@ -523,12 +523,13 @@ public function cancel(string $symbol, $orderid, $params = []) * @return array with error message or the order details * @throws \Exception */ - public function orderStatus(string $symbol, $orderid) + public function orderStatus(string $symbol, string $orderid, array $params = []) { - return $this->httpRequest("v3/order", "GET", [ + $request = [ "symbol" => $symbol, "orderId" => $orderid, - ], true); + ]; + return $this->spotRequest("v3/order", "GET", array_merge($request, $params), true); } /** @@ -541,15 +542,15 @@ public function orderStatus(string $symbol, $orderid) * @return array with error message or the order details * @throws \Exception */ - public function openOrders(string $symbol = null) + public function openOrders($symbol = null, array $params = []) { - $params = []; + $request = []; if (is_null($symbol) != true) { - $params = [ + $request = [ "symbol" => $symbol, ]; } - return $this->httpRequest("v3/openOrders", "GET", $params, true); + return $this->spotRequest("v3/openOrders", "GET", array_merge($request, $params), true); } /** @@ -559,15 +560,15 @@ public function openOrders(string $symbol = null) * @return array with error message or the order details * @throws \Exception */ - public function cancelOpenOrders(string $symbol = null) + public function cancelOpenOrders($symbol = null, array $params = []) { - $params = []; + $request = []; if (is_null($symbol) != true) { - $params = [ + $request = [ "symbol" => $symbol, ]; } - return $this->httpRequest("v3/openOrders", "DELETE", $params, true); + return $this->spotRequest("v3/openOrders", "DELETE", array_merge($request, $params), true); } /** @@ -584,12 +585,14 @@ public function cancelOpenOrders(string $symbol = null) */ public function orders(string $symbol, int $limit = 500, int $fromOrderId = 0, array $params = []) { - $params["symbol"] = $symbol; - $params["limit"] = $limit; + $request = [ + "symbol" => $symbol, + "limit" => $limit, + ]; if ($fromOrderId) { - $params["orderId"] = $fromOrderId; + $request["orderId"] = $fromOrderId; } - return $this->httpRequest("v3/allOrders", "GET", $params, true); + return $this->spotRequest("v3/allOrders", "GET", array_merge($request, $params), true); } /** @@ -609,23 +612,23 @@ public function orders(string $symbol, int $limit = 500, int $fromOrderId = 0, a * @return array with error message or array of orderDetails array * @throws \Exception */ - public function history(string $symbol, int $limit = 500, int $fromTradeId = -1, int $startTime = null, int $endTime = null) + public function history(string $symbol, int $limit = 500, int $fromTradeId = -1, int $startTime = null, int $endTime = null, array $params = []) { - $parameters = [ + $request = [ "symbol" => $symbol, "limit" => $limit, ]; if ($fromTradeId > 0) { - $parameters["fromId"] = $fromTradeId; + $request["fromId"] = $fromTradeId; } if (isset($startTime)) { - $parameters["startTime"] = $startTime; + $request["startTime"] = $startTime; } if (isset($endTime)) { - $parameters["endTime"] = $endTime; + $request["endTime"] = $endTime; } - return $this->httpRequest("v3/myTrades", "GET", $parameters, true); + return $this->spotRequest("v3/myTrades", "GET", array_merge($request, $params), true); } /** @@ -636,9 +639,9 @@ public function history(string $symbol, int $limit = 500, int $fromTradeId = -1, * @return array with error message or array of orderDetails array * @throws \Exception */ - public function myTrades(string $symbol, int $limit = 500, int $fromTradeId = -1, int $startTime = null, int $endTime = null) + public function myTrades(string $symbol, int $limit = 500, int $fromTradeId = -1, int $startTime = null, int $endTime = null, array $params = []) { - return $this->history($symbol, $limit, $fromTradeId, $startTime, $endTime); + return $this->history($symbol, $limit, $fromTradeId, $startTime, $endTime, $params); } /** @@ -649,9 +652,9 @@ public function myTrades(string $symbol, int $limit = 500, int $fromTradeId = -1 * @return null * @throws \Exception */ - public function useServerTime() + public function useServerTime(array $params = []) { - $request = $this->httpRequest("v3/time"); + $request = $this->spotRequest("v3/time", "GET", $params); if (isset($request['serverTime'])) { $this->info['timeOffset'] = $request['serverTime'] - (microtime(true) * 1000); } @@ -665,9 +668,9 @@ public function useServerTime() * @return array with error message or array with server time key * @throws \Exception */ - public function time() + public function time(array $params = []) { - return $this->httpRequest("v3/time"); + return $this->spotRequest("v3/time", "GET", $params); } /** @@ -688,20 +691,20 @@ public function time() * @return array containing the response * @throws \Exception */ - public function exchangeInfo($symbols = null) + public function exchangeInfo($symbols = null, array $params = []) { if (!$this->exchangeInfo) { $arr = array(); if ($symbols) { if (gettype($symbols) == "string") { - $parameters["symbol"] = $symbols; - $arr = $this->httpRequest("v3/exchangeInfo", "GET", $parameters); + $request["symbol"] = $symbols; + $arr = $this->spotRequest("v3/exchangeInfo", "GET", array_merge($request, $params)); } if (gettype($symbols) == "array") { - $arr = $this->httpRequest("v3/exchangeInfo?symbols=" . '["' . implode('","', $symbols) . '"]'); + $arr = $this->spotRequest("v3/exchangeInfo?symbols=" . '["' . implode('","', $symbols) . '"]', "GET", $params); } } else { - $arr = $this->httpRequest("v3/exchangeInfo"); + $arr = $this->spotRequest("v3/exchangeInfo", "GET", $params); } if ((is_array($arr) === false) || empty($arr)) { echo "Error: unable to fetch spot exchange info" . PHP_EOL; @@ -730,12 +733,12 @@ public function exchangeInfo($symbols = null) * * @return array containing the response */ - public function assetDetail($asset = '') + public function assetDetail($asset = '', array $params = []) { - $params["sapi"] = true; + $request = array(); if ($asset != '' && gettype($asset) == 'string') - $params['asset'] = $asset; - $arr = $this->httpRequest("v1/asset/assetDetail", 'GET', $params, true); + $request['asset'] = $asset; + $arr = $this->spotWalletRequest("v1/asset/assetDetail", 'GET', array_merge($request, $params), true); // if asset was set, no backward compatibility needed as this was implemented later if (isset($params['asset'])) return $arr; @@ -779,15 +782,15 @@ public function userAssetDribbletLog() * @return array containing the response * @throws \Exception */ - public function dustLog($startTime = NULL, $endTime = NULL) + public function dustLog($startTime = NULL, $endTime = NULL, array $params = []) { - $params["sapi"] = true; + $request = array(); if (!empty($startTime) && !empty($endTime)) { - $params['startTime'] = $startTime; - $params['endTime'] = $endTime; + $request['startTime'] = $startTime; + $request['endTime'] = $endTime; } - return $this->httpRequest("v1/asset/dribblet", 'GET', $params, true); + return $this->spotWalletRequest("v1/asset/dribblet", 'GET', array_merge($request, $params), true); } /** @@ -802,12 +805,13 @@ public function dustLog($startTime = NULL, $endTime = NULL) * @return array containing the response * @throws \Exception */ - public function dustTransfer($assets) + public function dustTransfer($assets, array $params = []) { - $params["sapi"] = true; - $params["asset"] = $assets; + $request = [ + 'assets' => $assets, + ]; - return $this->httpRequest("v1/asset/dust", 'POST', $params, true); + return $this->spotWalletRequest("v1/asset/dust", 'POST', array_merge($request, $params), true); } /** @@ -818,13 +822,12 @@ public function dustTransfer($assets) * @param string $symbol * @return mixed */ - public function tradeFee(string $symbol) + public function tradeFee(string $symbol, array $params = []) { - $params = [ + $request = [ "symbol" => $symbol, - "sapi" => true, ]; - return $this->httpRequest("v1/asset/tradeFee", 'GET', $params, true); + return $this->spotWalletRequest("v1/asset/tradeFee", 'GET', array_merge($request, $params), true); } /** @@ -839,13 +842,13 @@ public function tradeFee(string $symbol) * @return array containing the response * @throws \Exception */ - public function commissionFee($symbol = '') + public function commissionFee($symbol = '', array $params = []) { - $params = array('sapi' => true); + $request = array(); if ($symbol != '' && gettype($symbol) == 'string') - $params['symbol'] = $symbol; + $request['symbol'] = $symbol; - return $this->httpRequest("v1/asset/tradeFee", 'GET', $params, true); + return $this->spotWalletRequest("v1/asset/tradeFee", 'GET', array_merge($request, $params), true); } /** @@ -870,7 +873,7 @@ public function commissionFee($symbol = '') * @return array containing the response * @throws \Exception */ - public function withdraw(string $asset, string $address, $amount, $addressTag = null, $addressName = "", bool $transactionFeeFlag = false, $network = null, $orderId = null) + public function withdraw(string $asset, string $address, $amount, $addressTag = null, $addressName = "", bool $transactionFeeFlag = false, $network = null, $orderId = null, array $params = []) { $request = [ "coin" => $asset, @@ -893,7 +896,7 @@ public function withdraw(string $asset, string $address, $amount, $addressTag = if (is_null($orderId) === false && empty($orderId) === false) { $request['withdrawOrderId'] = $orderId; } - return $this->httpRequest("v1/capital/withdraw/apply", "POST", $request, true); + return $this->spotWalletRequest("v1/capital/withdraw/apply", "POST", array_merge($request, $params), true); } /** @@ -909,17 +912,16 @@ public function withdraw(string $asset, string $address, $amount, $addressTag = * @return array containing the response * @throws \Exception */ - public function depositAddress(string $asset, $network = null) + public function depositAddress(string $asset, $network = null, array $params = []) { - $params = [ - "sapi" => true, + $request = [ "coin" => $asset, ]; if (is_null($network) === false && empty($network) === false) { - $params['network'] = $network; + $request['network'] = $network; } - $return = $this->httpRequest("v1/capital/deposit/address", "GET", $params, true); + $return = $this->spotWalletRequest("v1/capital/deposit/address", "GET", array_merge($request, $params), true); // Adding for backwards compatibility with wapi if (is_array($return) && !empty($return)) { @@ -952,11 +954,11 @@ public function depositAddress(string $asset, $network = null) */ public function depositHistory(string $asset = null, array $params = []) { - $params["sapi"] = true; + $request = array(); if (is_null($asset) === false) { - $params['coin'] = $asset; + $request['coin'] = $asset; } - $return = $this->httpRequest("v1/capital/deposit/hisrec", "GET", $params, true); + $return = $this->spotWalletRequest("v1/capital/deposit/hisrec", "GET", array_merge($request, $params), true); // Adding for backwards compatibility with wapi if (is_array($return) && !empty($return)) { @@ -986,13 +988,13 @@ public function depositHistory(string $asset = null, array $params = []) */ public function withdrawHistory(string $asset = null, array $params = []) { - $params["sapi"] = true; + $request = array(); if (is_null($asset) === false) { - $params['coin'] = $asset; + $request['coin'] = $asset; } // Wrapping in array for backwards compatibility with wapi $return = array( - 'withdrawList' => $this->httpRequest("v1/capital/withdraw/history", "GET", $params, true) + 'withdrawList' => $this->spotWalletRequest("v1/capital/withdraw/history", "GET", array_merge($request, $params), true) ); // Adding for backwards compatibility with wapi @@ -1011,9 +1013,9 @@ public function withdrawHistory(string $asset = null, array $params = []) * @return array containing the response * @throws \Exception */ - public function withdrawFee(string $asset) + public function withdrawFee(string $asset, array $params = []) { - $return = $this->assetDetail(); + $return = $this->assetDetail('', $params); if (isset($return['success'], $return['assetDetail'], $return['assetDetail'][$asset]) && $return['success']) { return $return['assetDetail'][$asset]; @@ -1071,26 +1073,25 @@ public function withdrawFee(string $asset) * @return array containing the response * @throws \Exception */ - public function transfer(string $type, string $asset, string $amount, $fromSymbol = null, $toSymbol = null, int $recvWindow = null) + public function transfer(string $type, string $asset, string $amount, $fromSymbol = null, $toSymbol = null, int $recvWindow = null, array $params = []) { - $params = [ + $request = [ 'type' => $type, 'asset' => $asset, 'amount' => $amount, - 'sapi' => true, ]; // todo: check this method with real account if ($fromSymbol) { - $params['fromSymbol'] = $fromSymbol; + $request['fromSymbol'] = $fromSymbol; } if ($toSymbol) { - $params['toSymbol'] = $toSymbol; + $request['toSymbol'] = $toSymbol; } if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['recvWindow'] = $recvWindow; } - return $this->httpRequest("v1/asset/transfer", 'POST', $params, true); + return $this->spotWalletRequest("v1/asset/transfer", 'POST', array_merge($request, $params), true); } /** @@ -1112,36 +1113,35 @@ public function transfer(string $type, string $asset, string $amount, $fromSymbo * @return array containing the response * @throws \Exception */ - public function transfersHistory(string $type, $startTime = null, $endTime = null, $limit = null, $current = null, $fromSymbol = null, $toSymbol = null, $recvWindow = null) + public function transfersHistory(string $type, $startTime = null, $endTime = null, $limit = null, $current = null, $fromSymbol = null, $toSymbol = null, $recvWindow = null, array $params = []) { - $params = [ + $request = [ 'type' => $type, - 'sapi' => true, ]; // todo: check this method with real account if ($startTime) { - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($limit) { - $params['size'] = $limit; + $request['size'] = $limit; } if ($current) { - $params['current'] = $current; + $request['current'] = $current; } if ($fromSymbol) { - $params['fromSymbol'] = $fromSymbol; + $request['fromSymbol'] = $fromSymbol; } if ($toSymbol) { - $params['toSymbol'] = $toSymbol; + $request['toSymbol'] = $toSymbol; } if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['recvWindow'] = $recvWindow; } - return $this->httpRequest("v1/asset/transfer", 'GET', $params, true); + return $this->spotWalletRequest("v1/asset/transfer", 'GET', array_merge($request, $params), true); } /** @@ -1152,9 +1152,9 @@ public function transfersHistory(string $type, $startTime = null, $endTime = nul * @return array with error message or array of all the currencies prices * @throws \Exception */ - public function prices() + public function prices(array $params = []) { - return $this->priceData($this->httpRequest("v3/ticker/price")); + return $this->priceData($this->spotRequest("v3/ticker/price", "GET", $params)); } /** @@ -1165,9 +1165,12 @@ public function prices() * @return array with error message or array with symbol price * @throws \Exception */ - public function price(string $symbol) + public function price(string $symbol, array $params = []) { - $ticker = $this->httpRequest("v3/ticker/price", "GET", ["symbol" => $symbol]); + $request = [ + "symbol" => $symbol, + ]; + $ticker = $this->spotRequest("v3/ticker/price", "GET", array_merge($request, $params)); if (!isset($ticker['price'])) { echo "Error: unable to fetch price for $symbol" . PHP_EOL; return null; @@ -1183,9 +1186,9 @@ public function price(string $symbol) * @return array with error message or array of all the book prices * @throws \Exception */ - public function bookPrices() + public function bookPrices(array $params = []) { - return $this->bookPriceData($this->httpRequest("v3/ticker/bookTicker")); + return $this->bookPriceData($this->spotRequest("v3/ticker/bookTicker", "GET", $params)); } /** @@ -1196,9 +1199,9 @@ public function bookPrices() * @return array with error message or array of all the account information * @throws \Exception */ - public function account() + public function account(array $params = []) { - return $this->httpRequest("v3/account", "GET", [], true); + return $this->spotRequest("v3/account", "GET", $params, true); } /** @@ -1210,15 +1213,15 @@ public function account() * @return array with error message or array of prevDay change * @throws \Exception */ - public function prevDay(string $symbol = null) + public function prevDay(string $symbol = null, array $params = []) { - $additionalData = []; + $request = []; if (is_null($symbol) === false) { - $additionalData = [ + $request = [ 'symbol' => $symbol, ]; } - return $this->httpRequest("v1/ticker/24hr", "GET", $additionalData); + return $this->spotRequest("v1/ticker/24hr", "GET", array_merge($request, $params)); } /** @@ -1230,11 +1233,12 @@ public function prevDay(string $symbol = null) * @return array with error message or array of market history * @throws \Exception */ - public function aggTrades(string $symbol) + public function aggTrades(string $symbol, array $params = []) { - return $this->tradesData($this->httpRequest("v1/aggTrades", "GET", [ + $request = [ "symbol" => $symbol, - ])); + ]; + return $this->tradesData($this->spotRequest("v1/aggTrades", "GET", array_merge($request, $params))); } /** @@ -1253,23 +1257,23 @@ public function aggTrades(string $symbol) * @return array containing the response * @throws \Exception */ - public function historicalTrades(string $symbol, int $limit = 500, int $tradeId = -1) + public function historicalTrades(string $symbol, int $limit = 500, int $tradeId = -1, array $params = []) { - $parameters = [ + $request = [ "symbol" => $symbol, "limit" => $limit, ]; if ($tradeId > 0) { - $parameters["fromId"] = $tradeId; + $request["fromId"] = $tradeId; } else { // if there is no tradeId given, we can use v3/trades, weight is 1 and not 5 - return $this->httpRequest("v3/trades", "GET", $parameters); + return $this->spotRequest("v3/trades", "GET", array_merge($request, $params)); } // The endpoint cannot handle extra parameters like 'timestamp' or 'signature', // but it needs the http header with the key so we need to construct it here - $query = http_build_query($parameters, '', '&'); - return $this->httpRequest("v3/historicalTrades?$query"); + $query = http_build_query(array_merge($request, $params), '', '&'); + return $this->spotRequest("v3/historicalTrades?$query"); } /** @@ -1282,7 +1286,7 @@ public function historicalTrades(string $symbol, int $limit = 500, int $tradeId * @return array with error message or array of market depth * @throws \Exception */ - public function depth(string $symbol, int $limit = 100) + public function depth(string $symbol, int $limit = 100, array $params = []) { if (is_int($limit) === false) { $limit = 100; @@ -1292,10 +1296,11 @@ public function depth(string $symbol, int $limit = 100) // WPCS: XSS OK. echo "asset: expected bool false, " . gettype($symbol) . " given" . PHP_EOL; } - $json = $this->httpRequest("v1/depth", "GET", [ + $request = [ "symbol" => $symbol, "limit" => $limit, - ]); + ]; + $json = $this->spotRequest("v1/depth", "GET", array_merge($request, $params), true); if (is_array($json) === false) { echo "Error: unable to fetch depth" . PHP_EOL; $json = []; @@ -1323,16 +1328,16 @@ public function depth(string $symbol, int $limit = 100) * @return array with error message or array of balances * @throws \Exception */ - public function balances(string $market_type = 'spot', $recvWindow = null, string $api_version = 'v2') + public function balances(string $market_type = 'spot', $recvWindow = null, string $api_version = 'v2', array $params = []) { $is_spot = $market_type === 'spot'; - $params = []; + $request = []; if ($is_spot) { $url = "v3/account"; } else { - $params['fapi'] = true; + $request['fapi'] = true; if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['recvWindow'] = $recvWindow; } if ($api_version === 'v2') { $url = "v2/balance"; @@ -1342,7 +1347,7 @@ public function balances(string $market_type = 'spot', $recvWindow = null, strin throw new \Exception("Invalid API version specified. Use 'v2' or 'v3'."); } } - $response = $this->httpRequest($url, "GET", $params, true); + $response = $this->httpRequest($url, "GET", array_merge($request, $params), true); if (is_array($response) === false) { echo "Error: unable to fetch your account details" . PHP_EOL; } @@ -1360,9 +1365,9 @@ public function balances(string $market_type = 'spot', $recvWindow = null, strin * @return array with error message or array containing coins * @throws \Exception */ - public function coins() + public function coins(array $params = []) { - return $this->httpRequest("v1/capital/config/getall", 'GET', [ 'sapi' => true ], true); + return $this->spotWalletRequest("v1/capital/config/getall", 'GET', $params, true); } /** @@ -1460,6 +1465,12 @@ protected function futuresRequest($url, $method = "GET", $params = [], $signed = return $this->httpRequest($url, $method, $params, $signed); } + protected function fapiDataRequest($url, $method = "GET", $params = [], $signed = false) + { + $params['fapiData'] = true; + return $this->httpRequest($url, $method, $params, $signed); + } + /** * httpRequest curl wrapper for all http api requests. * You can't call this function directly, use the helper functions @@ -1810,7 +1821,7 @@ public function order(string $side, string $symbol, $quantity, $price, string $t } $qstring = ($test === false) ? "v3/order" : "v3/order/test"; - return $this->httpRequest($qstring, "POST", $request, true); + return $this->spotRequest($qstring, "POST", array_merge($request, $params), true); } /** @@ -1827,7 +1838,7 @@ public function order(string $side, string $symbol, $quantity, $price, string $t * @return array containing the response * @throws \Exception */ - public function candlesticks(string $symbol, string $interval = "5m", int $limit = null, $startTime = null, $endTime = null) + public function candlesticks(string $symbol, string $interval = "5m", int $limit = null, $startTime = null, $endTime = null, array $params = []) { if (!isset($this->charts[$symbol])) { $this->charts[$symbol] = []; @@ -1850,7 +1861,7 @@ public function candlesticks(string $symbol, string $interval = "5m", int $limit $request["endTime"] = $endTime; } - $response = $this->httpRequest("v1/klines", "GET", $request); + $response = $this->spotRequest("v1/klines", "GET", array_merge($request, $params)); if (is_array($response) === false) { return []; @@ -3101,24 +3112,24 @@ public function isOnTestnet() : bool * @return array containing the response * @throws \Exception */ - public function systemStatus() + public function systemStatus(array $params = []) { $arr = array(); - $api_status = $this->httpRequest("v3/ping", 'GET'); + $api_status = $this->spotRequest("v3/ping", 'GET', $params); if ( empty($api_status) ) { $arr['api']['status'] = 'ping ok'; } else { $arr['api']['status'] = $api_status; } - $fapi_status = $this->httpRequest("v1/ping", 'GET', [ 'fapi' => true ]); + $fapi_status = $this->futuresRequest("v1/ping", 'GET', $params); if ( empty($fapi_status) ) { $arr['fapi']['status'] = 'ping ok'; } else { $arr['fapi']['status'] = $fapi_status; } - $arr['sapi'] = $this->httpRequest("v1/system/status", 'GET', [ 'sapi' => true ]); + $arr['sapi'] = $this->spotWalletRequest("v1/system/status", 'GET', $params); return $arr; } @@ -3137,24 +3148,23 @@ public function systemStatus() * @return array containing the response * @throws \Exception */ - public function accountSnapshot($type, $nbrDays = 5, $startTime = 0, $endTime = 0) + public function accountSnapshot($type, $nbrDays = 5, $startTime = 0, $endTime = 0, array $params = []) { if ($nbrDays < 5 || $nbrDays > 30) $nbrDays = 5; - $params = [ - 'sapi' => true, + $request = [ 'type' => $type, ]; if ($startTime > 0) - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; if ($endTime > 0) - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; if ($nbrDays != 5) - $params['limit'] = $nbrDays; + $request['limit'] = $nbrDays; - return $this->httpRequest("v1/accountSnapshot", 'GET', $params, true); + return $this->spotWalletRequest("v1/accountSnapshot", 'GET', array_merge($request, $params), true); } /** @@ -3167,10 +3177,10 @@ public function accountSnapshot($type, $nbrDays = 5, $startTime = 0, $endTime = * @return array containing the response * @throws \Exception */ - public function accountStatus() + public function accountStatus(array $params = []) { $arr = array(); - $arr['sapi'] = $this->httpRequest("v1/account/status", 'GET', [ 'sapi' => true ], true); + $arr['sapi'] = $this->spotWalletRequest("v1/account/status", 'GET', $params, true); return $arr; } @@ -3184,9 +3194,9 @@ public function accountStatus() * @return array containing the response * @throws \Exception */ - public function apiRestrictions() + public function apiRestrictions(array $params = []) { - return $this->httpRequest("v1/account/apiRestrictions", 'GET', ['sapi' => true], true); + return $this->spotWalletRequest("v1/account/apiRestrictions", 'GET', $params, true); } /** @@ -3199,10 +3209,10 @@ public function apiRestrictions() * @return array containing the response * @throws \Exception */ - public function apiTradingStatus() + public function apiTradingStatus(array $params = []) { $arr = array(); - $arr['sapi'] = $this->httpRequest("v1/account/apiTradingStatus", 'GET', [ 'sapi' => true ], true); + $arr['sapi'] = $this->spotWalletRequest("v1/account/apiTradingStatus", 'GET', $params, true); return $arr; } @@ -3269,7 +3279,7 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp $request[$flag] = $params[$flag]; } - return $this->httpRequest("v3/order/oco", "POST", $request, true); + return $this->spotRequest("v3/order/oco", "POST", $request, true); } /** @@ -3284,9 +3294,12 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp * @return string with symbol price * @throws \Exception */ - public function avgPrice(string $symbol) + public function avgPrice(string $symbol, array $params = []) { - $ticker = $this->httpRequest("v3/avgPrice", "GET", ["symbol" => $symbol]); + $request = [ + 'symbol' => $symbol, + ]; + $ticker = $this->spotRequest("v3/avgPrice", "GET", array_merge($request, $params)); if (is_array($ticker) === false) { echo "Error: unable to fetch avg price" . PHP_EOL; $ticker = []; @@ -3319,15 +3332,14 @@ public function avgPrice(string $symbol) * @return array containing the response * @throws \Exception */ - public function bswapQuote($baseAsset, $quoteAsset, $quoteQty) { + public function bswapQuote($baseAsset, $quoteAsset, $quoteQty, array $params = []) { $request = [ - 'sapi' => true, 'quoteAsset' => $quoteAsset, 'baseAsset' => $baseAsset, 'quoteQty' => $quoteQty, ]; - return $this->httpRequest("v1/bswap/quote", 'GET', $request, true); + return $this->spotWalletRequest("v1/bswap/quote", 'GET', array_merge($request, $params), true); } /********************************************* @@ -3348,7 +3360,7 @@ public function bswapQuote($baseAsset, $quoteAsset, $quoteQty) { */ public function futuresTime() { - return $this->httpRequest("v1/time", "GET", [ 'fapi' => true ]); + return $this->futuresRequest("v1/time", "GET"); } /** @@ -3366,7 +3378,7 @@ public function futuresTime() public function futuresExchangeInfo() { if (!$this->futuresExchangeInfo) { - $arr = $this->httpRequest("v1/exchangeInfo", "GET", [ 'fapi' => true ]); + $arr = $this->futuresRequest("v1/exchangeInfo", "GET"); if ((is_array($arr) === false) || empty($arr)) { echo "Error: unable to fetch futures exchange info" . PHP_EOL; $arr = array(); @@ -4743,16 +4755,16 @@ public function futuresOrderAmendment(string $symbol, $orderId = null, $origClie */ public function futuresCancel(string $symbol, $orderid, $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, 'fapi' => true, ]; if ($orderid) { - $params['orderId'] = $orderid; + $request['orderId'] = $orderid; } else if (!isset($params['origClientOrderId'])) { throw new \Exception('futuresCancel: either orderId or origClientOrderId must be set'); } - return $this->httpRequest("v1/order", 'DELETE', array_merge($params, $params), true); + return $this->httpRequest("v1/order", 'DELETE', array_merge($request, $params), true); } /** From 203fdad783936c9d051af11d74f17d1ec4b87cc5 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:29:30 +0300 Subject: [PATCH 03/11] `order` and `depth` are fixed --- php-binance-api.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/php-binance-api.php b/php-binance-api.php index 9e5547e..c4cf0d6 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1300,7 +1300,7 @@ public function depth(string $symbol, int $limit = 100, array $params = []) "symbol" => $symbol, "limit" => $limit, ]; - $json = $this->spotRequest("v1/depth", "GET", array_merge($request, $params), true); + $json = $this->spotRequest("v1/depth", "GET", array_merge($request, $params)); if (is_array($json) === false) { echo "Error: unable to fetch depth" . PHP_EOL; $json = []; @@ -1799,6 +1799,8 @@ public function order(string $side, string $symbol, $quantity, $price, string $t if ($type === "MARKET" && isset($params['isQuoteOrder']) && $params['isQuoteOrder']) { unset($request['quantity']); + unset($params['quantity']); + unset($params['isQuoteOrder']); $request['quoteOrderQty'] = $quantity; } From a81fab386d78b66bcd0132342ef2e0fa0ae267ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Sun, 20 Apr 2025 11:47:44 +0300 Subject: [PATCH 04/11] removed from live tests --- php-binance-api.php | 63 ++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index c4cf0d6..1355737 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1448,24 +1448,27 @@ protected function curl_set_body($curl, $option, $query) { curl_setopt($curl, $option, $query); } - protected function spotRequest($url, $method = "GET", $params = [], $signed = false) + public function spotRequest($url, $method = "GET", $params = [], $signed = false) { return $this->httpRequest($url, $method, $params, $signed); } - protected function spotWalletRequest($url, $method = "GET", $params = [], $signed = false) + public function spotWalletRequest($url, $method = "GET", $params = [], $signed = false) { $params['sapi'] = true; return $this->httpRequest($url, $method, $params, $signed); } - protected function futuresRequest($url, $method = "GET", $params = [], $signed = false) + public function futuresRequest($url, $method = "GET", $params = [], $signed = false, $recvWindow = null) { $params['fapi'] = true; + if ($recvWindow) { + $params['recvWindow'] = $recvWindow; + } return $this->httpRequest($url, $method, $params, $signed); } - protected function fapiDataRequest($url, $method = "GET", $params = [], $signed = false) + public function fapiDataRequest($url, $method = "GET", $params = [], $signed = false) { $params['fapiData'] = true; return $this->httpRequest($url, $method, $params, $signed); @@ -3360,9 +3363,9 @@ public function bswapQuote($baseAsset, $quoteAsset, $quoteQty, array $params = [ * @return array with error message or array with server time key * @throws \Exception */ - public function futuresTime() + public function futuresTime(array $params = []) { - return $this->futuresRequest("v1/time", "GET"); + return $this->futuresRequest("v1/time", "GET", $params); } /** @@ -3377,10 +3380,10 @@ public function futuresTime() * @return array containing the response * @throws \Exception */ - public function futuresExchangeInfo() + public function futuresExchangeInfo(array $params = []) { if (!$this->futuresExchangeInfo) { - $arr = $this->futuresRequest("v1/exchangeInfo", "GET"); + $arr = $this->futuresRequest("v1/exchangeInfo", "GET", $params); if ((is_array($arr) === false) || empty($arr)) { echo "Error: unable to fetch futures exchange info" . PHP_EOL; $arr = array(); @@ -3415,21 +3418,20 @@ public function futuresExchangeInfo() * @return array with error message or array of market depth * @throws \Exception */ - public function futuresDepth(string $symbol, int $limit = null) + public function futuresDepth(string $symbol, int $limit = null, array $params = []) { if (isset($symbol) === false || is_string($symbol) === false) { // WPCS: XSS OK. echo "asset: expected bool false, " . gettype($symbol) . " given" . PHP_EOL; } - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($limit) { - $params['limit'] = $limit; + $request['limit'] = $limit; } - $json = $this->httpRequest("v1/depth", "GET", $params); + $json = $this->futuresRequest("v1/depth", "GET", array_merge($request, $params)); if (is_array($json) === false) { echo "Error: unable to fetch futures depth" . PHP_EOL; $json = []; @@ -3461,16 +3463,15 @@ public function futuresDepth(string $symbol, int $limit = null) * @return array containing the response * @throws \Exception */ - public function futuresRecentTrades(string $symbol, int $limit = null) + public function futuresRecentTrades(string $symbol, int $limit = null, array $params = []) { - $parameters = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($limit) { - $parameters['limit'] = $limit; + $request['limit'] = $limit; } - return $this->httpRequest("v1/trades", "GET", $parameters); + return $this->futuresRequest("v1/trades", "GET", array_merge($request, $params)); } /** @@ -3489,19 +3490,18 @@ public function futuresRecentTrades(string $symbol, int $limit = null) * @return array containing the response * @throws \Exception */ - public function futuresHistoricalTrades(string $symbol, int $limit = null, int $tradeId = null) + public function futuresHistoricalTrades(string $symbol, $limit = null, $tradeId = null, array $params = []) { - $parameters = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($limit) { - $parameters['limit'] = $limit; + $request['limit'] = $limit; } if ($tradeId) { - $parameters['fromId'] = $tradeId; + $request['fromId'] = $tradeId; } - return $this->httpRequest("v1/historicalTrades", "GET", $parameters, true); + return $this->futuresRequest("v1/historicalTrades", "GET", array_merge($request, $params), true); } /** @@ -3522,25 +3522,24 @@ public function futuresHistoricalTrades(string $symbol, int $limit = null, int $ * @return array with error message or array of market history * @throws \Exception */ - public function futuresAggTrades(string $symbol, int $fromId = null, int $startTime = null, int $endTime = null, int $limit = null) + public function futuresAggTrades(string $symbol, int $fromId = null, int $startTime = null, int $endTime = null, int $limit = null, array $params = []) { - $parameters = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($fromId) { - $parameters['fromId'] = $fromId; + $request['fromId'] = $fromId; } if ($startTime) { - $parameters['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $parameters['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($limit) { - $parameters['limit'] = $limit; + $request['limit'] = $limit; } - return $this->tradesData($this->httpRequest("v1/aggTrades", "GET", $parameters)); + return $this->tradesData($this->futuresRequest("v1/aggTrades", "GET", array_merge($request, $params))); } /** From f9d4b6990aff2ee1d23e31b85d570b6d9879859a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Sun, 20 Apr 2025 15:43:45 +0300 Subject: [PATCH 05/11] Futures endpoints updated with futuresRequest and params. recvWindow moved into params --- php-binance-api.php | 910 +++++++++++++---------------------- tests/BinanceLiveTests.php | 6 +- tests/BinanceStaticTests.php | 112 ++--- tests/updateMethods.js | 159 ++++++ 4 files changed, 563 insertions(+), 624 deletions(-) create mode 100644 tests/updateMethods.js diff --git a/php-binance-api.php b/php-binance-api.php index 1355737..6cdb923 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1073,7 +1073,7 @@ public function withdrawFee(string $asset, array $params = []) * @return array containing the response * @throws \Exception */ - public function transfer(string $type, string $asset, string $amount, $fromSymbol = null, $toSymbol = null, int $recvWindow = null, array $params = []) + public function transfer(string $type, string $asset, string $amount, $fromSymbol = null, $toSymbol = null, array $params = []) { $request = [ 'type' => $type, @@ -1087,9 +1087,7 @@ public function transfer(string $type, string $asset, string $amount, $fromSymbo if ($toSymbol) { $request['toSymbol'] = $toSymbol; } - if ($recvWindow) { - $request['recvWindow'] = $recvWindow; - } + return $this->spotWalletRequest("v1/asset/transfer", 'POST', array_merge($request, $params), true); } @@ -1113,7 +1111,7 @@ public function transfer(string $type, string $asset, string $amount, $fromSymbo * @return array containing the response * @throws \Exception */ - public function transfersHistory(string $type, $startTime = null, $endTime = null, $limit = null, $current = null, $fromSymbol = null, $toSymbol = null, $recvWindow = null, array $params = []) + public function transfersHistory(string $type, $startTime = null, $endTime = null, $limit = null, $current = null, $fromSymbol = null, $toSymbol = null, array $params = []) { $request = [ 'type' => $type, @@ -1137,9 +1135,7 @@ public function transfersHistory(string $type, $startTime = null, $endTime = nul if ($toSymbol) { $request['toSymbol'] = $toSymbol; } - if ($recvWindow) { - $request['recvWindow'] = $recvWindow; - } + return $this->spotWalletRequest("v1/asset/transfer", 'GET', array_merge($request, $params), true); } @@ -1322,13 +1318,14 @@ public function depth(string $symbol, int $limit = 100, array $params = []) * $balances = $api->balances(); * * @param string $market_type (optional) market type - "spot" or "futures" (default is "spot") - * @param int $recvWindow (optional) the time in milliseconds to wait for the transfer to complete (not for spot) + * @param array $params (optional) an array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the transfer to complete (not for spot) * @param string $api_version (optional) not for spot - the api version to use (default is v2) * * @return array with error message or array of balances * @throws \Exception */ - public function balances(string $market_type = 'spot', $recvWindow = null, string $api_version = 'v2', array $params = []) + public function balances(string $market_type = 'spot', array $params = [], string $api_version = 'v2') { $is_spot = $market_type === 'spot'; $request = []; @@ -1336,9 +1333,6 @@ public function balances(string $market_type = 'spot', $recvWindow = null, strin $url = "v3/account"; } else { $request['fapi'] = true; - if ($recvWindow) { - $request['recvWindow'] = $recvWindow; - } if ($api_version === 'v2') { $url = "v2/balance"; } else if ($api_version === 'v3') { @@ -1459,16 +1453,13 @@ public function spotWalletRequest($url, $method = "GET", $params = [], $signed = return $this->httpRequest($url, $method, $params, $signed); } - public function futuresRequest($url, $method = "GET", $params = [], $signed = false, $recvWindow = null) + public function futuresRequest($url, $method = "GET", $params = [], $signed = false) { $params['fapi'] = true; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } return $this->httpRequest($url, $method, $params, $signed); } - public function fapiDataRequest($url, $method = "GET", $params = [], $signed = false) + public function futuresDataRequest($url, $method = "GET", $params = [], $signed = false) { $params['fapiData'] = true; return $this->httpRequest($url, $method, $params, $signed); @@ -3565,9 +3556,9 @@ public function futuresAggTrades(string $symbol, int $fromId = null, int $startT * @return array containing the response * @throws \Exception */ - public function futuresCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'klines'); + return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'klines', null, $params); } /** @@ -3594,9 +3585,9 @@ public function futuresCandlesticks(string $symbol, string $interval = '5m', int * @return array containing the response * @throws \Exception */ - public function futuresContinuousCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, $contractType = 'PERPETUAL') + public function futuresContinuousCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, $contractType = 'PERPETUAL', array $params = []) { - return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'continuousKlines', $contractType); + return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'continuousKlines', $contractType, $params); } /** @@ -3622,9 +3613,9 @@ public function futuresContinuousCandlesticks(string $symbol, string $interval = * @return array containing the response * @throws \Exception */ - public function futuresIndexPriceCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresIndexPriceCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'indexPriceKlines'); + return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'indexPriceKlines', null, $params); } /** @@ -3650,9 +3641,9 @@ public function futuresIndexPriceCandlesticks(string $symbol, string $interval = * @return array containing the response * @throws \Exception */ - public function futuresMarkPriceCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresMarkPriceCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'markPriceKlines'); + return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'markPriceKlines', null, $params); } /** @@ -3678,16 +3669,16 @@ public function futuresMarkPriceCandlesticks(string $symbol, string $interval = * @return array containing the response * @throws \Exception */ - public function futuresPremiumIndexCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresPremiumIndexCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'premiumIndexKlines'); + return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'premiumIndexKlines', null, $params); } /** * futuresCandlesticksHelper * helper for routing the futuresCandlesticks, futuresContinuousCandlesticks, futuresIndexPriceCandlesticks, futuresMarkPriceCandlesticks and futuresPremiumIndexKlines */ - private function futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, $klineType, $contractType = null) + private function futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, $klineType, $contractType = null, $params = []) { if (!isset($this->charts['futures'])) { $this->charts['futures'] = []; @@ -3701,29 +3692,28 @@ private function futuresCandlesticksHelper($symbol, $interval, $limit, $startTim if (!isset($this->charts['futures'][$symbol][$contractType][$interval])) { $this->charts['futures'][$symbol][$contractType][$interval] = []; } - $params = [ + $request = [ 'interval' => $interval, - 'fapi' => true, ]; if ($klineType === 'continuousKlines' || $klineType === 'indexPriceKlines') { - $params['pair'] = $symbol; + $request['pair'] = $symbol; } else { - $params['symbol'] = $symbol; + $request['symbol'] = $symbol; } if ($limit) { - $params['limit'] = $limit; + $request['limit'] = $limit; } if ($startTime) { - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($contractType) { - $params['contractType'] = $contractType; + $request['contractType'] = $contractType; } - $response = $this->httpRequest("v1/{$klineType}", 'GET', $params); + $response = $this->futuresRequest("v1/{$klineType}", 'GET', array_merge($request, $params)); if (is_array($response) === false) { return []; @@ -3753,15 +3743,13 @@ private function futuresCandlesticksHelper($symbol, $interval, $limit, $startTim * @return array containing the response * @throws \Exception */ - public function futuresMarkPrice(string $symbol = null) + public function futuresMarkPrice(string $symbol = null, array $params = []) { - $parameters = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $parameters['symbol'] = $symbol; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/premiumIndex", "GET", $parameters); + return $this->futuresRequest("v1/premiumIndex", "GET", array_merge($request, $params)); } /** @@ -3780,24 +3768,22 @@ public function futuresMarkPrice(string $symbol = null) * @return array containing the response * @throws \Exception */ - public function futuresFundingRateHistory(string $symbol = null, int $limit = null, $startTime = null, $endTime = null) + public function futuresFundingRateHistory(string $symbol = null, int $limit = null, $startTime = null, $endTime = null, array $params = []) { - $parameters = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $parameters['symbol'] = $symbol; + $request['symbol'] = $symbol; } if ($limit) { - $parameters['limit'] = $limit; + $request['limit'] = $limit; } if ($startTime) { - $parameters['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $parameters['endTime'] = $endTime; + $request['endTime'] = $endTime; } - return $this->httpRequest("v1/fundingRate", "GET", $parameters); + return $this->futuresRequest("v1/fundingRate", "GET", array_merge($request, $params)); } /** @@ -3812,12 +3798,9 @@ public function futuresFundingRateHistory(string $symbol = null, int $limit = nu * @return array containing the response * @throws \Exception */ - public function futuresFundingInfo() + public function futuresFundingInfo(array $params = []) { - $parameters = [ - 'fapi' => true, - ]; - return $this->httpRequest("v1/fundingInfo", "GET", $parameters); + return $this->futuresRequest("v1/fundingInfo", "GET", $params); } /** @@ -3836,15 +3819,13 @@ public function futuresFundingInfo() * @return array containing the response * @throws \Exception */ - public function futuresPrevDay(string $symbol = null) + public function futuresPrevDay(string $symbol = null, array $params = []) { - $parameters = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $parameters['symbol'] = $symbol; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/ticker/24hr", "GET", $parameters); + return $this->futuresRequest("v1/ticker/24hr", "GET", array_merge($request, $params)); } /** @@ -3861,13 +3842,12 @@ public function futuresPrevDay(string $symbol = null) * @return array containing the response * @throws \Exception */ - public function futuresPrice(string $symbol) + public function futuresPrice(string $symbol, array $params = []) { - $parameters = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; - $ticker = $this->httpRequest("v1/ticker/price", "GET", $parameters); + $ticker = $this->futuresRequest("v1/ticker/price", "GET", array_merge($request, $params)); if (!isset($ticker['price'])) { echo "Error: unable to fetch futures price for $symbol" . PHP_EOL; return null; @@ -3887,12 +3867,9 @@ public function futuresPrice(string $symbol) * @return array containing the response * @throws \Exception */ - public function futuresPrices() + public function futuresPrices(array $params = []) { - $parameters = [ - 'fapi' => true, - ]; - return $this->priceData($this->httpRequest("v1/ticker/price", "GET", $parameters)); + return $this->priceData($this->futuresRequest("v1/ticker/price", "GET", $params)); } /** @@ -3909,13 +3886,12 @@ public function futuresPrices() * @return array containing the response * @throws \Exception */ - public function futuresPriceV2(string $symbol) + public function futuresPriceV2(string $symbol, array $params = []) { - $parameters = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; - $ticker = $this->httpRequest("v2/ticker/price", "GET", $parameters); + $ticker = $this->futuresRequest("v2/ticker/price", "GET", $request); if (!isset($ticker['price'])) { echo "Error: unable to fetch futures price for $symbol" . PHP_EOL; return null; @@ -3935,12 +3911,9 @@ public function futuresPriceV2(string $symbol) * @return array containing the response * @throws \Exception */ - public function futuresPricesV2() + public function futuresPricesV2(array $params = []) { - $parameters = [ - 'fapi' => true, - ]; - return $this->priceData($this->httpRequest("v2/ticker/price", "GET", $parameters)); + return $this->priceData($this->futuresRequest("v2/ticker/price", "GET", $params)); } /** @@ -3959,15 +3932,13 @@ public function futuresPricesV2() * @return array containing the response * @throws \Exception */ - public function futuresSymbolOrderBookTicker(string $symbol = null): array + public function futuresSymbolOrderBookTicker(string $symbol = null, array $params = []): array { - $parameters = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $parameters['symbol'] = $symbol; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/ticker/bookTicker", "GET", $parameters); + return $this->futuresRequest("v1/ticker/bookTicker", "GET", array_merge($request, $params)); } /** @@ -3982,14 +3953,13 @@ public function futuresSymbolOrderBookTicker(string $symbol = null): array * @return array containing the response * @throws \Exception */ - public function futuresDeliveryPrice(string $symbol): array + public function futuresDeliveryPrice(string $symbol, array $params = []): array { - $parameters = [ + $request = [ 'pair' => $symbol, - 'fapiData' => true, ]; - return $this->httpRequest("delivery-price", "GET", $parameters); + return $this->futuresDataRequest("delivery-price", "GET", array_merge($request, $params)); } /** @@ -4006,36 +3976,34 @@ public function futuresDeliveryPrice(string $symbol): array * @return array containing the response * @throws \Exception */ - public function futuresOpenInterest(string $symbol): array + public function futuresOpenInterest(string $symbol, array $params = []): array { - $parameters = [ + $request = [ 'symbol'=> $symbol, - 'fapi' => true, ]; - return $this->httpRequest("v1/openInterest", 'GET', $parameters); + return $this->futuresRequest("v1/openInterest", 'GET', array_merge($request, $params)); } /** - * symbolPeriodLimitStartEndRequest + * symbolPeriodLimitStartEndFuturesDataRequest * helper for routing GET methods that require symbol, period, limit, startTime and endTime */ - private function symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $startTime, $endTime, $url, $base = 'fapi', $contractType = null) + private function symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, $url, array $params = []) { - $parameters = [ + $request = [ 'symbol' => $symbol, 'period' => $period, ]; - $parameters[$base] = true; if ($limit) { - $parameters['limit'] = $limit; + $request['limit'] = $limit; } if ($startTime) { - $parameters['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $parameters['endTime'] = $endTime; + $request['endTime'] = $endTime; } - return $this->httpRequest($url, 'GET', $parameters); + return $this->futuresDataRequest($url, 'GET', array_merge($request, $params)); } /** @@ -4054,9 +4022,9 @@ private function symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $sta * @return array containing the response * @throws \Exception */ - public function futuresOpenInterestHistory(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresOpenInterestHistory(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $startTime, $endTime, 'openInterestHist', 'fapiData'); + return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'openInterestHist', $params); } /** @@ -4075,9 +4043,9 @@ public function futuresOpenInterestHistory(string $symbol, string $period = '5m' * @return array containing the response * @throws \Exception */ - public function futuresTopLongShortPositionRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresTopLongShortPositionRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortPositionRatio', 'fapiData'); + return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortPositionRatio', $params); } /** @@ -4096,9 +4064,9 @@ public function futuresTopLongShortPositionRatio(string $symbol, string $period * @return array containing the response * @throws \Exception */ - public function futuresTopLongShortAccountRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresTopLongShortAccountRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortAccountRatio', 'fapiData'); + return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortAccountRatio', $params); } /** @@ -4117,9 +4085,9 @@ public function futuresTopLongShortAccountRatio(string $symbol, string $period = * @return array containing the response * @throws \Exception */ - public function futuresGlobalLongShortAccountRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresGlobalLongShortAccountRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $startTime, $endTime, 'globalLongShortAccountRatio', 'fapiData'); + return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'globalLongShortAccountRatio', $params); } /** @@ -4138,11 +4106,12 @@ public function futuresGlobalLongShortAccountRatio(string $symbol, string $perio * @return array containing the response * @throws \Exception */ - public function futuresTakerLongShortRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null) + public function futuresTakerLongShortRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $startTime, $endTime, 'takerlongshortRatio', 'fapiData'); + return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'takerlongshortRatio', $params); } + /** * futuresBasis get future basis for symbol * @@ -4160,24 +4129,23 @@ public function futuresTakerLongShortRatio(string $symbol, string $period = '5m' * @return array containing the response * @throws \Exception */ - public function futuresBasis(string $symbol, string $period = '5m', int $limit = 30, $startTime = null, $endTime = null, $contractType = 'PERPETUAL') + public function futuresBasis(string $symbol, string $period = '5m', int $limit = 30, $startTime = null, $endTime = null, $contractType = 'PERPETUAL', array $params = []) { - $parameters = [ + $request = [ 'pair' => $symbol, 'period' => $period, 'contractType' => $contractType, - 'fapiData' => true, ]; if ($limit) { - $parameters['limit'] = $limit; + $request['limit'] = $limit; } if ($startTime) { - $parameters['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $parameters['endTime'] = $endTime; + $request['endTime'] = $endTime; } - return $this->httpRequest("basis", 'GET', $parameters); + return $this->futuresDataRequest("basis", 'GET', array_merge($request, $params)); } /** @@ -4195,13 +4163,12 @@ public function futuresBasis(string $symbol, string $period = '5m', int $limit = * @return array containing the response * @throws \Exception */ - public function futuresIndexInfo(string $symbol) + public function futuresIndexInfo(string $symbol, array $params = []) { - $parameters = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; - return $this->httpRequest("v1/indexInfo", 'GET', $parameters); + return $this->futuresRequest("v1/indexInfo", 'GET', array_merge($request, $params)); } /** @@ -4220,15 +4187,13 @@ public function futuresIndexInfo(string $symbol) * @return array containing the response * @throws \Exception */ - public function futuresAssetIndex(string $symbol = null) + public function futuresAssetIndex(string $symbol = null, array $params = []) { - $parameters = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $parameters['symbol'] = $symbol; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/assetIndex", 'GET', $parameters); + return $this->futuresRequest("v1/assetIndex", 'GET', array_merge($request, $params)); } /** @@ -4245,13 +4210,12 @@ public function futuresAssetIndex(string $symbol = null) * @return array containing the response * @throws \Exception */ - public function futuresConstituents(string $symbol) + public function futuresConstituents(string $symbol, array $params = []) { - $parameters = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; - return $this->httpRequest("v1/constituents", 'GET', $parameters); + return $this->futuresRequest("v1/constituents", 'GET', array_merge($request, $params)); } /** @@ -4299,14 +4263,6 @@ protected function createFuturesOrderRequest(string $side, string $symbol, $quan } } - if (isset($params['positionSide'])) { - $request['positionSide'] = $params['positionSide']; - } - - if (isset($params['timeInForce'])) { - $request['timeInForce'] = $params['timeInForce']; - } - if (isset($params['reduceOnly'])) { $reduceOnly = $params['reduceOnly']; if ($reduceOnly === true) { @@ -4314,18 +4270,13 @@ protected function createFuturesOrderRequest(string $side, string $symbol, $quan } else { $request['reduceOnly'] = 'false'; } + unset($params['reduceOnly']); } - if (isset($params['newClientOrderId'])) { - $request['newClientOrderId'] = $params['newClientOrderId']; - } else { + if (!isset($params['newClientOrderId'])) { $request['newClientOrderId'] = $this->generateFuturesClientOrderId(); } - if (isset($params['stopPrice'])) { - $request['stopPrice'] = $params['stopPrice']; - } - if (isset($params['closePosition'])) { $closePosition = $params['closePosition']; if ($closePosition === true) { @@ -4333,18 +4284,7 @@ protected function createFuturesOrderRequest(string $side, string $symbol, $quan } else { $request['closePosition'] = 'false'; } - } - - if (isset($params['activationPrice'])) { - $request['activationPrice'] = $params['activationPrice']; - } - - if (isset($params['callbackRate'])) { - $request['callbackRate'] = $params['callbackRate']; - } - - if (isset($params['workingType'])) { - $request['workingType'] = $params['workingType']; + unset($params['closePosition']); } if (isset($params['priceProtect'])) { @@ -4354,29 +4294,10 @@ protected function createFuturesOrderRequest(string $side, string $symbol, $quan } else { $request['priceProtect'] = 'FALSE'; } + unset($params['priceProtect']); } - if (isset($params['newOrderRespType'])) { - $request['newOrderRespType'] = $params['newOrderRespType']; - } - - if (isset($params['priceMatch'])) { - $request['priceMatch'] = $params['priceMatch']; - } - - if (isset($params['selfTradePreventionMode'])) { - $request['selfTradePreventionMode'] = $params['selfTradePreventionMode']; - } - - if (isset($params['goodTillDate'])) { - $request['goodTillDate'] = $params['goodTillDate']; - } - - if (isset($params['recvWindow'])) { - $request['recvWindow'] = $params['recvWindow']; - } - - return $request; + return array_merge($request, $params); } /** @@ -4418,9 +4339,8 @@ protected function createFuturesOrderRequest(string $side, string $symbol, $quan public function futuresOrder(string $side, string $symbol, $quantity = null, $price = null, string $type = 'LIMIT', array $params = [], $test = false) { $request = $this->createFuturesOrderRequest($side, $symbol, $quantity, $price, $type, $params); - $request['fapi'] = true; $qstring = ($test === false) ? 'v1/order' : 'v1/order/test'; - return $this->httpRequest($qstring, 'POST', $request, true); + return $this->futuresRequest($qstring, 'POST', $request, true); } /** @@ -4564,8 +4484,8 @@ protected function createBatchOrdersRequest(array $orders, bool $edit = false) if (!isset($order['price'])) { $order['price'] = null; } - if (!isset($order['flags'])) { - $order['flags'] = []; + if (!isset($order['params'])) { + $order['params'] = []; } if (!isset($order['type'])) { $order['type'] = 'LIMIT'; @@ -4576,7 +4496,7 @@ protected function createBatchOrdersRequest(array $orders, bool $edit = false) $order['quantity'], $order['price'], $order['type'], - $order['flags'] + $order['params'] ); if (isset($formatedOrder['recvWindow'])) { // remove recvWindow from the order @@ -4610,11 +4530,8 @@ protected function createBatchOrdersRequest(array $orders, bool $edit = false) * @return array containing the response or error message * @throws \Exception */ - public function futuresBatchOrders(array $orders, int $recvWindow = null) + public function futuresBatchOrders(array $orders, array $params = []) { - $params = [ - 'fapi' => true, - ]; $formatedOrders = $this->createBatchOrdersRequest($orders); if (count($formatedOrders) > 5) { throw new \Exception('futuresBatchOrders: max 5 orders allowed'); @@ -4622,13 +4539,12 @@ public function futuresBatchOrders(array $orders, int $recvWindow = null) if (count($formatedOrders) < 1) { throw new \Exception('futuresBatchOrders: at least 1 order required'); } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } + $request = []; + // current endpoint accepts orders list as a json string in the query string $encodedOrders = json_encode($formatedOrders); $url = 'v1/batchOrders?batchOrders=' . $encodedOrders; - return $this->httpRequest($url, 'POST', $params, true); + return $this->futuresRequest($url, 'POST', array_merge($request, $params), true); } /** @@ -4664,8 +4580,7 @@ public function futuresEditOrder(string $symbol, string $side, string $quantity, } unset($request['type']); unset($request['newClientOrderId']); - $request['fapi'] = true; - return $this->httpRequest("v1/order", 'PUT', $request, true); + return $this->futuresRequest("v1/order", 'PUT', $request, true); } /** @@ -4680,18 +4595,14 @@ public function futuresEditOrder(string $symbol, string $side, string $quantity, * @return array containing the response or error message * @throws \Exception */ - public function futuresEditOrders(array $orders, $recvWindow = null) + public function futuresEditOrders(array $orders, array $params = []) { - $params = [ - 'fapi' => true, - ]; $formatedOrders = $this->createBatchOrdersRequest($orders, true); - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } + $request = []; + // current endpoint accepts orders list as a json string in the query string - $params['batchOrders'] = json_encode($formatedOrders); - return $this->httpRequest("v1/batchOrders", 'PUT', $params, true); + $request['batchOrders'] = json_encode($formatedOrders); + return $this->futuresRequest("v1/batchOrders", 'PUT', array_merge($request, $params), true); } /** @@ -4712,31 +4623,28 @@ public function futuresEditOrders(array $orders, $recvWindow = null) * @return array containing the response * @throws \Exception */ - public function futuresOrderAmendment(string $symbol, $orderId = null, $origClientOrderId = null, $startTime = null, $endTime = null, $limit = null, int $recvWindow = null) + public function futuresOrderAmendment(string $symbol, $orderId = null, $origClientOrderId = null, $startTime = null, $endTime = null, $limit = null, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($orderId) { - $params['orderId'] = $orderId; + $request['orderId'] = $orderId; } if ($origClientOrderId) { - $params['origClientOrderId'] = $origClientOrderId; + $request['origClientOrderId'] = $origClientOrderId; } if ($startTime) { - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($limit) { - $params['limit'] = $limit; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['limit'] = $limit; } - return $this->httpRequest("v1/orderAmendment", 'GET', $params, true); + + return $this->futuresRequest("v1/orderAmendment", 'GET', array_merge($request, $params), true); } /** @@ -4758,14 +4666,13 @@ public function futuresCancel(string $symbol, $orderid, $params = []) { $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($orderid) { $request['orderId'] = $orderid; } else if (!isset($params['origClientOrderId'])) { throw new \Exception('futuresCancel: either orderId or origClientOrderId must be set'); } - return $this->httpRequest("v1/order", 'DELETE', array_merge($request, $params), true); + return $this->futuresRequest("v1/order", 'DELETE', array_merge($request, $params), true); } /** @@ -4782,26 +4689,23 @@ public function futuresCancel(string $symbol, $orderid, $params = []) * @return array with error message or the orders details * @throws \Exception */ - public function futuresCancelBatchOrders(string $symbol, $orderIdList = null, $origClientOrderIdList = null, int $recvWindow = null) + public function futuresCancelBatchOrders(string $symbol, $orderIdList = null, $origClientOrderIdList = null, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($orderIdList) { $idsString = json_encode($orderIdList); // remove quotes and spaces - $params['orderIdList'] = str_replace(' ', '', str_replace('"', '', str_replace("'", '', $idsString))); + $request['orderIdList'] = str_replace(' ', '', str_replace('"', '', str_replace("'", '', $idsString))); } else if ($origClientOrderIdList) { // remove spaces between the ids - $params['origClientOrderIdList'] = str_replace(', ', ',', json_encode($origClientOrderIdList)); + $request['origClientOrderIdList'] = str_replace(', ', ',', json_encode($origClientOrderIdList)); } else { throw new \Exception('futuresCancelBatchOrders: either orderIdList or origClientOrderIdList must be set'); } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/batchOrders", 'DELETE', $params, true); + + return $this->futuresRequest("v1/batchOrders", 'DELETE', array_merge($request, $params), true); } /** @@ -4817,16 +4721,13 @@ public function futuresCancelBatchOrders(string $symbol, $orderIdList = null, $o * @return array with error message or the orders details * @throws \Exception */ - public function futuresCancelOpenOrders(string $symbol, int $recvWindow = null) + public function futuresCancelOpenOrders(string $symbol, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/allOpenOrders", 'DELETE', $params, true); + + return $this->futuresRequest("v1/allOpenOrders", 'DELETE', array_merge($request, $params), true); } /** @@ -4843,17 +4744,14 @@ public function futuresCancelOpenOrders(string $symbol, int $recvWindow = null) * @return array with error message or the orders details * @throws \Exception */ - public function futuresCountdownCancelAllOrders(string $symbol, int $countdownTime, int $recvWindow = null) + public function futuresCountdownCancelAllOrders(string $symbol, int $countdownTime, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, 'countdownTime' => $countdownTime, ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/countdownCancelAll", 'POST', $params, true); + + return $this->futuresRequest("v1/countdownCancelAll", 'POST', array_merge($request, $params), true); } /** @@ -4871,23 +4769,20 @@ public function futuresCountdownCancelAllOrders(string $symbol, int $countdownTi * @return array with error message or the order details * @throws \Exception */ - public function futuresOrderStatus(string $symbol, $orderId = null, $origClientOrderId = null, int $recvWindow = null) + public function futuresOrderStatus(string $symbol, $orderId = null, $origClientOrderId = null, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($orderId) { - $params['orderId'] = $orderId; + $request['orderId'] = $orderId; } else if ($origClientOrderId) { - $params['origClientOrderId'] = $origClientOrderId; + $request['origClientOrderId'] = $origClientOrderId; } else { throw new \Exception('futuresOrderStatus: either orderId or origClientOrderId must be set'); } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/order", 'GET', $params, true); + + return $this->futuresRequest("v1/order", 'GET', array_merge($request, $params), true); } /** @@ -4905,28 +4800,25 @@ public function futuresOrderStatus(string $symbol, $orderId = null, $origClientO * @param string $orderId (optional) order id to get the response from (if is set it will get orders >= that orderId) * @param int $recvWindow (optional) the time in milliseconds to wait for a response */ - public function futuresAllOrders(string $symbol, $startTime = null, $endTime = null, $limit = null, $orderId = null, int $recvWindow = null) + public function futuresAllOrders(string $symbol, $startTime = null, $endTime = null, $limit = null, $orderId = null, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($startTime) { - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($limit) { - $params['limit'] = $limit; + $request['limit'] = $limit; } if ($orderId) { - $params['orderId'] = $orderId; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['orderId'] = $orderId; } - return $this->httpRequest("v1/allOrders", 'GET', $params, true); + + return $this->futuresRequest("v1/allOrders", 'GET', array_merge($request, $params), true); } /** @@ -4943,18 +4835,14 @@ public function futuresAllOrders(string $symbol, $startTime = null, $endTime = n * @return array with error message or the orders details * @throws \Exception */ - public function futuresOpenOrders($symbol = null, int $recvWindow = null) + public function futuresOpenOrders($symbol = null, array $params = []) { - $params = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $params['symbol'] = $symbol; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/openOrders", 'GET', $params, true); + + return $this->futuresRequest("v1/openOrders", 'GET', array_merge($request, $params), true); } /** @@ -4972,23 +4860,20 @@ public function futuresOpenOrders($symbol = null, int $recvWindow = null) * @return array with error message or the order details * @throws \Exception */ - public function futuresOpenOrder(string $symbol, $orderId = null, $origClientOrderId = null, int $recvWindow = null) + public function futuresOpenOrder(string $symbol, $orderId = null, $origClientOrderId = null, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($orderId) { - $params['orderId'] = $orderId; + $request['orderId'] = $orderId; } else if ($origClientOrderId) { - $params['origClientOrderId'] = $origClientOrderId; + $request['origClientOrderId'] = $origClientOrderId; } else { throw new \Exception('futuresOpenOrder: either orderId or origClientOrderId must be set'); } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/openOrder", 'GET', $params, true); + + return $this->futuresRequest("v1/openOrder", 'GET', array_merge($request, $params), true); } /** * futuresForceOrders gets all futures force orders @@ -5010,30 +4895,26 @@ public function futuresOpenOrder(string $symbol, $orderId = null, $origClientOrd * @return array with error message or the orders details * @throws \Exception */ - public function futuresForceOrders($symbol = null, $startTime = null, $endTime = null, $limit = null, $autoCloseType = null, $recvWindow = null) + public function futuresForceOrders($symbol = null, $startTime = null, $endTime = null, $limit = null, $autoCloseType = null, array $params = []) { - $params = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $params['symbol'] = $symbol; + $request['symbol'] = $symbol; } if ($startTime) { - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($limit) { - $params['limit'] = $limit; + $request['limit'] = $limit; } if ($autoCloseType) { - $params['autoCloseType'] = $autoCloseType; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['autoCloseType'] = $autoCloseType; } - return $this->httpRequest("v1/forceOrders", 'GET', $params, true); + + return $this->futuresRequest("v1/forceOrders", 'GET', array_merge($request, $params), true); } /** @@ -5056,31 +4937,28 @@ public function futuresForceOrders($symbol = null, $startTime = null, $endTime = * @return array with error message or the trades details * @throws \Exception */ - public function futuresMyTrades(string $symbol, $startTime = null, $endTime = null, $limit = null, $orderId = null, $fromId = null, int $recvWindow = null) + public function futuresMyTrades(string $symbol, $startTime = null, $endTime = null, $limit = null, $orderId = null, $fromId = null, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($startTime) { - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($limit) { - $params['limit'] = $limit; + $request['limit'] = $limit; } if ($orderId) { - $params['orderId'] = $orderId; + $request['orderId'] = $orderId; } if ($fromId) { - $params['fromId'] = $fromId; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['fromId'] = $fromId; } - return $this->httpRequest("v1/userTrades", 'GET', $params, true); + + return $this->futuresRequest("v1/userTrades", 'GET', array_merge($request, $params), true); } /** @@ -5088,9 +4966,9 @@ public function futuresMyTrades(string $symbol, $startTime = null, $endTime = nu * another name for futuresMyTrades (for naming compatibility with spot) * @deprecated */ - public function futuresHistory(string $symbol, $startTime = null, $endTime = null, $limit = null, $orderId = null, $fromId = null, int $recvWindow = null) + public function futuresHistory(string $symbol, $startTime = null, $endTime = null, $limit = null, $orderId = null, $fromId = null, array $params = []) { - return $this->futuresMyTrades($symbol, $startTime, $endTime, $limit, $orderId, $fromId, $recvWindow); + return $this->futuresMyTrades($symbol, $startTime, $endTime, $limit, $orderId, $fromId, $params); } /** @@ -5109,17 +4987,14 @@ public function futuresHistory(string $symbol, $startTime = null, $endTime = nul * @return array containing the response * @throws \Exception */ - public function futuresSetMarginMode(string $symbol, string $marginType, int $recvWindow = null) + public function futuresSetMarginMode(string $symbol, string $marginType, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, 'marginType' => $marginType, ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/marginType", 'POST', $params, true); + + return $this->futuresRequest("v1/marginType", 'POST', array_merge($request, $params), true); } /** @@ -5136,15 +5011,9 @@ public function futuresSetMarginMode(string $symbol, string $marginType, int $re * @return array containing the response * @throws \Exception */ - public function futuresPositionMode(int $recvWindow = null) + public function futuresPositionMode(array $params = []) { - $params = [ - 'fapi' => true, - ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/positionSide/dual", 'GET', $params, true); + return $this->futuresRequest("v1/positionSide/dual", 'GET', $params, true); } /** @@ -5162,16 +5031,13 @@ public function futuresPositionMode(int $recvWindow = null) * @return array containing the response * @throws \Exception */ - public function futuresSetPositionMode(bool $dualSidePosition, int $recvWindow = null) + public function futuresSetPositionMode(bool $dualSidePosition, array $params = []) { - $params = [ - 'fapi' => true, + $request = [ 'dualSidePosition' => $dualSidePosition ? 'true' : 'false', ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/positionSide/dual", 'POST', $params, true); + + return $this->futuresRequest("v1/positionSide/dual", 'POST', array_merge($request, $params), true); } /** @@ -5191,17 +5057,15 @@ public function futuresSetPositionMode(bool $dualSidePosition, int $recvWindow = * @return array containing the response * @throws \Exception */ - public function futuresSetLeverage(int $leverage, string $symbol, int $recvWindow = null) + public function futuresSetLeverage(int $leverage, string $symbol, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, 'fapi' => true, 'leverage' => $leverage, ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/leverage", 'POST', $params, true); + + return $this->futuresRequest("v1/leverage", 'POST', array_merge($request, $params), true); } /** @@ -5218,15 +5082,9 @@ public function futuresSetLeverage(int $leverage, string $symbol, int $recvWindo * @return array containing the response * @throws \Exception */ - public function futuresMultiAssetsMarginMode(int $recvWindow = null) + public function futuresMultiAssetsMarginMode(array $params = []) { - $params = [ - 'fapi' => true, - ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/multiAssetsMargin", 'GET', $params, true); + return $this->futuresRequest("v1/multiAssetsMargin", 'GET', $params, true); } /** @@ -5244,16 +5102,13 @@ public function futuresMultiAssetsMarginMode(int $recvWindow = null) * @return array containing the response * @throws \Exception */ - public function futuresSetMultiAssetsMarginMode(bool $multiAssetsMarginMode, int $recvWindow = null) + public function futuresSetMultiAssetsMarginMode(bool $multiAssetsMarginMode, array $params = []) { - $params = [ - 'fapi' => true, + $request = [ 'multiAssetsMarginMode' => $multiAssetsMarginMode ? 'true' : 'false', ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/multiAssetsMarginMode", 'POST', $params, true); + + return $this->futuresRequest("v1/multiAssetsMarginMode", 'POST', array_merge($request, $params), true); } /** @@ -5264,21 +5119,18 @@ public function futuresSetMultiAssetsMarginMode(bool $multiAssetsMarginMode, int * @return array containing the response * @throws \Exception */ - protected function modifyMarginHelper(string $symbol, string $amount, $addOrReduce, $positionSide = null, int $recvWindow = null) + protected function modifyMarginHelper(string $symbol, string $amount, $addOrReduce, $positionSide = null, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, 'amount' => $amount, 'type' => $addOrReduce, ]; if ($positionSide) { - $params['positionSide'] = $positionSide; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['positionSide'] = $positionSide; } - return $this->httpRequest("v1/positionMargin", 'POST', $params, true); + + return $this->futuresRequest("v1/positionMargin", 'POST', array_merge($request, $params), true); } /** @@ -5298,9 +5150,9 @@ protected function modifyMarginHelper(string $symbol, string $amount, $addOrRedu * @return array containing the response * @throws \Exception */ - public function futuresAddMargin(string $symbol, string $amount, $positionSide = null, int $recvWindow = null) + public function futuresAddMargin(string $symbol, string $amount, $positionSide = null, array $params = []) { - return $this->modifyMarginHelper($symbol, $amount, 1, $positionSide, $recvWindow); + return $this->modifyMarginHelper($symbol, $amount, 1, $positionSide, $params); } /** @@ -5320,9 +5172,9 @@ public function futuresAddMargin(string $symbol, string $amount, $positionSide = * @return array containing the response * @throws \Exception */ - public function futuresReduceMargin(string $symbol, string $amount, $positionSide = null, int $recvWindow = null) + public function futuresReduceMargin(string $symbol, string $amount, $positionSide = null, array $params = []) { - return $this->modifyMarginHelper($symbol, $amount, 2, $positionSide, $recvWindow); + return $this->modifyMarginHelper($symbol, $amount, 2, $positionSide, $params); } /** @@ -5336,44 +5188,41 @@ public function futuresReduceMargin(string $symbol, string $amount, $positionSid * @property int $weight 5 * * @param string $symbol (optional) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) an array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * @param string $api_version (optional) API version, "v2" or "v3" (default is v3) * * @return array with error message or the position details * @throws \Exception */ - public function futuresPositions($symbol = null, $recvWindow = null, $api_version = 'v3') + public function futuresPositions($symbol = null, array $params = [], string $api_version = 'v3') { - $params = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $params['symbol'] = $symbol; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['symbol'] = $symbol; } + if ($api_version !== 'v2' && $api_version !== 'v3') { throw new \Exception('futuresPositions: api_version must be either v2 or v3'); } - return $this->httpRequest($api_version . "/positionRisk", 'GET', $params, true); + return $this->futuresRequest($api_version . "/positionRisk", 'GET', array_merge($request, $params), true); } /** futuresPositionsV2 * @see futuresPositions */ - public function futuresPositionsV2($symbol = null, int $recvWindow = null) + public function futuresPositionsV2($symbol = null, array $params = []) { - return $this->futuresPositions($symbol, $recvWindow, 'v2'); + return $this->futuresPositions($symbol, $params, 'v2'); } /** * futuresPositionsV3 * @see futuresPositions */ - public function futuresPositionsV3($symbol = null, int $recvWindow = null) + public function futuresPositionsV3($symbol = null, array $params = []) { - return $this->futuresPositions($symbol, $recvWindow, 'v3'); + return $this->futuresPositions($symbol, $params, 'v3'); } /** @@ -5386,33 +5235,34 @@ public function futuresPositionsV3($symbol = null, int $recvWindow = null) * @property int $weight 5 * * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) an array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * @param string $api_version (optional) API version, "v2" or "v3" (default is v3) * * @return array with error message or the position details * @throws \Exception */ - public function futuresPosition(string $symbol, $recvWindow = null, string $api_version = 'v3') + public function futuresPosition(string $symbol, array $params = [], string $api_version = 'v3') { - return $this->futuresPositions($symbol, $recvWindow, $api_version); + return $this->futuresPositions($symbol, $params, $api_version); } /** * futuresPositionV2 * @see futuresPosition */ - public function futuresPositionV2(string $symbol, int $recvWindow = null) + public function futuresPositionV2(string $symbol, array $params = []) { - return $this->futuresPositionsV2($symbol, $recvWindow, 'v2'); + return $this->futuresPositionsV2($symbol, $params, 'v2'); } /** * futuresPositionV3 * @see futuresPosition */ - public function futuresPositionV3(string $symbol, int $recvWindow = null) + public function futuresPositionV3(string $symbol, array $params = []) { - return $this->futuresPositionsV3($symbol, $recvWindow, 'v3'); + return $this->futuresPositionsV3($symbol, $params, 'v3'); } /** @@ -5430,18 +5280,16 @@ public function futuresPositionV3(string $symbol, int $recvWindow = null) * @return array with error message or the ADL quantile details * @throws \Exception */ - public function futuresAdlQuantile($symbol = null, int $recvWindow = null) + public function futuresAdlQuantile($symbol = null, array $params = []) { - $params = [ + $request = [ 'fapi' => true, ]; if ($symbol) { - $params['symbol'] = $symbol; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/adlQuantile", 'GET', $params, true); + + return $this->futuresRequest("v1/adlQuantile", 'GET', array_merge($request, $params), true); } /** @@ -5460,30 +5308,29 @@ public function futuresAdlQuantile($symbol = null, int $recvWindow = null) * @param string $addOrReduce (optional) "ADD" or "REDUCE" to filter the history * @param int $recvWindow (optional) the time in milliseconds to wait for a response */ - public function futuresPositionMarginChangeHistory(string $symbol, $startTime = null, $endTime = null, $limit = null, $addOrReduce = null, int $recvWindow = null) + public function futuresPositionMarginChangeHistory(string $symbol, $startTime = null, $endTime = null, $limit = null, $addOrReduce = null, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; if ($startTime) { - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($limit) { - $params['limit'] = $limit; + $request['limit'] = $limit; } if ($addOrReduce) { if (is_numeric($addOrReduce)) { - $params['addOrReduce'] = $addOrReduce; + $request['addOrReduce'] = $addOrReduce; } else if (is_string($addOrReduce)) { $addOrReduce = strtoupper($addOrReduce); if ($addOrReduce === 'ADD' || $addOrReduce === '1') { - $params['addOrReduce'] = 1; + $request['addOrReduce'] = 1; } else if ($addOrReduce === 'REDUCE' || $addOrReduce === '2') { - $params['addOrReduce'] = 2; + $request['addOrReduce'] = 2; } else { throw new \Exception('futuresPositionMarginChangeHistory: addOrReduce must be "ADD" or "REDUCE" or 1 or 2'); } @@ -5491,10 +5338,8 @@ public function futuresPositionMarginChangeHistory(string $symbol, $startTime = throw new \Exception('futuresPositionMarginChangeHistory: addOrReduce must be "ADD" or "REDUCE" or 1 or 2'); } } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/positionMargin/history", 'GET', $params, true); + + return $this->futuresRequest("v1/positionMargin/history", 'GET', array_merge($request, $params), true); } /** @@ -5506,36 +5351,37 @@ public function futuresPositionMarginChangeHistory(string $symbol, $startTime = * * @property int $weight 5 * - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) an array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * @param string $api_version (optional) API version, "v2" or "v3" (default is v3) * * @return array with error message or the balance details * @throws \Exception */ - public function futuresBalances($recvWindow = null, string $api_version = 'v3') + public function futuresBalances(array $params = [], string $api_version = 'v3') { if ($api_version !== 'v2' && $api_version !== 'v3') { throw new \Exception('futuresBalances: api_version must be either v2 or v3'); } - return $this->balances('futures', $recvWindow, 'v3'); + return $this->balances('futures', $params, 'v3'); } /** * futuresBalancesV2 * see futuresBalances */ - public function futuresBalancesV2(int $recvWindow = null) + public function futuresBalancesV2(array $params = []) { - return $this->futuresBalances($recvWindow, 'v2'); + return $this->futuresBalances($params, 'v2'); } /** * futuresBalancesV3 * see futuresBalances */ - public function futuresBalancesV3(int $recvWindow = null) + public function futuresBalancesV3(array $params = []) { - return $this->futuresBalances($recvWindow, 'v3'); + return $this->futuresBalances($params, 'v3'); } /** @@ -5548,42 +5394,38 @@ public function futuresBalancesV3(int $recvWindow = null) * * @property int $weight 5 * - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) an array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * @param string $api_version (optional) API version, "v2" or "v3" (default is v3) * * @return array with error message or array of all the account information * @throws \Exception */ - public function futuresAccount($recvWindow = null, string $api_version = 'v3') + public function futuresAccount(array $params = [], string $api_version = 'v3') { if ($api_version !== 'v2' && $api_version !== 'v3') { throw new \Exception('futuresAccount: api_version must be either v2 or v3'); } - $params = [ - 'fapi' => true, - ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest($api_version . "/account", "GET", $params, true); + + return $this->futuresRequest($api_version . "/account", "GET", $params, true); } /** * futuresAccountV2 * see futuresAccount */ - public function futuresAccountV2(int $recvWindow = null) + public function futuresAccountV2(array $params = []) { - return $this->futuresAccount($recvWindow, 'v2'); + return $this->futuresAccount($params, 'v2'); } /** * futuresAccountV3 * see futuresAccount */ - public function futuresAccountV3(int $recvWindow = null) + public function futuresAccountV3(array $params = []) { - return $this->futuresAccount($recvWindow, 'v3'); + return $this->futuresAccount($params, 'v3'); } /** @@ -5601,16 +5443,13 @@ public function futuresAccountV3(int $recvWindow = null) * @return array with error message or the trade fee details * @throws \Exception */ - public function futuresTradeFee(string $symbol, int $recvWindow = null) + public function futuresTradeFee(string $symbol, array $params = []) { - $params = [ + $request = [ 'symbol' => $symbol, - 'fapi' => true, ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/commissionRate", 'GET', $params, true); + + return $this->futuresRequest("v1/commissionRate", 'GET', array_merge($request, $params), true); } /** @@ -5627,15 +5466,9 @@ public function futuresTradeFee(string $symbol, int $recvWindow = null) * @return array with error message or the account configuration details * @throws \Exception */ - public function futuresAccountConfig(int $recvWindow = null) + public function futuresAccountConfig(array $params = []) { - $params = [ - 'fapi' => true, - ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/accountConfig", 'GET', $params, true); + return $this->futuresRequest("v1/accountConfig", 'GET', $params, true); } /** @@ -5654,18 +5487,14 @@ public function futuresAccountConfig(int $recvWindow = null) * @return array with error message or the margin mode details * @throws \Exception */ - public function futuresMarginModes($symbol = null, int $recvWindow = null) + public function futuresMarginModes($symbol = null, array $params = []) { - $params = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $params['symbol'] = $symbol; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/symbolConfig", 'GET', $params, true); + + return $this->futuresRequest("v1/symbolConfig", 'GET', array_merge($request, $params), true); } /** @@ -5682,15 +5511,9 @@ public function futuresMarginModes($symbol = null, int $recvWindow = null) * @return array with error message or the rate limit details * @throws \Exception */ - public function futuresOrderRateLimit(int $recvWindow = null) + public function futuresOrderRateLimit(array $params = []) { - $params = [ - 'fapi' => true, - ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/rateLimit/order", 'GET', $params, true); + return $this->futuresRequest("v1/rateLimit/order", 'GET', $params, true); } /** @@ -5709,18 +5532,14 @@ public function futuresOrderRateLimit(int $recvWindow = null) * @return array with error message or the leverage details * @throws \Exception */ - public function futuresLeverages($symbol = null, int $recvWindow = null) + public function futuresLeverages($symbol = null, array $params = []) { - $params = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $params['symbol'] = $symbol; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/leverageBracket", 'GET', $params, true); + + return $this->futuresRequest("v1/leverageBracket", 'GET', array_merge($request, $params), true); } /** @@ -5768,33 +5587,29 @@ public function futuresLeverages($symbol = null, int $recvWindow = null) * @return array with error message or the income details * @throws \Exception */ - public function futuresLedger($symbol = null, $incomeType = null, $startTime = null, $endTime = null, $limit = null, $page = null, int $recvWindow = null) + public function futuresLedger($symbol = null, $incomeType = null, $startTime = null, $endTime = null, $limit = null, $page = null, array $params = []) { - $params = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $params['symbol'] = $symbol; + $request['symbol'] = $symbol; } if ($incomeType) { - $params['incomeType'] = $incomeType; + $request['incomeType'] = $incomeType; } if ($startTime) { - $params['startTime'] = $startTime; + $request['startTime'] = $startTime; } if ($endTime) { - $params['endTime'] = $endTime; + $request['endTime'] = $endTime; } if ($limit) { - $params['limit'] = $limit; + $request['limit'] = $limit; } if ($page) { - $params['page'] = $page; + $request['page'] = $page; } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/income", 'GET', $params, true); + + return $this->futuresRequest("v1/income", 'GET', array_merge($request, $params), true); } /** @@ -5813,51 +5628,42 @@ public function futuresLedger($symbol = null, $incomeType = null, $startTime = n * @return array with error message or the trading status details * @throws \Exception */ - public function futuresTradingStatus($symbol = null, int $recvWindow = null) + public function futuresTradingStatus($symbol = null, array $params = []) { - $params = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { - $params['symbol'] = $symbol; - } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; + $request['symbol'] = $symbol; } - return $this->httpRequest("v1/apiTradingStatus", 'GET', $params, true); + + return $this->futuresRequest("v1/apiTradingStatus", 'GET', array_merge($request, $params), true); } /** * futuresDownloadId * helper for other metods for getting download id */ - protected function futuresDownloadId($startTime, $endTime, $recvWindow = null, string $url = '') + protected function futuresDownloadId($startTime, $endTime, array $params = null, string $url = '') { - $params = [ + $request = [ 'fapi' => true, 'startTime' => $startTime, 'endTime' => $endTime, ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest($url, 'GET', $params, true); + + return $this->futuresRequest($url, 'GET', array_merge($request, $params), true); } /** * futuresDownloadLinkByDownloadId * helper for other metods for getting download link by download id */ - protected function futuresDownloadLinkByDownloadId(string $downloadId, $recvWindow = null, string $url = '') + protected function futuresDownloadLinkByDownloadId(string $downloadId, array $params = null, string $url = '') { - $params = [ - 'fapi' => true, + $request = [ 'downloadId' => $downloadId, ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest($url, 'GET', $params, true); + + return $this->futuresRequest($url, 'GET', array_merge($request, $params), true); } /** @@ -5878,9 +5684,9 @@ protected function futuresDownloadLinkByDownloadId(string $downloadId, $recvWind * @return array with error message or the response * @throws \Exception */ - public function futuresDownloadIdForTransactions(int $startTime, int $endTime, int $recvWindow = null) + public function futuresDownloadIdForTransactions(int $startTime, int $endTime, array $params = []) { - return $this->futuresDownloadId($startTime, $endTime, $recvWindow, "v1/income/asyn"); + return $this->futuresDownloadId($startTime, $endTime, $params, "v1/income/asyn"); } /** @@ -5899,9 +5705,9 @@ public function futuresDownloadIdForTransactions(int $startTime, int $endTime, i * @return array with error message or the download link * @throws \Exception */ - public function futuresDownloadTransactionsByDownloadId(string $downloadId, int $recvWindow = null) + public function futuresDownloadTransactionsByDownloadId(string $downloadId, array $params = []) { - return $this->futuresDownloadLinkByDownloadId($downloadId, $recvWindow, "v1/income/asyn/id"); + return $this->futuresDownloadLinkByDownloadId($downloadId, $params, "v1/income/asyn/id"); } /** @@ -5922,9 +5728,9 @@ public function futuresDownloadTransactionsByDownloadId(string $downloadId, int * @return array with error message or the response * @throws \Exception */ - public function futuresDownloadIdForOrders(int $startTime, int $endTime, int $recvWindow = null) + public function futuresDownloadIdForOrders(int $startTime, int $endTime, array $params = []) { - return $this->futuresDownloadId($startTime, $endTime, $recvWindow, "v1/order/asyn"); + return $this->futuresDownloadId($startTime, $endTime, $params, "v1/order/asyn"); } /** @@ -5943,9 +5749,9 @@ public function futuresDownloadIdForOrders(int $startTime, int $endTime, int $re * @return array with error message or the download link * @throws \Exception */ - public function futuresDownloadOrdersByDownloadId(string $downloadId, int $recvWindow = null) + public function futuresDownloadOrdersByDownloadId(string $downloadId, array $params = []) { - return $this->futuresDownloadLinkByDownloadId($downloadId, $recvWindow, "v1/order/asyn/id"); + return $this->futuresDownloadLinkByDownloadId($downloadId, $params, "v1/order/asyn/id"); } /** @@ -5966,9 +5772,9 @@ public function futuresDownloadOrdersByDownloadId(string $downloadId, int $recvW * @return array with error message or the response * @throws \Exception */ - public function futuresDownloadIdForTrades(int $startTime, int $endTime, int $recvWindow = null) + public function futuresDownloadIdForTrades(int $startTime, int $endTime, array $params = []) { - return $this->futuresDownloadId($startTime, $endTime, $recvWindow, "v1/trade/asyn"); + return $this->futuresDownloadId($startTime, $endTime, $params, "v1/trade/asyn"); } /** @@ -5987,9 +5793,9 @@ public function futuresDownloadIdForTrades(int $startTime, int $endTime, int $re * @return array with error message or the download link * @throws \Exception */ - public function futuresDownloadTradesByDownloadId(string $downloadId, int $recvWindow = null) + public function futuresDownloadTradesByDownloadId(string $downloadId, array $params = []) { - return $this->futuresDownloadLinkByDownloadId($downloadId, $recvWindow, "v1/trade/asyn/id"); + return $this->futuresDownloadLinkByDownloadId($downloadId, $params, "v1/trade/asyn/id"); } /** @@ -6007,16 +5813,13 @@ public function futuresDownloadTradesByDownloadId(string $downloadId, int $recvW * @return array containing the response * @throws \Exception */ - public function futuresFeeBurn(bool $flag, int $recvWindow = null) + public function futuresFeeBurn(bool $flag, array $params = []) { - $params = [ - 'fapi' => true, + $request = [ 'feeBurn' => $flag ? 'true' : 'false', ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/feeBurn", 'POST', $params, true); + + return $this->futuresRequest("v1/feeBurn", 'POST', array_merge($request, $params), true); } /** @@ -6033,15 +5836,9 @@ public function futuresFeeBurn(bool $flag, int $recvWindow = null) * @return array containing the response * @throws \Exception */ - public function futuresFeeBurnStatus(int $recvWindow = null) + public function futuresFeeBurnStatus(array $params = []) { - $params = [ - 'fapi' => true, - ]; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/feeBurn", 'GET', $params, true); + return $this->futuresRequest("v1/feeBurn", 'GET', $params, true); } /** @@ -6060,18 +5857,16 @@ public function futuresFeeBurnStatus(int $recvWindow = null) * @return array containing the response * @throws \Exception */ - public function convertExchangeInfo($fromAsset = null, $toAsset = null) + public function convertExchangeInfo($fromAsset = null, $toAsset = null, array $params = []) { - $params = [ - 'fapi' => true, - ]; + $request = []; if ($fromAsset) { - $params['fromAsset'] = $fromAsset; + $request['fromAsset'] = $fromAsset; } if ($toAsset) { - $params['toAsset'] = $toAsset; + $request['toAsset'] = $toAsset; } - return $this->httpRequest("v1/convert/exchangeInfo", 'GET', $params); + return $this->futuresRequest("v1/convert/exchangeInfo", 'GET', array_merge($request, $params)); } /** @@ -6093,27 +5888,24 @@ public function convertExchangeInfo($fromAsset = null, $toAsset = null) * @return array containing the response * @throws \Exception */ - public function convertSend(string $fromAsset, string $toAsset, $fromAmount = null, $toAmount = null, $validTime = null, int $recvWindow = null) + public function convertSend(string $fromAsset, string $toAsset, $fromAmount = null, $toAmount = null, $validTime = null, array $params = []) { - $params = [ - 'fapi' => true, + $request = [ 'fromAsset' => $fromAsset, 'toAsset' => $toAsset, ]; if ($fromAmount) { - $params['fromAmount'] = $fromAmount; + $request['fromAmount'] = $fromAmount; } else if ($toAmount) { - $params['toAmount'] = $toAmount; + $request['toAmount'] = $toAmount; } else { throw new \Exception('convertSendRequest: fromAmount or toAmount must be set'); } if ($validTime) { - $params['validTime'] = $validTime; + $request['validTime'] = $validTime; } - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest("v1/convert/getQuote", 'POST', $params, true); + + return $this->futuresRequest("v1/convert/getQuote", 'POST', array_merge($request, $params), true); } /** @@ -6132,24 +5924,12 @@ public function convertSend(string $fromAsset, string $toAsset, $fromAmount = nu * @return array containing the response * @throws \Exception */ - public function convertAccept(string $quoteId, int $recvWindow = null, array $params = []) + public function convertAccept(string $quoteId, array $params = []) { $request = [ 'quoteId' => $quoteId, ]; - return $this->fapiRequest("v1/convert/acceptQuote", 'POST', array_merge($request, $params), true, $recvWindow); - } - - /** - * fapiRequest helper for creating a fapi httpRequest - */ - protected function fapiRequest(string $url, string $method, array $params = [], $signed = false, int $recvWindow = null) - { - $params['fapi'] = true; - if ($recvWindow) { - $params['recvWindow'] = $recvWindow; - } - return $this->httpRequest($url, $method, $params, $signed); + return $this->futuresRequest("v1/convert/acceptQuote", 'POST', array_merge($request, $params), true); } /** @@ -6167,18 +5947,18 @@ protected function fapiRequest(string $url, string $method, array $params = [], * @return array containing the response * @throws \Exception */ - public function convertStatus($orderId = null, $quoteId = null) + public function convertStatus($orderId = null, $quoteId = null, array $params = []) { - $params = [ + $request = [ 'fapi' => true, ]; if ($orderId) { - $params['orderId'] = $orderId; + $request['orderId'] = $orderId; } else if ($quoteId) { - $params['quoteId'] = $quoteId; + $request['quoteId'] = $quoteId; } else { throw new \Exception('convertStatus: orderId or quoteId must be set'); } - return $this->httpRequest("v1/convert/orderStatus", 'GET', $params, true); + return $this->futuresRequest("v1/convert/orderStatus", 'GET', array_merge($request, $params), true); } } diff --git a/tests/BinanceLiveTests.php b/tests/BinanceLiveTests.php index 6325284..a412c2e 100644 --- a/tests/BinanceLiveTests.php +++ b/tests/BinanceLiveTests.php @@ -1017,7 +1017,7 @@ public function testPositionV3Futures() public function testAdlQuantileFutures() { - $res = $this->futuresBinance->futuresAdlQuantile($this->symbol, $this->recvWindow); + $res = $this->futuresBinance->futuresAdlQuantile($this->symbol); $this->assertIsArray($res); $this->assertEquals($this->symbol, $res['symbol']); $this->assertArrayHasKey('adlQuantile', $res); @@ -1175,7 +1175,7 @@ public function testAccountFutures() public function testAccountV2Futures() { - $res = $this->futuresBinance->futuresAccountV2($this->recvWindow); + $res = $this->futuresBinance->futuresAccountV2(); $this->assertIsArray($res); $this->assertArrayHasKey('totalInitialMargin', $res); $this->assertIsNumeric($res['totalInitialMargin']); @@ -1207,7 +1207,7 @@ public function testAccountV2Futures() public function testAccountV3Futures() { - $res = $this->futuresBinance->futuresAccountV3($this->recvWindow); + $res = $this->futuresBinance->futuresAccountV3(); $this->assertIsArray($res); $this->assertArrayHasKey('totalInitialMargin', $res); $this->assertIsNumeric($res['totalInitialMargin']); diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index d2ab4d6..8cb3997 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -687,7 +687,7 @@ public function testWithdrawFee() public function testTransfer() { try { - $this->binance->transfer($this->type, $this->asset, $this->amount, $this->fromSymbol, $this->toSymbol, $this->recvWindow); + $this->binance->transfer($this->type, $this->asset, $this->amount, $this->fromSymbol, $this->toSymbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -707,7 +707,7 @@ public function testTransfer() public function testTransfersHistory() { try { - $this->binance->transfersHistory($this->type, $this->startTime, $this->endTime, $this->limit, $this->current, $this->fromSymbol, $this->toSymbol, $this->recvWindow); + $this->binance->transfersHistory($this->type, $this->startTime, $this->endTime, $this->limit, $this->current, $this->fromSymbol, $this->toSymbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -889,7 +889,7 @@ public function testSpotBalances() public function testFuturesBalances() { try { - $this->binance->balances('futures', $this->recvWindow); + $this->binance->balances('futures', [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -907,7 +907,7 @@ public function testFuturesBalances() public function testFuturesBalancesV3() { try { - $this->binance->balances('futures', $this->recvWindow, 'v3'); + $this->binance->balances('futures', [ 'recvWindow' => $this->recvWindow ], 'v3'); } catch (\Throwable $e) { @@ -1798,7 +1798,7 @@ public function testFuturesBatchOrders() ]; try { - $this->binance->futuresBatchOrders([ $order ], $this->recvWindow); + $this->binance->futuresBatchOrders([ $order ], [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -1855,7 +1855,7 @@ public function testFuturesEditOrders() ]; try { - $this->binance->futuresEditOrders([ $order ], $this->recvWindow); + $this->binance->futuresEditOrders([ $order ], [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -1878,7 +1878,7 @@ public function testFuturesEditOrders() public function testFuturesOrderAmendment() { try { - $this->binance->futuresOrderAmendment($this->symbol, $this->orderId, $this->origClientOrderId, $this->startTime, $this->endTime, $this->limit, $this->recvWindow); + $this->binance->futuresOrderAmendment($this->symbol, $this->orderId, $this->origClientOrderId, $this->startTime, $this->endTime, $this->limit, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -1921,7 +1921,7 @@ public function testFuturesCancel() public function testFuturesCancelBatchOrdersByOrderIds() { try { - $this->binance->futuresCancelBatchOrders($this->symbol, $this->orderIdList, null, $this->recvWindow); + $this->binance->futuresCancelBatchOrders($this->symbol, $this->orderIdList, null, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -1940,7 +1940,7 @@ public function testFuturesCancelBatchOrdersByOrderIds() public function testFuturesCancelBatchOrdersByClientOrderIds() { try { - $this->binance->futuresCancelBatchOrders($this->symbol, null, $this->origClientOrderIdList, $this->recvWindow); + $this->binance->futuresCancelBatchOrders($this->symbol, null, $this->origClientOrderIdList, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -1959,7 +1959,7 @@ public function testFuturesCancelBatchOrdersByClientOrderIds() public function testFuturesCancelOpenOrders() { try { - $this->binance->futuresCancelOpenOrders($this->symbol, $this->recvWindow); + $this->binance->futuresCancelOpenOrders($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -1978,7 +1978,7 @@ public function testFuturesCancelOpenOrders() public function testFuturesCountdownCancelAllOrders() { try { - $this->binance->futuresCountdownCancelAllOrders($this->symbol, $this->countdownTime, $this->recvWindow); + $this->binance->futuresCountdownCancelAllOrders($this->symbol, $this->countdownTime, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -1995,7 +1995,7 @@ public function testFuturesCountdownCancelAllOrders() public function testFuturesOrderStatusByOrderId() { try { - $this->binance->futuresOrderStatus($this->symbol, $this->orderId, null, $this->recvWindow); + $this->binance->futuresOrderStatus($this->symbol, $this->orderId, null, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2015,7 +2015,7 @@ public function testFuturesOrderStatusByOrderId() public function testFuturesOrderStatusByClientOrderId() { try { - $this->binance->futuresOrderStatus($this->symbol, null, $this->origClientOrderId, $this->recvWindow); + $this->binance->futuresOrderStatus($this->symbol, null, $this->origClientOrderId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2035,7 +2035,7 @@ public function testFuturesOrderStatusByClientOrderId() public function testFuturesAllOrders() { try { - $this->binance->futuresAllOrders($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, $this->recvWindow); + $this->binance->futuresAllOrders($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2058,7 +2058,7 @@ public function testFuturesAllOrders() public function testFuturesOpenOrders() { try { - $this->binance->futuresOpenOrders($this->symbol, $this->recvWindow); + $this->binance->futuresOpenOrders($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2077,7 +2077,7 @@ public function testFuturesOpenOrders() public function testFuturesOpenOrderByOrderId() { try { - $this->binance->futuresOpenOrder($this->symbol, $this->orderId, null, $this->recvWindow); + $this->binance->futuresOpenOrder($this->symbol, $this->orderId, null, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2097,7 +2097,7 @@ public function testFuturesOpenOrderByOrderId() public function testFuturesOpenOrderByClientOrderId() { try { - $this->binance->futuresOpenOrder($this->symbol, null, $this->origClientOrderId, $this->recvWindow); + $this->binance->futuresOpenOrder($this->symbol, null, $this->origClientOrderId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2117,7 +2117,7 @@ public function testFuturesOpenOrderByClientOrderId() public function testFuturesForceOrders() { try { - $this->binance->futuresForceOrders($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->autoCloseType, $this->recvWindow); + $this->binance->futuresForceOrders($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->autoCloseType, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2140,7 +2140,7 @@ public function testFuturesForceOrders() public function testFuturesMyTrades() { try { - $this->binance->futuresMyTrades($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, $this->fromId, $this->recvWindow); + $this->binance->futuresMyTrades($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, $this->fromId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2163,7 +2163,7 @@ public function testFuturesMyTrades() public function testFuturesHistory() { try { - $this->binance->futuresHistory($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, $this->fromId, $this->recvWindow); + $this->binance->futuresHistory($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, $this->fromId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2186,7 +2186,7 @@ public function testFuturesHistory() public function testFuturesSetMarginMode() { try { - $this->binance->futuresSetMarginMode($this->symbol, $this->marginType, $this->recvWindow); + $this->binance->futuresSetMarginMode($this->symbol, $this->marginType, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2203,7 +2203,7 @@ public function testFuturesSetMarginMode() public function testFuturesPositionMode() { try { - $this->binance->futuresPositionMode($this->recvWindow); + $this->binance->futuresPositionMode([ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2219,7 +2219,7 @@ public function testFuturesPositionMode() public function testFuturesSetPositionMode() { try { - $this->binance->futuresSetPositionMode($this->dualSidePosition, $this->recvWindow); + $this->binance->futuresSetPositionMode($this->dualSidePosition, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2235,7 +2235,7 @@ public function testFuturesSetPositionMode() public function testFuturesSetLeverage() { try { - $this->binance->futuresSetLeverage($this->leverage, $this->symbol, $this->recvWindow); + $this->binance->futuresSetLeverage($this->leverage, $this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2252,7 +2252,7 @@ public function testFuturesSetLeverage() public function testFuturesMultiAssetsMarginMode() { try { - $this->binance->futuresMultiAssetsMarginMode($this->recvWindow); + $this->binance->futuresMultiAssetsMarginMode([ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2275,7 +2275,7 @@ public function testFuturesMultiAssetsMarginMode() public function testFuturesSetMultiAssetsMarginMode() { try { - $this->binance->futuresSetMultiAssetsMarginMode($this->multiAssetsMarginMode, $this->recvWindow); + $this->binance->futuresSetMultiAssetsMarginMode($this->multiAssetsMarginMode, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2291,7 +2291,7 @@ public function testFuturesSetMultiAssetsMarginMode() public function testFuturesAddMargin() { try { - $this->binance->futuresAddMargin($this->symbol, $this->amount, $this->positionSide, $this->recvWindow); + $this->binance->futuresAddMargin($this->symbol, $this->amount, $this->positionSide, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2311,7 +2311,7 @@ public function testFuturesAddMargin() public function testFuturesReduceMargin() { try { - $this->binance->futuresReduceMargin($this->symbol, $this->amount, $this->positionSide, $this->recvWindow); + $this->binance->futuresReduceMargin($this->symbol, $this->amount, $this->positionSide, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2331,7 +2331,7 @@ public function testFuturesReduceMargin() public function testFuturesPositions() { try { - $this->binance->futuresPositions($this->symbol, $this->recvWindow); + $this->binance->futuresPositions($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2349,7 +2349,7 @@ public function testFuturesPositions() public function testFuturesPositionsV2() { try { - $this->binance->futuresPositionsV2($this->symbol, $this->recvWindow); + $this->binance->futuresPositionsV2($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2367,7 +2367,7 @@ public function testFuturesPositionsV2() public function testFuturesPositionsV3() { try { - $this->binance->futuresPositionsV3($this->symbol, $this->recvWindow); + $this->binance->futuresPositionsV3($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2385,7 +2385,7 @@ public function testFuturesPositionsV3() public function testFuturesPosition() { try { - $this->binance->futuresPosition($this->symbol, $this->recvWindow); + $this->binance->futuresPosition($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2403,7 +2403,7 @@ public function testFuturesPosition() public function testFuturesPositionV2() { try { - $this->binance->futuresPositionV2($this->symbol, $this->recvWindow); + $this->binance->futuresPositionV2($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2421,7 +2421,7 @@ public function testFuturesPositionV2() public function testFuturesPositionV3() { try { - $this->binance->futuresPositionV3($this->symbol, $this->recvWindow); + $this->binance->futuresPositionV3($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2439,7 +2439,7 @@ public function testFuturesPositionV3() public function testFuturesAdlQuantile() { try { - $this->binance->futuresAdlQuantile($this->symbol, $this->recvWindow); + $this->binance->futuresAdlQuantile($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2457,7 +2457,7 @@ public function testFuturesAdlQuantile() public function testFuturesPositionMarginChangeHistory() { try { - $this->binance->futuresPositionMarginChangeHistory($this->symbol, $this->startTime, $this->endTime, $this->limit, 'ADD', $this->recvWindow); + $this->binance->futuresPositionMarginChangeHistory($this->symbol, $this->startTime, $this->endTime, $this->limit, 'ADD', [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2479,7 +2479,7 @@ public function testFuturesPositionMarginChangeHistory() public function testFuturesAccount() { try { - $this->binance->futuresAccount($this->recvWindow); + $this->binance->futuresAccount([ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2496,7 +2496,7 @@ public function testFuturesAccount() public function testFuturesAccountV2() { try { - $this->binance->futuresAccountV2($this->recvWindow); + $this->binance->futuresAccountV2([ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2513,7 +2513,7 @@ public function testFuturesAccountV2() public function testFuturesAccountV3() { try { - $this->binance->futuresAccountV3($this->recvWindow); + $this->binance->futuresAccountV3([ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2530,7 +2530,7 @@ public function testFuturesAccountV3() public function testFuturesTradeFee() { try { - $this->binance->futuresTradeFee($this->symbol, $this->recvWindow); + $this->binance->futuresTradeFee($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2548,7 +2548,7 @@ public function testFuturesTradeFee() public function testFuturesAccountConfig() { try { - $this->binance->futuresAccountConfig($this->recvWindow); + $this->binance->futuresAccountConfig([ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2565,7 +2565,7 @@ public function testFuturesAccountConfig() public function testFuturesMarginModes() { try { - $this->binance->futuresMarginModes($this->symbol, $this->recvWindow); + $this->binance->futuresMarginModes($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2583,7 +2583,7 @@ public function testFuturesMarginModes() public function testFuturesOrderRateLimit() { try { - $this->binance->futuresOrderRateLimit($this->recvWindow); + $this->binance->futuresOrderRateLimit([ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2600,7 +2600,7 @@ public function testFuturesOrderRateLimit() public function testFuturesLeverages() { try { - $this->binance->futuresLeverages($this->symbol, $this->recvWindow); + $this->binance->futuresLeverages($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2618,7 +2618,7 @@ public function testFuturesLeverages() public function testFuturesLedger() { try { - $this->binance->futuresLedger($this->symbol, $this->incomeType, $this->startTime, $this->endTime, $this->limit, $this->page, $this->recvWindow); + $this->binance->futuresLedger($this->symbol, $this->incomeType, $this->startTime, $this->endTime, $this->limit, $this->page, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2641,7 +2641,7 @@ public function testFuturesLedger() public function testFuturesTradingStatus() { try { - $this->binance->futuresTradingStatus($this->symbol, $this->recvWindow); + $this->binance->futuresTradingStatus($this->symbol, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2659,7 +2659,7 @@ public function testFuturesTradingStatus() public function testFuturesDownloadIdForTransactions() { try { - $this->binance->futuresDownloadIdForTransactions($this->startTime, $this->endTime, $this->recvWindow); + $this->binance->futuresDownloadIdForTransactions($this->startTime, $this->endTime, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2678,7 +2678,7 @@ public function testFuturesDownloadIdForTransactions() public function testFuturesDownloadTransactionsByDownloadId() { try { - $this->binance->futuresDownloadTransactionsByDownloadId($this->downloadId, $this->recvWindow); + $this->binance->futuresDownloadTransactionsByDownloadId($this->downloadId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2696,7 +2696,7 @@ public function testFuturesDownloadTransactionsByDownloadId() public function testFuturesDownloadIdForOrders() { try { - $this->binance->futuresDownloadIdForOrders($this->startTime, $this->endTime, $this->recvWindow); + $this->binance->futuresDownloadIdForOrders($this->startTime, $this->endTime, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2715,7 +2715,7 @@ public function testFuturesDownloadIdForOrders() public function testFuturesDownloadOrdersByDownloadId() { try { - $this->binance->futuresDownloadOrdersByDownloadId($this->downloadId, $this->recvWindow); + $this->binance->futuresDownloadOrdersByDownloadId($this->downloadId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2733,7 +2733,7 @@ public function testFuturesDownloadOrdersByDownloadId() public function testFuturesDownloadIdForTrades() { try { - $this->binance->futuresDownloadIdForTrades($this->startTime, $this->endTime, $this->recvWindow); + $this->binance->futuresDownloadIdForTrades($this->startTime, $this->endTime, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2752,7 +2752,7 @@ public function testFuturesDownloadIdForTrades() public function testFuturesDownloadTradesByDownloadId() { try { - $this->binance->futuresDownloadTradesByDownloadId($this->downloadId, $this->recvWindow); + $this->binance->futuresDownloadTradesByDownloadId($this->downloadId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2770,7 +2770,7 @@ public function testFuturesDownloadTradesByDownloadId() public function testFuturesFeeBurn() { try { - $this->binance->futuresFeeBurn(true, $this->recvWindow); + $this->binance->futuresFeeBurn(true, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2786,7 +2786,7 @@ public function testFuturesFeeBurn() public function testFuturesFeeBurnStatus() { try { - $this->binance->futuresFeeBurnStatus($this->recvWindow); + $this->binance->futuresFeeBurnStatus([ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2821,7 +2821,7 @@ public function testConvertExchangeInfo() public function testConvertSend() { try { - $this->binance->convertSend($this->fromAsset, $this->toAsset, $this->fromAmount, null, $this->validTime, $this->recvWindow); + $this->binance->convertSend($this->fromAsset, $this->toAsset, $this->fromAmount, null, $this->validTime, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { @@ -2840,7 +2840,7 @@ public function testConvertSend() public function testConvertAccept() { try { - $this->binance->convertAccept($this->quoteId, $this->recvWindow); + $this->binance->convertAccept($this->quoteId, [ 'recvWindow' => $this->recvWindow ]); } catch (\Throwable $e) { diff --git a/tests/updateMethods.js b/tests/updateMethods.js new file mode 100644 index 0000000..cb964cb --- /dev/null +++ b/tests/updateMethods.js @@ -0,0 +1,159 @@ +const source = './php-binance-api.php' +const dest = './generatedMethods.txt' +const fs = require('fs') +const path = require('path') + +const fapiUrl = 'https://fapi.binance.com/fapi/' +const spotUrl = 'https://api.binance.com/api/' + +const methodTemplate = /public function (\w+)\((.*?)\)/ + +function getMethodNameAndParams (signature = '') { + const match = signature.match(methodTemplate) + const methodName = match[1] + const params = [] + const rawParams = match[2].split(',') + for (const rawParam of rawParams) { + const splitted = rawParam.split('=') + const defaultValue = splitted[1] ? splitted[1].trim() : undefined + const param = splitted[0].trim() + const typeTemlate = /(\w+)\s+\$(\w+)/ + const typeMatch = param.match(typeTemlate) + let type = undefined; + let name = undefined; + if (typeMatch) { + type = typeMatch[1] + name = typeMatch[2] + } else { + name = param.replace(/\$/g, '').trim() + } + if (name && name !== 'flags') { + params.push({ + name, + type, + defaultValue + }) + } + } + return { + methodName, + params + } +} + + +function extractMethods(filePath) { + const fileContent = fs.readFileSync(filePath, 'utf-8') + const lines = fileContent.split('\n') + const methods = [] + for (let i = 0; i < lines.length; i++) { + const line = lines[i].trim() + if (line.startsWith('public function') && line.includes('(')) { + const method = getMethodNameAndParams(line) + for (let j = i + 1; j < lines.length; j++) { + const followingLine = lines[j].trim() + const httpMatch = followingLine.match(/this->(httpRequest)\(('|")([^'"]+)('|"), ('|")([^'"]+)/) + if (httpMatch) { + const url = httpMatch[3] + const baseUrl = method.methodName.includes('futures') ? fapiUrl : spotUrl + const methodType = httpMatch[6] + method.type = methodType + method.url = baseUrl + url + i = j + break + } else if (followingLine.startsWith('public function')) { + i = j - 1 + break + } + } + methods.push(method) + } + } + return methods +} + +function writeStaticTestForMethod (method) { + const methodName = method.methodName + let result = 'public function test' + `${methodName.charAt(0).toUpperCase() + methodName.slice(1)}` + '()\n{\n ' + const methodCall = writeMethodCall(method) + result += writeTryCatch(methodCall) + result += writeUrlCheck(method) + result += writeParamsCheck(method.params) + result += '}\n' + console.log (method) + return result +} + +function writeMethodCall (method) { + const methodName = method.methodName + const params = method.params + let paramStings = [] + for (const param of params) { + const string = `$this->${param.name}` + paramStings.push(string) + } + return `$this->binance->${methodName}(${paramStings.join(', ')});\n` +} + +function writeTryCatch (methodCall) { + return `try {\n ${methodCall}\n } catch (\\Throwable $e) {\n\n }\n` +} + +function writeUrlCheck (method) { + let url = method.url ? method.url : 'ADD_URL_HERE' + if (method.type === 'POST' || method.params.length === 0) { + return ` $this->assertEquals("${url}", self::$capturedUrl);\n` + } else { + let lines = ' $query = http_build_query([\n' + const params = method.params + for (const param of params) { + const paramName = param.name + lines += ` '${paramName}' => $this->${paramName},\n` + } + lines += ' ]);\n' + lines += ` $endpoint = "${url}?" . $query;\n` + lines += ` $this->assertEquals($endpoint, self::$capturedUrl);\n` + lines += ` $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint));\n` + return lines + } +} + +function writeParamsCheck (params = []) { + let result = '' + if (params.length > 0) { + result += '\n parse_str(self::$capturedBody, $params);\n\n' + for (const param of params) { + const paramName = param.name + result += ` $this->assertEquals($this->${paramName}, $params['${paramName}']);\n` + } + } + return result +} + +function getUniqueParams (methods) { + const uniqueParams = [] + for (const method of methods) { + for (const param of method.params) { + let fullName = `${param.name}` + if (param.type) { + fullName += ` type: ${param.type}` + } + if (param.defaultValue) { + fullName += ` default: ${param.defaultValue}` + } + uniqueParams.push(fullName) + } + } + return new Set(uniqueParams) +} + +(() => { + const methods = extractMethods(source) + const testCases = [] + for (const method of methods) { + const testCase = writeStaticTestForMethod(method) + testCases.push(testCase) + } + fs.writeFileSync(dest, testCases.join('\n')) + console.log(`Generated test cases for ${methods.length} methods.`) +})() \ No newline at end of file From 7dae91d6ece6ce8dcf6a99e73dd5b45ff69787f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Sun, 20 Apr 2025 16:01:55 +0300 Subject: [PATCH 06/11] Some docstrings updated --- php-binance-api.php | 136 ++++++++++++++++++++++++++++---------------- 1 file changed, 86 insertions(+), 50 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 6cdb923..2bcdff2 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1068,7 +1068,8 @@ public function withdrawFee(string $asset, array $params = []) * @param string $amount (mandatory) the amount to transfer * @param string $fromSymbol (optional) must be sent when type are ISOLATEDMARGIN_MARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN * @param string $toSymbol (optional) must be sent when type are MARGIN_ISOLATEDMARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN - * @param int $recvWindow (optional) the time in milliseconds to wait for the transfer to complete + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -1106,7 +1107,8 @@ public function transfer(string $type, string $asset, string $amount, $fromSymbo * @param int $current (optional) default 1 * @param string $fromSymbol (optional) must be sent when type are ISOLATEDMARGIN_MARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN * @param string $toSymbol (optional) must be sent when type are MARGIN_ISOLATEDMARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN - * @param int $recvWindow (optional) the time in milliseconds to wait for the transfer to complete + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -4468,7 +4470,7 @@ public function futuresSellTest(string $symbol, $quantity = null, $price = null, * createBatchOrdersRequest * helper for creating the request for multiple futures orders * @param array $orders (mandatory) array of orders to be placed - * objects in the array should contain literally the same keys as the @see futuresOrder but without the recvWindow + * objects in the array should contain literally the same keys as the @see futuresOrder but without the $params[recvWindow] * * @return array containing the request * @throws \Exception @@ -4525,7 +4527,8 @@ protected function createBatchOrdersRequest(array $orders, bool $edit = false) * * @param array $orders (mandatory) array of orders to be placed * objects in the array should contain literally the same keys as the @see futuresOrder but without the $params['recvWindow'] - * @param string $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response or error message * @throws \Exception @@ -4590,7 +4593,8 @@ public function futuresEditOrder(string $symbol, string $side, string $quantity, * * @param array $orders (mandatory) array of orders to be modified * objects in the array should contain literally the same keys as the @see futuresEditOrder but without the $params['recvWindow'] - * @param string $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response or error message * @throws \Exception @@ -4618,7 +4622,8 @@ public function futuresEditOrders(array $orders, array $params = []) * @param int $startTime (optional) timestamp in ms to get modification history from INCLUSIVE * @param int $endTime (optional) timestamp in ms to get modification history until INCLUSIVE * @param int $limit (optional) limit the amount of open interest history (default 50, max 100) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -4684,7 +4689,8 @@ public function futuresCancel(string $symbol, $orderid, $params = []) * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) * @param array $orderIdList (optional) list of ids to cancel (mandatory if origClientOrderIdList is not set) * @param array $origClientOrderIdList (optional) list of client order ids to cancel (mandatory if orderIdList is not set) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the orders details * @throws \Exception @@ -4739,7 +4745,8 @@ public function futuresCancelOpenOrders(string $symbol, array $params = []) * * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) * @param int $countdownTime (mandatory) countdown in milliseconds (0 to stop the timer) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the orders details * @throws \Exception @@ -4764,7 +4771,8 @@ public function futuresCountdownCancelAllOrders(string $symbol, int $countdownTi * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) * @param string $orderId (optional) order id to get the response for (mandatory if origClientOrderId is not set) * @param string $origClientOrderId (optional) original client order id to get the response for (mandatory if orderId is not set) - * @param string $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the order details * @throws \Exception @@ -4798,7 +4806,11 @@ public function futuresOrderStatus(string $symbol, $orderId = null, $origClientO * @param int $endTime (optional) timestamp in ms to get orders until INCLUSIVE * @param int $limit (optional) limit the amount of orders (default 500, max 1000) * @param string $orderId (optional) order id to get the response from (if is set it will get orders >= that orderId) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response + * + * @return array with error message or the orders details + * @throws \Exception */ public function futuresAllOrders(string $symbol, $startTime = null, $endTime = null, $limit = null, $orderId = null, array $params = []) { @@ -4830,7 +4842,8 @@ public function futuresAllOrders(string $symbol, $startTime = null, $endTime = n * $orders = $api->futuresOpenOrders("BNBBTC"); * * @param string $symbol (optional) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the orders details * @throws \Exception @@ -4855,7 +4868,8 @@ public function futuresOpenOrders($symbol = null, array $params = []) * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) * @param string $orderId (optional) order id to get the response for (mandatory if origClientOrderId is not set) * @param string $origClientOrderId (optional) original client order id to get the response for (mandatory if orderId is not set) - * @param string $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the order details * @throws \Exception @@ -4890,7 +4904,8 @@ public function futuresOpenOrder(string $symbol, $orderId = null, $origClientOrd * @param int $endTime (optional) timestamp in ms to get orders until INCLUSIVE * @param int $limit (optional) limit the amount of orders (default 500, max 1000) * @param string $autoCloseType (optional) "LIQUIDATION" for liquidation orders, "ADL" for ADL orders - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the orders details * @throws \Exception @@ -4932,7 +4947,8 @@ public function futuresForceOrders($symbol = null, $startTime = null, $endTime = * @param int $limit (optional) limit the amount of trades (default 500, max 1000) * @param string $orderId (optional) order id to get the trades for * @param string $fromId (optional) trade id to get the trades from (if is set it will get trades >= that Id) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the trades details * @throws \Exception @@ -4982,7 +4998,8 @@ public function futuresHistory(string $symbol, $startTime = null, $endTime = nul * * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) * @param string $marginType (mandatory) margin type, "CROSSED" or "ISOLATED" - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5006,7 +5023,8 @@ public function futuresSetMarginMode(string $symbol, string $marginType, array $ * * @property int $weight 30 * - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5026,7 +5044,8 @@ public function futuresPositionMode(array $params = []) * @property int $weight 1 * * @param bool $dualSidePosition (mandatory) true for Hedge Mode, false for One-way Mode - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5052,7 +5071,8 @@ public function futuresSetPositionMode(bool $dualSidePosition, array $params = [ * * @param int $leverage (mandatory) leverage to be set (min 1, max 125) * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5061,7 +5081,6 @@ public function futuresSetLeverage(int $leverage, string $symbol, array $params { $request = [ 'symbol' => $symbol, - 'fapi' => true, 'leverage' => $leverage, ]; @@ -5077,7 +5096,8 @@ public function futuresSetLeverage(int $leverage, string $symbol, array $params * * @property int $weight 30 * - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5097,7 +5117,8 @@ public function futuresMultiAssetsMarginMode(array $params = []) * @property int $weight 1 * * @param bool $multiAssetsMarginMode (mandatory) true for multi-assets mode, false for single-asset mode - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5145,7 +5166,8 @@ protected function modifyMarginHelper(string $symbol, string $amount, $addOrRedu * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) * @param string $amount (mandatory) amount to be added * @param string $positionSide (optional) position side - "BOTH" for non-hedged and "LONG" or "SHORT" for hedged (mandatory for hedged positions) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5167,7 +5189,8 @@ public function futuresAddMargin(string $symbol, string $amount, $positionSide = * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) * @param string $amount (mandatory) amount to be removed * @param string $positionSide (optional) position side - "BOTH" for non-hedged and "LONG" or "SHORT" for hedged (mandatory for hedged positions) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5275,16 +5298,15 @@ public function futuresPositionV3(string $symbol, array $params = []) * @property int $weight 5 * * @param string $symbol (optional) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the ADL quantile details * @throws \Exception */ public function futuresAdlQuantile($symbol = null, array $params = []) { - $request = [ - 'fapi' => true, - ]; + $request = []; if ($symbol) { $request['symbol'] = $symbol; } @@ -5306,7 +5328,8 @@ public function futuresAdlQuantile($symbol = null, array $params = []) * @param int $endTime (optional) timestamp in ms to get history until INCLUSIVE * @param int $limit (optional) limit the amount of history (default 500) * @param string $addOrReduce (optional) "ADD" or "REDUCE" to filter the history - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response */ public function futuresPositionMarginChangeHistory(string $symbol, $startTime = null, $endTime = null, $limit = null, $addOrReduce = null, array $params = []) { @@ -5438,7 +5461,8 @@ public function futuresAccountV3(array $params = []) * @property int $weight 20 * * @param string $symbol (mandatory) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the trade fee details * @throws \Exception @@ -5461,7 +5485,8 @@ public function futuresTradeFee(string $symbol, array $params = []) * * @property int $weight 5 * - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the account configuration details * @throws \Exception @@ -5482,7 +5507,8 @@ public function futuresAccountConfig(array $params = []) * @property int $weight 5 * * @param string $symbol (optional) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the margin mode details * @throws \Exception @@ -5506,7 +5532,8 @@ public function futuresMarginModes($symbol = null, array $params = []) * * @property int $weight 1 * - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the rate limit details * @throws \Exception @@ -5527,7 +5554,8 @@ public function futuresOrderRateLimit(array $params = []) * @property int $weight 1 * * @param string $symbol (optional) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the leverage details * @throws \Exception @@ -5582,7 +5610,8 @@ public function futuresLeverages($symbol = null, array $params = []) * @param int $endTime (optional) timestamp in ms to get income until INCLUSIVE * @param int $limit (optional) limit the amount of income (default 100, max 1000) * @param int $page (optional) number of page to get - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the income details * @throws \Exception @@ -5623,7 +5652,8 @@ public function futuresLedger($symbol = null, $incomeType = null, $startTime = n * weigth is 1 if symbol is provided * * @param string $symbol (optional) market symbol (e.g. ETHUSDT) - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the trading status details * @throws \Exception @@ -5645,7 +5675,6 @@ public function futuresTradingStatus($symbol = null, array $params = []) protected function futuresDownloadId($startTime, $endTime, array $params = null, string $url = '') { $request = [ - 'fapi' => true, 'startTime' => $startTime, 'endTime' => $endTime, ]; @@ -5679,7 +5708,8 @@ protected function futuresDownloadLinkByDownloadId(string $downloadId, array $pa * * @param int $startTime (optional) timestamp in ms to get transactions from INCLUSIVE * @param int $endTime (optional) timestamp in ms to get transactions until INCLUSIVE - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the response * @throws \Exception @@ -5700,7 +5730,8 @@ public function futuresDownloadIdForTransactions(int $startTime, int $endTime, a * @property int $weight 10 * * @param string $downloadId (mandatory) download id - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the download link * @throws \Exception @@ -5723,7 +5754,8 @@ public function futuresDownloadTransactionsByDownloadId(string $downloadId, arra * * @param int $startTime (optional) timestamp in ms to get orders from INCLUSIVE * @param int $endTime (optional) timestamp in ms to get orders until INCLUSIVE - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the response * @throws \Exception @@ -5744,7 +5776,8 @@ public function futuresDownloadIdForOrders(int $startTime, int $endTime, array $ * @property int $weight 10 * * @param string $downloadId (mandatory) download id - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the download link * @throws \Exception @@ -5767,7 +5800,8 @@ public function futuresDownloadOrdersByDownloadId(string $downloadId, array $par * * @param int $startTime (optional) timestamp in ms to get trades from INCLUSIVE * @param int $endTime (optional) timestamp in ms to get trades until INCLUSIVE - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the response * @throws \Exception @@ -5788,7 +5822,8 @@ public function futuresDownloadIdForTrades(int $startTime, int $endTime, array $ * @property int $weight 10 * * @param string $downloadId (mandatory) download id - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array with error message or the download link * @throws \Exception @@ -5808,7 +5843,8 @@ public function futuresDownloadTradesByDownloadId(string $downloadId, array $par * @property int $weight 1 * * @param bool $flag (mandatory) true for BNB Fee Discount On, false for BNB Fee Discount Off - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5831,7 +5867,8 @@ public function futuresFeeBurn(bool $flag, array $params = []) * * @property int $weight 30 * - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5883,7 +5920,8 @@ public function convertExchangeInfo($fromAsset = null, $toAsset = null, array $p * @param string $fromAmount (optional) mandatory if $toAmount is not set * @param string $toAmount (optional) mandatory if $fromAmount is not set * @param string $validTime (optional) deafault "10s" - * @param int $recvWindow (optional) the time in milliseconds to wait for a response + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5918,8 +5956,8 @@ public function convertSend(string $fromAsset, string $toAsset, $fromAmount = nu * @property int $weight 200 * * @param string $quoteId (mandatory) the quote ID to accept - * @param int $recvWindow (optional) the time in milliseconds to wait for a response - * @param array $params (optional) additional parameters + * @param array $params (optional) An array of additional parameters that the API endpoint allows + * - @param int $params['recvWindow'] (optional) the time in milliseconds to wait for the response * * @return array containing the response * @throws \Exception @@ -5949,9 +5987,7 @@ public function convertAccept(string $quoteId, array $params = []) */ public function convertStatus($orderId = null, $quoteId = null, array $params = []) { - $request = [ - 'fapi' => true, - ]; + $request = []; if ($orderId) { $request['orderId'] = $orderId; } else if ($quoteId) { From 1f9b48ffb2d564e42ae850f92c9c1c315fedc80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Sun, 20 Apr 2025 16:19:27 +0300 Subject: [PATCH 07/11] Program-helper deleted from repo --- tests/updateMethods.js | 159 ----------------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 tests/updateMethods.js diff --git a/tests/updateMethods.js b/tests/updateMethods.js deleted file mode 100644 index cb964cb..0000000 --- a/tests/updateMethods.js +++ /dev/null @@ -1,159 +0,0 @@ -const source = './php-binance-api.php' -const dest = './generatedMethods.txt' -const fs = require('fs') -const path = require('path') - -const fapiUrl = 'https://fapi.binance.com/fapi/' -const spotUrl = 'https://api.binance.com/api/' - -const methodTemplate = /public function (\w+)\((.*?)\)/ - -function getMethodNameAndParams (signature = '') { - const match = signature.match(methodTemplate) - const methodName = match[1] - const params = [] - const rawParams = match[2].split(',') - for (const rawParam of rawParams) { - const splitted = rawParam.split('=') - const defaultValue = splitted[1] ? splitted[1].trim() : undefined - const param = splitted[0].trim() - const typeTemlate = /(\w+)\s+\$(\w+)/ - const typeMatch = param.match(typeTemlate) - let type = undefined; - let name = undefined; - if (typeMatch) { - type = typeMatch[1] - name = typeMatch[2] - } else { - name = param.replace(/\$/g, '').trim() - } - if (name && name !== 'flags') { - params.push({ - name, - type, - defaultValue - }) - } - } - return { - methodName, - params - } -} - - -function extractMethods(filePath) { - const fileContent = fs.readFileSync(filePath, 'utf-8') - const lines = fileContent.split('\n') - const methods = [] - for (let i = 0; i < lines.length; i++) { - const line = lines[i].trim() - if (line.startsWith('public function') && line.includes('(')) { - const method = getMethodNameAndParams(line) - for (let j = i + 1; j < lines.length; j++) { - const followingLine = lines[j].trim() - const httpMatch = followingLine.match(/this->(httpRequest)\(('|")([^'"]+)('|"), ('|")([^'"]+)/) - if (httpMatch) { - const url = httpMatch[3] - const baseUrl = method.methodName.includes('futures') ? fapiUrl : spotUrl - const methodType = httpMatch[6] - method.type = methodType - method.url = baseUrl + url - i = j - break - } else if (followingLine.startsWith('public function')) { - i = j - 1 - break - } - } - methods.push(method) - } - } - return methods -} - -function writeStaticTestForMethod (method) { - const methodName = method.methodName - let result = 'public function test' + `${methodName.charAt(0).toUpperCase() + methodName.slice(1)}` + '()\n{\n ' - const methodCall = writeMethodCall(method) - result += writeTryCatch(methodCall) - result += writeUrlCheck(method) - result += writeParamsCheck(method.params) - result += '}\n' - console.log (method) - return result -} - -function writeMethodCall (method) { - const methodName = method.methodName - const params = method.params - let paramStings = [] - for (const param of params) { - const string = `$this->${param.name}` - paramStings.push(string) - } - return `$this->binance->${methodName}(${paramStings.join(', ')});\n` -} - -function writeTryCatch (methodCall) { - return `try {\n ${methodCall}\n } catch (\\Throwable $e) {\n\n }\n` -} - -function writeUrlCheck (method) { - let url = method.url ? method.url : 'ADD_URL_HERE' - if (method.type === 'POST' || method.params.length === 0) { - return ` $this->assertEquals("${url}", self::$capturedUrl);\n` - } else { - let lines = ' $query = http_build_query([\n' - const params = method.params - for (const param of params) { - const paramName = param.name - lines += ` '${paramName}' => $this->${paramName},\n` - } - lines += ' ]);\n' - lines += ` $endpoint = "${url}?" . $query;\n` - lines += ` $this->assertEquals($endpoint, self::$capturedUrl);\n` - lines += ` $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint));\n` - return lines - } -} - -function writeParamsCheck (params = []) { - let result = '' - if (params.length > 0) { - result += '\n parse_str(self::$capturedBody, $params);\n\n' - for (const param of params) { - const paramName = param.name - result += ` $this->assertEquals($this->${paramName}, $params['${paramName}']);\n` - } - } - return result -} - -function getUniqueParams (methods) { - const uniqueParams = [] - for (const method of methods) { - for (const param of method.params) { - let fullName = `${param.name}` - if (param.type) { - fullName += ` type: ${param.type}` - } - if (param.defaultValue) { - fullName += ` default: ${param.defaultValue}` - } - uniqueParams.push(fullName) - } - } - return new Set(uniqueParams) -} - -(() => { - const methods = extractMethods(source) - const testCases = [] - for (const method of methods) { - const testCase = writeStaticTestForMethod(method) - testCases.push(testCase) - } - fs.writeFileSync(dest, testCases.join('\n')) - console.log(`Generated test cases for ${methods.length} methods.`) -})() \ No newline at end of file From 65197793a9026ab07bc2f927d94c17074c4d0756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Mon, 21 Apr 2025 09:01:44 +0300 Subject: [PATCH 08/11] httpRequest methods renamed --- php-binance-api.php | 238 ++++++++++++++++++++++---------------------- 1 file changed, 119 insertions(+), 119 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 2bcdff2..1ebfc67 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -509,7 +509,7 @@ public function cancel(string $symbol, string $orderid, $params = []) "symbol" => $symbol, "orderId" => $orderid, ]; - return $this->spotRequest("v3/order", "DELETE", array_merge($request, $params), true); + return $this->apiRequest("v3/order", "DELETE", array_merge($request, $params), true); } /** @@ -529,7 +529,7 @@ public function orderStatus(string $symbol, string $orderid, array $params = []) "symbol" => $symbol, "orderId" => $orderid, ]; - return $this->spotRequest("v3/order", "GET", array_merge($request, $params), true); + return $this->apiRequest("v3/order", "GET", array_merge($request, $params), true); } /** @@ -550,7 +550,7 @@ public function openOrders($symbol = null, array $params = []) "symbol" => $symbol, ]; } - return $this->spotRequest("v3/openOrders", "GET", array_merge($request, $params), true); + return $this->apiRequest("v3/openOrders", "GET", array_merge($request, $params), true); } /** @@ -568,7 +568,7 @@ public function cancelOpenOrders($symbol = null, array $params = []) "symbol" => $symbol, ]; } - return $this->spotRequest("v3/openOrders", "DELETE", array_merge($request, $params), true); + return $this->apiRequest("v3/openOrders", "DELETE", array_merge($request, $params), true); } /** @@ -592,7 +592,7 @@ public function orders(string $symbol, int $limit = 500, int $fromOrderId = 0, a if ($fromOrderId) { $request["orderId"] = $fromOrderId; } - return $this->spotRequest("v3/allOrders", "GET", array_merge($request, $params), true); + return $this->apiRequest("v3/allOrders", "GET", array_merge($request, $params), true); } /** @@ -628,7 +628,7 @@ public function history(string $symbol, int $limit = 500, int $fromTradeId = -1, $request["endTime"] = $endTime; } - return $this->spotRequest("v3/myTrades", "GET", array_merge($request, $params), true); + return $this->apiRequest("v3/myTrades", "GET", array_merge($request, $params), true); } /** @@ -654,7 +654,7 @@ public function myTrades(string $symbol, int $limit = 500, int $fromTradeId = -1 */ public function useServerTime(array $params = []) { - $request = $this->spotRequest("v3/time", "GET", $params); + $request = $this->apiRequest("v3/time", "GET", $params); if (isset($request['serverTime'])) { $this->info['timeOffset'] = $request['serverTime'] - (microtime(true) * 1000); } @@ -670,7 +670,7 @@ public function useServerTime(array $params = []) */ public function time(array $params = []) { - return $this->spotRequest("v3/time", "GET", $params); + return $this->apiRequest("v3/time", "GET", $params); } /** @@ -698,13 +698,13 @@ public function exchangeInfo($symbols = null, array $params = []) if ($symbols) { if (gettype($symbols) == "string") { $request["symbol"] = $symbols; - $arr = $this->spotRequest("v3/exchangeInfo", "GET", array_merge($request, $params)); + $arr = $this->apiRequest("v3/exchangeInfo", "GET", array_merge($request, $params)); } if (gettype($symbols) == "array") { - $arr = $this->spotRequest("v3/exchangeInfo?symbols=" . '["' . implode('","', $symbols) . '"]', "GET", $params); + $arr = $this->apiRequest("v3/exchangeInfo?symbols=" . '["' . implode('","', $symbols) . '"]', "GET", $params); } } else { - $arr = $this->spotRequest("v3/exchangeInfo", "GET", $params); + $arr = $this->apiRequest("v3/exchangeInfo", "GET", $params); } if ((is_array($arr) === false) || empty($arr)) { echo "Error: unable to fetch spot exchange info" . PHP_EOL; @@ -738,7 +738,7 @@ public function assetDetail($asset = '', array $params = []) $request = array(); if ($asset != '' && gettype($asset) == 'string') $request['asset'] = $asset; - $arr = $this->spotWalletRequest("v1/asset/assetDetail", 'GET', array_merge($request, $params), true); + $arr = $this->sapiRequest("v1/asset/assetDetail", 'GET', array_merge($request, $params), true); // if asset was set, no backward compatibility needed as this was implemented later if (isset($params['asset'])) return $arr; @@ -790,7 +790,7 @@ public function dustLog($startTime = NULL, $endTime = NULL, array $params = []) $request['endTime'] = $endTime; } - return $this->spotWalletRequest("v1/asset/dribblet", 'GET', array_merge($request, $params), true); + return $this->sapiRequest("v1/asset/dribblet", 'GET', array_merge($request, $params), true); } /** @@ -811,7 +811,7 @@ public function dustTransfer($assets, array $params = []) 'assets' => $assets, ]; - return $this->spotWalletRequest("v1/asset/dust", 'POST', array_merge($request, $params), true); + return $this->sapiRequest("v1/asset/dust", 'POST', array_merge($request, $params), true); } /** @@ -827,7 +827,7 @@ public function tradeFee(string $symbol, array $params = []) $request = [ "symbol" => $symbol, ]; - return $this->spotWalletRequest("v1/asset/tradeFee", 'GET', array_merge($request, $params), true); + return $this->sapiRequest("v1/asset/tradeFee", 'GET', array_merge($request, $params), true); } /** @@ -848,7 +848,7 @@ public function commissionFee($symbol = '', array $params = []) if ($symbol != '' && gettype($symbol) == 'string') $request['symbol'] = $symbol; - return $this->spotWalletRequest("v1/asset/tradeFee", 'GET', array_merge($request, $params), true); + return $this->sapiRequest("v1/asset/tradeFee", 'GET', array_merge($request, $params), true); } /** @@ -896,7 +896,7 @@ public function withdraw(string $asset, string $address, $amount, $addressTag = if (is_null($orderId) === false && empty($orderId) === false) { $request['withdrawOrderId'] = $orderId; } - return $this->spotWalletRequest("v1/capital/withdraw/apply", "POST", array_merge($request, $params), true); + return $this->sapiRequest("v1/capital/withdraw/apply", "POST", array_merge($request, $params), true); } /** @@ -921,7 +921,7 @@ public function depositAddress(string $asset, $network = null, array $params = [ $request['network'] = $network; } - $return = $this->spotWalletRequest("v1/capital/deposit/address", "GET", array_merge($request, $params), true); + $return = $this->sapiRequest("v1/capital/deposit/address", "GET", array_merge($request, $params), true); // Adding for backwards compatibility with wapi if (is_array($return) && !empty($return)) { @@ -958,7 +958,7 @@ public function depositHistory(string $asset = null, array $params = []) if (is_null($asset) === false) { $request['coin'] = $asset; } - $return = $this->spotWalletRequest("v1/capital/deposit/hisrec", "GET", array_merge($request, $params), true); + $return = $this->sapiRequest("v1/capital/deposit/hisrec", "GET", array_merge($request, $params), true); // Adding for backwards compatibility with wapi if (is_array($return) && !empty($return)) { @@ -994,7 +994,7 @@ public function withdrawHistory(string $asset = null, array $params = []) } // Wrapping in array for backwards compatibility with wapi $return = array( - 'withdrawList' => $this->spotWalletRequest("v1/capital/withdraw/history", "GET", array_merge($request, $params), true) + 'withdrawList' => $this->sapiRequest("v1/capital/withdraw/history", "GET", array_merge($request, $params), true) ); // Adding for backwards compatibility with wapi @@ -1090,7 +1090,7 @@ public function transfer(string $type, string $asset, string $amount, $fromSymbo } - return $this->spotWalletRequest("v1/asset/transfer", 'POST', array_merge($request, $params), true); + return $this->sapiRequest("v1/asset/transfer", 'POST', array_merge($request, $params), true); } /** @@ -1139,7 +1139,7 @@ public function transfersHistory(string $type, $startTime = null, $endTime = nul } - return $this->spotWalletRequest("v1/asset/transfer", 'GET', array_merge($request, $params), true); + return $this->sapiRequest("v1/asset/transfer", 'GET', array_merge($request, $params), true); } /** @@ -1152,7 +1152,7 @@ public function transfersHistory(string $type, $startTime = null, $endTime = nul */ public function prices(array $params = []) { - return $this->priceData($this->spotRequest("v3/ticker/price", "GET", $params)); + return $this->priceData($this->apiRequest("v3/ticker/price", "GET", $params)); } /** @@ -1168,7 +1168,7 @@ public function price(string $symbol, array $params = []) $request = [ "symbol" => $symbol, ]; - $ticker = $this->spotRequest("v3/ticker/price", "GET", array_merge($request, $params)); + $ticker = $this->apiRequest("v3/ticker/price", "GET", array_merge($request, $params)); if (!isset($ticker['price'])) { echo "Error: unable to fetch price for $symbol" . PHP_EOL; return null; @@ -1186,7 +1186,7 @@ public function price(string $symbol, array $params = []) */ public function bookPrices(array $params = []) { - return $this->bookPriceData($this->spotRequest("v3/ticker/bookTicker", "GET", $params)); + return $this->bookPriceData($this->apiRequest("v3/ticker/bookTicker", "GET", $params)); } /** @@ -1199,7 +1199,7 @@ public function bookPrices(array $params = []) */ public function account(array $params = []) { - return $this->spotRequest("v3/account", "GET", $params, true); + return $this->apiRequest("v3/account", "GET", $params, true); } /** @@ -1219,7 +1219,7 @@ public function prevDay(string $symbol = null, array $params = []) 'symbol' => $symbol, ]; } - return $this->spotRequest("v1/ticker/24hr", "GET", array_merge($request, $params)); + return $this->apiRequest("v1/ticker/24hr", "GET", array_merge($request, $params)); } /** @@ -1236,7 +1236,7 @@ public function aggTrades(string $symbol, array $params = []) $request = [ "symbol" => $symbol, ]; - return $this->tradesData($this->spotRequest("v1/aggTrades", "GET", array_merge($request, $params))); + return $this->tradesData($this->apiRequest("v1/aggTrades", "GET", array_merge($request, $params))); } /** @@ -1265,13 +1265,13 @@ public function historicalTrades(string $symbol, int $limit = 500, int $tradeId $request["fromId"] = $tradeId; } else { // if there is no tradeId given, we can use v3/trades, weight is 1 and not 5 - return $this->spotRequest("v3/trades", "GET", array_merge($request, $params)); + return $this->apiRequest("v3/trades", "GET", array_merge($request, $params)); } // The endpoint cannot handle extra parameters like 'timestamp' or 'signature', // but it needs the http header with the key so we need to construct it here $query = http_build_query(array_merge($request, $params), '', '&'); - return $this->spotRequest("v3/historicalTrades?$query"); + return $this->apiRequest("v3/historicalTrades?$query"); } /** @@ -1298,7 +1298,7 @@ public function depth(string $symbol, int $limit = 100, array $params = []) "symbol" => $symbol, "limit" => $limit, ]; - $json = $this->spotRequest("v1/depth", "GET", array_merge($request, $params)); + $json = $this->apiRequest("v1/depth", "GET", array_merge($request, $params)); if (is_array($json) === false) { echo "Error: unable to fetch depth" . PHP_EOL; $json = []; @@ -1363,7 +1363,7 @@ public function balances(string $market_type = 'spot', array $params = [], strin */ public function coins(array $params = []) { - return $this->spotWalletRequest("v1/capital/config/getall", 'GET', $params, true); + return $this->sapiRequest("v1/capital/config/getall", 'GET', $params, true); } /** @@ -1444,24 +1444,24 @@ protected function curl_set_body($curl, $option, $query) { curl_setopt($curl, $option, $query); } - public function spotRequest($url, $method = "GET", $params = [], $signed = false) + public function apiRequest($url, $method = "GET", $params = [], $signed = false) { return $this->httpRequest($url, $method, $params, $signed); } - public function spotWalletRequest($url, $method = "GET", $params = [], $signed = false) + public function sapiRequest($url, $method = "GET", $params = [], $signed = false) { $params['sapi'] = true; return $this->httpRequest($url, $method, $params, $signed); } - public function futuresRequest($url, $method = "GET", $params = [], $signed = false) + public function fapiRequest($url, $method = "GET", $params = [], $signed = false) { $params['fapi'] = true; return $this->httpRequest($url, $method, $params, $signed); } - public function futuresDataRequest($url, $method = "GET", $params = [], $signed = false) + public function fapiDataRequest($url, $method = "GET", $params = [], $signed = false) { $params['fapiData'] = true; return $this->httpRequest($url, $method, $params, $signed); @@ -1819,7 +1819,7 @@ public function order(string $side, string $symbol, $quantity, $price, string $t } $qstring = ($test === false) ? "v3/order" : "v3/order/test"; - return $this->spotRequest($qstring, "POST", array_merge($request, $params), true); + return $this->apiRequest($qstring, "POST", array_merge($request, $params), true); } /** @@ -1859,7 +1859,7 @@ public function candlesticks(string $symbol, string $interval = "5m", int $limit $request["endTime"] = $endTime; } - $response = $this->spotRequest("v1/klines", "GET", array_merge($request, $params)); + $response = $this->apiRequest("v1/klines", "GET", array_merge($request, $params)); if (is_array($response) === false) { return []; @@ -3113,21 +3113,21 @@ public function isOnTestnet() : bool public function systemStatus(array $params = []) { $arr = array(); - $api_status = $this->spotRequest("v3/ping", 'GET', $params); + $api_status = $this->apiRequest("v3/ping", 'GET', $params); if ( empty($api_status) ) { $arr['api']['status'] = 'ping ok'; } else { $arr['api']['status'] = $api_status; } - $fapi_status = $this->futuresRequest("v1/ping", 'GET', $params); + $fapi_status = $this->fapiRequest("v1/ping", 'GET', $params); if ( empty($fapi_status) ) { $arr['fapi']['status'] = 'ping ok'; } else { $arr['fapi']['status'] = $fapi_status; } - $arr['sapi'] = $this->spotWalletRequest("v1/system/status", 'GET', $params); + $arr['sapi'] = $this->sapiRequest("v1/system/status", 'GET', $params); return $arr; } @@ -3162,7 +3162,7 @@ public function accountSnapshot($type, $nbrDays = 5, $startTime = 0, $endTime = if ($nbrDays != 5) $request['limit'] = $nbrDays; - return $this->spotWalletRequest("v1/accountSnapshot", 'GET', array_merge($request, $params), true); + return $this->sapiRequest("v1/accountSnapshot", 'GET', array_merge($request, $params), true); } /** @@ -3178,7 +3178,7 @@ public function accountSnapshot($type, $nbrDays = 5, $startTime = 0, $endTime = public function accountStatus(array $params = []) { $arr = array(); - $arr['sapi'] = $this->spotWalletRequest("v1/account/status", 'GET', $params, true); + $arr['sapi'] = $this->sapiRequest("v1/account/status", 'GET', $params, true); return $arr; } @@ -3194,7 +3194,7 @@ public function accountStatus(array $params = []) */ public function apiRestrictions(array $params = []) { - return $this->spotWalletRequest("v1/account/apiRestrictions", 'GET', $params, true); + return $this->sapiRequest("v1/account/apiRestrictions", 'GET', $params, true); } /** @@ -3210,7 +3210,7 @@ public function apiRestrictions(array $params = []) public function apiTradingStatus(array $params = []) { $arr = array(); - $arr['sapi'] = $this->spotWalletRequest("v1/account/apiTradingStatus", 'GET', $params, true); + $arr['sapi'] = $this->sapiRequest("v1/account/apiTradingStatus", 'GET', $params, true); return $arr; } @@ -3277,7 +3277,7 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp $request[$flag] = $params[$flag]; } - return $this->spotRequest("v3/order/oco", "POST", $request, true); + return $this->apiRequest("v3/order/oco", "POST", $request, true); } /** @@ -3297,7 +3297,7 @@ public function avgPrice(string $symbol, array $params = []) $request = [ 'symbol' => $symbol, ]; - $ticker = $this->spotRequest("v3/avgPrice", "GET", array_merge($request, $params)); + $ticker = $this->apiRequest("v3/avgPrice", "GET", array_merge($request, $params)); if (is_array($ticker) === false) { echo "Error: unable to fetch avg price" . PHP_EOL; $ticker = []; @@ -3337,7 +3337,7 @@ public function bswapQuote($baseAsset, $quoteAsset, $quoteQty, array $params = [ 'quoteQty' => $quoteQty, ]; - return $this->spotWalletRequest("v1/bswap/quote", 'GET', array_merge($request, $params), true); + return $this->sapiRequest("v1/bswap/quote", 'GET', array_merge($request, $params), true); } /********************************************* @@ -3358,7 +3358,7 @@ public function bswapQuote($baseAsset, $quoteAsset, $quoteQty, array $params = [ */ public function futuresTime(array $params = []) { - return $this->futuresRequest("v1/time", "GET", $params); + return $this->fapiRequest("v1/time", "GET", $params); } /** @@ -3376,7 +3376,7 @@ public function futuresTime(array $params = []) public function futuresExchangeInfo(array $params = []) { if (!$this->futuresExchangeInfo) { - $arr = $this->futuresRequest("v1/exchangeInfo", "GET", $params); + $arr = $this->fapiRequest("v1/exchangeInfo", "GET", $params); if ((is_array($arr) === false) || empty($arr)) { echo "Error: unable to fetch futures exchange info" . PHP_EOL; $arr = array(); @@ -3424,7 +3424,7 @@ public function futuresDepth(string $symbol, int $limit = null, array $params = if ($limit) { $request['limit'] = $limit; } - $json = $this->futuresRequest("v1/depth", "GET", array_merge($request, $params)); + $json = $this->fapiRequest("v1/depth", "GET", array_merge($request, $params)); if (is_array($json) === false) { echo "Error: unable to fetch futures depth" . PHP_EOL; $json = []; @@ -3464,7 +3464,7 @@ public function futuresRecentTrades(string $symbol, int $limit = null, array $pa if ($limit) { $request['limit'] = $limit; } - return $this->futuresRequest("v1/trades", "GET", array_merge($request, $params)); + return $this->fapiRequest("v1/trades", "GET", array_merge($request, $params)); } /** @@ -3494,7 +3494,7 @@ public function futuresHistoricalTrades(string $symbol, $limit = null, $tradeId if ($tradeId) { $request['fromId'] = $tradeId; } - return $this->futuresRequest("v1/historicalTrades", "GET", array_merge($request, $params), true); + return $this->fapiRequest("v1/historicalTrades", "GET", array_merge($request, $params), true); } /** @@ -3532,7 +3532,7 @@ public function futuresAggTrades(string $symbol, int $fromId = null, int $startT if ($limit) { $request['limit'] = $limit; } - return $this->tradesData($this->futuresRequest("v1/aggTrades", "GET", array_merge($request, $params))); + return $this->tradesData($this->fapiRequest("v1/aggTrades", "GET", array_merge($request, $params))); } /** @@ -3715,7 +3715,7 @@ private function futuresCandlesticksHelper($symbol, $interval, $limit, $startTim $request['contractType'] = $contractType; } - $response = $this->futuresRequest("v1/{$klineType}", 'GET', array_merge($request, $params)); + $response = $this->fapiRequest("v1/{$klineType}", 'GET', array_merge($request, $params)); if (is_array($response) === false) { return []; @@ -3751,7 +3751,7 @@ public function futuresMarkPrice(string $symbol = null, array $params = []) if ($symbol) { $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/premiumIndex", "GET", array_merge($request, $params)); + return $this->fapiRequest("v1/premiumIndex", "GET", array_merge($request, $params)); } /** @@ -3785,7 +3785,7 @@ public function futuresFundingRateHistory(string $symbol = null, int $limit = nu if ($endTime) { $request['endTime'] = $endTime; } - return $this->futuresRequest("v1/fundingRate", "GET", array_merge($request, $params)); + return $this->fapiRequest("v1/fundingRate", "GET", array_merge($request, $params)); } /** @@ -3802,7 +3802,7 @@ public function futuresFundingRateHistory(string $symbol = null, int $limit = nu */ public function futuresFundingInfo(array $params = []) { - return $this->futuresRequest("v1/fundingInfo", "GET", $params); + return $this->fapiRequest("v1/fundingInfo", "GET", $params); } /** @@ -3827,7 +3827,7 @@ public function futuresPrevDay(string $symbol = null, array $params = []) if ($symbol) { $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/ticker/24hr", "GET", array_merge($request, $params)); + return $this->fapiRequest("v1/ticker/24hr", "GET", array_merge($request, $params)); } /** @@ -3849,7 +3849,7 @@ public function futuresPrice(string $symbol, array $params = []) $request = [ 'symbol' => $symbol, ]; - $ticker = $this->futuresRequest("v1/ticker/price", "GET", array_merge($request, $params)); + $ticker = $this->fapiRequest("v1/ticker/price", "GET", array_merge($request, $params)); if (!isset($ticker['price'])) { echo "Error: unable to fetch futures price for $symbol" . PHP_EOL; return null; @@ -3871,7 +3871,7 @@ public function futuresPrice(string $symbol, array $params = []) */ public function futuresPrices(array $params = []) { - return $this->priceData($this->futuresRequest("v1/ticker/price", "GET", $params)); + return $this->priceData($this->fapiRequest("v1/ticker/price", "GET", $params)); } /** @@ -3893,7 +3893,7 @@ public function futuresPriceV2(string $symbol, array $params = []) $request = [ 'symbol' => $symbol, ]; - $ticker = $this->futuresRequest("v2/ticker/price", "GET", $request); + $ticker = $this->fapiRequest("v2/ticker/price", "GET", $request); if (!isset($ticker['price'])) { echo "Error: unable to fetch futures price for $symbol" . PHP_EOL; return null; @@ -3915,7 +3915,7 @@ public function futuresPriceV2(string $symbol, array $params = []) */ public function futuresPricesV2(array $params = []) { - return $this->priceData($this->futuresRequest("v2/ticker/price", "GET", $params)); + return $this->priceData($this->fapiRequest("v2/ticker/price", "GET", $params)); } /** @@ -3940,7 +3940,7 @@ public function futuresSymbolOrderBookTicker(string $symbol = null, array $param if ($symbol) { $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/ticker/bookTicker", "GET", array_merge($request, $params)); + return $this->fapiRequest("v1/ticker/bookTicker", "GET", array_merge($request, $params)); } /** @@ -3961,7 +3961,7 @@ public function futuresDeliveryPrice(string $symbol, array $params = []): array 'pair' => $symbol, ]; - return $this->futuresDataRequest("delivery-price", "GET", array_merge($request, $params)); + return $this->fapiDataRequest("delivery-price", "GET", array_merge($request, $params)); } /** @@ -3983,14 +3983,14 @@ public function futuresOpenInterest(string $symbol, array $params = []): array $request = [ 'symbol'=> $symbol, ]; - return $this->futuresRequest("v1/openInterest", 'GET', array_merge($request, $params)); + return $this->fapiRequest("v1/openInterest", 'GET', array_merge($request, $params)); } /** - * symbolPeriodLimitStartEndFuturesDataRequest + * sapieriodLimitStartEndFuturesDataRequest * helper for routing GET methods that require symbol, period, limit, startTime and endTime */ - private function symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, $url, array $params = []) + private function sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, $url, array $params = []) { $request = [ 'symbol' => $symbol, @@ -4005,7 +4005,7 @@ private function symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $ if ($endTime) { $request['endTime'] = $endTime; } - return $this->futuresDataRequest($url, 'GET', array_merge($request, $params)); + return $this->fapiDataRequest($url, 'GET', array_merge($request, $params)); } /** @@ -4026,7 +4026,7 @@ private function symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $ */ public function futuresOpenInterestHistory(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'openInterestHist', $params); + return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'openInterestHist', $params); } /** @@ -4047,7 +4047,7 @@ public function futuresOpenInterestHistory(string $symbol, string $period = '5m' */ public function futuresTopLongShortPositionRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortPositionRatio', $params); + return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortPositionRatio', $params); } /** @@ -4068,7 +4068,7 @@ public function futuresTopLongShortPositionRatio(string $symbol, string $period */ public function futuresTopLongShortAccountRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortAccountRatio', $params); + return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortAccountRatio', $params); } /** @@ -4089,7 +4089,7 @@ public function futuresTopLongShortAccountRatio(string $symbol, string $period = */ public function futuresGlobalLongShortAccountRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'globalLongShortAccountRatio', $params); + return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'globalLongShortAccountRatio', $params); } /** @@ -4110,7 +4110,7 @@ public function futuresGlobalLongShortAccountRatio(string $symbol, string $perio */ public function futuresTakerLongShortRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) { - return $this->symbolPeriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'takerlongshortRatio', $params); + return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'takerlongshortRatio', $params); } @@ -4147,7 +4147,7 @@ public function futuresBasis(string $symbol, string $period = '5m', int $limit = if ($endTime) { $request['endTime'] = $endTime; } - return $this->futuresDataRequest("basis", 'GET', array_merge($request, $params)); + return $this->fapiDataRequest("basis", 'GET', array_merge($request, $params)); } /** @@ -4170,7 +4170,7 @@ public function futuresIndexInfo(string $symbol, array $params = []) $request = [ 'symbol' => $symbol, ]; - return $this->futuresRequest("v1/indexInfo", 'GET', array_merge($request, $params)); + return $this->fapiRequest("v1/indexInfo", 'GET', array_merge($request, $params)); } /** @@ -4195,7 +4195,7 @@ public function futuresAssetIndex(string $symbol = null, array $params = []) if ($symbol) { $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/assetIndex", 'GET', array_merge($request, $params)); + return $this->fapiRequest("v1/assetIndex", 'GET', array_merge($request, $params)); } /** @@ -4217,7 +4217,7 @@ public function futuresConstituents(string $symbol, array $params = []) $request = [ 'symbol' => $symbol, ]; - return $this->futuresRequest("v1/constituents", 'GET', array_merge($request, $params)); + return $this->fapiRequest("v1/constituents", 'GET', array_merge($request, $params)); } /** @@ -4342,7 +4342,7 @@ public function futuresOrder(string $side, string $symbol, $quantity = null, $pr { $request = $this->createFuturesOrderRequest($side, $symbol, $quantity, $price, $type, $params); $qstring = ($test === false) ? 'v1/order' : 'v1/order/test'; - return $this->futuresRequest($qstring, 'POST', $request, true); + return $this->fapiRequest($qstring, 'POST', $request, true); } /** @@ -4547,7 +4547,7 @@ public function futuresBatchOrders(array $orders, array $params = []) // current endpoint accepts orders list as a json string in the query string $encodedOrders = json_encode($formatedOrders); $url = 'v1/batchOrders?batchOrders=' . $encodedOrders; - return $this->futuresRequest($url, 'POST', array_merge($request, $params), true); + return $this->fapiRequest($url, 'POST', array_merge($request, $params), true); } /** @@ -4583,7 +4583,7 @@ public function futuresEditOrder(string $symbol, string $side, string $quantity, } unset($request['type']); unset($request['newClientOrderId']); - return $this->futuresRequest("v1/order", 'PUT', $request, true); + return $this->fapiRequest("v1/order", 'PUT', $request, true); } /** @@ -4606,7 +4606,7 @@ public function futuresEditOrders(array $orders, array $params = []) // current endpoint accepts orders list as a json string in the query string $request['batchOrders'] = json_encode($formatedOrders); - return $this->futuresRequest("v1/batchOrders", 'PUT', array_merge($request, $params), true); + return $this->fapiRequest("v1/batchOrders", 'PUT', array_merge($request, $params), true); } /** @@ -4649,7 +4649,7 @@ public function futuresOrderAmendment(string $symbol, $orderId = null, $origClie $request['limit'] = $limit; } - return $this->futuresRequest("v1/orderAmendment", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/orderAmendment", 'GET', array_merge($request, $params), true); } /** @@ -4677,7 +4677,7 @@ public function futuresCancel(string $symbol, $orderid, $params = []) } else if (!isset($params['origClientOrderId'])) { throw new \Exception('futuresCancel: either orderId or origClientOrderId must be set'); } - return $this->futuresRequest("v1/order", 'DELETE', array_merge($request, $params), true); + return $this->fapiRequest("v1/order", 'DELETE', array_merge($request, $params), true); } /** @@ -4711,7 +4711,7 @@ public function futuresCancelBatchOrders(string $symbol, $orderIdList = null, $o throw new \Exception('futuresCancelBatchOrders: either orderIdList or origClientOrderIdList must be set'); } - return $this->futuresRequest("v1/batchOrders", 'DELETE', array_merge($request, $params), true); + return $this->fapiRequest("v1/batchOrders", 'DELETE', array_merge($request, $params), true); } /** @@ -4733,7 +4733,7 @@ public function futuresCancelOpenOrders(string $symbol, array $params = []) 'symbol' => $symbol, ]; - return $this->futuresRequest("v1/allOpenOrders", 'DELETE', array_merge($request, $params), true); + return $this->fapiRequest("v1/allOpenOrders", 'DELETE', array_merge($request, $params), true); } /** @@ -4758,7 +4758,7 @@ public function futuresCountdownCancelAllOrders(string $symbol, int $countdownTi 'countdownTime' => $countdownTime, ]; - return $this->futuresRequest("v1/countdownCancelAll", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/countdownCancelAll", 'POST', array_merge($request, $params), true); } /** @@ -4790,7 +4790,7 @@ public function futuresOrderStatus(string $symbol, $orderId = null, $origClientO throw new \Exception('futuresOrderStatus: either orderId or origClientOrderId must be set'); } - return $this->futuresRequest("v1/order", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/order", 'GET', array_merge($request, $params), true); } /** @@ -4830,7 +4830,7 @@ public function futuresAllOrders(string $symbol, $startTime = null, $endTime = n $request['orderId'] = $orderId; } - return $this->futuresRequest("v1/allOrders", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/allOrders", 'GET', array_merge($request, $params), true); } /** @@ -4855,7 +4855,7 @@ public function futuresOpenOrders($symbol = null, array $params = []) $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/openOrders", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/openOrders", 'GET', array_merge($request, $params), true); } /** @@ -4887,7 +4887,7 @@ public function futuresOpenOrder(string $symbol, $orderId = null, $origClientOrd throw new \Exception('futuresOpenOrder: either orderId or origClientOrderId must be set'); } - return $this->futuresRequest("v1/openOrder", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/openOrder", 'GET', array_merge($request, $params), true); } /** * futuresForceOrders gets all futures force orders @@ -4929,7 +4929,7 @@ public function futuresForceOrders($symbol = null, $startTime = null, $endTime = $request['autoCloseType'] = $autoCloseType; } - return $this->futuresRequest("v1/forceOrders", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/forceOrders", 'GET', array_merge($request, $params), true); } /** @@ -4974,7 +4974,7 @@ public function futuresMyTrades(string $symbol, $startTime = null, $endTime = nu $request['fromId'] = $fromId; } - return $this->futuresRequest("v1/userTrades", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/userTrades", 'GET', array_merge($request, $params), true); } /** @@ -5011,7 +5011,7 @@ public function futuresSetMarginMode(string $symbol, string $marginType, array $ 'marginType' => $marginType, ]; - return $this->futuresRequest("v1/marginType", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/marginType", 'POST', array_merge($request, $params), true); } /** @@ -5031,7 +5031,7 @@ public function futuresSetMarginMode(string $symbol, string $marginType, array $ */ public function futuresPositionMode(array $params = []) { - return $this->futuresRequest("v1/positionSide/dual", 'GET', $params, true); + return $this->fapiRequest("v1/positionSide/dual", 'GET', $params, true); } /** @@ -5056,7 +5056,7 @@ public function futuresSetPositionMode(bool $dualSidePosition, array $params = [ 'dualSidePosition' => $dualSidePosition ? 'true' : 'false', ]; - return $this->futuresRequest("v1/positionSide/dual", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/positionSide/dual", 'POST', array_merge($request, $params), true); } /** @@ -5084,7 +5084,7 @@ public function futuresSetLeverage(int $leverage, string $symbol, array $params 'leverage' => $leverage, ]; - return $this->futuresRequest("v1/leverage", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/leverage", 'POST', array_merge($request, $params), true); } /** @@ -5104,7 +5104,7 @@ public function futuresSetLeverage(int $leverage, string $symbol, array $params */ public function futuresMultiAssetsMarginMode(array $params = []) { - return $this->futuresRequest("v1/multiAssetsMargin", 'GET', $params, true); + return $this->fapiRequest("v1/multiAssetsMargin", 'GET', $params, true); } /** @@ -5129,7 +5129,7 @@ public function futuresSetMultiAssetsMarginMode(bool $multiAssetsMarginMode, arr 'multiAssetsMarginMode' => $multiAssetsMarginMode ? 'true' : 'false', ]; - return $this->futuresRequest("v1/multiAssetsMarginMode", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/multiAssetsMarginMode", 'POST', array_merge($request, $params), true); } /** @@ -5151,7 +5151,7 @@ protected function modifyMarginHelper(string $symbol, string $amount, $addOrRedu $request['positionSide'] = $positionSide; } - return $this->futuresRequest("v1/positionMargin", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/positionMargin", 'POST', array_merge($request, $params), true); } /** @@ -5228,7 +5228,7 @@ public function futuresPositions($symbol = null, array $params = [], string $api if ($api_version !== 'v2' && $api_version !== 'v3') { throw new \Exception('futuresPositions: api_version must be either v2 or v3'); } - return $this->futuresRequest($api_version . "/positionRisk", 'GET', array_merge($request, $params), true); + return $this->fapiRequest($api_version . "/positionRisk", 'GET', array_merge($request, $params), true); } /** futuresPositionsV2 @@ -5311,7 +5311,7 @@ public function futuresAdlQuantile($symbol = null, array $params = []) $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/adlQuantile", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/adlQuantile", 'GET', array_merge($request, $params), true); } /** @@ -5362,7 +5362,7 @@ public function futuresPositionMarginChangeHistory(string $symbol, $startTime = } } - return $this->futuresRequest("v1/positionMargin/history", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/positionMargin/history", 'GET', array_merge($request, $params), true); } /** @@ -5430,7 +5430,7 @@ public function futuresAccount(array $params = [], string $api_version = 'v3') throw new \Exception('futuresAccount: api_version must be either v2 or v3'); } - return $this->futuresRequest($api_version . "/account", "GET", $params, true); + return $this->fapiRequest($api_version . "/account", "GET", $params, true); } /** @@ -5473,7 +5473,7 @@ public function futuresTradeFee(string $symbol, array $params = []) 'symbol' => $symbol, ]; - return $this->futuresRequest("v1/commissionRate", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/commissionRate", 'GET', array_merge($request, $params), true); } /** @@ -5493,7 +5493,7 @@ public function futuresTradeFee(string $symbol, array $params = []) */ public function futuresAccountConfig(array $params = []) { - return $this->futuresRequest("v1/accountConfig", 'GET', $params, true); + return $this->fapiRequest("v1/accountConfig", 'GET', $params, true); } /** @@ -5520,7 +5520,7 @@ public function futuresMarginModes($symbol = null, array $params = []) $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/symbolConfig", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/symbolConfig", 'GET', array_merge($request, $params), true); } /** @@ -5540,7 +5540,7 @@ public function futuresMarginModes($symbol = null, array $params = []) */ public function futuresOrderRateLimit(array $params = []) { - return $this->futuresRequest("v1/rateLimit/order", 'GET', $params, true); + return $this->fapiRequest("v1/rateLimit/order", 'GET', $params, true); } /** @@ -5567,7 +5567,7 @@ public function futuresLeverages($symbol = null, array $params = []) $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/leverageBracket", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/leverageBracket", 'GET', array_merge($request, $params), true); } /** @@ -5638,7 +5638,7 @@ public function futuresLedger($symbol = null, $incomeType = null, $startTime = n $request['page'] = $page; } - return $this->futuresRequest("v1/income", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/income", 'GET', array_merge($request, $params), true); } /** @@ -5665,7 +5665,7 @@ public function futuresTradingStatus($symbol = null, array $params = []) $request['symbol'] = $symbol; } - return $this->futuresRequest("v1/apiTradingStatus", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/apiTradingStatus", 'GET', array_merge($request, $params), true); } /** @@ -5679,7 +5679,7 @@ protected function futuresDownloadId($startTime, $endTime, array $params = null, 'endTime' => $endTime, ]; - return $this->futuresRequest($url, 'GET', array_merge($request, $params), true); + return $this->fapiRequest($url, 'GET', array_merge($request, $params), true); } /** @@ -5692,7 +5692,7 @@ protected function futuresDownloadLinkByDownloadId(string $downloadId, array $pa 'downloadId' => $downloadId, ]; - return $this->futuresRequest($url, 'GET', array_merge($request, $params), true); + return $this->fapiRequest($url, 'GET', array_merge($request, $params), true); } /** @@ -5855,7 +5855,7 @@ public function futuresFeeBurn(bool $flag, array $params = []) 'feeBurn' => $flag ? 'true' : 'false', ]; - return $this->futuresRequest("v1/feeBurn", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/feeBurn", 'POST', array_merge($request, $params), true); } /** @@ -5875,7 +5875,7 @@ public function futuresFeeBurn(bool $flag, array $params = []) */ public function futuresFeeBurnStatus(array $params = []) { - return $this->futuresRequest("v1/feeBurn", 'GET', $params, true); + return $this->fapiRequest("v1/feeBurn", 'GET', $params, true); } /** @@ -5903,7 +5903,7 @@ public function convertExchangeInfo($fromAsset = null, $toAsset = null, array $p if ($toAsset) { $request['toAsset'] = $toAsset; } - return $this->futuresRequest("v1/convert/exchangeInfo", 'GET', array_merge($request, $params)); + return $this->fapiRequest("v1/convert/exchangeInfo", 'GET', array_merge($request, $params)); } /** @@ -5943,7 +5943,7 @@ public function convertSend(string $fromAsset, string $toAsset, $fromAmount = nu $request['validTime'] = $validTime; } - return $this->futuresRequest("v1/convert/getQuote", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/convert/getQuote", 'POST', array_merge($request, $params), true); } /** @@ -5967,7 +5967,7 @@ public function convertAccept(string $quoteId, array $params = []) $request = [ 'quoteId' => $quoteId, ]; - return $this->futuresRequest("v1/convert/acceptQuote", 'POST', array_merge($request, $params), true); + return $this->fapiRequest("v1/convert/acceptQuote", 'POST', array_merge($request, $params), true); } /** @@ -5995,6 +5995,6 @@ public function convertStatus($orderId = null, $quoteId = null, array $params = } else { throw new \Exception('convertStatus: orderId or quoteId must be set'); } - return $this->futuresRequest("v1/convert/orderStatus", 'GET', array_merge($request, $params), true); + return $this->fapiRequest("v1/convert/orderStatus", 'GET', array_merge($request, $params), true); } } From e855861b6239ab9f2cf41447d526ebc0cec68176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Tue, 22 Apr 2025 14:04:59 +0300 Subject: [PATCH 09/11] recvWindow check moved to httpRequest --- php-binance-api.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 1ebfc67..f750096 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -60,6 +60,7 @@ class API protected $requestCount = 0; // /< This stores the amount of API requests protected $httpDebug = false; // /< If you enable this, curl will output debugging information protected $subscriptions = []; // /< View all websocket subscriptions + protected $recvWindow = null; // /< The amount of time in milliseconds to wait for a response from the server for endpoints that accept a recvWindow parameter // /< value of available onOrder assets @@ -434,7 +435,7 @@ public function numberOfDecimals($val = 0.00000001) public function marketQuoteSell(string $symbol, $quantity, array $params = []) { $params['isQuoteOrder'] = true; - $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']); + $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][1]['minQty']); $quantity = $this->floorDecimal($quantity, $c); return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $params); @@ -470,7 +471,7 @@ public function marketQuoteSellTest(string $symbol, $quantity, array $params = [ */ public function marketSell(string $symbol, $quantity, array $params = []) { - $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']); + $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][1]['minQty']); $quantity = $this->floorDecimal($quantity, $c); return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $params); @@ -1494,6 +1495,10 @@ protected function httpRequest(string $url, string $method = "GET", array $param $this->downloadCurlCaBundle(); } } + if ((!isset ($params['recvWindow'])) && (!is_null($this->recvWindow))) { + $params['recvWindow'] = $this->recvWindow; + print_r($params); + } $base = $this->base; if ($this->useTestnet) { @@ -1768,7 +1773,6 @@ public function order(string $side, string $symbol, $quantity, $price, string $t "side" => $side, "type" => $type, "quantity" => $quantity, - "recvWindow" => 60000, ]; // someone has preformated there 8 decimal point double already @@ -3238,7 +3242,6 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp $request = [ "symbol" => $symbol, "side" => $side, - "recvWindow" => 60000, ]; if (is_numeric($quantity) === false) { From 4a5003d41831b4f289ee16567e27e4d4bc510600 Mon Sep 17 00:00:00 2001 From: carlosmiei <43336371+carlosmiei@users.noreply.github.com> Date: Wed, 23 Apr 2025 12:56:24 +0100 Subject: [PATCH 10/11] rm print_r --- php-binance-api.php | 1 - 1 file changed, 1 deletion(-) diff --git a/php-binance-api.php b/php-binance-api.php index f750096..834c7f8 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1497,7 +1497,6 @@ protected function httpRequest(string $url, string $method = "GET", array $param } if ((!isset ($params['recvWindow'])) && (!is_null($this->recvWindow))) { $params['recvWindow'] = $this->recvWindow; - print_r($params); } $base = $this->base; From 67db38f1c8a9c2dd6842840113ced2437ef39900 Mon Sep 17 00:00:00 2001 From: carlosmiei <43336371+carlosmiei@users.noreply.github.com> Date: Wed, 23 Apr 2025 13:12:44 +0100 Subject: [PATCH 11/11] fix warning --- php-binance-api.php | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 834c7f8..e6be222 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -148,7 +148,7 @@ public function __set(string $member, $value) * @param $file string file location * @return null */ - protected function setupApiConfigFromFile(string $file = null) + protected function setupApiConfigFromFile(?string $file = null) { $file = is_null($file) ? getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json" : $file; @@ -174,7 +174,7 @@ protected function setupApiConfigFromFile(string $file = null) * @param $file string file location * @return null */ - protected function setupCurlOptsFromFile(string $file = null) + protected function setupCurlOptsFromFile(?string $file = null) { $file = is_null($file) ? getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json" : $file; @@ -197,7 +197,7 @@ protected function setupCurlOptsFromFile(string $file = null) * * @return null */ - protected function setupProxyConfigFromFile(string $file = null) + protected function setupProxyConfigFromFile(?string $file = null) { $file = is_null($file) ? getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json" : $file; @@ -613,7 +613,7 @@ public function orders(string $symbol, int $limit = 500, int $fromOrderId = 0, a * @return array with error message or array of orderDetails array * @throws \Exception */ - public function history(string $symbol, int $limit = 500, int $fromTradeId = -1, int $startTime = null, int $endTime = null, array $params = []) + public function history(string $symbol, int $limit = 500, int $fromTradeId = -1, ?int $startTime = null, ?int $endTime = null, array $params = []) { $request = [ "symbol" => $symbol, @@ -640,7 +640,7 @@ public function history(string $symbol, int $limit = 500, int $fromTradeId = -1, * @return array with error message or array of orderDetails array * @throws \Exception */ - public function myTrades(string $symbol, int $limit = 500, int $fromTradeId = -1, int $startTime = null, int $endTime = null, array $params = []) + public function myTrades(string $symbol, int $limit = 500, int $fromTradeId = -1, ?int $startTime = null, ?int $endTime = null, array $params = []) { return $this->history($symbol, $limit, $fromTradeId, $startTime, $endTime, $params); } @@ -953,7 +953,7 @@ public function depositAddress(string $asset, $network = null, array $params = [ * @return array containing the response * @throws \Exception */ - public function depositHistory(string $asset = null, array $params = []) + public function depositHistory(?string $asset = null, array $params = []) { $request = array(); if (is_null($asset) === false) { @@ -987,7 +987,7 @@ public function depositHistory(string $asset = null, array $params = []) * @return array containing the response * @throws \Exception */ - public function withdrawHistory(string $asset = null, array $params = []) + public function withdrawHistory(?string $asset = null, array $params = []) { $request = array(); if (is_null($asset) === false) { @@ -1212,7 +1212,7 @@ public function account(array $params = []) * @return array with error message or array of prevDay change * @throws \Exception */ - public function prevDay(string $symbol = null, array $params = []) + public function prevDay(?string $symbol = null, array $params = []) { $request = []; if (is_null($symbol) === false) { @@ -1839,7 +1839,7 @@ public function order(string $side, string $symbol, $quantity, $price, string $t * @return array containing the response * @throws \Exception */ - public function candlesticks(string $symbol, string $interval = "5m", int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function candlesticks(string $symbol, string $interval = "5m", ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { if (!isset($this->charts[$symbol])) { $this->charts[$symbol] = []; @@ -2267,7 +2267,7 @@ public function displayDepth(array $array) * @param $json array of the depth infomration * @return array of the depth information */ - protected function depthData(string $symbol, array $json, string $product_type = null) + protected function depthData(string $symbol, array $json, ?string $product_type = null) { $bids = $asks = []; foreach ($json['bids'] as $obj) { @@ -2672,7 +2672,7 @@ public function ticker($symbol, callable $callback) * @return null * @throws \Exception */ - public function chart($symbols, string $interval = "30m", callable $callback = null, $limit = 500) + public function chart($symbols, string $interval = "30m", ?callable $callback = null, $limit = 500) { if (is_null($callback)) { throw new Exception("You must provide a valid callback"); @@ -2756,7 +2756,7 @@ public function chart($symbols, string $interval = "30m", callable $callback = n * @return null * @throws \Exception */ - public function kline($symbols, string $interval = "30m", callable $callback = null) + public function kline($symbols, string $interval = "30m", ?callable $callback = null) { if (is_null($callback)) { throw new Exception("You must provide a valid callback"); @@ -3413,7 +3413,7 @@ public function futuresExchangeInfo(array $params = []) * @return array with error message or array of market depth * @throws \Exception */ - public function futuresDepth(string $symbol, int $limit = null, array $params = []) + public function futuresDepth(string $symbol, ?int $limit = null, array $params = []) { if (isset($symbol) === false || is_string($symbol) === false) { // WPCS: XSS OK. @@ -3458,7 +3458,7 @@ public function futuresDepth(string $symbol, int $limit = null, array $params = * @return array containing the response * @throws \Exception */ - public function futuresRecentTrades(string $symbol, int $limit = null, array $params = []) + public function futuresRecentTrades(string $symbol, ?int $limit = null, array $params = []) { $request = [ 'symbol' => $symbol, @@ -3517,7 +3517,7 @@ public function futuresHistoricalTrades(string $symbol, $limit = null, $tradeId * @return array with error message or array of market history * @throws \Exception */ - public function futuresAggTrades(string $symbol, int $fromId = null, int $startTime = null, int $endTime = null, int $limit = null, array $params = []) + public function futuresAggTrades(string $symbol, ?int $fromId = null, ?int $startTime = null, ?int $endTime = null, ?int $limit = null, array $params = []) { $request = [ 'symbol' => $symbol, @@ -3560,7 +3560,7 @@ public function futuresAggTrades(string $symbol, int $fromId = null, int $startT * @return array containing the response * @throws \Exception */ - public function futuresCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresCandlesticks(string $symbol, string $interval = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'klines', null, $params); } @@ -3589,7 +3589,7 @@ public function futuresCandlesticks(string $symbol, string $interval = '5m', int * @return array containing the response * @throws \Exception */ - public function futuresContinuousCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, $contractType = 'PERPETUAL', array $params = []) + public function futuresContinuousCandlesticks(string $symbol, string $interval = '5m', ?int $limit = null, $startTime = null, $endTime = null, $contractType = 'PERPETUAL', array $params = []) { return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'continuousKlines', $contractType, $params); } @@ -3617,7 +3617,7 @@ public function futuresContinuousCandlesticks(string $symbol, string $interval = * @return array containing the response * @throws \Exception */ - public function futuresIndexPriceCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresIndexPriceCandlesticks(string $symbol, string $interval = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'indexPriceKlines', null, $params); } @@ -3645,7 +3645,7 @@ public function futuresIndexPriceCandlesticks(string $symbol, string $interval = * @return array containing the response * @throws \Exception */ - public function futuresMarkPriceCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresMarkPriceCandlesticks(string $symbol, string $interval = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'markPriceKlines', null, $params); } @@ -3673,7 +3673,7 @@ public function futuresMarkPriceCandlesticks(string $symbol, string $interval = * @return array containing the response * @throws \Exception */ - public function futuresPremiumIndexCandlesticks(string $symbol, string $interval = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresPremiumIndexCandlesticks(string $symbol, string $interval = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'premiumIndexKlines', null, $params); } @@ -3747,7 +3747,7 @@ private function futuresCandlesticksHelper($symbol, $interval, $limit, $startTim * @return array containing the response * @throws \Exception */ - public function futuresMarkPrice(string $symbol = null, array $params = []) + public function futuresMarkPrice(?string $symbol = null, array $params = []) { $request = []; if ($symbol) { @@ -3772,7 +3772,7 @@ public function futuresMarkPrice(string $symbol = null, array $params = []) * @return array containing the response * @throws \Exception */ - public function futuresFundingRateHistory(string $symbol = null, int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresFundingRateHistory(?string $symbol = null, ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { $request = []; if ($symbol) { @@ -3823,7 +3823,7 @@ public function futuresFundingInfo(array $params = []) * @return array containing the response * @throws \Exception */ - public function futuresPrevDay(string $symbol = null, array $params = []) + public function futuresPrevDay(?string $symbol = null, array $params = []) { $request = []; if ($symbol) { @@ -3936,7 +3936,7 @@ public function futuresPricesV2(array $params = []) * @return array containing the response * @throws \Exception */ - public function futuresSymbolOrderBookTicker(string $symbol = null, array $params = []): array + public function futuresSymbolOrderBookTicker(?string $symbol = null, array $params = []): array { $request = []; if ($symbol) { @@ -4026,7 +4026,7 @@ private function sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $lim * @return array containing the response * @throws \Exception */ - public function futuresOpenInterestHistory(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresOpenInterestHistory(string $symbol, string $period = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'openInterestHist', $params); } @@ -4047,7 +4047,7 @@ public function futuresOpenInterestHistory(string $symbol, string $period = '5m' * @return array containing the response * @throws \Exception */ - public function futuresTopLongShortPositionRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresTopLongShortPositionRatio(string $symbol, string $period = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortPositionRatio', $params); } @@ -4068,7 +4068,7 @@ public function futuresTopLongShortPositionRatio(string $symbol, string $period * @return array containing the response * @throws \Exception */ - public function futuresTopLongShortAccountRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresTopLongShortAccountRatio(string $symbol, string $period = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'topLongShortAccountRatio', $params); } @@ -4089,7 +4089,7 @@ public function futuresTopLongShortAccountRatio(string $symbol, string $period = * @return array containing the response * @throws \Exception */ - public function futuresGlobalLongShortAccountRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresGlobalLongShortAccountRatio(string $symbol, string $period = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'globalLongShortAccountRatio', $params); } @@ -4110,7 +4110,7 @@ public function futuresGlobalLongShortAccountRatio(string $symbol, string $perio * @return array containing the response * @throws \Exception */ - public function futuresTakerLongShortRatio(string $symbol, string $period = '5m', int $limit = null, $startTime = null, $endTime = null, array $params = []) + public function futuresTakerLongShortRatio(string $symbol, string $period = '5m', ?int $limit = null, $startTime = null, $endTime = null, array $params = []) { return $this->sapieriodLimitStartEndFuturesDataRequest($symbol, $period, $limit, $startTime, $endTime, 'takerlongshortRatio', $params); } @@ -4191,7 +4191,7 @@ public function futuresIndexInfo(string $symbol, array $params = []) * @return array containing the response * @throws \Exception */ - public function futuresAssetIndex(string $symbol = null, array $params = []) + public function futuresAssetIndex(?string $symbol = null, array $params = []) { $request = []; if ($symbol) { @@ -5674,7 +5674,7 @@ public function futuresTradingStatus($symbol = null, array $params = []) * futuresDownloadId * helper for other metods for getting download id */ - protected function futuresDownloadId($startTime, $endTime, array $params = null, string $url = '') + protected function futuresDownloadId($startTime, $endTime, ?array $params = null, string $url = '') { $request = [ 'startTime' => $startTime, @@ -5688,7 +5688,7 @@ protected function futuresDownloadId($startTime, $endTime, array $params = null, * futuresDownloadLinkByDownloadId * helper for other metods for getting download link by download id */ - protected function futuresDownloadLinkByDownloadId(string $downloadId, array $params = null, string $url = '') + protected function futuresDownloadLinkByDownloadId(string $downloadId, ?array $params = null, string $url = '') { $request = [ 'downloadId' => $downloadId,