niXman / binapi

Binance API C++ implementation
Apache License 2.0
240 stars 83 forks source link

Futures websockets and REST APIs #42

Open rodenwild opened 2 years ago

rodenwild commented 2 years ago

Thanks for the great repo, I relatively new to C++, coming from python, is there any simple way to implement futures into both websockets and the REST API? Or any example codes you may have?

niXman commented 2 years ago

please provide a link to the docs you are talking about.

rodenwild commented 2 years ago

https://binance-docs.github.io/apidocs/futures/en/#change-log

Spot websocket URL: wss://stream.binance.com:9443/ws/btcusdt@kline_5m Futures websocket URL: wss://fstream.binance.com/ws/btcusdt@kline_5m

niXman commented 2 years ago

git it. looks like a huge piece of work that I'm not ready to take on now.

alex290 commented 2 years ago

fstream.binance.com - port 443. I don't know why this is not in the documentation

damian123 commented 3 months ago

fstream.binance.com - port 443. I don't know why this is not in the documentation

The futures stream sends messages in a slightly different format, so it does not work.

Here is what happens if I run the main.cpp in websockets

binapi/src/websocket.cpp(346): binapi/include/binapi/flatjson.hpp(1456): key not found
Raw JSON causing error: {"e":"trade","E":1712555891750,"T":1712555891750,"s":"BTCUSDT","t":4847858716,"p":"69723.00","q":"0.020","X":"MARKET","m":false}

I add an extra line in websockets.cpp

try {
                message_type message = message_type::construct(json);
                return cb(nullptr, 0, std::string{}, std::move(message));
            } catch (const std::exception &ex) {
                std::fprintf(stderr, "%s: %s\n", __MAKE_FILELINE, ex.what());
                std::fprintf(stderr, "Raw JSON causing error: %s\n", ptr);         // <-------
                std::fflush(stderr);
            }