Skip to content

Commit

Permalink
add php-binance-api-rate-limiter.php,
Browse files Browse the repository at this point in the history
1. Laravel return error Class 'Binance\RateLimiter' not found
2. Round as necessary before selling
  • Loading branch information
max-grim committed Oct 18, 2019
1 parent 25fea7e commit 368f5ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ vendor**
.project
.settings/**

.DS_Store
3 changes: 2 additions & 1 deletion composer.json
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
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 368f5ef

Please sign in to comment.