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 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 diff --git a/php-binance-api.php b/php-binance-api.php index daaaf9b4..7a8605be 100644 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -515,17 +515,21 @@ 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); + ]; + if ($fromTradeId > 0) { + $parameters["fromId"] = $fromTradeId; + } + + return $this->httpRequest("v3/myTrades", "GET", $parameters, true); } /** @@ -798,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); } /** @@ -959,14 +973,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++; @@ -1104,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 []; } @@ -2110,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;