jaggedsoft / node-binance-api

Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use.
MIT License
1.58k stars 768 forks source link

roundTicks - accept string & numeric #434

Open cyri113 opened 4 years ago

cyri113 commented 4 years ago

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!

jaggedsoft commented 4 years ago

thank you for your contribution 👍

FaqSid commented 1 year ago

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