Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Fix miniTicker + 7 commits by dmzoneill
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Eyrick authored Apr 25, 2018
2 parents b6fd311 + 876a819 commit 9f55594
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 11 deletions.
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
36 changes: 36 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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("<api key>","<secret>");
$ticker = $api->prices();
print_r($ticker); // List prices of all symbols
echo "Price of BNB: {$ticker['BNBBTC']} BTC";
```

**result**
```
{
"result":"result"
}
```

thank you
39 changes: 29 additions & 10 deletions php-binance-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9f55594

Please sign in to comment.