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

Commit 9dea9e7

Browse files
author
Jon Eyrick
authored
Add roundTicks function to fix PRICE_FILTER errors
2 parents cd6d98e + 9b25bf7 commit 9dea9e7

2 files changed

Lines changed: 16 additions & 3 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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-binance-api",
3-
"version": "0.8.2",
3+
"version": "0.8.3",
44
"description": "Binance API for node https://github.com/jaggedsoft/node-binance-api",
55
"main": "node-binance-api.js",
66
"dependencies": {

0 commit comments

Comments
 (0)