From 897c9bbc0a09b0da080fec141b61d464898cc293 Mon Sep 17 00:00:00 2001 From: Jon Eyrick Date: Sat, 21 Apr 2018 20:10:07 -0700 Subject: [PATCH 1/8] fix history() fromId, defaults to all --- php-binance-api.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index daaaf9b4..40d8cb20 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -515,17 +515,18 @@ public function orders(string $symbol, int $limit = 500, int $fromOrderId = 1) * * @param $symbol string the currency symbol * @param $limit int the amount of orders returned - * @param $fromTradeId int return the orders from this order onwards + * @param $fromTradeId int (optional) return the orders from this order onwards. negative for all * @return array with error message or array of orderDetails array * @throws \Exception */ - public function history(string $symbol, int $limit = 500, int $fromTradeId = 1) + public function history(string $symbol, int $limit = 500, int $fromTradeId = -1) { - return $this->httpRequest("v3/myTrades", "GET", [ + $parameters = [ "symbol" => $symbol, - "limit" => $limit, - "fromId" => $fromTradeId, - ], true); + "limit" => $limit + ]; + if ( $fromTradeId > 0 ) $parameters["fromId"] = $fromTradeId; + return $this->httpRequest( "v3/myTrades", "GET", $parameters, true ); } /** From ea813d4e1f59722463c06fcfa0dec7079e0c7d7f Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 22 Apr 2018 10:50:47 +0100 Subject: [PATCH 2/8] Create ISSUE_TEMPLATE.md --- ISSUE_TEMPLATE.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ISSUE_TEMPLATE.md diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..a5901fa2 --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,36 @@ +**Title** +- bug: XYZ broken +- feature: please add +- enhancement: add this to existing features + +**Short Description:** +- Unable to get a result from blah + +**Platform:** +- windows +- linux +- macos + +**php version:** +- 7.0.24 + +**Long descrption** +- Doing xyz results in ypr and failing when fph + +**code** +```php +require 'vendor/autoload.php'; +$api = new Binance\API("",""); +$ticker = $api->prices(); +print_r($ticker); // List prices of all symbols +echo "Price of BNB: {$ticker['BNBBTC']} BTC"; +``` + +**result** +``` +{ + "result":"result" +} +``` + +thank you From 0ac1e5119f5bcdb9c0a98ffe102f608e423d6dc3 Mon Sep 17 00:00:00 2001 From: lanort Date: Sat, 21 Apr 2018 21:08:12 +0200 Subject: [PATCH 3/8] Output error message in httpRequest() only if $httpDebug is true The httpRequest() function always outputs errors, even if `$this->httpDebug` is set to false, which disables curl output. Now this error output is only shown, if `$this->httpDebug` is set to true. --- php-binance-api.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 40d8cb20..5c77a3cc 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -960,14 +960,18 @@ private function httpRequest(string $url, string $method = "GET", array $params // Check if any error occurred if (curl_errno($curl) > 0) { // WPCS: XSS OK. - echo 'Curl error: ' . curl_error($curl) . "\n"; + if($this->httpDebug) { + echo 'Curl error: ' . curl_error($curl) . "\n"; + } return []; } curl_close($curl); $json = json_decode($output, true); if (isset($json['msg'])) { // WPCS: XSS OK. - echo "signedRequest error: {$output}" . PHP_EOL; + if($this->httpDebug) { + echo "signedRequest error: {$output}" . PHP_EOL; + } } $this->transfered += strlen($output); $this->requestCount++; From 5ef4772cb2f04d1308710c3c307bdc4fad85f160 Mon Sep 17 00:00:00 2001 From: dmzoneill Date: Sun, 22 Apr 2018 10:54:32 +0100 Subject: [PATCH 4/8] fix formatting --- php-binance-api.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 5c77a3cc..3c55f596 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -521,12 +521,15 @@ public function orders(string $symbol, int $limit = 500, int $fromOrderId = 1) */ public function history(string $symbol, int $limit = 500, int $fromTradeId = -1) { - $parameters = [ + $parameters = [ "symbol" => $symbol, - "limit" => $limit + "limit" => $limit, ]; - if ( $fromTradeId > 0 ) $parameters["fromId"] = $fromTradeId; - return $this->httpRequest( "v3/myTrades", "GET", $parameters, true ); + if ($fromTradeId > 0) { + $parameters["fromId"] = $fromTradeId; + } + + return $this->httpRequest("v3/myTrades", "GET", $parameters, true); } /** @@ -960,7 +963,7 @@ private function httpRequest(string $url, string $method = "GET", array $params // Check if any error occurred if (curl_errno($curl) > 0) { // WPCS: XSS OK. - if($this->httpDebug) { + if ($this->httpDebug) { echo 'Curl error: ' . curl_error($curl) . "\n"; } return []; @@ -969,7 +972,7 @@ private function httpRequest(string $url, string $method = "GET", array $params $json = json_decode($output, true); if (isset($json['msg'])) { // WPCS: XSS OK. - if($this->httpDebug) { + if ($this->httpDebug) { echo "signedRequest error: {$output}" . PHP_EOL; } } From 685ce971d17216843b51d8a336209706e8acb2dd Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 22 Apr 2018 21:49:32 +0100 Subject: [PATCH 5/8] Update .travis.yml --- .travis.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9bf5ee4f..d2951a73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,9 @@ matrix: - php: 7.0 - php: 7.1 - php: 7.2 - env: QUALITY=yes + env: + - QUALITY=yes + - PROXY_VALIDATION=yes - php: nightly - os: osx osx_image: xcode7.2 @@ -17,6 +19,12 @@ notifications: webhooks: https://www.travisbuddy.com/?insertMode=update before_script: + - if [[ $PROXY_VALIDATION == "yes" ]]; then mkdir -vp /home/travis/.ssh/; fi + - if [[ $PROXY_VALIDATION == "yes" ]]; then ssh-keygen -f /home/travis/.ssh/id_ecdsa -t ecdsa -N ''; fi + - if [[ $PROXY_VALIDATION == "yes" ]]; then cat /home/travis/.ssh/*.pub > /home/travis/.ssh/authorized_keys; fi + - if [[ $PROXY_VALIDATION == "yes" ]]; then chmod 600 /home/travis/.ssh/*; fi + - if [[ $PROXY_VALIDATION == "yes" ]]; then chmod 700 /home/travis/.ssh/.; fi + - if [[ $PROXY_VALIDATION == "yes" ]]; then ssh -f -o "StrictHostKeyChecking no" -D 9999 -q -N travis@localhost; fi - mkdir -vp ~/.config/jaggedsoft/ - mkdir -vp build/logs - travis_retry wget https://raw.githubusercontent.com/jaggedsoft/php-binance-api/gh-travis/composer-test.json -O composer-test.json @@ -32,9 +40,14 @@ before_script: - chmod -v +x codecov.sh - chmod -v +x docs.sh - chmod -v +x coveralls.phar + - travis_retry sudo apt-get install tinyproxy curl + - if [[ $PROXY_VALIDATION == "yes" ]]; then tinyproxy; fi + - if [[ $PROXY_VALIDATION == "yes" ]]; then travis_retry curl -v -I --proxy socks://127.0.0.1:9999 https://www.google.com; fi script: - ./vendor/bin/phpunit --verbose --debug --coverage-clover build/logs/clover.xml --bootstrap vendor/autoload.php php-binance-api-test + - if [[ $PROXY_VALIDATION == "yes" ]]; then export socks_proxy=http://127.0.0.1:9999; fi + - if [[ $PROXY_VALIDATION == "yes" ]]; then ./vendor/bin/phpunit --verbose --debug --coverage-clover build/logs/clover.xml --bootstrap vendor/autoload.php php-binance-api-test; fi - php fmt.phar -v --psr2 --indent_with_space=4 -o=php-binance-api.php.fmt php-binance-api.php - diff php-binance-api.php.fmt php-binance-api.php From 0be3376ba9a71f26fdcd39a74d405594811efa9a Mon Sep 17 00:00:00 2001 From: dmzoneill Date: Wed, 25 Apr 2018 15:58:04 +0100 Subject: [PATCH 6/8] Updates for checks on accoutn blance data --- php-binance-api.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/php-binance-api.php b/php-binance-api.php index 3c55f596..6eb496f7 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -802,7 +802,17 @@ public function balances($priceData = false) $priceData = false; } - return $this->balanceData($this->httpRequest("v3/account", "GET", [], true), $priceData); + $account = $this->httpRequest("v3/account", "GET", [], true); + + if (is_array($account) === false) { + echo "Error: unable to fetch your account details" . PHP_EOL; + } + + if (isset($account['balances']) === false) { + echo "Error: your balances were empty or unset" . PHP_EOL; + } + + return $this->balanceData($account, $priceData); } /** From fb08002dc98b525ce94cad8264d419968e54980f Mon Sep 17 00:00:00 2001 From: Jon Eyrick Date: Wed, 25 Apr 2018 12:03:44 -0700 Subject: [PATCH 7/8] Troubleshooting error message for balanceData --- php-binance-api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php-binance-api.php b/php-binance-api.php index 6eb496f7..0aa4340d 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1122,7 +1122,8 @@ private function balanceData(array $array, $priceData) if (empty($array) || empty($array['balances'])) { // WPCS: XSS OK. - echo "balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option." . PHP_EOL; + echo "balanceData error: Please make sure your system time is synchronized: call $api->useServerTime() before this function" . PHP_EOL; + echo "ERROR: Invalid request. Please double check your API keys and permissions." . PHP_EOL; return []; } From 876a819e39000f4c10dd485885deb5fcfbce891b Mon Sep 17 00:00:00 2001 From: Jon Eyrick Date: Wed, 25 Apr 2018 12:21:21 -0700 Subject: [PATCH 8/8] Fix miniTicker endpoint --- 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 0aa4340d..7a8605be 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -2129,7 +2129,7 @@ public function miniTicker(callable $callback) // @codeCoverageIgnoreStart // phpunit can't cover async function - \Ratchet\Client\connect('wss://stream2.binance.com:9443/ws/!miniTicker@arr@1000ms')->then(function ($ws) use ($callback, $endpoint) { + \Ratchet\Client\connect($this->stream . '!miniTicker@arr')->then(function ($ws) use ($callback, $endpoint) { $ws->on('message', function ($data) use ($ws, $callback, $endpoint) { if ($this->subscriptions[$endpoint] === false) { //$this->subscriptions[$endpoint] = null;