binance-api-client
binance-api-client copied to clipboard
Type woes
Unfortunately for typescript, it's type system is an afterthought of Javascript. And binance mostly reports it's numbers using strings in the JSON. So everywhere that a type has been declared as number, and then assigned using something like:
this._openingPrice = json[ 1 ];
(for example Candlestick), what you end up with is typescript thinking it's got a number, when actually it's a string, because the type system doesn't do the conversion (at least not that I am aware of). Now any time you do something like openingPrice < lastPrice it's actually doing a string comparison. It's like the worst of both worlds.
I think you need to go through and parseFloat everywhere that you expect to be getting a number out of json when binance sends you a string.
Thanks a lot for reporting. Do you think you can submit a PR for this?
When you see strings used for prices, it is often done for the reason of avoiding the floating point errors and giving the users a choice in what kind of arithmetics they want to use (some users might want to parse directly into BigRational
)