binapi icon indicating copy to clipboard operation
binapi copied to clipboard

Futures websockets and REST APIs

Open rodenwild opened this issue 4 years ago • 5 comments

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?

rodenwild avatar Jul 24 '21 15:07 rodenwild

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

niXman avatar Jul 26 '21 06:07 niXman

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

rodenwild avatar Jul 26 '21 07:07 rodenwild

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

niXman avatar Jul 27 '21 10:07 niXman

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

alex290 avatar Apr 01 '22 08:04 alex290

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);
            }

damian123 avatar Apr 08 '24 06:04 damian123