Show HN: Binance Orderbooks Consumer in C++
github.com
github.com
There are a lot of alternatives, use them.
Never use floats for prices and rates.
TDLR; nope.
That depends what you use the incoming data for. Bookkeeping, yeah. And that's about it.
This doesn't look like it was meant for that. Some sort of trading where you track a bunch of indicators over a day (not HFT at their timings at the moment but along those lines): you absolutely want to avoid fixed point because of the speed penalty. See also [1].
With a caveat here, after a very quick look at the code: The price here is defined as long double, which can be different among platforms... My Mac/clang says that long double is still 8 bytes, Linux on that same arm64 machine says it's 16 bytes (and I'm not sure what that's mapped to these days - 80bit FPU instructions, or some Float128 representation)
It's not a good practice, but no disaster will happen either for this particular purpose - a trading API.
What if you have a NaN? Now all your comparisons return false and any values you calculate from the NaN will also be NaN.
There is no way you can confidently claim these issues won't show up in a production system without doing fuzzing and formal verification. Just use big integers, 64 bit integers can represent 18 quintillion (short scale) values, which if you're trading in fractions of cents should be enough of a range for the foreseeable future. 128 bit integers will always be enough.
Since Binance only provides 100ms diffs, there isn’t 'real-time' in the sense of receiving each atomic orderbook change. Thank you for your feedback, I changed the description.
Ancient history.
and the crypto market, despite its volatility, does not move that fast, it just has 24 hour trading, in comparison of 6-8 for equities, in a single day
so the 3x greater trading sessions create the eternity
Edit: actually no, the networking bits have some platform specific #ifdefs. The code looks not too difficult to rewrite into a WinHTTP based client, though.
It’s only slower if you trigger many world switches.