Skip to content

Commit

Permalink
fix laravel rate-limiter error, round as necessary before selling by …
Browse files Browse the repository at this point in the history
…max-grim

add php-binance-api-rate-limiter.php && Round as necessary before selling
  • Loading branch information
jaggedsoft authored Oct 18, 2019
2 parents 25fea7e + 368f5ef commit a7774eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor**
.project
.settings/**

.DS_Store
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"autoload": {
"classmap": [
"php-binance-api.php"
"php-binance-api.php",
"php-binance-api-rate-limiter.php"
]
}
}
28 changes: 26 additions & 2 deletions php-binance-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

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

}

0 comments on commit a7774eb

Please sign in to comment.