From 967c9b502e47fceaccd8f0d97c898182768ca1fd Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:45:31 +0300 Subject: [PATCH 01/17] Some static tests added --- tests/BinanceStaticTests.php | 412 ++++++++++++++++++++++++++++++++++- 1 file changed, 410 insertions(+), 2 deletions(-) diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index b44c1ea9..c1947d20 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -4,7 +4,6 @@ require_once __DIR__ . '/../php-binance-api.php'; // Adjust path if needed - class MockBinanceAPI extends Binance\API { public function curl_exec($handler) @@ -32,9 +31,64 @@ class BinanceStaticTests extends TestCase private $SPOT_ORDER_PREFIX = "x-HNA2TXFJ"; private $CONTRACT_ORDER_PREFIX = "x-Cb7ytekJ"; + // Default values for the tests + private $symbol = 'ETHUSDT'; + private $quantity = '1.234'; + private $price = '1000'; + private $type = 'LIMIT'; + private $orderid = '000'; + private $limit = 2; + private $fromOrderId = 1; + private $fromTradeId = 2; + private $startTime = 0; + private $endTime = 6; + private $symbols = ['ETHUSDT','BTCUSDT']; + private $asset = 'USDT'; + private $assets = ['IOST','AAVE','CHZ']; + private $address = '0x1234567890abcdef1234567890abcdef12345678'; + private $amount = 10.1; + private $addressTag = '123456'; + private $addressName = 'My Address'; + private $transactionFeeFlag = true; + private $network = 'TEST Network'; + private $fromSymbol = 'USDT'; + private $toSymbol = 'BNB'; + private $recvWindow = 1000; + private $current = 2; + private $tradeId = 3; + private $side = 'BUY'; + private $test = false; + private $interval = '15m'; + private $nbrDays = 6; + private $baseAsset = 'ETH'; + private $quoteAsset = 'USDT'; + private $quoteQty = 10.3; + private $fromId = 1; + private $contractType = 'CURRENT_QUARTER'; + private $period = '15m'; + private $origClientOrderId = 'test client order id'; + private $orderIdList = ['123456', '654321']; + private $origClientOrderIdList = ['test client order id 1', 'test client order id 2']; + private $countdownTime = 100; + private $autoCloseType = 'LIQUIDATION'; + private $marginType = 'CROSSED'; + private $dualSidePosition = true; + private $leverage = 10; + private $multiAssetsMarginMode = true; + private $positionSide = 'SHORT'; + private $incomeType = 'COMMISSION_REBATE'; + private $page = 3; + private $downloadId = 'test download id'; + private $fromAsset = 'USDT'; + private $toAsset = 'BNB'; + private $fromAmount = '100'; + private $validTime = '10s'; + private $quoteId = 'test quote id'; + public function setUp(): void { $this->binance = new MockBinanceAPI('api_key', 'api_secret'); } + public function testPricesSpot() { try { @@ -66,6 +120,361 @@ public function testSpotOrder() $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); } + public function testSpotBuy() + { + try { + $this->binance->buy($this->symbol, $this->quantity, $this->price, $this->type); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->type, $params['type']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotBuyTest() + { + try { + $this->binance->buyTest($this->symbol, $this->quantity, $this->price, $this->type); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order/test", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->type, $params['type']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotSell() + { + try { + $this->binance->sell($this->symbol, $this->quantity, $this->price, $this->type); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->type, $params['type']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotSellTest() + { + try { + $this->binance->sellTest($this->symbol, $this->quantity, $this->price, $this->type); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order/test", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->type, $params['type']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotMarketQuoteBuy() + { + try { + $this->binance->marketQuoteBuy($this->symbol, $this->quantity); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quoteOrderQty']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotMarketQuoteBuyTest() + { + try { + $this->binance->marketQuoteBuyTest($this->symbol, $this->quantity); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order/test", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quoteOrderQty']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotMarketBuy() + { + try { + $this->binance->marketBuy($this->symbol, $this->quantity); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotMarketBuyTest() + { + try { + $this->binance->marketBuyTest($this->symbol, $this->quantity); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order/test", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotMarketQuoteSell() + { + try { + $this->binance->marketQuoteSell($this->symbol, 1); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals(1, $params['quoteOrderQty']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotMarketQuoteSellTest() + { + try { + $this->binance->marketQuoteSellTest($this->symbol, 1); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order/test", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals(1, $params['quoteOrderQty']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotMarketSell() + { + try { + $this->binance->marketSell($this->symbol, 1); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals(1, $params['quantity']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotMarketSellTest() + { + try { + $this->binance->marketSellTest($this->symbol, $this->quantity); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/order/test", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); + } + + public function testSpotCancel() + { + try { + $this->binance->cancel($this->symbol, $this->orderid); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'orderId' => $this->orderid, + ]); + $endpoint = "https://api.binance.com/api/v3/order?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotOrderStatus() + { + try { + $this->binance->orderStatus($this->symbol, $this->orderid); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'orderId' => $this->orderid, + ]); + $endpoint = "https://api.binance.com/api/v3/order?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotOpenOrders() + { + try { + $this->binance->openOrders($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://api.binance.com/api/v3/openOrders?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotCancelOpenOrders() + { + try { + $this->binance->cancelOpenOrders($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://api.binance.com/api/v3/openOrders?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotOrders() + { + try { + $this->binance->orders($this->symbol, $this->limit, $this->fromOrderId); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'orderId' => $this->fromOrderId, + ]); + $endpoint = "https://api.binance.com/api/v3/allOrders?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotHistory() + { + try { + $this->binance->history($this->symbol, $this->limit, $this->fromTradeId, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'fromId' => $this->fromTradeId, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://api.binance.com/api/v3/myTrades?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotMyTrades() + { + try { + $this->binance->myTrades($this->symbol, $this->limit, $this->fromTradeId, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'fromId' => $this->fromTradeId, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://api.binance.com/api/v3/myTrades?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testUseServerTime() + { + try { + $this->binance->useServerTime(); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/time", self::$capturedUrl); + } + + public function testTime() + { + try { + $this->binance->time(); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/time", self::$capturedUrl); + } + public function testFuturesOrder() { try { @@ -76,7 +485,6 @@ public function testFuturesOrder() $this->assertEquals("https://fapi.binance.com/fapi/v1/order", self::$capturedUrl); parse_str(self::$capturedBody, $params); - print_r($params); $this->assertEquals("BTCUSDT", $params['symbol']); $this->assertEquals("BUY", $params['side']); From da1c056f1515c659597c3173717248a082d1d33d Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Sun, 13 Apr 2025 15:12:38 +0300 Subject: [PATCH 02/17] some fixes for php-binance-api.php --- php-binance-api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index d3d5c02c..37227983 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1091,7 +1091,7 @@ public function transfer(string $type, string $asset, string $amount, $fromSymbo * * @property int $weight 1 * - * @param string $type (optional) type of transfer, e.g. MAIN_MARGIN (@see transfer()) + * @param string $type (mandatory) type of transfer, e.g. MAIN_MARGIN (@see transfer()) * @param string $startTime (optional) start time in milliseconds * @param string $endTime (optional) end time in milliseconds * @param int $limit (optional) the number of records to return (default 10, max 100) @@ -3112,7 +3112,7 @@ public function accountSnapshot($type, $nbrDays = 5, $startTime = 0, $endTime = if ($startTime > 0) $params['startTime'] = $startTime; if ($endTime > 0) - $params['endTime'] = $startTime; + $params['endTime'] = $endTime; if ($nbrDays != 5) $params['limit'] = $nbrDays; @@ -6098,4 +6098,4 @@ public function convertStatus($orderId = null, $quoteId = null) } return $this->httpRequest("v1/convert/orderStatus", 'GET', $params, true); } -} \ No newline at end of file +} From edbe3c18d4ae3ff5c73e5433bf806ab3b0fa22de Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Sun, 13 Apr 2025 15:42:50 +0300 Subject: [PATCH 03/17] tests for spot added --- tests/BinanceStaticTests.php | 550 ++++++++++++++++++++++++++++++++++- 1 file changed, 545 insertions(+), 5 deletions(-) diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index c1947d20..3e4dc1ca 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -35,12 +35,14 @@ class BinanceStaticTests extends TestCase private $symbol = 'ETHUSDT'; private $quantity = '1.234'; private $price = '1000'; + private $stopprice = '1100'; + private $stoplimitprice = '900'; private $type = 'LIMIT'; private $orderid = '000'; private $limit = 2; private $fromOrderId = 1; private $fromTradeId = 2; - private $startTime = 0; + private $startTime = 1; private $endTime = 6; private $symbols = ['ETHUSDT','BTCUSDT']; private $asset = 'USDT'; @@ -48,9 +50,9 @@ class BinanceStaticTests extends TestCase private $address = '0x1234567890abcdef1234567890abcdef12345678'; private $amount = 10.1; private $addressTag = '123456'; - private $addressName = 'My Address'; + private $addressName = 'MyAddress'; private $transactionFeeFlag = true; - private $network = 'TEST Network'; + private $network = 'TESTNetwork'; private $fromSymbol = 'USDT'; private $toSymbol = 'BNB'; private $recvWindow = 1000; @@ -78,12 +80,12 @@ class BinanceStaticTests extends TestCase private $positionSide = 'SHORT'; private $incomeType = 'COMMISSION_REBATE'; private $page = 3; - private $downloadId = 'test download id'; + private $downloadId = 'testDownloadId'; private $fromAsset = 'USDT'; private $toAsset = 'BNB'; private $fromAmount = '100'; private $validTime = '10s'; - private $quoteId = 'test quote id'; + private $quoteId = 'testQuoteId'; public function setUp(): void { $this->binance = new MockBinanceAPI('api_key', 'api_secret'); @@ -475,6 +477,544 @@ public function testTime() $this->assertEquals("https://api.binance.com/api/v3/time", self::$capturedUrl); } + public function testSpotExchangeInfo() + { + try { + $this->binance->exchangeInfo($this->symbols); + + } catch (\Throwable $e) { + + } + $query ='symbols=["' . implode('","', $this->symbols) . '"]'; + $endpoint = "https://api.binance.com/api/v3/exchangeInfo?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testAssetDetail() + { + try { + $this->binance->assetDetail($this->asset); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'asset' => $this->asset, + ]); + $endpoint = "https://api.binance.com/sapi/v1/asset/assetDetail?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotDustLog() + { + try { + $this->binance->dustLog($this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://api.binance.com/sapi/v1/asset/dribblet?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotTradeFee() + { + try { + $this->binance->tradeFee($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://api.binance.com/sapi/v1/asset/tradeFee?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotCommissionFee() + { + try { + $this->binance->commissionFee($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://api.binance.com/sapi/v1/asset/tradeFee?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testWithdraw() + { + try { + $this->binance->withdraw($this->asset, $this->address, $this->amount, $this->addressTag, $this->addressName, $this->transactionFeeFlag, $this->network, $this->orderId); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/sapi/v1/capital/withdraw/apply", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->asset, $params['coin']); + $this->assertEquals($this->address, $params['address']); + $this->assertEquals($this->amount, $params['amount']); + $this->assertEquals($this->addressTag, $params['addressTag']); + $this->assertEquals($this->addressName, $params['name']); + $this->assertEquals($this->transactionFeeFlag, $params['transactionFeeFlag']); + $this->assertEquals($this->network, $params['network']); + $this->assertEquals($this->orderId, $params['withdrawOrderId']); + } + + public function testDepositAddress() + { + try { + $this->binance->depositAddress($this->asset, $this->network); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'coin' => $this->asset, + 'network' => $this->network, + ]); + $endpoint = "https://api.binance.com/sapi/v1/capital/deposit/address?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testDepositHistory() + { + try { + $this->binance->depositHistory($this->asset); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'coin' => $this->asset, + ]); + $endpoint = "https://api.binance.com/sapi/v1/capital/deposit/hisrec?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testWithdrawHistory() + { + try { + $this->binance->withdrawHistory($this->asset); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'coin' => $this->asset, + ]); + $endpoint = "https://api.binance.com/sapi/v1/capital/withdraw/history?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testWithdrawFee() + { + try { + $this->binance->withdrawFee($this->asset); + + } catch (\Throwable $e) { + + } + $endpoint = "https://api.binance.com/sapi/v1/asset/assetDetail"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testTransfer() + { + try { + $this->binance->transfer($this->type, $this->asset, $this->amount, $this->fromSymbol, $this->toSymbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v1/asset/transfer", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->type, $params['type']); + $this->assertEquals($this->asset, $params['asset']); + $this->assertEquals($this->amount, $params['amount']); + $this->assertEquals($this->fromSymbol, $params['fromSymbol']); + $this->assertEquals($this->toSymbol, $params['toSymbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testTransfersHistory() + { + try { + $this->binance->transfersHistory($this->type, $this->startTime, $this->endTime, $this->limit, $this->current, $this->fromSymbol, $this->toSymbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'type' => $this->type, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + 'size' => $this->limit, + 'current' => $this->current, + 'fromSymbol' => $this->fromSymbol, + 'toSymbol' => $this->toSymbol, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://api.binance.com/api/v1/asset/transfer?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotPrices() + { + try { + $this->binance->prices(); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/ticker/price", self::$capturedUrl); + } + + public function testSpotPrice() + { + try { + $this->binance->price($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://api.binance.com/api/v3/ticker/price?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testSpotBookPrices() + { + try { + $this->binance->bookPrices(); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://api.binance.com/api/v3/ticker/bookTicker", self::$capturedUrl); + } + + public function testSpotAccount() + { + try { + $this->binance->account(); + + } catch (\Throwable $e) { + + } + $this->assertTrue(str_starts_with(self::$capturedUrl, "https://api.binance.com/api/v3/account")); + } + + public function testSpotPrevDay() + { + try { + $this->binance->prevDay($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://api.binance.com/api/v1/ticker/24hr?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSotAggTrades() + { + try { + $this->binance->aggTrades($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://api.binance.com/api/v1/aggTrades?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotHistoricalTrades() + { + try { + $this->binance->historicalTrades($this->symbol, $this->limit); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + ]); + $endpoint = "https://api.binance.com/api/v3/trades?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotHistoricalTradesWithTradeId() + { + try { + $this->binance->historicalTrades($this->symbol, $this->limit, $this->tradeId); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'fromId' => $this->tradeId, + ]); + $endpoint = "https://api.binance.com/api/v3/historicalTrades?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotDepth() + { + try { + $this->binance->depth($this->symbol, $this->limit); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + ]); + $endpoint = "https://api.binance.com/api/v1/depth?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotBalances() + { + try { + $this->binance->balances(); + + } catch (\Throwable $e) { + + } + $endpoint = "https://api.binance.com/api/v3/account"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + parse_str(self::$capturedBody, $params); + } + + public function testFuturesBalances() + { + try { + $this->binance->balances('futures', $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v2/balance?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesBalancesV3() + { + try { + $this->binance->balances('futures', $this->recvWindow, 'v3'); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v3/balance?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testCoins() + { + try { + $this->binance->coins(); + + } catch (\Throwable $e) { + + } + $this->assertTrue(str_starts_with(self::$capturedUrl, "https://api.binance.com/sapi/v1/capital/config/getall")); + } + + public function testSpotCandlesticks() + { + try { + $this->binance->candlesticks($this->symbol, $this->interval, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'interval' => $this->interval, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://api.binance.com/api/v1/klines?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testSpotAccountSnapshot() + { + try { + $this->binance->accountSnapshot('SPOT', $this->nbrDays, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'type' => 'SPOT', + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + 'limit' => $this->nbrDays, + ]); + $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testMarginAccountSnapshot() + { + try { + $this->binance->accountSnapshot('MARGIN', $this->nbrDays, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'type' => 'MARGIN', + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + 'limit' => $this->nbrDays, + ]); + $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesAccountSnapshot() + { + try { + $this->binance->accountSnapshot('FUTURES', $this->nbrDays, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'type' => 'FUTURES', + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + 'limit' => $this->nbrDays, + ]); + $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testAccountStatus() + { + try { + $this->binance->accountStatus(); + + } catch (\Throwable $e) { + + } + $this->assertTrue(str_starts_with(self::$capturedUrl, "https://api.binance.com/sapi/v1/account/status")); + } + + public function testApiRestrictions() + { + try { + $this->binance->apiRestrictions(); + + } catch (\Throwable $e) { + + } + $this->assertTrue(str_starts_with(self::$capturedUrl, "https://api.binance.com/sapi/v1/account/apiRestrictions")); + } + + public function testApiTradingStatus() + { + try { + $this->binance->apiTradingStatus(); + + } catch (\Throwable $e) { + + } + $this->assertTrue(str_starts_with(self::$capturedUrl, "https://api.binance.com/sapi/v1/account/apiTradingStatus")); + } + + public function testOcoOrder() + { + try { + $this->binance->ocoOrder($this->side, $this->symbol, $this->quantity, $this->price, $this->stopprice, $this->stoplimitprice, $this->stoplimittimeinforce); + + } catch (\Throwable $e) { + print_r($e); + } + $this->assertEquals("https://api.binance.com/api/v3/order/oco", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->side, $params['side']); + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->stopprice, $params['stopPrice']); + $this->assertEquals($this->stoplimitprice, $params['stopLimitPrice']); + $this->assertEquals('GTC', $params['stopLimitTimeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX_ORDER_PREFIX)); + } + + public function testSpotAvgPrice() + { + try { + $this->binance->avgPrice($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://api.binance.com/api/v3/avgPrice?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testBswapQuote() + { + try { + $this->binance->bswapQuote($this->baseAsset, $this->quoteAsset, $this->quoteQty); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'quoteAsset' => $this->quoteAsset, + 'baseAsset' => $this->baseAsset, + 'quoteQty' => $this->quoteQty, + ]); + $endpoint = "https://api.binance.com/sapi/v1/bswap/quote?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + public function testFuturesOrder() { try { From 69a2dd589b1bb1739add15a5ce55dca2f946e568 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Sun, 13 Apr 2025 16:22:40 +0300 Subject: [PATCH 04/17] futuresPremiumIndexKlines renamed to futuresPremiumIndexCandlesticks --- php-binance-api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 37227983..5fa86a3f 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -3588,12 +3588,12 @@ public function futuresMarkPriceCandlesticks(string $symbol, string $interval = } /** - * futuresPremiumIndexKlines get the candles for the given intervals + * futuresPremiumIndexCandlesticks get the candles for the given intervals * 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M * * @link https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data * - * $candles = $api->futuresPremiumIndexKlines("ETHBTC", "5m"); + * $candles = $api->futuresPremiumIndexCandlesticks("ETHBTC", "5m"); * * @property int $weight 5 * for limit < 100 - weight 1 @@ -3610,7 +3610,7 @@ public function futuresMarkPriceCandlesticks(string $symbol, string $interval = * @return array containing the response * @throws \Exception */ - public function futuresPremiumIndexKlines(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) { return $this->futuresCandlesticksHelper($symbol, $interval, $limit, $startTime, $endTime, 'premiumIndexKlines'); } From 4ea3b9304572b170877a46c4b287a686167409a2 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Sun, 13 Apr 2025 16:43:51 +0300 Subject: [PATCH 05/17] symbolPeriodLimitStartEndRequest method name updated --- php-binance-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php-binance-api.php b/php-binance-api.php index 5fa86a3f..60381be9 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -3943,7 +3943,7 @@ public function futuresOpenInterest(string $symbol): array * symbolPeriodLimitStartEndRequest * helper for routing GET methods that require symbol, period, limit, startTime and endTime */ - private function symbolPeriodLimitStartEndContractTypeRequest($symbol, $period, $limit, $startTime, $endTime, $url, $base = 'fapi', $contractType = null) + private function symbolPeriodLimitStartEndRequest($symbol, $period, $limit, $startTime, $endTime, $url, $base = 'fapi', $contractType = null) { $parameters = [ 'symbol' => $symbol, From a024d7dab38d49f3d9484cf50b9c0e532e0ee5df Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Sun, 13 Apr 2025 18:39:28 +0300 Subject: [PATCH 06/17] Editing futures orders updated --- php-binance-api.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 60381be9..4300e99f 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -4477,7 +4477,7 @@ public function futuresSellTest(string $symbol, $quantity = null, $price = null, * @return array containing the request * @throws \Exception */ - protected function createBatchOrdersRequest(array $orders) + protected function createBatchOrdersRequest(array $orders, bool $edit = false) { $formatedOrders = []; for ($index = 0; $index < count($orders); $index++) { @@ -4491,6 +4491,9 @@ protected function createBatchOrdersRequest(array $orders) if (!isset($order['flags'])) { $order['flags'] = []; } + if (!isset($order['type'])) { + $order['type'] = 'LIMIT'; + } $formatedOrder = $this->createFuturesOrderRequest( $order['side'], $order['symbol'], @@ -4503,11 +4506,15 @@ protected function createBatchOrdersRequest(array $orders) // remove recvWindow from the order unset($formatedOrder['recvWindow']); } - if (isset($order['orderId'])) { - $formatedOrder['orderId'] = $order['orderId']; - } - if (isset($order['origClientOrderId'])) { - $formatedOrder['origClientOrderId'] = $order['origClientOrderId']; + if ($edit) { + if (isset($order['orderId'])) { + $formatedOrder['orderId'] = $order['orderId']; + } + if (isset($order['origClientOrderId'])) { + $formatedOrder['origClientOrderId'] = $order['origClientOrderId']; + } + unset($formatedOrder['type']); + unset($formatedOrder['newClientOrderId']); } $formatedOrders[$index] = $formatedOrder; } @@ -4580,6 +4587,7 @@ public function futuresEditOrder(string $symbol, string $side, string $quantity, $opt['orderId'] = $orderId; } unset($opt['type']); + unset($opt['newClientOrderId']); $opt['fapi'] = true; return $this->httpRequest("v1/order", 'PUT', $opt, true); } @@ -4601,14 +4609,13 @@ public function futuresEditOrders(array $orders, $recvWindow = null) $params = [ 'fapi' => true, ]; - $formatedOrders = $this->createBatchOrdersRequest($orders); + $formatedOrders = $this->createBatchOrdersRequest($orders, true); if ($recvWindow) { $params['recvWindow'] = $recvWindow; } // 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, 'PUT', $params, true); + $params['batchOrders'] = json_encode($formatedOrders); + return $this->httpRequest("v1/batchOrders", 'PUT', $params, true); } /** From aa0f51e965de1c6ded2f14774e339cd73c2e72e0 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Sun, 13 Apr 2025 19:03:06 +0300 Subject: [PATCH 07/17] futuresCancelBatchOrders updated --- php-binance-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 4300e99f..e73b0be6 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -4717,8 +4717,8 @@ public function futuresCancelBatchOrders(string $symbol, $orderIdList = null, $o // remove quotes and spaces $params['orderIdList'] = str_replace(' ', '', str_replace('"', '', str_replace("'", '', $idsString))); } else if ($origClientOrderIdList) { - // remove spaces - $params['origClientOrderIdList'] = str_replace(' ', '', json_encode($origClientOrderIdList)); + // remove spaces between the ids + $params['origClientOrderIdList'] = str_replace(', ', ',', json_encode($origClientOrderIdList)); } else { throw new \Exception('futuresCancelBatchOrders: either orderIdList or origClientOrderIdList must be set'); } From 71cadd801da8b18dcbd0e2e6df27c58f7684997b Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Sun, 13 Apr 2025 19:19:24 +0300 Subject: [PATCH 08/17] some futures tests added --- tests/BinanceStaticTests.php | 910 ++++++++++++++++++++++++++++++++++- 1 file changed, 897 insertions(+), 13 deletions(-) diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index 3e4dc1ca..5840dcf1 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -39,6 +39,7 @@ class BinanceStaticTests extends TestCase private $stoplimitprice = '900'; private $type = 'LIMIT'; private $orderid = '000'; + private $orderId = '1234567890'; private $limit = 2; private $fromOrderId = 1; private $fromTradeId = 2; @@ -967,7 +968,7 @@ public function testOcoOrder() $this->binance->ocoOrder($this->side, $this->symbol, $this->quantity, $this->price, $this->stopprice, $this->stoplimitprice, $this->stoplimittimeinforce); } catch (\Throwable $e) { - print_r($e); + } $this->assertEquals("https://api.binance.com/api/v3/order/oco", self::$capturedUrl); @@ -1015,23 +1016,906 @@ public function testBswapQuote() $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); } - public function testFuturesOrder() + public function testFuturesTime() { try { - $this->binance->futuresOrder('BUY', 'BTCUSDT', 1, 1000); - } catch(\Throwable $e) { + $this->binance->futuresTime(); + + } catch (\Throwable $e) { } - $this->assertEquals("https://fapi.binance.com/fapi/v1/order", self::$capturedUrl); + $this->assertEquals("https://fapi.binance.com/fapi/v1/time", self::$capturedUrl); + } - parse_str(self::$capturedBody, $params); + public function testFuturesExchangeInfo() + { + try { + $this->binance->futuresExchangeInfo(); - $this->assertEquals("BTCUSDT", $params['symbol']); - $this->assertEquals("BUY", $params['side']); - $this->assertEquals("LIMIT", $params['type']); - $this->assertEquals(1, $params['quantity']); - $this->assertEquals(1000, $params['price']); - $this->assertEquals("GTC", $params['timeInForce']); - $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->CONTRACT_ORDER_PREFIX)); + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/exchangeInfo", self::$capturedUrl); + } + + public function testFuturesDepth() + { + try { + $this->binance->futuresDepth($this->symbol, $this->limit); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/depth?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesRecentTrades() + { + try { + $this->binance->futuresRecentTrades($this->symbol, $this->limit); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/trades?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesHistoricalTrades() + { + try { + $this->binance->futuresHistoricalTrades($this->symbol, $this->limit, $this->tradeId); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'fromId' => $this->tradeId, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/historicalTrades?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesAggTrades() + { + try { + $this->binance->futuresAggTrades($this->symbol, $this->fromId, $this->startTime, $this->endTime, $this->limit); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'fromId' => $this->fromId, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + 'limit' => $this->limit, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/aggTrades?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesCandlesticks() + { + try { + $this->binance->futuresCandlesticks($this->symbol, $this->interval, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'interval' => $this->interval, + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/klines?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesContinuousCandlesticks() + { + try { + $this->binance->futuresContinuousCandlesticks($this->symbol, $this->interval, $this->limit, $this->startTime, $this->endTime, $this->contractType); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'interval' => $this->interval, + 'pair' => $this->symbol, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + 'contractType' => $this->contractType, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/continuousKlines?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesIndexPriceCandlesticks() + { + try { + $this->binance->futuresIndexPriceCandlesticks($this->symbol, $this->interval, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'interval' => $this->interval, + 'pair' => $this->symbol, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/indexPriceKlines?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesMarkPriceCandlesticks() + { + try { + $this->binance->futuresMarkPriceCandlesticks($this->symbol, $this->interval, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'interval' => $this->interval, + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/markPriceKlines?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesPremiumIndexCandlesticks() + { + try { + $this->binance->futuresPremiumIndexCandlesticks($this->symbol, $this->interval, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'interval' => $this->interval, + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/premiumIndexKlines?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesMarkPrice() + { + try { + $this->binance->futuresMarkPrice($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/premiumIndex?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesFundingRateHistory() + { + try { + $this->binance->futuresFundingRateHistory($this->symbol, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/fundingRate?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesFundingInfo() + { + try { + $this->binance->futuresFundingInfo(); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/fundingInfo", self::$capturedUrl); + } + + public function testFuturesPrevDay() + { + try { + $this->binance->futuresPrevDay($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/ticker/24hr?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesPrice() + { + try { + $this->binance->futuresPrice($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/ticker/price?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesPrices() + { + try { + $this->binance->futuresPrices(); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/ticker/price", self::$capturedUrl); + } + + public function testFuturesPriceV2() + { + try { + $this->binance->futuresPriceV2($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v2/ticker/price?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesSymbolOrderBookTicker() + { + try { + $this->binance->futuresSymbolOrderBookTicker($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/ticker/bookTicker?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesDeliveryPrice() + { + try { + $this->binance->futuresDeliveryPrice($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'pair' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/futures/data/delivery-price?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesOpenInterest() + { + try { + $this->binance->futuresOpenInterest($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/openInterest?" . $query; + $this->assertEquals(self::$capturedUrl, $endpoint); + } + + public function testFuturesOpenInterestHistory() + { + try { + $this->binance->futuresOpenInterestHistory($this->symbol, $this->period, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'period' => $this->period, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/futures/data/openInterestHist?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesTopLongShortPositionRatio() + { + try { + $this->binance->futuresTopLongShortPositionRatio($this->symbol, $this->period, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'period' => $this->period, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/futures/data/topLongShortPositionRatio?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesTopLongShortAccountRatio() + { + try { + $this->binance->futuresTopLongShortAccountRatio($this->symbol, $this->period, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'period' => $this->period, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/futures/data/topLongShortAccountRatio?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesGlobalLongShortAccountRatio() + { + try { + $this->binance->futuresGlobalLongShortAccountRatio($this->symbol, $this->period, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'period' => $this->period, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/futures/data/globalLongShortAccountRatio?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesTakerLongShortRatio() + { + try { + $this->binance->futuresTakerLongShortRatio($this->symbol, $this->period, $this->limit, $this->startTime, $this->endTime); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'period' => $this->period, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/futures/data/takerlongshortRatio?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesBasis() + { + try { + $this->binance->futuresBasis($this->symbol, $this->period, $this->limit, $this->startTime, $this->endTime, $this->contractType); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'pair' => $this->symbol, + 'period' => $this->period, + 'contractType' => $this->contractType, + 'limit' => $this->limit, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + ]); + $endpoint = "https://fapi.binance.com/futures/data/basis?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesIndexInfo() + { + try { + $this->binance->futuresIndexInfo($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/indexInfo?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesAssetIndex() + { + try { + $this->binance->futuresAssetIndex($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/assetIndex?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesConstituents() + { + try { + $this->binance->futuresConstituents($this->symbol); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/indexInfo?" . $query; + $this->assertEquals($endpoint, self::$capturedUrl); + } + + public function testFuturesOrder() + { + try { + $this->binance->futuresOrder('BUY', 'BTCUSDT', 1, 1000); + } catch(\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/order", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals("BTCUSDT", $params['symbol']); + $this->assertEquals("BUY", $params['side']); + $this->assertEquals("LIMIT", $params['type']); + $this->assertEquals(1, $params['quantity']); + $this->assertEquals(1000, $params['price']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->CONTRACT_ORDER_PREFIX)); + } + + public function testFuturesBuy() + { + try { + $this->binance->futuresBuy($this->symbol, $this->quantity, $this->price, $this->type); + + } catch (\Throwable $e) { + + } + + $endpoint = "https://fapi.binance.com/fapi/v1/order"; + $this->assertEquals($endpoint, self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->type, $params['type']); + $this->assertEquals("BUY", $params['side']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->CONTRACT_ORDER_PREFIX)); + } + + public function testFuturesBuyTest() + { + try { + $this->binance->futuresBuyTest($this->symbol, $this->quantity, $this->price, $this->type); + + } catch (\Throwable $e) { + + } + + $endpoint = "https://fapi.binance.com/fapi/v1/order/test"; + $this->assertEquals($endpoint, self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->type, $params['type']); + $this->assertEquals("BUY", $params['side']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->CONTRACT_ORDER_PREFIX)); + } + + public function testFuturesSell() + { + try { + $this->binance->futuresSell($this->symbol, $this->quantity, $this->price, $this->type); + + } catch (\Throwable $e) { + + } + + $endpoint = "https://fapi.binance.com/fapi/v1/order"; + $this->assertEquals($endpoint, self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->type, $params['type']); + $this->assertEquals("SELL", $params['side']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->CONTRACT_ORDER_PREFIX)); + } + + public function testFuturesSellTest() + { + try { + $this->binance->futuresSellTest($this->symbol, $this->quantity, $this->price, $this->type); + + } catch (\Throwable $e) { + + } + + $endpoint = "https://fapi.binance.com/fapi/v1/order/test"; + $this->assertEquals($endpoint, self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->type, $params['type']); + $this->assertEquals("SELL", $params['side']); + $this->assertEquals("GTC", $params['timeInForce']); + $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->CONTRACT_ORDER_PREFIX)); + } + + public function testFuturesBatchOrders() + { + $order = [ + 'symbol' => $this->symbol, + 'side' => $this->side, + 'quantity' => $this->quantity, + 'price' => $this->price, + 'type' => $this->type, + ]; + + try { + $this->binance->futuresBatchOrders([ $order ], $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?batchOrders="; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $ordersString = substr(self::$capturedUrl, strlen($endpoint)); + + $orders = json_decode(urldecode($ordersString), true); + $this->assertEquals($this->symbol, $orders[0]['symbol']); + $this->assertEquals($this->side, $orders[0]['side']); + $this->assertEquals($this->quantity, $orders[0]['quantity']); + $this->assertEquals($this->price, $orders[0]['price']); + $this->assertEquals($this->type, $orders[0]['type']); + $this->assertEquals("GTC", $orders[0]['timeInForce']); + $this->assertTrue(str_starts_with($orders[0]['newClientOrderId'], $this->CONTRACT_ORDER_PREFIX)); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesEditOrder() + { + try { + $this->binance->futuresEditOrder($this->symbol, $this->side, $this->quantity, $this->price, $this->orderId); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/order?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $orderString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($orderString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->side, $params['side']); + $this->assertEquals($this->quantity, $params['quantity']); + $this->assertEquals($this->price, $params['price']); + $this->assertEquals($this->paramsId, $params['paramsId']); + $this->assertEquals("GTC", $params['timeInForce']); + } + + public function testFuturesEditOrders() + { + $order = [ + 'symbol' => $this->symbol, + 'side' => $this->side, + 'quantity' => $this->quantity, + 'price' => $this->price, + 'orderId' => $this->orderId, + ]; + + try { + $this->binance->futuresEditOrders([ $order ], $this->recvWindow); + + } catch (\Throwable $e) { + print_r($e); + } + $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + + $orders = json_decode($params['batchOrders'], true); + $this->assertEquals($this->symbol, $orders[0]['symbol']); + $this->assertEquals($this->side, $orders[0]['side']); + $this->assertEquals($this->quantity, $orders[0]['quantity']); + $this->assertEquals($this->price, $orders[0]['price']); + $this->assertEquals("GTC", $orders[0]['timeInForce']); + } + + public function testFuturesOrderAmendment() + { + try { + $this->binance->futuresOrderAmendment($this->symbol, $this->orderId, $this->origClientOrderId, $this->startTime, $this->endTime, $this->limit, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'orderId' => $this->orderId, + 'origClientOrderId' => $this->origClientOrderId, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + 'limit' => $this->limit, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/orderAmendment?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesCancel() + { + try { + $this->binance->futuresCancel($this->symbol, $this->orderid); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'orderId' => $this->orderid, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/order?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesCancelBatchOrdersByOrderIds() + { + try { + $this->binance->futuresCancelBatchOrders($this->symbol, $this->orderIdList, null, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals('[123456,654321]', $params['orderIdList']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesCancelBatchOrdersByClientOrderIds() + { + try { + $this->binance->futuresCancelBatchOrders($this->symbol, null, $this->origClientOrderIdList, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals('["test client order id 1","test client order id 2"]', $params['origClientOrderIdList']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesCancelOpenOrders() + { + try { + $this->binance->futuresCancelOpenOrders($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/allOpenOrders?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesCountdownCancelAllOrders() + { + try { + $this->binance->futuresCountdownCancelAllOrders($this->symbol, $this->countdownTime, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/countdownCancelAll", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->countdownTime, $params['countdownTime']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesOrderStatusByOrderId() + { + try { + $this->binance->futuresOrderStatus($this->symbol, $this->orderId, null, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'orderId' => $this->orderId, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/order?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesOrderStatusByClientOrderId() + { + try { + $this->binance->futuresOrderStatus($this->symbol, null, $this->origClientOrderId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'origClientOrderId' => $this->origClientOrderId, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/order?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesAllOrders() + { + try { + $this->binance->futuresAllOrders($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'startTime' => $this->startTime, + 'endTime' => $this->endTime, + 'limit' => $this->limit, + 'orderId' => $this->orderId, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/allOrders?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesOpenOrders() + { + try { + $this->binance->futuresOpenOrders($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/openOrders?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesOpenOrderByOrderId() + { + try { + $this->binance->futuresOpenOrder($this->symbol, $this->orderId, null, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'orderId' => $this->orderId, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/openOrder?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + } + + public function testFuturesOpenOrderByClientOrderId() + { + try { + $this->binance->futuresOpenOrder($this->symbol, null, $this->origClientOrderId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'symbol' => $this->symbol, + 'origClientOrderId' => $this->origClientOrderId, + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/openOrder?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); } } From 30bf0291d0f34130e13f48fdaa16237b52a12555 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 15:17:46 +0300 Subject: [PATCH 09/17] Futures tests added --- tests/BinanceStaticTests.php | 772 +++++++++++++++++++++++++++++++++++ 1 file changed, 772 insertions(+) diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index 5840dcf1..a0ab41fd 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -1918,4 +1918,776 @@ public function testFuturesOpenOrderByClientOrderId() $endpoint = "https://fapi.binance.com/fapi/v1/openOrder?" . $query; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); } + + public function testFuturesForceOrders() + { + try { + $this->binance->futuresForceOrders($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->autoCloseType, $this->recvWindow); + + } catch (\Throwable $e) { + + } + + $endpoint = "https://fapi.binance.com/fapi/v1/forceOrders?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->autoCloseType, $params['autoCloseType']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesMyTrades() + { + try { + $this->binance->futuresMyTrades($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, $this->fromId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/userTrades?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->orderId, $params['orderId']); + $this->assertEquals($this->fromId, $params['fromId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesHistory() + { + try { + $this->binance->futuresHistory($this->symbol, $this->startTime, $this->endTime, $this->limit, $this->orderId, $this->fromId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/userTrades?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->orderId, $params['orderId']); + $this->assertEquals($this->fromId, $params['fromId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesSetMarginMode() + { + try { + $this->binance->futuresSetMarginMode($this->symbol, $this->marginType, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/marginType", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->marginType, $params['marginType']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesPositionMode() + { + try { + $this->binance->futuresPositionMode($this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/positionSide/dual?" . $query; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesSetPositionMode() + { + try { + $this->binance->futuresSetPositionMode($this->dualSidePosition, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/positionSide/dual", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->dualSidePosition, $params['dualSidePosition']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesSetLeverage() + { + try { + $this->binance->futuresSetLeverage($this->leverage, $this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/leverage", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->leverage, $params['leverage']); + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesMultiAssetsMarginMode() + { + try { + $this->binance->futuresMultiAssetsMarginMode($this->recvWindow); + + } catch (\Throwable $e) { + + } + $query = http_build_query([ + 'recvWindow' => $this->recvWindow, + ]); + $endpoint = "https://fapi.binance.com/fapi/v1/multiAssetsMargin?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesSetMultiAssetsMarginMode() + { + try { + $this->binance->futuresSetMultiAssetsMarginMode($this->multiAssetsMarginMode, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/multiAssetsMarginMode", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->multiAssetsMarginMode, $params['multiAssetsMarginMode']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesAddMargin() + { + try { + $this->binance->futuresAddMargin($this->symbol, $this->amount, $this->positionSide, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/positionMargin"; + $this->assertEquals($endpoint, self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->amount, $params['amount']); + $this->assertEquals($this->positionSide, $params['positionSide']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + $this->assertEquals(1, $params['type']); + } + + public function testFuturesReduceMargin() + { + try { + $this->binance->futuresReduceMargin($this->symbol, $this->amount, $this->positionSide, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/positionMargin"; + $this->assertEquals($endpoint, self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->amount, $params['amount']); + $this->assertEquals($this->positionSide, $params['positionSide']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + $this->assertEquals(2, $params['type']); + } + + public function testFuturesPositions() + { + try { + $this->binance->futuresPositions($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v3/positionRisk?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesPositionsV2() + { + try { + $this->binance->futuresPositionsV2($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v2/positionRisk?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesPositionsV3() + { + try { + $this->binance->futuresPositionsV3($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v3/positionRisk?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesPosition() + { + try { + $this->binance->futuresPosition($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v3/positionRisk?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesPositionV2() + { + try { + $this->binance->futuresPositionV2($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v2/positionRisk?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesPositionV3() + { + try { + $this->binance->futuresPositionV3($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v3/positionRisk?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesAdlQuantile() + { + try { + $this->binance->futuresAdlQuantile($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/adlQuantile?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesPositionMarginChangeHistory() + { + try { + $this->binance->futuresPositionMarginChangeHistory($this->symbol, $this->startTime, $this->endTime, $this->limit, 'ADD', $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/positionMargin/history?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals(1, $params['addOrReduce']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesAccount() + { + try { + $this->binance->futuresAccount($this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v3/account?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesAccountV2() + { + try { + $this->binance->futuresAccountV2($this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v2/account?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesAccountV3() + { + try { + $this->binance->futuresAccountV3($this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v3/account?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesTradeFee() + { + try { + $this->binance->futuresTradeFee($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/commissionRate?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesAccountConfig() + { + try { + $this->binance->futuresAccountConfig($this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/accountConfig?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesMarginModes() + { + try { + $this->binance->futuresMarginModes($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/symbolConfig?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesOrderRateLimit() + { + try { + $this->binance->futuresOrderRateLimit($this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/rateLimit/order?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesLeverages() + { + try { + $this->binance->futuresLeverages($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/leverageBracket?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesLedger() + { + try { + $this->binance->futuresLedger($this->symbol, $this->incomeType, $this->startTime, $this->endTime, $this->limit, $this->page, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/income?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->incomeType, $params['incomeType']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->page, $params['page']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesTradingStatus() + { + try { + $this->binance->futuresTradingStatus($this->symbol, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/apiTradingStatus?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesDownloadIdForTransactions() + { + try { + $this->binance->futuresDownloadIdForTransactions($this->startTime, $this->endTime, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/income/asyn?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesDownloadTransactionsByDownloadId() + { + try { + $this->binance->futuresDownloadTransactionsByDownloadId($this->downloadId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/income/asyn/id?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->downloadId, $params['downloadId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesDownloadIdForOrders() + { + try { + $this->binance->futuresDownloadIdForOrders($this->startTime, $this->endTime, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/order/asyn?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesDownloadOrdersByDownloadId() + { + try { + $this->binance->futuresDownloadOrdersByDownloadId($this->downloadId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/order/asyn/id?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->downloadId, $params['downloadId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesDownloadIdForTrades() + { + try { + $this->binance->futuresDownloadIdForTrades($this->startTime, $this->endTime, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/trade/asyn?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesDownloadTradesByDownloadId() + { + try { + $this->binance->futuresDownloadTradesByDownloadId($this->downloadId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/trade/asyn/id?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->downloadId, $params['downloadId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesFeeBurn() + { + try { + $this->binance->futuresFeeBurn(true, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/feeBurn", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals('true', $params['feeBurn']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testFuturesFeeBurnStatus() + { + try { + $this->binance->futuresFeeBurnStatus($this->recvWindow); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/feeBurn?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testConvertExchangeInfo() + { + try { + $this->binance->convertExchangeInfo($this->fromAsset, $this->toAsset); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/convert/exchangeInfo?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->fromAsset, $params['fromAsset']); + $this->assertEquals($this->toAsset, $params['toAsset']); + } + + public function testConvertSend() + { + try { + $this->binance->convertSend($this->fromAsset, $this->toAsset, $this->fromAmount, null, $this->validTime, $this->recvWindow); + + } catch (\Throwable $e) { + print_r ($e); + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/convert/getQuote", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->fromAsset, $params['fromAsset']); + $this->assertEquals($this->toAsset, $params['toAsset']); + $this->assertEquals($this->fromAmount, $params['fromAmount']); + $this->assertEquals($this->validTime, $params['validTime']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } + + public function testConvertAccept() + { + try { + $this->binance->convertAccept($this->quoteId, $this->recvWindow); + + } catch (\Throwable $e) { + + } + $this->assertEquals("https://fapi.binance.com/fapi/v1/convert/acceptQuote", self::$capturedUrl); + + parse_str(self::$capturedBody, $params); + + $this->assertEquals($this->quoteId, $params['quoteId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + $this->assertEquals($this->params, $params['params']); + } + + public function testConvertStatusByOrderId() + { + try { + $this->binance->convertStatus($this->orderId, null); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/convert/orderStatus?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->orderId, $params['orderId']); + } + + public function testConvertStatusByQuoteId() + { + try { + $this->binance->convertStatus(null, $this->quoteId); + + } catch (\Throwable $e) { + + } + $endpoint = "https://fapi.binance.com/fapi/v1/convert/orderStatus?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->quoteId, $params['quoteId']); + } } From e7b2341b264c60eed0fd300d5e1c4b5fea996045 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:22:20 +0300 Subject: [PATCH 10/17] Query check is updated Query check is now insensitive to the order of arguments --- tests/BinanceStaticTests.php | 995 +++++++++++++++++++++-------------- 1 file changed, 595 insertions(+), 400 deletions(-) diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index a0ab41fd..f1d5f536 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -347,12 +347,15 @@ public function testSpotCancel() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'orderId' => $this->orderid, - ]); - $endpoint = "https://api.binance.com/api/v3/order?" . $query; + $endpoint = "https://api.binance.com/api/v3/order?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->orderid, $params['orderId']); + } public function testSpotOrderStatus() @@ -363,12 +366,15 @@ public function testSpotOrderStatus() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'orderId' => $this->orderid, - ]); - $endpoint = "https://api.binance.com/api/v3/order?" . $query; + $endpoint = "https://api.binance.com/api/v3/order?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->orderid, $params['orderId']); + } public function testSpotOpenOrders() @@ -379,11 +385,14 @@ public function testSpotOpenOrders() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://api.binance.com/api/v3/openOrders?" . $query; + $endpoint = "https://api.binance.com/api/v3/openOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testSpotCancelOpenOrders() @@ -394,11 +403,14 @@ public function testSpotCancelOpenOrders() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://api.binance.com/api/v3/openOrders?" . $query; + $endpoint = "https://api.binance.com/api/v3/openOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testSpotOrders() @@ -409,13 +421,16 @@ public function testSpotOrders() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'orderId' => $this->fromOrderId, - ]); - $endpoint = "https://api.binance.com/api/v3/allOrders?" . $query; + $endpoint = "https://api.binance.com/api/v3/allOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->fromOrderId, $params['orderId']); + } public function testSpotHistory() @@ -426,15 +441,18 @@ public function testSpotHistory() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'fromId' => $this->fromTradeId, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://api.binance.com/api/v3/myTrades?" . $query; + $endpoint = "https://api.binance.com/api/v3/myTrades?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->fromTradeId, $params['fromId']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testSpotMyTrades() @@ -445,15 +463,18 @@ public function testSpotMyTrades() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'fromId' => $this->fromTradeId, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://api.binance.com/api/v3/myTrades?" . $query; + $endpoint = "https://api.binance.com/api/v3/myTrades?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->fromTradeId, $params['fromId']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testUseServerTime() @@ -499,11 +520,14 @@ public function testAssetDetail() } catch (\Throwable $e) { } - $query = http_build_query([ - 'asset' => $this->asset, - ]); - $endpoint = "https://api.binance.com/sapi/v1/asset/assetDetail?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/asset/assetDetail?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->asset, $params['asset']); + } public function testSpotDustLog() @@ -514,12 +538,15 @@ public function testSpotDustLog() } catch (\Throwable $e) { } - $query = http_build_query([ - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://api.binance.com/sapi/v1/asset/dribblet?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/asset/dribblet?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testSpotTradeFee() @@ -530,11 +557,14 @@ public function testSpotTradeFee() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://api.binance.com/sapi/v1/asset/tradeFee?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/asset/tradeFee?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testSpotCommissionFee() @@ -545,11 +575,14 @@ public function testSpotCommissionFee() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://api.binance.com/sapi/v1/asset/tradeFee?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/asset/tradeFee?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testWithdraw() @@ -582,12 +615,15 @@ public function testDepositAddress() } catch (\Throwable $e) { } - $query = http_build_query([ - 'coin' => $this->asset, - 'network' => $this->network, - ]); - $endpoint = "https://api.binance.com/sapi/v1/capital/deposit/address?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/capital/deposit/address?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->asset, $params['coin']); + $this->assertEquals($this->network, $params['network']); + } public function testDepositHistory() @@ -598,11 +634,14 @@ public function testDepositHistory() } catch (\Throwable $e) { } - $query = http_build_query([ - 'coin' => $this->asset, - ]); - $endpoint = "https://api.binance.com/sapi/v1/capital/deposit/hisrec?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/capital/deposit/hisrec?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->asset, $params['coin']); + } public function testWithdrawHistory() @@ -613,11 +652,14 @@ public function testWithdrawHistory() } catch (\Throwable $e) { } - $query = http_build_query([ - 'coin' => $this->asset, - ]); - $endpoint = "https://api.binance.com/sapi/v1/capital/withdraw/history?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/capital/withdraw/history?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->asset, $params['coin']); + } public function testWithdrawFee() @@ -660,18 +702,21 @@ public function testTransfersHistory() } catch (\Throwable $e) { } - $query = http_build_query([ - 'type' => $this->type, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - 'size' => $this->limit, - 'current' => $this->current, - 'fromSymbol' => $this->fromSymbol, - 'toSymbol' => $this->toSymbol, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://api.binance.com/api/v1/asset/transfer?" . $query; + $endpoint = "https://api.binance.com/api/v1/asset/transfer?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->type, $params['type']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['size']); + $this->assertEquals($this->current, $params['current']); + $this->assertEquals($this->fromSymbol, $params['fromSymbol']); + $this->assertEquals($this->toSymbol, $params['toSymbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testSpotPrices() @@ -693,11 +738,14 @@ public function testSpotPrice() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://api.binance.com/api/v3/ticker/price?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://api.binance.com/api/v3/ticker/price?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testSpotBookPrices() @@ -730,11 +778,14 @@ public function testSpotPrevDay() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://api.binance.com/api/v1/ticker/24hr?" . $query; + $endpoint = "https://api.binance.com/api/v1/ticker/24hr?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testSotAggTrades() @@ -745,11 +796,14 @@ public function testSotAggTrades() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://api.binance.com/api/v1/aggTrades?" . $query; + $endpoint = "https://api.binance.com/api/v1/aggTrades?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testSpotHistoricalTrades() @@ -760,12 +814,15 @@ public function testSpotHistoricalTrades() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - ]); - $endpoint = "https://api.binance.com/api/v3/trades?" . $query; + $endpoint = "https://api.binance.com/api/v3/trades?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + } public function testSpotHistoricalTradesWithTradeId() @@ -776,13 +833,16 @@ public function testSpotHistoricalTradesWithTradeId() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'fromId' => $this->tradeId, - ]); - $endpoint = "https://api.binance.com/api/v3/historicalTrades?" . $query; + $endpoint = "https://api.binance.com/api/v3/historicalTrades?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->tradeId, $params['fromId']); + } public function testSpotDepth() @@ -793,12 +853,15 @@ public function testSpotDepth() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - ]); - $endpoint = "https://api.binance.com/api/v1/depth?" . $query; + $endpoint = "https://api.binance.com/api/v1/depth?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + } public function testSpotBalances() @@ -823,11 +886,14 @@ public function testFuturesBalances() } catch (\Throwable $e) { } - $query = http_build_query([ - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v2/balance?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v2/balance?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesBalancesV3() @@ -838,11 +904,14 @@ public function testFuturesBalancesV3() } catch (\Throwable $e) { } - $query = http_build_query([ - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v3/balance?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v3/balance?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testCoins() @@ -864,15 +933,18 @@ public function testSpotCandlesticks() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'interval' => $this->interval, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://api.binance.com/api/v1/klines?" . $query; + $endpoint = "https://api.binance.com/api/v1/klines?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->interval, $params['interval']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testSpotAccountSnapshot() @@ -883,14 +955,17 @@ public function testSpotAccountSnapshot() } catch (\Throwable $e) { } - $query = http_build_query([ - 'type' => 'SPOT', - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - 'limit' => $this->nbrDays, - ]); - $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals('SPOT', $params['type']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->nbrDays, $params['limit']); + } public function testMarginAccountSnapshot() @@ -901,14 +976,17 @@ public function testMarginAccountSnapshot() } catch (\Throwable $e) { } - $query = http_build_query([ - 'type' => 'MARGIN', - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - 'limit' => $this->nbrDays, - ]); - $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals('MARGIN', $params['type']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->nbrDays, $params['limit']); + } public function testFuturesAccountSnapshot() @@ -919,14 +997,17 @@ public function testFuturesAccountSnapshot() } catch (\Throwable $e) { } - $query = http_build_query([ - 'type' => 'FUTURES', - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - 'limit' => $this->nbrDays, - ]); - $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/accountSnapshot?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals('FUTURES', $params['type']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->nbrDays, $params['limit']); + } public function testAccountStatus() @@ -992,11 +1073,14 @@ public function testSpotAvgPrice() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://api.binance.com/api/v3/avgPrice?" . $query; + $endpoint = "https://api.binance.com/api/v3/avgPrice?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testBswapQuote() @@ -1007,13 +1091,16 @@ public function testBswapQuote() } catch (\Throwable $e) { } - $query = http_build_query([ - 'quoteAsset' => $this->quoteAsset, - 'baseAsset' => $this->baseAsset, - 'quoteQty' => $this->quoteQty, - ]); - $endpoint = "https://api.binance.com/sapi/v1/bswap/quote?" . $query; + $endpoint = "https://api.binance.com/sapi/v1/bswap/quote?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->quoteAsset, $params['quoteAsset']); + $this->assertEquals($this->baseAsset, $params['baseAsset']); + $this->assertEquals($this->quoteQty, $params['quoteQty']); + } public function testFuturesTime() @@ -1046,12 +1133,15 @@ public function testFuturesDepth() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/depth?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v1/depth?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + } public function testFuturesRecentTrades() @@ -1062,12 +1152,15 @@ public function testFuturesRecentTrades() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/trades?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v1/trades?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + } public function testFuturesHistoricalTrades() @@ -1078,13 +1171,16 @@ public function testFuturesHistoricalTrades() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'fromId' => $this->tradeId, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/historicalTrades?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/historicalTrades?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->tradeId, $params['fromId']); + } public function testFuturesAggTrades() @@ -1095,15 +1191,18 @@ public function testFuturesAggTrades() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'fromId' => $this->fromId, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - 'limit' => $this->limit, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/aggTrades?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v1/aggTrades?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->fromId, $params['fromId']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['limit']); + } public function testFuturesCandlesticks() @@ -1114,15 +1213,18 @@ public function testFuturesCandlesticks() } catch (\Throwable $e) { } - $query = http_build_query([ - 'interval' => $this->interval, - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/klines?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v1/klines?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->interval, $params['interval']); + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesContinuousCandlesticks() @@ -1133,16 +1235,19 @@ public function testFuturesContinuousCandlesticks() } catch (\Throwable $e) { } - $query = http_build_query([ - 'interval' => $this->interval, - 'pair' => $this->symbol, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - 'contractType' => $this->contractType, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/continuousKlines?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/continuousKlines?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->interval, $params['interval']); + $this->assertEquals($this->symbol, $params['pair']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->contractType, $params['contractType']); + } public function testFuturesIndexPriceCandlesticks() @@ -1153,15 +1258,18 @@ public function testFuturesIndexPriceCandlesticks() } catch (\Throwable $e) { } - $query = http_build_query([ - 'interval' => $this->interval, - 'pair' => $this->symbol, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/indexPriceKlines?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/indexPriceKlines?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->interval, $params['interval']); + $this->assertEquals($this->symbol, $params['pair']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesMarkPriceCandlesticks() @@ -1172,15 +1280,18 @@ public function testFuturesMarkPriceCandlesticks() } catch (\Throwable $e) { } - $query = http_build_query([ - 'interval' => $this->interval, - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/markPriceKlines?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/markPriceKlines?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->interval, $params['interval']); + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesPremiumIndexCandlesticks() @@ -1191,15 +1302,18 @@ public function testFuturesPremiumIndexCandlesticks() } catch (\Throwable $e) { } - $query = http_build_query([ - 'interval' => $this->interval, - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/premiumIndexKlines?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/premiumIndexKlines?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->interval, $params['interval']); + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesMarkPrice() @@ -1209,12 +1323,15 @@ public function testFuturesMarkPrice() } catch (\Throwable $e) { - } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/premiumIndex?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + } + $endpoint = "https://fapi.binance.com/fapi/v1/premiumIndex?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesFundingRateHistory() @@ -1225,14 +1342,17 @@ public function testFuturesFundingRateHistory() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/fundingRate?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/fundingRate?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesFundingInfo() @@ -1254,11 +1374,14 @@ public function testFuturesPrevDay() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/ticker/24hr?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v1/ticker/24hr?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesPrice() @@ -1269,11 +1392,14 @@ public function testFuturesPrice() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/ticker/price?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v1/ticker/price?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesPrices() @@ -1295,11 +1421,14 @@ public function testFuturesPriceV2() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v2/ticker/price?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v2/ticker/price?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesSymbolOrderBookTicker() @@ -1310,11 +1439,14 @@ public function testFuturesSymbolOrderBookTicker() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/ticker/bookTicker?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v1/ticker/bookTicker?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesDeliveryPrice() @@ -1325,11 +1457,14 @@ public function testFuturesDeliveryPrice() } catch (\Throwable $e) { } - $query = http_build_query([ - 'pair' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/futures/data/delivery-price?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/futures/data/delivery-price?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['pair']); + } public function testFuturesOpenInterest() @@ -1340,11 +1475,14 @@ public function testFuturesOpenInterest() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/openInterest?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://fapi.binance.com/fapi/v1/openInterest?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesOpenInterestHistory() @@ -1355,15 +1493,18 @@ public function testFuturesOpenInterestHistory() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'period' => $this->period, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/futures/data/openInterestHist?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/futures/data/openInterestHist?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->period, $params['period']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesTopLongShortPositionRatio() @@ -1374,15 +1515,18 @@ public function testFuturesTopLongShortPositionRatio() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'period' => $this->period, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/futures/data/topLongShortPositionRatio?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/futures/data/topLongShortPositionRatio?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->period, $params['period']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesTopLongShortAccountRatio() @@ -1393,15 +1537,18 @@ public function testFuturesTopLongShortAccountRatio() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'period' => $this->period, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/futures/data/topLongShortAccountRatio?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/futures/data/topLongShortAccountRatio?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->period, $params['period']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesGlobalLongShortAccountRatio() @@ -1412,15 +1559,18 @@ public function testFuturesGlobalLongShortAccountRatio() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'period' => $this->period, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/futures/data/globalLongShortAccountRatio?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/futures/data/globalLongShortAccountRatio?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->period, $params['period']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesTakerLongShortRatio() @@ -1431,15 +1581,18 @@ public function testFuturesTakerLongShortRatio() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'period' => $this->period, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/futures/data/takerlongshortRatio?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/futures/data/takerlongshortRatio?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->period, $params['period']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesBasis() @@ -1450,16 +1603,19 @@ public function testFuturesBasis() } catch (\Throwable $e) { } - $query = http_build_query([ - 'pair' => $this->symbol, - 'period' => $this->period, - 'contractType' => $this->contractType, - 'limit' => $this->limit, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - ]); - $endpoint = "https://fapi.binance.com/futures/data/basis?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/futures/data/basis?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['pair']); + $this->assertEquals($this->period, $params['period']); + $this->assertEquals($this->contractType, $params['contractType']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + } public function testFuturesIndexInfo() @@ -1470,11 +1626,14 @@ public function testFuturesIndexInfo() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/indexInfo?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/fapi/v1/indexInfo?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesAssetIndex() @@ -1485,11 +1644,14 @@ public function testFuturesAssetIndex() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/assetIndex?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/fapi/v1/assetIndex?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesConstituents() @@ -1500,11 +1662,14 @@ public function testFuturesConstituents() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/indexInfo?" . $query; - $this->assertEquals($endpoint, self::$capturedUrl); + $endpoint = "https://fapi.binance.com/fapi/v1/indexInfo?"; + $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + } public function testFuturesOrder() @@ -1715,17 +1880,20 @@ public function testFuturesOrderAmendment() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'orderId' => $this->orderId, - 'origClientOrderId' => $this->origClientOrderId, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - 'limit' => $this->limit, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/orderAmendment?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/orderAmendment?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->orderId, $params['orderId']); + $this->assertEquals($this->origClientOrderId, $params['origClientOrderId']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesCancel() @@ -1736,12 +1904,15 @@ public function testFuturesCancel() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'orderId' => $this->orderid, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/order?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/order?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->orderid, $params['orderId']); + } public function testFuturesCancelBatchOrdersByOrderIds() @@ -1790,12 +1961,15 @@ public function testFuturesCancelOpenOrders() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/allOpenOrders?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/allOpenOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesCountdownCancelAllOrders() @@ -1823,13 +1997,16 @@ public function testFuturesOrderStatusByOrderId() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'orderId' => $this->orderId, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/order?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/order?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->orderId, $params['orderId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesOrderStatusByClientOrderId() @@ -1840,13 +2017,16 @@ public function testFuturesOrderStatusByClientOrderId() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'origClientOrderId' => $this->origClientOrderId, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/order?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/order?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->origClientOrderId, $params['origClientOrderId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesAllOrders() @@ -1857,16 +2037,19 @@ public function testFuturesAllOrders() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'startTime' => $this->startTime, - 'endTime' => $this->endTime, - 'limit' => $this->limit, - 'orderId' => $this->orderId, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/allOrders?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/allOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->startTime, $params['startTime']); + $this->assertEquals($this->endTime, $params['endTime']); + $this->assertEquals($this->limit, $params['limit']); + $this->assertEquals($this->orderId, $params['orderId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesOpenOrders() @@ -1877,12 +2060,15 @@ public function testFuturesOpenOrders() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/openOrders?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/openOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesOpenOrderByOrderId() @@ -1893,13 +2079,16 @@ public function testFuturesOpenOrderByOrderId() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'orderId' => $this->orderId, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/openOrder?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/openOrder?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->orderId, $params['orderId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesOpenOrderByClientOrderId() @@ -1910,13 +2099,16 @@ public function testFuturesOpenOrderByClientOrderId() } catch (\Throwable $e) { } - $query = http_build_query([ - 'symbol' => $this->symbol, - 'origClientOrderId' => $this->origClientOrderId, - 'recvWindow' => $this->recvWindow, - ]); - $endpoint = "https://fapi.binance.com/fapi/v1/openOrder?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/openOrder?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals($this->origClientOrderId, $params['origClientOrderId']); + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesForceOrders() @@ -2063,9 +2255,6 @@ public function testFuturesMultiAssetsMarginMode() } catch (\Throwable $e) { } - $query = http_build_query([ - 'recvWindow' => $this->recvWindow, - ]); $endpoint = "https://fapi.binance.com/fapi/v1/multiAssetsMargin?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); @@ -2073,6 +2262,12 @@ public function testFuturesMultiAssetsMarginMode() parse_str($queryString, $params); $this->assertEquals($this->recvWindow, $params['recvWindow']); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + + $this->assertEquals($this->recvWindow, $params['recvWindow']); + } public function testFuturesSetMultiAssetsMarginMode() From 42811fe7a0607a3a1fd9716e89d34aa0a0a6fbe9 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:25:00 +0300 Subject: [PATCH 11/17] typo fixed --- php-binance-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php-binance-api.php b/php-binance-api.php index e73b0be6..dffdb76c 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -6061,7 +6061,7 @@ public function convertAccept(string $quoteId, int $recvWindow = null, array $pa $request = [ 'quoteId' => $quoteId, ]; - return $this->fapiRequest("v1/cconvert/acceptQuote", 'POST', array_merge($request, $params), true, $recvWindow); + return $this->fapiRequest("v1/convert/acceptQuote", 'POST', array_merge($request, $params), true, $recvWindow); } /** From 44ff64ec9a6a4c51d8e291128172c0002f8ace1a Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 22:16:54 +0300 Subject: [PATCH 12/17] another typo fixed --- php-binance-api.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index dffdb76c..b916c177 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -3627,11 +3627,11 @@ private function futuresCandlesticksHelper($symbol, $interval, $limit, $startTim if (!isset($this->charts['futures'][$symbol])) { $this->charts['futures'][$symbol] = []; } - if (!isset($this->charts['futures'][$symbol][$type])) { - $this->charts['futures'][$symbol][$type] = []; + if (!isset($this->charts['futures'][$symbol][$contractType])) { + $this->charts['futures'][$symbol][$contractType] = []; } - if (!isset($this->charts['futures'][$symbol][$type][$interval])) { - $this->charts['futures'][$symbol][$type][$interval] = []; + if (!isset($this->charts['futures'][$symbol][$contractType][$interval])) { + $this->charts['futures'][$symbol][$contractType][$interval] = []; } $params = [ 'interval' => $interval, @@ -3800,6 +3800,9 @@ public function futuresPrice(string $symbol) 'fapi' => true, ]; $ticker = $this->httpRequest("v1/ticker/price", "GET", $parameters); + if (!isset($ticker['price'])) { + throw new \Exception("No price found for symbol $symbol"); + } return $ticker['price']; } @@ -3844,6 +3847,9 @@ public function futuresPriceV2(string $symbol) 'fapi' => true, ]; $ticker = $this->httpRequest("v2/ticker/price", "GET", $parameters); + if (!isset($ticker['price'])) { + throw new \Exception("No price found for symbol $symbol"); + } return $ticker['price']; } @@ -6024,6 +6030,8 @@ public function convertSend(string $fromAsset, string $toAsset, $fromAmount = nu 'fromAsset' => $fromAsset, 'toAsset' => $toAsset, ]; + print_r(PHP_EOL); + print_r('convertSend' . PHP_EOL); if ($fromAmount) { $params['fromAmount'] = $fromAmount; } else if ($toAmount) { From 726e266a7da275c525363a902dd81b35883abacf Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 22:19:03 +0300 Subject: [PATCH 13/17] a few `print_r` removed --- php-binance-api.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index b916c177..26d2e834 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -6030,8 +6030,6 @@ public function convertSend(string $fromAsset, string $toAsset, $fromAmount = nu 'fromAsset' => $fromAsset, 'toAsset' => $toAsset, ]; - print_r(PHP_EOL); - print_r('convertSend' . PHP_EOL); if ($fromAmount) { $params['fromAmount'] = $fromAmount; } else if ($toAmount) { From 02b7d720b13220ae4db362209c8855ca5561c4a2 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 22:48:22 +0300 Subject: [PATCH 14/17] A few warnings for empty response added --- php-binance-api.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 26d2e834..fd74c9d9 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -3249,6 +3249,14 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp public function avgPrice(string $symbol) { $ticker = $this->httpRequest("v3/avgPrice", "GET", ["symbol" => $symbol]); + if (is_array($ticker) === false) { + echo "Error: unable to fetch avg price" . PHP_EOL; + $ticker = []; + } + if (empty($ticker)) { + echo "Error: avg price was empty" . PHP_EOL; + return null; + } return $ticker['price']; } @@ -3320,11 +3328,12 @@ public function futuresTime() public function futuresExchangeInfo() { if (!$this->futuresExchangeInfo) { - $arr = array(); - $arr['symbols'] = array(); - $arr = $this->httpRequest("v1/exchangeInfo", "GET", [ 'fapi' => true ]); - + if ((is_array($arr) === false) || empty($arr)) { + echo "Error: unable to fetch futures exchange info" . PHP_EOL; + $arr = array(); + $arr['symbols'] = array(); + } $this->futuresExchangeInfo = $arr; $this->futuresExchangeInfo['symbols'] = null; @@ -3369,6 +3378,13 @@ public function futuresDepth(string $symbol, int $limit = null) $params['limit'] = $limit; } $json = $this->httpRequest("v1/depth", "GET", $params); + if (is_array($json) === false) { + echo "Error: unable to fetch futures depth" . PHP_EOL; + } + if (empty($json)) { + echo "Error: futures depth were empty" . PHP_EOL; + return []; + } if (isset($this->info[$symbol]) === false) { $this->info[$symbol] = []; $this->info[$symbol]['futures'] = []; @@ -3801,7 +3817,8 @@ public function futuresPrice(string $symbol) ]; $ticker = $this->httpRequest("v1/ticker/price", "GET", $parameters); if (!isset($ticker['price'])) { - throw new \Exception("No price found for symbol $symbol"); + echo "Error: unable to fetch futures price for $symbol" . PHP_EOL; + return null; } return $ticker['price']; } @@ -3848,7 +3865,8 @@ public function futuresPriceV2(string $symbol) ]; $ticker = $this->httpRequest("v2/ticker/price", "GET", $parameters); if (!isset($ticker['price'])) { - throw new \Exception("No price found for symbol $symbol"); + echo "Error: unable to fetch futures price for $symbol" . PHP_EOL; + return null; } return $ticker['price']; } From d46a82df029b7438920b52612420caae3dce299d Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 23:18:06 +0300 Subject: [PATCH 15/17] Some other checks for empty response added --- php-binance-api.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index fd74c9d9..c761789d 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1158,7 +1158,10 @@ public function prices() public function price(string $symbol) { $ticker = $this->httpRequest("v3/ticker/price", "GET", ["symbol" => $symbol]); - + if (!isset($ticker['price'])) { + echo "Error: unable to fetch price for $symbol" . PHP_EOL; + return null; + } return $ticker['price']; } @@ -1283,6 +1286,14 @@ public function depth(string $symbol, int $limit = 100) "symbol" => $symbol, "limit" => $limit, ]); + if (is_array($json) === false) { + echo "Error: unable to fetch depth" . PHP_EOL; + $json = []; + } + if (empty($json)) { + echo "Error: depth were empty" . PHP_EOL; + return $json; + } if (isset($this->info[$symbol]) === false) { $this->info[$symbol] = []; } @@ -3380,10 +3391,11 @@ public function futuresDepth(string $symbol, int $limit = null) $json = $this->httpRequest("v1/depth", "GET", $params); if (is_array($json) === false) { echo "Error: unable to fetch futures depth" . PHP_EOL; + $json = []; } if (empty($json)) { echo "Error: futures depth were empty" . PHP_EOL; - return []; + return $json; } if (isset($this->info[$symbol]) === false) { $this->info[$symbol] = []; From a8b7a228a606da70160978ea0a596e8b72d19b3b Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 23:45:12 +0300 Subject: [PATCH 16/17] Another check for empty response added --- php-binance-api.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index c761789d..d154d3c4 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -692,9 +692,6 @@ public function exchangeInfo($symbols = null) { if (!$this->exchangeInfo) { $arr = array(); - $arr['symbols'] = array(); - $parameters = []; - if ($symbols) { if (gettype($symbols) == "string") { $parameters["symbol"] = $symbols; @@ -706,7 +703,11 @@ public function exchangeInfo($symbols = null) } else { $arr = $this->httpRequest("v3/exchangeInfo"); } - + if ((is_array($arr) === false) || empty($arr)) { + echo "Error: unable to fetch spot exchange info" . PHP_EOL; + $arr = array(); + $arr['symbols'] = array(); + } $this->exchangeInfo = $arr; $this->exchangeInfo['symbols'] = null; @@ -921,13 +922,16 @@ public function depositAddress(string $asset, $network = null) $return = $this->httpRequest("v1/capital/deposit/address", "GET", $params, true); // Adding for backwards compatibility with wapi - $return['asset'] = $return['coin']; - $return['addressTag'] = $return['tag']; - - if (!empty($return['address'])) { - $return['success'] = 1; + if (is_array($return) && !empty($return)) { + $return['asset'] = $return['coin']; + $return['addressTag'] = $return['tag']; + if (!empty($return['address'])) { + $return['success'] = 1; + } else { + $return['success'] = 0; + } } else { - $return['success'] = 0; + echo "Error: no deposit address found" . PHP_EOL; } return $return; @@ -955,8 +959,12 @@ public function depositHistory(string $asset = null, array $params = []) $return = $this->httpRequest("v1/capital/deposit/hisrec", "GET", $params, true); // Adding for backwards compatibility with wapi - foreach ($return as $key=>$item) { - $return[$key]['asset'] = $item['coin']; + if (is_array($return) && !empty($return)) { + foreach ($return as $key=>$item) { + $return[$key]['asset'] = $item['coin']; + } + } else { + echo "Error: no deposit history found" . PHP_EOL; } return $return; From 25775ae3ef2016f85214500c9246954a20a8a494 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 14 Apr 2025 23:46:41 +0300 Subject: [PATCH 17/17] most of warnings in tests are handled --- tests/BinanceStaticTests.php | 47 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index f1d5f536..bdacdba5 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -274,16 +274,19 @@ public function testSpotMarketBuyTest() public function testSpotMarketQuoteSell() { try { - $this->binance->marketQuoteSell($this->symbol, 1); + $this->binance->marketQuoteSell($this->symbol, '1'); } catch (\Throwable $e) { } + // warns here cuz method needs information fetched by exchangeInfo $this->assertEquals("https://api.binance.com/api/v3/order", self::$capturedUrl); parse_str(self::$capturedBody, $params); $this->assertEquals($this->symbol, $params['symbol']); + $this->assertEquals('SELL', $params['side']); + $this->assertEquals('MARKET', $params['type']); $this->assertEquals(1, $params['quoteOrderQty']); $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); } @@ -313,12 +316,15 @@ public function testSpotMarketSell() } catch (\Throwable $e) { } + // warns here cuz method needs information fetched by exchangeInfo $this->assertEquals("https://api.binance.com/api/v3/order", self::$capturedUrl); parse_str(self::$capturedBody, $params); $this->assertEquals($this->symbol, $params['symbol']); $this->assertEquals(1, $params['quantity']); + $this->assertEquals('SELL', $params['side']); + $this->assertEquals('MARKET', $params['type']); $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX)); } @@ -507,9 +513,15 @@ public function testSpotExchangeInfo() } catch (\Throwable $e) { } - $query ='symbols=["' . implode('","', $this->symbols) . '"]'; - $endpoint = "https://api.binance.com/api/v3/exchangeInfo?" . $query; - $this->assertEquals(self::$capturedUrl, $endpoint); + $endpoint = "https://api.binance.com/api/v3/exchangeInfo?"; + $this->assertTrue(str_starts_with (self::$capturedUrl, $endpoint)); + + $queryString = substr(self::$capturedUrl, strlen($endpoint)); + parse_str($queryString, $params); + $this->assertTrue(!empty($params['symbols'])); + $symbols = $params['symbols']; + $this->assertTrue(str_contains($symbols, $this->symbols[0])); + $this->assertTrue(str_contains($symbols, $this->symbols[1])); } public function testAssetDetail() @@ -623,7 +635,6 @@ public function testDepositAddress() $this->assertEquals($this->asset, $params['coin']); $this->assertEquals($this->network, $params['network']); - } public function testDepositHistory() @@ -641,7 +652,6 @@ public function testDepositHistory() parse_str($queryString, $params); $this->assertEquals($this->asset, $params['coin']); - } public function testWithdrawHistory() @@ -745,7 +755,6 @@ public function testSpotPrice() parse_str($queryString, $params); $this->assertEquals($this->symbol, $params['symbol']); - } public function testSpotBookPrices() @@ -861,7 +870,6 @@ public function testSpotDepth() $this->assertEquals($this->symbol, $params['symbol']); $this->assertEquals($this->limit, $params['limit']); - } public function testSpotBalances() @@ -1046,7 +1054,7 @@ public function testApiTradingStatus() public function testOcoOrder() { try { - $this->binance->ocoOrder($this->side, $this->symbol, $this->quantity, $this->price, $this->stopprice, $this->stoplimitprice, $this->stoplimittimeinforce); + $this->binance->ocoOrder($this->side, $this->symbol, $this->quantity, $this->price, $this->stopprice, $this->stoplimitprice); } catch (\Throwable $e) { @@ -1062,7 +1070,6 @@ public function testOcoOrder() $this->assertEquals($this->stopprice, $params['stopPrice']); $this->assertEquals($this->stoplimitprice, $params['stopLimitPrice']); $this->assertEquals('GTC', $params['stopLimitTimeInForce']); - $this->assertTrue(str_starts_with($params['newClientOrderId'], $this->SPOT_ORDER_PREFIX_ORDER_PREFIX)); } public function testSpotAvgPrice() @@ -1080,7 +1087,6 @@ public function testSpotAvgPrice() parse_str($queryString, $params); $this->assertEquals($this->symbol, $params['symbol']); - } public function testBswapQuote() @@ -1141,7 +1147,6 @@ public function testFuturesDepth() $this->assertEquals($this->symbol, $params['symbol']); $this->assertEquals($this->limit, $params['limit']); - } public function testFuturesRecentTrades() @@ -1313,7 +1318,6 @@ public function testFuturesPremiumIndexCandlesticks() $this->assertEquals($this->limit, $params['limit']); $this->assertEquals($this->startTime, $params['startTime']); $this->assertEquals($this->endTime, $params['endTime']); - } public function testFuturesMarkPrice() @@ -1428,7 +1432,6 @@ public function testFuturesPriceV2() parse_str($queryString, $params); $this->assertEquals($this->symbol, $params['symbol']); - } public function testFuturesSymbolOrderBookTicker() @@ -1837,8 +1840,8 @@ public function testFuturesEditOrder() $this->assertEquals($this->side, $params['side']); $this->assertEquals($this->quantity, $params['quantity']); $this->assertEquals($this->price, $params['price']); - $this->assertEquals($this->paramsId, $params['paramsId']); - $this->assertEquals("GTC", $params['timeInForce']); + $this->assertEquals($this->orderId, $params['orderId']); + $this->assertEquals('GTC', $params['timeInForce']); } public function testFuturesEditOrders() @@ -1855,7 +1858,7 @@ public function testFuturesEditOrders() $this->binance->futuresEditOrders([ $order ], $this->recvWindow); } catch (\Throwable $e) { - print_r($e); + } $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); @@ -1923,7 +1926,7 @@ public function testFuturesCancelBatchOrdersByOrderIds() } catch (\Throwable $e) { } - $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); $queryString = substr(self::$capturedUrl, strlen($endpoint)); @@ -1942,7 +1945,7 @@ public function testFuturesCancelBatchOrdersByClientOrderIds() } catch (\Throwable $e) { } - $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/batchOrders?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); $queryString = substr(self::$capturedUrl, strlen($endpoint)); @@ -2205,12 +2208,11 @@ public function testFuturesPositionMode() } catch (\Throwable $e) { } - $endpoint = "https://fapi.binance.com/fapi/v1/positionSide/dual?" . $query; + $endpoint = "https://fapi.binance.com/fapi/v1/positionSide/dual?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); $queryString = substr(self::$capturedUrl, strlen($endpoint)); parse_str($queryString, $params); - $this->assertEquals($this->recvWindow, $params['recvWindow']); } @@ -2822,7 +2824,7 @@ public function testConvertSend() $this->binance->convertSend($this->fromAsset, $this->toAsset, $this->fromAmount, null, $this->validTime, $this->recvWindow); } catch (\Throwable $e) { - print_r ($e); + } $this->assertEquals("https://fapi.binance.com/fapi/v1/convert/getQuote", self::$capturedUrl); @@ -2849,7 +2851,6 @@ public function testConvertAccept() $this->assertEquals($this->quoteId, $params['quoteId']); $this->assertEquals($this->recvWindow, $params['recvWindow']); - $this->assertEquals($this->params, $params['params']); } public function testConvertStatusByOrderId()