crypto-chassis / ccapi

A header-only C++ library for interacting with crypto exchanges. Bindings for Python, Java, C#, Go, and Javascript are provided.
https://discord.gg/b5EKcp9s8T
MIT License
585 stars 202 forks source link

FTX services don't correctly escape numbers represented in scientific notation #120

Closed quazzuk closed 3 years ago

quazzuk commented 3 years ago

Describe the bug FTX orderbook sporadically contains entries represented in scientific notation which the quoting regex doesn't handle.

To Reproduce subscribe to FTX market data feed with logging enabled and CCAPI_ENABLE_LOG_ERROR defined.

Expected behavior Numbers represented in scientific notation should be correctly escaped.

Additional context

A quick grep of the codebase shows that some of the exchanges handle this and other don't. Shouldn't this logic be exchange agnostic, as it's based on the json standard for number representation? Below is a link to Doug Crockford's regex for parsing numbers. Perhaps this could be added as a common utility which can then be used across the various exchanges?

https://github.com/douglascrockford/JSON-js/blob/594c8fa5f8e3fb38b0977f1ff8a87e9d709e7db1/json2.js#L166

cryptochassis commented 3 years ago

By running the data collectors (that are used to collect data in https://github.com/crypto-chassis/cryptochassis-data-api-docs, we've noticed that converting json numbers to strings impose a sizable performance penalty. So far each regex was tailored and optimized (to speed up regex matching) to cope with the specifics of each exchange. However indeed there's some commonality which can be refactored into base class.