Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
PRICE_FILTER fix: roundTicks now rounds price with tickSize
Browse files Browse the repository at this point in the history
> 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');
```
  • Loading branch information
Jon Eyrick authored Sep 8, 2018
1 parent 1d20b3e commit 4be9587
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions php-binance-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1498,17 +1498,29 @@ private function depthData(string $symbol, array $json)
}

/**
* roundStep rounds number with given step
* @param $value price
* roundStep rounds quantity with stepSize
* @param $qty quantity
* @param $stepSize parameter from exchangeInfo
* @return rounded value. example: roundStep(1.2345, 0.1) = 1.2
*
*/
public function roundStep($value, $stepSize = 0.1) {
public function roundStep($qty, $stepSize = 0.1) {
$precision = strlen(substr(strrchr(rtrim($stepSize,'0'), '.'), 1));
return round((($value / $stepSize) | 0) * $stepSize, $precision);
return round((($qty / $stepSize) | 0) * $stepSize, $precision);
}


/**
* roundTicks rounds price with tickSize
* @param $value price
* @param $tickSize parameter from exchangeInfo
* @return rounded value. example: roundStep(1.2345, 0.1) = 1.2
*
*/
public function roundTicks($price, $tickSize) {
$precision = strlen(rtrim(substr($tickSize,strpos($tickSize, '.', 1) + 1), '0'));
return number_format($price, $precision, '.', '');
}

/**
* getTransfered gets the total transfered in b,Kb,Mb,Gb
*
Expand Down

0 comments on commit 4be9587

Please sign in to comment.