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); + } + }