Skip to content

Commit 4be9587

Browse files
author
Jon Eyrick
authored
PRICE_FILTER fix: roundTicks now rounds price with tickSize
> roundTicks: Used to round price with tickSize. Example: `roundTicks(0.12345, '0.001') = 0.123` ```php function roundTicks($price, $tickSize) { $precision = strlen(rtrim(substr($tickSize,strpos($tickSize, '.', 1) + 1), '0')); return number_format($price, $precision, '.', ''); } echo roundTicks(0.00016552, '0.00000010'); ```
1 parent 1d20b3e commit 4be9587

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

php-binance-api.php

+17-5
Original file line numberDiff line numberDiff line change
@@ -1498,17 +1498,29 @@ private function depthData(string $symbol, array $json)
14981498
}
14991499

15001500
/**
1501-
* roundStep rounds number with given step
1502-
* @param $value price
1501+
* roundStep rounds quantity with stepSize
1502+
* @param $qty quantity
15031503
* @param $stepSize parameter from exchangeInfo
15041504
* @return rounded value. example: roundStep(1.2345, 0.1) = 1.2
15051505
*
15061506
*/
1507-
public function roundStep($value, $stepSize = 0.1) {
1507+
public function roundStep($qty, $stepSize = 0.1) {
15081508
$precision = strlen(substr(strrchr(rtrim($stepSize,'0'), '.'), 1));
1509-
return round((($value / $stepSize) | 0) * $stepSize, $precision);
1509+
return round((($qty / $stepSize) | 0) * $stepSize, $precision);
15101510
}
1511-
1511+
1512+
/**
1513+
* roundTicks rounds price with tickSize
1514+
* @param $value price
1515+
* @param $tickSize parameter from exchangeInfo
1516+
* @return rounded value. example: roundStep(1.2345, 0.1) = 1.2
1517+
*
1518+
*/
1519+
public function roundTicks($price, $tickSize) {
1520+
$precision = strlen(rtrim(substr($tickSize,strpos($tickSize, '.', 1) + 1), '0'));
1521+
return number_format($price, $precision, '.', '');
1522+
}
1523+
15121524
/**
15131525
* getTransfered gets the total transfered in b,Kb,Mb,Gb
15141526
*

0 commit comments

Comments
 (0)