node-binance-api icon indicating copy to clipboard operation
node-binance-api copied to clipboard

roundTicks - accept string & numeric

Open cyri113 opened this issue 5 years ago • 2 comments

Hello,

I am getting the following error.

TypeError: Cannot read property 'length' of undefined
    at Object.roundTicks (/backend/node_modules/node-binance-api/node-binance-api.js:1550:75)

It occurs when the tickSize=1.00000000. I overcame this by modifying the roundTicks function in the following manner:

const roundTicks = (price, tickSize) => {
  const formatter = new Intl.NumberFormat('en-US', { style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 8 })
  const value = formatter.format(tickSize).split('.')[1]
  const precision = value === undefined ? 0 : value.length
  if (typeof price === 'string') price = parseFloat(price);
  return price.toFixed(precision)
}

I hope this helps the community! Thank you for the API!

cyri113 avatar May 27 '20 15:05 cyri113

thank you for your contribution 👍

jaggedsoft avatar May 27 '20 15:05 jaggedsoft

The problem is still relevant for tickSize = 1, but the code suggested above works

FaqSid avatar Nov 21 '22 11:11 FaqSid