From 9345e7be46ab682cf77142df93cff0182aa09e1d Mon Sep 17 00:00:00 2001 From: Crypto Chassis Date: Mon, 6 Mar 2023 13:52:25 -0800 Subject: [PATCH 1/7] draft: first draft to use boost beast websocket --- include/ccapi_cpp/ccapi_http_retry.h | 1 + include/ccapi_cpp/ccapi_session.h | 20 +- include/ccapi_cpp/ccapi_session_options.h | 4 + include/ccapi_cpp/ccapi_ws_connection.h | 95 ++ .../ccapi_execution_management_service.h | 38 +- ...pi_execution_management_service_ascendex.h | 4 +- ...api_execution_management_service_binance.h | 2 +- ...xecution_management_service_binance_base.h | 2 +- ..._management_service_binance_coin_futures.h | 2 +- ...cution_management_service_binance_margin.h | 2 +- ..._execution_management_service_binance_us.h | 2 +- ..._management_service_binance_usds_futures.h | 2 +- ...pi_execution_management_service_bitfinex.h | 2 +- ...capi_execution_management_service_bitget.h | 2 +- ...cution_management_service_bitget_futures.h | 2 +- ...api_execution_management_service_bitmart.h | 2 +- ...capi_execution_management_service_bitmex.h | 2 +- ...pi_execution_management_service_bitstamp.h | 4 +- ...ccapi_execution_management_service_bybit.h | 2 +- ...ion_management_service_bybit_derivatives.h | 2 +- ...pi_execution_management_service_coinbase.h | 2 +- ...i_execution_management_service_cryptocom.h | 2 +- ...api_execution_management_service_deribit.h | 2 +- .../ccapi_execution_management_service_ftx.h | 2 +- ...capi_execution_management_service_ftx_us.h | 2 +- ...capi_execution_management_service_gateio.h | 2 +- ...agement_service_gateio_perpetual_futures.h | 6 +- ...capi_execution_management_service_gemini.h | 2 +- ...ccapi_execution_management_service_huobi.h | 2 +- ...ution_management_service_huobi_coin_swap.h | 2 +- ...ution_management_service_huobi_usdt_swap.h | 2 +- ...capi_execution_management_service_kraken.h | 4 +- ...cution_management_service_kraken_futures.h | 2 +- ...capi_execution_management_service_kucoin.h | 2 +- ...cution_management_service_kucoin_futures.h | 2 +- .../ccapi_execution_management_service_mexc.h | 4 +- ...xecution_management_service_mexc_futures.h | 2 +- .../ccapi_execution_management_service_okx.h | 2 +- include/ccapi_cpp/service/ccapi_fix_service.h | 10 - .../service/ccapi_market_data_service.h | 663 ++++++++++---- .../ccapi_market_data_service_ascendex.h | 2 +- .../ccapi_market_data_service_binance.h | 2 +- ...market_data_service_binance_coin_futures.h | 2 +- .../ccapi_market_data_service_binance_us.h | 2 +- ...market_data_service_binance_usds_futures.h | 2 +- .../ccapi_market_data_service_bitfinex.h | 2 +- .../ccapi_market_data_service_bitget.h | 2 +- ...ccapi_market_data_service_bitget_futures.h | 2 +- .../ccapi_market_data_service_bitmart.h | 2 +- .../ccapi_market_data_service_bitmex.h | 2 +- .../ccapi_market_data_service_bitstamp.h | 2 +- .../service/ccapi_market_data_service_bybit.h | 2 +- ...pi_market_data_service_bybit_derivatives.h | 2 +- .../ccapi_market_data_service_coinbase.h | 18 +- .../ccapi_market_data_service_cryptocom.h | 2 +- .../ccapi_market_data_service_deribit.h | 2 +- .../service/ccapi_market_data_service_erisx.h | 2 +- .../service/ccapi_market_data_service_ftx.h | 2 +- .../ccapi_market_data_service_ftx_us.h | 2 +- .../ccapi_market_data_service_gateio.h | 2 +- ...et_data_service_gateio_perpetual_futures.h | 4 +- .../ccapi_market_data_service_gemini.h | 4 +- .../service/ccapi_market_data_service_huobi.h | 2 +- .../ccapi_market_data_service_huobi_base.h | 2 +- ...capi_market_data_service_huobi_coin_swap.h | 2 +- ...capi_market_data_service_huobi_usdt_swap.h | 2 +- .../ccapi_market_data_service_kraken.h | 2 +- ...ccapi_market_data_service_kraken_futures.h | 2 +- .../ccapi_market_data_service_kucoin.h | 2 +- ...ccapi_market_data_service_kucoin_futures.h | 2 +- .../service/ccapi_market_data_service_mexc.h | 2 +- .../ccapi_market_data_service_mexc_futures.h | 2 +- .../service/ccapi_market_data_service_okx.h | 2 +- .../ccapi_market_data_service_whitebit.h | 2 +- include/ccapi_cpp/service/ccapi_service.h | 866 +++++++++++++++--- .../ccapi_cpp/service/ccapi_service_context.h | 44 + test/test_build/CMakeLists.txt | 1 + 77 files changed, 1496 insertions(+), 412 deletions(-) diff --git a/include/ccapi_cpp/ccapi_http_retry.h b/include/ccapi_cpp/ccapi_http_retry.h index bc8eb559..27f3a0f3 100644 --- a/include/ccapi_cpp/ccapi_http_retry.h +++ b/include/ccapi_cpp/ccapi_http_retry.h @@ -1,5 +1,6 @@ #ifndef INCLUDE_CCAPI_CPP_CCAPI_HTTP_RETRY_H_ #define INCLUDE_CCAPI_CPP_CCAPI_HTTP_RETRY_H_ +#include #include namespace ccapi { /** diff --git a/include/ccapi_cpp/ccapi_session.h b/include/ccapi_cpp/ccapi_session.h index b96a579c..f280f748 100644 --- a/include/ccapi_cpp/ccapi_session.h +++ b/include/ccapi_cpp/ccapi_session.h @@ -689,7 +689,7 @@ class Session { for (auto& subscriptionListByExchange : subscriptionListByExchangeMap) { auto exchange = subscriptionListByExchange.first; auto subscriptionList = subscriptionListByExchange.second; - std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); + std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); if (serviceByExchangeMap.find(exchange) == serviceByExchangeMap.end()) { this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, "please enable exchange: " + exchange); return; @@ -706,7 +706,7 @@ class Session { for (auto& subscriptionListByExchange : subscriptionListByExchangeMap) { auto exchange = subscriptionListByExchange.first; auto subscriptionList = subscriptionListByExchange.second; - std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); + std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); if (serviceByExchangeMap.find(exchange) == serviceByExchangeMap.end()) { this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, "please enable exchange: " + exchange); return; @@ -725,7 +725,7 @@ class Session { return; } auto exchange = subscription.getExchange(); - std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); + std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); if (serviceByExchangeMap.find(exchange) == serviceByExchangeMap.end()) { this->onError(Event::Type::FIX_STATUS, Message::Type::FIX_FAILURE, "please enable exchange: " + exchange); return; @@ -781,7 +781,7 @@ class Session { this->onError(Event::Type::FIX_STATUS, Message::Type::FIX_FAILURE, "please enable service: " + serviceName + ", and the exchanges that you want"); return; } - std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); + std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); auto exchange = request.getExchange(); if (serviceByExchangeMap.find(exchange) == serviceByExchangeMap.end()) { this->onError(Event::Type::FIX_STATUS, Message::Type::FIX_FAILURE, "please enable exchange: " + exchange); @@ -805,7 +805,7 @@ class Session { this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, "please enable service: " + serviceName + ", and the exchanges that you want"); return; } - std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); + std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); auto exchange = request.getExchange(); if (serviceByExchangeMap.find(exchange) == serviceByExchangeMap.end()) { this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, "please enable exchange: " + exchange); @@ -841,7 +841,7 @@ class Session { "please enable service: " + serviceName + ", and the exchanges that you want", eventQueuePtr); return; } - std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); + std::map >& serviceByExchangeMap = this->serviceByServiceNameExchangeMap.at(serviceName); auto exchange = request.getExchange(); if (serviceByExchangeMap.find(exchange) == serviceByExchangeMap.end()) { this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, "please enable exchange: " + exchange, eventQueuePtr); @@ -888,7 +888,7 @@ class Session { #ifndef SWIG virtual void setTimer(const std::string& id, long delayMilliSeconds, std::function errorHandler, std::function successHandler) { - wspp::lib::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), [this, id, delayMilliSeconds, errorHandler, successHandler]() { + boost::asio::post(*this->serviceContextPtr->ioContextPtr, [this, id, delayMilliSeconds, errorHandler, successHandler]() { std::shared_ptr timerPtr(new steady_timer(*this->serviceContextPtr->ioContextPtr, boost::asio::chrono::milliseconds(delayMilliSeconds))); timerPtr->async_wait([this, id, errorHandler, successHandler](const boost::system::error_code& ec) { if (this->eventHandler) { @@ -914,7 +914,7 @@ class Session { }); } virtual void cancelTimer(const std::string& id) { - wspp::lib::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), [this, id]() { + boost::asio::post(*this->serviceContextPtr->ioContextPtr, [this, id]() { if (this->delayTimerByIdMap.find(id) != this->delayTimerByIdMap.end()) { this->delayTimerByIdMap[id]->cancel(); this->delayTimerByIdMap.erase(id); @@ -944,8 +944,8 @@ class Session { EventDispatcher* eventDispatcher; bool useInternalEventDispatcher{}; #endif - wspp::lib::shared_ptr serviceContextPtr; - std::map > > serviceByServiceNameExchangeMap; + std::shared_ptr serviceContextPtr; + std::map > > serviceByServiceNameExchangeMap; std::thread t; Queue eventQueue; std::function* eventQueue)> internalEventHandler; diff --git a/include/ccapi_cpp/ccapi_session_options.h b/include/ccapi_cpp/ccapi_session_options.h index bb27345e..e4ab6134 100644 --- a/include/ccapi_cpp/ccapi_session_options.h +++ b/include/ccapi_cpp/ccapi_session_options.h @@ -54,6 +54,10 @@ class SessionOptions CCAPI_FINAL { long httpConnectionPoolIdleTimeoutMilliSeconds{0}; // used to purge the http connection pool if all connections in the // pool have stayed idle for at least this amount of time bool enableOneHttpConnectionPerRequest{}; // create a new http connection for each request +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else + long websocketConnectTimeoutMilliSeconds{10000}; +#endif }; } /* namespace ccapi */ #endif // INCLUDE_CCAPI_CPP_CCAPI_SESSION_OPTIONS_H_ diff --git a/include/ccapi_cpp/ccapi_ws_connection.h b/include/ccapi_cpp/ccapi_ws_connection.h index 2c6d356f..cde6d64f 100644 --- a/include/ccapi_cpp/ccapi_ws_connection.h +++ b/include/ccapi_cpp/ccapi_ws_connection.h @@ -1,5 +1,6 @@ #ifndef INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_ #define INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_ +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET #include #include "ccapi_cpp/ccapi_logger.h" @@ -74,4 +75,98 @@ class WsConnection CCAPI_FINAL { std::map credential; }; } /* namespace ccapi */ +#else +#include + +#include "ccapi_cpp/ccapi_logger.h" +#include "ccapi_cpp/ccapi_subscription.h" +namespace ccapi { +/** + * This class represents a TCP socket connection for the websocket API. + */ +class WsConnection CCAPI_FINAL { + public: + WsConnection(std::string url, std::string group, std::vector subscriptionList, std::map credential, + std::shared_ptr > > streamPtr) + : url(url), group(group), subscriptionList(subscriptionList), credential(credential), streamPtr(streamPtr) { + this->id = this->url + "||" + this->group + "||" + ccapi::toString(this->subscriptionList) + "||" + ccapi::toString(this->credential); + this->correlationIdList.reserve(subscriptionList.size()); + std::transform(subscriptionList.cbegin(), subscriptionList.cend(), this->correlationIdList.begin(), + [](Subscription subscription) { return subscription.getCorrelationId(); }); + auto splitted1 = UtilString::split(url, "://"); + auto foundSlash = splitted1[1].find_first_of('/'); + auto foundQuestionMark = splitted1[1].find_first_of('?'); + if (foundSlash == std::string::npos && foundQuestionMark == std::string::npos) { + this->path = "/"; + } else if (foundSlash == std::string::npos && foundQuestionMark != std::string::npos) { + this->path = "/" + splitted1[1].substr(foundQuestionMark); + } else if (foundSlash != std::string::npos && foundQuestionMark == std::string::npos) { + this->path = splitted1[1].substr(foundSlash); + } else { + this->path = splitted1[1].substr(foundSlash); + } + } + WsConnection() {} + std::string toString() const { + std::map shortCredential; + for (const auto& x : credential) { + shortCredential.insert(std::make_pair(x.first, UtilString::firstNCharacter(x.second, CCAPI_CREDENTIAL_DISPLAY_LENGTH))); + } + std::ostringstream oss; + oss << streamPtr; + std::string output = "WsConnection [id = " + id + ", url = " + url + ", group = " + group + ", subscriptionList = " + ccapi::toString(subscriptionList) + + ", credential = " + ccapi::toString(shortCredential) + ", status = " + statusToString(status) + + ", headers = " + ccapi::toString(headers) + ", streamPtr = " + oss.str() + "]"; + return output; + } + enum class Status { + UNKNOWN, + CONNECTING, + OPEN, + FAILED, + CLOSING, + CLOSED, + }; + static std::string statusToString(Status status) { + std::string output; + switch (status) { + case Status::UNKNOWN: + output = "UNKNOWN"; + break; + case Status::CONNECTING: + output = "CONNECTING"; + break; + case Status::OPEN: + output = "OPEN"; + break; + case Status::FAILED: + output = "FAILED"; + break; + case Status::CLOSING: + output = "CLOSING"; + break; + case Status::CLOSED: + output = "CLOSED"; + break; + default: + CCAPI_LOGGER_FATAL(CCAPI_UNSUPPORTED_VALUE); + } + return output; + } + std::string id; + std::string url; + std::string group; + std::vector subscriptionList; + std::vector correlationIdList; + Status status{Status::UNKNOWN}; + std::map headers; + std::map credential; + std::shared_ptr > > streamPtr; + beast::websocket::close_code remoteCloseCode; + beast::websocket::close_reason remoteCloseReason; + std::string hostHttpHeaderValue; + std::string path; +}; +} /* namespace ccapi */ +#endif #endif // INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service.h b/include/ccapi_cpp/service/ccapi_execution_management_service.h index 9dc3c4bd..599165e6 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service.h @@ -45,20 +45,34 @@ class ExecutionManagementService : public Service { // each subscription creates a unique websocket connection void subscribe(std::vector& subscriptionList) override { CCAPI_LOGGER_FUNCTION_ENTER; - CCAPI_LOGGER_DEBUG("this->baseUrl = " + this->baseUrl); + CCAPI_LOGGER_DEBUG("this->baseUrlWs = " + this->baseUrlWs); if (this->shouldContinue.load()) { for (auto& subscription : subscriptionList) { - wspp::lib::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), - [that = shared_from_base(), subscription]() mutable { - auto now = UtilTime::now(); - subscription.setTimeSent(now); - auto credential = subscription.getCredential(); - if (credential.empty()) { - credential = that->credentialDefault; + boost::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), + [that = shared_from_base(), subscription]() mutable { + auto now = UtilTime::now(); + subscription.setTimeSent(now); + auto credential = subscription.getCredential(); + if (credential.empty()) { + credential = that->credentialDefault; + } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + WsConnection wsConnection(that->baseUrlWs, "", {subscription}, credential); + that->prepareConnect(wsConnection); +#else + std::shared_ptr> streamPtr(nullptr); + try { + streamPtr = this->createStream>>(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, this->hostWs); + } catch (const beast::error_code& ec) { + CCAPI_LOGGER_TRACE("fail"); + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "create stream", {subscription.getCorrelationId()}, eventQueuePtr); + return; } - WsConnection wsConnection(that->baseUrl, "", {subscription}, credential); - that->prepareConnect(wsConnection); - }); + std::shared_ptr wsConnectionPtr(new WsConnection(this->hostWs, this->portWs, streamPtr)); + CCAPI_LOGGER_WARN("about to subscribe with new wsConnectionPtr " + toString(*wsConnectionPtr)); + that->prepareConnect(wsConnectionPtr); +#endif + }); } } CCAPI_LOGGER_FUNCTION_EXIT; @@ -210,7 +224,7 @@ class ExecutionManagementService : public Service { void sendRequestByWebsocket(Request& request, const TimePoint& now) override { CCAPI_LOGGER_FUNCTION_ENTER; CCAPI_LOGGER_TRACE("now = " + toString(now)); - wspp::lib::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), [that = shared_from_base(), request]() mutable { + boost::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), [that = shared_from_base(), request]() mutable { auto now = UtilTime::now(); CCAPI_LOGGER_DEBUG("request = " + toString(request)); CCAPI_LOGGER_TRACE("now = " + toString(now)); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h index f85a0bba..a19fff4f 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceAscendex : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_ASCENDEX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { @@ -350,7 +350,7 @@ class ExecutionManagementServiceAscendex : public ExecutionManagementService { credential = that->credentialDefault; } const auto& accountGroup = mapGetWithDefault(credential, that->apiAccountGroupName); - WsConnection wsConnection(that->baseUrl + "/" + accountGroup + "/api/pro/v1/stream", "", {subscription}, credential); + WsConnection wsConnection(that->baseUrlWs + "/" + accountGroup + "/api/pro/v1/stream", "", {subscription}, credential); that->prepareConnect(wsConnection); }); } diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h index 200fd32d..ee73bbe2 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h @@ -13,7 +13,7 @@ class ExecutionManagementServiceBinance : public ExecutionManagementServiceBinan ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_base.h index 70fff87d..7e88c468 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_base.h @@ -309,7 +309,7 @@ class ExecutionManagementServiceBinanceBase : public ExecutionManagementService rj::Document document; document.Parse(body.c_str()); std::string listenKey = document["listenKey"].GetString(); - std::string url = that->baseUrl + "/" + listenKey; + std::string url = that->baseUrlWs + "/" + listenKey; thisWsConnection.url = url; that->connect(thisWsConnection); that->extraPropertyByConnectionIdMap[thisWsConnection.id].insert({ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h index a9384ced..209cca11 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBinanceCoinFutures : public ExecutionManagementS SessionConfigs sessionConfigs, ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBinanceDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_COIN_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h index 6c72c932..e6bc7c26 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBinanceMargin : public ExecutionManagementServic ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_MARGIN; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h index d1beb18e..9f2992c1 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBinanceUs : public ExecutionManagementServiceBin ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_US; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h index fa738677..829a35f3 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBinanceUsdsFutures : public ExecutionManagementS SessionConfigs sessionConfigs, ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBinanceDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_USDS_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h index f2842a55..fe31cc0e 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBitfinex : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITFINEX; - this->baseUrl = std::string(CCAPI_BITFINEX_PRIVATE_URL_WS_BASE) + "/ws/2"; + this->baseUrlWs = std::string(CCAPI_BITFINEX_PRIVATE_URL_WS_BASE) + "/ws/2"; this->baseUrlRest = CCAPI_BITFINEX_PRIVATE_URL_REST_BASE; this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h index f4a07b47..5bbdd422 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBitget : public ExecutionManagementServiceBitget ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBitgetBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITGET; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/v1/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h index 3321e7f6..cdef55b3 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBitgetFutures : public ExecutionManagementServic ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBitgetBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITGET_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/mix/v1/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/mix/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h index 33873927..2a96e6ca 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBitmart : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITMART; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/user?protocol=1.1"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/user?protocol=1.1"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h index a022b1f9..2dedc4b6 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBitmex : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITMEX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/realtime"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/realtime"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h index 0b755426..7cd28cec 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITSTAMP; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { @@ -299,7 +299,7 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { if (document.HasMember("token") && document.HasMember("user_id")) { std::string token = document["token"].GetString(); std::string userId = document["user_id"].GetString(); - thisWsConnection.url = that->baseUrl; + thisWsConnection.url = that->baseUrlWs; that->connect(thisWsConnection); that->extraPropertyByConnectionIdMap[thisWsConnection.id].insert({ {"token", token}, diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h index f12d98bc..ea2e23bd 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBybit : public ExecutionManagementServiceBybitBa ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBybitBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BYBIT; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/private/v3"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/private/v3"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h index 8100f5bb..7a6082cd 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceBybitDerivatives : public ExecutionManagementSer SessionConfigs sessionConfigs, ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceBybitBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BYBIT_DERIVATIVES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/unified/private/v3"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/unified/private/v3"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h index c767a80c..b3d51b8f 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceCoinbase : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_COINBASE; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h index 6e5caa76..12baa19f 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceCryptocom : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_CRYPTOCOM; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v2/user"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v2/user"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h index 88540ec3..0193b63f 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceDeribit : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_DERIBIT; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/api/v2"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/api/v2"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h index 71a583a8..9697f65d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceFtx : public ExecutionManagementServiceFtxBase { ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceFtxBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_FTX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h index 7ed37b87..09e9f7cd 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceFtxUs : public ExecutionManagementServiceFtxBase ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceFtxBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_FTX_US; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h index 489808ec..a4d32079 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceGateio : public ExecutionManagementServiceGateio ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceGateioBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GATEIO; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v4/"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v4/"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h index 7844b776..c9f01f81 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceGateioPerpetualFutures : public ExecutionManagem SessionConfigs sessionConfigs, ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceGateioBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v4/ws/"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v4/ws/"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { @@ -75,7 +75,7 @@ class ExecutionManagementServiceGateioPerpetualFutures : public ExecutionManagem } void subscribe(std::vector& subscriptionList) override { CCAPI_LOGGER_FUNCTION_ENTER; - CCAPI_LOGGER_DEBUG("this->baseUrl = " + this->baseUrl); + CCAPI_LOGGER_DEBUG("this->baseUrlWs = " + this->baseUrlWs); if (this->shouldContinue.load()) { for (auto& subscription : subscriptionList) { wspp::lib::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), @@ -96,7 +96,7 @@ class ExecutionManagementServiceGateioPerpetualFutures : public ExecutionManagem if (credential.empty()) { credential = that->credentialDefault; } - WsConnection wsConnection(that->baseUrl + settle, "", {subscription}, credential); + WsConnection wsConnection(that->baseUrlWs + settle, "", {subscription}, credential); that->prepareConnect(wsConnection); } }); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h index f69304ad..90b1de36 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceGemini : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GEMINI; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v1/order/events"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v1/order/events"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h index 168c450e..a6195a4f 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceHuobi : public ExecutionManagementServiceHuobiBa ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceHuobiBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v2"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v2"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h index 1ecb26cb..7eee7329 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceHuobiCoinSwap : public ExecutionManagementServic ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceHuobiDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI_COIN_SWAP; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/swap-notification"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/swap-notification"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h index 91fedb3f..bcc17d32 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceHuobiUsdtSwap : public ExecutionManagementServic ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceHuobiDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI_USDT_SWAP; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/linear-swap-notification"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/linear-swap-notification"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h index 54d140d6..423bfac1 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h @@ -11,7 +11,7 @@ class ExecutionManagementServiceKraken : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KRAKEN; - this->baseUrl = CCAPI_KRAKEN_URL_WS_BASE_PRIVATE; + this->baseUrlWs = CCAPI_KRAKEN_URL_WS_BASE_PRIVATE; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { @@ -294,7 +294,7 @@ class ExecutionManagementServiceKraken : public ExecutionManagementService { document.Parse(body.c_str()); if (document.HasMember("result") && document["result"].HasMember("token")) { std::string token = document["result"]["token"].GetString(); - thisWsConnection.url = that->baseUrl; + thisWsConnection.url = that->baseUrlWs; that->connect(thisWsConnection); that->extraPropertyByConnectionIdMap[thisWsConnection.id].insert({ {"token", token}, diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h index 6b3f08d9..d56cc076 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h @@ -11,7 +11,7 @@ class ExecutionManagementServiceKrakenFutures : public ExecutionManagementServic ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KRAKEN_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v1"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v1"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h index 380031dd..b7e54013 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceKucoin : public ExecutionManagementServiceKucoin ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceKucoinBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KUCOIN; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h index fdf113b1..394f1867 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceKucoinFutures : public ExecutionManagementServic ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceKucoinBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KUCOIN_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h index ac3d8263..36f8cd54 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h @@ -11,7 +11,7 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService { : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->pingListenKeyIntervalSeconds = 600; this->exchangeName = CCAPI_EXCHANGE_NAME_MEXC; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { @@ -245,7 +245,7 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService { rj::Document document; document.Parse(body.c_str()); std::string listenKey = document["listenKey"].GetString(); - std::string url = that->baseUrl + "?listenKey=" + listenKey; + std::string url = that->baseUrlWs + "?listenKey=" + listenKey; thisWsConnection.url = url; that->connect(thisWsConnection); that->extraPropertyByConnectionIdMap[thisWsConnection.id].insert({ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h index 5eec79fd..35486f31 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceMexcFutures : public ExecutionManagementService ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_MEXC_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h index e4e83e87..115842fa 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h @@ -10,7 +10,7 @@ class ExecutionManagementServiceOkx : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_OKX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + CCAPI_OKX_PRIVATE_WS_PATH; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + CCAPI_OKX_PRIVATE_WS_PATH; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_fix_service.h b/include/ccapi_cpp/service/ccapi_fix_service.h index 9eaaa5f7..551d0e45 100644 --- a/include/ccapi_cpp/service/ccapi_fix_service.h +++ b/include/ccapi_cpp/service/ccapi_fix_service.h @@ -26,16 +26,6 @@ class FixService : public Service { protected: #endif - static std::string printableString(const char* s, size_t n) { - std::string output(s, n); - std::replace(output.begin(), output.end(), '\x01', '^'); - return output; - } - static std::string printableString(const std::string& s) { - std::string output(s); - std::replace(output.begin(), output.end(), '\x01', '^'); - return output; - } void setHostFixFromUrlFix(std::string& aHostFix, std::string& aPortFix, const std::string& baseUrlFix) { auto hostPort = this->extractHostFromUrl(baseUrlFix); aHostFix = hostPort.first; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service.h b/include/ccapi_cpp/service/ccapi_market_data_service.h index 24b395a5..d0dc5562 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service.h @@ -42,16 +42,17 @@ class MarketDataService : public Service { } } } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET // subscriptions are grouped and each group creates a unique websocket connection void subscribe(std::vector& subscriptionList) override { CCAPI_LOGGER_FUNCTION_ENTER; - CCAPI_LOGGER_DEBUG("this->baseUrl = " + this->baseUrl); + CCAPI_LOGGER_DEBUG("this->baseUrlWs = " + this->baseUrlWs); if (this->shouldContinue.load()) { for (auto& x : this->groupSubscriptionListByInstrumentGroup(subscriptionList)) { auto instrumentGroup = x.first; auto subscriptionListGivenInstrumentGroup = x.second; - wspp::lib::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), [that = shared_from_base(), instrumentGroup, - subscriptionListGivenInstrumentGroup]() mutable { + boost::asio::post(*this->serviceContextPtr->ioContextPtr, [that = shared_from_base(), instrumentGroup, + subscriptionListGivenInstrumentGroup]() mutable { auto now = UtilTime::now(); for (auto& subscription : subscriptionListGivenInstrumentGroup) { subscription.setTimeSent(now); @@ -88,12 +89,79 @@ class MarketDataService : public Service { } CCAPI_LOGGER_FUNCTION_EXIT; } +#else + // subscriptions are grouped and each group creates a unique websocket connection + void subscribe(std::vector& subscriptionList) override { + CCAPI_LOGGER_FUNCTION_ENTER; + CCAPI_LOGGER_DEBUG("this->baseUrlWs = " + this->baseUrlWs); + if (this->shouldContinue.load()) { + for (auto& x : this->groupSubscriptionListByInstrumentGroup(subscriptionList)) { + auto instrumentGroup = x.first; + auto subscriptionListGivenInstrumentGroup = x.second; + boost::asio::post(*this->serviceContextPtr->ioContextPtr, [that = shared_from_base(), instrumentGroup, + subscriptionListGivenInstrumentGroup]() mutable { + auto now = UtilTime::now(); + for (auto& subscription : subscriptionListGivenInstrumentGroup) { + subscription.setTimeSent(now); + } + std::map> wsConnectionIdListByInstrumentGroupMap = invertMapMulti(that->instrumentGroupByWsConnectionIdMap); + if (wsConnectionIdListByInstrumentGroupMap.find(instrumentGroup) != wsConnectionIdListByInstrumentGroupMap.end() && + that->subscriptionStatusByInstrumentGroupInstrumentMap.find(instrumentGroup) != that->subscriptionStatusByInstrumentGroupInstrumentMap.end()) { + auto wsConnectionId = wsConnectionIdListByInstrumentGroupMap.at(instrumentGroup).at(0); + auto wsConnectionPtr = that->wsConnectionByIdMap.at(wsConnectionId); + WsConnection& wsConnection = *wsConnectionPtr; + for (const auto& subscription : subscriptionListGivenInstrumentGroup) { + auto instrument = subscription.getInstrument(); + if (that->subscriptionStatusByInstrumentGroupInstrumentMap[instrumentGroup].find(instrument) != + that->subscriptionStatusByInstrumentGroupInstrumentMap[instrumentGroup].end()) { + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, "already subscribed: " + toString(subscription)); + return; + } + wsConnection.subscriptionList.push_back(subscription); + that->subscriptionStatusByInstrumentGroupInstrumentMap[instrumentGroup][instrument] = Subscription::Status::SUBSCRIBING; + that->prepareSubscription(wsConnection, subscription); + } + CCAPI_LOGGER_INFO("about to subscribe to exchange"); + that->subscribeToExchange(wsConnectionPtr); + } else { + auto url = UtilString::split(instrumentGroup, "|").at(0); + auto credential = subscriptionListGivenInstrumentGroup.at(0).getCredential(); + if (credential.empty()) { + credential = that->credentialDefault; + } + std::shared_ptr>> streamPtr(nullptr); + try { + streamPtr = that->createStream>>( + that->serviceContextPtr->ioContextPtr, that->serviceContextPtr->sslContextPtr, that->hostWs); + } catch (const beast::error_code& ec) { + CCAPI_LOGGER_TRACE("fail"); + std::vector correlationIdList; + correlationIdList.reserve(subscriptionListGivenInstrumentGroup.size()); + std::transform(subscriptionListGivenInstrumentGroup.cbegin(), subscriptionListGivenInstrumentGroup.cend(), correlationIdList.begin(), + [](Subscription subscription) { return subscription.getCorrelationId(); }); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "create stream", correlationIdList); + return; + } + std::shared_ptr wsConnectionPtr(new WsConnection(url, instrumentGroup, subscriptionListGivenInstrumentGroup, credential, streamPtr)); + CCAPI_LOGGER_WARN("about to subscribe with new wsConnectionPtr " + toString(*wsConnectionPtr)); + that->prepareConnect(wsConnectionPtr); + } + }); + } + } + CCAPI_LOGGER_FUNCTION_EXIT; + } +#endif #ifndef CCAPI_EXPOSE_INTERNAL protected: #endif +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET typedef wspp::lib::error_code ErrorCode; typedef wspp::lib::function TimerHandler; +#else + typedef boost::system::error_code ErrorCode; +#endif std::map> groupSubscriptionListByInstrumentGroup(const std::vector& subscriptionList) { std::map> groups; for (const auto& subscription : subscriptionList) { @@ -103,7 +171,7 @@ class MarketDataService : public Service { return groups; } virtual std::string getInstrumentGroup(const Subscription& subscription) { - return this->baseUrl + "|" + subscription.getField() + "|" + subscription.getSerializedOptions() + "|" + subscription.getSerializedCredential(); + return this->baseUrlWs + "|" + subscription.getField() + "|" + subscription.getSerializedOptions() + "|" + subscription.getSerializedCredential(); } void prepareSubscription(const WsConnection& wsConnection, const Subscription& subscription) { auto instrument = subscription.getInstrument(); @@ -128,6 +196,7 @@ class MarketDataService : public Service { CCAPI_LOGGER_TRACE("this->correlationIdListByConnectionIdChannelSymbolIdMap = " + toString(this->correlationIdListByConnectionIdChannelIdSymbolIdMap)); CCAPI_LOGGER_FUNCTION_EXIT; } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET void processMarketDataMessageList(WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived, Event& event, std::vector& marketDataMessageList) { CCAPI_LOGGER_TRACE("marketDataMessageList = " + toString(marketDataMessageList)); @@ -213,15 +282,262 @@ class MarketDataService : public Service { } } } - void onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) override { + void onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) override { + CCAPI_LOGGER_FUNCTION_ENTER; + WsConnection& wsConnection = this->getWsConnectionFromConnectionPtr(this->serviceContextPtr->tlsClientPtr->get_con_from_hdl(hdl)); + if (this->correlationIdByConnectionIdMap.find(wsConnection.id) == this->correlationIdByConnectionIdMap.end()) { + Event event; + std::vector marketDataMessageList; + this->processTextMessage(wsConnection, hdl, textMessage, timeReceived, event, marketDataMessageList); + if (!marketDataMessageList.empty()) { + this->processMarketDataMessageList(wsConnection, hdl, textMessage, timeReceived, event, marketDataMessageList); + } + if (!event.getMessageList().empty()) { + this->eventHandler(event, nullptr); + } + } else { + Event event; + event.setType(Event::Type::SUBSCRIPTION_DATA); + Message message; + message.setType(Message::Type::GENERIC_PUBLIC_SUBSCRIPTION); + message.setTimeReceived(timeReceived); + message.setCorrelationIdList({this->correlationIdByConnectionIdMap.at(wsConnection.id)}); + Element element; + element.insert(CCAPI_WEBSOCKET_MESSAGE_PAYLOAD, textMessage); + message.setElementList({element}); + event.setMessageList({message}); + this->eventHandler(event, nullptr); + } + this->onPongByMethod(PingPongMethod::WEBSOCKET_APPLICATION_LEVEL, hdl, textMessage, timeReceived); + CCAPI_LOGGER_FUNCTION_EXIT; + } + virtual void onIncorrectStatesFound(WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived, + const std::string& exchangeSubscriptionId, std::string const& reason) { + std::string errorMessage = "incorrect states found: connection = " + toString(wsConnection) + ", textMessage = " + textMessage + + ", timeReceived = " + UtilTime::getISOTimestamp(timeReceived) + ", exchangeSubscriptionId = " + exchangeSubscriptionId + + ", reason = " + reason; + CCAPI_LOGGER_ERROR(errorMessage); + ErrorCode ec; + this->close(wsConnection, hdl, websocketpp::close::status::normal, "incorrect states found: " + reason, ec); + if (ec) { + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, "shutdown"); + } + this->shouldProcessRemainingMessageOnClosingByConnectionIdMap[wsConnection.id] = false; + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::INCORRECT_STATE_FOUND, errorMessage); + } + void connect(WsConnection& wsConnection) override { + CCAPI_LOGGER_FUNCTION_ENTER; + Service::connect(wsConnection); + this->instrumentGroupByWsConnectionIdMap.insert(std::pair(wsConnection.id, wsConnection.group)); + CCAPI_LOGGER_DEBUG("this->instrumentGroupByWsConnectionIdMap = " + toString(this->instrumentGroupByWsConnectionIdMap)); + CCAPI_LOGGER_FUNCTION_EXIT; + } + void onOpen(wspp::connection_hdl hdl) override { + CCAPI_LOGGER_FUNCTION_ENTER; + auto now = UtilTime::now(); + Service::onOpen(hdl); + WsConnection& wsConnection = this->getWsConnectionFromConnectionPtr(this->serviceContextPtr->tlsClientPtr->get_con_from_hdl(hdl)); + auto credential = wsConnection.credential; + if (!credential.empty()) { + this->logonToExchange(wsConnection, now, credential); + } else { + this->startSubscribe(wsConnection); + } + } + void onFail_(WsConnection& wsConnection) override { + WsConnection thisWsConnection = wsConnection; + Service::onFail_(wsConnection); + this->instrumentGroupByWsConnectionIdMap.erase(thisWsConnection.id); + } + void clearStates(WsConnection& wsConnection) override { + Service::clearStates(wsConnection); + this->fieldByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->optionMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->subscriptionListByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->correlationIdListByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->channelIdSymbolIdByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); + this->snapshotBidByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->snapshotAskByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->previousConflateSnapshotBidByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->previousConflateSnapshotAskByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->processedInitialTradeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->l2UpdateIsReplaceByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->previousConflateTimeMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + if (this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.find(wsConnection.id) != this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.end()) { + for (const auto& x : this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id)) { + for (const auto& y : x.second) { + y.second->cancel(); + } + } + this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + } + this->openByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->highByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->lowByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->closeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->orderBookChecksumByConnectionIdSymbolIdMap.erase(wsConnection.id); + this->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.erase(wsConnection.id); + if (this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.find(wsConnection.id) != + this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.end()) { + for (const auto& x : this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.at(wsConnection.id)) { + x.second->cancel(); + } + this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); + } + this->orderbookVersionIdByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); + } + void onClose(wspp::connection_hdl hdl) override { + CCAPI_LOGGER_FUNCTION_ENTER; + WsConnection& wsConnection = this->getWsConnectionFromConnectionPtr(this->serviceContextPtr->tlsClientPtr->get_con_from_hdl(hdl)); + this->exchangeSubscriptionIdListByExchangeJsonPayloadIdByConnectionIdMap.erase(wsConnection.id); + this->exchangeJsonPayloadIdByConnectionIdMap.erase(wsConnection.id); + this->instrumentGroupByWsConnectionIdMap.erase(wsConnection.id); + this->correlationIdByConnectionIdMap.erase(wsConnection.id); + Service::onClose(hdl); + } + virtual void subscribeToExchange(const WsConnection& wsConnection) { + CCAPI_LOGGER_INFO("exchange is " + this->exchangeName); + std::vector sendStringList; + if (this->correlationIdByConnectionIdMap.find(wsConnection.id) == this->correlationIdByConnectionIdMap.end()) { + sendStringList = this->createSendStringList(wsConnection); + } else { + auto subscription = wsConnection.subscriptionList.at(0); + sendStringList = std::vector(1, subscription.getRawOptions()); + } + for (const auto& sendString : sendStringList) { + CCAPI_LOGGER_INFO("sendString = " + sendString); + ErrorCode ec; + this->send(wsConnection.hdl, sendString, wspp::frame::opcode::text, ec); + if (ec) { + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "subscribe"); + } + } + } + void startSubscribe(WsConnection& wsConnection) { + auto instrumentGroup = wsConnection.group; + for (const auto& subscription : wsConnection.subscriptionList) { + auto instrument = subscription.getInstrument(); + this->subscriptionStatusByInstrumentGroupInstrumentMap[instrumentGroup][instrument] = Subscription::Status::SUBSCRIBING; + if (subscription.getRawOptions().empty()) { + this->prepareSubscription(wsConnection, subscription); + } else { + this->correlationIdByConnectionIdMap.insert({wsConnection.id, subscription.getCorrelationId()}); + } + } + CCAPI_LOGGER_INFO("about to subscribe to exchange"); + this->subscribeToExchange(wsConnection); + } + virtual void logonToExchange(const WsConnection& wsConnection, const TimePoint& now, const std::map& credential) { + CCAPI_LOGGER_INFO("about to logon to exchange"); + CCAPI_LOGGER_INFO("exchange is " + this->exchangeName); + auto subscriptionList = wsConnection.subscriptionList; + std::vector sendStringList = this->createSendStringListFromSubscriptionList(wsConnection, subscriptionList, now, credential); + for (const auto& sendString : sendStringList) { + CCAPI_LOGGER_INFO("sendString = " + sendString); + ErrorCode ec; + this->send(wsConnection.hdl, sendString, wspp::frame::opcode::text, ec); + if (ec) { + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "subscribe"); + } + } + } +#else + void processMarketDataMessageList(std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessage, const TimePoint& timeReceived, + Event& event, std::vector& marketDataMessageList) { + CCAPI_LOGGER_TRACE("marketDataMessageList = " + toString(marketDataMessageList)); + WsConnection& wsConnection = *wsConnectionPtr; + event.setType(Event::Type::SUBSCRIPTION_DATA); + for (auto& marketDataMessage : marketDataMessageList) { + if (marketDataMessage.type == MarketDataMessage::Type::MARKET_DATA_EVENTS_MARKET_DEPTH || + marketDataMessage.type == MarketDataMessage::Type::MARKET_DATA_EVENTS_TRADE || + marketDataMessage.type == MarketDataMessage::Type::MARKET_DATA_EVENTS_AGG_TRADE) { + if (this->sessionOptions.warnLateEventMaxMilliSeconds > 0 && + std::chrono::duration_cast(timeReceived - marketDataMessage.tp).count() > + this->sessionOptions.warnLateEventMaxMilliSeconds && + marketDataMessage.recapType == MarketDataMessage::RecapType::NONE) { + CCAPI_LOGGER_WARN("late websocket message: timeReceived = " + toString(timeReceived) + ", marketDataMessage.tp = " + toString(marketDataMessage.tp) + + ", wsConnection = " + toString(wsConnection)); + } + + std::string& exchangeSubscriptionId = marketDataMessage.exchangeSubscriptionId; + CCAPI_LOGGER_TRACE("this->channelIdSymbolIdByConnectionIdExchangeSubscriptionIdMap = " + + toString(this->channelIdSymbolIdByConnectionIdExchangeSubscriptionIdMap)); + std::string& channelId = + this->channelIdSymbolIdByConnectionIdExchangeSubscriptionIdMap.at(wsConnection.id).at(exchangeSubscriptionId).at(CCAPI_CHANNEL_ID); + std::string& symbolId = + this->channelIdSymbolIdByConnectionIdExchangeSubscriptionIdMap.at(wsConnection.id).at(exchangeSubscriptionId).at(CCAPI_SYMBOL_ID); + auto& field = this->fieldByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id).at(channelId).at(symbolId); + CCAPI_LOGGER_TRACE("this->optionMapByConnectionIdChannelIdSymbolIdMap = " + toString(this->optionMapByConnectionIdChannelIdSymbolIdMap)); + CCAPI_LOGGER_TRACE("wsConnection = " + toString(wsConnection)); + CCAPI_LOGGER_TRACE("channelId = " + toString(channelId)); + CCAPI_LOGGER_TRACE("symbolId = " + toString(symbolId)); + auto& optionMap = this->optionMapByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id).at(channelId).at(symbolId); + CCAPI_LOGGER_TRACE("optionMap = " + toString(optionMap)); + auto& correlationIdList = this->correlationIdListByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id).at(channelId).at(symbolId); + CCAPI_LOGGER_TRACE("correlationIdList = " + toString(correlationIdList)); + if (marketDataMessage.data.find(MarketDataMessage::DataType::BID) != marketDataMessage.data.end() || + marketDataMessage.data.find(MarketDataMessage::DataType::ASK) != marketDataMessage.data.end()) { + std::map& snapshotBid = this->snapshotBidByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId]; + std::map& snapshotAsk = this->snapshotAskByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId]; + if (this->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId] && + marketDataMessage.recapType == MarketDataMessage::RecapType::NONE) { + this->processOrderBookUpdate(wsConnection, channelId, symbolId, event, marketDataMessage.tp, timeReceived, marketDataMessage.data, field, optionMap, + correlationIdList, snapshotBid, snapshotAsk); + if (this->sessionOptions.enableCheckOrderBookChecksum && + this->orderBookChecksumByConnectionIdSymbolIdMap.find(wsConnection.id) != this->orderBookChecksumByConnectionIdSymbolIdMap.end() && + this->orderBookChecksumByConnectionIdSymbolIdMap.at(wsConnection.id).find(symbolId) != + this->orderBookChecksumByConnectionIdSymbolIdMap.at(wsConnection.id).end()) { + bool shouldProcessRemainingMessage = true; + std::string receivedOrderBookChecksumStr = this->orderBookChecksumByConnectionIdSymbolIdMap[wsConnection.id][symbolId]; + if (!this->checkOrderBookChecksum(snapshotBid, snapshotAsk, receivedOrderBookChecksumStr, shouldProcessRemainingMessage)) { + CCAPI_LOGGER_ERROR("snapshotBid = " + toString(snapshotBid)); + CCAPI_LOGGER_ERROR("snapshotAsk = " + toString(snapshotAsk)); + this->onIncorrectStatesFound(wsConnectionPtr, textMessage, timeReceived, exchangeSubscriptionId, "order book incorrect checksum found"); + } + if (!shouldProcessRemainingMessage) { + return; + } + } + if (this->sessionOptions.enableCheckOrderBookCrossed) { + bool shouldProcessRemainingMessage = true; + if (!this->checkOrderBookCrossed(snapshotBid, snapshotAsk, shouldProcessRemainingMessage)) { + CCAPI_LOGGER_ERROR("lastNToString(snapshotBid, 1) = " + lastNToString(snapshotBid, 1)); + CCAPI_LOGGER_ERROR("firstNToString(snapshotAsk, 1) = " + firstNToString(snapshotAsk, 1)); + this->onIncorrectStatesFound(wsConnectionPtr, textMessage, timeReceived, exchangeSubscriptionId, "order book crossed market found"); + } + if (!shouldProcessRemainingMessage) { + return; + } + } + } else if (marketDataMessage.recapType == MarketDataMessage::RecapType::SOLICITED) { + this->processOrderBookInitial(wsConnection, channelId, symbolId, event, marketDataMessage.tp, timeReceived, marketDataMessage.data, field, + optionMap, correlationIdList, snapshotBid, snapshotAsk); + } + CCAPI_LOGGER_TRACE("snapshotBid.size() = " + toString(snapshotBid.size())); + CCAPI_LOGGER_TRACE("snapshotAsk.size() = " + toString(snapshotAsk.size())); + } + if (marketDataMessage.data.find(MarketDataMessage::DataType::TRADE) != marketDataMessage.data.end() || + marketDataMessage.data.find(MarketDataMessage::DataType::AGG_TRADE) != marketDataMessage.data.end()) { + bool isSolicited = marketDataMessage.recapType == MarketDataMessage::RecapType::SOLICITED; + this->processTrade(wsConnection, channelId, symbolId, event, marketDataMessage.tp, timeReceived, marketDataMessage.data, field, optionMap, + correlationIdList, isSolicited); + } + } else { + CCAPI_LOGGER_WARN("websocket event type is unknown for " + toString(marketDataMessage)); + CCAPI_LOGGER_WARN("textMessage is " + std::string(textMessage)); + } + } + } + void onTextMessage(std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessage, const TimePoint& timeReceived) override { CCAPI_LOGGER_FUNCTION_ENTER; - WsConnection& wsConnection = this->getWsConnectionFromConnectionPtr(this->serviceContextPtr->tlsClientPtr->get_con_from_hdl(hdl)); - if (this->correlationIdByConnectionIdMap.find(wsConnection.id) == this->correlationIdByConnectionIdMap.end()) { + if (this->correlationIdByConnectionIdMap.find(wsConnectionPtr->id) == this->correlationIdByConnectionIdMap.end()) { Event event; std::vector marketDataMessageList; - this->processTextMessage(wsConnection, hdl, textMessage, timeReceived, event, marketDataMessageList); + this->processTextMessage(wsConnectionPtr, textMessage, timeReceived, event, marketDataMessageList); if (!marketDataMessageList.empty()) { - this->processMarketDataMessageList(wsConnection, hdl, textMessage, timeReceived, event, marketDataMessageList); + this->processMarketDataMessageList(wsConnectionPtr, textMessage, timeReceived, event, marketDataMessageList); } if (!event.getMessageList().empty()) { this->eventHandler(event, nullptr); @@ -232,16 +548,157 @@ class MarketDataService : public Service { Message message; message.setType(Message::Type::GENERIC_PUBLIC_SUBSCRIPTION); message.setTimeReceived(timeReceived); - message.setCorrelationIdList({this->correlationIdByConnectionIdMap.at(wsConnection.id)}); + message.setCorrelationIdList({this->correlationIdByConnectionIdMap.at(wsConnectionPtr->id)}); Element element; - element.insert(CCAPI_WEBSOCKET_MESSAGE_PAYLOAD, textMessage); + element.insert(CCAPI_WEBSOCKET_MESSAGE_PAYLOAD, std::string(textMessage)); message.setElementList({element}); event.setMessageList({message}); this->eventHandler(event, nullptr); } - this->onPongByMethod(PingPongMethod::WEBSOCKET_APPLICATION_LEVEL, hdl, textMessage, timeReceived); + this->onPongByMethod(PingPongMethod::WEBSOCKET_APPLICATION_LEVEL, wsConnectionPtr, timeReceived); + CCAPI_LOGGER_FUNCTION_EXIT; + } + virtual void onIncorrectStatesFound(std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessage, const TimePoint& timeReceived, + const std::string& exchangeSubscriptionId, std::string const& reason) { + WsConnection& wsConnection = *wsConnectionPtr; + std::string errorMessage = "incorrect states found: connection = " + toString(wsConnection) + ", textMessage = " + std::string(textMessage) + + ", timeReceived = " + UtilTime::getISOTimestamp(timeReceived) + ", exchangeSubscriptionId = " + exchangeSubscriptionId + + ", reason = " + reason; + CCAPI_LOGGER_ERROR(errorMessage); + ErrorCode ec; + this->close(wsConnectionPtr, beast::websocket::close_code::normal, + beast::websocket::close_reason(beast::websocket::close_code::normal, "incorrect states found: " + reason), ec); + if (ec) { + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, "shutdown"); + } + this->shouldProcessRemainingMessageOnClosingByConnectionIdMap[wsConnection.id] = false; + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::INCORRECT_STATE_FOUND, errorMessage); + } + void connect(std::shared_ptr wsConnectionPtr) override { + CCAPI_LOGGER_FUNCTION_ENTER; + Service::connect(wsConnectionPtr); + this->instrumentGroupByWsConnectionIdMap.insert(std::pair(wsConnectionPtr->id, wsConnectionPtr->group)); + CCAPI_LOGGER_DEBUG("this->instrumentGroupByWsConnectionIdMap = " + toString(this->instrumentGroupByWsConnectionIdMap)); CCAPI_LOGGER_FUNCTION_EXIT; } + void onOpen(std::shared_ptr wsConnectionPtr) override { + CCAPI_LOGGER_FUNCTION_ENTER; + WsConnection& wsConnection = *wsConnectionPtr; + auto now = UtilTime::now(); + Service::onOpen(wsConnectionPtr); + WsConnection thisWsConnection = wsConnection; + auto credential = wsConnection.credential; + if (!credential.empty()) { + this->logonToExchange(wsConnectionPtr, now, credential); + } else { + this->startSubscribe(wsConnectionPtr); + } + } + void onFail_(std::shared_ptr wsConnectionPtr) override { + WsConnection& wsConnection = *wsConnectionPtr; + WsConnection thisWsConnection = wsConnection; + Service::onFail_(wsConnectionPtr); + this->instrumentGroupByWsConnectionIdMap.erase(thisWsConnection.id); + } + void clearStates(std::shared_ptr wsConnectionPtr) override { + WsConnection& wsConnection = *wsConnectionPtr; + Service::clearStates(wsConnectionPtr); + this->fieldByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->optionMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->subscriptionListByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->correlationIdListByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->channelIdSymbolIdByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); + this->snapshotBidByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->snapshotAskByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->previousConflateSnapshotBidByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->previousConflateSnapshotAskByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->processedInitialTradeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->l2UpdateIsReplaceByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->previousConflateTimeMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + if (this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.find(wsConnection.id) != this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.end()) { + for (const auto& x : this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id)) { + for (const auto& y : x.second) { + y.second->cancel(); + } + } + this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + } + this->openByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->highByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->lowByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->closeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); + this->orderBookChecksumByConnectionIdSymbolIdMap.erase(wsConnection.id); + this->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.erase(wsConnection.id); + if (this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.find(wsConnection.id) != + this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.end()) { + for (const auto& x : this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.at(wsConnection.id)) { + x.second->cancel(); + } + this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); + } + this->orderbookVersionIdByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); + } + virtual void onClose(std::shared_ptr wsConnectionPtr, ErrorCode ec) override { + CCAPI_LOGGER_FUNCTION_ENTER; + WsConnection& wsConnection = *wsConnectionPtr; + this->exchangeSubscriptionIdListByExchangeJsonPayloadIdByConnectionIdMap.erase(wsConnection.id); + this->exchangeJsonPayloadIdByConnectionIdMap.erase(wsConnection.id); + this->instrumentGroupByWsConnectionIdMap.erase(wsConnection.id); + this->correlationIdByConnectionIdMap.erase(wsConnection.id); + Service::onClose(wsConnectionPtr, ec); + } + virtual void subscribeToExchange(std::shared_ptr wsConnectionPtr) { + WsConnection& wsConnection = *wsConnectionPtr; + CCAPI_LOGGER_INFO("exchange is " + this->exchangeName); + std::vector sendStringList; + if (this->correlationIdByConnectionIdMap.find(wsConnection.id) == this->correlationIdByConnectionIdMap.end()) { + sendStringList = this->createSendStringList(wsConnection); + } else { + auto subscription = wsConnection.subscriptionList.at(0); + sendStringList = std::vector(1, subscription.getRawOptions()); + } + for (const auto& sendString : sendStringList) { + CCAPI_LOGGER_INFO("sendString = " + sendString); + ErrorCode ec; + this->send(wsConnectionPtr, sendString, ec); + if (ec) { + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "subscribe"); + } + } + } + void startSubscribe(std::shared_ptr wsConnectionPtr) { + WsConnection& wsConnection = *wsConnectionPtr; + auto instrumentGroup = wsConnection.group; + for (const auto& subscription : wsConnection.subscriptionList) { + auto instrument = subscription.getInstrument(); + this->subscriptionStatusByInstrumentGroupInstrumentMap[instrumentGroup][instrument] = Subscription::Status::SUBSCRIBING; + if (subscription.getRawOptions().empty()) { + this->prepareSubscription(wsConnection, subscription); + } else { + this->correlationIdByConnectionIdMap.insert({wsConnection.id, subscription.getCorrelationId()}); + } + } + CCAPI_LOGGER_INFO("about to subscribe to exchange"); + this->subscribeToExchange(wsConnectionPtr); + } + virtual void logonToExchange(std::shared_ptr wsConnectionPtr, const TimePoint& now, const std::map& credential) { + WsConnection& wsConnection = *wsConnectionPtr; + CCAPI_LOGGER_INFO("about to logon to exchange"); + CCAPI_LOGGER_INFO("exchange is " + this->exchangeName); + auto subscriptionList = wsConnection.subscriptionList; + std::vector sendStringList = this->createSendStringListFromSubscriptionList(wsConnection, subscriptionList, now, credential); + for (const auto& sendString : sendStringList) { + CCAPI_LOGGER_INFO("sendString = " + sendString); + ErrorCode ec; + this->send(wsConnectionPtr, sendString, ec); + if (ec) { + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "subscribe"); + } + } + } +#endif void updateOrderBook(std::map& snapshot, const Decimal& price, const std::string& size, bool sizeMayHaveTrailingZero = false) { auto it = snapshot.find(price); if (it == snapshot.end()) { @@ -862,20 +1319,6 @@ class MarketDataService : public Service { } return true; } - virtual void onIncorrectStatesFound(WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived, - const std::string& exchangeSubscriptionId, std::string const& reason) { - std::string errorMessage = "incorrect states found: connection = " + toString(wsConnection) + ", textMessage = " + textMessage + - ", timeReceived = " + UtilTime::getISOTimestamp(timeReceived) + ", exchangeSubscriptionId = " + exchangeSubscriptionId + - ", reason = " + reason; - CCAPI_LOGGER_ERROR(errorMessage); - ErrorCode ec; - this->close(wsConnection, hdl, websocketpp::close::status::normal, "incorrect states found: " + reason, ec); - if (ec) { - this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, "shutdown"); - } - this->shouldProcessRemainingMessageOnClosingByConnectionIdMap[wsConnection.id] = false; - this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::INCORRECT_STATE_FOUND, errorMessage); - } int calculateMarketDepthSubscribedToExchange(int depthWanted, std::vector availableMarketDepth) { int i = ceilSearch(availableMarketDepth, 0, availableMarketDepth.size(), depthWanted); if (i < 0) { @@ -914,15 +1357,15 @@ class MarketDataService : public Service { } } if (waitMilliseconds > 0) { - this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId] = this->serviceContextPtr->tlsClientPtr->set_timer( - waitMilliseconds, + TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(waitMilliseconds))); + timerPtr->async_wait( [wsConnection, channelId, symbolId, field, optionMap, correlationIdList, previousConflateTp, interval, gracePeriod, this](ErrorCode const& ec) { if (this->wsConnectionByIdMap.find(wsConnection.id) != this->wsConnectionByIdMap.end()) { if (ec) { CCAPI_LOGGER_ERROR("wsConnection = " + toString(wsConnection) + ", conflate timer error: " + ec.message()); this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); } else { - if (this->wsConnectionByIdMap.at(wsConnection.id).status == WsConnection::Status::OPEN) { + if (this->wsConnectionByIdMap.at(wsConnection.id)->status == WsConnection::Status::OPEN) { auto conflateTp = previousConflateTp + interval; if (conflateTp > this->previousConflateTimeMapByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id).at(channelId).at(symbolId)) { Event event; @@ -964,28 +1407,11 @@ class MarketDataService : public Service { } } }); + this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId] = timerPtr; } } CCAPI_LOGGER_FUNCTION_EXIT; } - virtual void subscribeToExchange(const WsConnection& wsConnection) { - CCAPI_LOGGER_INFO("exchange is " + this->exchangeName); - std::vector sendStringList; - if (this->correlationIdByConnectionIdMap.find(wsConnection.id) == this->correlationIdByConnectionIdMap.end()) { - sendStringList = this->createSendStringList(wsConnection); - } else { - auto subscription = wsConnection.subscriptionList.at(0); - sendStringList = std::vector(1, subscription.getRawOptions()); - } - for (const auto& sendString : sendStringList) { - CCAPI_LOGGER_INFO("sendString = " + sendString); - ErrorCode ec; - this->send(wsConnection.hdl, sendString, wspp::frame::opcode::text, ec); - if (ec) { - this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "subscribe"); - } - } - } void processSuccessfulTextMessageRest(int statusCode, const Request& request, const std::string& textMessage, const TimePoint& timeReceived, Queue* eventQueuePtr) override { CCAPI_LOGGER_FUNCTION_ENTER; @@ -1063,106 +1489,6 @@ class MarketDataService : public Service { messageList.emplace_back(std::move(message)); event.addMessages(messageList); } - void connect(WsConnection& wsConnection) override { - CCAPI_LOGGER_FUNCTION_ENTER; - Service::connect(wsConnection); - this->instrumentGroupByWsConnectionIdMap.insert(std::pair(wsConnection.id, wsConnection.group)); - CCAPI_LOGGER_DEBUG("this->instrumentGroupByWsConnectionIdMap = " + toString(this->instrumentGroupByWsConnectionIdMap)); - CCAPI_LOGGER_FUNCTION_EXIT; - } - void onOpen(wspp::connection_hdl hdl) override { - CCAPI_LOGGER_FUNCTION_ENTER; - auto now = UtilTime::now(); - Service::onOpen(hdl); - WsConnection& wsConnection = this->getWsConnectionFromConnectionPtr(this->serviceContextPtr->tlsClientPtr->get_con_from_hdl(hdl)); - auto credential = wsConnection.credential; - if (!credential.empty()) { - this->logonToExchange(wsConnection, now, credential); - } else { - this->startSubscribe(wsConnection); - } - } - void startSubscribe(WsConnection& wsConnection) { - auto instrumentGroup = wsConnection.group; - for (const auto& subscription : wsConnection.subscriptionList) { - auto instrument = subscription.getInstrument(); - this->subscriptionStatusByInstrumentGroupInstrumentMap[instrumentGroup][instrument] = Subscription::Status::SUBSCRIBING; - if (subscription.getRawOptions().empty()) { - this->prepareSubscription(wsConnection, subscription); - } else { - this->correlationIdByConnectionIdMap.insert({wsConnection.id, subscription.getCorrelationId()}); - } - } - CCAPI_LOGGER_INFO("about to subscribe to exchange"); - this->subscribeToExchange(wsConnection); - } - virtual void logonToExchange(const WsConnection& wsConnection, const TimePoint& now, const std::map& credential) { - CCAPI_LOGGER_INFO("about to logon to exchange"); - CCAPI_LOGGER_INFO("exchange is " + this->exchangeName); - auto subscriptionList = wsConnection.subscriptionList; - std::vector sendStringList = this->createSendStringListFromSubscriptionList(wsConnection, subscriptionList, now, credential); - for (const auto& sendString : sendStringList) { - CCAPI_LOGGER_INFO("sendString = " + sendString); - ErrorCode ec; - this->send(wsConnection.hdl, sendString, wspp::frame::opcode::text, ec); - if (ec) { - this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "subscribe"); - } - } - } - void onFail_(WsConnection& wsConnection) override { - WsConnection thisWsConnection = wsConnection; - Service::onFail_(wsConnection); - this->instrumentGroupByWsConnectionIdMap.erase(thisWsConnection.id); - } - void clearStates(WsConnection& wsConnection) override { - Service::clearStates(wsConnection); - this->fieldByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->optionMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->subscriptionListByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->correlationIdListByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->channelIdSymbolIdByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); - this->snapshotBidByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->snapshotAskByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->previousConflateSnapshotBidByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->previousConflateSnapshotAskByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->processedInitialTradeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->l2UpdateIsReplaceByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->previousConflateTimeMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - if (this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.find(wsConnection.id) != this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.end()) { - for (const auto& x : this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id)) { - for (const auto& y : x.second) { - y.second->cancel(); - } - } - this->conflateTimerMapByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - } - this->openByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->highByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->lowByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->closeByConnectionIdChannelIdSymbolIdMap.erase(wsConnection.id); - this->orderBookChecksumByConnectionIdSymbolIdMap.erase(wsConnection.id); - this->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap.erase(wsConnection.id); - if (this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.find(wsConnection.id) != - this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.end()) { - for (const auto& x : this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.at(wsConnection.id)) { - x.second->cancel(); - } - this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); - } - this->orderbookVersionIdByConnectionIdExchangeSubscriptionIdMap.erase(wsConnection.id); - } - void onClose(wspp::connection_hdl hdl) override { - CCAPI_LOGGER_FUNCTION_ENTER; - WsConnection& wsConnection = this->getWsConnectionFromConnectionPtr(this->serviceContextPtr->tlsClientPtr->get_con_from_hdl(hdl)); - this->exchangeSubscriptionIdListByExchangeJsonPayloadIdByConnectionIdMap.erase(wsConnection.id); - this->exchangeJsonPayloadIdByConnectionIdMap.erase(wsConnection.id); - this->instrumentGroupByWsConnectionIdMap.erase(wsConnection.id); - this->correlationIdByConnectionIdMap.erase(wsConnection.id); - Service::onClose(hdl); - } void convertRequestForRestGenericPublicRequest(http::request& req, const Request& request, const TimePoint& now, const std::string& symbolId, const std::map& credential) { const std::map param = request.getFirstParamWithDefault(); @@ -1197,16 +1523,16 @@ class MarketDataService : public Service { if (this->marketDataMessageDataBufferByConnectionIdExchangeSubscriptionIdVersionIdMap[wsConnection.id][exchangeSubscriptionId].empty()) { int delayMilliSeconds = std::stoi(optionMap.at(CCAPI_FETCH_MARKET_DEPTH_INITIAL_SNAPSHOT_DELAY_MILLISECONDS)); if (delayMilliSeconds > 0) { - this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnection.id][exchangeSubscriptionId] = - this->serviceContextPtr->tlsClientPtr->set_timer(delayMilliSeconds, - [wsConnection, exchangeSubscriptionId, delayMilliSeconds, that = this](ErrorCode const& ec) { - auto now = UtilTime::now(); - if (ec) { - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); - } else { - that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, delayMilliSeconds); - } - }); + TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(delayMilliSeconds))); + timerPtr->async_wait([wsConnection, exchangeSubscriptionId, delayMilliSeconds, that = this](ErrorCode const& ec) { + auto now = UtilTime::now(); + if (ec) { + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, delayMilliSeconds); + } + }); + this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnection.id][exchangeSubscriptionId] = timerPtr; } else { this->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, delayMilliSeconds); } @@ -1218,15 +1544,15 @@ class MarketDataService : public Service { void buildOrderBookInitialOnFail(const WsConnection& wsConnection, const std::string& exchangeSubscriptionId, long delayMilliSeconds) { auto thisDelayMilliSeconds = delayMilliSeconds * 2; if (thisDelayMilliSeconds > 0) { - this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnection.id][exchangeSubscriptionId] = - this->serviceContextPtr->tlsClientPtr->set_timer(thisDelayMilliSeconds, - [wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds, that = this](ErrorCode const& ec) { - if (ec) { - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); - } else { - that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds); - } - }); + TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(thisDelayMilliSeconds))); + timerPtr->async_wait([wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds, that = this](ErrorCode const& ec) { + if (ec) { + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds); + } + }); + this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnection.id][exchangeSubscriptionId] = timerPtr; } else { this->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds); } @@ -1402,8 +1728,13 @@ class MarketDataService : public Service { } virtual void convertTextMessageToMarketDataMessage(const Request& request, const std::string& textMessage, const TimePoint& timeReceived, Event& event, std::vector& marketDataMessageList) {} +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET virtual void processTextMessage(WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived, Event& event, std::vector& marketDataMessageList) {} +#else + virtual void processTextMessage(std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessageView, const TimePoint& timeReceived, + Event& event, std::vector& marketDataMessageList) {} +#endif virtual std::string calculateOrderBookChecksum(const std::map& snapshotBid, const std::map& snapshotAsk) { return {}; } diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h index d60eefc2..6126da33 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h @@ -10,7 +10,7 @@ class MarketDataServiceAscendex : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_ASCENDEX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/api/pro/v1/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/api/pro/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h index 5ae4d6a8..1096a48a 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h @@ -10,7 +10,7 @@ class MarketDataServiceBinance : public MarketDataServiceBinanceBase { std::shared_ptr serviceContextPtr) : MarketDataServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h index bfd122eb..f85ec135 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h @@ -10,7 +10,7 @@ class MarketDataServiceBinanceCoinFutures : public MarketDataServiceBinanceDeriv std::shared_ptr serviceContextPtr) : MarketDataServiceBinanceDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_COIN_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h index bd3845dc..f0927dc8 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h @@ -10,7 +10,7 @@ class MarketDataServiceBinanceUs : public MarketDataServiceBinanceBase { std::shared_ptr serviceContextPtr) : MarketDataServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_US; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h index a7b8ea4a..6b685b4c 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h @@ -10,7 +10,7 @@ class MarketDataServiceBinanceUsdsFutures : public MarketDataServiceBinanceDeriv std::shared_ptr serviceContextPtr) : MarketDataServiceBinanceDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_USDS_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h index 34309003..d433fb96 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h @@ -10,7 +10,7 @@ class MarketDataServiceBitfinex : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITFINEX; - this->baseUrl = std::string(CCAPI_BITFINEX_PUBLIC_URL_WS_BASE) + "/ws/2"; + this->baseUrlWs = std::string(CCAPI_BITFINEX_PUBLIC_URL_WS_BASE) + "/ws/2"; this->baseUrlRest = CCAPI_BITFINEX_PUBLIC_URL_REST_BASE; this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h index ea53e7d2..954d48b8 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h @@ -10,7 +10,7 @@ class MarketDataServiceBitget : public MarketDataServiceBitgetBase { std::shared_ptr serviceContextPtr) : MarketDataServiceBitgetBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITGET; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/v1/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h index 32f24efc..4a7b9281 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h @@ -10,7 +10,7 @@ class MarketDataServiceBitgetFutures : public MarketDataServiceBitgetBase { std::shared_ptr serviceContextPtr) : MarketDataServiceBitgetBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITGET_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/mix/v1/stream"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/mix/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h index 4dda7d70..67105591 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h @@ -10,7 +10,7 @@ class MarketDataServiceBitmart : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITMART; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/api?protocol=1.1"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/api?protocol=1.1"; // this->needDecompressWebsocketMessage = true; // ErrorCode ec = this->inflater.init(false); // if (ec) { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h index 03398994..4b20b7d3 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h @@ -10,7 +10,7 @@ class MarketDataServiceBitmex : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITMEX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/realtime"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/realtime"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h index 35914f6a..d29aa447 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h @@ -10,7 +10,7 @@ class MarketDataServiceBitstamp : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITSTAMP; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->enableCheckPingPongWebsocketApplicationLevel = false; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h index 03c737c0..9ac68d85 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h @@ -10,7 +10,7 @@ class MarketDataServiceBybit : public MarketDataServiceBybitBase { std::shared_ptr serviceContextPtr) : MarketDataServiceBybitBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BYBIT; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/public/v3"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/public/v3"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h b/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h index b26e1301..a1b93111 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h @@ -10,7 +10,7 @@ class MarketDataServiceBybitDerivatives : public MarketDataServiceBybitBase { std::shared_ptr serviceContextPtr) : MarketDataServiceBybitBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BYBIT_DERIVATIVES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/{instrumentTypeSubstitute}/public/v3"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/{instrumentTypeSubstitute}/public/v3"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h index 369ae519..4fc7c1bf 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h @@ -10,7 +10,7 @@ class MarketDataServiceCoinbase : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_COINBASE; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { @@ -65,8 +65,20 @@ class MarketDataServiceCoinbase : public MarketDataService { sendStringList.push_back(sendString); return sendStringList; } - void processTextMessage(WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived, Event& event, - std::vector& marketDataMessageList) override { + void processTextMessage( +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage +#else + std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessageView +#endif + , + const TimePoint& timeReceived, Event& event, std::vector& marketDataMessageList) override { + +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else + WsConnection& wsConnection = *wsConnectionPtr; + std::string textMessage(textMessageView); +#endif rj::Document document; document.Parse(textMessage.c_str()); auto type = std::string(document["type"].GetString()); diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h index 8ceb298b..51a89dbd 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h @@ -10,7 +10,7 @@ class MarketDataServiceCryptocom : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_CRYPTOCOM; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v2/market"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v2/market"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h index fa5a40bc..d902cfba 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h @@ -10,7 +10,7 @@ class MarketDataServiceDeribit : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_DERIBIT; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/api/v2"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/api/v2"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h b/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h index a05f7417..7759f6c5 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h @@ -10,7 +10,7 @@ class MarketDataServiceErisx : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_ERISX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); // this->convertNumberToStringInJsonRegex = std::regex("(\\[|,|\":)(-?\\d+\\.?\\d*)"); } virtual ~MarketDataServiceErisx() {} diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h index e8980574..56f4309e 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h @@ -10,7 +10,7 @@ class MarketDataServiceFtx : public MarketDataServiceFtxBase { std::shared_ptr serviceContextPtr) : MarketDataServiceFtxBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_FTX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h index dbbc92e1..6683aa39 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h @@ -10,7 +10,7 @@ class MarketDataServiceFtxUs : public MarketDataServiceFtxBase { std::shared_ptr serviceContextPtr) : MarketDataServiceFtxBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_FTX_US; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h index c6444ec9..0221250b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h @@ -10,7 +10,7 @@ class MarketDataServiceGateio : public MarketDataServiceGateioBase { std::shared_ptr serviceContextPtr) : MarketDataServiceGateioBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GATEIO; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v4/"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v4/"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h index 10840458..12736fd7 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h @@ -10,7 +10,7 @@ class MarketDataServiceGateioPerpetualFutures : public MarketDataServiceGateioBa std::shared_ptr serviceContextPtr) : MarketDataServiceGateioBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v4/ws/"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v4/ws/"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { @@ -33,7 +33,7 @@ class MarketDataServiceGateioPerpetualFutures : public MarketDataServiceGateioBa virtual ~MarketDataServiceGateioPerpetualFutures() {} std::string getInstrumentGroup(const Subscription& subscription) override { auto instrument = subscription.getInstrument(); - std::string url(this->baseUrl); + std::string url(this->baseUrlWs); if (UtilString::endsWith(instrument, "_USD")) { url += "btc"; } else if (UtilString::endsWith(instrument, "_USDT")) { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h index 0300d6c3..9b0e5504 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h @@ -10,7 +10,7 @@ class MarketDataServiceGemini : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GEMINI; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v1/marketdata"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v1/marketdata"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { @@ -154,7 +154,7 @@ class MarketDataServiceGemini : public MarketDataService { auto field = subscription.getField(); auto parameterList = UtilString::split(this->sessionConfigs.getExchangeFieldWebsocketChannelMap().at(this->exchangeName).at(field), ","); std::set parameterSet(parameterList.begin(), parameterList.end()); - std::string url = this->baseUrl + "/" + symbolId; + std::string url = this->baseUrlWs + "/" + symbolId; url += "?"; if ((parameterSet.find(CCAPI_WEBSOCKET_GEMINI_PARAMETER_BIDS) != parameterSet.end() || parameterSet.find(CCAPI_WEBSOCKET_GEMINI_PARAMETER_OFFERS) != parameterSet.end())) { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h index db02922b..e9811b24 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h @@ -10,7 +10,7 @@ class MarketDataServiceHuobi : public MarketDataServiceHuobiBase { std::shared_ptr serviceContextPtr) : MarketDataServiceHuobiBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h index 41d9abc7..e35b7e9a 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h @@ -86,7 +86,7 @@ class MarketDataServiceHuobiBase : public MarketDataService { return sendStringList; } std::string getInstrumentGroup(const Subscription& subscription) override { - auto url = this->baseUrl; + auto url = this->baseUrlWs; auto field = subscription.getField(); if (!this->isDerivatives) { if (field == CCAPI_TRADE || field == CCAPI_MARKET_DEPTH || field == CCAPI_GENERIC_PUBLIC_SUBSCRIPTION) { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h index 3bdd7367..c535631e 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h @@ -10,7 +10,7 @@ class MarketDataServiceHuobiCoinSwap : public MarketDataServiceHuobiDerivativesB std::shared_ptr serviceContextPtr) : MarketDataServiceHuobiDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI_COIN_SWAP; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/swap-ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/swap-ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h index 70021966..14e6241c 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h @@ -10,7 +10,7 @@ class MarketDataServiceHuobiUsdtSwap : public MarketDataServiceHuobiDerivativesB std::shared_ptr serviceContextPtr) : MarketDataServiceHuobiDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI_USDT_SWAP; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/linear-swap-ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/linear-swap-ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h index 35726c31..8f2d6dae 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h @@ -10,7 +10,7 @@ class MarketDataServiceKraken : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KRAKEN; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h index 8d56d15f..d0f8fe2c 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h @@ -10,7 +10,7 @@ class MarketDataServiceKrakenFutures : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KRAKEN_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v1"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v1"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h index 3b1a57d5..38e3a947 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h @@ -10,7 +10,7 @@ class MarketDataServiceKucoin : public MarketDataServiceKucoinBase { std::shared_ptr serviceContextPtr) : MarketDataServiceKucoinBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KUCOIN; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h index 2b04e0f4..8eeb1f59 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h @@ -10,7 +10,7 @@ class MarketDataServiceKucoinFutures : public MarketDataServiceKucoinBase { std::shared_ptr serviceContextPtr) : MarketDataServiceKucoinBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KUCOIN_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h index d60d2f0f..2d4349cd 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h @@ -10,7 +10,7 @@ class MarketDataServiceMexc : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_MEXC; - this->baseUrl = std::string(CCAPI_MEXC_URL_WS_BASE) + "/ws"; + this->baseUrlWs = std::string(CCAPI_MEXC_URL_WS_BASE) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h index a1aff36b..5918662b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h @@ -10,7 +10,7 @@ class MarketDataServiceMexcFutures : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_MEXC_FUTURES; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h index 84927143..f15d622c 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h @@ -10,7 +10,7 @@ class MarketDataServiceOkx : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_OKX; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + CCAPI_OKX_PUBLIC_WS_PATH; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + CCAPI_OKX_PUBLIC_WS_PATH; // this->needDecompressWebsocketMessage = true; // ErrorCode ec = this->inflater.init(false); // if (ec) { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h index eb5a63c5..848c4974 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h @@ -10,7 +10,7 @@ class MarketDataServiceWhitebit : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_WHITEBIT; - this->baseUrl = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); try { diff --git a/include/ccapi_cpp/service/ccapi_service.h b/include/ccapi_cpp/service/ccapi_service.h index a24a2c81..a7f7dcff 100644 --- a/include/ccapi_cpp/service/ccapi_service.h +++ b/include/ccapi_cpp/service/ccapi_service.h @@ -13,6 +13,9 @@ #ifndef RAPIDJSON_PARSE_ERROR_NORETURN #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) throw std::runtime_error(#parseErrorCode) #endif +#ifndef CCAPI_WEBSOCKET_WRITE_BUFFER_SIZE +#define CCAPI_WEBSOCKET_WRITE_BUFFER_SIZE 1 << 20 +#endif #include #include "boost/asio/strand.hpp" @@ -28,11 +31,16 @@ #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" // clang-format off +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET #include "websocketpp/config/boost_config.hpp" #include "websocketpp/client.hpp" #include "websocketpp/common/connection_hdl.hpp" #include "websocketpp/config/asio_client.hpp" +#else +#include "boost/beast/websocket.hpp" +#endif // clang-format on + #if defined(CCAPI_ENABLE_SERVICE_MARKET_DATA) && \ (defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP)) || \ defined(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) && \ @@ -58,7 +66,9 @@ namespace http = beast::http; namespace net = boost::asio; namespace ssl = boost::asio::ssl; using tcp = boost::asio::ip::tcp; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET namespace wspp = websocketpp; +#endif namespace rj = rapidjson; namespace ccapi { /** @@ -67,8 +77,12 @@ namespace ccapi { */ class Service : public std::enable_shared_from_this { public: - typedef wspp::lib::shared_ptr ServiceContextPtr; + typedef std::shared_ptr ServiceContextPtr; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET typedef wspp::lib::error_code ErrorCode; +#else + typedef boost::system::error_code ErrorCode; // a.k.a. beast::error_code +#endif enum class PingPongMethod { WEBSOCKET_PROTOCOL_LEVEL, WEBSOCKET_APPLICATION_LEVEL, @@ -98,11 +112,12 @@ class Service : public std::enable_shared_from_this { sessionConfigs(sessionConfigs), serviceContextPtr(serviceContextPtr), resolver(*serviceContextPtr->ioContextPtr), + resolverWs(*serviceContextPtr->ioContextPtr), httpConnectionPool(sessionOptions.httpConnectionPoolMaxSize) { this->enableCheckPingPongWebsocketProtocolLevel = this->sessionOptions.enableCheckPingPongWebsocketProtocolLevel; this->enableCheckPingPongWebsocketApplicationLevel = this->sessionOptions.enableCheckPingPongWebsocketApplicationLevel; - this->pingIntervalMilliSecondsByMethodMap[PingPongMethod::WEBSOCKET_PROTOCOL_LEVEL] = sessionOptions.pingWebsocketProtocolLevelIntervalMilliSeconds; - this->pongTimeoutMilliSecondsByMethodMap[PingPongMethod::WEBSOCKET_PROTOCOL_LEVEL] = sessionOptions.pongWebsocketProtocolLevelTimeoutMilliSeconds; + // this->pingIntervalMilliSecondsByMethodMap[PingPongMethod::WEBSOCKET_PROTOCOL_LEVEL] = sessionOptions.pingWebsocketProtocolLevelIntervalMilliSeconds; + // this->pongTimeoutMilliSecondsByMethodMap[PingPongMethod::WEBSOCKET_PROTOCOL_LEVEL] = sessionOptions.pongWebsocketProtocolLevelTimeoutMilliSeconds; this->pingIntervalMilliSecondsByMethodMap[PingPongMethod::WEBSOCKET_APPLICATION_LEVEL] = sessionOptions.pingWebsocketApplicationLevelIntervalMilliSeconds; this->pongTimeoutMilliSecondsByMethodMap[PingPongMethod::WEBSOCKET_APPLICATION_LEVEL] = sessionOptions.pongWebsocketApplicationLevelTimeoutMilliSeconds; this->pingIntervalMilliSecondsByMethodMap[PingPongMethod::FIX_PROTOCOL_LEVEL] = sessionOptions.heartbeatFixIntervalMilliSeconds; @@ -134,13 +149,22 @@ class Service : public std::enable_shared_from_this { sendRequestDelayTimerByCorrelationIdMap.clear(); this->shouldContinue = false; for (const auto& x : this->wsConnectionByIdMap) { - auto wsConnection = x.second; ErrorCode ec; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + auto wsConnection = x.second; this->close(wsConnection, wsConnection.hdl, websocketpp::close::status::normal, "stop", ec); +#else + auto wsConnectionPtr = x.second; + this->close(wsConnectionPtr, beast::websocket::close_code::normal, beast::websocket::close_reason("stop"), ec); +#endif if (ec) { this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "shutdown"); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET this->shouldProcessRemainingMessageOnClosingByConnectionIdMap[wsConnection.id] = false; +#else + this->shouldProcessRemainingMessageOnClosingByConnectionIdMap[wsConnectionPtr->id] = false; +#endif } } virtual void convertRequestForRestCustom(http::request& req, const Request& request, const TimePoint& now, const std::string& symbolId, @@ -189,19 +213,20 @@ class Service : public std::enable_shared_from_this { std::shared_ptr> promisePtr(promisePtrRaw); HttpRetry retry(0, 0, "", promisePtr); if (delayMilliSeconds > 0) { - this->sendRequestDelayTimerByCorrelationIdMap[request.getCorrelationId()] = this->serviceContextPtr->tlsClientPtr->set_timer( - delayMilliSeconds, [that = shared_from_this(), request, req, retry, eventQueuePtr](ErrorCode const& ec) mutable { - if (ec) { - CCAPI_LOGGER_ERROR("request = " + toString(request) + ", sendRequest timer error: " + ec.message()); - that->onError(Event::Type::REQUEST_STATUS, Message::Type::GENERIC_ERROR, ec, "timer", {request.getCorrelationId()}, eventQueuePtr); - } else { - auto thatReq = req; - auto now = UtilTime::now(); - request.setTimeSent(now); - that->tryRequest(request, thatReq, retry, eventQueuePtr); - } - that->sendRequestDelayTimerByCorrelationIdMap.erase(request.getCorrelationId()); - }); + TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(delayMilliSeconds))); + timerPtr->async_wait([that = shared_from_this(), request, req, retry, eventQueuePtr](ErrorCode const& ec) mutable { + if (ec) { + CCAPI_LOGGER_ERROR("request = " + toString(request) + ", sendRequest timer error: " + ec.message()); + that->onError(Event::Type::REQUEST_STATUS, Message::Type::GENERIC_ERROR, ec, "timer", {request.getCorrelationId()}, eventQueuePtr); + } else { + auto thatReq = req; + auto now = UtilTime::now(); + request.setTimeSent(now); + that->tryRequest(request, thatReq, retry, eventQueuePtr); + } + that->sendRequestDelayTimerByCorrelationIdMap.erase(request.getCorrelationId()); + }); + this->sendRequestDelayTimerByCorrelationIdMap[request.getCorrelationId()] = timerPtr; } else { request.setTimeSent(now); this->tryRequest(request, req, retry, eventQueuePtr); @@ -262,14 +287,31 @@ class Service : public std::enable_shared_from_this { protected: #endif + static std::string printableString(const char* s, size_t n) { + std::string output(s, n); + std::replace(output.begin(), output.end(), '\x01', '^'); + return output; + } + static std::string printableString(const std::string& s) { + std::string output(s); + std::replace(output.begin(), output.end(), '\x01', '^'); + return output; + } typedef ServiceContext::SslContextPtr SslContextPtr; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET typedef ServiceContext::TlsClient TlsClient; - typedef wspp::lib::shared_ptr TimerPtr; +#endif + typedef std::shared_ptr TimerPtr; void setHostRestFromUrlRest(std::string baseUrlRest) { auto hostPort = this->extractHostFromUrl(baseUrlRest); this->hostRest = hostPort.first; this->portRest = hostPort.second; } + void setHostWsFromUrlWs(std::string baseUrlWs) { + auto hostPort = this->extractHostFromUrl(baseUrlWs); + this->hostWs = hostPort.first; + this->portWs = hostPort.second; + } std::pair extractHostFromUrl(std::string baseUrl) { std::string host; std::string port; @@ -300,7 +342,8 @@ class Service : public std::enable_shared_from_this { #endif std::shared_ptr> streamPtr(nullptr); try { - streamPtr = this->createStream(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, this->hostRest); + streamPtr = this->createStream>(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, + this->hostRest); } catch (const beast::error_code& ec) { CCAPI_LOGGER_TRACE("fail"); errorHandler(ec); @@ -320,7 +363,7 @@ class Service : public std::enable_shared_from_this { #endif std::shared_ptr> streamPtr(nullptr); try { - streamPtr = this->createStream(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, host); + streamPtr = this->createStream>(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, host); } catch (const beast::error_code& ec) { CCAPI_LOGGER_TRACE("fail"); errorHandler(ec); @@ -369,21 +412,21 @@ class Service : public std::enable_shared_from_this { // #ifdef CCAPI_DISABLE_NAGLE_ALGORITHM beast::get_lowest_layer(stream).socket().set_option(tcp::no_delay(true)); // #endif - CCAPI_LOGGER_TRACE("before async_handshake"); + CCAPI_LOGGER_TRACE("before ssl async_handshake"); stream.async_handshake(ssl::stream_base::client, - beast::bind_front_handler(&Service::onHandshake, shared_from_this(), httpConnectionPtr, req, errorHandler, responseHandler)); - CCAPI_LOGGER_TRACE("after async_handshake"); + beast::bind_front_handler(&Service::onSslHandshake, shared_from_this(), httpConnectionPtr, req, errorHandler, responseHandler)); + CCAPI_LOGGER_TRACE("after ssl async_handshake"); } - void onHandshake(std::shared_ptr httpConnectionPtr, http::request req, - std::function errorHandler, std::function&)> responseHandler, - beast::error_code ec) { - CCAPI_LOGGER_TRACE("async_handshake callback start"); + void onSslHandshake(std::shared_ptr httpConnectionPtr, http::request req, + std::function errorHandler, std::function&)> responseHandler, + beast::error_code ec) { + CCAPI_LOGGER_TRACE("ssl async_handshake callback start"); if (ec) { CCAPI_LOGGER_TRACE("fail"); errorHandler(ec); return; } - CCAPI_LOGGER_TRACE("handshaked"); + CCAPI_LOGGER_TRACE("ssl handshaked"); beast::ssl_stream& stream = *httpConnectionPtr->streamPtr; std::shared_ptr> reqPtr(new http::request(std::move(req))); CCAPI_LOGGER_TRACE("before async_write"); @@ -437,9 +480,9 @@ class Service : public std::enable_shared_from_this { #endif responseHandler(*resPtr); } - std::shared_ptr> createStream(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, - const std::string& host) { - std::shared_ptr> streamPtr(new beast::ssl_stream(*iocPtr, *ctxPtr)); + template + std::shared_ptr createStream(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, const std::string& host) { + std::shared_ptr streamPtr(new T(*iocPtr, *ctxPtr)); // Set SNI Hostname (many hosts need this to handshake successfully) if (!SSL_set_tlsext_host_name(streamPtr->native_handle(), host.c_str())) { beast::error_code ec{static_cast(::ERR_get_error()), net::error::get_ssl_category()}; @@ -448,6 +491,31 @@ class Service : public std::enable_shared_from_this { } return streamPtr; } + template <> + std::shared_ptr>> createStream(std::shared_ptr iocPtr, + std::shared_ptr ctxPtr, + const std::string& host) { + std::shared_ptr>> streamPtr( + new beast::websocket::stream>(*iocPtr, *ctxPtr)); + // Set SNI Hostname (many hosts need this to handshake successfully) + if (!SSL_set_tlsext_host_name(streamPtr->next_layer().native_handle(), host.c_str())) { + beast::error_code ec{static_cast(::ERR_get_error()), net::error::get_ssl_category()}; + CCAPI_LOGGER_DEBUG("error SSL_set_tlsext_host_name: " + ec.message()); + throw ec; + } + return streamPtr; + } + // std::shared_ptr> createStream(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, + // const std::string& host) { + // std::shared_ptr> streamPtr(new beast::ssl_stream(*iocPtr, *ctxPtr)); + // // Set SNI Hostname (many hosts need this to handshake successfully) + // if (!SSL_set_tlsext_host_name(streamPtr->native_handle(), host.c_str())) { + // beast::error_code ec{static_cast(::ERR_get_error()), net::error::get_ssl_category()}; + // CCAPI_LOGGER_DEBUG("error SSL_set_tlsext_host_name: " + ec.message()); + // throw ec; + // } + // return streamPtr; + // } void performRequest(std::shared_ptr httpConnectionPtr, const Request& request, http::request& req, const HttpRetry& retry, Queue* eventQueuePtr) { CCAPI_LOGGER_FUNCTION_ENTER; @@ -478,20 +546,20 @@ class Service : public std::enable_shared_from_this { // #ifdef CCAPI_DISABLE_NAGLE_ALGORITHM beast::get_lowest_layer(stream).socket().set_option(tcp::no_delay(true)); // #endif - CCAPI_LOGGER_TRACE("before async_handshake"); + CCAPI_LOGGER_TRACE("before ssl async_handshake"); stream.async_handshake(ssl::stream_base::client, - beast::bind_front_handler(&Service::onHandshake_2, shared_from_this(), httpConnectionPtr, request, req, retry, eventQueuePtr)); - CCAPI_LOGGER_TRACE("after async_handshake"); + beast::bind_front_handler(&Service::onSslHandshake_2, shared_from_this(), httpConnectionPtr, request, req, retry, eventQueuePtr)); + CCAPI_LOGGER_TRACE("after ssl async_handshake"); } - void onHandshake_2(std::shared_ptr httpConnectionPtr, Request request, http::request req, HttpRetry retry, - Queue* eventQueuePtr, beast::error_code ec) { - CCAPI_LOGGER_TRACE("async_handshake callback start"); + void onSslHandshake_2(std::shared_ptr httpConnectionPtr, Request request, http::request req, HttpRetry retry, + Queue* eventQueuePtr, beast::error_code ec) { + CCAPI_LOGGER_TRACE("ssl async_handshake callback start"); if (ec) { CCAPI_LOGGER_TRACE("fail"); - this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "handshake", {request.getCorrelationId()}, eventQueuePtr); + this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "ssl handshake", {request.getCorrelationId()}, eventQueuePtr); return; } - CCAPI_LOGGER_TRACE("handshaked"); + CCAPI_LOGGER_TRACE("ssl handshaked"); this->startWrite_2(httpConnectionPtr, request, req, retry, eventQueuePtr); } void startWrite_2(std::shared_ptr httpConnectionPtr, Request request, http::request req, HttpRetry retry, @@ -530,7 +598,8 @@ class Service : public std::enable_shared_from_this { CCAPI_LOGGER_TRACE("after async_read"); } void setHttpConnectionPoolPurgeTimer() { - this->httpConnectionPoolPurgeTimer = this->serviceContextPtr->tlsClientPtr->set_timer(5000, [that = shared_from_this()](ErrorCode const& ec) { + TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(5000))); + timerPtr->async_wait([that = shared_from_this()](ErrorCode const& ec) { auto now = UtilTime::now(); if (ec) { that->onError(Event::Type::SESSION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); @@ -542,6 +611,7 @@ class Service : public std::enable_shared_from_this { that->setHttpConnectionPoolPurgeTimer(); } }); + this->httpConnectionPoolPurgeTimer = timerPtr; } void onRead_2(std::shared_ptr httpConnectionPtr, Request request, std::shared_ptr> reqPtr, HttpRetry retry, std::shared_ptr bufferPtr, std::shared_ptr> resPtr, Queue* eventQueuePtr, @@ -652,7 +722,8 @@ class Service : public std::enable_shared_from_this { if (this->sessionOptions.enableOneHttpConnectionPerRequest || this->httpConnectionPool.empty()) { std::shared_ptr> streamPtr(nullptr); try { - streamPtr = this->createStream(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, this->hostRest); + streamPtr = this->createStream>(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, + this->hostRest); } catch (const beast::error_code& ec) { CCAPI_LOGGER_TRACE("fail"); this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "create stream", {request.getCorrelationId()}, eventQueuePtr); @@ -673,7 +744,8 @@ class Service : public std::enable_shared_from_this { } std::shared_ptr> streamPtr(nullptr); try { - streamPtr = this->createStream(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, this->hostRest); + streamPtr = this->createStream>(this->serviceContextPtr->ioContextPtr, + this->serviceContextPtr->sslContextPtr, this->hostRest); } catch (const beast::error_code& ec) { CCAPI_LOGGER_TRACE("fail"); this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "create stream", {request.getCorrelationId()}, eventQueuePtr); @@ -721,24 +793,6 @@ class Service : public std::enable_shared_from_this { CCAPI_LOGGER_FUNCTION_EXIT; return req; } - SslContextPtr onTlsInit(wspp::connection_hdl hdl) { return this->serviceContextPtr->sslContextPtr; } - WsConnection& getWsConnectionFromConnectionPtr(TlsClient::connection_ptr connectionPtr) { - return this->wsConnectionByIdMap.at(this->connectionAddressToString(connectionPtr)); - } - std::string connectionAddressToString(const TlsClient::connection_ptr con) { - const void* address = static_cast(con.get()); - std::stringstream ss; - ss << address; - return ss.str(); - } - void close(WsConnection& wsConnection, wspp::connection_hdl hdl, wspp::close::status::value const code, std::string const& reason, ErrorCode& ec) { - if (wsConnection.status == WsConnection::Status::CLOSING) { - CCAPI_LOGGER_WARN("websocket connection is already in the state of closing"); - return; - } - wsConnection.status = WsConnection::Status::CLOSING; - this->serviceContextPtr->tlsClientPtr->close(hdl, code, reason, ec); - } void substituteParam(std::string& target, const std::map& param, const std::map standardizationMap = {}) { for (const auto& kv : param) { auto key = standardizationMap.find(kv.first) != standardizationMap.end() ? standardizationMap.at(kv.first) : kv.first; @@ -769,10 +823,6 @@ class Service : public std::enable_shared_from_this { queryString += "&"; } } - // virtual std::string convertNumberToStringInJson(const std::string& jsonString) { - // auto quotedTextMessage = std::regex_replace(jsonString, this->convertNumberToStringInJsonRegex, - // this->convertNumberToStringInJsonRewrite); return quotedTextMessage; - // } void setupCredential(std::vector nameList) { for (const auto& x : nameList) { if (this->sessionConfigs.getCredential().find(x) != this->sessionConfigs.getCredential().end()) { @@ -782,6 +832,29 @@ class Service : public std::enable_shared_from_this { } } } + http::verb convertHttpMethodStringToMethod(const std::string& methodString) { + std::string methodStringUpper = UtilString::toUpper(methodString); + return http::string_to_verb(methodStringUpper); + } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + SslContextPtr onTlsInit(wspp::connection_hdl hdl) { return this->serviceContextPtr->sslContextPtr; } + WsConnection& getWsConnectionFromConnectionPtr(TlsClient::connection_ptr connectionPtr) { + return this->wsConnectionByIdMap.at(this->connectionAddressToString(connectionPtr)); + } + std::string connectionAddressToString(const TlsClient::connection_ptr con) { + const void* address = static_cast(con.get()); + std::stringstream ss; + ss << address; + return ss.str(); + } + void close(WsConnection& wsConnection, wspp::connection_hdl hdl, wspp::close::status::value const code, std::string const& reason, ErrorCode& ec) { + if (wsConnection.status == WsConnection::Status::CLOSING) { + CCAPI_LOGGER_WARN("websocket connection is already in the state of closing"); + return; + } + wsConnection.status = WsConnection::Status::CLOSING; + this->serviceContextPtr->tlsClientPtr->close(hdl, code, reason, ec); + } virtual void prepareConnect(WsConnection& wsConnection) { this->connect(wsConnection); } virtual void connect(WsConnection& wsConnection) { CCAPI_LOGGER_FUNCTION_ENTER; @@ -860,21 +933,22 @@ class Service : public std::enable_shared_from_this { if (this->connectRetryOnFailTimerByConnectionIdMap.find(thisWsConnection.id) != this->connectRetryOnFailTimerByConnectionIdMap.end()) { this->connectRetryOnFailTimerByConnectionIdMap.at(thisWsConnection.id)->cancel(); } - this->connectRetryOnFailTimerByConnectionIdMap[thisWsConnection.id] = - this->serviceContextPtr->tlsClientPtr->set_timer(seconds * 1000, [thisWsConnection, that = shared_from_this(), urlBase](ErrorCode const& ec) { - if (that->wsConnectionByIdMap.find(thisWsConnection.id) == that->wsConnectionByIdMap.end()) { - if (ec) { - CCAPI_LOGGER_ERROR("wsConnection = " + toString(thisWsConnection) + ", connect retry on fail timer error: " + ec.message()); - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); - } else { - CCAPI_LOGGER_INFO("about to retry"); - auto thatWsConnection = thisWsConnection; - thatWsConnection.assignDummyId(); - that->prepareConnect(thatWsConnection); - that->connectNumRetryOnFailByConnectionUrlMap[urlBase] += 1; - } - } - }); + TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(seconds * 1000))); + timerPtr->async_wait([thisWsConnection, that = shared_from_this(), urlBase](ErrorCode const& ec) { + if (that->wsConnectionByIdMap.find(thisWsConnection.id) == that->wsConnectionByIdMap.end()) { + if (ec) { + CCAPI_LOGGER_ERROR("wsConnection = " + toString(thisWsConnection) + ", connect retry on fail timer error: " + ec.message()); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + CCAPI_LOGGER_INFO("about to retry"); + auto thatWsConnection = thisWsConnection; + thatWsConnection.assignDummyId(); + that->prepareConnect(thatWsConnection); + that->connectNumRetryOnFailByConnectionUrlMap[urlBase] += 1; + } + } + }); + this->connectRetryOnFailTimerByConnectionIdMap[thisWsConnection.id] = timerPtr; } virtual void onFail(wspp::connection_hdl hdl) { CCAPI_LOGGER_FUNCTION_ENTER; @@ -1037,89 +1111,607 @@ class Service : public std::enable_shared_from_this { this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id).find(method) != this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id).end()) { this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id).at(method)->cancel(); } - this->pingTimerByMethodByConnectionIdMap[wsConnection.id][method] = this->serviceContextPtr->tlsClientPtr->set_timer( - pingIntervalMilliSeconds - pongTimeoutMilliSeconds, - [wsConnection, that = shared_from_this(), hdl, pingMethod, pongTimeoutMilliSeconds, method](ErrorCode const& ec) { - if (that->wsConnectionByIdMap.find(wsConnection.id) != that->wsConnectionByIdMap.end()) { + TimerPtr timerPtr( + new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(pingIntervalMilliSeconds - pongTimeoutMilliSeconds))); + timerPtr->async_wait([wsConnection, that = shared_from_this(), hdl, pingMethod, pongTimeoutMilliSeconds, method](ErrorCode const& ec) { + if (that->wsConnectionByIdMap.find(wsConnection.id) != that->wsConnectionByIdMap.end()) { + if (ec) { + CCAPI_LOGGER_ERROR("wsConnection = " + toString(wsConnection) + ", ping timer error: " + ec.message()); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + if (that->wsConnectionByIdMap.at(wsConnection.id).status == WsConnection::Status::OPEN) { + ErrorCode ec; + pingMethod(hdl, ec); if (ec) { - CCAPI_LOGGER_ERROR("wsConnection = " + toString(wsConnection) + ", ping timer error: " + ec.message()); - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); - } else { - if (that->wsConnectionByIdMap.at(wsConnection.id).status == WsConnection::Status::OPEN) { - ErrorCode ec; - pingMethod(hdl, ec); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "ping"); + } + if (pongTimeoutMilliSeconds <= 0) { + return; + } + if (that->pongTimeOutTimerByMethodByConnectionIdMap.find(wsConnection.id) != that->pongTimeOutTimerByMethodByConnectionIdMap.end() && + that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).find(method) != + that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).end()) { + that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).at(method)->cancel(); + } + TimerPtr timerPtr(new boost::asio::steady_timer(*that->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(pongTimeoutMilliSeconds))); + timerPtr->async_wait([wsConnection, that, hdl, pingMethod, pongTimeoutMilliSeconds, method](ErrorCode const& ec) { + if (that->wsConnectionByIdMap.find(wsConnection.id) != that->wsConnectionByIdMap.end()) { if (ec) { - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "ping"); - } - if (pongTimeoutMilliSeconds <= 0) { - return; - } - if (that->pongTimeOutTimerByMethodByConnectionIdMap.find(wsConnection.id) != that->pongTimeOutTimerByMethodByConnectionIdMap.end() && - that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).find(method) != - that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).end()) { - that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).at(method)->cancel(); - } - that->pongTimeOutTimerByMethodByConnectionIdMap[wsConnection.id][method] = that->serviceContextPtr->tlsClientPtr->set_timer( - pongTimeoutMilliSeconds, [wsConnection, that, hdl, pingMethod, pongTimeoutMilliSeconds, method](ErrorCode const& ec) { - if (that->wsConnectionByIdMap.find(wsConnection.id) != that->wsConnectionByIdMap.end()) { - if (ec) { - CCAPI_LOGGER_ERROR("wsConnection = " + toString(wsConnection) + ", pong time out timer error: " + ec.message()); - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); - } else { - if (that->wsConnectionByIdMap.at(wsConnection.id).status == WsConnection::Status::OPEN) { - auto now = UtilTime::now(); - if (that->lastPongTpByMethodByConnectionIdMap.find(wsConnection.id) != that->lastPongTpByMethodByConnectionIdMap.end() && - that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).find(method) != - that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).end() && - std::chrono::duration_cast( - now - that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).at(method)) - .count() >= pongTimeoutMilliSeconds) { - auto thisWsConnection = wsConnection; - ErrorCode ec; - that->close(thisWsConnection, hdl, websocketpp::close::status::normal, "pong timeout", ec); - if (ec) { - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "shutdown"); - } - that->shouldProcessRemainingMessageOnClosingByConnectionIdMap[thisWsConnection.id] = true; - } else { - auto thisWsConnection = wsConnection; - that->setPingPongTimer(method, thisWsConnection, hdl, pingMethod); - } - } - } + CCAPI_LOGGER_ERROR("wsConnection = " + toString(wsConnection) + ", pong time out timer error: " + ec.message()); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + if (that->wsConnectionByIdMap.at(wsConnection.id).status == WsConnection::Status::OPEN) { + auto now = UtilTime::now(); + if (that->lastPongTpByMethodByConnectionIdMap.find(wsConnection.id) != that->lastPongTpByMethodByConnectionIdMap.end() && + that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).find(method) != + that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).end() && + std::chrono::duration_cast(now - that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).at(method)) + .count() >= pongTimeoutMilliSeconds) { + auto thisWsConnection = wsConnection; + ErrorCode ec; + that->close(thisWsConnection, hdl, websocketpp::close::status::normal, "pong timeout", ec); + if (ec) { + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "shutdown"); } - }); + that->shouldProcessRemainingMessageOnClosingByConnectionIdMap[thisWsConnection.id] = true; + } else { + auto thisWsConnection = wsConnection; + that->setPingPongTimer(method, thisWsConnection, hdl, pingMethod); + } + } + } } - } + }); + that->pongTimeOutTimerByMethodByConnectionIdMap[wsConnection.id][method] = timerPtr; } - }); + } + } + }); + this->pingTimerByMethodByConnectionIdMap[wsConnection.id][method] = timerPtr; } CCAPI_LOGGER_FUNCTION_EXIT; } - http::verb convertHttpMethodStringToMethod(const std::string& methodString) { - std::string methodStringUpper = UtilString::toUpper(methodString); - return http::string_to_verb(methodStringUpper); - } virtual void onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) {} + +#else + + void close(std::shared_ptr wsConnectionPtr, beast::websocket::close_code const code, beast::websocket::close_reason reason, ErrorCode& ec) { + WsConnection& wsConnection = *wsConnectionPtr; + if (wsConnection.status == WsConnection::Status::CLOSING) { + CCAPI_LOGGER_WARN("websocket connection is already in the state of closing"); + return; + } + wsConnection.status = WsConnection::Status::CLOSING; + wsConnection.remoteCloseCode = code; + wsConnection.remoteCloseReason = reason; + wsConnectionPtr->streamPtr->async_close(code, beast::bind_front_handler(&Service::onClose, shared_from_this(), wsConnectionPtr)); + } + virtual void prepareConnect(std::shared_ptr wsConnectionPtr) { this->connect(wsConnectionPtr); } + virtual void connect(std::shared_ptr wsConnectionPtr) { + CCAPI_LOGGER_FUNCTION_ENTER; + WsConnection& wsConnection = *wsConnectionPtr; + wsConnection.status = WsConnection::Status::CONNECTING; + CCAPI_LOGGER_DEBUG("connection initialization on id " + wsConnection.id); + std::string url = wsConnection.url; + CCAPI_LOGGER_DEBUG("url = " + url); + this->startConnectWs(wsConnectionPtr, this->sessionOptions.websocketConnectTimeoutMilliSeconds, this->tcpResolverResultsWs); + // for (const auto& kv : wsConnection.headers) { + // con->append_header(kv.first, kv.second); + // } + // wsConnection.id = this->connectionAddressToString(con); + // CCAPI_LOGGER_DEBUG("connection initialization on actual id " + wsConnection.id); + // if (ec) { + // CCAPI_LOGGER_FATAL("connection initialization error: " + ec.message()); + // } + // this->wsConnectionByIdMap.insert(std::pair(wsConnection.id, wsConnection)); + // CCAPI_LOGGER_DEBUG("this->wsConnectionByIdMap = " + toString(this->wsConnectionByIdMap)); + // con->set_open_handler(std::bind(&Service::onOpen, shared_from_this(), std::placeholders::_1)); + // con->set_fail_handler(std::bind(&Service::onFail, shared_from_this(), std::placeholders::_1)); + // con->set_close_handler(std::bind(&Service::onClose, shared_from_this(), std::placeholders::_1)); + // con->set_message_handler(std::bind(&Service::onMessage, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); + // if (this->sessionOptions.enableCheckPingPongWebsocketProtocolLevel) { + // con->set_pong_handler(std::bind(&Service::onPong, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); + // } + // con->set_ping_handler(std::bind(&Service::onPing, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); + // this->serviceContextPtr->tlsClientPtr->connect(con); + CCAPI_LOGGER_FUNCTION_EXIT; + } + void startConnectWs(std::shared_ptr wsConnectionPtr, long timeoutMilliSeconds, tcp::resolver::results_type tcpResolverResults) { + beast::websocket::stream>& stream = *wsConnectionPtr->streamPtr; + if (timeoutMilliSeconds > 0) { + beast::get_lowest_layer(stream).expires_after(std::chrono::milliseconds(timeoutMilliSeconds)); + } + CCAPI_LOGGER_TRACE("before async_connect"); + beast::get_lowest_layer(stream).async_connect(tcpResolverResults, beast::bind_front_handler(&Service::onConnectWs, shared_from_this(), wsConnectionPtr)); + CCAPI_LOGGER_TRACE("after async_connect"); + } + void onConnectWs(std::shared_ptr wsConnectionPtr, beast::error_code ec, tcp::resolver::results_type::endpoint_type ep) { + CCAPI_LOGGER_TRACE("async_connect callback start"); + if (ec) { + CCAPI_LOGGER_TRACE("fail"); + this->onFail(wsConnectionPtr); + return; + } + CCAPI_LOGGER_TRACE("connected"); + wsConnectionPtr->hostHttpHeaderValue = this->hostWs + ':' + std::to_string(ep.port()); + beast::websocket::stream>& stream = *wsConnectionPtr->streamPtr; + beast::get_lowest_layer(stream).socket().set_option(tcp::no_delay(true)); + CCAPI_LOGGER_TRACE("before ssl async_handshake"); + stream.next_layer().async_handshake(ssl::stream_base::client, beast::bind_front_handler(&Service::onSslHandshakeWs, shared_from_this(), wsConnectionPtr)); + CCAPI_LOGGER_TRACE("after ssl async_handshake"); + } + void onSslHandshakeWs(std::shared_ptr wsConnectionPtr, beast::error_code ec) { + CCAPI_LOGGER_TRACE("ssl async_handshake callback start"); + if (ec) { + CCAPI_LOGGER_TRACE("fail"); + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "ssl handshake", wsConnectionPtr->correlationIdList); + return; + } + CCAPI_LOGGER_TRACE("ssl handshaked"); + beast::websocket::stream>& stream = *wsConnectionPtr->streamPtr; + beast::get_lowest_layer(stream).expires_never(); + + beast::websocket::stream_base::timeout opt{std::chrono::milliseconds(this->sessionOptions.websocketConnectTimeoutMilliSeconds), + std::chrono::milliseconds(this->sessionOptions.pongWebsocketProtocolLevelTimeoutMilliSeconds), true}; + + // Set the timeout options on the stream. + stream.set_option(opt); + stream.set_option(beast::websocket::stream_base::decorator([wsConnectionPtr](beast::websocket::request_type& req) { + req.set(http::field::user_agent, std::string(BOOST_BEAST_VERSION_STRING)); + for (const auto& kv : wsConnectionPtr->headers) { + req.set(kv.first, kv.second); + } + })); + CCAPI_LOGGER_TRACE("before ws async_handshake"); + stream.async_handshake(wsConnectionPtr->hostHttpHeaderValue, wsConnectionPtr->path, + beast::bind_front_handler(&Service::onWsHandshakeWs, shared_from_this(), wsConnectionPtr)); + CCAPI_LOGGER_TRACE("after ws async_handshake"); + } + void onWsHandshakeWs(std::shared_ptr wsConnectionPtr, beast::error_code ec) { + CCAPI_LOGGER_TRACE("ws async_handshake callback start"); + if (ec) { + CCAPI_LOGGER_TRACE("fail"); + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "ws handshake", wsConnectionPtr->correlationIdList); + return; + } + CCAPI_LOGGER_TRACE("ws handshaked"); + this->onOpen(wsConnectionPtr); + this->wsConnectionByIdMap.insert(std::make_pair(wsConnectionPtr->id, wsConnectionPtr)); + CCAPI_LOGGER_TRACE("about to start read"); + this->startReadWs(wsConnectionPtr); + auto& stream = *wsConnectionPtr->streamPtr; + stream.control_callback(beast::bind_front_handler(&Service::onControlCallback, shared_from_this(), wsConnectionPtr)); + } + void startReadWs(std::shared_ptr wsConnectionPtr) { + auto& stream = *wsConnectionPtr->streamPtr; + CCAPI_LOGGER_TRACE("before async_read"); + auto& connectionId = wsConnectionPtr->id; + auto& readMessageBuffer = this->readMessageBufferByConnectionIdMap[connectionId]; + stream.async_read(readMessageBuffer, beast::bind_front_handler(&Service::onReadWs, shared_from_this(), wsConnectionPtr)); + CCAPI_LOGGER_TRACE("after async_read"); + } + void onReadWs(std::shared_ptr wsConnectionPtr, const boost::system::error_code& ec, std::size_t n) { + CCAPI_LOGGER_FUNCTION_ENTER; + CCAPI_LOGGER_TRACE("n = " + toString(n)); + auto now = UtilTime::now(); + if (ec) { + if (ec == beast::error::timeout) { + CCAPI_LOGGER_TRACE("timeout, connection closed"); + } else { + CCAPI_LOGGER_TRACE("fail"); + Event event; + event.setType(Event::Type::SESSION_STATUS); + Message message; + message.setTimeReceived(now); + message.setType(Message::Type::SESSION_CONNECTION_DOWN); + message.setCorrelationIdList(wsConnectionPtr->correlationIdList); + Element element(true); + auto& connectionId = wsConnectionPtr->id; + element.insert(CCAPI_CONNECTION_ID, connectionId); + message.setElementList({element}); + event.setMessageList({message}); + this->eventHandler(event, nullptr); + this->onFail(wsConnectionPtr); + } + return; + } + if (wsConnectionPtr->status != WsConnection::Status::OPEN) { + CCAPI_LOGGER_WARN("should not process remaining message on closing"); + return; + } + auto& connectionId = wsConnectionPtr->id; + auto& readMessageBuffer = this->readMessageBufferByConnectionIdMap[connectionId]; + this->onMessage(wsConnectionPtr, (const char*)readMessageBuffer.data().data(), readMessageBuffer.size()); + readMessageBuffer.consume(readMessageBuffer.size()); + this->startReadWs(wsConnectionPtr); + this->onPongByMethod(PingPongMethod::WEBSOCKET_PROTOCOL_LEVEL, wsConnectionPtr, now); + CCAPI_LOGGER_FUNCTION_EXIT; + } + virtual void onOpen(std::shared_ptr wsConnectionPtr) { + CCAPI_LOGGER_FUNCTION_ENTER; + auto now = UtilTime::now(); + WsConnection& wsConnection = *wsConnectionPtr; + wsConnection.status = WsConnection::Status::OPEN; + CCAPI_LOGGER_INFO("connection " + toString(wsConnection) + " established"); + auto urlBase = UtilString::split(wsConnection.url, "?").at(0); + this->connectNumRetryOnFailByConnectionUrlMap[urlBase] = 0; + Event event; + event.setType(Event::Type::SESSION_STATUS); + Message message; + message.setTimeReceived(now); + message.setType(Message::Type::SESSION_CONNECTION_UP); + std::vector correlationIdList = wsConnection.correlationIdList; + CCAPI_LOGGER_DEBUG("correlationIdList = " + toString(correlationIdList)); + message.setCorrelationIdList(correlationIdList); + Element element; + element.insert(CCAPI_CONNECTION_ID, wsConnection.id); + element.insert(CCAPI_CONNECTION_URL, wsConnection.url); + message.setElementList({element}); + event.setMessageList({message}); + this->eventHandler(event, nullptr); + if (this->enableCheckPingPongWebsocketProtocolLevel) { + this->setPingPongTimer(PingPongMethod::WEBSOCKET_PROTOCOL_LEVEL, wsConnectionPtr, + [wsConnectionPtr, that = shared_from_this()](ErrorCode& ec) { that->ping(wsConnectionPtr, "", ec); }); + } + if (this->enableCheckPingPongWebsocketApplicationLevel) { + this->setPingPongTimer(PingPongMethod::WEBSOCKET_APPLICATION_LEVEL, wsConnectionPtr, + [wsConnectionPtr, that = shared_from_this()](ErrorCode& ec) { that->pingOnApplicationLevel(wsConnectionPtr, ec); }); + } + } + void writeMessage(std::shared_ptr wsConnectionPtr, const char* data, size_t dataSize, bool binary) { + if (wsConnectionPtr->status != WsConnection::Status::OPEN) { + CCAPI_LOGGER_WARN("should write no more messages"); + return; + } + auto& connectionId = wsConnectionPtr->id; + auto& writeMessageBuffer = this->writeMessageBufferByConnectionIdMap[connectionId]; + auto& writeMessageBufferWrittenLength = this->writeMessageBufferWrittenLengthByConnectionIdMap[connectionId]; + size_t n = writeMessageBufferWrittenLength + dataSize; + CCAPI_LOGGER_DEBUG("about to send " + printableString(data, dataSize)); + CCAPI_LOGGER_TRACE("writeMessageBufferWrittenLength = " + toString(writeMessageBufferWrittenLength)); + if (writeMessageBufferWrittenLength == 0) { + CCAPI_LOGGER_TRACE("about to start write"); + this->startWriteWs(wsConnectionPtr, data, dataSize, binary); + } + writeMessageBufferWrittenLength = n; + CCAPI_LOGGER_TRACE("writeMessageBufferWrittenLength = " + toString(writeMessageBufferWrittenLength)); + } + void startWriteWs(std::shared_ptr wsConnectionPtr, const char* data, size_t numBytesToWrite, bool binary) { + auto& stream = *wsConnectionPtr->streamPtr; + CCAPI_LOGGER_TRACE("before async_write"); + CCAPI_LOGGER_TRACE("numBytesToWrite = " + toString(numBytesToWrite)); + stream.binary(binary); + stream.async_write(boost::asio::buffer(data, numBytesToWrite), beast::bind_front_handler(&Service::onWriteWs, shared_from_this(), wsConnectionPtr, binary)); + CCAPI_LOGGER_TRACE("after async_write"); + } + void onWriteWs(std::shared_ptr wsConnectionPtr, bool binary, const boost::system::error_code& ec, std::size_t n) { + CCAPI_LOGGER_FUNCTION_ENTER; + auto& connectionId = wsConnectionPtr->id; + auto& writeMessageBuffer = this->writeMessageBufferByConnectionIdMap[connectionId]; + auto& writeMessageBufferWrittenLength = this->writeMessageBufferWrittenLengthByConnectionIdMap[connectionId]; + writeMessageBufferWrittenLength -= n; + CCAPI_LOGGER_TRACE("writeMessageBufferWrittenLength = " + toString(writeMessageBufferWrittenLength)); + if (writeMessageBufferWrittenLength > 0) { + std::memmove(writeMessageBuffer.data(), writeMessageBuffer.data() + n, writeMessageBufferWrittenLength); + CCAPI_LOGGER_TRACE("about to start write"); + this->startWriteWs(wsConnectionPtr, writeMessageBuffer.data(), writeMessageBufferWrittenLength, binary); + } + CCAPI_LOGGER_FUNCTION_EXIT; + } + virtual void onFail_(std::shared_ptr wsConnectionPtr) { + WsConnection& wsConnection = *wsConnectionPtr; + wsConnection.status = WsConnection::Status::FAILED; + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, "connection " + toString(wsConnection) + " has failed before opening"); + WsConnection thisWsConnection = wsConnection; + this->wsConnectionByIdMap.erase(thisWsConnection.id); + auto urlBase = UtilString::split(thisWsConnection.url, "?").at(0); + long seconds = std::round(UtilAlgorithm::exponentialBackoff(1, 1, 2, std::min(this->connectNumRetryOnFailByConnectionUrlMap[urlBase], 6))); + CCAPI_LOGGER_INFO("about to set timer for " + toString(seconds) + " seconds"); + if (this->connectRetryOnFailTimerByConnectionIdMap.find(thisWsConnection.id) != this->connectRetryOnFailTimerByConnectionIdMap.end()) { + this->connectRetryOnFailTimerByConnectionIdMap.at(thisWsConnection.id)->cancel(); + } + TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(seconds * 1000))); + timerPtr->async_wait([wsConnectionPtr, that = shared_from_this(), urlBase](ErrorCode const& ec) { + WsConnection& thisWsConnection = *wsConnectionPtr; + if (that->wsConnectionByIdMap.find(thisWsConnection.id) == that->wsConnectionByIdMap.end()) { + if (ec) { + CCAPI_LOGGER_ERROR("wsConnection = " + toString(thisWsConnection) + ", connect retry on fail timer error: " + ec.message()); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + CCAPI_LOGGER_INFO("about to retry"); + try { + auto thatWsConnectionPtr = that->createWsConnectionPtr(wsConnectionPtr); + that->prepareConnect(thatWsConnectionPtr); + that->connectNumRetryOnFailByConnectionUrlMap[urlBase] += 1; + } catch (const beast::error_code& ec) { + CCAPI_LOGGER_TRACE("fail"); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "create stream", wsConnectionPtr->correlationIdList); + return; + } + } + } + }); + this->connectRetryOnFailTimerByConnectionIdMap[thisWsConnection.id] = timerPtr; + } + std::shared_ptr createWsConnectionPtr(std::shared_ptr wsConnectionPtr) { + std::shared_ptr thatWsConnectionPtr = wsConnectionPtr; + std::shared_ptr>> streamPtr(nullptr); + try { + streamPtr = this->createStream>>(this->serviceContextPtr->ioContextPtr, + this->serviceContextPtr->sslContextPtr, this->hostWs); + } catch (const beast::error_code& ec) { + throw ec; + } + thatWsConnectionPtr->streamPtr = streamPtr; + return thatWsConnectionPtr; + } + virtual void onFail(std::shared_ptr wsConnectionPtr) { + CCAPI_LOGGER_FUNCTION_ENTER; + this->clearStates(wsConnectionPtr); + this->onFail_(wsConnectionPtr); + CCAPI_LOGGER_FUNCTION_EXIT; + } + virtual void clearStates(std::shared_ptr wsConnectionPtr) { + WsConnection& wsConnection = *wsConnectionPtr; + CCAPI_LOGGER_INFO("clear states for wsConnection " + toString(wsConnection)); + this->shouldProcessRemainingMessageOnClosingByConnectionIdMap.erase(wsConnection.id); + this->lastPongTpByMethodByConnectionIdMap.erase(wsConnection.id); + this->extraPropertyByConnectionIdMap.erase(wsConnection.id); + if (this->pingTimerByMethodByConnectionIdMap.find(wsConnection.id) != this->pingTimerByMethodByConnectionIdMap.end()) { + for (const auto& x : this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id)) { + x.second->cancel(); + } + this->pingTimerByMethodByConnectionIdMap.erase(wsConnection.id); + } + if (this->pongTimeOutTimerByMethodByConnectionIdMap.find(wsConnection.id) != this->pongTimeOutTimerByMethodByConnectionIdMap.end()) { + for (const auto& x : this->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id)) { + x.second->cancel(); + } + this->pongTimeOutTimerByMethodByConnectionIdMap.erase(wsConnection.id); + } + // auto urlBase = UtilString::split(wsConnection.url, "?").at(0); + // this->connectNumRetryOnFailByConnectionUrlMap.erase(urlBase); + if (this->connectRetryOnFailTimerByConnectionIdMap.find(wsConnection.id) != this->connectRetryOnFailTimerByConnectionIdMap.end()) { + this->connectRetryOnFailTimerByConnectionIdMap.at(wsConnection.id)->cancel(); + this->connectRetryOnFailTimerByConnectionIdMap.erase(wsConnection.id); + } + this->readMessageBufferByConnectionIdMap.erase(wsConnection.id); + this->writeMessageBufferByConnectionIdMap.erase(wsConnection.id); + this->writeMessageBufferWrittenLengthByConnectionIdMap.erase(wsConnection.id); + } + virtual void onClose(std::shared_ptr wsConnectionPtr, ErrorCode ec) { + CCAPI_LOGGER_FUNCTION_ENTER; + auto now = UtilTime::now(); + WsConnection& wsConnection = *wsConnectionPtr; + wsConnection.status = WsConnection::Status::CLOSED; + CCAPI_LOGGER_INFO("connection " + toString(wsConnection) + " is closed"); + std::stringstream s; + s << "close code: " << wsConnectionPtr->remoteCloseCode << " (" << std::to_string(wsConnectionPtr->remoteCloseCode) + << "), close reason: " << wsConnectionPtr->remoteCloseReason.reason; + std::string reason = s.str(); + CCAPI_LOGGER_INFO("reason is " + reason); + Event event; + event.setType(Event::Type::SESSION_STATUS); + Message message; + message.setTimeReceived(now); + message.setType(Message::Type::SESSION_CONNECTION_DOWN); + Element element; + element.insert(CCAPI_CONNECTION_ID, wsConnection.id); + element.insert(CCAPI_CONNECTION_URL, wsConnection.url); + element.insert(CCAPI_REASON, reason); + message.setElementList({element}); + std::vector correlationIdList; + for (const auto& subscription : wsConnection.subscriptionList) { + correlationIdList.push_back(subscription.getCorrelationId()); + } + CCAPI_LOGGER_DEBUG("correlationIdList = " + toString(correlationIdList)); + message.setCorrelationIdList(correlationIdList); + event.setMessageList({message}); + this->eventHandler(event, nullptr); + CCAPI_LOGGER_INFO("connection " + toString(wsConnection) + " is closed"); + this->clearStates(wsConnectionPtr); + auto thisWsConnectionPtr = this->createWsConnectionPtr(wsConnectionPtr); + this->wsConnectionByIdMap.erase(wsConnectionPtr->id); + if (this->shouldContinue.load()) { + this->prepareConnect(thisWsConnectionPtr); + } + CCAPI_LOGGER_FUNCTION_EXIT; + } + void onMessage(std::shared_ptr wsConnectionPtr, const char* data, size_t dataSize) { + auto now = UtilTime::now(); + WsConnection& wsConnection = *wsConnectionPtr; + CCAPI_LOGGER_DEBUG("received a message from connection " + toString(wsConnection)); + if (wsConnection.status != WsConnection::Status::OPEN && !this->shouldProcessRemainingMessageOnClosingByConnectionIdMap[wsConnection.id]) { + CCAPI_LOGGER_WARN("should not process remaining message on closing"); + return; + } + auto& stream = *wsConnectionPtr->streamPtr; + if (stream.got_text()) { + CCAPI_LOGGER_DEBUG(std::string("received a text message: ") + data); + boost::beast::string_view textMessage(data, dataSize); + try { + this->onTextMessage(wsConnectionPtr, textMessage, now); + } catch (const std::exception& e) { + CCAPI_LOGGER_ERROR(std::string("textMessage = ") + std::string(textMessage)); + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, e); + } + } else if (stream.got_binary()) { +#if defined(CCAPI_ENABLE_SERVICE_MARKET_DATA) && \ + (defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP)) || \ + defined(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) && \ + (defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_BITMART)) + if (this->needDecompressWebsocketMessage) { + std::string decompressed; + const std::string& payload = msg->get_payload(); + try { + ErrorCode ec = this->inflater.decompress(reinterpret_cast(&payload[0]), payload.size(), decompressed); + if (ec) { + CCAPI_LOGGER_FATAL(ec.message()); + } + CCAPI_LOGGER_DEBUG("decompressed = " + decompressed); + this->onTextMessage(hdl, decompressed, now); + } catch (const std::exception& e) { + std::stringstream ss; + ss << std::hex << std::setfill('0'); + for (int i = 0; i < payload.size(); ++i) { + ss << std::setw(2) << static_cast(reinterpret_cast(&payload[0])[i]); + } + CCAPI_LOGGER_ERROR("binaryMessage = " + ss.str()); + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, e); + } + ErrorCode ec = this->inflater.inflate_reset(); + if (ec) { + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "decompress"); + } + } +#endif + } + } + void onControlCallback(std::shared_ptr wsConnectionPtr, boost::beast::websocket::frame_type kind, boost::beast::string_view payload) { + if (kind == boost::beast::websocket::frame_type::ping) { + this->onPing(wsConnectionPtr, payload); + } else if (kind == boost::beast::websocket::frame_type::pong) { + this->onPong(wsConnectionPtr, payload); + } else if (kind == boost::beast::websocket::frame_type::close) { + this->onClose(wsConnectionPtr, ErrorCode()); + } + } + void onPong(std::shared_ptr wsConnectionPtr, boost::beast::string_view payload) { + auto now = UtilTime::now(); + this->onPongByMethod(PingPongMethod::WEBSOCKET_PROTOCOL_LEVEL, wsConnectionPtr, now); + } + void onPongByMethod(PingPongMethod method, std::shared_ptr wsConnectionPtr, const TimePoint& timeReceived) { + CCAPI_LOGGER_FUNCTION_ENTER; + CCAPI_LOGGER_TRACE(pingPongMethodToString(method) + ": received a pong from " + toString(*wsConnectionPtr)); + this->lastPongTpByMethodByConnectionIdMap[wsConnectionPtr->id][method] = timeReceived; + CCAPI_LOGGER_FUNCTION_EXIT; + } + void onPing(std::shared_ptr wsConnectionPtr, boost::beast::string_view payload) { + CCAPI_LOGGER_FUNCTION_ENTER; + CCAPI_LOGGER_TRACE("received a ping from " + toString(*wsConnectionPtr)); + CCAPI_LOGGER_FUNCTION_EXIT; + } + void send(std::shared_ptr wsConnectionPtr, boost::beast::string_view payload, ErrorCode& ec) { + this->writeMessage(wsConnectionPtr, payload.data(), payload.length(), false); + } + void ping(std::shared_ptr wsConnectionPtr, boost::beast::string_view payload, ErrorCode& ec) { + if (!this->wsConnectionPendingPingingByIdMap[wsConnectionPtr->id]) { + auto& stream = *wsConnectionPtr->streamPtr; + stream.async_ping("", [that = this, wsConnectionPtr](ErrorCode const& ec) { that->wsConnectionPendingPingingByIdMap[wsConnectionPtr->id] = false; }); + this->wsConnectionPendingPingingByIdMap[wsConnectionPtr->id] = true; + } + } + virtual void pingOnApplicationLevel(std::shared_ptr wsConnectionPtr, ErrorCode& ec) {} + void setPingPongTimer(PingPongMethod method, std::shared_ptr wsConnectionPtr, std::function pingMethod) { + CCAPI_LOGGER_FUNCTION_ENTER; + CCAPI_LOGGER_TRACE("method = " + pingPongMethodToString(method)); + auto pingIntervalMilliSeconds = this->pingIntervalMilliSecondsByMethodMap[method]; + auto pongTimeoutMilliSeconds = this->pongTimeoutMilliSecondsByMethodMap[method]; + CCAPI_LOGGER_TRACE("pingIntervalMilliSeconds = " + toString(pingIntervalMilliSeconds)); + CCAPI_LOGGER_TRACE("pongTimeoutMilliSeconds = " + toString(pongTimeoutMilliSeconds)); + if (pingIntervalMilliSeconds <= pongTimeoutMilliSeconds) { + return; + } + WsConnection& wsConnection = *wsConnectionPtr; + if (wsConnection.status == WsConnection::Status::OPEN) { + if (this->pingTimerByMethodByConnectionIdMap.find(wsConnection.id) != this->pingTimerByMethodByConnectionIdMap.end() && + this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id).find(method) != this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id).end()) { + this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id).at(method)->cancel(); + } + TimerPtr timerPtr( + new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(pingIntervalMilliSeconds - pongTimeoutMilliSeconds))); + timerPtr->async_wait([wsConnectionPtr, that = shared_from_this(), pingMethod, pongTimeoutMilliSeconds, method](ErrorCode const& ec) { + WsConnection& wsConnection = *wsConnectionPtr; + if (that->wsConnectionByIdMap.find(wsConnection.id) != that->wsConnectionByIdMap.end()) { + if (ec) { + CCAPI_LOGGER_ERROR("wsConnection = " + toString(wsConnection) + ", ping timer error: " + ec.message()); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + if (that->wsConnectionByIdMap.at(wsConnection.id)->status == WsConnection::Status::OPEN) { + ErrorCode ec; + pingMethod(ec); + if (ec) { + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "ping"); + } + if (pongTimeoutMilliSeconds <= 0) { + return; + } + if (that->pongTimeOutTimerByMethodByConnectionIdMap.find(wsConnection.id) != that->pongTimeOutTimerByMethodByConnectionIdMap.end() && + that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).find(method) != + that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).end()) { + that->pongTimeOutTimerByMethodByConnectionIdMap.at(wsConnection.id).at(method)->cancel(); + } + TimerPtr timerPtr(new boost::asio::steady_timer(*that->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(pongTimeoutMilliSeconds))); + timerPtr->async_wait([wsConnectionPtr, that, pingMethod, pongTimeoutMilliSeconds, method](ErrorCode const& ec) { + WsConnection& wsConnection = *wsConnectionPtr; + if (that->wsConnectionByIdMap.find(wsConnection.id) != that->wsConnectionByIdMap.end()) { + if (ec) { + CCAPI_LOGGER_ERROR("wsConnection = " + toString(wsConnection) + ", pong time out timer error: " + ec.message()); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + if (that->wsConnectionByIdMap.at(wsConnection.id)->status == WsConnection::Status::OPEN) { + auto now = UtilTime::now(); + if (that->lastPongTpByMethodByConnectionIdMap.find(wsConnection.id) != that->lastPongTpByMethodByConnectionIdMap.end() && + that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).find(method) != + that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).end() && + std::chrono::duration_cast(now - that->lastPongTpByMethodByConnectionIdMap.at(wsConnection.id).at(method)) + .count() >= pongTimeoutMilliSeconds) { + auto thisWsConnectionPtr = wsConnectionPtr; + ErrorCode ec; + that->close(thisWsConnectionPtr, beast::websocket::close_code::normal, + beast::websocket::close_reason(beast::websocket::close_code::normal, "pong timeout"), ec); + if (ec) { + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "shutdown"); + } + that->shouldProcessRemainingMessageOnClosingByConnectionIdMap[thisWsConnectionPtr->id] = true; + } else { + auto thisWsConnectionPtr = wsConnectionPtr; + that->setPingPongTimer(method, thisWsConnectionPtr, pingMethod); + } + } + } + } + }); + that->pongTimeOutTimerByMethodByConnectionIdMap[wsConnection.id][method] = timerPtr; + } + } + } + }); + this->pingTimerByMethodByConnectionIdMap[wsConnection.id][method] = timerPtr; + } + CCAPI_LOGGER_FUNCTION_EXIT; + } + virtual void onTextMessage(std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessage, const TimePoint& timeReceived) {} +#endif std::string apiKeyName; std::string apiSecretName; std::string exchangeName; - std::string baseUrl; + std::string baseUrlWs; std::string baseUrlRest; std::function* eventQueue)> eventHandler; SessionOptions sessionOptions; SessionConfigs sessionConfigs; ServiceContextPtr serviceContextPtr; - tcp::resolver resolver; + tcp::resolver resolver, resolverWs; std::string hostRest; std::string portRest; - tcp::resolver::results_type tcpResolverResultsRest; + std::string hostWs; + std::string portWs; + tcp::resolver::results_type tcpResolverResultsRest, tcpResolverResultsWs; Queue> httpConnectionPool; TimePoint lastHttpConnectionPoolPushBackTp{std::chrono::seconds{0}}; TimerPtr httpConnectionPoolPurgeTimer; std::map credentialDefault; std::map sendRequestDelayTimerByCorrelationIdMap; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET std::map wsConnectionByIdMap; +#else + std::map> wsConnectionByIdMap; // TODO(cryptochassis): for consistency, to be renamed to wsConnectionPtrByIdMap + std::map readMessageBufferByConnectionIdMap; + std::map> writeMessageBufferByConnectionIdMap; + std::map writeMessageBufferWrittenLengthByConnectionIdMap; +#endif + std::map wsConnectionPendingPingingByIdMap; std::map shouldProcessRemainingMessageOnClosingByConnectionIdMap; std::map connectNumRetryOnFailByConnectionUrlMap; std::map connectRetryOnFailTimerByConnectionIdMap; diff --git a/include/ccapi_cpp/service/ccapi_service_context.h b/include/ccapi_cpp/service/ccapi_service_context.h index dabfe646..033f9560 100644 --- a/include/ccapi_cpp/service/ccapi_service_context.h +++ b/include/ccapi_cpp/service/ccapi_service_context.h @@ -1,5 +1,6 @@ #ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_ #define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_ +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET #include "ccapi_cpp/ccapi_logger.h" #include "websocketpp/client.hpp" #include "websocketpp/common/connection_hdl.hpp" @@ -67,5 +68,48 @@ class ServiceContext CCAPI_FINAL { }; } /* namespace ccapi */ +#else +#include "ccapi_cpp/ccapi_logger.h" +namespace ccapi { +/** + * Defines the service that the service depends on. + */ +class ServiceContext CCAPI_FINAL { + public: + typedef boost::asio::io_context IoContext; + typedef std::shared_ptr IoContextPtr; + typedef boost::asio::executor_work_guard ExecutorWorkGuard; + typedef std::shared_ptr ExecutorWorkGuardPtr; + typedef boost::asio::ssl::context SslContext; + typedef std::shared_ptr SslContextPtr; + ServiceContext() { + this->sslContextPtr->set_options(SslContext::default_workarounds | SslContext::no_sslv2 | SslContext::no_sslv3 | SslContext::single_dh_use); + this->sslContextPtr->set_verify_mode(boost::asio::ssl::verify_none); + // TODO(cryptochassis): verify ssl certificate to strengthen security + // https://github.com/boostorg/asio/blob/develop/example/cpp03/ssl/client.cpp + } + ServiceContext(const ServiceContext&) = delete; + ServiceContext& operator=(const ServiceContext&) = delete; + virtual ~ServiceContext() { + // delete this->ExecutorWorkGuardPtr; + // delete this->ioContextPtr; + // delete this->sslContextPtr; + } + void start() { + CCAPI_LOGGER_INFO("about to start client asio io_context run loop"); + this->ioContextPtr->run(); + CCAPI_LOGGER_INFO("just exited client asio io_context run loop"); + } + void stop() { + this->executorWorkGuardPtr->reset(); + this->ioContextPtr->stop(); + } + IoContextPtr ioContextPtr{new IoContext()}; + ExecutorWorkGuardPtr executorWorkGuardPtr{new ExecutorWorkGuard(ioContextPtr->get_executor())}; + SslContextPtr sslContextPtr{new SslContext(SslContext::tls_client)}; +}; +} /* namespace ccapi */ + +#endif #endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_SERVICE_CONTEXT_H_ diff --git a/test/test_build/CMakeLists.txt b/test/test_build/CMakeLists.txt index 8ce77e73..75de02ba 100644 --- a/test/test_build/CMakeLists.txt +++ b/test/test_build/CMakeLists.txt @@ -1,5 +1,6 @@ set(NAME build_test) project(${NAME}) +add_compile_definitions(CCAPI_ENABLE_LOG_TRACE) set(SERVICE_LIST "MARKET_DATA" "EXECUTION_MANAGEMENT" "FIX") set(MARKET_DATA_EXCHANGE_LIST "COINBASE" "GEMINI" "KRAKEN" "KRAKEN_FUTURES" "BITSTAMP" "BITFINEX" "BITMEX" "BINANCE_US" "BINANCE" "BINANCE_USDS_FUTURES" "BINANCE_COIN_FUTURES" "HUOBI" "HUOBI_USDT_SWAP" "HUOBI_COIN_SWAP" "OKX" "ERISX" "KUCOIN" "KUCOIN_FUTURES" "DERIBIT" "GATEIO" "GATEIO_PERPETUAL_FUTURES" "CRYPTOCOM" "ASCENDEX" "BYBIT" "BYBIT_DERIVATIVES" "BITGET" "BITGET_FUTURES" "BITMART" "MEXC" "MEXC_FUTURES" "WHITEBIT") set(EXECUTION_MANAGEMENT_EXCHANGE_LIST "COINBASE" "GEMINI" "KRAKEN" "KRAKEN_FUTURES" "BITSTAMP" "BITFINEX" "BITMEX" "BINANCE_US" "BINANCE" "BINANCE_USDS_FUTURES" "BINANCE_COIN_FUTURES" "HUOBI" "HUOBI_USDT_SWAP" "HUOBI_COIN_SWAP" "OKX" "ERISX" "KUCOIN" "KUCOIN_FUTURES" "DERIBIT" "GATEIO" "GATEIO_PERPETUAL_FUTURES" "CRYPTOCOM" "ASCENDEX" "BYBIT" "BYBIT_DERIVATIVES" "BITGET" "BITGET_FUTURES" "BITMART" "MEXC" "WHITEBIT") From 1ce5abf1bafb6ea0bb53ec493dbd23a5ae307794 Mon Sep 17 00:00:00 2001 From: Crypto Chassis Date: Sat, 18 Mar 2023 13:40:18 -0700 Subject: [PATCH 2/7] build: fix more compile errors --- .../ccapi_execution_management_service.h | 175 ++++++++++++------ ...pi_execution_management_service_coinbase.h | 14 +- .../service/ccapi_market_data_service.h | 8 +- .../ccapi_market_data_service_binance_base.h | 24 ++- .../ccapi_market_data_service_coinbase.h | 1 - include/ccapi_cpp/service/ccapi_service.h | 22 +-- 6 files changed, 164 insertions(+), 80 deletions(-) diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service.h b/include/ccapi_cpp/service/ccapi_execution_management_service.h index 599165e6..41f8b0ab 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service.h @@ -48,31 +48,30 @@ class ExecutionManagementService : public Service { CCAPI_LOGGER_DEBUG("this->baseUrlWs = " + this->baseUrlWs); if (this->shouldContinue.load()) { for (auto& subscription : subscriptionList) { - boost::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), - [that = shared_from_base(), subscription]() mutable { - auto now = UtilTime::now(); - subscription.setTimeSent(now); - auto credential = subscription.getCredential(); - if (credential.empty()) { - credential = that->credentialDefault; - } + boost::asio::post(*this->serviceContextPtr->ioContextPtr, [that = shared_from_base(), subscription]() mutable { + auto now = UtilTime::now(); + subscription.setTimeSent(now); + auto credential = subscription.getCredential(); + if (credential.empty()) { + credential = that->credentialDefault; + } #ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET - WsConnection wsConnection(that->baseUrlWs, "", {subscription}, credential); - that->prepareConnect(wsConnection); + WsConnection wsConnection(that->baseUrlWs, "", {subscription}, credential); + that->prepareConnect(wsConnection); #else - std::shared_ptr> streamPtr(nullptr); + std::shared_ptr>> streamPtr(nullptr); try { - streamPtr = this->createStream>>(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, this->hostWs); + streamPtr = that->createStream>>(that->serviceContextPtr->ioContextPtr, that->serviceContextPtr->sslContextPtr, that->hostWs); } catch (const beast::error_code& ec) { CCAPI_LOGGER_TRACE("fail"); - this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "create stream", {subscription.getCorrelationId()}, eventQueuePtr); + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "create stream", {subscription.getCorrelationId()}); return; } - std::shared_ptr wsConnectionPtr(new WsConnection(this->hostWs, this->portWs, streamPtr)); + std::shared_ptr wsConnectionPtr(new WsConnection(that->baseUrlWs, "", {subscription}, credential, streamPtr)); CCAPI_LOGGER_WARN("about to subscribe with new wsConnectionPtr " + toString(*wsConnectionPtr)); that->prepareConnect(wsConnectionPtr); #endif - }); + }); } } CCAPI_LOGGER_FUNCTION_EXIT; @@ -180,6 +179,7 @@ class ExecutionManagementService : public Service { } } } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET virtual void logonToExchange(const WsConnection& wsConnection, const TimePoint& now, const std::map& credential) { CCAPI_LOGGER_INFO("about to logon to exchange"); CCAPI_LOGGER_INFO("exchange is " + this->exchangeName); @@ -221,53 +221,65 @@ class ExecutionManagementService : public Service { this->wsRequestIdByConnectionIdMap.erase(wsConnection.id); Service::onClose(hdl); } - void sendRequestByWebsocket(Request& request, const TimePoint& now) override { - CCAPI_LOGGER_FUNCTION_ENTER; - CCAPI_LOGGER_TRACE("now = " + toString(now)); - boost::asio::post(this->serviceContextPtr->tlsClientPtr->get_io_service(), [that = shared_from_base(), request]() mutable { - auto now = UtilTime::now(); - CCAPI_LOGGER_DEBUG("request = " + toString(request)); - CCAPI_LOGGER_TRACE("now = " + toString(now)); - request.setTimeSent(now); - auto nowFixTimeStr = UtilTime::convertTimePointToFIXTime(now); - auto& correlationId = request.getCorrelationId(); - auto it = that->wsConnectionByCorrelationIdMap.find(correlationId); - if (it == that->wsConnectionByCorrelationIdMap.end()) { - that->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, "Websocket connection was not found", {correlationId}); - return; - } - auto& wsConnection = it->second; - CCAPI_LOGGER_TRACE("wsConnection = " + toString(wsConnection)); - auto instrument = request.getInstrument(); - auto symbolId = instrument; - CCAPI_LOGGER_TRACE("symbolId = " + symbolId); + virtual void convertRequestForWebsocketCustom(rj::Document& document, rj::Document::AllocatorType& allocator, const WsConnection& wsConnection, + const Request& request, int wsRequestId, const TimePoint& now, const std::string& symbolId, + const std::map& credential) { + auto errorMessage = "Websocket unimplemented operation " + Request::operationToString(request.getOperation()) + " for exchange " + request.getExchange(); + throw std::runtime_error(errorMessage); + } + virtual void onTextMessage(const WsConnection& wsConnection, const Subscription& subscription, const std::string& textMessage, + const TimePoint& timeReceived) {} +#else + virtual void logonToExchange(std::shared_ptr wsConnectionPtr, const TimePoint& now, const std::map& credential) { + CCAPI_LOGGER_INFO("about to logon to exchange"); + CCAPI_LOGGER_INFO("exchange is " + this->exchangeName); + WsConnection& wsConnection = *wsConnectionPtr; + auto subscription = wsConnection.subscriptionList.at(0); + std::vector sendStringList = this->createSendStringListFromSubscription(wsConnection, subscription, now, credential); + for (const auto& sendString : sendStringList) { + CCAPI_LOGGER_INFO("sendString = " + sendString); ErrorCode ec; - rj::Document document; - rj::Document::AllocatorType& allocator = document.GetAllocator(); - auto credential = request.getCredential(); - if (credential.empty()) { - credential = that->credentialDefault; - } - that->convertRequestForWebsocket(document, allocator, wsConnection, request, ++that->wsRequestIdByConnectionIdMap[wsConnection.id], now, symbolId, - credential); - rj::StringBuffer stringBuffer; - rj::Writer writer(stringBuffer); - document.Accept(writer); - std::string sendString = stringBuffer.GetString(); - CCAPI_LOGGER_TRACE("sendString = " + sendString); - that->send(wsConnection.hdl, sendString, wspp::frame::opcode::text, ec); + this->send(wsConnectionPtr, sendString, ec); if (ec) { - that->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "request"); + this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "subscribe"); } - }); - CCAPI_LOGGER_FUNCTION_EXIT; + } } - virtual void convertRequestForWebsocketCustom(rj::Document& document, rj::Document::AllocatorType& allocator, const WsConnection& wsConnection, + void onTextMessage(std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessageView, const TimePoint& timeReceived) override { + auto subscription = wsConnectionPtr->subscriptionList.at(0); + this->onTextMessage(wsConnectionPtr, subscription, textMessageView, timeReceived); + this->onPongByMethod(PingPongMethod::WEBSOCKET_APPLICATION_LEVEL, wsConnectionPtr, timeReceived); + } + void onOpen(std::shared_ptr wsConnectionPtr) override { + CCAPI_LOGGER_FUNCTION_ENTER; + Service::onOpen(wsConnectionPtr); + auto now = UtilTime::now(); + WsConnection& wsConnection = *wsConnectionPtr; + auto correlationId = wsConnection.subscriptionList.at(0).getCorrelationId(); + this->wsConnectionByCorrelationIdMap.insert({correlationId, wsConnectionPtr}); + this->correlationIdByConnectionIdMap.insert({wsConnection.id, correlationId}); + auto credential = wsConnection.credential; + this->logonToExchange(wsConnectionPtr, now, credential); + } + void onClose(std::shared_ptr wsConnectionPtr, ErrorCode ec) override { + CCAPI_LOGGER_FUNCTION_ENTER; + WsConnection& wsConnection = *wsConnectionPtr; + if (this->correlationIdByConnectionIdMap.find(wsConnection.id) != this->correlationIdByConnectionIdMap.end()) { + this->wsConnectionByCorrelationIdMap.erase(this->correlationIdByConnectionIdMap.at(wsConnection.id)); + this->correlationIdByConnectionIdMap.erase(wsConnection.id); + } + this->wsRequestIdByConnectionIdMap.erase(wsConnection.id); + Service::onClose(wsConnectionPtr, ec); + } + virtual void convertRequestForWebsocketCustom(rj::Document& document, rj::Document::AllocatorType& allocator, std::shared_ptr wsConnectionPtr, const Request& request, int wsRequestId, const TimePoint& now, const std::string& symbolId, const std::map& credential) { auto errorMessage = "Websocket unimplemented operation " + Request::operationToString(request.getOperation()) + " for exchange " + request.getExchange(); throw std::runtime_error(errorMessage); } + virtual void onTextMessage(std::shared_ptr wsConnectionPtr, const Subscription& subscription, boost::beast::string_view textMessage, + const TimePoint& timeReceived) {} +#endif void convertRequestForRestGenericPrivateRequest(http::request& req, const Request& request, const TimePoint& now, const std::string& symbolId, const std::map& credential) { const std::map param = request.getFirstParamWithDefault(); @@ -304,8 +316,56 @@ class ExecutionManagementService : public Service { int64_t nonce = std::chrono::duration_cast(now.time_since_epoch()).count() + requestIndex; return nonce; } - virtual void onTextMessage(const WsConnection& wsConnection, const Subscription& subscription, const std::string& textMessage, - const TimePoint& timeReceived) {} + void sendRequestByWebsocket(Request& request, const TimePoint& now) override { + CCAPI_LOGGER_FUNCTION_ENTER; + CCAPI_LOGGER_TRACE("now = " + toString(now)); + boost::asio::post(*this->serviceContextPtr->ioContextPtr, [that = shared_from_base(), request]() mutable { + auto now = UtilTime::now(); + CCAPI_LOGGER_DEBUG("request = " + toString(request)); + CCAPI_LOGGER_TRACE("now = " + toString(now)); + request.setTimeSent(now); + auto nowFixTimeStr = UtilTime::convertTimePointToFIXTime(now); + auto& correlationId = request.getCorrelationId(); + auto it = that->wsConnectionByCorrelationIdMap.find(correlationId); + if (it == that->wsConnectionByCorrelationIdMap.end()) { + that->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, "Websocket connection was not found", {correlationId}); + return; + } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + auto& wsConnection = it->second; +#else + auto wsConnectionPtr = it->second; + auto& wsConnection = *wsConnectionPtr; +#endif + CCAPI_LOGGER_TRACE("wsConnection = " + toString(wsConnection)); + auto instrument = request.getInstrument(); + auto symbolId = instrument; + CCAPI_LOGGER_TRACE("symbolId = " + symbolId); + ErrorCode ec; + rj::Document document; + rj::Document::AllocatorType& allocator = document.GetAllocator(); + auto credential = request.getCredential(); + if (credential.empty()) { + credential = that->credentialDefault; + } + that->convertRequestForWebsocket(document, allocator, wsConnection, request, ++that->wsRequestIdByConnectionIdMap[wsConnection.id], now, symbolId, + credential); + rj::StringBuffer stringBuffer; + rj::Writer writer(stringBuffer); + document.Accept(writer); + std::string sendString = stringBuffer.GetString(); + CCAPI_LOGGER_TRACE("sendString = " + sendString); +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + that->send(wsConnection.hdl, sendString, wspp::frame::opcode::text, ec); +#else + that->send(wsConnectionPtr, sendString, ec); +#endif + if (ec) { + that->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "request"); + } + }); + CCAPI_LOGGER_FUNCTION_EXIT; + } virtual void convertRequestForRest(http::request& req, const Request& request, const std::string& wsRequestId, const TimePoint& now, const std::string& symbolId, const std::map& credential) {} virtual void convertRequestForWebsocket(rj::Document& document, rj::Document::AllocatorType& allocator, const WsConnection& wsConnection, @@ -331,7 +391,12 @@ class ExecutionManagementService : public Service { std::string getAccountBalancesTarget; std::string getAccountPositionsTarget; std::map correlationIdByConnectionIdMap; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET std::map wsConnectionByCorrelationIdMap; +#else + std::map > + wsConnectionByCorrelationIdMap; // TODO(cryptochassis): for consistency, to be renamed to wsConnectionPtrByCorrelationIdMap +#endif std::map wsRequestIdByConnectionIdMap; }; } /* namespace ccapi */ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h index b3d51b8f..61a2e938 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h @@ -284,8 +284,18 @@ class ExecutionManagementServiceCoinbase : public ExecutionManagementService { sendStringList.push_back(sendString); return sendStringList; } - void onTextMessage(const WsConnection& wsConnection, const Subscription& subscription, const std::string& textMessage, - const TimePoint& timeReceived) override { + void onTextMessage( +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + const WsConnection& wsConnection, const Subscription& subscription, const std::string& textMessage +#else + std::shared_ptr wsConnectionPtr, const Subscription& subscription, boost::beast::string_view textMessageView +#endif + , + const TimePoint& timeReceived) override { +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else + std::string textMessage(textMessageView); +#endif rj::Document document; document.Parse(textMessage.c_str()); Event event = this->createEvent(subscription, textMessage, document, timeReceived); diff --git a/include/ccapi_cpp/service/ccapi_market_data_service.h b/include/ccapi_cpp/service/ccapi_market_data_service.h index d0dc5562..76160010 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service.h @@ -1365,7 +1365,13 @@ class MarketDataService : public Service { CCAPI_LOGGER_ERROR("wsConnection = " + toString(wsConnection) + ", conflate timer error: " + ec.message()); this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); } else { - if (this->wsConnectionByIdMap.at(wsConnection.id)->status == WsConnection::Status::OPEN) { + if ( +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + this->wsConnectionByIdMap.at(wsConnection.id).status == WsConnection::Status::OPEN +#else + this->wsConnectionByIdMap.at(wsConnection.id)->status == WsConnection::Status::OPEN +#endif + ) { auto conflateTp = previousConflateTp + interval; if (conflateTp > this->previousConflateTimeMapByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id).at(channelId).at(symbolId)) { Event event; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h index 0537d379..761f65cb 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h @@ -17,6 +17,7 @@ class MarketDataServiceBinanceBase : public MarketDataService { protected: #endif +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET void onOpen(wspp::connection_hdl hdl) override { CCAPI_LOGGER_FUNCTION_ENTER; auto now = UtilTime::now(); @@ -24,6 +25,14 @@ class MarketDataServiceBinanceBase : public MarketDataService { WsConnection& wsConnection = this->getWsConnectionFromConnectionPtr(this->serviceContextPtr->tlsClientPtr->get_con_from_hdl(hdl)); this->startSubscribe(wsConnection); } +#else + void onOpen(std::shared_ptr wsConnectionPtr) override { + CCAPI_LOGGER_FUNCTION_ENTER; + auto now = UtilTime::now(); + Service::onOpen(wsConnectionPtr); + this->startSubscribe(wsConnectionPtr); + } +#endif void prepareSubscriptionDetail(std::string& channelId, std::string& symbolId, const std::string& field, const WsConnection& wsConnection, const Subscription& subscription, const std::map optionMap) override { auto marketDepthRequested = std::stoi(optionMap.at(CCAPI_MARKET_DEPTH_MAX)); @@ -95,8 +104,19 @@ class MarketDataServiceBinanceBase : public MarketDataService { sendStringList.push_back(sendString); return sendStringList; } - void processTextMessage(WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived, Event& event, - std::vector& marketDataMessageList) override { + void processTextMessage( +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage +#else + std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessageView +#endif + , + const TimePoint& timeReceived, Event& event, std::vector& marketDataMessageList) override { +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else + WsConnection& wsConnection = *wsConnectionPtr; + std::string textMessage(textMessageView); +#endif rj::Document document; document.Parse(textMessage.c_str()); if (document.IsObject() && document.HasMember("result") && document["result"].IsNull()) { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h index 4fc7c1bf..c9a68aa8 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h @@ -73,7 +73,6 @@ class MarketDataServiceCoinbase : public MarketDataService { #endif , const TimePoint& timeReceived, Event& event, std::vector& marketDataMessageList) override { - #ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET #else WsConnection& wsConnection = *wsConnectionPtr; diff --git a/include/ccapi_cpp/service/ccapi_service.h b/include/ccapi_cpp/service/ccapi_service.h index a7f7dcff..510e41c9 100644 --- a/include/ccapi_cpp/service/ccapi_service.h +++ b/include/ccapi_cpp/service/ccapi_service.h @@ -491,6 +491,8 @@ class Service : public std::enable_shared_from_this { } return streamPtr; } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else template <> std::shared_ptr>> createStream(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, @@ -505,6 +507,7 @@ class Service : public std::enable_shared_from_this { } return streamPtr; } +#endif // std::shared_ptr> createStream(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, // const std::string& host) { // std::shared_ptr> streamPtr(new beast::ssl_stream(*iocPtr, *ctxPtr)); @@ -1195,25 +1198,6 @@ class Service : public std::enable_shared_from_this { std::string url = wsConnection.url; CCAPI_LOGGER_DEBUG("url = " + url); this->startConnectWs(wsConnectionPtr, this->sessionOptions.websocketConnectTimeoutMilliSeconds, this->tcpResolverResultsWs); - // for (const auto& kv : wsConnection.headers) { - // con->append_header(kv.first, kv.second); - // } - // wsConnection.id = this->connectionAddressToString(con); - // CCAPI_LOGGER_DEBUG("connection initialization on actual id " + wsConnection.id); - // if (ec) { - // CCAPI_LOGGER_FATAL("connection initialization error: " + ec.message()); - // } - // this->wsConnectionByIdMap.insert(std::pair(wsConnection.id, wsConnection)); - // CCAPI_LOGGER_DEBUG("this->wsConnectionByIdMap = " + toString(this->wsConnectionByIdMap)); - // con->set_open_handler(std::bind(&Service::onOpen, shared_from_this(), std::placeholders::_1)); - // con->set_fail_handler(std::bind(&Service::onFail, shared_from_this(), std::placeholders::_1)); - // con->set_close_handler(std::bind(&Service::onClose, shared_from_this(), std::placeholders::_1)); - // con->set_message_handler(std::bind(&Service::onMessage, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); - // if (this->sessionOptions.enableCheckPingPongWebsocketProtocolLevel) { - // con->set_pong_handler(std::bind(&Service::onPong, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); - // } - // con->set_ping_handler(std::bind(&Service::onPing, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); - // this->serviceContextPtr->tlsClientPtr->connect(con); CCAPI_LOGGER_FUNCTION_EXIT; } void startConnectWs(std::shared_ptr wsConnectionPtr, long timeoutMilliSeconds, tcp::resolver::results_type tcpResolverResults) { From 12a5b77e08a441ee529fc5441786b45d841917da Mon Sep 17 00:00:00 2001 From: Crypto Chassis Date: Sat, 18 Mar 2023 14:42:40 -0700 Subject: [PATCH 3/7] test: fix runtime errors --- .../ccapi_execution_management_service_ascendex.h | 6 ++++++ .../ccapi_execution_management_service_binance.h | 6 ++++++ ...cution_management_service_binance_coin_futures.h | 6 ++++++ ...pi_execution_management_service_binance_margin.h | 6 ++++++ .../ccapi_execution_management_service_binance_us.h | 6 ++++++ ...cution_management_service_binance_usds_futures.h | 6 ++++++ .../ccapi_execution_management_service_bitfinex.h | 6 ++++++ .../ccapi_execution_management_service_bitget.h | 6 ++++++ ...pi_execution_management_service_bitget_futures.h | 6 ++++++ .../ccapi_execution_management_service_bitmart.h | 6 ++++++ .../ccapi_execution_management_service_bitmex.h | 6 ++++++ .../ccapi_execution_management_service_bitstamp.h | 6 ++++++ .../ccapi_execution_management_service_bybit.h | 6 ++++++ ...execution_management_service_bybit_derivatives.h | 6 ++++++ .../ccapi_execution_management_service_coinbase.h | 6 ++++++ .../ccapi_execution_management_service_cryptocom.h | 6 ++++++ .../ccapi_execution_management_service_deribit.h | 6 ++++++ .../ccapi_execution_management_service_erisx.h | 6 ++++++ .../ccapi_execution_management_service_ftx.h | 6 ++++++ .../ccapi_execution_management_service_ftx_us.h | 6 ++++++ .../ccapi_execution_management_service_gateio.h | 6 ++++++ ...on_management_service_gateio_perpetual_futures.h | 6 ++++++ .../ccapi_execution_management_service_gemini.h | 6 ++++++ .../ccapi_execution_management_service_huobi.h | 6 ++++++ ...i_execution_management_service_huobi_coin_swap.h | 6 ++++++ ...i_execution_management_service_huobi_usdt_swap.h | 6 ++++++ .../ccapi_execution_management_service_kraken.h | 6 ++++++ ...pi_execution_management_service_kraken_futures.h | 6 ++++++ .../ccapi_execution_management_service_kucoin.h | 6 ++++++ ...pi_execution_management_service_kucoin_futures.h | 6 ++++++ .../ccapi_execution_management_service_mexc.h | 6 ++++++ ...capi_execution_management_service_mexc_futures.h | 6 ++++++ .../ccapi_execution_management_service_okx.h | 6 ++++++ .../service/ccapi_market_data_service_ascendex.h | 6 ++++++ .../service/ccapi_market_data_service_binance.h | 6 ++++++ ...ccapi_market_data_service_binance_coin_futures.h | 6 ++++++ .../service/ccapi_market_data_service_binance_us.h | 6 ++++++ ...ccapi_market_data_service_binance_usds_futures.h | 6 ++++++ .../service/ccapi_market_data_service_bitfinex.h | 6 ++++++ .../service/ccapi_market_data_service_bitget.h | 6 ++++++ .../ccapi_market_data_service_bitget_futures.h | 6 ++++++ .../service/ccapi_market_data_service_bitmart.h | 6 ++++++ .../service/ccapi_market_data_service_bitmex.h | 6 ++++++ .../service/ccapi_market_data_service_bitstamp.h | 6 ++++++ .../service/ccapi_market_data_service_bybit.h | 6 ++++++ .../ccapi_market_data_service_bybit_derivatives.h | 6 ++++++ .../service/ccapi_market_data_service_coinbase.h | 6 ++++++ .../service/ccapi_market_data_service_cryptocom.h | 6 ++++++ .../service/ccapi_market_data_service_deribit.h | 6 ++++++ .../service/ccapi_market_data_service_ftx.h | 6 ++++++ .../service/ccapi_market_data_service_ftx_us.h | 6 ++++++ .../service/ccapi_market_data_service_gateio.h | 6 ++++++ ...i_market_data_service_gateio_perpetual_futures.h | 6 ++++++ .../service/ccapi_market_data_service_gemini.h | 6 ++++++ .../service/ccapi_market_data_service_huobi.h | 6 ++++++ .../ccapi_market_data_service_huobi_coin_swap.h | 6 ++++++ .../ccapi_market_data_service_huobi_usdt_swap.h | 6 ++++++ .../service/ccapi_market_data_service_kraken.h | 6 ++++++ .../ccapi_market_data_service_kraken_futures.h | 6 ++++++ .../service/ccapi_market_data_service_kucoin.h | 6 ++++++ .../ccapi_market_data_service_kucoin_futures.h | 6 ++++++ .../service/ccapi_market_data_service_mexc.h | 6 ++++++ .../ccapi_market_data_service_mexc_futures.h | 6 ++++++ .../service/ccapi_market_data_service_okx.h | 6 ++++++ .../service/ccapi_market_data_service_whitebit.h | 6 ++++++ include/ccapi_cpp/service/ccapi_service.h | 13 ++++++++----- include/ccapi_cpp/service/ccapi_service_context.h | 2 +- 67 files changed, 399 insertions(+), 6 deletions(-) diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h index a19fff4f..df631454 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceAscendex : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_ASCENDEX_API_KEY; this->apiSecretName = CCAPI_ASCENDEX_API_SECRET; this->apiAccountGroupName = CCAPI_ASCENDEX_API_ACCOUNT_GROUP; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h index ee73bbe2..c0db038f 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h @@ -16,11 +16,17 @@ class ExecutionManagementServiceBinance : public ExecutionManagementServiceBinan this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_API_KEY; this->apiSecretName = CCAPI_BINANCE_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h index 209cca11..1aed6382 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBinanceCoinFutures : public ExecutionManagementS this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_COIN_FUTURES_API_KEY; this->apiSecretName = CCAPI_BINANCE_COIN_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h index e6bc7c26..0cd6f8da 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBinanceMargin : public ExecutionManagementServic this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_MARGIN_API_KEY; this->apiSecretName = CCAPI_BINANCE_MARGIN_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h index 9f2992c1..6a6a2a91 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBinanceUs : public ExecutionManagementServiceBin this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_US_API_KEY; this->apiSecretName = CCAPI_BINANCE_US_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h index 829a35f3..9f3c52e1 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBinanceUsdsFutures : public ExecutionManagementS this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_USDS_FUTURES_API_KEY; this->apiSecretName = CCAPI_BINANCE_USDS_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h index fe31cc0e..767268d3 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBitfinex : public ExecutionManagementService { this->baseUrlWs = std::string(CCAPI_BITFINEX_PRIVATE_URL_WS_BASE) + "/ws/2"; this->baseUrlRest = CCAPI_BITFINEX_PRIVATE_URL_REST_BASE; this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BITFINEX_API_KEY; this->apiSecretName = CCAPI_BITFINEX_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h index 5bbdd422..990c12f8 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBitget : public ExecutionManagementServiceBitget this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BITGET_API_KEY; this->apiSecretName = CCAPI_BITGET_API_SECRET; this->apiPassphraseName = CCAPI_BITGET_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h index cdef55b3..3fed9d42 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBitgetFutures : public ExecutionManagementServic this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/mix/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BITGET_FUTURES_API_KEY; this->apiSecretName = CCAPI_BITGET_FUTURES_API_SECRET; this->apiPassphraseName = CCAPI_BITGET_FUTURES_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h index 2a96e6ca..0eb464eb 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBitmart : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/user?protocol=1.1"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BITMART_API_KEY; this->apiSecretName = CCAPI_BITMART_API_SECRET; this->apiMemoName = CCAPI_BITMART_API_MEMO; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h index 2dedc4b6..e415ed0d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBitmex : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/realtime"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BITMEX_API_KEY; this->apiSecretName = CCAPI_BITMEX_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h index 7cd28cec..4f4dd43d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BITSTAMP_API_KEY; this->apiSecretName = CCAPI_BITSTAMP_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h index f410ae9e..02c3994e 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBybit : public ExecutionManagementServiceBybitBa this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/private/v3"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BYBIT_API_KEY; this->apiSecretName = CCAPI_BYBIT_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h index 7a6082cd..c37a9eaa 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceBybitDerivatives : public ExecutionManagementSer this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/unified/private/v3"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BYBIT_DERIVATIVES_API_KEY; this->apiSecretName = CCAPI_BYBIT_DERIVATIVES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h index 61a2e938..df86622d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceCoinbase : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_COINBASE_API_KEY; this->apiSecretName = CCAPI_COINBASE_API_SECRET; this->apiPassphraseName = CCAPI_COINBASE_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h index 12baa19f..f7270736 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceCryptocom : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v2/user"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_CRYPTOCOM_API_KEY; this->apiSecretName = CCAPI_CRYPTOCOM_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h index 0193b63f..579058a2 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceDeribit : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/api/v2"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->clientIdName = CCAPI_DERIBIT_CLIENT_ID; this->clientSecretName = CCAPI_DERIBIT_CLIENT_SECRET; this->setupCredential({this->clientIdName, this->clientSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h index 815baa55..18967a16 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceErisx : public ExecutionManagementService { this->exchangeName = CCAPI_EXCHANGE_NAME_ERISX; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_ERISX_API_KEY; this->apiSecretName = CCAPI_ERISX_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h index 9697f65d..4ba3eac5 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceFtx : public ExecutionManagementServiceFtxBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_FTX_API_KEY; this->apiSecretName = CCAPI_FTX_API_SECRET; this->apiSubaccountName = CCAPI_FTX_API_SUBACCOUNT; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h index 09e9f7cd..53d672e7 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceFtxUs : public ExecutionManagementServiceFtxBase this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_FTX_US_API_KEY; this->apiSecretName = CCAPI_FTX_US_API_SECRET; this->apiSubaccountName = CCAPI_FTX_US_API_SUBACCOUNT; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h index a4d32079..b27b9b7b 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceGateio : public ExecutionManagementServiceGateio this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v4/"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_GATEIO_API_KEY; this->apiSecretName = CCAPI_GATEIO_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h index c9f01f81..767f50d1 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceGateioPerpetualFutures : public ExecutionManagem this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v4/ws/"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_GATEIO_PERPETUAL_FUTURES_API_KEY; this->apiSecretName = CCAPI_GATEIO_PERPETUAL_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h index 90b1de36..8459ea07 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceGemini : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v1/order/events"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_GEMINI_API_KEY; this->apiSecretName = CCAPI_GEMINI_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h index a6195a4f..ba334b7e 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceHuobi : public ExecutionManagementServiceHuobiBa this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v2"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_HUOBI_API_KEY; this->apiSecretName = CCAPI_HUOBI_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h index 7eee7329..5f77f577 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceHuobiCoinSwap : public ExecutionManagementServic this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/swap-notification"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_HUOBI_COIN_SWAP_API_KEY; this->apiSecretName = CCAPI_HUOBI_COIN_SWAP_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h index bcc17d32..5bd004c2 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceHuobiUsdtSwap : public ExecutionManagementServic this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/linear-swap-notification"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_HUOBI_USDT_SWAP_API_KEY; this->apiSecretName = CCAPI_HUOBI_USDT_SWAP_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h index 423bfac1..398a23aa 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h @@ -14,11 +14,17 @@ class ExecutionManagementServiceKraken : public ExecutionManagementService { this->baseUrlWs = CCAPI_KRAKEN_URL_WS_BASE_PRIVATE; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_KRAKEN_API_KEY; this->apiSecretName = CCAPI_KRAKEN_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h index d56cc076..15c80f71 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h @@ -14,11 +14,17 @@ class ExecutionManagementServiceKrakenFutures : public ExecutionManagementServic this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v1"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_KRAKEN_FUTURES_API_KEY; this->apiSecretName = CCAPI_KRAKEN_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h index b7e54013..2abf28ff 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceKucoin : public ExecutionManagementServiceKucoin this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_KUCOIN_API_KEY; this->apiSecretName = CCAPI_KUCOIN_API_SECRET; this->apiPassphraseName = CCAPI_KUCOIN_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h index 394f1867..0257dd08 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceKucoinFutures : public ExecutionManagementServic this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_KUCOIN_FUTURES_API_KEY; this->apiSecretName = CCAPI_KUCOIN_FUTURES_API_SECRET; this->apiPassphraseName = CCAPI_KUCOIN_FUTURES_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h index 36f8cd54..716992ca 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h @@ -14,11 +14,17 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_MEXC_API_KEY; this->apiSecretName = CCAPI_MEXC_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h index 35486f31..efec5c18 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceMexcFutures : public ExecutionManagementService this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_MEXC_FUTURES_API_KEY; this->apiSecretName = CCAPI_MEXC_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h index 115842fa..972f5d1b 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h @@ -13,11 +13,17 @@ class ExecutionManagementServiceOkx : public ExecutionManagementService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + CCAPI_OKX_PRIVATE_WS_PATH; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_OKX_API_KEY; this->apiSecretName = CCAPI_OKX_API_SECRET; this->apiPassphraseName = CCAPI_OKX_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h index 6126da33..43226fdf 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h @@ -13,11 +13,17 @@ class MarketDataServiceAscendex : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/api/pro/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/pro/v1/trades"; this->getInstrumentTarget = "/api/pro/v1/products"; this->getInstrumentsTarget = "/api/pro/v1/products"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h index 1096a48a..b3967ed2 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h @@ -13,11 +13,17 @@ class MarketDataServiceBinance : public MarketDataServiceBinanceBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_API_KEY; this->setupCredential({this->apiKeyName}); this->getRecentTradesTarget = "/api/v3/trades"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h index f85ec135..5336a4c0 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h @@ -13,11 +13,17 @@ class MarketDataServiceBinanceCoinFutures : public MarketDataServiceBinanceDeriv this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_COIN_FUTURES_API_KEY; this->setupCredential({this->apiKeyName}); this->getRecentTradesTarget = "/dapi/v1/trades"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h index f0927dc8..202f757b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h @@ -13,11 +13,17 @@ class MarketDataServiceBinanceUs : public MarketDataServiceBinanceBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_US_API_KEY; this->setupCredential({this->apiKeyName}); this->getRecentTradesTarget = "/api/v3/trades"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h index 6b685b4c..b55817a1 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h @@ -13,11 +13,17 @@ class MarketDataServiceBinanceUsdsFutures : public MarketDataServiceBinanceDeriv this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BINANCE_USDS_FUTURES_API_KEY; this->setupCredential({this->apiKeyName}); this->getRecentTradesTarget = "/fapi/v1/trades"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h index d433fb96..149a5e6f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h @@ -13,11 +13,17 @@ class MarketDataServiceBitfinex : public MarketDataService { this->baseUrlWs = std::string(CCAPI_BITFINEX_PUBLIC_URL_WS_BASE) + "/ws/2"; this->baseUrlRest = CCAPI_BITFINEX_PUBLIC_URL_REST_BASE; this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/v2/trades/{Symbol}/hist"; this->getInstrumentsTarget = CCAPI_BITFINEX_GET_INSTRUMENTS_PATH; this->getInstrumentTarget = CCAPI_BITFINEX_GET_INSTRUMENTS_PATH; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h index 954d48b8..ed675bd3 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h @@ -13,11 +13,17 @@ class MarketDataServiceBitget : public MarketDataServiceBitgetBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/spot/v1/market/fills"; this->getInstrumentTarget = "/api/spot/v1/public/product"; this->getInstrumentsTarget = "/api/spot/v1/public/products"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h index 4a7b9281..bc402c52 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h @@ -13,11 +13,17 @@ class MarketDataServiceBitgetFutures : public MarketDataServiceBitgetBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/mix/v1/stream"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/mix/v1/market/fills"; this->getInstrumentTarget = "/api/mix/v1/market/contracts"; this->getInstrumentsTarget = "/api/mix/v1/market/contracts"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h index 67105591..7c2a8c27 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h @@ -18,11 +18,17 @@ class MarketDataServiceBitmart : public MarketDataService { // } this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_BITMART_API_KEY; this->apiSecretName = CCAPI_BITMART_API_SECRET; this->apiMemo = CCAPI_BITMART_API_MEMO; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h index 4b20b7d3..71fb7caa 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h @@ -13,11 +13,17 @@ class MarketDataServiceBitmex : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/realtime"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/v1/trade"; this->getInstrumentTarget = "/api/v1/instrument"; this->getInstrumentsTarget = "/api/v1/instrument"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h index d29aa447..412acac0 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h @@ -14,11 +14,17 @@ class MarketDataServiceBitstamp : public MarketDataService { this->enableCheckPingPongWebsocketApplicationLevel = false; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/v2/transactions/{currency_pair}/"; // must have trailing slash this->getInstrumentTarget = "/api/v2/trading-pairs-info/"; this->getInstrumentsTarget = "/api/v2/trading-pairs-info/"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h index 9ac68d85..78dfabde 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h @@ -13,11 +13,17 @@ class MarketDataServiceBybit : public MarketDataServiceBybitBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/spot/public/v3"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/spot/v3/public/quote/trades"; this->getInstrumentsTarget = "/spot/v3/public/symbols"; } diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h b/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h index a1b93111..cb5031fe 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h @@ -13,11 +13,17 @@ class MarketDataServiceBybitDerivatives : public MarketDataServiceBybitBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/{instrumentTypeSubstitute}/public/v3"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/derivatives/v3/public/recent-trade"; this->getInstrumentTarget = "/derivatives/v3/public/instruments-info"; this->getInstrumentsTarget = "/derivatives/v3/public/instruments-info"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h index c9a68aa8..0a39f227 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h @@ -13,11 +13,17 @@ class MarketDataServiceCoinbase : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/products//trades"; this->getInstrumentTarget = "/products/"; this->getInstrumentsTarget = "/products"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h index 51a89dbd..02f95ab5 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h @@ -13,11 +13,17 @@ class MarketDataServiceCryptocom : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v2/market"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/v2/public/get-trades"; this->getInstrumentTarget = "/v2/public/get-instruments"; this->getInstrumentsTarget = "/v2/public/get-instruments"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h index d902cfba..0d613c3f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h @@ -13,11 +13,17 @@ class MarketDataServiceDeribit : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/api/v2"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->restTarget = "/api/v2"; this->getRecentTradesTarget = "/public/get_last_trades_by_instrument"; this->getInstrumentTarget = "/public/get_instrument"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h index 56f4309e..0b8730cd 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h @@ -13,11 +13,17 @@ class MarketDataServiceFtx : public MarketDataServiceFtxBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } } virtual ~MarketDataServiceFtx() {} }; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h index 6683aa39..3c9a23d5 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h @@ -13,11 +13,17 @@ class MarketDataServiceFtxUs : public MarketDataServiceFtxBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } } virtual ~MarketDataServiceFtxUs() {} }; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h index 0221250b..ee0c119a 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h @@ -13,11 +13,17 @@ class MarketDataServiceGateio : public MarketDataServiceGateioBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v4/"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_GATEIO_API_KEY; this->setupCredential({this->apiKeyName}); std::string prefix = "/api/v4"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h index 12736fd7..7f21a88f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h @@ -13,11 +13,17 @@ class MarketDataServiceGateioPerpetualFutures : public MarketDataServiceGateioBa this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v4/ws/"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_GATEIO_PERPETUAL_FUTURES_API_KEY; this->setupCredential({this->apiKeyName}); std::string prefix = "/api/v4"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h index 9b0e5504..a6b0021b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h @@ -13,11 +13,17 @@ class MarketDataServiceGemini : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/v1/marketdata"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/v1/trades/:symbol"; this->getInstrumentTarget = "/v1/symbols/details/:symbol"; this->getInstrumentsTarget = "/v1/symbols"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h index e9811b24..cab99a85 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h @@ -13,11 +13,17 @@ class MarketDataServiceHuobi : public MarketDataServiceHuobiBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/market/history/trade"; this->getInstrumentTarget = "/v1/common/symbols"; this->getInstrumentsTarget = "/v1/common/symbols"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h index c535631e..54031f4e 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h @@ -13,11 +13,17 @@ class MarketDataServiceHuobiCoinSwap : public MarketDataServiceHuobiDerivativesB this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/swap-ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = CCAPI_HUOBI_COIN_SWAP_GET_RECENT_TRADES_PATH; this->getInstrumentTarget = "/swap-api/v1/swap_contract_info"; this->getInstrumentsTarget = "/swap-api/v1/swap_contract_info"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h index 14e6241c..baec819f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h @@ -13,11 +13,17 @@ class MarketDataServiceHuobiUsdtSwap : public MarketDataServiceHuobiDerivativesB this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/linear-swap-ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = CCAPI_HUOBI_USDT_SWAP_GET_RECENT_TRADES_PATH; this->getInstrumentTarget = "/linear-swap-api/v1/swap_contract_info"; this->getInstrumentsTarget = "/linear-swap-api/v1/swap_contract_info"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h index 8f2d6dae..58334ead 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h @@ -13,11 +13,17 @@ class MarketDataServiceKraken : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/0/public/Trades"; this->getInstrumentTarget = "/0/public/AssetPairs"; this->getInstrumentsTarget = "/0/public/AssetPairs"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h index d0f8fe2c..9dcd0003 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h @@ -13,11 +13,17 @@ class MarketDataServiceKrakenFutures : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws/v1"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } std::string prefix("/derivatives/api/v3"); this->getRecentTradesTarget = prefix + "/history"; this->getInstrumentTarget = prefix + "/instruments"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h index 38e3a947..0f174f47 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h @@ -13,11 +13,17 @@ class MarketDataServiceKucoin : public MarketDataServiceKucoinBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_KUCOIN_API_KEY; this->apiSecretName = CCAPI_KUCOIN_API_SECRET; this->apiPassphraseName = CCAPI_KUCOIN_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h index 8eeb1f59..3268eb75 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h @@ -13,11 +13,17 @@ class MarketDataServiceKucoinFutures : public MarketDataServiceKucoinBase { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/v1/trade/history"; this->getInstrumentTarget = "/api/v1/contracts/active"; this->getInstrumentsTarget = "/api/v1/contracts/active"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h index 2d4349cd..ec90a0a1 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h @@ -13,11 +13,17 @@ class MarketDataServiceMexc : public MarketDataService { this->baseUrlWs = std::string(CCAPI_MEXC_URL_WS_BASE) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/v3/trades"; this->getRecentAggTradesTarget = "/api/v3/aggTrades"; this->getInstrumentsTarget = "/api/v3/exchangeInfo"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h index 5918662b..f3f6a116 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h @@ -13,11 +13,17 @@ class MarketDataServiceMexcFutures : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/v1/contract/deals/{symbol}"; this->getInstrumentsTarget = "/api/v1/contract/detail"; } diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h index f15d622c..3acfc5c3 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h @@ -18,11 +18,17 @@ class MarketDataServiceOkx : public MarketDataService { // } this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->apiKeyName = CCAPI_OKX_API_KEY; this->apiSecretName = CCAPI_OKX_API_SECRET; this->apiPassphraseName = CCAPI_OKX_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h index 848c4974..4356d491 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h @@ -13,11 +13,17 @@ class MarketDataServiceWhitebit : public MarketDataService { this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); + this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } + try { + this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); + } catch (const std::exception& e) { + CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + } this->getRecentTradesTarget = "/api/v4/public/trades/{market}"; this->getInstrumentsTarget = "/api/v4/public/markets"; this->methodDepthSubscribe = std::string(CCAPI_WEBSOCKET_WHITEBIT_CHANNEL_MARKET_DEPTH) + "_subscribe"; diff --git a/include/ccapi_cpp/service/ccapi_service.h b/include/ccapi_cpp/service/ccapi_service.h index 081fb64c..c119c7c2 100644 --- a/include/ccapi_cpp/service/ccapi_service.h +++ b/include/ccapi_cpp/service/ccapi_service.h @@ -321,7 +321,7 @@ class Service : public std::enable_shared_from_this { if (splitted2.size() == 2) { port = splitted2[1]; } else { - if (splitted1[0] == "https") { + if (splitted1[0] == "https" || splitted1[0] == "wss") { port = CCAPI_HTTPS_PORT_DEFAULT; } else { port = CCAPI_HTTP_PORT_DEFAULT; @@ -497,6 +497,7 @@ class Service : public std::enable_shared_from_this { std::shared_ptr>> createStream(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, const std::string& host) { + CCAPI_LOGGER_TRACE("host = " + host) std::shared_ptr>> streamPtr( new beast::websocket::stream>(*iocPtr, *ctxPtr)); // Set SNI Hostname (many hosts need this to handshake successfully) @@ -666,10 +667,11 @@ class Service : public std::enable_shared_from_this { this->processSuccessfulTextMessageRest(statusCode, request, body, now, eventQueuePtr); } else if (statusCode / 100 == 3) { if (resPtr->base().find("Location") != resPtr->base().end()) { - Url url(resPtr->base().at("Location") + Url url(resPtr->base() + .at("Location") #if BOOST_VERSION < 108100 - // Boost Beast 1.81 uses boost::core::string_view which doesn't contain to_string() method - .to_string() + // Boost Beast 1.81 uses boost::core::string_view which doesn't contain to_string() method + .to_string() #endif ); std::string host(url.host); @@ -1222,6 +1224,7 @@ class Service : public std::enable_shared_from_this { return; } CCAPI_LOGGER_TRACE("connected"); + CCAPI_LOGGER_TRACE("ep.port() = " + std::to_string(ep.port())); wsConnectionPtr->hostHttpHeaderValue = this->hostWs + ':' + std::to_string(ep.port()); beast::websocket::stream>& stream = *wsConnectionPtr->streamPtr; beast::get_lowest_layer(stream).socket().set_option(tcp::no_delay(true)); @@ -1516,8 +1519,8 @@ class Service : public std::enable_shared_from_this { } auto& stream = *wsConnectionPtr->streamPtr; if (stream.got_text()) { - CCAPI_LOGGER_DEBUG(std::string("received a text message: ") + data); boost::beast::string_view textMessage(data, dataSize); + CCAPI_LOGGER_DEBUG(std::string("received a text message: ") + std::string(textMessage)); try { this->onTextMessage(wsConnectionPtr, textMessage, now); } catch (const std::exception& e) { diff --git a/include/ccapi_cpp/service/ccapi_service_context.h b/include/ccapi_cpp/service/ccapi_service_context.h index 033f9560..60618c6f 100644 --- a/include/ccapi_cpp/service/ccapi_service_context.h +++ b/include/ccapi_cpp/service/ccapi_service_context.h @@ -83,7 +83,7 @@ class ServiceContext CCAPI_FINAL { typedef boost::asio::ssl::context SslContext; typedef std::shared_ptr SslContextPtr; ServiceContext() { - this->sslContextPtr->set_options(SslContext::default_workarounds | SslContext::no_sslv2 | SslContext::no_sslv3 | SslContext::single_dh_use); + // this->sslContextPtr->set_options(SslContext::default_workarounds | SslContext::no_sslv2 | SslContext::no_sslv3 | SslContext::single_dh_use); this->sslContextPtr->set_verify_mode(boost::asio::ssl::verify_none); // TODO(cryptochassis): verify ssl certificate to strengthen security // https://github.com/boostorg/asio/blob/develop/example/cpp03/ssl/client.cpp From 5cd00d0118e0d5c8e5a5d16c475c6f5759c0d026 Mon Sep 17 00:00:00 2001 From: Crypto Chassis Date: Sun, 26 Mar 2023 12:21:28 -0700 Subject: [PATCH 4/7] test: fix runtime errors --- include/ccapi_cpp/ccapi_inflate_stream.h | 95 +++++++++++++++++++ .../ccapi_execution_management_service.h | 18 ++-- ...cution_management_service_binance_margin.h | 43 --------- ...api_execution_management_service_bitmart.h | 4 + .../ccapi_execution_management_service_okx.h | 22 ++++- .../ccapi_market_data_service_bitmart.h | 5 - .../ccapi_market_data_service_huobi_base.h | 35 ++++++- .../service/ccapi_market_data_service_okx.h | 5 - include/ccapi_cpp/service/ccapi_service.h | 67 ++++++++----- 9 files changed, 198 insertions(+), 96 deletions(-) create mode 100644 include/ccapi_cpp/ccapi_inflate_stream.h delete mode 100644 include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h diff --git a/include/ccapi_cpp/ccapi_inflate_stream.h b/include/ccapi_cpp/ccapi_inflate_stream.h new file mode 100644 index 00000000..6a715673 --- /dev/null +++ b/include/ccapi_cpp/ccapi_inflate_stream.h @@ -0,0 +1,95 @@ +#ifndef INCLUDE_CCAPI_CPP_CCAPI_INFLATE_STREAM_H_ +#define INCLUDE_CCAPI_CPP_CCAPI_INFLATE_STREAM_H_ +#ifndef CCAPI_DECOMPRESS_BUFFER_SIZE +#define CCAPI_DECOMPRESS_BUFFER_SIZE 1 << 20 +#endif +#include "zlib.h" +namespace ccapi { +/** + * Due to Huobi using gzip instead of zip in data compression, we cannot use beast::zboost::system::inflate_stream. Therefore we have to create our own. + */ +class InflateStream CCAPI_FINAL { + public: + explicit InflateStream() { + this->windowBits = 15; + this->windowBitsOverride = 0; + this->istate.zalloc = Z_NULL; + this->istate.zfree = Z_NULL; + this->istate.opaque = Z_NULL; + this->istate.avail_in = 0; + this->istate.next_in = Z_NULL; + this->decompressBufferSize = CCAPI_DECOMPRESS_BUFFER_SIZE; + } + std::string toString() const { + std::string output = "InflateStream [windowBits = " + ccapi::toString(windowBits) + "]"; + return output; + } + virtual ~InflateStream() { + if (!this->initialized) { + return; + } + int ret = inflateEnd(&this->istate); + if (ret != Z_OK) { + CCAPI_LOGGER_ERROR("error cleaning up zlib decompression state"); + } + } + void setWindowBitsOverride(int windowBitsOverride) { this->windowBitsOverride = windowBitsOverride; } + boost::system::error_code init() { + int ret; + if (this->windowBitsOverride == 0) { + ret = inflateInit2(&this->istate, -1 * this->windowBits); + } else { + ret = inflateInit2(&this->istate, this->windowBitsOverride + // 31 + ); + } + if (ret != Z_OK) { + CCAPI_LOGGER_ERROR("decompress error"); + return boost::system::error_code(); + } + this->buffer.reset(new unsigned char[this->decompressBufferSize]); + this->initialized = true; + return boost::system::error_code(); + } + boost::system::error_code decompress(uint8_t const *buf, size_t len, std::string &out) { + if (!this->initialized) { + CCAPI_LOGGER_ERROR("decompress error"); + return boost::system::error_code(); + } + int ret; + this->istate.avail_in = len; + this->istate.next_in = const_cast(buf); + do { + this->istate.avail_out = this->decompressBufferSize; + this->istate.next_out = this->buffer.get(); + int ret = inflate(&this->istate, Z_SYNC_FLUSH); + if (ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) { + CCAPI_LOGGER_ERROR("decompress error"); + return boost::system::error_code(); + } + out.append(reinterpret_cast(this->buffer.get()), this->decompressBufferSize - this->istate.avail_out); + } while (this->istate.avail_out == 0); + return boost::system::error_code(); + } + boost::system::error_code inflate_reset() { + int ret = inflateReset(&this->istate); + if (ret != Z_OK) { + CCAPI_LOGGER_ERROR("decompress error"); + return boost::system::error_code(); + } + return boost::system::error_code(); + } +#ifndef CCAPI_EXPOSE_INTERNAL + + private: +#endif + int windowBits; + int windowBitsOverride; + bool initialized; + std::unique_ptr buffer; + z_stream istate; + size_t decompressBufferSize; +}; + +} /* namespace ccapi */ +#endif // INCLUDE_CCAPI_CPP_CCAPI_INFLATE_STREAM_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service.h b/include/ccapi_cpp/service/ccapi_execution_management_service.h index 41f8b0ab..0e5544d9 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service.h @@ -179,6 +179,12 @@ class ExecutionManagementService : public Service { } } } + virtual void convertRequestForWebsocketCustom(rj::Document& document, rj::Document::AllocatorType& allocator, const WsConnection& wsConnection, + const Request& request, int wsRequestId, const TimePoint& now, const std::string& symbolId, + const std::map& credential) { + auto errorMessage = "Websocket unimplemented operation " + Request::operationToString(request.getOperation()) + " for exchange " + request.getExchange(); + throw std::runtime_error(errorMessage); + } #ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET virtual void logonToExchange(const WsConnection& wsConnection, const TimePoint& now, const std::map& credential) { CCAPI_LOGGER_INFO("about to logon to exchange"); @@ -221,12 +227,6 @@ class ExecutionManagementService : public Service { this->wsRequestIdByConnectionIdMap.erase(wsConnection.id); Service::onClose(hdl); } - virtual void convertRequestForWebsocketCustom(rj::Document& document, rj::Document::AllocatorType& allocator, const WsConnection& wsConnection, - const Request& request, int wsRequestId, const TimePoint& now, const std::string& symbolId, - const std::map& credential) { - auto errorMessage = "Websocket unimplemented operation " + Request::operationToString(request.getOperation()) + " for exchange " + request.getExchange(); - throw std::runtime_error(errorMessage); - } virtual void onTextMessage(const WsConnection& wsConnection, const Subscription& subscription, const std::string& textMessage, const TimePoint& timeReceived) {} #else @@ -271,12 +271,6 @@ class ExecutionManagementService : public Service { this->wsRequestIdByConnectionIdMap.erase(wsConnection.id); Service::onClose(wsConnectionPtr, ec); } - virtual void convertRequestForWebsocketCustom(rj::Document& document, rj::Document::AllocatorType& allocator, std::shared_ptr wsConnectionPtr, - const Request& request, int wsRequestId, const TimePoint& now, const std::string& symbolId, - const std::map& credential) { - auto errorMessage = "Websocket unimplemented operation " + Request::operationToString(request.getOperation()) + " for exchange " + request.getExchange(); - throw std::runtime_error(errorMessage); - } virtual void onTextMessage(std::shared_ptr wsConnectionPtr, const Subscription& subscription, boost::beast::string_view textMessage, const TimePoint& timeReceived) {} #endif diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h deleted file mode 100644 index 0cd6f8da..00000000 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_margin.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_MARGIN_H_ -#define INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_MARGIN_H_ -#ifdef CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT -#ifdef CCAPI_ENABLE_EXCHANGE_BINANCE_MARGIN -#include "ccapi_cpp/service/ccapi_execution_management_service_binance_base.h" -namespace ccapi { -class ExecutionManagementServiceBinanceMargin : public ExecutionManagementServiceBinanceBase { - public: - ExecutionManagementServiceBinanceMargin(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - ServiceContextPtr serviceContextPtr) - : ExecutionManagementServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { - this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_MARGIN; - this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; - this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); - this->setHostRestFromUrlRest(this->baseUrlRest); - this->setHostWsFromUrlWs(this->baseUrlWs); - try { - this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); - } catch (const std::exception& e) { - CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); - } - try { - this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); - } catch (const std::exception& e) { - CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); - } - this->apiKeyName = CCAPI_BINANCE_MARGIN_API_KEY; - this->apiSecretName = CCAPI_BINANCE_MARGIN_API_SECRET; - this->setupCredential({this->apiKeyName, this->apiSecretName}); - this->createOrderTarget = "/sapi/v1/margin/order"; - this->cancelOrderTarget = "/sapi/v1/margin/order"; - this->getOrderTarget = "/sapi/v1/margin/order"; - this->getOpenOrdersTarget = "/sapi/v1/margin/openOrders"; - this->cancelOpenOrdersTarget = "/sapi/v1/margin/openOrders"; - this->listenKeyTarget = CCAPI_BINANCE_LISTEN_KEY_PATH; - this->getAccountBalancesTarget = "/sapi/v1/margin/account"; - } - virtual ~ExecutionManagementServiceBinanceMargin() {} -}; -} /* namespace ccapi */ -#endif -#endif -#endif // INCLUDE_CCAPI_CPP_SERVICE_CCAPI_EXECUTION_MANAGEMENT_SERVICE_BINANCE_MARGIN_H_ diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h index 0eb464eb..0d9df521 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h @@ -35,7 +35,11 @@ class ExecutionManagementServiceBitmart : public ExecutionManagementService { this->cancelOpenOrdersTarget = "/spot/v1/cancel_orders"; this->getAccountBalancesTarget = "/spot/v1/wallet"; this->needDecompressWebsocketMessage = true; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET ErrorCode ec = this->inflater.init(false); +#else + ErrorCode ec = this->inflater.init(); +#endif if (ec) { CCAPI_LOGGER_FATAL(ec.message()); } diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h index 972f5d1b..9c4e3ccf 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h @@ -41,7 +41,11 @@ class ExecutionManagementServiceOkx : public ExecutionManagementService { private: #endif +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET void pingOnApplicationLevel(wspp::connection_hdl hdl, ErrorCode& ec) override { this->send(hdl, "ping", wspp::frame::opcode::text, ec); } +#else + void pingOnApplicationLevel(std::shared_ptr wsConnectionPtr, ErrorCode& ec) override { this->send(wsConnectionPtr, "ping", ec); } +#endif bool doesHttpBodyContainError(const std::string& body) override { return !std::regex_search(body, std::regex("\"code\":\\s*\"0\"")); } void signReqeustForRestGenericPrivateRequest(http::request& req, const Request& request, std::string& methodString, std::string& headerString, std::string& path, std::string& queryString, std::string& body, const TimePoint& now, @@ -362,8 +366,18 @@ class ExecutionManagementServiceOkx : public ExecutionManagementService { sendStringList.push_back(sendString); return sendStringList; } - void onTextMessage(const WsConnection& wsConnection, const Subscription& subscription, const std::string& textMessage, - const TimePoint& timeReceived) override { + void onTextMessage( +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + const WsConnection& wsConnection, const Subscription& subscription, const std::string& textMessage +#else + std::shared_ptr wsConnectionPtr, const Subscription& subscription, boost::beast::string_view textMessageView +#endif + , + const TimePoint& timeReceived) override { +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else + std::string textMessage(textMessageView); +#endif if (textMessage != "pong") { rj::Document document; document.Parse(textMessage.c_str()); @@ -394,7 +408,11 @@ class ExecutionManagementServiceOkx : public ExecutionManagementService { document.Accept(writerSubscribe); std::string sendString = stringBufferSubscribe.GetString(); ErrorCode ec; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET this->send(wsConnection.hdl, sendString, wspp::frame::opcode::text, ec); +#else + this->send(wsConnectionPtr, sendString, ec); +#endif if (ec) { this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "subscribe"); } diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h index 7c2a8c27..a7a2572a 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h @@ -11,11 +11,6 @@ class MarketDataServiceBitmart : public MarketDataService { : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITMART; this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/api?protocol=1.1"; - // this->needDecompressWebsocketMessage = true; - // ErrorCode ec = this->inflater.init(false); - // if (ec) { - // CCAPI_LOGGER_FATAL(ec.message()); - // } this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); this->setHostWsFromUrlWs(this->baseUrlWs); diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h index e35b7e9a..59184e3f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h @@ -10,7 +10,12 @@ class MarketDataServiceHuobiBase : public MarketDataService { std::shared_ptr serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->needDecompressWebsocketMessage = true; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET ErrorCode ec = this->inflater.init(false, 31); +#else + this->inflater.setWindowBitsOverride(31); + ErrorCode ec = this->inflater.init(); +#endif if (ec) { CCAPI_LOGGER_FATAL(ec.message()); } @@ -21,10 +26,17 @@ class MarketDataServiceHuobiBase : public MarketDataService { protected: #endif +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET void pingOnApplicationLevel(wspp::connection_hdl hdl, ErrorCode& ec) override { auto now = UtilTime::now(); this->send(hdl, "{\"ping\":" + std::to_string(UtilTime::getUnixTimestamp(now)) + "}", wspp::frame::opcode::text, ec); } +#else + void pingOnApplicationLevel(std::shared_ptr wsConnectionPtr, ErrorCode& ec) override { + auto now = UtilTime::now(); + this->send(wsConnectionPtr, "{\"ping\":" + std::to_string(UtilTime::getUnixTimestamp(now)) + "}", ec); + } +#endif std::vector createSendStringList(const WsConnection& wsConnection) override { std::vector sendStringList; for (const auto& subscriptionListByChannelIdSymbolId : this->subscriptionListByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id)) { @@ -57,12 +69,12 @@ class MarketDataServiceHuobiBase : public MarketDataService { } if (channelId.rfind(CCAPI_WEBSOCKET_HUOBI_CHANNEL_MARKET_BY_PRICE_REFRESH_UPDATE, 0) == 0) { std::string toReplace("$levels"); - CCAPI_LOGGER_TRACE(""); + CCAPI_LOGGER_TRACE("marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap=" + toString(marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap)); std::string replacement( std::to_string(this->marketDepthSubscribedToExchangeByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id).at(channelId).at(symbolId))); - CCAPI_LOGGER_TRACE(""); + exchangeSubscriptionId.replace(exchangeSubscriptionId.find(toReplace), toReplace.length(), replacement); } document.AddMember("sub", rj::Value(exchangeSubscriptionId.c_str(), allocator).Move(), allocator); @@ -95,8 +107,19 @@ class MarketDataServiceHuobiBase : public MarketDataService { } return url + "|" + field + "|" + subscription.getSerializedOptions(); } - void processTextMessage(WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived, Event& event, - std::vector& marketDataMessageList) override { + void processTextMessage( +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET + WsConnection& wsConnection, wspp::connection_hdl hdl, const std::string& textMessage +#else + std::shared_ptr wsConnectionPtr, boost::beast::string_view textMessageView +#endif + , + const TimePoint& timeReceived, Event& event, std::vector& marketDataMessageList) override { +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else + WsConnection& wsConnection = *wsConnectionPtr; + std::string textMessage(textMessageView); +#endif rj::Document document; document.Parse(textMessage.c_str()); if (document.IsObject() && document.HasMember("ch") && document.HasMember("tick")) { @@ -243,7 +266,11 @@ class MarketDataServiceHuobiBase : public MarketDataService { payload += document["ping"].GetString(); payload += "}"; ErrorCode ec; +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET this->send(hdl, payload, wspp::frame::opcode::text, ec); +#else + this->send(wsConnectionPtr, payload, ec); +#endif if (ec) { this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, ec, "pong"); } diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h index 3acfc5c3..a27245ab 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h @@ -11,11 +11,6 @@ class MarketDataServiceOkx : public MarketDataService { : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_OKX; this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + CCAPI_OKX_PUBLIC_WS_PATH; - // this->needDecompressWebsocketMessage = true; - // ErrorCode ec = this->inflater.init(false); - // if (ec) { - // CCAPI_LOGGER_FATAL(ec.message()); - // } this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); this->setHostWsFromUrlWs(this->baseUrlWs); diff --git a/include/ccapi_cpp/service/ccapi_service.h b/include/ccapi_cpp/service/ccapi_service.h index c119c7c2..1e1fac34 100644 --- a/include/ccapi_cpp/service/ccapi_service.h +++ b/include/ccapi_cpp/service/ccapi_service.h @@ -41,6 +41,7 @@ #endif // clang-format on +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET #if defined(CCAPI_ENABLE_SERVICE_MARKET_DATA) && \ (defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP)) || \ defined(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) && \ @@ -50,6 +51,10 @@ #include "ccapi_cpp/websocketpp_decompress_workaround.h" #endif +#else +#include "ccapi_cpp/ccapi_inflate_stream.h" +#endif + #include "ccapi_cpp/ccapi_fix_connection.h" #include "ccapi_cpp/ccapi_http_connection.h" #include "ccapi_cpp/ccapi_http_retry.h" @@ -287,16 +292,16 @@ class Service : public std::enable_shared_from_this { protected: #endif - static std::string printableString(const char* s, size_t n) { - std::string output(s, n); - std::replace(output.begin(), output.end(), '\x01', '^'); - return output; - } - static std::string printableString(const std::string& s) { - std::string output(s); - std::replace(output.begin(), output.end(), '\x01', '^'); - return output; - } + // static std::string printableString(const char* s, size_t n) { + // std::string output(s, n); + // std::replace(output.begin(), output.end(), '\x01', '^'); + // return output; + // } + // static std::string printableString(const std::string& s) { + // std::string output(s); + // std::replace(output.begin(), output.end(), '\x01', '^'); + // return output; + // } typedef ServiceContext::SslContextPtr SslContextPtr; #ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET typedef ServiceContext::TlsClient TlsClient; @@ -1242,11 +1247,9 @@ class Service : public std::enable_shared_from_this { CCAPI_LOGGER_TRACE("ssl handshaked"); beast::websocket::stream>& stream = *wsConnectionPtr->streamPtr; beast::get_lowest_layer(stream).expires_never(); - beast::websocket::stream_base::timeout opt{std::chrono::milliseconds(this->sessionOptions.websocketConnectTimeoutMilliSeconds), std::chrono::milliseconds(this->sessionOptions.pongWebsocketProtocolLevelTimeoutMilliSeconds), true}; - // Set the timeout options on the stream. stream.set_option(opt); stream.set_option(beast::websocket::stream_base::decorator([wsConnectionPtr](beast::websocket::request_type& req) { req.set(http::field::user_agent, std::string(BOOST_BEAST_VERSION_STRING)); @@ -1350,7 +1353,7 @@ class Service : public std::enable_shared_from_this { [wsConnectionPtr, that = shared_from_this()](ErrorCode& ec) { that->pingOnApplicationLevel(wsConnectionPtr, ec); }); } } - void writeMessage(std::shared_ptr wsConnectionPtr, const char* data, size_t dataSize, bool binary) { + void writeMessage(std::shared_ptr wsConnectionPtr, const char* data, size_t dataSize) { if (wsConnectionPtr->status != WsConnection::Status::OPEN) { CCAPI_LOGGER_WARN("should write no more messages"); return; @@ -1358,35 +1361,43 @@ class Service : public std::enable_shared_from_this { auto& connectionId = wsConnectionPtr->id; auto& writeMessageBuffer = this->writeMessageBufferByConnectionIdMap[connectionId]; auto& writeMessageBufferWrittenLength = this->writeMessageBufferWrittenLengthByConnectionIdMap[connectionId]; - size_t n = writeMessageBufferWrittenLength + dataSize; - CCAPI_LOGGER_DEBUG("about to send " + printableString(data, dataSize)); + auto& writeMessageBufferBoundary = this->writeMessageBufferBoundaryByConnectionIdMap[connectionId]; + size_t n = writeMessageBufferWrittenLength; + memcpy(writeMessageBuffer.data() + n, data, dataSize); + writeMessageBufferBoundary.push_back(dataSize); + n += dataSize; + CCAPI_LOGGER_DEBUG("about to send " + std::string(data, dataSize)); CCAPI_LOGGER_TRACE("writeMessageBufferWrittenLength = " + toString(writeMessageBufferWrittenLength)); if (writeMessageBufferWrittenLength == 0) { CCAPI_LOGGER_TRACE("about to start write"); - this->startWriteWs(wsConnectionPtr, data, dataSize, binary); + this->startWriteWs(wsConnectionPtr, writeMessageBuffer.data(), writeMessageBufferBoundary.front()); } writeMessageBufferWrittenLength = n; CCAPI_LOGGER_TRACE("writeMessageBufferWrittenLength = " + toString(writeMessageBufferWrittenLength)); + CCAPI_LOGGER_TRACE("writeMessageBufferBoundary = " + toString(writeMessageBufferBoundary)); } - void startWriteWs(std::shared_ptr wsConnectionPtr, const char* data, size_t numBytesToWrite, bool binary) { + void startWriteWs(std::shared_ptr wsConnectionPtr, const char* data, size_t numBytesToWrite) { auto& stream = *wsConnectionPtr->streamPtr; CCAPI_LOGGER_TRACE("before async_write"); CCAPI_LOGGER_TRACE("numBytesToWrite = " + toString(numBytesToWrite)); - stream.binary(binary); - stream.async_write(boost::asio::buffer(data, numBytesToWrite), beast::bind_front_handler(&Service::onWriteWs, shared_from_this(), wsConnectionPtr, binary)); + stream.binary(false); + stream.async_write(boost::asio::buffer(data, numBytesToWrite), beast::bind_front_handler(&Service::onWriteWs, shared_from_this(), wsConnectionPtr)); CCAPI_LOGGER_TRACE("after async_write"); } - void onWriteWs(std::shared_ptr wsConnectionPtr, bool binary, const boost::system::error_code& ec, std::size_t n) { + void onWriteWs(std::shared_ptr wsConnectionPtr, const boost::system::error_code& ec, std::size_t n) { CCAPI_LOGGER_FUNCTION_ENTER; auto& connectionId = wsConnectionPtr->id; auto& writeMessageBuffer = this->writeMessageBufferByConnectionIdMap[connectionId]; auto& writeMessageBufferWrittenLength = this->writeMessageBufferWrittenLengthByConnectionIdMap[connectionId]; - writeMessageBufferWrittenLength -= n; + auto& writeMessageBufferBoundary = this->writeMessageBufferBoundaryByConnectionIdMap[connectionId]; + writeMessageBufferWrittenLength -= writeMessageBufferBoundary.front(); + writeMessageBufferBoundary.erase(writeMessageBufferBoundary.begin()); CCAPI_LOGGER_TRACE("writeMessageBufferWrittenLength = " + toString(writeMessageBufferWrittenLength)); + CCAPI_LOGGER_TRACE("writeMessageBufferBoundary = " + toString(writeMessageBufferBoundary)); if (writeMessageBufferWrittenLength > 0) { std::memmove(writeMessageBuffer.data(), writeMessageBuffer.data() + n, writeMessageBufferWrittenLength); CCAPI_LOGGER_TRACE("about to start write"); - this->startWriteWs(wsConnectionPtr, writeMessageBuffer.data(), writeMessageBufferWrittenLength, binary); + this->startWriteWs(wsConnectionPtr, writeMessageBuffer.data(), writeMessageBufferBoundary.front()); } CCAPI_LOGGER_FUNCTION_EXIT; } @@ -1528,20 +1539,21 @@ class Service : public std::enable_shared_from_this { this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, e); } } else if (stream.got_binary()) { + CCAPI_LOGGER_DEBUG(std::string("received a binary message: ") + UtilAlgorithm::stringToHex(std::string(data, dataSize))); #if defined(CCAPI_ENABLE_SERVICE_MARKET_DATA) && \ (defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP)) || \ defined(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) && \ (defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_BITMART)) if (this->needDecompressWebsocketMessage) { std::string decompressed; - const std::string& payload = msg->get_payload(); + boost::beast::string_view payload(data, dataSize); try { ErrorCode ec = this->inflater.decompress(reinterpret_cast(&payload[0]), payload.size(), decompressed); if (ec) { CCAPI_LOGGER_FATAL(ec.message()); } CCAPI_LOGGER_DEBUG("decompressed = " + decompressed); - this->onTextMessage(hdl, decompressed, now); + this->onTextMessage(wsConnectionPtr, decompressed, now); } catch (const std::exception& e) { std::stringstream ss; ss << std::hex << std::setfill('0'); @@ -1584,7 +1596,7 @@ class Service : public std::enable_shared_from_this { CCAPI_LOGGER_FUNCTION_EXIT; } void send(std::shared_ptr wsConnectionPtr, boost::beast::string_view payload, ErrorCode& ec) { - this->writeMessage(wsConnectionPtr, payload.data(), payload.length(), false); + this->writeMessage(wsConnectionPtr, payload.data(), payload.length()); } void ping(std::shared_ptr wsConnectionPtr, boost::beast::string_view payload, ErrorCode& ec) { if (!this->wsConnectionPendingPingingByIdMap[wsConnectionPtr->id]) { @@ -1702,6 +1714,7 @@ class Service : public std::enable_shared_from_this { std::map readMessageBufferByConnectionIdMap; std::map> writeMessageBufferByConnectionIdMap; std::map writeMessageBufferWrittenLengthByConnectionIdMap; + std::map> writeMessageBufferBoundaryByConnectionIdMap; #endif std::map wsConnectionPendingPingingByIdMap; std::map shouldProcessRemainingMessageOnClosingByConnectionIdMap; @@ -1724,8 +1737,12 @@ class Service : public std::enable_shared_from_this { (defined(CCAPI_ENABLE_EXCHANGE_HUOBI) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP)) || \ defined(CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT) && \ (defined(CCAPI_ENABLE_EXCHANGE_HUOBI_USDT_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_HUOBI_COIN_SWAP) || defined(CCAPI_ENABLE_EXCHANGE_BITMART)) +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET struct monostate {}; websocketpp::extensions_workaround::permessage_deflate::enabled inflater; +#else + InflateStream inflater; +#endif #endif }; } /* namespace ccapi */ From b2e3f983b1128f692c74e164288c683c31d4a35c Mon Sep 17 00:00:00 2001 From: Crypto Chassis Date: Mon, 27 Mar 2023 10:02:55 -0700 Subject: [PATCH 5/7] revert accidental change in include/ccapi_cpp/service/ccapi_fix_service.h --- include/ccapi_cpp/service/ccapi_fix_service.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/ccapi_cpp/service/ccapi_fix_service.h b/include/ccapi_cpp/service/ccapi_fix_service.h index 551d0e45..9eaaa5f7 100644 --- a/include/ccapi_cpp/service/ccapi_fix_service.h +++ b/include/ccapi_cpp/service/ccapi_fix_service.h @@ -26,6 +26,16 @@ class FixService : public Service { protected: #endif + static std::string printableString(const char* s, size_t n) { + std::string output(s, n); + std::replace(output.begin(), output.end(), '\x01', '^'); + return output; + } + static std::string printableString(const std::string& s) { + std::string output(s); + std::replace(output.begin(), output.end(), '\x01', '^'); + return output; + } void setHostFixFromUrlFix(std::string& aHostFix, std::string& aPortFix, const std::string& baseUrlFix) { auto hostPort = this->extractHostFromUrl(baseUrlFix); aHostFix = hostPort.first; From 411f8f7759c9759dcfabe4ab350651e869b9dcc1 Mon Sep 17 00:00:00 2001 From: Crypto Chassis Date: Mon, 27 Mar 2023 17:35:02 -0700 Subject: [PATCH 6/7] test: fix failed unit tests --- ...pi_execution_management_service_ascendex.h | 3 +++ ...api_execution_management_service_binance.h | 3 +++ ..._management_service_binance_coin_futures.h | 3 +++ ..._execution_management_service_binance_us.h | 3 +++ ..._management_service_binance_usds_futures.h | 3 +++ ...pi_execution_management_service_bitfinex.h | 3 +++ ...capi_execution_management_service_bitget.h | 3 +++ ...cution_management_service_bitget_futures.h | 3 +++ ...api_execution_management_service_bitmart.h | 3 +++ ...capi_execution_management_service_bitmex.h | 3 +++ ...pi_execution_management_service_bitstamp.h | 3 +++ ...ccapi_execution_management_service_bybit.h | 3 +++ ...ion_management_service_bybit_derivatives.h | 3 +++ ...pi_execution_management_service_coinbase.h | 3 +++ ...i_execution_management_service_cryptocom.h | 3 +++ ...api_execution_management_service_deribit.h | 3 +++ ...ccapi_execution_management_service_erisx.h | 4 ++++ .../ccapi_execution_management_service_ftx.h | 3 +++ ...capi_execution_management_service_ftx_us.h | 3 +++ ...capi_execution_management_service_gateio.h | 3 +++ ...agement_service_gateio_perpetual_futures.h | 3 +++ ...capi_execution_management_service_gemini.h | 3 +++ ...ccapi_execution_management_service_huobi.h | 3 +++ ...ution_management_service_huobi_coin_swap.h | 3 +++ ...ution_management_service_huobi_usdt_swap.h | 3 +++ ...capi_execution_management_service_kraken.h | 3 +++ ...cution_management_service_kraken_futures.h | 3 +++ ...capi_execution_management_service_kucoin.h | 5 +++-- ...cution_management_service_kucoin_futures.h | 5 +++-- .../ccapi_execution_management_service_mexc.h | 3 +++ ...xecution_management_service_mexc_futures.h | 3 +++ .../ccapi_execution_management_service_okx.h | 3 +++ .../ccapi_market_data_service_ascendex.h | 3 +++ .../ccapi_market_data_service_binance.h | 3 +++ ...market_data_service_binance_coin_futures.h | 3 +++ .../ccapi_market_data_service_binance_us.h | 3 +++ ...market_data_service_binance_usds_futures.h | 3 +++ .../ccapi_market_data_service_bitfinex.h | 3 +++ .../ccapi_market_data_service_bitget.h | 3 +++ ...ccapi_market_data_service_bitget_futures.h | 3 +++ .../ccapi_market_data_service_bitmart.h | 3 +++ .../ccapi_market_data_service_bitmex.h | 3 +++ .../ccapi_market_data_service_bitstamp.h | 3 +++ .../service/ccapi_market_data_service_bybit.h | 3 +++ ...pi_market_data_service_bybit_derivatives.h | 3 +++ .../ccapi_market_data_service_coinbase.h | 3 +++ .../ccapi_market_data_service_cryptocom.h | 3 +++ .../ccapi_market_data_service_deribit.h | 3 +++ .../service/ccapi_market_data_service_ftx.h | 3 +++ .../ccapi_market_data_service_ftx_us.h | 3 +++ .../ccapi_market_data_service_gateio.h | 3 +++ ...et_data_service_gateio_perpetual_futures.h | 3 +++ .../ccapi_market_data_service_gemini.h | 3 +++ .../service/ccapi_market_data_service_huobi.h | 3 +++ ...capi_market_data_service_huobi_coin_swap.h | 3 +++ ...capi_market_data_service_huobi_usdt_swap.h | 3 +++ .../ccapi_market_data_service_kraken.h | 3 +++ ...ccapi_market_data_service_kraken_futures.h | 3 +++ .../ccapi_market_data_service_kucoin.h | 3 +++ ...ccapi_market_data_service_kucoin_futures.h | 3 +++ .../service/ccapi_market_data_service_mexc.h | 3 +++ .../ccapi_market_data_service_mexc_futures.h | 3 +++ .../service/ccapi_market_data_service_okx.h | 3 +++ .../ccapi_market_data_service_whitebit.h | 3 +++ include/ccapi_cpp/service/ccapi_service.h | 20 ++++++++++--------- 65 files changed, 204 insertions(+), 13 deletions(-) diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h index df631454..661ac8a7 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceAscendex : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_ASCENDEX_API_KEY; this->apiSecretName = CCAPI_ASCENDEX_API_SECRET; this->apiAccountGroupName = CCAPI_ASCENDEX_API_ACCOUNT_GROUP; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h index c0db038f..217b926d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h @@ -22,11 +22,14 @@ class ExecutionManagementServiceBinance : public ExecutionManagementServiceBinan } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BINANCE_API_KEY; this->apiSecretName = CCAPI_BINANCE_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h index 1aed6382..cf5ddfbd 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_coin_futures.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBinanceCoinFutures : public ExecutionManagementS } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BINANCE_COIN_FUTURES_API_KEY; this->apiSecretName = CCAPI_BINANCE_COIN_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h index 6a6a2a91..45979af9 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_us.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBinanceUs : public ExecutionManagementServiceBin } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BINANCE_US_API_KEY; this->apiSecretName = CCAPI_BINANCE_US_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h index 9f3c52e1..89542308 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBinanceUsdsFutures : public ExecutionManagementS } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BINANCE_USDS_FUTURES_API_KEY; this->apiSecretName = CCAPI_BINANCE_USDS_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h index 767268d3..f2299fe2 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBitfinex : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BITFINEX_API_KEY; this->apiSecretName = CCAPI_BITFINEX_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h index 990c12f8..279d2c5b 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBitget : public ExecutionManagementServiceBitget } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BITGET_API_KEY; this->apiSecretName = CCAPI_BITGET_API_SECRET; this->apiPassphraseName = CCAPI_BITGET_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h index 3fed9d42..32464894 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget_futures.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBitgetFutures : public ExecutionManagementServic } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BITGET_FUTURES_API_KEY; this->apiSecretName = CCAPI_BITGET_FUTURES_API_SECRET; this->apiPassphraseName = CCAPI_BITGET_FUTURES_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h index 0d9df521..a3b887bf 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBitmart : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BITMART_API_KEY; this->apiSecretName = CCAPI_BITMART_API_SECRET; this->apiMemoName = CCAPI_BITMART_API_MEMO; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h index e415ed0d..a6614cca 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBitmex : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BITMEX_API_KEY; this->apiSecretName = CCAPI_BITMEX_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h index 4f4dd43d..14fd3605 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BITSTAMP_API_KEY; this->apiSecretName = CCAPI_BITSTAMP_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h index 02c3994e..12983bc8 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBybit : public ExecutionManagementServiceBybitBa } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BYBIT_API_KEY; this->apiSecretName = CCAPI_BYBIT_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h index c37a9eaa..8cde5f4d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit_derivatives.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceBybitDerivatives : public ExecutionManagementSer } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BYBIT_DERIVATIVES_API_KEY; this->apiSecretName = CCAPI_BYBIT_DERIVATIVES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h index df86622d..827e34df 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceCoinbase : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_COINBASE_API_KEY; this->apiSecretName = CCAPI_COINBASE_API_SECRET; this->apiPassphraseName = CCAPI_COINBASE_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h index f7270736..8410f722 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceCryptocom : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_CRYPTOCOM_API_KEY; this->apiSecretName = CCAPI_CRYPTOCOM_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h index 579058a2..70be1f32 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceDeribit : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->clientIdName = CCAPI_DERIBIT_CLIENT_ID; this->clientSecretName = CCAPI_DERIBIT_CLIENT_SECRET; this->setupCredential({this->clientIdName, this->clientSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h index 18967a16..c5038480 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h @@ -11,6 +11,7 @@ class ExecutionManagementServiceErisx : public ExecutionManagementService { ServiceContextPtr serviceContextPtr) : ExecutionManagementService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_ERISX; + this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); this->setHostWsFromUrlWs(this->baseUrlWs); @@ -19,11 +20,14 @@ class ExecutionManagementServiceErisx : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_ERISX_API_KEY; this->apiSecretName = CCAPI_ERISX_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h index 4ba3eac5..b9d22521 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceFtx : public ExecutionManagementServiceFtxBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_FTX_API_KEY; this->apiSecretName = CCAPI_FTX_API_SECRET; this->apiSubaccountName = CCAPI_FTX_API_SUBACCOUNT; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h index 53d672e7..422bb595 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ftx_us.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceFtxUs : public ExecutionManagementServiceFtxBase } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_FTX_US_API_KEY; this->apiSecretName = CCAPI_FTX_US_API_SECRET; this->apiSubaccountName = CCAPI_FTX_US_API_SUBACCOUNT; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h index b27b9b7b..aebaae74 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceGateio : public ExecutionManagementServiceGateio } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_GATEIO_API_KEY; this->apiSecretName = CCAPI_GATEIO_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h index 767f50d1..09a79994 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio_perpetual_futures.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceGateioPerpetualFutures : public ExecutionManagem } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_GATEIO_PERPETUAL_FUTURES_API_KEY; this->apiSecretName = CCAPI_GATEIO_PERPETUAL_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h index 8459ea07..6fff3bfb 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceGemini : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_GEMINI_API_KEY; this->apiSecretName = CCAPI_GEMINI_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h index ba334b7e..0b9ecfbb 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceHuobi : public ExecutionManagementServiceHuobiBa } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_HUOBI_API_KEY; this->apiSecretName = CCAPI_HUOBI_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h index 5f77f577..1efe0a65 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_coin_swap.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceHuobiCoinSwap : public ExecutionManagementServic } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_HUOBI_COIN_SWAP_API_KEY; this->apiSecretName = CCAPI_HUOBI_COIN_SWAP_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h index 5bd004c2..a77805cb 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi_usdt_swap.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceHuobiUsdtSwap : public ExecutionManagementServic } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_HUOBI_USDT_SWAP_API_KEY; this->apiSecretName = CCAPI_HUOBI_USDT_SWAP_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h index 398a23aa..f6d6cc74 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h @@ -20,11 +20,14 @@ class ExecutionManagementServiceKraken : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_KRAKEN_API_KEY; this->apiSecretName = CCAPI_KRAKEN_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h index 15c80f71..9470cec9 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken_futures.h @@ -20,11 +20,14 @@ class ExecutionManagementServiceKrakenFutures : public ExecutionManagementServic } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_KRAKEN_FUTURES_API_KEY; this->apiSecretName = CCAPI_KRAKEN_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h index 2abf28ff..d76adb7c 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h @@ -10,20 +10,21 @@ class ExecutionManagementServiceKucoin : public ExecutionManagementServiceKucoin ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceKucoinBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KUCOIN; - this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); - this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_KUCOIN_API_KEY; this->apiSecretName = CCAPI_KUCOIN_API_SECRET; this->apiPassphraseName = CCAPI_KUCOIN_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h index 0257dd08..6d1bb4b5 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin_futures.h @@ -10,20 +10,21 @@ class ExecutionManagementServiceKucoinFutures : public ExecutionManagementServic ServiceContextPtr serviceContextPtr) : ExecutionManagementServiceKucoinBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KUCOIN_FUTURES; - this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); - this->setHostWsFromUrlWs(this->baseUrlWs); try { this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_KUCOIN_FUTURES_API_KEY; this->apiSecretName = CCAPI_KUCOIN_FUTURES_API_SECRET; this->apiPassphraseName = CCAPI_KUCOIN_FUTURES_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h index 716992ca..ca9199be 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h @@ -20,11 +20,14 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_MEXC_API_KEY; this->apiSecretName = CCAPI_MEXC_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h index efec5c18..149b6357 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc_futures.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceMexcFutures : public ExecutionManagementService } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_MEXC_FUTURES_API_KEY; this->apiSecretName = CCAPI_MEXC_FUTURES_API_SECRET; this->setupCredential({this->apiKeyName, this->apiSecretName}); diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h index 9c4e3ccf..5c426dec 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h @@ -19,11 +19,14 @@ class ExecutionManagementServiceOkx : public ExecutionManagementService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_OKX_API_KEY; this->apiSecretName = CCAPI_OKX_API_SECRET; this->apiPassphraseName = CCAPI_OKX_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h index 43226fdf..d6f6e3bc 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h @@ -19,11 +19,14 @@ class MarketDataServiceAscendex : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/pro/v1/trades"; this->getInstrumentTarget = "/api/pro/v1/products"; this->getInstrumentsTarget = "/api/pro/v1/products"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h index b3967ed2..371f790c 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h @@ -19,11 +19,14 @@ class MarketDataServiceBinance : public MarketDataServiceBinanceBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BINANCE_API_KEY; this->setupCredential({this->apiKeyName}); this->getRecentTradesTarget = "/api/v3/trades"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h index 5336a4c0..e03e9e6f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_coin_futures.h @@ -19,11 +19,14 @@ class MarketDataServiceBinanceCoinFutures : public MarketDataServiceBinanceDeriv } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BINANCE_COIN_FUTURES_API_KEY; this->setupCredential({this->apiKeyName}); this->getRecentTradesTarget = "/dapi/v1/trades"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h index 202f757b..10de42af 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_us.h @@ -19,11 +19,14 @@ class MarketDataServiceBinanceUs : public MarketDataServiceBinanceBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BINANCE_US_API_KEY; this->setupCredential({this->apiKeyName}); this->getRecentTradesTarget = "/api/v3/trades"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h index b55817a1..76e9559f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_usds_futures.h @@ -19,11 +19,14 @@ class MarketDataServiceBinanceUsdsFutures : public MarketDataServiceBinanceDeriv } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BINANCE_USDS_FUTURES_API_KEY; this->setupCredential({this->apiKeyName}); this->getRecentTradesTarget = "/fapi/v1/trades"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h index 149a5e6f..3998c848 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h @@ -19,11 +19,14 @@ class MarketDataServiceBitfinex : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/v2/trades/{Symbol}/hist"; this->getInstrumentsTarget = CCAPI_BITFINEX_GET_INSTRUMENTS_PATH; this->getInstrumentTarget = CCAPI_BITFINEX_GET_INSTRUMENTS_PATH; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h index ed675bd3..0cc60f34 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h @@ -19,11 +19,14 @@ class MarketDataServiceBitget : public MarketDataServiceBitgetBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/spot/v1/market/fills"; this->getInstrumentTarget = "/api/spot/v1/public/product"; this->getInstrumentsTarget = "/api/spot/v1/public/products"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h index bc402c52..62f03697 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_futures.h @@ -19,11 +19,14 @@ class MarketDataServiceBitgetFutures : public MarketDataServiceBitgetBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/mix/v1/market/fills"; this->getInstrumentTarget = "/api/mix/v1/market/contracts"; this->getInstrumentsTarget = "/api/mix/v1/market/contracts"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h index a7a2572a..3974c371 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h @@ -19,11 +19,14 @@ class MarketDataServiceBitmart : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_BITMART_API_KEY; this->apiSecretName = CCAPI_BITMART_API_SECRET; this->apiMemo = CCAPI_BITMART_API_MEMO; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h index 71fb7caa..5e2534d4 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h @@ -19,11 +19,14 @@ class MarketDataServiceBitmex : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/v1/trade"; this->getInstrumentTarget = "/api/v1/instrument"; this->getInstrumentsTarget = "/api/v1/instrument"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h index 412acac0..3791479e 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h @@ -20,11 +20,14 @@ class MarketDataServiceBitstamp : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/v2/transactions/{currency_pair}/"; // must have trailing slash this->getInstrumentTarget = "/api/v2/trading-pairs-info/"; this->getInstrumentsTarget = "/api/v2/trading-pairs-info/"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h index 78dfabde..9e537d6f 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h @@ -19,11 +19,14 @@ class MarketDataServiceBybit : public MarketDataServiceBybitBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/spot/v3/public/quote/trades"; this->getInstrumentsTarget = "/spot/v3/public/symbols"; } diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h b/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h index cb5031fe..9b7461ac 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit_derivatives.h @@ -19,11 +19,14 @@ class MarketDataServiceBybitDerivatives : public MarketDataServiceBybitBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/derivatives/v3/public/recent-trade"; this->getInstrumentTarget = "/derivatives/v3/public/instruments-info"; this->getInstrumentsTarget = "/derivatives/v3/public/instruments-info"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h index 0a39f227..e7e409d9 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h @@ -19,11 +19,14 @@ class MarketDataServiceCoinbase : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/products//trades"; this->getInstrumentTarget = "/products/"; this->getInstrumentsTarget = "/products"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h index 02f95ab5..93ed6714 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h @@ -19,11 +19,14 @@ class MarketDataServiceCryptocom : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/v2/public/get-trades"; this->getInstrumentTarget = "/v2/public/get-instruments"; this->getInstrumentsTarget = "/v2/public/get-instruments"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h index 0d613c3f..1a777e94 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h @@ -19,11 +19,14 @@ class MarketDataServiceDeribit : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->restTarget = "/api/v2"; this->getRecentTradesTarget = "/public/get_last_trades_by_instrument"; this->getInstrumentTarget = "/public/get_instrument"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h index 0b8730cd..23621671 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h @@ -19,11 +19,14 @@ class MarketDataServiceFtx : public MarketDataServiceFtxBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif } virtual ~MarketDataServiceFtx() {} }; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h index 3c9a23d5..31708a70 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_us.h @@ -19,11 +19,14 @@ class MarketDataServiceFtxUs : public MarketDataServiceFtxBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif } virtual ~MarketDataServiceFtxUs() {} }; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h index ee0c119a..13786e57 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h @@ -19,11 +19,14 @@ class MarketDataServiceGateio : public MarketDataServiceGateioBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_GATEIO_API_KEY; this->setupCredential({this->apiKeyName}); std::string prefix = "/api/v4"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h index 7f21a88f..f7023214 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_perpetual_futures.h @@ -19,11 +19,14 @@ class MarketDataServiceGateioPerpetualFutures : public MarketDataServiceGateioBa } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_GATEIO_PERPETUAL_FUTURES_API_KEY; this->setupCredential({this->apiKeyName}); std::string prefix = "/api/v4"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h index a6b0021b..5de73f6b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h @@ -19,11 +19,14 @@ class MarketDataServiceGemini : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/v1/trades/:symbol"; this->getInstrumentTarget = "/v1/symbols/details/:symbol"; this->getInstrumentsTarget = "/v1/symbols"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h index cab99a85..54dc4f28 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h @@ -19,11 +19,14 @@ class MarketDataServiceHuobi : public MarketDataServiceHuobiBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/market/history/trade"; this->getInstrumentTarget = "/v1/common/symbols"; this->getInstrumentsTarget = "/v1/common/symbols"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h index 54031f4e..c0af9922 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_coin_swap.h @@ -19,11 +19,14 @@ class MarketDataServiceHuobiCoinSwap : public MarketDataServiceHuobiDerivativesB } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = CCAPI_HUOBI_COIN_SWAP_GET_RECENT_TRADES_PATH; this->getInstrumentTarget = "/swap-api/v1/swap_contract_info"; this->getInstrumentsTarget = "/swap-api/v1/swap_contract_info"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h index baec819f..3b2820c3 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_usdt_swap.h @@ -19,11 +19,14 @@ class MarketDataServiceHuobiUsdtSwap : public MarketDataServiceHuobiDerivativesB } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = CCAPI_HUOBI_USDT_SWAP_GET_RECENT_TRADES_PATH; this->getInstrumentTarget = "/linear-swap-api/v1/swap_contract_info"; this->getInstrumentsTarget = "/linear-swap-api/v1/swap_contract_info"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h index 58334ead..e8504873 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h @@ -19,11 +19,14 @@ class MarketDataServiceKraken : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/0/public/Trades"; this->getInstrumentTarget = "/0/public/AssetPairs"; this->getInstrumentsTarget = "/0/public/AssetPairs"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h index 9dcd0003..4a1525fa 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken_futures.h @@ -19,11 +19,14 @@ class MarketDataServiceKrakenFutures : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif std::string prefix("/derivatives/api/v3"); this->getRecentTradesTarget = prefix + "/history"; this->getInstrumentTarget = prefix + "/instruments"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h index 0f174f47..e5d5dc52 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h @@ -19,11 +19,14 @@ class MarketDataServiceKucoin : public MarketDataServiceKucoinBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_KUCOIN_API_KEY; this->apiSecretName = CCAPI_KUCOIN_API_SECRET; this->apiPassphraseName = CCAPI_KUCOIN_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h index 3268eb75..aa13851c 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_futures.h @@ -19,11 +19,14 @@ class MarketDataServiceKucoinFutures : public MarketDataServiceKucoinBase { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/v1/trade/history"; this->getInstrumentTarget = "/api/v1/contracts/active"; this->getInstrumentsTarget = "/api/v1/contracts/active"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h index ec90a0a1..3bbb1d69 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h @@ -19,11 +19,14 @@ class MarketDataServiceMexc : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/v3/trades"; this->getRecentAggTradesTarget = "/api/v3/aggTrades"; this->getInstrumentsTarget = "/api/v3/exchangeInfo"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h b/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h index f3f6a116..eba85b60 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc_futures.h @@ -19,11 +19,14 @@ class MarketDataServiceMexcFutures : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/v1/contract/deals/{symbol}"; this->getInstrumentsTarget = "/api/v1/contract/detail"; } diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h index a27245ab..5f501d21 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h @@ -19,11 +19,14 @@ class MarketDataServiceOkx : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->apiKeyName = CCAPI_OKX_API_KEY; this->apiSecretName = CCAPI_OKX_API_SECRET; this->apiPassphraseName = CCAPI_OKX_API_PASSPHRASE; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h index 4356d491..6dbd39d7 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h @@ -19,11 +19,14 @@ class MarketDataServiceWhitebit : public MarketDataService { } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#ifndef CCAPI_USE_BOOST_BEAST_WEBSOCKET +#else try { this->tcpResolverResultsWs = this->resolverWs.resolve(this->hostWs, this->portWs); } catch (const std::exception& e) { CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); } +#endif this->getRecentTradesTarget = "/api/v4/public/trades/{market}"; this->getInstrumentsTarget = "/api/v4/public/markets"; this->methodDepthSubscribe = std::string(CCAPI_WEBSOCKET_WHITEBIT_CHANNEL_MARKET_DEPTH) + "_subscribe"; diff --git a/include/ccapi_cpp/service/ccapi_service.h b/include/ccapi_cpp/service/ccapi_service.h index 1e1fac34..a3dd0bf5 100644 --- a/include/ccapi_cpp/service/ccapi_service.h +++ b/include/ccapi_cpp/service/ccapi_service.h @@ -320,16 +320,18 @@ class Service : public std::enable_shared_from_this { std::pair extractHostFromUrl(std::string baseUrl) { std::string host; std::string port; - auto splitted1 = UtilString::split(baseUrl, "://"); - auto splitted2 = UtilString::split(UtilString::split(splitted1[1], "/")[0], ":"); - host = splitted2[0]; - if (splitted2.size() == 2) { - port = splitted2[1]; - } else { - if (splitted1[0] == "https" || splitted1[0] == "wss") { - port = CCAPI_HTTPS_PORT_DEFAULT; + if (!baseUrl.empty()) { + auto splitted1 = UtilString::split(baseUrl, "://"); + auto splitted2 = UtilString::split(UtilString::split(splitted1.at(1), "/").at(0), ":"); + host = splitted2.at(0); + if (splitted2.size() == 2) { + port = splitted2.at(1); } else { - port = CCAPI_HTTP_PORT_DEFAULT; + if (splitted1.at(0) == "https" || splitted1.at(0) == "wss") { + port = CCAPI_HTTPS_PORT_DEFAULT; + } else { + port = CCAPI_HTTP_PORT_DEFAULT; + } } } return std::make_pair(host, port); From c83de711ce3bb9160bda1cf8d8cdd38808d864bc Mon Sep 17 00:00:00 2001 From: Crypto Chassis Date: Mon, 27 Mar 2023 19:37:16 -0700 Subject: [PATCH 7/7] minor: update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 98b98ec1..549319d1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +Notification to Maintainers and Developers: we are aiming at an effort to transition our websocket related code from using websocketpp to boost beast websocket. In release v5.43.x, everything remains fully backward compatible. The codebase introduced a macro `CCAPI_USE_BOOST_BEAST_WEBSOCKET` to faciliate the future transition. If you have any questions, feel free to contact us at any time. Thank you. + **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*