niXman / binapi

Binance API C++ implementation
Apache License 2.0
253 stars 85 forks source link

Issue Websocket Limitations #8

Closed kyo06 closed 3 years ago

kyo06 commented 3 years ago

Hi niXman,

Thank you very much for your code. I have an issue with websocket api, regards to the documentation as below :

General WSS information The base endpoint is: wss://stream.binance.com:9443 Streams can be accessed either in a single raw stream or in a combined stream Raw streams are accessed at /ws/ Combined streams are accessed at /stream?streams=// Combined stream events are wrapped as follows: {"stream":"","data":} All symbols for streams are lowercase A single connection to stream.binance.com is only valid for 24 hours; expect to be disconnected at the 24 hour mark The websocket server will send a ping frame every 3 minutes. If the websocket server does not receive a pong frame back from the connection within a 10 minute period, the connection will be disconnected. Unsolicited pong frames are allowed. Websocket Limits WebSocket connections have a limit of 5 incoming messages per second. A message is considered: A PING frame A PONG frame A JSON controlled message (e.g. subscribe, unsubscribe) A connection that goes beyond the limit will be disconnected; IPs that are repeatedly disconnected may be banned. A single connection can listen to a maximum of 1024 streams.

There is no pong message sending method after receiving a ping frame in the code every 3 minute. Can you fix it or add pong method on websocket api ?

Can you add the streams limit (1024) regarding to the limitation ? Can you add websocket reconnect method because it is closed after 24 hours ?

Thank you very much for your support :)

Best Regards

niXman commented 3 years ago

hi,

Can you fix it or add pong method on websocket api ?

will look at this...

Can you add the streams limit (1024) regarding to the limitation ?

I think yes :)

Can you add websocket reconnect method because it is closed after 24 hours ?

no, because I think it should be implemented above the level, i.e. by the user of this code...

niXman commented 3 years ago

Can you fix it or add pong method on websocket api ?

please read the doc:

During read operations, Beast automatically reads and processes control frames.
If a control callback is registered, the callback is notified of the incoming control frame.
The implementation will respond to pings automatically. The receipt of a close frame
initiates the WebSocket close procedure, eventually resulting in the error code
error::closed being delivered to the caller in a subsequent read operation, assuming
no other error takes place. 
kyo06 commented 3 years ago

OK thank you but I have still issues like error on received markets fl=/mnt/c/Users/Sultan/Work/binapi/src/websocket.cpp(146), ec=2, errmsg: End of file when I would like monitor all tickers (the issue comes after 2 minutes or 10 minutes) is it a problem with sending pong frame ?

niXman commented 3 years ago

hi,

please provide me a complete example and describe how can I reproduce this.

niXman commented 3 years ago

because this example runs without any problems for 30 minutes... or use wireshark to analyze.

kyo06 commented 3 years ago

Here the code :

#include <binapi/api.hpp>
#include <binapi/websocket.hpp>

#include <boost/asio/io_context.hpp>

#include <iostream>

int main(int argc, char **argv) {

        boost::asio::io_context ioctx;
        binapi::ws::websockets_pool wsp(ioctx, "stream.binance.com", "9443");

        binapi::ws::websockets_pool::on_markets_received_cd callback_all_markets = [](const char *fl, int ec, std::string errmsg, binapi::ws::markets_tickers_t msg) -> bool {

            if ( ec ) {
                std::cerr << "error on received markets fl=" << fl << ", ec=" << ec << ", errmsg: " << errmsg << std::endl;
                return false;
            }
            return true;
        };

        wsp.subscribe_markets(callback_all_markets);

        std::cerr << "Connected..." << std::endl;
        ioctx.run();
        return 0;
}
niXman commented 3 years ago

I think you are running into the message count limit...

ps my test has been running successfully for an hour now.

kyo06 commented 3 years ago

Maybe the issue comes from the message count limit ... (I will investigate that) However there is no implementation for

Is it in your roadmap ?

niXman commented 3 years ago

Is it in your roadmap ?

no, I will look at this now...

but for the diff-depth-stream: https://github.com/niXman/binapi/blob/master/include/binapi/websocket.hpp#L77

niXman commented 3 years ago

in master: https://github.com/niXman/binapi/commit/d4bac3c41856505facbef4677aeb86876a4ca6f7 test it please.

kyo06 commented 3 years ago

OK i will test it 👍

niXman commented 3 years ago

hi,

any result? can I close this issue?