Skip to content

Commit 368f5ef

Browse files
author
max-grim
committed
add php-binance-api-rate-limiter.php,
1. Laravel return error Class 'Binance\RateLimiter' not found 2. Round as necessary before selling
1 parent 25fea7e commit 368f5ef

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ vendor**
44
.project
55
.settings/**
66

7+
.DS_Store

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
},
2525
"autoload": {
2626
"classmap": [
27-
"php-binance-api.php"
27+
"php-binance-api.php",
28+
"php-binance-api-rate-limiter.php"
2829
]
2930
}
3031
}

php-binance-api.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class API
5050
private $btc_total = 0.00;
5151

5252
// /< value of available onOrder assets
53-
53+
54+
protected $exchangeInfo = NULL;
55+
5456
/**
5557
* Constructor for the class,
5658
* send as many argument as you want.
@@ -336,6 +338,9 @@ public function marketBuyTest(string $symbol, $quantity, array $flags = [])
336338
*/
337339
public function marketSell(string $symbol, $quantity, array $flags = [])
338340
{
341+
$c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']);
342+
$quantity = $this->floorDecimal($quantity, $c);
343+
339344
return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags);
340345
}
341346

@@ -501,7 +506,20 @@ public function time()
501506
*/
502507
public function exchangeInfo()
503508
{
504-
return $this->httpRequest("v1/exchangeInfo");
509+
if(!$this->exchangeInfo){
510+
511+
$arr = $this->httpRequest("v1/exchangeInfo");
512+
513+
$this->exchangeInfo = $arr;
514+
$this->exchangeInfo['symbols'] = null;
515+
516+
foreach($arr['symbols'] as $key => $value){
517+
$this->exchangeInfo['symbols'][$value['symbol']] = $value;
518+
}
519+
520+
}
521+
522+
return $this->exchangeInfo;
505523
}
506524

507525
public function assetDetail()
@@ -2283,4 +2301,10 @@ private function downloadCurlCaBundle()
22832301
fwrite($fp, $result);
22842302
fclose($fp);
22852303
}
2304+
2305+
private function floorDecimal($n, $decimals=2)
2306+
{
2307+
return floor($n * pow(10, $decimals)) / pow(10, $decimals);
2308+
}
2309+
22862310
}

0 commit comments

Comments
 (0)