From 368f5ef094657b6868cfd7499ae7c00436c3d51f Mon Sep 17 00:00:00 2001 From: max-grim Date: Fri, 18 Oct 2019 18:13:42 +0300 Subject: [PATCH] add php-binance-api-rate-limiter.php, 1. Laravel return error Class 'Binance\RateLimiter' not found 2. Round as necessary before selling --- .gitignore | 1 + composer.json | 3 ++- php-binance-api.php | 28 ++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 94af004b..b8341e4d 100755 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ vendor** .project .settings/** +.DS_Store diff --git a/composer.json b/composer.json index c1e35239..95ea673a 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ }, "autoload": { "classmap": [ - "php-binance-api.php" + "php-binance-api.php", + "php-binance-api-rate-limiter.php" ] } } diff --git a/php-binance-api.php b/php-binance-api.php index ce4bd6a6..cf8eeed2 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -50,7 +50,9 @@ class API private $btc_total = 0.00; // /< value of available onOrder assets - + + protected $exchangeInfo = NULL; + /** * Constructor for the class, * send as many argument as you want. @@ -336,6 +338,9 @@ public function marketBuyTest(string $symbol, $quantity, array $flags = []) */ public function marketSell(string $symbol, $quantity, array $flags = []) { + $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']); + $quantity = $this->floorDecimal($quantity, $c); + return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags); } @@ -501,7 +506,20 @@ public function time() */ public function exchangeInfo() { - return $this->httpRequest("v1/exchangeInfo"); + if(!$this->exchangeInfo){ + + $arr = $this->httpRequest("v1/exchangeInfo"); + + $this->exchangeInfo = $arr; + $this->exchangeInfo['symbols'] = null; + + foreach($arr['symbols'] as $key => $value){ + $this->exchangeInfo['symbols'][$value['symbol']] = $value; + } + + } + + return $this->exchangeInfo; } public function assetDetail() @@ -2283,4 +2301,10 @@ private function downloadCurlCaBundle() fwrite($fp, $result); fclose($fp); } + + private function floorDecimal($n, $decimals=2) + { + return floor($n * pow(10, $decimals)) / pow(10, $decimals); + } + }