luzzif / binance-api-client

A wrapper which can be used to interact with Binance's API. Entirely developed in TypeScript.
24 stars 12 forks source link

Type woes #37

Open gemmell opened 5 years ago

gemmell commented 5 years ago

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.

luzzif commented 5 years ago

Thanks a lot for reporting. Do you think you can submit a PR for this?

ArtemGr commented 4 years ago

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)