From 3e1ea8928e235dbbb4ff6d4aa998741541e9e7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 14:36:45 +0300 Subject: [PATCH 01/11] Some live tests added --- tests/BinanceLiveTests.php | 297 +++++++++++++++++++++++++++++++++++++ 1 file changed, 297 insertions(+) diff --git a/tests/BinanceLiveTests.php b/tests/BinanceLiveTests.php index 6539968f..81da1e2f 100644 --- a/tests/BinanceLiveTests.php +++ b/tests/BinanceLiveTests.php @@ -19,6 +19,68 @@ public function setUp(): void { $this->futuresBinance = new API('227719da8d8499e8d3461587d19f259c0b39c2b462a77c9b748a6119abd74401', 'b14b935f9cfacc5dec829008733c40da0588051f29a44625c34967b45c11d73c'); $this->futuresBinance->useTestnet = true; } + + // Default values for the tests + private $symbol = 'ETHUSDT'; + private $quantity = '1.23400000'; + private $price = '1000.00000000'; + private $stopprice = '1100.00000000'; + private $stoplimitprice = '900.00000000'; + private $type = 'LIMIT'; + private $orderid = '000'; + private $orderId = '1234567890'; + private $limit = 2; + private $fromOrderId = 1; + private $fromTradeId = 2; + private $startTime = 1; + 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 = 'MyAddress'; + private $transactionFeeFlag = true; + private $network = 'TESTNetwork'; + 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 = 'testDownloadId'; + private $fromAsset = 'USDT'; + private $toAsset = 'BNB'; + private $fromAmount = '100'; + private $validTime = '10s'; + private $quoteId = 'testQuoteId'; + private $timeInForce = 'GTC'; + + private $SPOT_ORDER_PREFIX = "x-HNA2TXFJ"; + private $CONTRACT_ORDER_PREFIX = "x-Cb7ytekJ"; + public function testPricesSpot() { $res = $this->spotBinance->prices(); @@ -52,4 +114,239 @@ public function testBalanceFutures() $this->assertArrayHasKey('asset', $first); $this->assertArrayHasKey('walletBalance', $first); } + + public function testBuyTestSpot() + { + $res = $this->spotBinance->buyTest($this->symbol, $this->quantity, $this->price, $this->type); + $this->assertIsArray($res); + } + + public function testSellTestSpot() + { + $res = $this->spotBinance->sellTest($this->symbol, $this->quantity, $this->price, $this->type); + $this->assertIsArray($res); + } + + public function testMarketQuoteBuyTestSpot() + { + $res = $this->spotBinance->marketQuoteBuyTest($this->symbol, 10); + $this->assertIsArray($res); + } + + public function testMarketBuyTestSpot() + { + $res = $this->spotBinance->marketBuyTest($this->symbol, $this->quantity); + $this->assertIsArray($res); + } + + public function testMarketQuoteSellTestSpot() + { + $res = $this->spotBinance->marketQuoteSellTest($this->symbol, 10); + $this->assertIsArray($res); + } + + public function testUseServerTimeSpot() + { + $this->spotBinance->useServerTime(); + $offset = $this->spotBinance->info['timeOffset']; + $this->assertTrue(0 !== $offset); + } + + public function testTimeSpot() + { + $res = $this->spotBinance->time(); + $this->assertIsArray($res); + $this->assertArrayHasKey('serverTime', $res); + $this->assertIsInt($res['serverTime']); + } + + public function testExchangeInfoSpot() + { + $res = $this->spotBinance->exchangeInfo($this->symbols); + $this->assertIsArray($res); + $this->assertArrayHasKey('timezone', $res); + $this->assertArrayHasKey('serverTime', $res); + $this->assertIsInt($res['serverTime']); + $this->assertArrayHasKey('rateLimits', $res); + $this->assertIsArray($res['rateLimits']); + $this->assertArrayHasKey('exchangeFilters', $res); + $this->assertIsArray($res['exchangeFilters']); + $this->assertArrayHasKey('symbols', $res); + $this->assertIsArray($res['symbols']); + + // Check if the symbols are present in the exchange info + $symbol1 = $this->symbols[0]; + $symbol2 = $this->symbols[1]; + $symbolsInfo = $this->spotBinance->exchangeInfo['symbols']; + $this->assertArrayHasKey($symbol1, $symbolsInfo); + $this->assertArrayHasKey($symbol2, $symbolsInfo); + $this->assertIsArray($symbolsInfo[$symbol1]); + $this->assertIsArray($symbolsInfo[$symbol2]); + } + + public function testAccountSpot() + { + $res = $this->spotBinance->account(); + $this->assertIsArray($res); + $this->assertArrayHasKey('makerCommission', $res); + $this->assertArrayHasKey('takerCommission', $res); + $this->assertArrayHasKey('buyerCommission', $res); + $this->assertArrayHasKey('sellerCommission', $res); + $this->assertArrayHasKey('commissionRates', $res); + $this->assertIsArray($res['commissionRates']); + $this->assertArrayHasKey('canTrade', $res); + $this->assertArrayHasKey('canWithdraw', $res); + $this->assertArrayHasKey('canDeposit', $res); + $this->assertArrayHasKey('brokered', $res); + $this->assertArrayHasKey('requireSelfTradePrevention', $res); + $this->assertArrayHasKey('preventSor', $res); + $this->assertArrayHasKey('updateTime', $res); + $this->assertArrayHasKey('accountType', $res); + $this->assertEquals('SPOT', $res['accountType']); + $this->assertArrayHasKey('balances', $res); + $this->assertIsArray($res['balances']); + } + + public function testPrevDaySpot() + { + $res = $this->spotBinance->prevDay($this->symbol); + $this->assertIsArray($res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('priceChange', $res); + $this->assertIsNumeric($res['priceChange']); + $this->assertArrayHasKey('priceChangePercent', $res); + $this->assertIsNumeric($res['priceChangePercent']); + $this->assertArrayHasKey('weightedAvgPrice', $res); + $this->assertIsNumeric($res['weightedAvgPrice']); + $this->assertArrayHasKey('prevClosePrice', $res); + $this->assertIsNumeric($res['prevClosePrice']); + $this->assertArrayHasKey('lastPrice', $res); + $this->assertIsNumeric($res['lastPrice']); + $this->assertArrayHasKey('lastQty', $res); + $this->assertIsNumeric($res['lastQty']); + $this->assertArrayHasKey('bidPrice', $res); + $this->assertIsNumeric($res['bidPrice']); + $this->assertArrayHasKey('bidQty', $res); + $this->assertIsNumeric($res['bidQty']); + $this->assertArrayHasKey('askPrice', $res); + $this->assertIsNumeric($res['askPrice']); + $this->assertArrayHasKey('askQty', $res); + $this->assertIsNumeric($res['askQty']); + $this->assertArrayHasKey('openPrice', $res); + $this->assertIsNumeric($res['openPrice']); + $this->assertArrayHasKey('highPrice', $res); + $this->assertIsNumeric($res['highPrice']); + $this->assertArrayHasKey('lowPrice', $res); + $this->assertIsNumeric($res['lowPrice']); + $this->assertArrayHasKey('volume', $res); + $this->assertIsNumeric($res['volume']); + $this->assertArrayHasKey('quoteVolume', $res); + $this->assertIsNumeric($res['quoteVolume']); + $this->assertArrayHasKey('openTime', $res); + $this->assertIsInt($res['openTime']); + $this->assertArrayHasKey('closeTime', $res); + $this->assertIsInt($res['closeTime']); + $this->assertArrayHasKey('firstId', $res); + $this->assertIsInt($res['firstId']); + $this->assertArrayHasKey('lastId', $res); + $this->assertIsInt($res['lastId']); + $this->assertArrayHasKey('count', $res); + $this->assertIsInt($res['count']); + } + + public function testAggTradesSpot() + { + $res = $this->spotBinance->aggTrades($this->symbol); + $this->assertIsArray($res); + $this->assertIsArray($res[0]); + $trade = $res[0]; + $this->assertArrayHasKey('price', $trade); + $this->assertIsNumeric($trade['price']); + $this->assertArrayHasKey('quantity', $trade); + $this->assertIsNumeric($trade['quantity']); + $this->assertArrayHasKey('timestamp', $trade); + $this->assertIsInt($trade['timestamp']); + $this->assertArrayHasKey('maker', $trade); + $this->assertIsString($trade['maker']); + } + + public function testHistoricalTradesSpot() + { + $res = $this->spotBinance->historicalTrades($this->symbol, $this->limit, $this->tradeId); + $this->assertIsArray($res); + $this->assertIsArray($res[0]); + $this->assertArrayHasKey('id', $res[0]); + $this->assertIsNumeric($res[0]['id']); + $this->assertArrayHasKey('price', $res[0]); + $this->assertIsNumeric($res[0]['price']); + $this->assertArrayHasKey('qty', $res[0]); + $this->assertIsNumeric($res[0]['qty']); + $this->assertArrayHasKey('time', $res[0]); + $this->assertIsNumeric($res[0]['time']); + $this->assertArrayHasKey('isBuyerMaker', $res[0]); + $this->assertIsBool($res[0]['isBuyerMaker']); + $this->assertArrayHasKey('isBestMatch', $res[0]); + $this->assertIsBool($res[0]['isBestMatch']); + } + + public function testDepthSpot() + { + $res = $this->spotBinance->depth($this->symbol, $this->limit); + $this->assertIsArray($res); + + $this->assertArrayHasKey('bids', $res); + $this->assertIsArray($res['bids']); + $this->assertArrayHasKey('asks', $res); + $this->assertIsArray($res['asks']); + } + + public function testCandlesticksSpot() + { + $res = $this->spotBinance->candlesticks($this->symbol, $this->interval, $this->limit); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsNumeric($firstKey); + $candle = $res[$firstKey]; + $this->assertArrayHasKey('open', $candle); + $this->assertIsNumeric($candle['open']); + $this->assertArrayHasKey('high', $candle); + $this->assertIsNumeric($candle['high']); + $this->assertArrayHasKey('low', $candle); + $this->assertIsNumeric($candle['low']); + $this->assertArrayHasKey('close', $candle); + $this->assertIsNumeric($candle['close']); + $this->assertArrayHasKey('volume', $candle); + $this->assertIsNumeric($candle['volume']); + $this->assertArrayHasKey('openTime', $candle); + $this->assertIsInt($candle['openTime']); + $this->assertArrayHasKey('closeTime', $candle); + $this->assertIsInt($candle['closeTime']); + $this->assertArrayHasKey('assetVolume', $candle); + $this->assertIsNumeric($candle['assetVolume']); + $this->assertArrayHasKey('baseVolume', $candle); + $this->assertIsNumeric($candle['baseVolume']); + $this->assertArrayHasKey('trades', $candle); + $this->assertIsInt($candle['trades']); + $this->assertArrayHasKey('assetBuyVolume', $candle); + $this->assertIsNumeric($candle['assetBuyVolume']); + $this->assertArrayHasKey('takerBuyVolume', $candle); + $this->assertIsNumeric($candle['takerBuyVolume']); + } + + public function testSystemStatusSpot() + { + $this->spotBinance->useTestnet = false; // set to false for sapi request + $res = $this->spotBinance->systemStatus(); + $this->assertIsArray($res); + $this->assertArrayHasKey('api', $res); + $this->assertIsArray($res['api']); + $this->assertArrayHasKey('status', $res['api']); + $this->assertArrayHasKey('fapi', $res); + $this->assertIsArray($res['fapi']); + $this->assertArrayHasKey('status', $res['fapi']); + $this->assertArrayHasKey('sapi', $res); + $this->assertIsArray($res['sapi']); + $this->assertArrayHasKey('status', $res['sapi']); + $this->spotBinance->useTestnet = true; // reset to true for other tests + } } From e13656499723fea2ad06f2fd97e7a3be248554c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 14:40:41 +0300 Subject: [PATCH 02/11] transfer and transfersHistory updated --- php-binance-api.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/php-binance-api.php b/php-binance-api.php index d154d3c4..91fda78e 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1077,6 +1077,7 @@ public function transfer(string $type, string $asset, string $amount, $fromSymbo 'type' => $type, 'asset' => $asset, 'amount' => $amount, + 'sapi' => true, ]; // todo: check this method with real account if ($fromSymbol) { @@ -1115,6 +1116,7 @@ public function transfersHistory(string $type, $startTime = null, $endTime = nul { $params = [ 'type' => $type, + 'sapi' => true, ]; // todo: check this method with real account if ($startTime) { @@ -6149,4 +6151,4 @@ public function convertStatus($orderId = null, $quoteId = null) } return $this->httpRequest("v1/convert/orderStatus", 'GET', $params, true); } -} +} \ No newline at end of file From 10a48b80eede8d346003b706411f7c68498dde9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 14:42:27 +0300 Subject: [PATCH 03/11] testSystemStatusSpot removed due to the strange error --- tests/BinanceLiveTests.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/BinanceLiveTests.php b/tests/BinanceLiveTests.php index 81da1e2f..c60d3402 100644 --- a/tests/BinanceLiveTests.php +++ b/tests/BinanceLiveTests.php @@ -333,20 +333,21 @@ public function testCandlesticksSpot() $this->assertIsNumeric($candle['takerBuyVolume']); } - public function testSystemStatusSpot() - { - $this->spotBinance->useTestnet = false; // set to false for sapi request - $res = $this->spotBinance->systemStatus(); - $this->assertIsArray($res); - $this->assertArrayHasKey('api', $res); - $this->assertIsArray($res['api']); - $this->assertArrayHasKey('status', $res['api']); - $this->assertArrayHasKey('fapi', $res); - $this->assertIsArray($res['fapi']); - $this->assertArrayHasKey('status', $res['fapi']); - $this->assertArrayHasKey('sapi', $res); - $this->assertIsArray($res['sapi']); - $this->assertArrayHasKey('status', $res['sapi']); - $this->spotBinance->useTestnet = true; // reset to true for other tests - } + // could throw an error: https://github.com/ccxt/php-binance-api/actions/runs/14491775733/job/40649647274?pr=511 + // public function testSystemStatusSpot() + // { + // $this->spotBinance->useTestnet = false; // set to false for sapi request + // $res = $this->spotBinance->systemStatus(); + // $this->assertIsArray($res); + // $this->assertArrayHasKey('api', $res); + // $this->assertIsArray($res['api']); + // $this->assertArrayHasKey('status', $res['api']); + // $this->assertArrayHasKey('fapi', $res); + // $this->assertIsArray($res['fapi']); + // $this->assertArrayHasKey('status', $res['fapi']); + // $this->assertArrayHasKey('sapi', $res); + // $this->assertIsArray($res['sapi']); + // $this->assertArrayHasKey('status', $res['sapi']); + // $this->spotBinance->useTestnet = true; // reset to true for other tests + // } } From 6f846e60e2153057b8c8f8e62ecd72234ad30517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 14:44:31 +0300 Subject: [PATCH 04/11] Static tests for transfer and transfersHistory updated --- tests/BinanceStaticTests.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index bdacdba5..add73821 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -692,7 +692,7 @@ public function testTransfer() } catch (\Throwable $e) { } - $this->assertEquals("https://api.binance.com/api/v1/asset/transfer", self::$capturedUrl); + $this->assertEquals("https://api.binance.com/sapi/v1/asset/transfer", self::$capturedUrl); parse_str(self::$capturedBody, $params); @@ -712,7 +712,7 @@ public function testTransfersHistory() } catch (\Throwable $e) { } - $endpoint = "https://api.binance.com/api/v1/asset/transfer?"; + $endpoint = "https://api.binance.com/sapi/v1/asset/transfer?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); $queryString = substr(self::$capturedUrl, strlen($endpoint)); From d6f1ef1440b645ae8011d52a0e19a811384be1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 15:44:18 +0300 Subject: [PATCH 05/11] Some live tests added --- tests/BinanceLiveTests.php | 380 +++++++++++++++++++++++++++++++++++-- 1 file changed, 363 insertions(+), 17 deletions(-) diff --git a/tests/BinanceLiveTests.php b/tests/BinanceLiveTests.php index c60d3402..9c9dadfa 100644 --- a/tests/BinanceLiveTests.php +++ b/tests/BinanceLiveTests.php @@ -27,13 +27,7 @@ public function setUp(): void { private $stopprice = '1100.00000000'; private $stoplimitprice = '900.00000000'; private $type = 'LIMIT'; - private $orderid = '000'; - private $orderId = '1234567890'; private $limit = 2; - private $fromOrderId = 1; - private $fromTradeId = 2; - private $startTime = 1; - private $endTime = 6; private $symbols = ['ETHUSDT','BTCUSDT']; private $asset = 'USDT'; private $assets = ['IOST','AAVE','CHZ']; @@ -46,8 +40,6 @@ public function setUp(): void { private $fromSymbol = 'USDT'; private $toSymbol = 'BNB'; private $recvWindow = 1000; - private $current = 2; - private $tradeId = 3; private $side = 'BUY'; private $test = false; private $interval = '15m'; @@ -89,14 +81,6 @@ public function testPricesSpot() $this->assertIsString($res['BTCUSDT']); } - public function testPricesFutures() - { - $res = $this->futuresBinance->futuresPrices(); - $this->assertIsArray($res); - $this->assertArrayHasKey('BTCUSDT', $res); - $this->assertIsString($res['BTCUSDT']); - } - public function testBalanceSpot() { $res = $this->spotBinance->balances(); @@ -272,7 +256,7 @@ public function testAggTradesSpot() public function testHistoricalTradesSpot() { - $res = $this->spotBinance->historicalTrades($this->symbol, $this->limit, $this->tradeId); + $res = $this->spotBinance->historicalTrades($this->symbol, $this->limit); $this->assertIsArray($res); $this->assertIsArray($res[0]); $this->assertArrayHasKey('id', $res[0]); @@ -350,4 +334,366 @@ public function testCandlesticksSpot() // $this->assertArrayHasKey('status', $res['sapi']); // $this->spotBinance->useTestnet = true; // reset to true for other tests // } + + public function testAvgPriceSpot() + { + $res = $this->spotBinance->avgPrice($this->symbol); + $this->assertIsNumeric($res); + } + + public function testTimeFutures() + { + $res = $this->futuresBinance->futuresTime(); + $this->assertIsArray($res); + $this->assertArrayHasKey('serverTime', $res); + $this->assertIsInt($res['serverTime']); + } + + public function testExchangeInfoFutures() + { + $res = $this->futuresBinance->futuresExchangeInfo(); + $this->assertIsArray($res); + $this->assertArrayHasKey('timezone', $res); + $this->assertArrayHasKey('serverTime', $res); + $this->assertIsInt($res['serverTime']); + $this->assertArrayHasKey('futuresType', $res); + $this->assertArrayHasKey('rateLimits', $res); + $this->assertIsArray($res['rateLimits']); + $this->assertArrayHasKey('exchangeFilters', $res); + $this->assertIsArray($res['exchangeFilters']); + $this->assertArrayHasKey('assets', $res); + $this->assertIsArray($res['assets']); + $this->assertArrayHasKey('symbols', $res); + $this->assertIsArray($res['symbols']); + } + + public function testDepthFutures() + { + $res = $this->futuresBinance->futuresDepth($this->symbol, 5); + $this->assertIsArray($res); + $this->assertArrayHasKey('bids', $res); + $this->assertIsArray($res['bids']); + $this->assertArrayHasKey('asks', $res); + $this->assertIsArray($res['asks']); + } + + public function testRecentTradesFutures() + { + $res = $this->futuresBinance->futuresRecentTrades($this->symbol, $this->limit); + $this->assertIsArray($res); + $this->assertIsArray($res[0]); + $this->assertArrayHasKey('id', $res[0]); + $this->assertIsNumeric($res[0]['id']); + $this->assertArrayHasKey('price', $res[0]); + $this->assertIsNumeric($res[0]['price']); + $this->assertArrayHasKey('qty', $res[0]); + $this->assertIsNumeric($res[0]['qty']); + $this->assertArrayHasKey('quoteQty', $res[0]); + $this->assertIsNumeric($res[0]['quoteQty']); + $this->assertArrayHasKey('time', $res[0]); + $this->assertIsNumeric($res[0]['time']); + $this->assertArrayHasKey('isBuyerMaker', $res[0]); + $this->assertIsBool($res[0]['isBuyerMaker']); + } + + public function testHistoricalTradesFutures() + { + $res = $this->futuresBinance->futuresHistoricalTrades($this->symbol, $this->limit); + $this->assertIsArray($res); + $this->assertIsArray($res[0]); + $this->assertArrayHasKey('id', $res[0]); + $this->assertIsNumeric($res[0]['id']); + $this->assertArrayHasKey('price', $res[0]); + $this->assertIsNumeric($res[0]['price']); + $this->assertArrayHasKey('qty', $res[0]); + $this->assertIsNumeric($res[0]['qty']); + $this->assertArrayHasKey('quoteQty', $res[0]); + $this->assertIsNumeric($res[0]['quoteQty']); + $this->assertArrayHasKey('time', $res[0]); + $this->assertIsNumeric($res[0]['time']); + $this->assertArrayHasKey('isBuyerMaker', $res[0]); + $this->assertIsBool($res[0]['isBuyerMaker']); + } + + public function testAggTradesFutures() + { + $res = $this->futuresBinance->futuresAggTrades($this->symbol); + $this->assertIsArray($res); + $this->assertIsArray($res[0]); + $this->assertArrayHasKey('price', $res[0]); + $this->assertIsNumeric($res[0]['price']); + $this->assertArrayHasKey('quantity', $res[0]); + $this->assertIsNumeric($res[0]['quantity']); + $this->assertArrayHasKey('timestamp', $res[0]); + $this->assertIsInt($res[0]['timestamp']); + $this->assertArrayHasKey('maker', $res[0]); + $this->assertIsString($res[0]['maker']); + } + + public function testCandlesticksFutures() + { + $res = $this->futuresBinance->futuresCandlesticks($this->symbol, $this->interval, $this->limit); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsNumeric($firstKey); + $candle = $res[$firstKey]; + $this->assertArrayHasKey('open', $candle); + $this->assertIsNumeric($candle['open']); + $this->assertArrayHasKey('high', $candle); + $this->assertIsNumeric($candle['high']); + $this->assertArrayHasKey('low', $candle); + $this->assertIsNumeric($candle['low']); + $this->assertArrayHasKey('close', $candle); + $this->assertIsNumeric($candle['close']); + $this->assertArrayHasKey('volume', $candle); + $this->assertIsNumeric($candle['volume']); + $this->assertArrayHasKey('openTime', $candle); + $this->assertIsInt($candle['openTime']); + $this->assertArrayHasKey('closeTime', $candle); + $this->assertIsInt($candle['closeTime']); + $this->assertArrayHasKey('assetVolume', $candle); + $this->assertIsNumeric($candle['assetVolume']); + $this->assertArrayHasKey('baseVolume', $candle); + $this->assertIsNumeric($candle['baseVolume']); + $this->assertArrayHasKey('trades', $candle); + $this->assertIsInt($candle['trades']); + $this->assertArrayHasKey('assetBuyVolume', $candle); + $this->assertIsNumeric($candle['assetBuyVolume']); + $this->assertArrayHasKey('takerBuyVolume', $candle); + $this->assertIsNumeric($candle['takerBuyVolume']); + } + + public function testContinuousCandlesticksFutures() + { + $res = $this->futuresBinance->futuresContinuousCandlesticks($this->symbol, $this->interval, $this->limit, null, null, $this->contractType); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsNumeric($firstKey); + $candle = $res[$firstKey]; + $this->assertArrayHasKey('open', $candle); + $this->assertIsNumeric($candle['open']); + $this->assertArrayHasKey('high', $candle); + $this->assertIsNumeric($candle['high']); + $this->assertArrayHasKey('low', $candle); + $this->assertIsNumeric($candle['low']); + $this->assertArrayHasKey('close', $candle); + $this->assertIsNumeric($candle['close']); + $this->assertArrayHasKey('volume', $candle); + $this->assertIsNumeric($candle['volume']); + $this->assertArrayHasKey('openTime', $candle); + $this->assertIsInt($candle['openTime']); + $this->assertArrayHasKey('closeTime', $candle); + $this->assertIsInt($candle['closeTime']); + $this->assertArrayHasKey('assetVolume', $candle); + $this->assertIsNumeric($candle['assetVolume']); + $this->assertArrayHasKey('baseVolume', $candle); + $this->assertIsNumeric($candle['baseVolume']); + $this->assertArrayHasKey('trades', $candle); + $this->assertIsInt($candle['trades']); + $this->assertArrayHasKey('assetBuyVolume', $candle); + $this->assertIsNumeric($candle['assetBuyVolume']); + $this->assertArrayHasKey('takerBuyVolume', $candle); + $this->assertIsNumeric($candle['takerBuyVolume']); + } + + public function testIndexPriceCandlesticksFutures() + { + $res = $this->futuresBinance->futuresIndexPriceCandlesticks($this->symbol, $this->interval, $this->limit); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsNumeric($firstKey); + $candle = $res[$firstKey]; + $this->assertArrayHasKey('open', $candle); + $this->assertIsNumeric($candle['open']); + $this->assertArrayHasKey('high', $candle); + $this->assertIsNumeric($candle['high']); + $this->assertArrayHasKey('low', $candle); + $this->assertIsNumeric($candle['low']); + $this->assertArrayHasKey('close', $candle); + $this->assertIsNumeric($candle['close']); + $this->assertArrayHasKey('volume', $candle); + $this->assertIsNumeric($candle['volume']); + $this->assertArrayHasKey('openTime', $candle); + $this->assertIsInt($candle['openTime']); + $this->assertArrayHasKey('closeTime', $candle); + $this->assertIsInt($candle['closeTime']); + $this->assertArrayHasKey('assetVolume', $candle); + $this->assertIsNumeric($candle['assetVolume']); + $this->assertArrayHasKey('baseVolume', $candle); + $this->assertIsNumeric($candle['baseVolume']); + $this->assertArrayHasKey('trades', $candle); + $this->assertIsInt($candle['trades']); + $this->assertArrayHasKey('assetBuyVolume', $candle); + $this->assertIsNumeric($candle['assetBuyVolume']); + $this->assertArrayHasKey('takerBuyVolume', $candle); + $this->assertIsNumeric($candle['takerBuyVolume']); + } + + public function testMarkPriceCandlesticksFutures() + { + $res = $this->futuresBinance->futuresMarkPriceCandlesticks($this->symbol, $this->interval, $this->limit); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsNumeric($firstKey); + $candle = $res[$firstKey]; + $this->assertArrayHasKey('open', $candle); + $this->assertIsNumeric($candle['open']); + $this->assertArrayHasKey('high', $candle); + $this->assertIsNumeric($candle['high']); + $this->assertArrayHasKey('low', $candle); + $this->assertIsNumeric($candle['low']); + $this->assertArrayHasKey('close', $candle); + $this->assertIsNumeric($candle['close']); + $this->assertArrayHasKey('volume', $candle); + $this->assertIsNumeric($candle['volume']); + $this->assertArrayHasKey('openTime', $candle); + $this->assertIsInt($candle['openTime']); + $this->assertArrayHasKey('closeTime', $candle); + $this->assertIsInt($candle['closeTime']); + $this->assertArrayHasKey('assetVolume', $candle); + $this->assertIsNumeric($candle['assetVolume']); + $this->assertArrayHasKey('baseVolume', $candle); + $this->assertIsNumeric($candle['baseVolume']); + $this->assertArrayHasKey('trades', $candle); + $this->assertIsInt($candle['trades']); + $this->assertArrayHasKey('assetBuyVolume', $candle); + $this->assertIsNumeric($candle['assetBuyVolume']); + $this->assertArrayHasKey('takerBuyVolume', $candle); + $this->assertIsNumeric($candle['takerBuyVolume']); + } + + public function testPremiumIndexCandlesticksFutures() + { + $res = $this->futuresBinance->futuresPremiumIndexCandlesticks($this->symbol, $this->interval, $this->limit); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsNumeric($firstKey); + $candle = $res[$firstKey]; + $this->assertArrayHasKey('open', $candle); + $this->assertIsNumeric($candle['open']); + $this->assertArrayHasKey('high', $candle); + $this->assertIsNumeric($candle['high']); + $this->assertArrayHasKey('low', $candle); + $this->assertIsNumeric($candle['low']); + $this->assertArrayHasKey('close', $candle); + $this->assertIsNumeric($candle['close']); + $this->assertArrayHasKey('volume', $candle); + $this->assertIsNumeric($candle['volume']); + $this->assertArrayHasKey('openTime', $candle); + $this->assertIsInt($candle['openTime']); + $this->assertArrayHasKey('closeTime', $candle); + $this->assertIsInt($candle['closeTime']); + $this->assertArrayHasKey('assetVolume', $candle); + $this->assertIsNumeric($candle['assetVolume']); + $this->assertArrayHasKey('baseVolume', $candle); + $this->assertIsNumeric($candle['baseVolume']); + $this->assertArrayHasKey('trades', $candle); + $this->assertIsInt($candle['trades']); + $this->assertArrayHasKey('assetBuyVolume', $candle); + $this->assertIsNumeric($candle['assetBuyVolume']); + $this->assertArrayHasKey('takerBuyVolume', $candle); + $this->assertIsNumeric($candle['takerBuyVolume']); + } + + public function testMarkPriceFutures() + { + $res = $this->futuresBinance->futuresMarkPrice($this->symbol); + $this->assertIsArray($res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('markPrice', $res); + $this->assertIsNumeric($res['markPrice']); + $this->assertArrayHasKey('indexPrice', $res); + $this->assertIsNumeric($res['indexPrice']); + $this->assertArrayHasKey('estimatedSettlePrice', $res); + $this->assertIsNumeric($res['estimatedSettlePrice']); + $this->assertArrayHasKey('lastFundingRate', $res); + $this->assertIsNumeric($res['lastFundingRate']); + $this->assertArrayHasKey('interestRate', $res); + $this->assertIsNumeric($res['interestRate']); + $this->assertArrayHasKey('nextFundingTime', $res); + $this->assertIsInt($res['nextFundingTime']); + $this->assertArrayHasKey('time', $res); + $this->assertIsInt($res['time']); + } + + public function testFundingRateHistoryFutures() + { + $res = $this->futuresBinance->futuresFundingRateHistory($this->symbol, $this->limit); + $this->assertIsArray($res); + $this->assertIsArray($res[0]); + $entry = $res[0]; + $this->assertArrayHasKey('symbol', $entry); + $this->assertEquals($this->symbol, $entry['symbol']); + $this->assertArrayHasKey('fundingTime', $entry); + $this->assertIsInt($entry['fundingTime']); + $this->assertArrayHasKey('fundingRate', $entry); + $this->assertIsNumeric($entry['fundingRate']); + $this->assertArrayHasKey('markPrice', $entry); + $this->assertIsNumeric($entry['markPrice']); + } + + public function testPrevDayFutures() + { + $res = $this->futuresBinance->futuresPrevDay($this->symbol); + $this->assertIsArray($res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('priceChange', $res); + $this->assertIsNumeric($res['priceChange']); + $this->assertArrayHasKey('priceChangePercent', $res); + $this->assertIsNumeric($res['priceChangePercent']); + $this->assertArrayHasKey('weightedAvgPrice', $res); + $this->assertIsNumeric($res['weightedAvgPrice']); + $this->assertArrayHasKey('lastPrice', $res); + $this->assertIsNumeric($res['lastPrice']); + $this->assertArrayHasKey('lastQty', $res); + $this->assertIsNumeric($res['lastQty']); + $this->assertArrayHasKey('openPrice', $res); + $this->assertIsNumeric($res['openPrice']); + $this->assertArrayHasKey('highPrice', $res); + $this->assertIsNumeric($res['highPrice']); + $this->assertArrayHasKey('lowPrice', $res); + $this->assertIsNumeric($res['lowPrice']); + $this->assertArrayHasKey('volume', $res); + $this->assertIsNumeric($res['volume']); + $this->assertArrayHasKey('quoteVolume', $res); + $this->assertIsNumeric($res['quoteVolume']); + $this->assertArrayHasKey('openTime', $res); + $this->assertIsInt($res['openTime']); + $this->assertArrayHasKey('closeTime', $res); + $this->assertIsInt($res['closeTime']); + $this->assertArrayHasKey('firstId', $res); + $this->assertIsInt($res['firstId']); + $this->assertArrayHasKey('lastId', $res); + $this->assertIsInt($res['lastId']); + $this->assertArrayHasKey('count', $res); + $this->assertIsInt($res['count']); + } + + public function testPriceFutures() + { + $res = $this->futuresBinance->futuresPrice($this->symbol); + $this->assertIsNumeric($res); + } + + public function testPricesFutures() + { + $res = $this->futuresBinance->futuresPrices(); + $this->assertIsArray($res); + $this->assertArrayHasKey($this->symbol, $res); + $this->assertIsNumeric($res[$this->symbol]); + } + + public function testPriceV2Futures() + { + $res = $this->futuresBinance->futuresPriceV2($this->symbol); + $this->assertIsNumeric($res); + } + + public function testPricesV2Futures() + { + $res = $this->futuresBinance->futuresPricesV2(); + $this->assertIsArray($res); + $this->assertArrayHasKey($this->symbol, $res); + $this->assertIsNumeric($res[$this->symbol]); + } } From b40c60c4519fd39f48abbfdb1fd4560780c1c21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 17:38:51 +0300 Subject: [PATCH 06/11] futuresConstituents url 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 91fda78e..79aa3bdd 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -4221,7 +4221,7 @@ public function futuresConstituents(string $symbol) 'symbol' => $symbol, 'fapi' => true, ]; - return $this->httpRequest("v1/indexInfo", 'GET', $parameters); + return $this->httpRequest("v1/constituents", 'GET', $parameters); } /** From 239a5b7988589e363e2c1e180af967b24f1c3ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 17:40:48 +0300 Subject: [PATCH 07/11] static test for futuresConstituents updated --- tests/BinanceStaticTests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BinanceStaticTests.php b/tests/BinanceStaticTests.php index add73821..d2ab4d6f 100644 --- a/tests/BinanceStaticTests.php +++ b/tests/BinanceStaticTests.php @@ -1665,7 +1665,7 @@ public function testFuturesConstituents() } catch (\Throwable $e) { } - $endpoint = "https://fapi.binance.com/fapi/v1/indexInfo?"; + $endpoint = "https://fapi.binance.com/fapi/v1/constituents?"; $this->assertTrue(str_starts_with(self::$capturedUrl, $endpoint)); $queryString = substr(self::$capturedUrl, strlen($endpoint)); From 12d236d6bd23d6a3d2832a8f254d7359a613412e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 17:43:51 +0300 Subject: [PATCH 08/11] Some more live tests added --- tests/BinanceLiveTests.php | 218 +++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) diff --git a/tests/BinanceLiveTests.php b/tests/BinanceLiveTests.php index 9c9dadfa..3dcdc444 100644 --- a/tests/BinanceLiveTests.php +++ b/tests/BinanceLiveTests.php @@ -696,4 +696,222 @@ public function testPricesV2Futures() $this->assertArrayHasKey($this->symbol, $res); $this->assertIsNumeric($res[$this->symbol]); } + + public function testSymbolOrderBookTickerFutures() + { + $res = $this->futuresBinance->futuresSymbolOrderBookTicker($this->symbol); + $this->assertIsArray($res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('bidPrice', $res); + $this->assertIsNumeric($res['bidPrice']); + $this->assertArrayHasKey('bidQty', $res); + $this->assertIsNumeric($res['bidQty']); + $this->assertArrayHasKey('askPrice', $res); + $this->assertIsNumeric($res['askPrice']); + $this->assertArrayHasKey('askQty', $res); + $this->assertIsNumeric($res['askQty']); + $this->assertArrayHasKey('time', $res); + $this->assertIsInt($res['time']); + } + + public function testDeliveryPriceFutures() + { + $this->futuresBinance->useTestnet = false; // set to false for fapiData request + $res = $this->futuresBinance->futuresDeliveryPrice($this->symbol); + $this->assertIsArray($res); + $this->assertIsArray($res[0]); + $this->assertArrayHasKey('deliveryTime', $res[0]); + $this->assertIsInt($res[0]['deliveryTime']); + $this->assertArrayHasKey('deliveryPrice', $res[0]); + $this->assertIsNumeric($res[0]['deliveryPrice']); + $this->futuresBinance->useTestnet = true; // reset to true for other tests + } + + public function testOpenInterestFutures() + { + $res = $this->futuresBinance->futuresOpenInterest($this->symbol); + $this->assertIsArray($res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('openInterest', $res); + $this->assertIsNumeric($res['openInterest']); + $this->assertArrayHasKey('time', $res); + $this->assertIsInt($res['time']); + } + + public function testOpenInterestHistoryFutures() + { + $this->futuresBinance->useTestnet = false; // set to false for fapiData request + $res = $this->futuresBinance->futuresOpenInterestHistory($this->symbol, $this->period, $this->limit); + $this->assertIsArray($res); + $entry = $res[0]; + $this->assertIsArray($entry); + $this->assertArrayHasKey('symbol', $entry); + $this->assertEquals($this->symbol, $entry['symbol']); + $this->assertArrayHasKey('sumOpenInterest', $entry); + $this->assertIsNumeric($entry['sumOpenInterest']); + $this->assertArrayHasKey('sumOpenInterestValue', $entry); + $this->assertIsNumeric($entry['sumOpenInterestValue']); + $this->assertArrayHasKey('timestamp', $entry); + $this->assertIsInt($entry['timestamp']); + $this->futuresBinance->useTestnet = true; // reset to true for other tests + } + + public function testTopLongShortPositionRatioFutures() + { + $this->futuresBinance->useTestnet = false; // set to false for fapiData request + $res = $this->futuresBinance->futuresTopLongShortPositionRatio($this->symbol, $this->period, $this->limit); + $this->assertIsArray($res); + $entry = $res[0]; + $this->assertIsArray($entry); + $this->assertArrayHasKey('symbol', $entry); + $this->assertEquals($this->symbol, $entry['symbol']); + $this->assertArrayHasKey('longAccount', $entry); + $this->assertIsNumeric($entry['longAccount']); + $this->assertArrayHasKey('longShortRatio', $entry); + $this->assertIsNumeric($entry['longShortRatio']); + $this->assertArrayHasKey('shortAccount', $entry); + $this->assertIsNumeric($entry['shortAccount']); + $this->assertArrayHasKey('timestamp', $entry); + $this->assertIsInt($entry['timestamp']); + $this->futuresBinance->useTestnet = true; // reset to true for other tests + } + + public function testTopLongShortAccountRatioFutures() + { + $this->futuresBinance->useTestnet = false; // set to false for fapiData request + $res = $this->futuresBinance->futuresTopLongShortAccountRatio($this->symbol, $this->period, $this->limit); + $this->assertIsArray($res); + $entry = $res[0]; + $this->assertIsArray($entry); + $this->assertArrayHasKey('symbol', $entry); + $this->assertEquals($this->symbol, $entry['symbol']); + $this->assertArrayHasKey('longAccount', $entry); + $this->assertIsNumeric($entry['longAccount']); + $this->assertArrayHasKey('longShortRatio', $entry); + $this->assertIsNumeric($entry['longShortRatio']); + $this->assertArrayHasKey('shortAccount', $entry); + $this->assertIsNumeric($entry['shortAccount']); + $this->assertArrayHasKey('timestamp', $entry); + $this->assertIsInt($entry['timestamp']); + $this->futuresBinance->useTestnet = true; // reset to true for other tests + } + + public function testGlobalLongShortAccountRatioFutures() + { + $this->futuresBinance->useTestnet = false; // set to false for fapiData request + $res = $this->futuresBinance->futuresGlobalLongShortAccountRatio($this->symbol, $this->period, $this->limit); + $this->assertIsArray($res); + $entry = $res[0]; + $this->assertIsArray($entry); + $this->assertArrayHasKey('symbol', $entry); + $this->assertEquals($this->symbol, $entry['symbol']); + $this->assertArrayHasKey('longAccount', $entry); + $this->assertIsNumeric($entry['longAccount']); + $this->assertArrayHasKey('longShortRatio', $entry); + $this->assertIsNumeric($entry['longShortRatio']); + $this->assertArrayHasKey('shortAccount', $entry); + $this->assertIsNumeric($entry['shortAccount']); + $this->assertArrayHasKey('timestamp', $entry); + $this->assertIsInt($entry['timestamp']); + $this->futuresBinance->useTestnet = true; // reset to true for other tests + } + + public function testTakerLongShortRatioFutures() + { + $this->futuresBinance->useTestnet = false; // set to false for fapiData request + $res = $this->futuresBinance->futuresTakerLongShortRatio($this->symbol, $this->period, $this->limit); + $this->assertIsArray($res); + $entry = $res[0]; + $this->assertIsArray($entry); + $this->assertArrayHasKey('buySellRatio', $entry); + $this->assertIsNumeric($entry['buySellRatio']); + $this->assertArrayHasKey('sellVol', $entry); + $this->assertIsNumeric($entry['sellVol']); + $this->assertArrayHasKey('buyVol', $entry); + $this->assertIsNumeric($entry['buyVol']); + $this->assertArrayHasKey('timestamp', $entry); + $this->assertIsInt($entry['timestamp']); + $this->futuresBinance->useTestnet = true; // reset to true for other tests + } + + public function testBasisFutures() + { + $this->futuresBinance->useTestnet = false; // set to false for fapiData request + $res = $this->futuresBinance->futuresBasis($this->symbol, $this->period, $this->limit, null, null, $this->contractType); + $this->assertIsArray($res); + $entry = $res[0]; + $this->assertIsArray($entry); + $this->assertArrayHasKey('indexPrice', $entry); + $this->assertIsNumeric($entry['indexPrice']); + $this->assertArrayHasKey('contractType', $entry); + $this->assertEquals($this->contractType, $entry['contractType']); + $this->assertArrayHasKey('basisRate', $entry); + $this->assertIsNumeric($entry['basisRate']); + $this->assertArrayHasKey('futuresPrice', $entry); + $this->assertIsNumeric($entry['futuresPrice']); + $this->assertArrayHasKey('annualizedBasisRate', $entry); + $this->assertIsNumeric($entry['annualizedBasisRate']); + $this->assertArrayHasKey('basis', $entry); + $this->assertIsNumeric($entry['basis']); + $this->assertArrayHasKey('pair', $entry); + $this->assertEquals($this->symbol, $entry['pair']); + $this->assertArrayHasKey('timestamp', $entry); + $this->assertIsInt($entry['timestamp']); + $this->futuresBinance->useTestnet = true; // reset to true for other tests + } + + public function testIndexInfoFutures() + { + $compositeIndex = 'DEFIUSDT'; + $res = $this->futuresBinance->futuresIndexInfo($compositeIndex); + $this->assertIsArray($res); + $this->assertArrayHasKey('symbol', $res); + $this->assertEquals($compositeIndex, $res['symbol']); + $this->assertArrayHasKey('time', $res); + $this->assertIsInt($res['time']); + $this->assertArrayHasKey('component', $res); + $this->assertArrayHasKey('baseAssetList', $res); + $this->assertIsArray($res['baseAssetList']); + } + + public function testAssetIndexFutures() + { + $res = $this->futuresBinance->futuresAssetIndex(); + $this->assertIsArray($res); + $entry = $res[0]; + $this->assertIsArray($entry); + $this->assertArrayHasKey('symbol', $entry); + $this->assertIsString($entry['symbol']); + $this->assertArrayHasKey('time', $entry); + $this->assertIsInt($entry['time']); + $this->assertArrayHasKey('index', $entry); + $this->assertIsNumeric($entry['index']); + $this->assertArrayHasKey('bidBuffer', $entry); + $this->assertIsNumeric($entry['bidBuffer']); + $this->assertArrayHasKey('askBuffer', $entry); + $this->assertIsNumeric($entry['askBuffer']); + $this->assertArrayHasKey('bidRate', $entry); + $this->assertIsNumeric($entry['bidRate']); + $this->assertArrayHasKey('askRate', $entry); + $this->assertIsNumeric($entry['askRate']); + $this->assertArrayHasKey('autoExchangeBidBuffer', $entry); + $this->assertIsNumeric($entry['autoExchangeBidBuffer']); + $this->assertArrayHasKey('autoExchangeAskBuffer', $entry); + $this->assertIsNumeric($entry['autoExchangeAskBuffer']); + $this->assertArrayHasKey('autoExchangeBidRate', $entry); + $this->assertIsNumeric($entry['autoExchangeBidRate']); + $this->assertArrayHasKey('autoExchangeAskRate', $entry); + $this->assertIsNumeric($entry['autoExchangeAskRate']); + } + + public function testConstituentsFutures() + { + $res = $this->futuresBinance->futuresConstituents($this->symbol); + $this->assertIsArray($res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('time', $res); + $this->assertIsInt($res['time']); + $this->assertArrayHasKey('constituents', $res); + $this->assertIsArray($res['constituents']); + } } From 54b182341c4911218a31dc073013647f0eb28846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 16 Apr 2025 19:23:25 +0300 Subject: [PATCH 09/11] Tests that require useTestsnet = false are commented --- tests/BinanceLiveTests.php | 356 ++++++++++++++++++++++++------------- 1 file changed, 228 insertions(+), 128 deletions(-) diff --git a/tests/BinanceLiveTests.php b/tests/BinanceLiveTests.php index 3dcdc444..b183f626 100644 --- a/tests/BinanceLiveTests.php +++ b/tests/BinanceLiveTests.php @@ -714,18 +714,19 @@ public function testSymbolOrderBookTickerFutures() $this->assertIsInt($res['time']); } - public function testDeliveryPriceFutures() - { - $this->futuresBinance->useTestnet = false; // set to false for fapiData request - $res = $this->futuresBinance->futuresDeliveryPrice($this->symbol); - $this->assertIsArray($res); - $this->assertIsArray($res[0]); - $this->assertArrayHasKey('deliveryTime', $res[0]); - $this->assertIsInt($res[0]['deliveryTime']); - $this->assertArrayHasKey('deliveryPrice', $res[0]); - $this->assertIsNumeric($res[0]['deliveryPrice']); - $this->futuresBinance->useTestnet = true; // reset to true for other tests - } + + // public function testDeliveryPriceFutures() // Could throw an error if useTestnet is set to false + // { + // $this->futuresBinance->useTestnet = false; // set to false for fapiData request + // $res = $this->futuresBinance->futuresDeliveryPrice($this->symbol); + // $this->assertIsArray($res); + // $this->assertIsArray($res[0]); + // $this->assertArrayHasKey('deliveryTime', $res[0]); + // $this->assertIsInt($res[0]['deliveryTime']); + // $this->assertArrayHasKey('deliveryPrice', $res[0]); + // $this->assertIsNumeric($res[0]['deliveryPrice']); + // $this->futuresBinance->useTestnet = true; // reset to true for other tests + // } public function testOpenInterestFutures() { @@ -738,127 +739,127 @@ public function testOpenInterestFutures() $this->assertIsInt($res['time']); } - public function testOpenInterestHistoryFutures() - { - $this->futuresBinance->useTestnet = false; // set to false for fapiData request - $res = $this->futuresBinance->futuresOpenInterestHistory($this->symbol, $this->period, $this->limit); - $this->assertIsArray($res); - $entry = $res[0]; - $this->assertIsArray($entry); - $this->assertArrayHasKey('symbol', $entry); - $this->assertEquals($this->symbol, $entry['symbol']); - $this->assertArrayHasKey('sumOpenInterest', $entry); - $this->assertIsNumeric($entry['sumOpenInterest']); - $this->assertArrayHasKey('sumOpenInterestValue', $entry); - $this->assertIsNumeric($entry['sumOpenInterestValue']); - $this->assertArrayHasKey('timestamp', $entry); - $this->assertIsInt($entry['timestamp']); - $this->futuresBinance->useTestnet = true; // reset to true for other tests - } + // public function testOpenInterestHistoryFutures() // Could throw an error if useTestnet is set to false + // { + // $this->futuresBinance->useTestnet = false; // set to false for fapiData request + // $res = $this->futuresBinance->futuresOpenInterestHistory($this->symbol, $this->period, $this->limit); + // $this->assertIsArray($res); + // $entry = $res[0]; + // $this->assertIsArray($entry); + // $this->assertArrayHasKey('symbol', $entry); + // $this->assertEquals($this->symbol, $entry['symbol']); + // $this->assertArrayHasKey('sumOpenInterest', $entry); + // $this->assertIsNumeric($entry['sumOpenInterest']); + // $this->assertArrayHasKey('sumOpenInterestValue', $entry); + // $this->assertIsNumeric($entry['sumOpenInterestValue']); + // $this->assertArrayHasKey('timestamp', $entry); + // $this->assertIsInt($entry['timestamp']); + // $this->futuresBinance->useTestnet = true; // reset to true for other tests + // } - public function testTopLongShortPositionRatioFutures() - { - $this->futuresBinance->useTestnet = false; // set to false for fapiData request - $res = $this->futuresBinance->futuresTopLongShortPositionRatio($this->symbol, $this->period, $this->limit); - $this->assertIsArray($res); - $entry = $res[0]; - $this->assertIsArray($entry); - $this->assertArrayHasKey('symbol', $entry); - $this->assertEquals($this->symbol, $entry['symbol']); - $this->assertArrayHasKey('longAccount', $entry); - $this->assertIsNumeric($entry['longAccount']); - $this->assertArrayHasKey('longShortRatio', $entry); - $this->assertIsNumeric($entry['longShortRatio']); - $this->assertArrayHasKey('shortAccount', $entry); - $this->assertIsNumeric($entry['shortAccount']); - $this->assertArrayHasKey('timestamp', $entry); - $this->assertIsInt($entry['timestamp']); - $this->futuresBinance->useTestnet = true; // reset to true for other tests - } + // public function testTopLongShortPositionRatioFutures() // Could throw an error if useTestnet is set to false + // { + // $this->futuresBinance->useTestnet = false; // set to false for fapiData request + // $res = $this->futuresBinance->futuresTopLongShortPositionRatio($this->symbol, $this->period, $this->limit); + // $this->assertIsArray($res); + // $entry = $res[0]; + // $this->assertIsArray($entry); + // $this->assertArrayHasKey('symbol', $entry); + // $this->assertEquals($this->symbol, $entry['symbol']); + // $this->assertArrayHasKey('longAccount', $entry); + // $this->assertIsNumeric($entry['longAccount']); + // $this->assertArrayHasKey('longShortRatio', $entry); + // $this->assertIsNumeric($entry['longShortRatio']); + // $this->assertArrayHasKey('shortAccount', $entry); + // $this->assertIsNumeric($entry['shortAccount']); + // $this->assertArrayHasKey('timestamp', $entry); + // $this->assertIsInt($entry['timestamp']); + // $this->futuresBinance->useTestnet = true; // reset to true for other tests + // } - public function testTopLongShortAccountRatioFutures() - { - $this->futuresBinance->useTestnet = false; // set to false for fapiData request - $res = $this->futuresBinance->futuresTopLongShortAccountRatio($this->symbol, $this->period, $this->limit); - $this->assertIsArray($res); - $entry = $res[0]; - $this->assertIsArray($entry); - $this->assertArrayHasKey('symbol', $entry); - $this->assertEquals($this->symbol, $entry['symbol']); - $this->assertArrayHasKey('longAccount', $entry); - $this->assertIsNumeric($entry['longAccount']); - $this->assertArrayHasKey('longShortRatio', $entry); - $this->assertIsNumeric($entry['longShortRatio']); - $this->assertArrayHasKey('shortAccount', $entry); - $this->assertIsNumeric($entry['shortAccount']); - $this->assertArrayHasKey('timestamp', $entry); - $this->assertIsInt($entry['timestamp']); - $this->futuresBinance->useTestnet = true; // reset to true for other tests - } + // public function testTopLongShortAccountRatioFutures() // Could throw an error if useTestnet is set to false + // { + // $this->futuresBinance->useTestnet = false; // set to false for fapiData request + // $res = $this->futuresBinance->futuresTopLongShortAccountRatio($this->symbol, $this->period, $this->limit); + // $this->assertIsArray($res); + // $entry = $res[0]; + // $this->assertIsArray($entry); + // $this->assertArrayHasKey('symbol', $entry); + // $this->assertEquals($this->symbol, $entry['symbol']); + // $this->assertArrayHasKey('longAccount', $entry); + // $this->assertIsNumeric($entry['longAccount']); + // $this->assertArrayHasKey('longShortRatio', $entry); + // $this->assertIsNumeric($entry['longShortRatio']); + // $this->assertArrayHasKey('shortAccount', $entry); + // $this->assertIsNumeric($entry['shortAccount']); + // $this->assertArrayHasKey('timestamp', $entry); + // $this->assertIsInt($entry['timestamp']); + // $this->futuresBinance->useTestnet = true; // reset to true for other tests + // } - public function testGlobalLongShortAccountRatioFutures() - { - $this->futuresBinance->useTestnet = false; // set to false for fapiData request - $res = $this->futuresBinance->futuresGlobalLongShortAccountRatio($this->symbol, $this->period, $this->limit); - $this->assertIsArray($res); - $entry = $res[0]; - $this->assertIsArray($entry); - $this->assertArrayHasKey('symbol', $entry); - $this->assertEquals($this->symbol, $entry['symbol']); - $this->assertArrayHasKey('longAccount', $entry); - $this->assertIsNumeric($entry['longAccount']); - $this->assertArrayHasKey('longShortRatio', $entry); - $this->assertIsNumeric($entry['longShortRatio']); - $this->assertArrayHasKey('shortAccount', $entry); - $this->assertIsNumeric($entry['shortAccount']); - $this->assertArrayHasKey('timestamp', $entry); - $this->assertIsInt($entry['timestamp']); - $this->futuresBinance->useTestnet = true; // reset to true for other tests - } + // public function testGlobalLongShortAccountRatioFutures() // Could throw an error if useTestnet is set to false + // { + // $this->futuresBinance->useTestnet = false; // set to false for fapiData request + // $res = $this->futuresBinance->futuresGlobalLongShortAccountRatio($this->symbol, $this->period, $this->limit); + // $this->assertIsArray($res); + // $entry = $res[0]; + // $this->assertIsArray($entry); + // $this->assertArrayHasKey('symbol', $entry); + // $this->assertEquals($this->symbol, $entry['symbol']); + // $this->assertArrayHasKey('longAccount', $entry); + // $this->assertIsNumeric($entry['longAccount']); + // $this->assertArrayHasKey('longShortRatio', $entry); + // $this->assertIsNumeric($entry['longShortRatio']); + // $this->assertArrayHasKey('shortAccount', $entry); + // $this->assertIsNumeric($entry['shortAccount']); + // $this->assertArrayHasKey('timestamp', $entry); + // $this->assertIsInt($entry['timestamp']); + // $this->futuresBinance->useTestnet = true; // reset to true for other tests + // } - public function testTakerLongShortRatioFutures() - { - $this->futuresBinance->useTestnet = false; // set to false for fapiData request - $res = $this->futuresBinance->futuresTakerLongShortRatio($this->symbol, $this->period, $this->limit); - $this->assertIsArray($res); - $entry = $res[0]; - $this->assertIsArray($entry); - $this->assertArrayHasKey('buySellRatio', $entry); - $this->assertIsNumeric($entry['buySellRatio']); - $this->assertArrayHasKey('sellVol', $entry); - $this->assertIsNumeric($entry['sellVol']); - $this->assertArrayHasKey('buyVol', $entry); - $this->assertIsNumeric($entry['buyVol']); - $this->assertArrayHasKey('timestamp', $entry); - $this->assertIsInt($entry['timestamp']); - $this->futuresBinance->useTestnet = true; // reset to true for other tests - } + // public function testTakerLongShortRatioFutures() // Could throw an error if useTestnet is set to false + // { + // $this->futuresBinance->useTestnet = false; // set to false for fapiData request + // $res = $this->futuresBinance->futuresTakerLongShortRatio($this->symbol, $this->period, $this->limit); + // $this->assertIsArray($res); + // $entry = $res[0]; + // $this->assertIsArray($entry); + // $this->assertArrayHasKey('buySellRatio', $entry); + // $this->assertIsNumeric($entry['buySellRatio']); + // $this->assertArrayHasKey('sellVol', $entry); + // $this->assertIsNumeric($entry['sellVol']); + // $this->assertArrayHasKey('buyVol', $entry); + // $this->assertIsNumeric($entry['buyVol']); + // $this->assertArrayHasKey('timestamp', $entry); + // $this->assertIsInt($entry['timestamp']); + // $this->futuresBinance->useTestnet = true; // reset to true for other tests + // } - public function testBasisFutures() - { - $this->futuresBinance->useTestnet = false; // set to false for fapiData request - $res = $this->futuresBinance->futuresBasis($this->symbol, $this->period, $this->limit, null, null, $this->contractType); - $this->assertIsArray($res); - $entry = $res[0]; - $this->assertIsArray($entry); - $this->assertArrayHasKey('indexPrice', $entry); - $this->assertIsNumeric($entry['indexPrice']); - $this->assertArrayHasKey('contractType', $entry); - $this->assertEquals($this->contractType, $entry['contractType']); - $this->assertArrayHasKey('basisRate', $entry); - $this->assertIsNumeric($entry['basisRate']); - $this->assertArrayHasKey('futuresPrice', $entry); - $this->assertIsNumeric($entry['futuresPrice']); - $this->assertArrayHasKey('annualizedBasisRate', $entry); - $this->assertIsNumeric($entry['annualizedBasisRate']); - $this->assertArrayHasKey('basis', $entry); - $this->assertIsNumeric($entry['basis']); - $this->assertArrayHasKey('pair', $entry); - $this->assertEquals($this->symbol, $entry['pair']); - $this->assertArrayHasKey('timestamp', $entry); - $this->assertIsInt($entry['timestamp']); - $this->futuresBinance->useTestnet = true; // reset to true for other tests - } + // public function testBasisFutures() // Could throw an error if useTestnet is set to false + // { + // $this->futuresBinance->useTestnet = false; // set to false for fapiData request + // $res = $this->futuresBinance->futuresBasis($this->symbol, $this->period, $this->limit, null, null, $this->contractType); + // $this->assertIsArray($res); + // $entry = $res[0]; + // $this->assertIsArray($entry); + // $this->assertArrayHasKey('indexPrice', $entry); + // $this->assertIsNumeric($entry['indexPrice']); + // $this->assertArrayHasKey('contractType', $entry); + // $this->assertEquals($this->contractType, $entry['contractType']); + // $this->assertArrayHasKey('basisRate', $entry); + // $this->assertIsNumeric($entry['basisRate']); + // $this->assertArrayHasKey('futuresPrice', $entry); + // $this->assertIsNumeric($entry['futuresPrice']); + // $this->assertArrayHasKey('annualizedBasisRate', $entry); + // $this->assertIsNumeric($entry['annualizedBasisRate']); + // $this->assertArrayHasKey('basis', $entry); + // $this->assertIsNumeric($entry['basis']); + // $this->assertArrayHasKey('pair', $entry); + // $this->assertEquals($this->symbol, $entry['pair']); + // $this->assertArrayHasKey('timestamp', $entry); + // $this->assertIsInt($entry['timestamp']); + // $this->futuresBinance->useTestnet = true; // reset to true for other tests + // } public function testIndexInfoFutures() { @@ -914,4 +915,103 @@ public function testConstituentsFutures() $this->assertArrayHasKey('constituents', $res); $this->assertIsArray($res['constituents']); } + + public function testOrderAmendmentFutures() + { + $res = $this->futuresBinance->futuresOrderAmendment($this->symbol); + $this->assertIsArray($res); + } + + public function testCountdownCancelAllOrdersFutures() + { + $countdownTime = 1000; + $res = $this->futuresBinance->futuresCountdownCancelAllOrders($this->symbol, $countdownTime); + $this->assertIsArray($res); + $this->assertArrayHasKey('symbol', $res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('countdownTime', $res); + $this->assertEquals($countdownTime, $res['countdownTime']); + } + + public function testAllOrdersFutures() + { + $res = $this->futuresBinance->futuresAllOrders($this->symbol); + $this->assertIsArray($res); + } + + public function testOpenOrdersFutures() + { + $res = $this->futuresBinance->futuresOpenOrders($this->symbol); + $this->assertIsArray($res); + } + + public function testForceOrdersFutures() + { + $res = $this->futuresBinance->futuresForceOrders(); + $this->assertIsArray($res); + } + + public function testMyTradesFutures() + { + $res = $this->futuresBinance->futuresMyTrades($this->symbol); + $this->assertIsArray($res); + } + + public function testHistoryFutures() + { + $res = $this->futuresBinance->futuresHistory($this->symbol); + $this->assertIsArray($res); + } + + public function testPositionModeFutures() + { + $res = $this->futuresBinance->futuresPositionMode(); + $this->assertIsArray($res); + $this->assertArrayHasKey('dualSidePosition', $res); + $this->assertIsBool($res['dualSidePosition']); + } + + public function testMultiAssetsMarginModeFutures() + { + $res = $this->futuresBinance->futuresMultiAssetsMarginMode(); + $this->assertIsArray($res); + $this->assertArrayHasKey('multiAssetsMargin', $res); + $this->assertIsBool($res['multiAssetsMargin']); + } + + public function testPositionsFutures() + { + $res = $this->futuresBinance->futuresPositions($this->symbol); + $this->assertIsArray($res); + } + + public function testPositionsV2Futures() + { + $res = $this->futuresBinance->futuresPositionsV2($this->symbol); + $this->assertIsArray($res); + } + + public function testPositionsV3Futures() + { + $res = $this->futuresBinance->futuresPositionsV3($this->symbol); + $this->assertIsArray($res); + } + + public function testPositionFutures() + { + $res = $this->futuresBinance->futuresPosition($this->symbol); + $this->assertIsArray($res); + } + + public function testPositionV2Futures() + { + $res = $this->futuresBinance->futuresPositionV2($this->symbol); + $this->assertIsArray($res); + } + + public function testPositionV3Futures() + { + $res = $this->futuresBinance->futuresPositionV3($this->symbol); + $this->assertIsArray($res); + } } From cb0bfeb88712c36a83c63eb08d297913e0c82bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Thu, 17 Apr 2025 11:52:28 +0300 Subject: [PATCH 10/11] Live tests added --- tests/BinanceLiveTests.php | 339 +++++++++++++++++++++++++++++++++++++ 1 file changed, 339 insertions(+) diff --git a/tests/BinanceLiveTests.php b/tests/BinanceLiveTests.php index b183f626..f4e34b73 100644 --- a/tests/BinanceLiveTests.php +++ b/tests/BinanceLiveTests.php @@ -1014,4 +1014,343 @@ public function testPositionV3Futures() $res = $this->futuresBinance->futuresPositionV3($this->symbol); $this->assertIsArray($res); } + + public function testAdlQuantileFutures() + { + $res = $this->futuresBinance->futuresAdlQuantile($this->symbol, $this->recvWindow); + $this->assertIsArray($res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('adlQuantile', $res); + $this->assertIsArray($res['adlQuantile']); + } + + public function testPositionMarginChangeHistoryFutures() + { + $res = $this->futuresBinance->futuresPositionMarginChangeHistory($this->symbol); + $this->assertIsArray($res); + } + + public function testBalancesFutures() + { + $res = $this->futuresBinance->futuresBalances(); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsString($firstKey); + $firstValue = $res[$firstKey]; + $this->assertIsArray($firstValue); + $this->assertArrayHasKey('available', $firstValue); + $this->assertIsNumeric($firstValue['available']); + $this->assertArrayHasKey('onOrder', $firstValue); + $this->assertIsNumeric($firstValue['onOrder']); + $this->assertArrayHasKey('total', $firstValue); + $this->assertIsNumeric($firstValue['total']); + $this->assertArrayHasKey('info', $firstValue); + $info = $firstValue['info']; + $this->assertIsArray($info); + $this->assertArrayHasKey('accountAlias', $info); + $this->assertIsString($info['accountAlias']); + $this->assertArrayHasKey('asset', $info); + $this->assertIsString($info['asset']); + $this->assertArrayHasKey('balance', $info); + $this->assertIsNumeric($info['balance']); + $this->assertArrayHasKey('crossWalletBalance', $info); + $this->assertIsNumeric($info['crossWalletBalance']); + $this->assertArrayHasKey('crossUnPnl', $info); + $this->assertIsNumeric($info['crossUnPnl']); + $this->assertArrayHasKey('availableBalance', $info); + $this->assertIsNumeric($info['availableBalance']); + $this->assertArrayHasKey('maxWithdrawAmount', $info); + $this->assertIsNumeric($info['maxWithdrawAmount']); + $this->assertArrayHasKey('marginAvailable', $info); + $this->assertIsBool($info['marginAvailable']); + $this->assertArrayHasKey('updateTime', $info); + $this->assertIsInt($info['updateTime']); + } + + public function testBalancesV2Futures() + { + $res = $this->futuresBinance->futuresBalancesV2(); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsString($firstKey); + $firstValue = $res[$firstKey]; + $this->assertIsArray($firstValue); + $this->assertArrayHasKey('available', $firstValue); + $this->assertIsNumeric($firstValue['available']); + $this->assertArrayHasKey('onOrder', $firstValue); + $this->assertIsNumeric($firstValue['onOrder']); + $this->assertArrayHasKey('total', $firstValue); + $this->assertIsNumeric($firstValue['total']); + $this->assertArrayHasKey('info', $firstValue); + $info = $firstValue['info']; + $this->assertIsArray($info); + $this->assertArrayHasKey('accountAlias', $info); + $this->assertIsString($info['accountAlias']); + $this->assertArrayHasKey('asset', $info); + $this->assertIsString($info['asset']); + $this->assertArrayHasKey('balance', $info); + $this->assertIsNumeric($info['balance']); + $this->assertArrayHasKey('crossWalletBalance', $info); + $this->assertIsNumeric($info['crossWalletBalance']); + $this->assertArrayHasKey('crossUnPnl', $info); + $this->assertIsNumeric($info['crossUnPnl']); + $this->assertArrayHasKey('availableBalance', $info); + $this->assertIsNumeric($info['availableBalance']); + $this->assertArrayHasKey('maxWithdrawAmount', $info); + $this->assertIsNumeric($info['maxWithdrawAmount']); + $this->assertArrayHasKey('marginAvailable', $info); + $this->assertIsBool($info['marginAvailable']); + $this->assertArrayHasKey('updateTime', $info); + $this->assertIsInt($info['updateTime']); + } + + public function testBalancesV3Futures() + { + $res = $this->futuresBinance->futuresBalancesV3(); + $this->assertIsArray($res); + $firstKey = array_key_first($res); + $this->assertIsString($firstKey); + $firstValue = $res[$firstKey]; + $this->assertIsArray($firstValue); + $this->assertArrayHasKey('available', $firstValue); + $this->assertIsNumeric($firstValue['available']); + $this->assertArrayHasKey('onOrder', $firstValue); + $this->assertIsNumeric($firstValue['onOrder']); + $this->assertArrayHasKey('total', $firstValue); + $this->assertIsNumeric($firstValue['total']); + $this->assertArrayHasKey('info', $firstValue); + $info = $firstValue['info']; + $this->assertIsArray($info); + $this->assertArrayHasKey('accountAlias', $info); + $this->assertIsString($info['accountAlias']); + $this->assertArrayHasKey('asset', $info); + $this->assertIsString($info['asset']); + $this->assertArrayHasKey('balance', $info); + $this->assertIsNumeric($info['balance']); + $this->assertArrayHasKey('crossWalletBalance', $info); + $this->assertIsNumeric($info['crossWalletBalance']); + $this->assertArrayHasKey('crossUnPnl', $info); + $this->assertIsNumeric($info['crossUnPnl']); + $this->assertArrayHasKey('availableBalance', $info); + $this->assertIsNumeric($info['availableBalance']); + $this->assertArrayHasKey('maxWithdrawAmount', $info); + $this->assertIsNumeric($info['maxWithdrawAmount']); + $this->assertArrayHasKey('marginAvailable', $info); + $this->assertIsBool($info['marginAvailable']); + $this->assertArrayHasKey('updateTime', $info); + $this->assertIsInt($info['updateTime']); + } + + public function testAccountFutures() + { + $res = $this->futuresBinance->futuresAccount(); + $this->assertIsArray($res); + $this->assertArrayHasKey('totalInitialMargin', $res); + $this->assertIsNumeric($res['totalInitialMargin']); + $this->assertArrayHasKey('totalMaintMargin', $res); + $this->assertIsNumeric($res['totalMaintMargin']); + $this->assertArrayHasKey('totalWalletBalance', $res); + $this->assertIsNumeric($res['totalWalletBalance']); + $this->assertArrayHasKey('totalUnrealizedProfit', $res); + $this->assertIsNumeric($res['totalUnrealizedProfit']); + $this->assertArrayHasKey('totalMarginBalance', $res); + $this->assertIsNumeric($res['totalMarginBalance']); + $this->assertArrayHasKey('totalPositionInitialMargin', $res); + $this->assertIsNumeric($res['totalPositionInitialMargin']); + $this->assertArrayHasKey('totalOpenOrderInitialMargin', $res); + $this->assertIsNumeric($res['totalOpenOrderInitialMargin']); + $this->assertArrayHasKey('totalCrossWalletBalance', $res); + $this->assertIsNumeric($res['totalCrossWalletBalance']); + $this->assertArrayHasKey('totalCrossUnPnl', $res); + $this->assertIsNumeric($res['totalCrossUnPnl']); + $this->assertArrayHasKey('availableBalance', $res); + $this->assertIsNumeric($res['availableBalance']); + $this->assertArrayHasKey('maxWithdrawAmount', $res); + $this->assertIsNumeric($res['maxWithdrawAmount']); + $this->assertArrayHasKey('assets', $res); + $this->assertIsArray($res['assets']); + $this->assertArrayHasKey('positions', $res); + $this->assertIsArray($res['positions']); + } + + public function testAccountV2Futures() + { + $res = $this->futuresBinance->futuresAccountV2($this->recvWindow); + $this->assertIsArray($res); + $this->assertArrayHasKey('totalInitialMargin', $res); + $this->assertIsNumeric($res['totalInitialMargin']); + $this->assertArrayHasKey('totalMaintMargin', $res); + $this->assertIsNumeric($res['totalMaintMargin']); + $this->assertArrayHasKey('totalWalletBalance', $res); + $this->assertIsNumeric($res['totalWalletBalance']); + $this->assertArrayHasKey('totalUnrealizedProfit', $res); + $this->assertIsNumeric($res['totalUnrealizedProfit']); + $this->assertArrayHasKey('totalMarginBalance', $res); + $this->assertIsNumeric($res['totalMarginBalance']); + $this->assertArrayHasKey('totalPositionInitialMargin', $res); + $this->assertIsNumeric($res['totalPositionInitialMargin']); + $this->assertArrayHasKey('totalOpenOrderInitialMargin', $res); + $this->assertIsNumeric($res['totalOpenOrderInitialMargin']); + $this->assertArrayHasKey('totalCrossWalletBalance', $res); + $this->assertIsNumeric($res['totalCrossWalletBalance']); + $this->assertArrayHasKey('totalCrossUnPnl', $res); + $this->assertIsNumeric($res['totalCrossUnPnl']); + $this->assertArrayHasKey('availableBalance', $res); + $this->assertIsNumeric($res['availableBalance']); + $this->assertArrayHasKey('maxWithdrawAmount', $res); + $this->assertIsNumeric($res['maxWithdrawAmount']); + $this->assertArrayHasKey('assets', $res); + $this->assertIsArray($res['assets']); + $this->assertArrayHasKey('positions', $res); + $this->assertIsArray($res['positions']); + } + + public function testAccountV3Futures() + { + $res = $this->futuresBinance->futuresAccountV3($this->recvWindow); + $this->assertIsArray($res); + $this->assertArrayHasKey('totalInitialMargin', $res); + $this->assertIsNumeric($res['totalInitialMargin']); + $this->assertArrayHasKey('totalMaintMargin', $res); + $this->assertIsNumeric($res['totalMaintMargin']); + $this->assertArrayHasKey('totalWalletBalance', $res); + $this->assertIsNumeric($res['totalWalletBalance']); + $this->assertArrayHasKey('totalUnrealizedProfit', $res); + $this->assertIsNumeric($res['totalUnrealizedProfit']); + $this->assertArrayHasKey('totalMarginBalance', $res); + $this->assertIsNumeric($res['totalMarginBalance']); + $this->assertArrayHasKey('totalPositionInitialMargin', $res); + $this->assertIsNumeric($res['totalPositionInitialMargin']); + $this->assertArrayHasKey('totalOpenOrderInitialMargin', $res); + $this->assertIsNumeric($res['totalOpenOrderInitialMargin']); + $this->assertArrayHasKey('totalCrossWalletBalance', $res); + $this->assertIsNumeric($res['totalCrossWalletBalance']); + $this->assertArrayHasKey('totalCrossUnPnl', $res); + $this->assertIsNumeric($res['totalCrossUnPnl']); + $this->assertArrayHasKey('availableBalance', $res); + $this->assertIsNumeric($res['availableBalance']); + $this->assertArrayHasKey('maxWithdrawAmount', $res); + $this->assertIsNumeric($res['maxWithdrawAmount']); + $this->assertArrayHasKey('assets', $res); + $this->assertIsArray($res['assets']); + $this->assertArrayHasKey('positions', $res); + $this->assertIsArray($res['positions']); + } + + public function testTradeFeeFutures() + { + $res = $this->futuresBinance->futuresTradeFee($this->symbol); + $this->assertIsArray($res); + $this->assertArrayHasKey('symbol', $res); + $this->assertEquals($this->symbol, $res['symbol']); + $this->assertArrayHasKey('makerCommissionRate', $res); + $this->assertIsNumeric($res['makerCommissionRate']); + $this->assertArrayHasKey('takerCommissionRate', $res); + $this->assertIsNumeric($res['takerCommissionRate']); + } + + public function testAccountConfigFutures() + { + $res = $this->futuresBinance->futuresAccountConfig(); + $this->assertIsArray($res); + $this->assertArrayHasKey('feeTier', $res); + $this->assertIsInt($res['feeTier']); + $this->assertArrayHasKey('canTrade', $res); + $this->assertIsBool($res['canTrade']); + $this->assertArrayHasKey('canDeposit', $res); + $this->assertIsBool($res['canDeposit']); + $this->assertArrayHasKey('canWithdraw', $res); + $this->assertIsBool($res['canWithdraw']); + $this->assertArrayHasKey('dualSidePosition', $res); + $this->assertIsBool($res['dualSidePosition']); + $this->assertArrayHasKey('updateTime', $res); + $this->assertIsInt($res['updateTime']); + $this->assertArrayHasKey('multiAssetsMargin', $res); + $this->assertIsBool($res['multiAssetsMargin']); + $this->assertArrayHasKey('tradeGroupId', $res); + } + + public function testMarginModesFutures() + { + $res = $this->futuresBinance->futuresMarginModes($this->symbol); + $this->assertIsArray($res); + $firstEntry = $res[0]; + $this->assertIsArray($firstEntry); + $this->assertArrayHasKey('symbol', $firstEntry); + $this->assertEquals($this->symbol, $firstEntry['symbol']); + $this->assertArrayHasKey('marginType', $firstEntry); + $this->assertIsString($firstEntry['marginType']); + $this->assertArrayHasKey('isAutoAddMargin', $firstEntry); + $this->assertIsBool($firstEntry['isAutoAddMargin']); + $this->assertArrayHasKey('leverage', $firstEntry); + $this->assertIsNumeric($firstEntry['leverage']); + $this->assertArrayHasKey('maxNotionalValue', $firstEntry); + $this->assertIsNumeric($firstEntry['maxNotionalValue']); + } + + public function testOrderRateLimitFutures() + { + $res = $this->futuresBinance->futuresOrderRateLimit(); + $this->assertIsArray($res); + $firstEntry = $res[0]; + $this->assertIsArray($firstEntry); + $this->assertArrayHasKey('rateLimitType', $firstEntry); + $this->assertEquals('ORDERS', $firstEntry['rateLimitType']); + $this->assertArrayHasKey('interval', $firstEntry); + $this->assertIsString($firstEntry['interval']); + $this->assertArrayHasKey('intervalNum', $firstEntry); + $this->assertIsNumeric($firstEntry['intervalNum']); + $this->assertArrayHasKey('limit', $firstEntry); + $this->assertIsInt($firstEntry['limit']); + } + + public function testLeveragesFutures() + { + $res = $this->futuresBinance->futuresLeverages($this->symbol); + $this->assertIsArray($res); + $firstEntry = $res[0]; + $this->assertIsArray($firstEntry); + $this->assertArrayHasKey('symbol', $firstEntry); + $this->assertEquals($this->symbol, $firstEntry['symbol']); + $this->assertArrayHasKey('brackets', $firstEntry); + $this->assertIsArray($firstEntry['brackets']); + $firstBracket = $firstEntry['brackets'][0]; + $this->assertIsArray($firstBracket); + $this->assertArrayHasKey('bracket', $firstBracket); + $this->assertIsInt($firstBracket['bracket']); + $this->assertArrayHasKey('initialLeverage', $firstBracket); + $this->assertIsNumeric($firstBracket['initialLeverage']); + $this->assertArrayHasKey('notionalCap', $firstBracket); + $this->assertIsNumeric($firstBracket['notionalCap']); + $this->assertArrayHasKey('notionalFloor', $firstBracket); + $this->assertIsNumeric($firstBracket['notionalFloor']); + $this->assertArrayHasKey('maintMarginRatio', $firstBracket); + $this->assertIsNumeric($firstBracket['maintMarginRatio']); + $this->assertArrayHasKey('cum', $firstBracket); + $this->assertIsNumeric($firstBracket['cum']); + } + + public function testLedgerFutures() + { + $res = $this->futuresBinance->futuresLedger(); + $this->assertIsArray($res); + } + + public function testTradingStatusFutures() + { + $res = $this->futuresBinance->futuresTradingStatus(); + $this->assertIsArray($res); + $this->assertArrayHasKey('indicators', $res); + $this->assertIsArray($res['indicators']); + $this->assertArrayHasKey('updateTime', $res); + $this->assertIsInt($res['updateTime']); + } + + public function testFeeBurnStatusFutures() + { + $res = $this->futuresBinance->futuresFeeBurnStatus(); + $this->assertIsArray($res); + $this->assertArrayHasKey('feeBurn', $res); + $this->assertIsBool($res['feeBurn']); + } } From 54f481f0244f0599699c2957f7ae89a510849773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Thu, 17 Apr 2025 12:20:41 +0300 Subject: [PATCH 11/11] testOpenInterestFutures commented (the exchange returns null) --- tests/BinanceLiveTests.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/BinanceLiveTests.php b/tests/BinanceLiveTests.php index f4e34b73..6325284e 100644 --- a/tests/BinanceLiveTests.php +++ b/tests/BinanceLiveTests.php @@ -728,16 +728,16 @@ public function testSymbolOrderBookTickerFutures() // $this->futuresBinance->useTestnet = true; // reset to true for other tests // } - public function testOpenInterestFutures() - { - $res = $this->futuresBinance->futuresOpenInterest($this->symbol); - $this->assertIsArray($res); - $this->assertEquals($this->symbol, $res['symbol']); - $this->assertArrayHasKey('openInterest', $res); - $this->assertIsNumeric($res['openInterest']); - $this->assertArrayHasKey('time', $res); - $this->assertIsInt($res['time']); - } + // public function testOpenInterestFutures() + // { + // $res = $this->futuresBinance->futuresOpenInterest($this->symbol); // for now the exchange returns null + // $this->assertIsArray($res); + // $this->assertEquals($this->symbol, $res['symbol']); + // $this->assertArrayHasKey('openInterest', $res); + // $this->assertIsNumeric($res['openInterest']); + // $this->assertArrayHasKey('time', $res); + // $this->assertIsInt($res['time']); + // } // public function testOpenInterestHistoryFutures() // Could throw an error if useTestnet is set to false // {