From 3b2b83a56fe234b0e40a48f82fec21f15f6fd78c Mon Sep 17 00:00:00 2001 From: David O Neill Date: Thu, 15 Mar 2018 21:55:51 +0000 Subject: [PATCH 1/5] Update test cases --- tests/BinanceTest.php | 62 ++++++++++++++++++++++++++++++------------- tests/run.sh | 2 +- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/tests/BinanceTest.php b/tests/BinanceTest.php index 1b601b11..853a40d8 100644 --- a/tests/BinanceTest.php +++ b/tests/BinanceTest.php @@ -42,10 +42,14 @@ public function testBuy() { // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->buy( "TRXBTC", "5", "0.001" ); - $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( isset( $result['code'] ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + $this->assertTrue( $result['code'] == "-2010" ); + } + + if( isset( $result['code'] ) == false ) { + fwrite(STDOUT, __METHOD__ . ": shouldn't be any code in the account\n"); } } public function testBuyTest() { @@ -62,10 +66,14 @@ public function testSell() { // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->sell( "TRXBTC", "5", "0.001" ); - $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( isset( $result['code'] ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + $this->assertTrue( $result['code'] == "-2010" ); + } + + if( isset( $result['code'] ) == false ) { + fwrite(STDOUT, __METHOD__ . ": shouldn't be any code in the account\n"); } } public function testSellTest() { @@ -75,17 +83,21 @@ public function testSellTest() { $this->assertTrue( ( isset( $result['code'] ) == false ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": sell error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testMarketBuy() { // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->marketBuy( "TRXBTC", "5" ); - $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( isset( $result['code'] ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + $this->assertTrue( $result['code'] == "-2010" ); + } + + if( isset( $result['code'] ) == false ) { + fwrite(STDOUT, __METHOD__ . ": shouldn't be any code in the account\n"); } } public function testMarketBuyTest() { @@ -95,17 +107,21 @@ public function testMarketBuyTest() { $this->assertTrue( ( isset( $result['code'] ) == false ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": market buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testMarketSell() { // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->marketSell( "TRXBTC", "5" ); - $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( isset( $result['code'] ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + $this->assertTrue( $result['code'] == "-2010" ); + } + + if( isset( $result['code'] ) == false ) { + fwrite(STDOUT, __METHOD__ . ": shouldn't be any code in the account\n"); } } public function testMarketSellTest() { @@ -115,27 +131,35 @@ public function testMarketSellTest() { $this->assertTrue( ( isset( $result['code'] ) == false ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": market sell error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testCancel() { // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->cancel( "TRXBTC", "55555555" ); - $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( isset( $result['code'] ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + $this->assertTrue( $result['code'] == "-2011" ); + } + + if( isset( $result['code'] ) == false ) { + fwrite(STDOUT, __METHOD__ . ": shouldn't be anything to cancel\n"); } } public function testOrderStatus() { // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->orderStatus( "TRXBTC", "55555555" ); - $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( isset( $result['code'] ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + $this->assertTrue( $result['code'] == "-2013" ); + } + + if( isset( $result['code'] ) == false ) { + fwrite(STDOUT, __METHOD__ . ": shouldn't be any order with this id\n"); } } public function testOpenOrders() { @@ -158,7 +182,7 @@ public function testOrders() { fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } - public function testHstory() { + public function testHistory() { // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->history( "TRXBTC" ); @@ -245,7 +269,7 @@ public function testAccount() { public function testPrevDay() { // todo fwrite(STDOUT, __METHOD__ . "\n"); - $result = $this->_testable->prevDay( "TRXBTX" ); + $result = $this->_testable->prevDay( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); if( isset( $result['code'] ) ) { @@ -255,7 +279,7 @@ public function testPrevDay() { public function testAggTrades() { // todo fwrite(STDOUT, __METHOD__ . "\n"); - $result = $this->_testable->aggTrades( "TRXBTX" ); + $result = $this->_testable->aggTrades( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); if( isset( $result['code'] ) ) { @@ -265,7 +289,7 @@ public function testAggTrades() { public function testDepth() { // todo fwrite(STDOUT, __METHOD__ . "\n"); - $result = $this->_testable->depth( "TRXBTX" ); + $result = $this->_testable->depth( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); if( isset( $result['code'] ) ) { diff --git a/tests/run.sh b/tests/run.sh index ca6ec16c..ca968890 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -2,4 +2,4 @@ composer install ./vendor/bin/phpunit --verbose --debug --coverage-clover build/logs/clover.xml --bootstrap vendor/autoload.php BinanceTest -php ./vendor/bin/php-coveralls -v +#php ./vendor/bin/php-coveralls -v From 8b1468455f8c72020c5dd63a18db04cead93b983 Mon Sep 17 00:00:00 2001 From: David O Neill Date: Thu, 15 Mar 2018 22:51:59 +0000 Subject: [PATCH 2/5] Addtional checks for test cases --- tests/BinanceTest.php | 124 ++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 78 deletions(-) diff --git a/tests/BinanceTest.php b/tests/BinanceTest.php index 853a40d8..628178e4 100644 --- a/tests/BinanceTest.php +++ b/tests/BinanceTest.php @@ -34,12 +34,26 @@ public function testInstantiate() { $this->_testable = new Binance\API(); $this->assertInstanceOf('Binance\API', $this->_testable); } - public function testAccountInfo() { + public function testAccount() { fwrite(STDOUT, __METHOD__ . "\n"); - $this->assertTrue( isset( $this->_testable->account()['balances'] ) ); + $details = $this->_testable->account(); + $check_keys = array( 'makerCommission', + 'takerCommission', + 'buyerCommission', + 'sellerCommission', + 'canTrade', + 'canWithdraw', + 'canDeposit', + 'updateTime', + 'balances' ); + + foreach ($check_keys as $check_key) { + $this->assertTrue( isset( $details[ $check_key ] ) ); + } + + $this->assertTrue( count( $details[ 'balances' ] ) > 0 ); } public function testBuy() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->buy( "TRXBTC", "5", "0.001" ); $this->assertTrue( isset( $result['code'] ) ); @@ -49,11 +63,10 @@ public function testBuy() { } if( isset( $result['code'] ) == false ) { - fwrite(STDOUT, __METHOD__ . ": shouldn't be any code in the account\n"); + fwrite(STDOUT, __METHOD__ . ": shouldn't be any money in the account\n"); } } public function testBuyTest() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->buyTest( "TRXBTC", "5", "0.001" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); @@ -63,7 +76,6 @@ public function testBuyTest() { } } public function testSell() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->sell( "TRXBTC", "5", "0.001" ); $this->assertTrue( isset( $result['code'] ) ); @@ -77,7 +89,6 @@ public function testSell() { } } public function testSellTest() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->sellTest( "TRXBTC", "5", "0.001" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); @@ -87,7 +98,6 @@ public function testSellTest() { } } public function testMarketBuy() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->marketBuy( "TRXBTC", "5" ); $this->assertTrue( isset( $result['code'] ) ); @@ -101,7 +111,6 @@ public function testMarketBuy() { } } public function testMarketBuyTest() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->marketBuyTest( "TRXBTC", "5" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); @@ -111,7 +120,6 @@ public function testMarketBuyTest() { } } public function testMarketSell() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->marketSell( "TRXBTC", "5" ); $this->assertTrue( isset( $result['code'] ) ); @@ -125,7 +133,6 @@ public function testMarketSell() { } } public function testMarketSellTest() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->marketSellTest( "TRXBTC", "5" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); @@ -135,7 +142,6 @@ public function testMarketSellTest() { } } public function testCancel() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->cancel( "TRXBTC", "55555555" ); $this->assertTrue( isset( $result['code'] ) ); @@ -149,7 +155,6 @@ public function testCancel() { } } public function testOrderStatus() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->orderStatus( "TRXBTC", "55555555" ); $this->assertTrue( isset( $result['code'] ) ); @@ -163,297 +168,260 @@ public function testOrderStatus() { } } public function testOpenOrders() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->openOrders( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( is_array( $result ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": open orders error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testOrders() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->orders( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( is_array( $result ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": orders error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testHistory() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->history( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( is_array( $result ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": my trades error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testUseServerTime() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testTime() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->time(); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( isset( $result[ 'serverTime' ] ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": server time error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testExchangeInfo() { fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->exchangeInfo(); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $check_keys = array( 'timezone', 'serverTime', 'rateLimits', 'exchangeFilters', 'symbols' ); + + foreach ($check_keys as $check_key) { + $this->assertTrue( isset( $details[ $check_key ] ) ); + } + + $this->assertTrue( count( $details[ 'symbols' ] ) > 0 ); + $this->assertTrue( count( $details[ 'rateLimits' ] ) > 0 ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": exchange info error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testWithdraw() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testDepositAddress() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testDepositHistory() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testWithdrawHistory() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testPrices() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->prices(); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( count( $result ) > 0 ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": prices error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testBookPrices() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->bookPrices(); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( count( $result ) > 0 ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); - } - } - public function testAccount() { - // todo - fwrite(STDOUT, __METHOD__ . "\n"); - $result = $this->_testable->account(); - $this->assertTrue( ( isset( $result['code'] ) == false ) ); - - if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": book prices error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testPrevDay() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->prevDay( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": previous day error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testAggTrades() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->aggTrades( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( count( $result ) > 0 ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": agg trades error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testDepth() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->depth( "TRXBTC" ); $this->assertTrue( ( isset( $result['code'] ) == false ) ); + $this->assertTrue( isset( $result['bids'] ) ); + $this->assertTrue( isset( $result['asks'] ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": depth error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testBalances() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $result = $this->_testable->balances(); $this->assertTrue( ( isset( $result['code'] ) == false ) ); if( isset( $result['code'] ) ) { - fwrite(STDOUT, __METHOD__ . ": buy error: " . $result['code'] . ":" . $result['msg'] ."\n"); + fwrite(STDOUT, __METHOD__ . ": balances error: " . $result['code'] . ":" . $result['msg'] ."\n"); } } public function testGetProxyUriString() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testHttpRequest() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testOrder() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testOrderTest() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testCandlesticks() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testBalanceData() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testBalanceHandler() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testTickerStreamHandler() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testExecutionHandler() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testChartData() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testTradesData() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testBookPriceData() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testPriceData() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testCumulative() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testHighstock() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testDepthHandler() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testChartHandler() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testFirst() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testLast() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testDisplayDepth() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testSortDepth() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testDepthData() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testDepthCache() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testTicker() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testChart() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testKeepAlive() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testMiniTicker() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testGetTransfered() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } public function testGetRequestCount() { - // todo fwrite(STDOUT, __METHOD__ . "\n"); $this->assertTrue( true ); } From 2e4a2db45812344d0b4fd6109c6ae8d7a9789ffd Mon Sep 17 00:00:00 2001 From: David O Neill Date: Thu, 15 Mar 2018 22:58:23 +0000 Subject: [PATCH 3/5] Additional checks for tests cases --- tests/BinanceTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/BinanceTest.php b/tests/BinanceTest.php index 628178e4..f6ca4d31 100644 --- a/tests/BinanceTest.php +++ b/tests/BinanceTest.php @@ -49,6 +49,9 @@ public function testAccount() { foreach ($check_keys as $check_key) { $this->assertTrue( isset( $details[ $check_key ] ) ); + if( isset( $details[ $check_key ] ) == false ) { + fwrite(STDOUT, __METHOD__ . ": exchange info error: $check_key missing\n"); + } } $this->assertTrue( count( $details[ 'balances' ] ) > 0 ); @@ -218,7 +221,10 @@ public function testExchangeInfo() { $check_keys = array( 'timezone', 'serverTime', 'rateLimits', 'exchangeFilters', 'symbols' ); foreach ($check_keys as $check_key) { - $this->assertTrue( isset( $details[ $check_key ] ) ); + $this->assertTrue( isset( $result[ $check_key ] ) ); + if( isset( $result[ $check_key ] ) == false ) { + fwrite(STDOUT, __METHOD__ . ": exchange info error: $check_key missing\n"); + } } $this->assertTrue( count( $details[ 'symbols' ] ) > 0 ); From 43d4edd41fc00d59b8f12dfe2656add029a2849e Mon Sep 17 00:00:00 2001 From: David O Neill Date: Thu, 15 Mar 2018 23:01:02 +0000 Subject: [PATCH 4/5] Addtional test case fixes --- tests/BinanceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/BinanceTest.php b/tests/BinanceTest.php index f6ca4d31..5164d0ea 100644 --- a/tests/BinanceTest.php +++ b/tests/BinanceTest.php @@ -227,8 +227,8 @@ public function testExchangeInfo() { } } - $this->assertTrue( count( $details[ 'symbols' ] ) > 0 ); - $this->assertTrue( count( $details[ 'rateLimits' ] ) > 0 ); + $this->assertTrue( count( $result[ 'symbols' ] ) > 0 ); + $this->assertTrue( count( $result[ 'rateLimits' ] ) > 0 ); if( isset( $result['code'] ) ) { fwrite(STDOUT, __METHOD__ . ": exchange info error: " . $result['code'] . ":" . $result['msg'] ."\n"); From ba61ac49ea5518709c358b6d3c9443885849d623 Mon Sep 17 00:00:00 2001 From: Chikashi Kato Date: Fri, 16 Mar 2018 16:47:13 -0700 Subject: [PATCH 5/5] Pass $symbol to the close event handler of the websocket in order to display it in the error message correctly. --- php-binance-api.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index c765e650..ca62be5f 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -588,7 +588,7 @@ public function depthCache($symbols, $callback) { if ( !isset($this->depthQueue[$symbol]) ) $this->depthQueue[$symbol] = []; if ( !isset($this->depthCache[$symbol]) ) $this->depthCache[$symbol] = ["bids" => [], "asks" => []]; $this->info[$symbol]['firstUpdate'] = 0; - $connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@depth')->then(function($ws) use($callback) { + $connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@depth')->then(function($ws) use($callback, $symbol) { $ws->on('message', function($data) use($ws, $callback) { $json = json_decode($data, true); $symbol = $json['s']; @@ -599,7 +599,7 @@ public function depthCache($symbols, $callback) { $this->depthHandler($json); call_user_func($callback, $this, $symbol, $this->depthCache[$symbol]); }); - $ws->on('close', function($code = null, $reason = null) { + $ws->on('close', function($code = null, $reason = null) use($symbol) { echo "depthCache({$symbol}) WebSocket Connection closed! ({$code} - {$reason})".PHP_EOL; }); }, function($e) use($loop) { @@ -625,7 +625,7 @@ public function trades($symbols, $callback) { foreach ( $symbols as $symbol ) { if ( !isset($this->info[$symbol]) ) $this->info[$symbol] = []; //$this->info[$symbol]['tradesCallback'] = $callback; - $connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@aggTrade')->then(function($ws) use($callback) { + $connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@aggTrade')->then(function($ws) use($callback, $symbol) { $ws->on('message', function($data) use($ws, $callback) { $json = json_decode($data, true); $symbol = $json['s']; @@ -637,7 +637,7 @@ public function trades($symbols, $callback) { //$this->info[$symbol]['tradesCallback']($this, $symbol, $trades); call_user_func($callback, $this, $symbol, $trades); }); - $ws->on('close', function($code = null, $reason = null) { + $ws->on('close', function($code = null, $reason = null) use($symbol) { echo "trades({$symbol}) WebSocket Connection closed! ({$code} - {$reason})".PHP_EOL; }); }, function($e) use($loop) { @@ -687,7 +687,7 @@ public function chart($symbols, $interval = "30m", $callback) { $this->chartQueue[$symbol][$interval] = []; $this->info[$symbol][$interval]['firstOpen'] = 0; //$this->info[$symbol]['chartCallback'.$interval] = $callback; - $connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@kline_'.$interval)->then(function($ws) use($callback) { + $connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@kline_'.$interval)->then(function($ws) use($callback, $symbol) { $ws->on('message', function($data) use($ws, $callback) { $json = json_decode($data); $chart = $json->k; @@ -697,7 +697,7 @@ public function chart($symbols, $interval = "30m", $callback) { //$this->info[$symbol]['chartCallback'.$interval]($this, $symbol, $this->charts[$symbol][$interval]); call_user_func($callback, $this, $symbol, $this->charts[$symbol][$interval]); }); - $ws->on('close', function($code = null, $reason = null) { + $ws->on('close', function($code = null, $reason = null) use($symbol) { echo "chart({$symbol},{$interval}) WebSocket Connection closed! ({$code} - {$reason})".PHP_EOL; }); }, function($e) use($loop) {