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

Commit 185a012

Browse files
author
Jon Eyrick
authored
Add roundTicks function to fix PRICE_FILTER errors
Usage: binance.roundTicks(price, tickSize) ```js function roundTicks(number, tickSize) { const formatter = new Intl.NumberFormat('en-US', { style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 8 }); const precision = formatter.format(tickSize).split('.')[1].length || 0; if ( typeof number === 'string' ) number = parseFloat(number); return number.toFixed(precision); } ```
1 parent 3a3b73e commit 185a012

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

node-binance-api.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,14 +814,27 @@ let api = function Binance() {
814814

815815
/**
816816
* rounds number with given step
817-
* @param {float} number - number to round
818-
* @param {float} stepSize - step size
817+
* @param {float} number - quantity to round
818+
* @param {float} stepSize - stepSize as specified by exchangeInfo
819819
* @return {float} - number
820820
*/
821821
roundStep: function (number, stepSize) {
822822
const precision = stepSize.toString().split('.')[1].length || 0;
823823
return (((number / stepSize) | 0) * stepSize).toFixed(precision);
824824
},
825+
826+
/**
827+
* rounds price to required precision
828+
* @param {float} number - price to round
829+
* @param {float} tickSize - tickSize as specified by exchangeInfo
830+
* @return {float} - number
831+
*/
832+
roundTicks: function (number, tickSize) {
833+
const formatter = new Intl.NumberFormat('en-US', { style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 8 });
834+
const precision = formatter.format(tickSize).split('.')[1].length || 0;
835+
if ( typeof number === 'string' ) number = parseFloat(number);
836+
return number.toFixed(precision);
837+
},
825838

826839
/**
827840
* Gets percentage of given numbers

0 commit comments

Comments
 (0)