diff --git a/README.md b/README.md index 7b49d7a..5c9913f 100644 --- a/README.md +++ b/README.md @@ -125,19 +125,18 @@ All (except for ones that don't have mandatory parameters) REST request methods Each time a client object is created, a websocket client is also instantiated. In fact, the websocket client accepts the Client object as an argument.
The websocket client holds a map of all stream connection names and their current status. **symbol@stream_name** (i.e: btc@aggTrade). This is very crucial to know in order to be able to close a stream by using the `close_stream()` method. -
Not all streams accept the same arguments list, but all of them accept an `std::string` buffer and a functor object to use as callback. +
Not all streams accept the same arguments list, but all of them accept a functor object to use as callback. - #### Callback functor - All streams accepts a reference to std::string buffer and a reference to a functor object. This is implemented using templates, therefore the template type of the stream, when called, should be the type of the functor object. - >client_obj.stream_aggTrade(symbol, buff, functor_obj) + All streams accept a reference to a functor object. This is implemented using templates, therefore the template type of the stream, when called, should be the type of the functor object. + >client_obj.stream_aggTrade(symbol, functor_obj) -
It would be good practice to set the buffer as a member of the functor object. - #### Stream Manager The WebsocketClient class has a `stream_manager` method, which is responsible for the stream connection. It is possible to set `reconnect_on_error` by using Client's `ws_auto_reconnect()` method, and also specify the number of attempts by using `set_max_reconnect_count()` method.
The `stream_manager` method closes a stream when the stream status is set to zero by the `close_stream()` method, or if any other error was encountered (unless `reconnect_on_error` is true).
The stream manager also accepts a `bool` for whether or not to ping a listen key periodically. The ping interval is 30 minutes by default, and can be set using `set_refresh_key_interval()` method (in `Client`). - #### Custom Streams - Custom streams are possible by using `Client`'s `custom_stream()` method. This method accepts 4 arguments: `stream_path` std::string, `buffer` std::string, `functor` functor, and `ping_listen_key` bool (when true, pings listen key periodically). + Custom streams are possible by using `Client`'s `custom_stream()` method. This method accepts 3 arguments: `stream_path`, std::string, `functor` functor, and `ping_listen_key` bool (when true, pings listen key periodically). - #### Notes 1. Default arguments are not allowed with threads. The argument must be specified diff --git a/examples/custom_ws_stream.cpp b/examples/custom_ws_stream.cpp index ca0d8d3..68ef22b 100644 --- a/examples/custom_ws_stream.cpp +++ b/examples/custom_ws_stream.cpp @@ -7,11 +7,10 @@ struct SomeFunctor Json::CharReaderBuilder charbuilder; Json::CharReader* charreader; std::string parse_errors; - std::string msg_buffer; Json::Value stream_msg; SomeFunctor() - : msg_buffer{ "" }, parse_errors{ }, charreader{ charbuilder.newCharReader() } + : parse_errors{ }, charreader{ charbuilder.newCharReader() } {} @@ -40,7 +39,7 @@ int main() SomeFunctor ws_stream_read{}; std::string cust_stream = "btcusdt@aggTrade/ethusdt@aggTrade"; - std::thread t1(&SpotClient::custom_stream, std::ref(my_client), cust_stream, std::ref(ws_stream_read.msg_buffer), std::ref(ws_stream_read), 0); + std::thread t1(&SpotClient::custom_stream, std::ref(my_client), cust_stream, std::ref(ws_stream_read), 0); t1.join(); } diff --git a/examples/futures_user_stream.cpp b/examples/futures_user_stream.cpp index 9917d9c..8dafd72 100644 --- a/examples/futures_user_stream.cpp +++ b/examples/futures_user_stream.cpp @@ -7,11 +7,10 @@ struct SomeFunctor Json::CharReaderBuilder charbuilder; Json::CharReader* charreader; std::string parse_errors; - std::string msg_buffer; Json::Value stream_msg; SomeFunctor() - : msg_buffer{ "" }, parse_errors{ }, charreader{ charbuilder.newCharReader() } + : parse_errors{ }, charreader{ charbuilder.newCharReader() } {} @@ -43,7 +42,7 @@ int main() FuturesClientUSDT my_client{ api_key, api_secret }; SomeFunctor ws_stream_read{}; - std::thread t1(&FuturesClientUSDT::stream_userStream, std::ref(my_client), std::ref(ws_stream_read.msg_buffer), std::ref(ws_stream_read), 1); + std::thread t1(&FuturesClientUSDT::stream_userStream, std::ref(my_client), std::ref(ws_stream_read), 1); t1.join(); } diff --git a/examples/options_trade_stream.cpp b/examples/options_trade_stream.cpp index b20aaa8..436f2b1 100644 --- a/examples/options_trade_stream.cpp +++ b/examples/options_trade_stream.cpp @@ -7,11 +7,10 @@ struct SomeFunctor Json::CharReaderBuilder charbuilder; Json::CharReader* charreader; std::string parse_errors; - std::string msg_buffer; Json::Value stream_msg; SomeFunctor() - : msg_buffer{ "" }, parse_errors{ }, charreader{ charbuilder.newCharReader() } + : parse_errors{ }, charreader{ charbuilder.newCharReader() } {} @@ -40,7 +39,7 @@ int main() SomeFunctor ws_stream_read{}; std::string symbol = "BTC-210430-56000-C"; - std::thread t1(&OpsClient::stream_Trade, std::ref(my_client), symbol, std::ref(ws_stream_read.msg_buffer), std::ref(ws_stream_read)); + std::thread t1(&OpsClient::stream_Trade, std::ref(my_client), symbol, std::ref(ws_stream_read)); t1.join(); } diff --git a/examples/orderbook_manager.cpp b/examples/orderbook_manager.cpp index 6841801..06e3efb 100755 --- a/examples/orderbook_manager.cpp +++ b/examples/orderbook_manager.cpp @@ -29,7 +29,6 @@ class OrderbookManager public: const std::string symbol; - std::string msg_buffer; std::vector> bids; std::vector> asks; @@ -50,7 +49,7 @@ int main() FuturesClientUSDT public_client{}; OrderbookManager btcusdt_orderbook{ "btcusdt", public_client }; - std::thread t4(&FuturesClientUSDT::stream_depth_partial, std::ref(public_client), btcusdt_orderbook.symbol, std::ref(btcusdt_orderbook.msg_buffer), std::ref(btcusdt_orderbook), 5, 100); + std::thread t4(&FuturesClientUSDT::stream_depth_partial, std::ref(public_client), btcusdt_orderbook.symbol, std::ref(btcusdt_orderbook), 5, 100); btcusdt_orderbook.setup_initial_snap(); while (1) @@ -65,7 +64,7 @@ int main() OrderbookManager::OrderbookManager(const std::string ticker_symbol, FuturesClientUSDT& client_init) - : symbol{ ticker_symbol }, user_client{ &client_init }, msg_buffer{ "" }, parse_errors{ }, charreader{ charbuilder.newCharReader() } + : symbol{ ticker_symbol }, user_client{ &client_init }, parse_errors{ }, charreader{ charbuilder.newCharReader() } {} void OrderbookManager::reset_order_book(std::vector>& side) diff --git a/include/Exchange_Client.h b/include/Exchange_Client.h index 78792f3..9927a66 100644 --- a/include/Exchange_Client.h +++ b/include/Exchange_Client.h @@ -101,40 +101,40 @@ class Client // WS Streams template - unsigned int stream_aggTrade(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int stream_aggTrade(const std::string& symbol, FT& functor); template - unsigned int stream_Trade(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int stream_Trade(const std::string& symbol, FT& functor); template - unsigned int stream_kline(const std::string& symbol, std::string& buffer, FT& functor, std::string interval = "1h"); + unsigned int stream_kline(const std::string& symbol, FT& functor, std::string interval = "1h"); template - unsigned int stream_ticker_ind_mini(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int stream_ticker_ind_mini(const std::string& symbol, FT& functor); template - unsigned int stream_ticker_all_mini(std::string& buffer, FT& functor); + unsigned int stream_ticker_all_mini(FT& functor); template - unsigned int stream_ticker_ind(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int stream_ticker_ind(const std::string& symbol, FT& functor); template - unsigned int stream_ticker_all(std::string& buffer, FT& functor); + unsigned int stream_ticker_all(FT& functor); template - unsigned int stream_ticker_ind_book(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int stream_ticker_ind_book(const std::string& symbol, FT& functor); template - unsigned int stream_ticker_all_book(std::string& buffer, FT& functor); + unsigned int stream_ticker_all_book(FT& functor); template - unsigned int stream_depth_partial(const std::string& symbol, std::string& buffer, FT& functor, const unsigned int levels = 5, const unsigned int interval = 100); + unsigned int stream_depth_partial(const std::string& symbol, FT& functor, const unsigned int levels = 5, const unsigned int interval = 100); template - unsigned int stream_depth_diff(const std::string& symbol, std::string& buffer, FT& functor, const unsigned int interval = 100); + unsigned int stream_depth_diff(const std::string& symbol, FT& functor, const unsigned int interval = 100); template - unsigned int stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key = 0); + unsigned int stream_userstream(FT& functor, const bool ping_listen_key = 0); std::string get_listen_key(); Json::Value ping_listen_key(const std::string& listen_key = ""); // only spot requires key @@ -303,7 +303,7 @@ class Client Json::Value query_margin_interest_rate_history(const Params* params_ptr); template - unsigned int margin_stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key = 0, const bool& isolated_margin_type = 0); + unsigned int margin_stream_userstream(FT& functor, const bool ping_listen_key = 0, const bool& isolated_margin_type = 0); std::string margin_get_listen_key(); std::string margin_isolated_get_listen_key(const std::string symbol); Json::Value margin_ping_listen_key(const std::string& listen_key); @@ -421,7 +421,7 @@ class Client Json::Value custom_delete_req(const std::string& base, const std::string& endpoint, const Params* params_ptr, const bool& signature = 0); template - unsigned int custom_stream(const std::string stream_name, std::string& buffer, FT& functor, const bool ping_listen_key = 0); + unsigned int custom_stream(const std::string stream_name, FT& functor, const bool ping_listen_key = 0); RestSession* _rest_client = nullptr; WebsocketClient* _ws_client = nullptr; @@ -475,7 +475,7 @@ class FuturesClient : public Client> // -- Global that are going deeper to USDT and COIN template - unsigned int v_stream_Trade(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int v_stream_Trade(const std::string& symbol, FT& functor); public: friend Client>; @@ -531,43 +531,43 @@ class FuturesClient : public Client> // WS Streams template - unsigned int stream_markprice(const std::string& symbol, std::string& buffer, FT& functor, unsigned int interval = 1000); + unsigned int stream_markprice(const std::string& symbol, FT& functor, unsigned int interval = 1000); template - unsigned int stream_liquidation_orders(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int stream_liquidation_orders(const std::string& symbol, FT& functor); template - unsigned int stream_liquidation_orders_all(std::string& buffer, FT& functor); + unsigned int stream_liquidation_orders_all(FT& functor); template - unsigned int stream_blvt_info(std::string& buffer, FT& functor, std::string token_name); + unsigned int stream_blvt_info(FT& functor, std::string token_name); template - unsigned int stream_blvt_klines(std::string& buffer, FT& functor, std::string token_name, std::string interval); + unsigned int stream_blvt_klines(FT& functor, std::string token_name, std::string interval); template - unsigned int stream_composite_index_symbol(std::string& buffer, FT& functor, std::string token_name); + unsigned int stream_composite_index_symbol(FT& functor, std::string token_name); template - unsigned int stream_markprice_all(const std::string& pair, std::string& buffer, FT& functor); // only USDT + unsigned int stream_markprice_all(const std::string& pair, FT& functor); // only USDT template - unsigned int stream_indexprice(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval = 1000); // only Coin + unsigned int stream_indexprice(const std::string& pair, FT& functor, unsigned int interval = 1000); // only Coin template - unsigned int stream_markprice_by_pair(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval = 1000); // only coin + unsigned int stream_markprice_by_pair(const std::string& pair, FT& functor, unsigned int interval = 1000); // only coin template - unsigned int stream_kline_contract(const std::string& pair_and_type, std::string& buffer, FT& functor, std::string interval = "1h"); // only coin + unsigned int stream_kline_contract(const std::string& pair_and_type, FT& functor, std::string interval = "1h"); // only coin template - unsigned int stream_kline_index(const std::string& pair, std::string& buffer, FT& functor, std::string interval = "1h"); // only coin + unsigned int stream_kline_index(const std::string& pair, FT& functor, std::string interval = "1h"); // only coin template - unsigned int stream_kline_markprice(const std::string& symbol, std::string& buffer, FT& functor, std::string interval = "1h"); // only coin + unsigned int stream_kline_markprice(const std::string& symbol, FT& functor, std::string interval = "1h"); // only coin template - unsigned int v_stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key); + unsigned int v_stream_userstream(FT& functor, const bool ping_listen_key); @@ -661,34 +661,34 @@ class FuturesClientUSDT : public FuturesClient template - unsigned int v_stream_markprice_all(const std::string& pair, std::string& buffer, FT& functor); // only USDT + unsigned int v_stream_markprice_all(const std::string& pair, FT& functor); // only USDT template - unsigned int v_stream_indexprice(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval); // only Coin + unsigned int v_stream_indexprice(const std::string& pair, FT& functor, unsigned int interval); // only Coin template - unsigned int v_stream_markprice_by_pair(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval); // only coin + unsigned int v_stream_markprice_by_pair(const std::string& pair, FT& functor, unsigned int interval); // only coin template - unsigned int v_stream_blvt_info(std::string& buffer, FT& functor, std::string token_name); // only USDT + unsigned int v_stream_blvt_info(FT& functor, std::string token_name); // only USDT template - unsigned int v_stream_blvt_klines(std::string& buffer, FT& functor, std::string token_name, std::string interval); // only USDT + unsigned int v_stream_blvt_klines(FT& functor, std::string token_name, std::string interval); // only USDT template - unsigned int v_stream_composite_index_symbol(std::string& buffer, FT& functor, std::string token_name); // only USDT + unsigned int v_stream_composite_index_symbol(FT& functor, std::string token_name); // only USDT template - unsigned int v_stream_kline_contract(const std::string& pair_and_type, std::string& buffer, FT& functor, std::string interval); // only coin + unsigned int v_stream_kline_contract(const std::string& pair_and_type, FT& functor, std::string interval); // only coin template - unsigned int v_stream_kline_index(const std::string& pair, std::string& buffer, FT& functor, std::string interval); // only coin + unsigned int v_stream_kline_index(const std::string& pair, FT& functor, std::string interval); // only coin template - unsigned int v_stream_kline_markprice(const std::string& symbol, std::string& buffer, FT& functor, std::string interval); // only coin + unsigned int v_stream_kline_markprice(const std::string& symbol, FT& functor, std::string interval); // only coin template - unsigned int v__stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key); + unsigned int v__stream_userstream(FT& functor, const bool ping_listen_key); std::string v__get_listen_key(); Json::Value v__ping_listen_key(); @@ -786,34 +786,34 @@ class FuturesClientCoin : public FuturesClient // -- going deeper... template - unsigned int v_stream_markprice_all(const std::string& pair, std::string& buffer, FT& functor); // only USDT + unsigned int v_stream_markprice_all(const std::string& pair, FT& functor); // only USDT template - unsigned int v_stream_indexprice(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval); // only Coin + unsigned int v_stream_indexprice(const std::string& pair, FT& functor, unsigned int interval); // only Coin template - unsigned int v_stream_markprice_by_pair(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval); // only coin + unsigned int v_stream_markprice_by_pair(const std::string& pair, FT& functor, unsigned int interval); // only coin template - unsigned int v_stream_blvt_info(std::string& buffer, FT& functor, std::string token_name); // only USDT + unsigned int v_stream_blvt_info(FT& functor, std::string token_name); // only USDT template - unsigned int v_stream_blvt_klines(std::string& buffer, FT& functor, std::string token_name, std::string interval); // only USDT + unsigned int v_stream_blvt_klines(FT& functor, std::string token_name, std::string interval); // only USDT template - unsigned int v_stream_composite_index_symbol(std::string& buffer, FT& functor, std::string token_name); // only USDT + unsigned int v_stream_composite_index_symbol(FT& functor, std::string token_name); // only USDT template - unsigned int v_stream_kline_contract(const std::string& pair_and_type, std::string& buffer, FT& functor, std::string interval); // only coin + unsigned int v_stream_kline_contract(const std::string& pair_and_type, FT& functor, std::string interval); // only coin template - unsigned int v_stream_kline_index(const std::string& pair, std::string& buffer, FT& functor, std::string interval); // only coin + unsigned int v_stream_kline_index(const std::string& pair, FT& functor, std::string interval); // only coin template - unsigned int v_stream_kline_markprice(const std::string& symbol, std::string& buffer, FT& functor, std::string interval); // only coin + unsigned int v_stream_kline_markprice(const std::string& symbol, FT& functor, std::string interval); // only coin template - unsigned int v__stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key); + unsigned int v__stream_userstream(FT& functor, const bool ping_listen_key); std::string v__get_listen_key(); Json::Value v__ping_listen_key(); @@ -876,7 +876,7 @@ class SpotClient : public Client // WS Streams template - unsigned int v_stream_Trade(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int v_stream_Trade(const std::string& symbol, FT& functor); // crtp infrastructure start @@ -884,7 +884,7 @@ class SpotClient : public Client void v_init_ws_session(); template - unsigned int v_stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key); + unsigned int v_stream_userstream(FT& functor, const bool ping_listen_key); std::string v_get_listen_key(); Json::Value v_ping_listen_key(const std::string& listen_key); Json::Value v_revoke_listen_key(const std::string& listen_key); @@ -950,7 +950,7 @@ class OpsClient : public Client void v_init_ws_session(); // todo: define (what is the port??? gzip used??) template - unsigned int v_stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key); // todo: define + unsigned int v_stream_userstream(FT& functor, const bool ping_listen_key); // todo: define std::string v_get_listen_key(); Json::Value v_ping_listen_key(const std::string& listen_key); @@ -958,10 +958,10 @@ class OpsClient : public Client template - unsigned int v_stream_Trade(const std::string& symbol, std::string& buffer, FT& functor); + unsigned int v_stream_Trade(const std::string& symbol, FT& functor); template - unsigned int v_stream_kline(const std::string& symbol, std::string& buffer, FT& functor, std::string interval = "1h"); + unsigned int v_stream_kline(const std::string& symbol, FT& functor, std::string interval = "1h"); // crtp infrastructure end diff --git a/include/WS_Client.h b/include/WS_Client.h index e8d0f1b..269580b 100644 --- a/include/WS_Client.h +++ b/include/WS_Client.h @@ -13,7 +13,7 @@ class WebsocketClient template - void _connect_to_endpoint(const std::string stream_map_name, const std::string stream_path, std::string& buf, FT& functor, const bool ping_listen_key); + void _connect_to_endpoint(const std::string stream_map_name, const std::string stream_path, FT& functor, const bool ping_listen_key); public: unsigned int _max_reconnect_count; @@ -28,7 +28,7 @@ class WebsocketClient bool is_open(const std::string& stream_name) const; template - void _stream_manager(std::string stream_map_name, const std::string stream_path, std::string& buf, FT& functor, const bool ping_listen_key = 0); + void _stream_manager(std::string stream_map_name, const std::string stream_path, FT& functor, const bool ping_listen_key = 0); void _set_reconnect(const bool& reconnect); diff --git a/include/inl_files/Websocket_methods.inl b/include/inl_files/Websocket_methods.inl index 10e90df..385dd3f 100644 --- a/include/inl_files/Websocket_methods.inl +++ b/include/inl_files/Websocket_methods.inl @@ -4,7 +4,6 @@ /** Start userstream (Margin) - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param ping_listen_key - if true, will ping listen key periodically @param isolaten_margin_type - if true, userstream will be for isolated margin @@ -12,7 +11,7 @@ */ template template -unsigned int Client::MarginAccount::margin_stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key, const bool& isolated_margin_type) +unsigned int Client::MarginAccount::margin_stream_userstream(FT& functor, const bool ping_listen_key, const bool& isolated_margin_type) { try { @@ -22,7 +21,7 @@ unsigned int Client::MarginAccount::margin_stream_userstream(std::string& buf { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor, ping_listen_key); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor, ping_listen_key); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -35,13 +34,12 @@ unsigned int Client::MarginAccount::margin_stream_userstream(std::string& buf /** Start userstream (Spot) - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param ping_listen_key - if true, will ping listen key periodically @return an unsigned int representing success */ template -unsigned int SpotClient::v_stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key) +unsigned int SpotClient::v_stream_userstream(FT& functor, const bool ping_listen_key) { std::string stream_name = this->get_listen_key(); std::string stream_query = "/ws/" + stream_name; @@ -49,7 +47,7 @@ unsigned int SpotClient::v_stream_userstream(std::string& buffer, FT& functor, c { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor, ping_listen_key); + this->_ws_client->_stream_manager(stream_name, stream_query, functor, ping_listen_key); return this->_ws_client->running_streams[stream_query]; } @@ -57,12 +55,11 @@ unsigned int SpotClient::v_stream_userstream(std::string& buffer, FT& functor, c /** Start trades stream (Spot) @param symbol - the symbol of the trades - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template -unsigned int SpotClient::v_stream_Trade(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int SpotClient::v_stream_Trade(const std::string& symbol, FT& functor) { std::string stream_name = symbol + '@' + "trade"; std::string stream_query = "/ws/" + stream_name; @@ -70,21 +67,20 @@ unsigned int SpotClient::v_stream_Trade(const std::string& symbol, std::string& { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } /** Start mark price stream (symbol) @param symbol - the symbol of the trades - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_markprice(const std::string& symbol, std::string& buffer, FT& functor, unsigned int interval) +unsigned int FuturesClient::stream_markprice(const std::string& symbol, FT& functor, unsigned int interval) { try { @@ -94,7 +90,7 @@ unsigned int FuturesClient::stream_markprice(const std::string& symbol, std: { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -108,13 +104,12 @@ unsigned int FuturesClient::stream_markprice(const std::string& symbol, std: /** Start trades stream (Futures) @param symbol - the symbol of the trades - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int FuturesClient::v_stream_Trade(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int FuturesClient::v_stream_Trade(const std::string& symbol, FT& functor) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -125,17 +120,16 @@ unsigned int FuturesClient::v_stream_Trade(const std::string& symbol, std::s /** Start mark price stream (all) @param pair - the pair - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_markprice_all(const std::string& pair, std::string& buffer, FT& functor) +unsigned int FuturesClient::stream_markprice_all(const std::string& pair, FT& functor) { try { - return static_cast(this)->v_stream_markprice_all(pair, buffer, functor); + return static_cast(this)->v_stream_markprice_all(pair, functor); } catch (ClientException e) { @@ -147,18 +141,17 @@ unsigned int FuturesClient::stream_markprice_all(const std::string& pair, st /** Start index price stream @param pair - the pair - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_indexprice(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval) +unsigned int FuturesClient::stream_indexprice(const std::string& pair, FT& functor, unsigned int interval) { try { - return static_cast(this)->v_stream_indexprice(pair, buffer, functor, interval); + return static_cast(this)->v_stream_indexprice(pair, functor, interval); } catch (ClientException e) { @@ -172,18 +165,17 @@ unsigned int FuturesClient::stream_indexprice(const std::string& pair, std:: /** Start mark price stream (by pair) @param pair - the pair - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_markprice_by_pair(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval) +unsigned int FuturesClient::stream_markprice_by_pair(const std::string& pair, FT& functor, unsigned int interval) { try { - return static_cast(this)->v_stream_markprice_by_pair(pair, buffer, functor, interval); + return static_cast(this)->v_stream_markprice_by_pair(pair, functor, interval); } catch (ClientException e) { @@ -196,18 +188,17 @@ unsigned int FuturesClient::stream_markprice_by_pair(const std::string& pair /** Start kline contract stream @param pair_and_type - the pair & type - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_kline_contract(const std::string& pair_and_type, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClient::stream_kline_contract(const std::string& pair_and_type, FT& functor, std::string interval) { try { - return static_cast(this)->v_stream_kline_contract(pair_and_type, buffer, functor, interval); + return static_cast(this)->v_stream_kline_contract(pair_and_type, functor, interval); } catch (ClientException e) { @@ -219,18 +210,17 @@ unsigned int FuturesClient::stream_kline_contract(const std::string& pair_an /** Start kline index stream @param pair - the pair - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_kline_index(const std::string& pair, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClient::stream_kline_index(const std::string& pair, FT& functor, std::string interval) { try { - return static_cast(this)->v_stream_kline_index(pair, buffer, functor, interval); + return static_cast(this)->v_stream_kline_index(pair, functor, interval); } catch (ClientException e) { @@ -242,18 +232,17 @@ unsigned int FuturesClient::stream_kline_index(const std::string& pair, std: /** Start kline mark price stream @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_kline_markprice(const std::string& symbol, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClient::stream_kline_markprice(const std::string& symbol, FT& functor, std::string interval) { try { - return static_cast(this)->v_stream_kline_markprice(symbol, buffer, functor, interval); + return static_cast(this)->v_stream_kline_markprice(symbol, functor, interval); } catch (ClientException e) { @@ -265,13 +254,12 @@ unsigned int FuturesClient::stream_kline_markprice(const std::string& symbol /** Start liquidation orders stream @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_liquidation_orders(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int FuturesClient::stream_liquidation_orders(const std::string& symbol, FT& functor) { try { @@ -281,7 +269,7 @@ unsigned int FuturesClient::stream_liquidation_orders(const std::string& sym { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -293,13 +281,12 @@ unsigned int FuturesClient::stream_liquidation_orders(const std::string& sym /** Start liquidation orders stream (all) - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_liquidation_orders_all(std::string& buffer, FT& functor) +unsigned int FuturesClient::stream_liquidation_orders_all(FT& functor) { try { @@ -309,7 +296,7 @@ unsigned int FuturesClient::stream_liquidation_orders_all(std::string& buffe { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -321,18 +308,17 @@ unsigned int FuturesClient::stream_liquidation_orders_all(std::string& buffe /** BLVT Info Streams - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param token_name - token name @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_blvt_info(std::string& buffer, FT& functor, std::string token_name) +unsigned int FuturesClient::stream_blvt_info(FT& functor, std::string token_name) { try { - return static_cast(this)->v_stream_blvt_info(buffer, functor, token_name); + return static_cast(this)->v_stream_blvt_info(functor, token_name); } catch (ClientException e) { @@ -343,7 +329,6 @@ unsigned int FuturesClient::stream_blvt_info(std::string& buffer, FT& functo /** BLVT NAV Kline/Candlestick Streams - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param token_name - token name @param interval - interval of klines @@ -351,11 +336,11 @@ unsigned int FuturesClient::stream_blvt_info(std::string& buffer, FT& functo */ template template -unsigned int FuturesClient::stream_blvt_klines(std::string& buffer, FT& functor, std::string token_name, std::string interval) +unsigned int FuturesClient::stream_blvt_klines(FT& functor, std::string token_name, std::string interval) { try { - return static_cast(this)->v_stream_blvt_klines(buffer, functor, token_name, interval); + return static_cast(this)->v_stream_blvt_klines(functor, token_name, interval); } catch (ClientException e) { @@ -366,18 +351,17 @@ unsigned int FuturesClient::stream_blvt_klines(std::string& buffer, FT& func /** BLVT NAV Kline/Candlestick Streams - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param token_name - token name @return an unsigned int representing success */ template template -unsigned int FuturesClient::stream_composite_index_symbol(std::string& buffer, FT& functor, std::string token_name) +unsigned int FuturesClient::stream_composite_index_symbol(FT& functor, std::string token_name) { try { - return static_cast(this)->v_stream_composite_index_symbol(buffer, functor, token_name); + return static_cast(this)->v_stream_composite_index_symbol(functor, token_name); } catch (ClientException e) { @@ -391,13 +375,16 @@ unsigned int FuturesClient::stream_composite_index_symbol(std::string& buffe */ template template -unsigned int FuturesClient::v_stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key) { return static_cast(this)->v__stream_userstream(buffer, functor, ping_listen_key); } +unsigned int FuturesClient::v_stream_userstream(FT& functor, const bool ping_listen_key) +{ + return static_cast(this)->v__stream_userstream(functor, ping_listen_key); +} /** CRTP of stream_markprice_all */ template -unsigned int FuturesClientUSDT::v_stream_markprice_all(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int FuturesClientUSDT::v_stream_markprice_all(const std::string& symbol, FT& functor) { std::string stream_name = symbol + '@' + "miniTicker"; std::string stream_query = "/ws/" + stream_name; @@ -405,7 +392,7 @@ unsigned int FuturesClientUSDT::v_stream_markprice_all(const std::string& symbol { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } @@ -413,7 +400,7 @@ unsigned int FuturesClientUSDT::v_stream_markprice_all(const std::string& symbol CRTP of stream_indexprice */ template -unsigned int FuturesClientUSDT::v_stream_indexprice(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval) +unsigned int FuturesClientUSDT::v_stream_indexprice(const std::string& pair, FT& functor, unsigned int interval) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -424,7 +411,7 @@ unsigned int FuturesClientUSDT::v_stream_indexprice(const std::string& pair, std CRTP of stream_markprice_by_pair */ template -unsigned int FuturesClientUSDT::v_stream_markprice_by_pair(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval) +unsigned int FuturesClientUSDT::v_stream_markprice_by_pair(const std::string& pair, FT& functor, unsigned int interval) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -435,7 +422,7 @@ unsigned int FuturesClientUSDT::v_stream_markprice_by_pair(const std::string& pa CRTP of stream_kline_contract */ template -unsigned int FuturesClientUSDT::v_stream_kline_contract(const std::string& pair_and_type, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClientUSDT::v_stream_kline_contract(const std::string& pair_and_type, FT& functor, std::string interval) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -446,7 +433,7 @@ unsigned int FuturesClientUSDT::v_stream_kline_contract(const std::string& pair_ CRTP of stream_kline_index */ template -unsigned int FuturesClientUSDT::v_stream_kline_index(const std::string& pair, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClientUSDT::v_stream_kline_index(const std::string& pair, FT& functor, std::string interval) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -457,7 +444,7 @@ unsigned int FuturesClientUSDT::v_stream_kline_index(const std::string& pair, st CRTP of stream_kline_markprice */ template -unsigned int FuturesClientUSDT::v_stream_kline_markprice(const std::string& symbol, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClientUSDT::v_stream_kline_markprice(const std::string& symbol, FT& functor, std::string interval) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -468,7 +455,7 @@ unsigned int FuturesClientUSDT::v_stream_kline_markprice(const std::string& symb CRTP of v_stream_userstream */ template -unsigned int FuturesClientUSDT::v__stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key) +unsigned int FuturesClientUSDT::v__stream_userstream(FT& functor, const bool ping_listen_key) { std::string stream_name = this->get_listen_key(); std::string stream_query = "/ws/" + stream_name; @@ -476,7 +463,7 @@ unsigned int FuturesClientUSDT::v__stream_userstream(std::string& buffer, FT& fu { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } @@ -484,7 +471,7 @@ unsigned int FuturesClientUSDT::v__stream_userstream(std::string& buffer, FT& fu CRTP of stream_indexprice */ template -unsigned int FuturesClientCoin::v_stream_indexprice(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval) +unsigned int FuturesClientCoin::v_stream_indexprice(const std::string& pair, FT& functor, unsigned int interval) { std::string stream_name = pair + "@" + "indexPrice" + "@" + std::to_string(interval) + "ms"; std::string stream_query = "/ws/" + stream_name; @@ -492,7 +479,7 @@ unsigned int FuturesClientCoin::v_stream_indexprice(const std::string& pair, std { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } @@ -500,7 +487,7 @@ unsigned int FuturesClientCoin::v_stream_indexprice(const std::string& pair, std CRTP of stream_markprice_by_pair */ template -unsigned int FuturesClientCoin::v_stream_markprice_by_pair(const std::string& pair, std::string& buffer, FT& functor, unsigned int interval) +unsigned int FuturesClientCoin::v_stream_markprice_by_pair(const std::string& pair, FT& functor, unsigned int interval) { std::string stream_name = pair + "@" + "markPrice" + "@" + std::to_string(interval) + "ms"; std::string stream_query = "/ws/" + stream_name; @@ -508,7 +495,7 @@ unsigned int FuturesClientCoin::v_stream_markprice_by_pair(const std::string& pa { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } @@ -516,7 +503,7 @@ unsigned int FuturesClientCoin::v_stream_markprice_by_pair(const std::string& pa CRTP of stream_blvt_info */ template -unsigned int FuturesClientCoin::v_stream_blvt_info(std::string& buffer, FT& functor, std::string token_name) +unsigned int FuturesClientCoin::v_stream_blvt_info(FT& functor, std::string token_name) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -527,7 +514,7 @@ unsigned int FuturesClientCoin::v_stream_blvt_info(std::string& buffer, FT& func CRTP of stream_blvt_klines */ template -unsigned int FuturesClientCoin::v_stream_blvt_klines(std::string& buffer, FT& functor, std::string token_name, std::string interval) +unsigned int FuturesClientCoin::v_stream_blvt_klines(FT& functor, std::string token_name, std::string interval) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -538,7 +525,7 @@ unsigned int FuturesClientCoin::v_stream_blvt_klines(std::string& buffer, FT& fu CRTP of stream_composite_index_symbol */ template -unsigned int FuturesClientCoin::v_stream_composite_index_symbol(std::string& buffer, FT& functor, std::string token_name) +unsigned int FuturesClientCoin::v_stream_composite_index_symbol(FT& functor, std::string token_name) { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__)); @@ -549,7 +536,7 @@ unsigned int FuturesClientCoin::v_stream_composite_index_symbol(std::string& buf CRTP of stream_kline_contract */ template -unsigned int FuturesClientCoin::v_stream_kline_contract(const std::string& pair_and_type, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClientCoin::v_stream_kline_contract(const std::string& pair_and_type, FT& functor, std::string interval) { std::string stream_name = pair_and_type + "@" + "continuousKline_" + (interval); std::string stream_query = "/ws/" + stream_name; @@ -557,7 +544,7 @@ unsigned int FuturesClientCoin::v_stream_kline_contract(const std::string& pair_ { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } @@ -565,7 +552,7 @@ unsigned int FuturesClientCoin::v_stream_kline_contract(const std::string& pair_ CRTP of stream_kline_index */ template -unsigned int FuturesClientCoin::v_stream_kline_index(const std::string& pair, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClientCoin::v_stream_kline_index(const std::string& pair, FT& functor, std::string interval) { std::string stream_name = pair + "@" + "indexPriceKline_" + (interval); std::string stream_query = "/ws/" + stream_name; @@ -573,7 +560,7 @@ unsigned int FuturesClientCoin::v_stream_kline_index(const std::string& pair, st { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } @@ -581,7 +568,7 @@ unsigned int FuturesClientCoin::v_stream_kline_index(const std::string& pair, st CRTP of stream_kline_markprice */ template -unsigned int FuturesClientCoin::v_stream_kline_markprice(const std::string& symbol, std::string& buffer, FT& functor, std::string interval) +unsigned int FuturesClientCoin::v_stream_kline_markprice(const std::string& symbol, FT& functor, std::string interval) { std::string stream_name = symbol + "@" + "markPriceKline_" + (interval); std::string stream_query = "/ws/" + stream_name; @@ -589,7 +576,7 @@ unsigned int FuturesClientCoin::v_stream_kline_markprice(const std::string& symb { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } @@ -598,7 +585,7 @@ unsigned int FuturesClientCoin::v_stream_kline_markprice(const std::string& symb CRTP of stream_blvt_info */ template -unsigned int FuturesClientUSDT::v_stream_blvt_info(std::string& buffer, FT& functor, std::string token_name) +unsigned int FuturesClientUSDT::v_stream_blvt_info(FT& functor, std::string token_name) { try { @@ -608,7 +595,7 @@ unsigned int FuturesClientUSDT::v_stream_blvt_info(std::string& buffer, FT& func { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -622,7 +609,7 @@ unsigned int FuturesClientUSDT::v_stream_blvt_info(std::string& buffer, FT& func CRTP of stream_blvt_klines */ template -unsigned int FuturesClientUSDT::v_stream_blvt_klines(std::string& buffer, FT& functor, std::string token_name, std::string interval) +unsigned int FuturesClientUSDT::v_stream_blvt_klines(FT& functor, std::string token_name, std::string interval) { try { @@ -632,7 +619,7 @@ unsigned int FuturesClientUSDT::v_stream_blvt_klines(std::string& buffer, FT& fu { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -646,7 +633,7 @@ unsigned int FuturesClientUSDT::v_stream_blvt_klines(std::string& buffer, FT& fu CRTP of stream_composite_index_symbol */ template -unsigned int FuturesClientUSDT::v_stream_composite_index_symbol(std::string& buffer, FT& functor, std::string token_name) +unsigned int FuturesClientUSDT::v_stream_composite_index_symbol(FT& functor, std::string token_name) { try { @@ -656,7 +643,7 @@ unsigned int FuturesClientUSDT::v_stream_composite_index_symbol(std::string& buf { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -670,7 +657,7 @@ unsigned int FuturesClientUSDT::v_stream_composite_index_symbol(std::string& buf CRTP of v_stream_userstream */ template -unsigned int FuturesClientCoin::v__stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key) +unsigned int FuturesClientCoin::v__stream_userstream(FT& functor, const bool ping_listen_key) { std::string stream_name = this->get_listen_key(); std::string stream_query = "/ws/" + stream_name; @@ -678,20 +665,19 @@ unsigned int FuturesClientCoin::v__stream_userstream(std::string& buffer, FT& fu { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor, ping_listen_key); + this->_ws_client->_stream_manager(stream_name, stream_query, functor, ping_listen_key); return this->_ws_client->running_streams[stream_query]; } /** Start aggregated trades stream @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int Client::stream_aggTrade(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int Client::stream_aggTrade(const std::string& symbol, FT& functor) { try { @@ -701,7 +687,7 @@ unsigned int Client::stream_aggTrade(const std::string& symbol, std::string& { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -714,14 +700,13 @@ unsigned int Client::stream_aggTrade(const std::string& symbol, std::string& /** Start kline (candlesticks) stream @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template template -unsigned int Client::stream_kline(const std::string& symbol, std::string& buffer, FT& functor, std::string interval) +unsigned int Client::stream_kline(const std::string& symbol, FT& functor, std::string interval) { try { @@ -731,7 +716,7 @@ unsigned int Client::stream_kline(const std::string& symbol, std::string& buf { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -744,13 +729,12 @@ unsigned int Client::stream_kline(const std::string& symbol, std::string& buf /** Start mini ticker stream (individual) @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int Client::stream_ticker_ind_mini(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int Client::stream_ticker_ind_mini(const std::string& symbol, FT& functor) { try { @@ -760,7 +744,7 @@ unsigned int Client::stream_ticker_ind_mini(const std::string& symbol, std::s { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -772,13 +756,12 @@ unsigned int Client::stream_ticker_ind_mini(const std::string& symbol, std::s /** Start mini ticker stream (all) - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int Client::stream_ticker_all_mini(std::string& buffer, FT& functor) +unsigned int Client::stream_ticker_all_mini(FT& functor) { try { @@ -788,7 +771,7 @@ unsigned int Client::stream_ticker_all_mini(std::string& buffer, FT& functor) { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -801,13 +784,12 @@ unsigned int Client::stream_ticker_all_mini(std::string& buffer, FT& functor) /** Start ticker stream (individual) @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int Client::stream_ticker_ind(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int Client::stream_ticker_ind(const std::string& symbol, FT& functor) { try { @@ -817,7 +799,7 @@ unsigned int Client::stream_ticker_ind(const std::string& symbol, std::string { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -829,13 +811,12 @@ unsigned int Client::stream_ticker_ind(const std::string& symbol, std::string /** Start ticker stream (all) - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int Client::stream_ticker_all(std::string& buffer, FT& functor) +unsigned int Client::stream_ticker_all(FT& functor) { try { @@ -845,7 +826,7 @@ unsigned int Client::stream_ticker_all(std::string& buffer, FT& functor) { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -858,13 +839,12 @@ unsigned int Client::stream_ticker_all(std::string& buffer, FT& functor) /** Start book ticker stream (individual) @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int Client::stream_ticker_ind_book(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int Client::stream_ticker_ind_book(const std::string& symbol, FT& functor) { try { @@ -874,7 +854,7 @@ unsigned int Client::stream_ticker_ind_book(const std::string& symbol, std::s { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -886,13 +866,12 @@ unsigned int Client::stream_ticker_ind_book(const std::string& symbol, std::s /** Start book ticker stream (all) - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int Client::stream_ticker_all_book(std::string& buffer, FT& functor) +unsigned int Client::stream_ticker_all_book(FT& functor) { try { @@ -902,7 +881,7 @@ unsigned int Client::stream_ticker_all_book(std::string& buffer, FT& functor) { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -915,7 +894,6 @@ unsigned int Client::stream_ticker_all_book(std::string& buffer, FT& functor) /** Start partial depth stream @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param levels - how many depth level, part of the query @param interval - interval of the responses, part of the query @@ -923,7 +901,7 @@ unsigned int Client::stream_ticker_all_book(std::string& buffer, FT& functor) */ template template -unsigned int Client::stream_depth_partial(const std::string& symbol, std::string& buffer, FT& functor, unsigned int levels, unsigned int interval) +unsigned int Client::stream_depth_partial(const std::string& symbol, FT& functor, unsigned int levels, unsigned int interval) { try { @@ -934,7 +912,7 @@ unsigned int Client::stream_depth_partial(const std::string& symbol, std::str { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -947,14 +925,13 @@ unsigned int Client::stream_depth_partial(const std::string& symbol, std::str /** Start diff depth stream @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template template -unsigned int Client::stream_depth_diff(const std::string& symbol, std::string& buffer, FT& functor, unsigned int interval) +unsigned int Client::stream_depth_diff(const std::string& symbol, FT& functor, unsigned int interval) { try { @@ -964,7 +941,7 @@ unsigned int Client::stream_depth_diff(const std::string& symbol, std::string { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } catch (ClientException e) @@ -976,18 +953,17 @@ unsigned int Client::stream_depth_diff(const std::string& symbol, std::string /** Start User Stream - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param ping_listen_key - if true, will ping listen key @return an unsigned int representing success */ template template -unsigned int Client::stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key) +unsigned int Client::stream_userstream(FT& functor, const bool ping_listen_key) { try { - return static_cast(this)->v_stream_userstream(buffer, functor, ping_listen_key); + return static_cast(this)->v_stream_userstream(functor, ping_listen_key); } catch (ClientException e) { @@ -999,14 +975,13 @@ unsigned int Client::stream_userstream(std::string& buffer, FT& functor, cons /** Start Custom Stream @param stream_name - The name of the stream - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param ping_listen_key - if true, will ping listen key @return an unsigned int representing success */ template template -unsigned int Client::custom_stream(const std::string stream_name, std::string& buffer, FT& functor, const bool ping_listen_key) +unsigned int Client::custom_stream(const std::string stream_name, FT& functor, const bool ping_listen_key) { try { @@ -1015,7 +990,7 @@ unsigned int Client::custom_stream(const std::string stream_name, std::string { this->_ws_client->close_stream(stream_query); } - this->_ws_client->template _stream_manager(stream_name, stream_query, buffer, functor, ping_listen_key); + this->_ws_client->template _stream_manager(stream_name, stream_query, functor, ping_listen_key); return this->_ws_client->running_streams[stream_query]; } @@ -1029,17 +1004,16 @@ unsigned int Client::custom_stream(const std::string stream_name, std::string /** Open trade stream @param symbol - a string reference of the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template template -unsigned int Client::stream_Trade(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int Client::stream_Trade(const std::string& symbol, FT& functor) { try { - return static_cast(this)->v_stream_Trade(symbol, buffer, functor); + return static_cast(this)->v_stream_Trade(symbol, functor); } catch (ClientException e) { @@ -1050,13 +1024,12 @@ unsigned int Client::stream_Trade(const std::string& symbol, std::string& buf /** Start userstream (Ops) - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param ping_listen_key - if true, will ping listen key periodically @return an unsigned int representing success */ template -unsigned int OpsClient::v_stream_userstream(std::string& buffer, FT& functor, const bool ping_listen_key) +unsigned int OpsClient::v_stream_userstream(FT& functor, const bool ping_listen_key) { std::string stream_name = this->get_listen_key(); std::string stream_query = "/ws/" + stream_name; @@ -1064,19 +1037,18 @@ unsigned int OpsClient::v_stream_userstream(std::string& buffer, FT& functor, co { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor, ping_listen_key); + this->_ws_client->_stream_manager(stream_name, stream_query, functor, ping_listen_key); return this->_ws_client->running_streams[stream_query]; } /** Start trades stream (Ops) @param symbol - the symbol of the trades - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @return an unsigned int representing success */ template -unsigned int OpsClient::v_stream_Trade(const std::string& symbol, std::string& buffer, FT& functor) +unsigned int OpsClient::v_stream_Trade(const std::string& symbol, FT& functor) { std::string stream_name = symbol + '@' + "trade"; std::string stream_query = "/ws/" + stream_name; @@ -1084,20 +1056,19 @@ unsigned int OpsClient::v_stream_Trade(const std::string& symbol, std::string& b { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } /** Start kline (candlesticks) stream @param symbol - the symbol - @param buffer - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param interval - interval of the responses, part of the query @return an unsigned int representing success */ template -unsigned int OpsClient::v_stream_kline(const std::string& symbol, std::string& buffer, FT& functor, std::string interval) +unsigned int OpsClient::v_stream_kline(const std::string& symbol, FT& functor, std::string interval) { std::string stream_name = symbol + "@" + "kline_" + (interval); std::string stream_query = "/ws/" + stream_name; @@ -1105,7 +1076,7 @@ unsigned int OpsClient::v_stream_kline(const std::string& symbol, std::string& b { this->_ws_client->close_stream(stream_query); } - this->_ws_client->_stream_manager(stream_name, stream_query, buffer, functor); + this->_ws_client->_stream_manager(stream_name, stream_query, functor); return this->_ws_client->running_streams[stream_query]; } @@ -1119,14 +1090,13 @@ unsigned int OpsClient::v_stream_kline(const std::string& symbol, std::string& b @param stream_map_name - The name of the stream @param stream_path - The path of the string (query) - @param buf - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param ping_listen_key - if true, will ping listen key @return an unsigned int representing success */ template template -void WebsocketClient::_stream_manager(std::string stream_map_name, const std::string stream_path, std::string& buf, FT& functor, const bool ping_listen_key) +void WebsocketClient::_stream_manager(std::string stream_map_name, const std::string stream_path, FT& functor, const bool ping_listen_key) { unsigned int reconnect_attempts = 0; this->running_streams[stream_map_name] = 0; // init @@ -1134,7 +1104,7 @@ void WebsocketClient::_stream_manager(std::string stream_map_name, const std: { try { - this->_connect_to_endpoint(stream_map_name, stream_path, buf, functor, ping_listen_key); // will not proceed unless connection is broken + this->_connect_to_endpoint(stream_map_name, stream_path, functor, ping_listen_key); // will not proceed unless connection is broken } catch (ClientException e) @@ -1154,24 +1124,24 @@ void WebsocketClient::_stream_manager(std::string stream_map_name, const std: /** Starts a new stream - This method starts the stream and maintains a 'while' loop that loads the websocket messages into 'buf' and - invoke 'functor' as the callback. + This method starts the stream and maintains a 'while' loop that reads the websocket messages into a buffer and + invokes 'functor' as the callback. The member 'running_streams' contains names of active streams. In order to close a stream, the name should be removed from there. @param stream_map_name - The name of the stream @param stream_path - The path of the string (query) - @param buf - a reference of the string buffer to load responses to @param functor - a reference to the functor object to be called as callback @param ping_listen_key - if true, will ping listen key @return an unsigned int representing success */ template template -void WebsocketClient::_connect_to_endpoint(const std::string stream_map_name, const std::string stream_path, std::string& buf, FT& functor, const bool ping_listen_key) +void WebsocketClient::_connect_to_endpoint(const std::string stream_map_name, const std::string stream_path, FT& functor, const bool ping_listen_key) { long long unsigned int last_keepalive{ 0 }; - + + std::string buf{}; net::io_context ioc; ssl::context ctx{ ssl::context::tlsv12_client }; tcp::resolver resolver{ ioc }; diff --git a/src/Binance_Client.cpp b/src/Binance_Client.cpp index 3142eae..e3d99e5 100755 --- a/src/Binance_Client.cpp +++ b/src/Binance_Client.cpp @@ -7638,7 +7638,7 @@ Json::Value FuturesClientCoin::v_get_composite_index_symbol_info(const Params* p CRTP of stream_markprice_all() */ template -unsigned int FuturesClientCoin::v_stream_markprice_all(const std::string& symbol, std::string& buffer, FT& functor) // here +unsigned int FuturesClientCoin::v_stream_markprice_all(const std::string& symbol, FT& functor) // here { MissingEndpoint e{}; e.append_to_traceback(std::string(__FUNCTION__));