diff --git a/app/src/single_order_execution/main.cpp b/app/src/single_order_execution/main.cpp index 928118f3..2535b311 100644 --- a/app/src/single_order_execution/main.cpp +++ b/app/src/single_order_execution/main.cpp @@ -132,9 +132,6 @@ int main(int argc, char** argv) { eventHandler.promisePtr = promisePtr; #ifndef CCAPI_APP_IS_BACKTEST SessionOptions sessionOptions; - sessionOptions.httpConnectionPoolIdleTimeoutMilliseconds = 1; - sessionOptions.httpMaxNumRetry = 0; - sessionOptions.httpMaxNumRedirect = 0; SessionConfigs sessionConfigs; Session session(sessionOptions, sessionConfigs, &eventHandler); eventHandler.onInit(&session); diff --git a/app/src/spot_market_making/main.cpp b/app/src/spot_market_making/main.cpp index 7f79f08a..013db77b 100644 --- a/app/src/spot_market_making/main.cpp +++ b/app/src/spot_market_making/main.cpp @@ -168,9 +168,6 @@ int main(int argc, char** argv) { eventHandler.promisePtr = promisePtr; #ifndef CCAPI_APP_IS_BACKTEST SessionOptions sessionOptions; - sessionOptions.httpConnectionPoolIdleTimeoutMilliseconds = 1 + eventHandler.accountBalanceRefreshWaitSeconds; - sessionOptions.httpMaxNumRetry = 0; - sessionOptions.httpMaxNumRedirect = 0; SessionConfigs sessionConfigs; Session session(sessionOptions, sessionConfigs, &eventHandler); eventHandler.onInit(&session); diff --git a/example/src/market_data_simple_subscription/CMakeLists.txt b/example/src/market_data_simple_subscription/CMakeLists.txt index 1305df16..c72cc750 100644 --- a/example/src/market_data_simple_subscription/CMakeLists.txt +++ b/example/src/market_data_simple_subscription/CMakeLists.txt @@ -1,6 +1,6 @@ set(NAME market_data_simple_subscription) project(${NAME}) add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA) -add_compile_definitions(CCAPI_ENABLE_EXCHANGE_COINBASE) +add_compile_definitions(CCAPI_ENABLE_EXCHANGE_OKX) add_executable(${NAME} main.cpp) add_dependencies(${NAME} boost rapidjson) diff --git a/example/src/market_data_simple_subscription/main.cpp b/example/src/market_data_simple_subscription/main.cpp index ecca75df..18675550 100644 --- a/example/src/market_data_simple_subscription/main.cpp +++ b/example/src/market_data_simple_subscription/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char** argv) { SessionConfigs sessionConfigs; MyEventHandler eventHandler; Session session(sessionOptions, sessionConfigs, &eventHandler); - Subscription subscription("coinbase", "BTC-USD", "MARKET_DEPTH"); + Subscription subscription("okx", "BTC-USDT", "MARKET_DEPTH"); session.subscribe(subscription); std::this_thread::sleep_for(std::chrono::seconds(10)); session.stop(); diff --git a/include/ccapi_cpp/ccapi_http_connection.h b/include/ccapi_cpp/ccapi_http_connection.h index c8dfde83..95f38623 100644 --- a/include/ccapi_cpp/ccapi_http_connection.h +++ b/include/ccapi_cpp/ccapi_http_connection.h @@ -15,12 +15,14 @@ class HttpConnection CCAPI_FINAL { std::string toString() const { std::ostringstream oss; oss << streamPtr; - std::string output = "HttpConnection [host = " + host + ", port = " + port + ", streamPtr = " + oss.str() + "]"; + std::string output = "HttpConnection [host = " + host + ", port = " + port + ", streamPtr = " + oss.str() + + ", lastReceiveDataTp = " + UtilTime::getISOTimestamp(lastReceiveDataTp) + "]"; return output; } std::string host; std::string port; std::shared_ptr > streamPtr; + TimePoint lastReceiveDataTp{std::chrono::seconds{0}}; }; } /* namespace ccapi */ #endif // INCLUDE_CCAPI_CPP_CCAPI_HTTP_CONNECTION_H_ diff --git a/include/ccapi_cpp/ccapi_macro.h b/include/ccapi_cpp/ccapi_macro.h index d385220f..d4851958 100644 --- a/include/ccapi_cpp/ccapi_macro.h +++ b/include/ccapi_cpp/ccapi_macro.h @@ -274,6 +274,9 @@ #ifndef CCAPI_ORDER_PRICE_TIMES_QUANTITY_MIN #define CCAPI_ORDER_PRICE_TIMES_QUANTITY_MIN "PRICE_TIMES_QUANTITY_MIN" #endif +#ifndef CCAPI_INSTRUMENT_STATUS +#define CCAPI_INSTRUMENT_STATUS "INSTRUMENT_STATUS" +#endif #ifndef CCAPI_CONTRACT_SIZE #define CCAPI_CONTRACT_SIZE "CONTRACT_SIZE" #endif @@ -1004,12 +1007,6 @@ #ifndef CCAPI_BINANCE_API_SECRET #define CCAPI_BINANCE_API_SECRET "BINANCE_API_SECRET" #endif -// #ifndef CCAPI_BINANCE_MARGIN_API_KEY -// #define CCAPI_BINANCE_MARGIN_API_KEY "BINANCE_MARGIN_API_KEY" -// #endif -// #ifndef CCAPI_BINANCE_MARGIN_API_SECRET -// #define CCAPI_BINANCE_MARGIN_API_SECRET "BINANCE_MARGIN_API_SECRET" -// #endif #ifndef CCAPI_BINANCE_USDS_FUTURES_API_KEY #define CCAPI_BINANCE_USDS_FUTURES_API_KEY "BINANCE_USDS_FUTURES_API_KEY" #endif diff --git a/include/ccapi_cpp/ccapi_request.h b/include/ccapi_cpp/ccapi_request.h index 28436597..d2e4f14f 100644 --- a/include/ccapi_cpp/ccapi_request.h +++ b/include/ccapi_cpp/ccapi_request.h @@ -148,7 +148,8 @@ class Request CCAPI_FINAL { ", correlationId = " + correlationId + ", secondaryCorrelationId = " + secondaryCorrelationId + (this->serviceName == CCAPI_FIX ? ", paramListFix = " + ccapi::toString(paramListFix) : ", paramList = " + ccapi::toString(paramList)) + ", credential = " + ccapi::toString(shortCredential) + ", operation = " + operationToString(operation) + - ", timeSent = " + UtilTime::getISOTimestamp(timeSent) + "]"; + ", timeSent = " + UtilTime::getISOTimestamp(timeSent) + ", index = " + ccapi::toString(index) + ", localIpAddress = " + localIpAddress + + ", baseUrl = " + baseUrl + "]"; return output; } const std::string& getCorrelationId() const { return correlationId; } @@ -181,11 +182,36 @@ class Request CCAPI_FINAL { std::pair getTimeSentPair() const { return UtilTime::divide(timeSent); } void setTimeSent(TimePoint timeSent) { this->timeSent = timeSent; } int getIndex() const { return index; } + const std::string& getLocalIpAddress() const { return localIpAddress; } + const std::string& getBaseUrl() const { return baseUrl; } + const std::string& getHost() const { return host; } + const std::string& getPort() const { return port; } void setIndex(int index) { this->index = index; } void setCredential(const std::map& credential) { this->credential = credential; } void setCorrelationId(const std::string& correlationId) { this->correlationId = correlationId; } void setSecondaryCorrelationId(const std::string& secondaryCorrelationId) { this->secondaryCorrelationId = secondaryCorrelationId; } void setMarginType(const std::string& marginType) { this->marginType = marginType; } + void setLocalIpAddress(const std::string& localIpAddress) { this->localIpAddress = localIpAddress; } + void setBaseUrl(const std::string& baseUrl) { + this->baseUrl = baseUrl; + this->setBaseUrlParts(); + } + void setBaseUrlParts() { + auto splitted1 = UtilString::split(this->baseUrl, "://"); + if (splitted1.size() >= 2) { + auto splitted2 = UtilString::split(UtilString::split(splitted1.at(1), "/").at(0), ":"); + this->host = splitted2.at(0); + if (splitted2.size() == 2) { + this->port = splitted2.at(1); + } else { + if (splitted1.at(0) == "https" || splitted1.at(0) == "wss") { + this->port = CCAPI_HTTPS_PORT_DEFAULT; + } else { + this->port = CCAPI_HTTP_PORT_DEFAULT; + } + } + } + } #ifndef CCAPI_EXPOSE_INTERNAL private: @@ -202,6 +228,10 @@ class Request CCAPI_FINAL { std::vector > > paramListFix; TimePoint timeSent{std::chrono::seconds{0}}; int index{}; + std::string localIpAddress; + std::string baseUrl; + std::string host; + std::string port; }; } /* namespace ccapi */ #endif // INCLUDE_CCAPI_CPP_CCAPI_REQUEST_H_ diff --git a/include/ccapi_cpp/ccapi_session.h b/include/ccapi_cpp/ccapi_session.h index 57dca882..32e47ab3 100644 --- a/include/ccapi_cpp/ccapi_session.h +++ b/include/ccapi_cpp/ccapi_session.h @@ -259,15 +259,27 @@ class Session { Session(const Session&) = delete; Session& operator=(const Session&) = delete; Session(const SessionOptions& sessionOptions = SessionOptions(), const SessionConfigs& sessionConfigs = SessionConfigs(), - EventHandler* eventHandler = nullptr, EventDispatcher* eventDispatcher = nullptr) + EventHandler* eventHandler = nullptr, EventDispatcher* eventDispatcher = nullptr +#ifndef SWIG + , + ServiceContext* serviceContextPtr = nullptr +#endif + ) : sessionOptions(sessionOptions), sessionConfigs(sessionConfigs), eventHandler(eventHandler), #ifndef CCAPI_USE_SINGLE_THREAD eventDispatcher(eventDispatcher), #endif - eventQueue(sessionOptions.maxEventQueueSize), - serviceContextPtr(new ServiceContext()) { + eventQueue(sessionOptions.maxEventQueueSize) +#ifndef SWIG + , + serviceContextPtr(serviceContextPtr) +#endif + { + if (!this->serviceContextPtr) { + this->serviceContextPtr = new ServiceContext(); + } CCAPI_LOGGER_FUNCTION_ENTER; #ifndef CCAPI_USE_SINGLE_THREAD if (this->eventHandler) { @@ -291,6 +303,7 @@ class Session { delete this->eventDispatcher; } #endif + delete this->serviceContextPtr; CCAPI_LOGGER_FUNCTION_EXIT; } virtual void start() { @@ -637,19 +650,19 @@ class Session { return; } if (serviceName == CCAPI_MARKET_DATA) { - std::set correlationIdSet; - std::set duplicateCorrelationIdSet; + // std::set correlationIdSet; + // std::set duplicateCorrelationIdSet; std::unordered_set unsupportedExchangeFieldSet; std::map > subscriptionListByExchangeMap; auto exchangeFieldMap = this->sessionConfigs.getExchangeFieldMap(); CCAPI_LOGGER_DEBUG("exchangeFieldMap = " + toString(exchangeFieldMap)); for (const auto& subscription : subscriptionList) { - auto correlationId = subscription.getCorrelationId(); - if (correlationIdSet.find(correlationId) != correlationIdSet.end()) { - duplicateCorrelationIdSet.insert(correlationId); - } else { - correlationIdSet.insert(correlationId); - } + // auto correlationId = subscription.getCorrelationId(); + // if (correlationIdSet.find(correlationId) != correlationIdSet.end()) { + // duplicateCorrelationIdSet.insert(correlationId); + // } else { + // correlationIdSet.insert(correlationId); + // } auto exchange = subscription.getExchange(); CCAPI_LOGGER_DEBUG("exchange = " + exchange); auto field = subscription.getField(); @@ -663,11 +676,11 @@ class Session { } subscriptionListByExchangeMap[exchange].push_back(subscription); } - if (!duplicateCorrelationIdSet.empty()) { - this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, - "duplicated correlation ids: " + toString(duplicateCorrelationIdSet)); - return; - } + // if (!duplicateCorrelationIdSet.empty()) { + // this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, + // "duplicated correlation ids: " + toString(duplicateCorrelationIdSet)); + // return; + // } if (!unsupportedExchangeFieldSet.empty()) { this->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::SUBSCRIPTION_FAILURE, "unsupported exchange fields: " + toString(unsupportedExchangeFieldSet)); @@ -902,7 +915,8 @@ class Session { virtual void setTimer(const std::string& id, long delayMilliseconds, std::function errorHandler, std::function 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))); + std::shared_ptr timerPtr( + new boost::asio::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) { #ifdef CCAPI_USE_SINGLE_THREAD @@ -963,12 +977,12 @@ class Session { #endif SessionOptions sessionOptions; SessionConfigs sessionConfigs; - EventHandler* eventHandler; + EventHandler* eventHandler{nullptr}; #ifndef CCAPI_USE_SINGLE_THREAD - EventDispatcher* eventDispatcher; + EventDispatcher* eventDispatcher{nullptr}; bool useInternalEventDispatcher{}; #endif - std::shared_ptr serviceContextPtr; + ServiceContext* serviceContextPtr{nullptr}; std::map > > serviceByServiceNameExchangeMap; std::thread t; Queue eventQueue; diff --git a/include/ccapi_cpp/ccapi_session_configs.h b/include/ccapi_cpp/ccapi_session_configs.h index c35a6206..7afac633 100644 --- a/include/ccapi_cpp/ccapi_session_configs.h +++ b/include/ccapi_cpp/ccapi_session_configs.h @@ -332,7 +332,6 @@ class SessionConfigs CCAPI_FINAL { {CCAPI_EXCHANGE_NAME_BITMEX, CCAPI_BITMEX_URL_WS_BASE}, {CCAPI_EXCHANGE_NAME_BINANCE_US, CCAPI_BINANCE_US_URL_WS_BASE}, {CCAPI_EXCHANGE_NAME_BINANCE, CCAPI_BINANCE_URL_WS_BASE}, - // {CCAPI_EXCHANGE_NAME_BINANCE_MARGIN, CCAPI_BINANCE_URL_WS_BASE}, {CCAPI_EXCHANGE_NAME_BINANCE_USDS_FUTURES, CCAPI_BINANCE_USDS_FUTURES_URL_WS_BASE}, {CCAPI_EXCHANGE_NAME_BINANCE_COIN_FUTURES, CCAPI_BINANCE_COIN_FUTURES_URL_WS_BASE}, {CCAPI_EXCHANGE_NAME_HUOBI, CCAPI_HUOBI_URL_WS_BASE}, @@ -374,7 +373,6 @@ class SessionConfigs CCAPI_FINAL { {CCAPI_EXCHANGE_NAME_BITMEX, CCAPI_BITMEX_URL_REST_BASE}, {CCAPI_EXCHANGE_NAME_BINANCE_US, CCAPI_BINANCE_US_URL_REST_BASE}, {CCAPI_EXCHANGE_NAME_BINANCE, CCAPI_BINANCE_URL_REST_BASE}, - // {CCAPI_EXCHANGE_NAME_BINANCE_MARGIN, CCAPI_BINANCE_URL_REST_BASE}, {CCAPI_EXCHANGE_NAME_BINANCE_USDS_FUTURES, CCAPI_BINANCE_USDS_FUTURES_URL_REST_BASE}, {CCAPI_EXCHANGE_NAME_BINANCE_COIN_FUTURES, CCAPI_BINANCE_COIN_FUTURES_URL_REST_BASE}, {CCAPI_EXCHANGE_NAME_HUOBI, CCAPI_HUOBI_URL_REST_BASE}, diff --git a/include/ccapi_cpp/ccapi_session_options.h b/include/ccapi_cpp/ccapi_session_options.h index 70e9975c..1281a2f9 100644 --- a/include/ccapi_cpp/ccapi_session_options.h +++ b/include/ccapi_cpp/ccapi_session_options.h @@ -28,7 +28,7 @@ class SessionOptions CCAPI_FINAL { ", httpMaxNumRedirect = " + ccapi::toString(httpMaxNumRedirect) + ", httpRequestTimeoutMilliseconds = " + ccapi::toString(httpRequestTimeoutMilliseconds) + ", httpConnectionPoolMaxSize = " + ccapi::toString(httpConnectionPoolMaxSize) + - ", httpConnectionPoolIdleTimeoutMilliseconds = " + ccapi::toString(httpConnectionPoolIdleTimeoutMilliseconds) + + ", httpConnectionKeepAliveTimeoutSeconds = " + ccapi::toString(httpConnectionKeepAliveTimeoutSeconds) + ", enableOneHttpConnectionPerRequest = " + ccapi::toString(enableOneHttpConnectionPerRequest) + "]"; return output; } @@ -50,9 +50,9 @@ class SessionOptions CCAPI_FINAL { int httpMaxNumRedirect{1}; long httpRequestTimeoutMilliseconds{10000}; int httpConnectionPoolMaxSize{1}; // used to set the maximal number of http connections to be kept in the pool (connections in the pool are idle) - 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 + long httpConnectionKeepAliveTimeoutSeconds{ + 10}; // used to remove a http connection from the http connection pool if it has stayed idle for at least this amount of time + bool enableOneHttpConnectionPerRequest{}; // create a new http connection for each request #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP #else long websocketConnectTimeoutMilliseconds{10000}; diff --git a/include/ccapi_cpp/ccapi_subscription.h b/include/ccapi_cpp/ccapi_subscription.h index fcf5fa47..e2c14d7c 100644 --- a/include/ccapi_cpp/ccapi_subscription.h +++ b/include/ccapi_cpp/ccapi_subscription.h @@ -98,7 +98,7 @@ class Subscription CCAPI_FINAL { } return output; } - const std::string getSerializedCredential() const { return ::ccapi::toString(this->credential); } + const std::string getSerializedCredential() const { return ccapi::toString(this->credential); } // 'getTimeSent' only works in C++. For other languages, please use 'getTimeSentISO'. TimePoint getTimeSent() const { return timeSent; } std::string getTimeSentISO() const { return UtilTime::getISOTimestamp(timeSent); } 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 8d5bd970..dbce1f47 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_ascendex.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceAscendex : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 a76ef252..5ecba791 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance.h @@ -17,19 +17,19 @@ class ExecutionManagementServiceBinance : public ExecutionManagementServiceBinan 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 e547aedc..2cba2a42 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceBinanceCoinFutures : public ExecutionManagementS 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 a2ee6a64..662b93d3 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceBinanceUs : public ExecutionManagementServiceBin 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 7e92b7b9..be3a4f91 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceBinanceUsdsFutures : public ExecutionManagementS 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 71c1e2a2..0ff55fea 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitfinex.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceBitfinex : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 67ba0ff2..b83f331c 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitget.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceBitget : public ExecutionManagementServiceBitget 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 ac1a967e..cc06a703 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceBitgetFutures : public ExecutionManagementServic 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 d759bfe6..56619c97 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmart.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceBitmart : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 814c95a6..4184ad81 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitmex.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceBitmex : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 9379c6aa..b01c891d 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bitstamp.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceBitstamp : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 a70aeb39..914eb7c5 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_bybit.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceBybit : public ExecutionManagementServiceBybitBa 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 90cf73fa..35584e91 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceBybitDerivatives : public ExecutionManagementSer 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 d7db6cea..3d02c7b1 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_coinbase.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceCoinbase : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 f6578364..008bde90 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_cryptocom.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceCryptocom : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 bf16a43d..5c90de68 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_deribit.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceDeribit : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 2e2b2b1e..4d06382e 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_erisx.h @@ -15,19 +15,19 @@ class ExecutionManagementServiceErisx : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_gateio.h b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h index 9983165b..66cfe571 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gateio.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceGateio : public ExecutionManagementServiceGateio 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 5b73e05d..475d048c 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceGateioPerpetualFutures : public ExecutionManagem 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 4b3ca9d6..6e3b08f1 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_gemini.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceGemini : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 7215a85c..5cb8ede7 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_huobi.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceHuobi : public ExecutionManagementServiceHuobiBa 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 aaae947c..2793db6e 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceHuobiCoinSwap : public ExecutionManagementServic 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 de7121bc..f2d33fdc 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceHuobiUsdtSwap : public ExecutionManagementServic 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 394cbfd5..d495e232 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kraken.h @@ -15,19 +15,19 @@ class ExecutionManagementServiceKraken : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 73a4d1a8..1e655f9e 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 @@ -15,19 +15,19 @@ class ExecutionManagementServiceKrakenFutures : public ExecutionManagementServic 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 944c24b0..b19b4240 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_kucoin.h @@ -12,11 +12,11 @@ class ExecutionManagementServiceKucoin : public ExecutionManagementServiceKucoin this->exchangeName = CCAPI_EXCHANGE_NAME_KUCOIN; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); - 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->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP // #else // 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 bc8d1f63..b1cfcc0f 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 @@ -12,11 +12,11 @@ class ExecutionManagementServiceKucoinFutures : public ExecutionManagementServic this->exchangeName = CCAPI_EXCHANGE_NAME_KUCOIN_FUTURES; this->baseUrlRest = sessionConfigs.getUrlRestBase().at(this->exchangeName); this->setHostRestFromUrlRest(this->baseUrlRest); - 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->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP // #else // 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 fabec045..c72837a9 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h @@ -15,19 +15,19 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 16dd0d0a..5064e943 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 @@ -14,19 +14,19 @@ class ExecutionManagementServiceMexcFutures : public ExecutionManagementService 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 94de8d5b..d3eb8bd6 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_okx.h @@ -14,19 +14,19 @@ class ExecutionManagementServiceOkx : public ExecutionManagementService { 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_fix_service.h b/include/ccapi_cpp/service/ccapi_fix_service.h index 88d41bf1..7fcdae90 100644 --- a/include/ccapi_cpp/service/ccapi_fix_service.h +++ b/include/ccapi_cpp/service/ccapi_fix_service.h @@ -105,7 +105,7 @@ class FixService : public Service { }); this->connectRetryOnFailTimerByConnectionIdMap[fixConnectionPtr->id] = timerPtr; } - std::shared_ptr createStreamFix(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, const std::string& host); + std::shared_ptr createStreamFix(net::io_context* iocPtr, net::ssl::context* ctxPtr, const std::string& host); void connect(Subscription& subscription) { std::string aHostFix = this->hostFix; std::string aPortFix = this->portFix; @@ -558,8 +558,9 @@ class FixService : public Service { std::string targetCompID; }; template <> -inline std::shared_ptr> FixService>::createStreamFix( - std::shared_ptr iocPtr, std::shared_ptr ctxPtr, const std::string& host) { +inline std::shared_ptr> FixService>::createStreamFix(net::io_context* iocPtr, + net::ssl::context* 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())) { @@ -570,8 +571,8 @@ inline std::shared_ptr> FixService -inline std::shared_ptr FixService::createStreamFix(std::shared_ptr iocPtr, - std::shared_ptr ctxPtr, const std::string& host) { +inline std::shared_ptr FixService::createStreamFix(net::io_context* iocPtr, net::ssl::context* ctxPtr, + const std::string& host) { std::shared_ptr streamPtr(new beast::tcp_stream(*iocPtr)); return streamPtr; } diff --git a/include/ccapi_cpp/service/ccapi_market_data_service.h b/include/ccapi_cpp/service/ccapi_market_data_service.h index 40db7432..2eff1bfa 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service.h @@ -17,7 +17,7 @@ namespace ccapi { class MarketDataService : public Service { public: MarketDataService(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : Service(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { CCAPI_LOGGER_FUNCTION_ENTER; this->requestOperationToMessageTypeMap = { @@ -175,7 +175,12 @@ class MarketDataService : public Service { return groups; } virtual std::string getInstrumentGroup(const Subscription& subscription) { - return this->baseUrlWs + "|" + subscription.getField() + "|" + subscription.getSerializedOptions() + "|" + subscription.getSerializedCredential(); + const auto& field = subscription.getField(); + if (field == CCAPI_GENERIC_PUBLIC_SUBSCRIPTION) { + return this->baseUrlWs + "|" + subscription.getField() + "|" + subscription.getCorrelationId() + "|" + subscription.getSerializedCredential(); + } else { + return this->baseUrlWs + "|" + subscription.getField() + "|" + subscription.getSerializedOptions() + "|" + subscription.getSerializedCredential(); + } } void prepareSubscription(const WsConnection& wsConnection, const Subscription& subscription) { auto instrument = subscription.getInstrument(); @@ -706,10 +711,10 @@ class MarketDataService : public Service { 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 { + if (subscription.getField() == CCAPI_GENERIC_PUBLIC_SUBSCRIPTION) { this->correlationIdByConnectionIdMap.insert({wsConnection.id, subscription.getCorrelationId()}); + } else { + this->prepareSubscription(wsConnection, subscription); } } CCAPI_LOGGER_INFO("about to subscribe to exchange"); 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 2c6da558..1362bee2 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ascendex.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceAscendex : public MarketDataService { public: MarketDataServiceAscendex(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_ASCENDEX; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 79afc94a..50da338c 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBinance : public MarketDataServiceBinanceBase { public: MarketDataServiceBinance(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_base.h index 78b450ab..2a556f3c 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 @@ -8,7 +8,7 @@ namespace ccapi { class MarketDataServiceBinanceBase : public MarketDataService { public: MarketDataServiceBinanceBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->enableCheckPingPongWebsocketApplicationLevel = false; } 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 a63db71d..dacf03b0 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBinanceCoinFutures : public MarketDataServiceBinanceDerivativesBase { public: MarketDataServiceBinanceCoinFutures(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBinanceDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_COIN_FUTURES; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_derivatives_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h index 947f9997..7cc5bc6b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_binance_derivatives_base.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceBinanceDerivativesBase : public MarketDataServiceBinanceBase { public: MarketDataServiceBinanceDerivativesBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->isDerivatives = true; } @@ -46,6 +46,7 @@ class MarketDataServiceBinanceDerivativesBase : public MarketDataServiceBinanceB } void extractInstrumentInfo(Element& element, const rj::Value& x) { element.insert(CCAPI_INSTRUMENT, x["symbol"].GetString()); + element.insert(CCAPI_INSTRUMENT_STATUS, x["status"].GetString()); element.insert(CCAPI_BASE_ASSET, x["baseAsset"].GetString()); element.insert(CCAPI_QUOTE_ASSET, x["quoteAsset"].GetString()); element.insert(CCAPI_INSTRUMENT, x["symbol"].GetString()); 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 ce814272..3ba26865 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBinanceUs : public MarketDataServiceBinanceBase { public: MarketDataServiceBinanceUs(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBinanceBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_US; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 d5dabf99..e5d42476 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBinanceUsdsFutures : public MarketDataServiceBinanceDerivativesBase { public: MarketDataServiceBinanceUsdsFutures(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBinanceDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BINANCE_USDS_FUTURES; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 ed0bc0de..23fc0dd7 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitfinex.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBitfinex : public MarketDataService { public: MarketDataServiceBitfinex(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITFINEX; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 b9f1145e..9bc0086e 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBitget : public MarketDataServiceBitgetBase { public: MarketDataServiceBitget(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBitgetBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITGET; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_base.h index aded1335..82ceff9d 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitget_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitget_base.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceBitgetBase : public MarketDataService { public: MarketDataServiceBitgetBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->hostHttpHeaderValueIgnorePort = true; } 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 2425d3e7..84634f9f 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBitgetFutures : public MarketDataServiceBitgetBase { public: MarketDataServiceBitgetFutures(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBitgetBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITGET_FUTURES; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 a3046e6f..c95f0eb7 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmart.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBitmart : public MarketDataService { public: MarketDataServiceBitmart(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITMART; this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/api?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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 1d5ac457..9c207986 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitmex.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBitmex : public MarketDataService { public: MarketDataServiceBitmex(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITMEX; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 91b36c07..d7449b95 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bitstamp.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceBitstamp : public MarketDataService { public: MarketDataServiceBitstamp(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BITSTAMP; this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); @@ -15,19 +15,19 @@ class MarketDataServiceBitstamp : 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 7f678eaf..383c4b2b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBybit : public MarketDataServiceBybitBase { public: MarketDataServiceBybit(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBybitBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BYBIT; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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->getHistoricalTradesTarget = "/spot/v3/public/quote/trades"; this->getRecentCandlesticksTarget = "/spot/v3/public/quote/kline"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_bybit_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_bybit_base.h index fcfcb2bf..d7791406 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_bybit_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_bybit_base.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceBybitBase : public MarketDataService { public: MarketDataServiceBybitBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) {} virtual ~MarketDataServiceBybitBase() {} #ifndef CCAPI_EXPOSE_INTERNAL 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 f59fba9a..0cd3f464 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceBybitDerivatives : public MarketDataServiceBybitBase { public: MarketDataServiceBybitDerivatives(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceBybitBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_BYBIT_DERIVATIVES; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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->getHistoricalTradesTarget = "/derivatives/v3/public/recent-trade"; this->getRecentCandlesticksTarget = "/derivatives/v3/public/kline"; 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 9ddb2094..cc02f039 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_coinbase.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceCoinbase : public MarketDataService { public: MarketDataServiceCoinbase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_COINBASE; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 10f9ccc7..68b978ac 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_cryptocom.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceCryptocom : public MarketDataService { public: MarketDataServiceCryptocom(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_CRYPTOCOM; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 b46c098b..5d829d76 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceDeribit : public MarketDataService { public: MarketDataServiceDeribit(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_DERIBIT; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_erisx.h b/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h index 00e8dbe6..354c4407 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_erisx.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceErisx : public MarketDataService { public: MarketDataServiceErisx(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_ERISX; this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName); 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 4e74d2b1..c580eac6 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceFtx : public MarketDataServiceFtxBase { public: MarketDataServiceFtx(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceFtxBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_FTX; this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_base.h index 2ae27847..dd5632f5 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_ftx_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_ftx_base.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceFtxBase : public MarketDataService { public: MarketDataServiceFtxBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->shouldAlignSnapshot = true; this->getRecentTradesTarget = "/api/markets/{market_name}/trades"; 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 c3e67d0f..d2b7f1a8 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 @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceFtxUs : public MarketDataServiceFtxBase { public: MarketDataServiceFtxUs(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceFtxBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_FTX_US; this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + "/ws"; 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 328bad71..6327817a 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceGateio : public MarketDataServiceGateioBase { public: MarketDataServiceGateio(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceGateioBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GATEIO; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_base.h index 732b2b63..bc3da42c 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gateio_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gateio_base.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceGateioBase : public MarketDataService { public: MarketDataServiceGateioBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) {} virtual ~MarketDataServiceGateioBase() {} #ifndef CCAPI_EXPOSE_INTERNAL 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 bb5d6f1f..2a8d8631 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceGateioPerpetualFutures : public MarketDataServiceGateioBase { public: MarketDataServiceGateioPerpetualFutures(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceGateioBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GATEIO_PERPETUAL_FUTURES; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 63b8b4fe..c099df57 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_gemini.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceGemini : public MarketDataService { public: MarketDataServiceGemini(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_GEMINI; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 dd6386e0..8eea345e 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceHuobi : public MarketDataServiceHuobiBase { public: MarketDataServiceHuobi(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceHuobiBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_base.h index 5acc29b3..108ce337 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 @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceHuobiBase : public MarketDataService { public: MarketDataServiceHuobiBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->needDecompressWebsocketMessage = true; #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP 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 27abe079..46f5ef56 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceHuobiCoinSwap : public MarketDataServiceHuobiDerivativesBase { public: MarketDataServiceHuobiCoinSwap(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceHuobiDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI_COIN_SWAP; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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_derivatives_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h index 2bef11e9..d8f02e9d 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_huobi_derivatives_base.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceHuobiDerivativesBase : public MarketDataServiceHuobiBase { public: MarketDataServiceHuobiDerivativesBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceHuobiBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->isDerivatives = true; } 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 a3d255a8..114a3f72 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceHuobiUsdtSwap : public MarketDataServiceHuobiDerivativesBase { public: MarketDataServiceHuobiUsdtSwap(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceHuobiDerivativesBase(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_HUOBI_USDT_SWAP; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 fba83d10..569093da 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kraken.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceKraken : public MarketDataService { public: MarketDataServiceKraken(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KRAKEN; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 85f88e8b..8dccc1e1 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceKrakenFutures : public MarketDataService { public: MarketDataServiceKrakenFutures(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_KRAKEN_FUTURES; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 6f63c087..19474523 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin.h @@ -7,18 +7,18 @@ namespace ccapi { class MarketDataServiceKucoin : public MarketDataServiceKucoinBase { public: MarketDataServiceKucoin(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceKucoinBase(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()); - } + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP // #else // try { diff --git a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h index ca53f782..892722f3 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_kucoin_base.h @@ -7,7 +7,7 @@ namespace ccapi { class MarketDataServiceKucoinBase : public MarketDataService { public: MarketDataServiceKucoinBase(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) {} virtual ~MarketDataServiceKucoinBase() {} #ifndef CCAPI_EXPOSE_INTERNAL 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 29fc56be..f4764f5d 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 @@ -7,18 +7,18 @@ namespace ccapi { class MarketDataServiceKucoinFutures : public MarketDataServiceKucoinBase { public: MarketDataServiceKucoinFutures(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataServiceKucoinBase(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()); - } + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP // #else // 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 952339f5..224d4fd1 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_mexc.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceMexc : public MarketDataService { public: MarketDataServiceMexc(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_MEXC; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 753ef1ec..929d48f8 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 @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceMexcFutures : public MarketDataService { public: MarketDataServiceMexcFutures(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_MEXC_FUTURES; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 6c816677..16ed7f4e 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_okx.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_okx.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceOkx : public MarketDataService { public: MarketDataServiceOkx(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_OKX; this->baseUrlWs = sessionConfigs.getUrlWebsocketBase().at(this->exchangeName) + CCAPI_OKX_PUBLIC_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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 52e336a5..7aaa0792 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service_whitebit.h @@ -7,26 +7,26 @@ namespace ccapi { class MarketDataServiceWhitebit : public MarketDataService { public: MarketDataServiceWhitebit(std::function*)> eventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(eventHandler, sessionOptions, sessionConfigs, serviceContextPtr) { this->exchangeName = CCAPI_EXCHANGE_NAME_WHITEBIT; 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()); - } -#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP -#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 + // try { + // this->tcpResolverResultsRest = this->resolver.resolve(this->hostRest, this->portRest); + // } catch (const std::exception& e) { + // CCAPI_LOGGER_FATAL(std::string("e.what() = ") + e.what()); + // } + // #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP + // #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 dc0bc960..e7f10aa7 100644 --- a/include/ccapi_cpp/service/ccapi_service.h +++ b/include/ccapi_cpp/service/ccapi_service.h @@ -69,8 +69,8 @@ namespace beast = boost::beast; namespace http = beast::http; namespace net = boost::asio; -namespace ssl = boost::asio::ssl; -using tcp = boost::asio::ip::tcp; +namespace ssl = net::ssl; +using tcp = net::ip::tcp; #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP namespace wspp = websocketpp; #endif @@ -82,7 +82,7 @@ namespace ccapi { */ class Service : public std::enable_shared_from_this { public: - typedef std::shared_ptr ServiceContextPtr; + typedef ServiceContext* ServiceContextPtr; #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP typedef wspp::lib::error_code ErrorCode; #else @@ -117,8 +117,7 @@ class Service : public std::enable_shared_from_this { sessionConfigs(sessionConfigs), serviceContextPtr(serviceContextPtr), resolver(*serviceContextPtr->ioContextPtr), - resolverWs(*serviceContextPtr->ioContextPtr), - httpConnectionPool(sessionOptions.httpConnectionPoolMaxSize) { + resolverWs(*serviceContextPtr->ioContextPtr) { this->enableCheckPingPongWebsocketProtocolLevel = this->sessionOptions.enableCheckPingPongWebsocketProtocolLevel; this->enableCheckPingPongWebsocketApplicationLevel = this->sessionOptions.enableCheckPingPongWebsocketApplicationLevel; // this->pingIntervalMillisecondsByMethodMap[PingPongMethod::WEBSOCKET_PROTOCOL_LEVEL] = sessionOptions.pingWebsocketProtocolLevelIntervalMilliseconds; @@ -142,11 +141,10 @@ class Service : public std::enable_shared_from_this { for (const auto& x : this->connectRetryOnFailTimerByConnectionIdMap) { x.second->cancel(); } - if (this->httpConnectionPoolPurgeTimer) { - this->httpConnectionPoolPurgeTimer->cancel(); - } } - void purgeHttpConnectionPool() { this->httpConnectionPool.purge(); } + void purgeHttpConnectionPool() { this->httpConnectionPool.clear(); } + void purgeHttpConnectionPool(const std::string& localIpAddress) { this->httpConnectionPool.erase(localIpAddress); } + void purgeHttpConnectionPool(const std::string& localIpAddress, const std::string& baseUrl) { this->httpConnectionPool[localIpAddress].erase(baseUrl); } void forceCloseWebsocketConnections() { for (const auto& x : this->wsConnectionByIdMap) { ErrorCode ec; @@ -219,23 +217,23 @@ class Service : public std::enable_shared_from_this { std::shared_ptr> promisePtr(promisePtrRaw); HttpRetry retry(0, 0, "", promisePtr); if (delayMilliseconds > 0) { - TimerPtr timerPtr(new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(delayMilliseconds))); + TimerPtr timerPtr(new net::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->tryRequest(request, req, retry, eventQueuePtr); } that->sendRequestDelayTimerByCorrelationIdMap.erase(request.getCorrelationId()); }); this->sendRequestDelayTimerByCorrelationIdMap[request.getCorrelationId()] = timerPtr; } else { request.setTimeSent(now); - this->tryRequest(request, req, retry, eventQueuePtr); + net::post(*this->serviceContextPtr->ioContextPtr, + [that = shared_from_this(), request, req, retry, eventQueuePtr]() mutable { that->tryRequest(request, req, retry, eventQueuePtr); }); } std::shared_ptr> futurePtr(nullptr); if (useFuture) { @@ -307,7 +305,7 @@ class Service : public std::enable_shared_from_this { #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP typedef ServiceContext::TlsClient TlsClient; #endif - typedef std::shared_ptr TimerPtr; + typedef std::shared_ptr TimerPtr; void setHostRestFromUrlRest(std::string baseUrlRest) { auto hostPort = this->extractHostFromUrl(baseUrlRest); this->hostRest = hostPort.first; @@ -359,7 +357,13 @@ class Service : public std::enable_shared_from_this { } std::shared_ptr httpConnectionPtr(new HttpConnection(this->hostRest, this->portRest, streamPtr)); CCAPI_LOGGER_DEBUG("httpConnection = " + toString(*httpConnectionPtr)); - this->startConnect(httpConnectionPtr, req, errorHandler, responseHandler, timeoutMilliseconds, this->tcpResolverResultsRest); + std::shared_ptr newResolverPtr(new tcp::resolver(*this->serviceContextPtr->ioContextPtr)); + CCAPI_LOGGER_TRACE("this->hostRest = " + this->hostRest); + CCAPI_LOGGER_TRACE("this->portRest = " + this->portRest); + newResolverPtr->async_resolve(this->hostRest, this->portRest, + beast::bind_front_handler(&Service::onResolve, shared_from_this(), httpConnectionPtr, newResolverPtr, req, errorHandler, + responseHandler, timeoutMilliseconds)); + // this->startConnect(httpConnectionPtr, req, errorHandler, responseHandler, timeoutMilliseconds, this->tcpResolverResultsRest); } void sendRequest(const std::string& host, const std::string& port, const http::request& req, std::function errorHandler, std::function&)> responseHandler, @@ -491,7 +495,7 @@ class Service : public std::enable_shared_from_this { responseHandler(*resPtr); } template - std::shared_ptr createStream(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, const std::string& host) { + std::shared_ptr createStream(net::io_context* iocPtr, net::ssl::context* 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())) { @@ -503,14 +507,13 @@ class Service : public std::enable_shared_from_this { } #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP #else - std::shared_ptr>> createWsStream(std::shared_ptr iocPtr, - std::shared_ptr ctxPtr) { + std::shared_ptr>> createWsStream(net::io_context* iocPtr, net::ssl::context* ctxPtr) { std::shared_ptr>> streamPtr( new beast::websocket::stream>(*iocPtr, *ctxPtr)); return streamPtr; } #endif - // std::shared_ptr> createStream(std::shared_ptr iocPtr, std::shared_ptr ctxPtr, + // std::shared_ptr> createStream(net::io_context* iocPtr, net::ssl::context* 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) @@ -521,31 +524,120 @@ class Service : public std::enable_shared_from_this { // } // return streamPtr; // } - void performRequest(std::shared_ptr httpConnectionPtr, const Request& request, http::request& req, const HttpRetry& retry, - Queue* eventQueuePtr) { + void performRequestWithNewHttpConnection(std::shared_ptr httpConnectionPtr, const Request& request, http::request& req, + const HttpRetry& retry, Queue* eventQueuePtr) { CCAPI_LOGGER_FUNCTION_ENTER; CCAPI_LOGGER_DEBUG("httpConnection = " + toString(*httpConnectionPtr)); + CCAPI_LOGGER_DEBUG("request = " + toString(request)); CCAPI_LOGGER_DEBUG("retry = " + toString(retry)); beast::ssl_stream& stream = *httpConnectionPtr->streamPtr; CCAPI_LOGGER_DEBUG("this->sessionOptions.httpRequestTimeoutMilliseconds = " + toString(this->sessionOptions.httpRequestTimeoutMilliseconds)); if (this->sessionOptions.httpRequestTimeoutMilliseconds > 0) { beast::get_lowest_layer(stream).expires_after(std::chrono::milliseconds(this->sessionOptions.httpRequestTimeoutMilliseconds)); } + const auto& localIpAddress = request.getLocalIpAddress(); + CCAPI_LOGGER_TRACE("localIpAddress = " + localIpAddress); + if (!localIpAddress.empty()) { + if (!beast::get_lowest_layer(stream).socket().is_open()) { + ErrorCode ec; + CCAPI_LOGGER_TRACE("before socket open"); + beast::get_lowest_layer(stream).socket().open(net::ip::tcp::v4(), ec); + if (ec) { + CCAPI_LOGGER_TRACE("fail"); + this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "socket open", {request.getCorrelationId()}, eventQueuePtr); + return; + } + } + ErrorCode ec; + tcp::endpoint existingLocalEndpoint = beast::get_lowest_layer(stream).socket().local_endpoint(ec); + if (ec) { + CCAPI_LOGGER_TRACE("fail"); + this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "socket get local endpoint", {request.getCorrelationId()}, + eventQueuePtr); + return; + } + tcp::endpoint localEndpoint(net::ip::address::from_string(localIpAddress), + 0); // Note: Setting the port to 0 means the OS will select a free port for you + if (localEndpoint != existingLocalEndpoint) { + ErrorCode ec; + CCAPI_LOGGER_TRACE("before socket bind"); + beast::get_lowest_layer(stream).socket().bind(localEndpoint, ec); + if (ec) { + CCAPI_LOGGER_TRACE("fail"); + this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "socket bind", {request.getCorrelationId()}, eventQueuePtr); + return; + } + } + } + std::shared_ptr newResolverPtr(new tcp::resolver(*this->serviceContextPtr->ioContextPtr)); + CCAPI_LOGGER_TRACE("httpConnectionPtr->host = " + httpConnectionPtr->host); + CCAPI_LOGGER_TRACE("httpConnectionPtr->port = " + httpConnectionPtr->port); + newResolverPtr->async_resolve( + httpConnectionPtr->host, httpConnectionPtr->port, + beast::bind_front_handler(&Service::onResolveWorkaround, shared_from_this(), httpConnectionPtr, newResolverPtr, request, req, retry, eventQueuePtr)); + CCAPI_LOGGER_FUNCTION_EXIT; + } + void onResolveWorkaround(std::shared_ptr httpConnectionPtr, std::shared_ptr newResolverPtr, Request request, + http::request req, HttpRetry retry, Queue* eventQueuePtr, beast::error_code ec, + tcp::resolver::results_type tcpNewResolverResults) { + if (ec) { + CCAPI_LOGGER_TRACE("fail"); + this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "DNS resolve", {request.getCorrelationId()}, eventQueuePtr); + return; + } + CCAPI_LOGGER_TRACE("before asyncConnectWorkaround"); + TimerPtr timerPtr{nullptr}; + if (this->sessionOptions.httpRequestTimeoutMilliseconds > 0) { + timerPtr = std::make_shared(*this->serviceContextPtr->ioContextPtr, + std::chrono::milliseconds(this->sessionOptions.httpRequestTimeoutMilliseconds)); + timerPtr->async_wait([httpConnectionPtr](ErrorCode const& ec) { + if (ec) { + if (ec != net::error::make_error_code(net::error::basic_errors::operation_aborted)) { + CCAPI_LOGGER_ERROR("httpConnectionPtr = " + toString(*httpConnectionPtr) + ", connect timeout timer error: " + ec.message()); + } + } else { + CCAPI_LOGGER_TRACE("httpConnectionPtr = " + toString(*httpConnectionPtr) + ", connect timeout timer triggered"); + beast::ssl_stream& stream = *httpConnectionPtr->streamPtr; + beast::get_lowest_layer(stream).socket().cancel(); + } + }); + } + this->asyncConnectWorkaround(httpConnectionPtr, timerPtr, request, req, retry, eventQueuePtr, tcpNewResolverResults, 0); + CCAPI_LOGGER_TRACE("after asyncConnectWorkaround"); + } + // used to avoid asio close and reopen the socket and therefore losing the bound local ip address + void asyncConnectWorkaround(std::shared_ptr httpConnectionPtr, TimerPtr timerPtr, Request request, http::request req, + HttpRetry retry, Queue* eventQueuePtr, tcp::resolver::results_type tcpNewResolverResults, + size_t tcpNewResolverResultsIndex) { + auto it = tcpNewResolverResults.begin(); + std::advance(it, tcpNewResolverResultsIndex); + if (it == tcpNewResolverResults.end()) { + ErrorCode ec = net::error::make_error_code(net::error::misc_errors::not_found); + this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "connect", {request.getCorrelationId()}, eventQueuePtr); + return; + } CCAPI_LOGGER_TRACE("before async_connect"); - beast::get_lowest_layer(stream).async_connect( - this->tcpResolverResultsRest, - beast::bind_front_handler(&Service::onConnect_2, shared_from_this(), httpConnectionPtr, request, req, retry, eventQueuePtr)); + beast::ssl_stream& stream = *httpConnectionPtr->streamPtr; + beast::get_lowest_layer(stream).socket().async_connect( + *it, beast::bind_front_handler(&Service::onConnect_2, shared_from_this(), httpConnectionPtr, timerPtr, request, req, retry, eventQueuePtr, + tcpNewResolverResults, tcpNewResolverResultsIndex)); CCAPI_LOGGER_TRACE("after async_connect"); - CCAPI_LOGGER_FUNCTION_EXIT; } - void onConnect_2(std::shared_ptr httpConnectionPtr, Request request, http::request req, HttpRetry retry, - Queue* eventQueuePtr, beast::error_code ec, tcp::resolver::results_type::endpoint_type) { + void onConnect_2(std::shared_ptr httpConnectionPtr, TimerPtr timerPtr, Request request, http::request req, HttpRetry retry, + Queue* eventQueuePtr, tcp::resolver::results_type tcpNewResolverResults, size_t tcpNewResolverResultsIndex, beast::error_code ec) { CCAPI_LOGGER_TRACE("async_connect callback start"); + CCAPI_LOGGER_TRACE("local endpoint has address " + beast::get_lowest_layer(*httpConnectionPtr->streamPtr).socket().local_endpoint().address().to_string()); if (ec) { CCAPI_LOGGER_TRACE("fail"); - this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "connect", {request.getCorrelationId()}, eventQueuePtr); + if (ec == net::error::make_error_code(net::error::basic_errors::operation_aborted)) { + CCAPI_LOGGER_TRACE("fail"); + this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "connect attempt timeout", {request.getCorrelationId()}, eventQueuePtr); + return; + } + this->asyncConnectWorkaround(httpConnectionPtr, timerPtr, request, req, retry, eventQueuePtr, tcpNewResolverResults, tcpNewResolverResultsIndex + 1); return; } + timerPtr->cancel(); CCAPI_LOGGER_TRACE("connected"); beast::ssl_stream& stream = *httpConnectionPtr->streamPtr; // #ifdef CCAPI_DISABLE_NAGLE_ALGORITHM @@ -586,7 +678,7 @@ class Service : public std::enable_shared_from_this { if (ec) { CCAPI_LOGGER_TRACE("fail"); this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "write", {request.getCorrelationId()}, eventQueuePtr); - this->httpConnectionPool.purge(); + this->httpConnectionPool[request.getLocalIpAddress()][request.getBaseUrl()].clear(); auto now = UtilTime::now(); auto req = this->convertRequest(request, now); retry.numRetry += 1; @@ -603,32 +695,17 @@ class Service : public std::enable_shared_from_this { beast::bind_front_handler(&Service::onRead_2, shared_from_this(), httpConnectionPtr, request, reqPtr, retry, bufferPtr, resPtr, eventQueuePtr)); CCAPI_LOGGER_TRACE("after async_read"); } - void setHttpConnectionPoolPurgeTimer() { - 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"); - } else { - if (std::chrono::duration_cast(now - that->lastHttpConnectionPoolPushBackTp).count() > - that->sessionOptions.httpConnectionPoolIdleTimeoutMilliseconds) { - that->httpConnectionPool.purge(); - } - 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, beast::error_code ec, std::size_t bytes_transferred) { CCAPI_LOGGER_TRACE("async_read callback start"); + CCAPI_LOGGER_TRACE("local endpoint has address " + beast::get_lowest_layer(*httpConnectionPtr->streamPtr).socket().local_endpoint().address().to_string()); auto now = UtilTime::now(); boost::ignore_unused(bytes_transferred); if (ec) { CCAPI_LOGGER_TRACE("fail"); this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "read", {request.getCorrelationId()}, eventQueuePtr); - this->httpConnectionPool.purge(); + this->httpConnectionPool[request.getLocalIpAddress()][request.getBaseUrl()].clear(); auto now = UtilTime::now(); auto req = this->convertRequest(request, now); retry.numRetry += 1; @@ -636,19 +713,17 @@ class Service : public std::enable_shared_from_this { return; } if (!this->sessionOptions.enableOneHttpConnectionPerRequest) { - try { - if (std::chrono::duration_cast(this->lastHttpConnectionPoolPushBackTp.time_since_epoch()).count() == 0 && - this->sessionOptions.httpConnectionPoolIdleTimeoutMilliseconds > 0) { - this->setHttpConnectionPoolPurgeTimer(); - } - this->httpConnectionPool.pushBack(std::move(httpConnectionPtr)); - this->lastHttpConnectionPoolPushBackTp = now; - CCAPI_LOGGER_TRACE("pushed back httpConnectionPtr " + toString(*httpConnectionPtr) + " to pool"); - } catch (const std::runtime_error& e) { - if (e.what() != this->httpConnectionPool.EXCEPTION_QUEUE_FULL) { - CCAPI_LOGGER_ERROR(std::string("e.what() = ") + e.what()); - } + httpConnectionPtr->lastReceiveDataTp = now; + const auto& localIpAddress = request.getLocalIpAddress(); + const auto& requestBaseUrl = request.getBaseUrl(); + if (this->sessionOptions.httpConnectionPoolMaxSize > 0 && + this->httpConnectionPool[localIpAddress][requestBaseUrl].size() >= this->sessionOptions.httpConnectionPoolMaxSize) { + CCAPI_LOGGER_TRACE("httpConnectionPool is full for localIpAddress = " + localIpAddress + ", requestBaseUrl = " + toString(requestBaseUrl)); + this->httpConnectionPool[localIpAddress][requestBaseUrl].pop_front(); } + this->httpConnectionPool[localIpAddress][requestBaseUrl].push_back(httpConnectionPtr); + CCAPI_LOGGER_TRACE("pushed back httpConnectionPtr " + toString(*httpConnectionPtr) + " to httpConnectionPool for localIpAddress = " + localIpAddress + + ", requestBaseUrl = " + toString(requestBaseUrl)); } #if defined(CCAPI_ENABLE_LOG_DEBUG) || defined(CCAPI_ENABLE_LOG_TRACE) { @@ -731,7 +806,13 @@ class Service : public std::enable_shared_from_this { CCAPI_LOGGER_TRACE("retry = " + toString(retry)); if (retry.numRetry <= this->sessionOptions.httpMaxNumRetry && retry.numRedirect <= this->sessionOptions.httpMaxNumRedirect) { try { - if (this->sessionOptions.enableOneHttpConnectionPerRequest || this->httpConnectionPool.empty()) { + const auto& localIpAddress = request.getLocalIpAddress(); + const auto& requestBaseUrl = request.getBaseUrl(); + if (this->sessionOptions.enableOneHttpConnectionPerRequest || this->httpConnectionPool[localIpAddress][requestBaseUrl].empty() || + std::chrono::duration_cast(request.getTimeSent() - + this->httpConnectionPool[localIpAddress][requestBaseUrl].back()->lastReceiveDataTp) + .count() >= this->sessionOptions.httpConnectionKeepAliveTimeoutSeconds) { + this->httpConnectionPool[localIpAddress][requestBaseUrl].clear(); std::shared_ptr> streamPtr(nullptr); try { streamPtr = this->createStream>(this->serviceContextPtr->ioContextPtr, this->serviceContextPtr->sslContextPtr, @@ -741,32 +822,24 @@ class Service : public std::enable_shared_from_this { this->onError(Event::Type::REQUEST_STATUS, Message::Type::REQUEST_FAILURE, ec, "create stream", {request.getCorrelationId()}, eventQueuePtr); return; } - std::shared_ptr httpConnectionPtr(new HttpConnection(this->hostRest, this->portRest, streamPtr)); - CCAPI_LOGGER_WARN("about to perform request with new httpConnectionPtr " + toString(*httpConnectionPtr)); - this->performRequest(httpConnectionPtr, request, req, retry, eventQueuePtr); - } else { - std::shared_ptr httpConnectionPtr(nullptr); - try { - httpConnectionPtr = std::move(this->httpConnectionPool.popBack()); - CCAPI_LOGGER_TRACE("about to perform request with existing httpConnectionPtr " + toString(*httpConnectionPtr)); - this->startWrite_2(httpConnectionPtr, request, req, retry, eventQueuePtr); - } catch (const std::runtime_error& e) { - if (e.what() != this->httpConnectionPool.EXCEPTION_QUEUE_EMPTY) { - CCAPI_LOGGER_ERROR(std::string("e.what() = ") + e.what()); - } - std::shared_ptr> streamPtr(nullptr); - try { - 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); - return; - } - httpConnectionPtr = std::make_shared(this->hostRest, this->portRest, streamPtr); - CCAPI_LOGGER_WARN("about to perform request with new httpConnectionPtr " + toString(*httpConnectionPtr)); - this->performRequest(httpConnectionPtr, request, req, retry, eventQueuePtr); + std::string host, port; + if (requestBaseUrl.empty()) { + host = this->hostRest; + port = this->portRest; + } else { + host = request.getHost(); + port = request.getPort(); } + std::shared_ptr httpConnectionPtr(new HttpConnection(host, port, streamPtr)); + CCAPI_LOGGER_WARN("about to perform request with new httpConnectionPtr " + toString(*httpConnectionPtr) + " for localIpAddress = " + localIpAddress + + ", requestBaseUrl = " + toString(requestBaseUrl)); + this->performRequestWithNewHttpConnection(httpConnectionPtr, request, req, retry, eventQueuePtr); + } else { + std::shared_ptr httpConnectionPtr = this->httpConnectionPool[localIpAddress][requestBaseUrl].back(); + this->httpConnectionPool[localIpAddress][requestBaseUrl].pop_back(); + CCAPI_LOGGER_TRACE("about to perform request with existing httpConnectionPtr " + toString(*httpConnectionPtr) + + " for localIpAddress = " + localIpAddress + ", requestBaseUrl = " + toString(requestBaseUrl)); + this->startWrite_2(httpConnectionPtr, request, req, retry, eventQueuePtr); } } catch (const std::exception& e) { CCAPI_LOGGER_ERROR(std::string("e.what() = ") + e.what()); @@ -799,7 +872,7 @@ class Service : public std::enable_shared_from_this { } else { req.keep_alive(true); } - req.set(http::field::host, this->hostRest); + req.set(http::field::host, request.getBaseUrl().empty() ? this->hostRest : request.getHost()); req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); this->convertRequestForRest(req, request, now, symbolId, credential); CCAPI_LOGGER_FUNCTION_EXIT; @@ -949,7 +1022,7 @@ class Service : public std::enable_shared_from_this { 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 timerPtr(new net::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) { @@ -1128,7 +1201,7 @@ class Service : public std::enable_shared_from_this { this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id).at(method)->cancel(); } TimerPtr timerPtr( - new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(pingIntervalMilliseconds - pongTimeoutMilliseconds))); + new net::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) { @@ -1149,7 +1222,7 @@ class Service : public std::enable_shared_from_this { 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 timerPtr(new net::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) { @@ -1315,7 +1388,7 @@ class Service : public std::enable_shared_from_this { 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) { + void onReadWs(std::shared_ptr wsConnectionPtr, const ErrorCode& ec, std::size_t n) { CCAPI_LOGGER_FUNCTION_ENTER; CCAPI_LOGGER_TRACE("n = " + toString(n)); auto now = UtilTime::now(); @@ -1412,10 +1485,10 @@ class Service : public std::enable_shared_from_this { CCAPI_LOGGER_TRACE("before async_write"); CCAPI_LOGGER_TRACE("numBytesToWrite = " + toString(numBytesToWrite)); stream.binary(false); - stream.async_write(boost::asio::buffer(data, numBytesToWrite), beast::bind_front_handler(&Service::onWriteWs, shared_from_this(), wsConnectionPtr)); + stream.async_write(net::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, const boost::system::error_code& ec, std::size_t n) { + void onWriteWs(std::shared_ptr wsConnectionPtr, const ErrorCode& ec, std::size_t n) { CCAPI_LOGGER_FUNCTION_ENTER; auto& connectionId = wsConnectionPtr->id; auto& writeMessageBuffer = this->writeMessageBufferByConnectionIdMap[connectionId]; @@ -1444,7 +1517,7 @@ class Service : public std::enable_shared_from_this { 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 timerPtr(new net::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()) { @@ -1657,7 +1730,7 @@ class Service : public std::enable_shared_from_this { this->pingTimerByMethodByConnectionIdMap.at(wsConnection.id).at(method)->cancel(); } TimerPtr timerPtr( - new boost::asio::steady_timer(*this->serviceContextPtr->ioContextPtr, std::chrono::milliseconds(pingIntervalMilliseconds - pongTimeoutMilliseconds))); + new net::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()) { @@ -1679,7 +1752,7 @@ class Service : public std::enable_shared_from_this { 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 timerPtr(new net::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()) { @@ -1744,10 +1817,8 @@ class Service : public std::enable_shared_from_this { std::string portRest; std::string hostWs; std::string portWs; - tcp::resolver::results_type tcpResolverResultsRest, tcpResolverResultsWs; - Queue> httpConnectionPool; - TimePoint lastHttpConnectionPoolPushBackTp{std::chrono::seconds{0}}; - TimerPtr httpConnectionPoolPurgeTimer; + // tcp::resolver::results_type tcpResolverResultsRest, tcpResolverResultsWs; + std::map>>> httpConnectionPool; std::map credentialDefault; std::map sendRequestDelayTimerByCorrelationIdMap; #ifdef CCAPI_LEGACY_USE_WEBSOCKETPP diff --git a/include/ccapi_cpp/service/ccapi_service_context.h b/include/ccapi_cpp/service/ccapi_service_context.h index b3a31f42..589e6888 100644 --- a/include/ccapi_cpp/service/ccapi_service_context.h +++ b/include/ccapi_cpp/service/ccapi_service_context.h @@ -77,23 +77,46 @@ namespace ccapi { class ServiceContext CCAPI_FINAL { public: typedef boost::asio::io_context IoContext; - typedef std::shared_ptr IoContextPtr; + typedef boost::asio::io_context* IoContextPtr; typedef boost::asio::executor_work_guard ExecutorWorkGuard; - typedef std::shared_ptr ExecutorWorkGuardPtr; + typedef ExecutorWorkGuard* ExecutorWorkGuardPtr; typedef boost::asio::ssl::context SslContext; - typedef std::shared_ptr SslContextPtr; + typedef SslContext* SslContextPtr; ServiceContext() { + this->ioContextPtr = new boost::asio::io_context(); + this->executorWorkGuardPtr = new ExecutorWorkGuard(this->ioContextPtr->get_executor()); + this->sslContextPtr = new SslContext(SslContext::tls_client); // 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 } +#ifndef SWIG + ServiceContext(IoContextPtr ioContextPtr) { + this->ioContextPtr = ioContextPtr; + this->executorWorkGuardPtr = new ExecutorWorkGuard(this->ioContextPtr->get_executor()); + this->sslContextPtr = new SslContext(SslContext::tls_client); + this->sslContextPtr->set_verify_mode(boost::asio::ssl::verify_none); + } + ServiceContext(SslContextPtr sslContextPtr) { + this->ioContextPtr = new boost::asio::io_context(); + this->executorWorkGuardPtr = new ExecutorWorkGuard(this->ioContextPtr->get_executor()); + this->sslContextPtr = sslContextPtr; + this->sslContextPtr->set_verify_mode(boost::asio::ssl::verify_none); + } + ServiceContext(IoContextPtr ioContextPtr, SslContextPtr sslContextPtr) { + this->ioContextPtr = ioContextPtr; + this->executorWorkGuardPtr = new ExecutorWorkGuard(this->ioContextPtr->get_executor()); + this->sslContextPtr = sslContextPtr; + this->sslContextPtr->set_verify_mode(boost::asio::ssl::verify_none); + } +#endif ServiceContext(const ServiceContext&) = delete; ServiceContext& operator=(const ServiceContext&) = delete; virtual ~ServiceContext() { - // delete this->ExecutorWorkGuardPtr; - // delete this->ioContextPtr; - // delete this->sslContextPtr; + delete this->executorWorkGuardPtr; + delete this->ioContextPtr; + delete this->sslContextPtr; } void start() { CCAPI_LOGGER_INFO("about to start client asio io_context run loop"); @@ -104,9 +127,12 @@ class ServiceContext CCAPI_FINAL { this->executorWorkGuardPtr->reset(); this->ioContextPtr->stop(); } - IoContextPtr ioContextPtr{new IoContext()}; - ExecutorWorkGuardPtr executorWorkGuardPtr{new ExecutorWorkGuard(ioContextPtr->get_executor())}; - SslContextPtr sslContextPtr{new SslContext(SslContext::tls_client)}; + IoContextPtr ioContextPtr{nullptr}; + ExecutorWorkGuardPtr executorWorkGuardPtr{nullptr}; + SslContextPtr sslContextPtr{nullptr}; + // IoContextPtr ioContextPtr{new IoContext()}; + // ExecutorWorkGuardPtr executorWorkGuardPtr{new ExecutorWorkGuard(ioContextPtr->get_executor())}; + // SslContextPtr sslContextPtr{new SslContext(SslContext::tls_client)}; }; } /* namespace ccapi */ diff --git a/test/test_unit/include/ccapi_cpp/ccapi_test_market_data_helper.h b/test/test_unit/include/ccapi_cpp/ccapi_test_market_data_helper.h index 15ebc54f..2a0ca10f 100644 --- a/test/test_unit/include/ccapi_cpp/ccapi_test_market_data_helper.h +++ b/test/test_unit/include/ccapi_cpp/ccapi_test_market_data_helper.h @@ -5,7 +5,7 @@ namespace ccapi { class MarketDataServiceGeneric final : public MarketDataService { public: MarketDataServiceGeneric(std::function*)> wsEventHandler, SessionOptions sessionOptions, SessionConfigs sessionConfigs, - std::shared_ptr serviceContextPtr) + ServiceContext* serviceContextPtr) : MarketDataService(wsEventHandler, sessionOptions, sessionConfigs, serviceContextPtr) {} using MarketDataService::updateOrderBook; }; diff --git a/test/test_unit/src/execution_management/binance_us/test.cpp b/test/test_unit/src/execution_management/binance_us/test.cpp index 2fd4018e..0ada7a52 100644 --- a/test/test_unit/src/execution_management/binance_us/test.cpp +++ b/test/test_unit/src/execution_management/binance_us/test.cpp @@ -10,8 +10,8 @@ class ExecutionManagementServiceBinanceUsTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = + std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_BINANCE_US_API_KEY, "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"}, {CCAPI_BINANCE_US_API_SECRET, "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"}, @@ -19,6 +19,7 @@ class ExecutionManagementServiceBinanceUsTest : public ::testing::Test { this->timestamp = 1499827319559; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/binance_usds_futures/test.cpp b/test/test_unit/src/execution_management/binance_usds_futures/test.cpp index 8e8337e4..ebb2c0f2 100644 --- a/test/test_unit/src/execution_management/binance_usds_futures/test.cpp +++ b/test/test_unit/src/execution_management/binance_usds_futures/test.cpp @@ -10,8 +10,8 @@ class ExecutionManagementServiceBinanceUsdsFuturesTest : public ::testing::Test public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = + std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_BINANCE_USDS_FUTURES_API_KEY, "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"}, {CCAPI_BINANCE_USDS_FUTURES_API_SECRET, "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"}, @@ -19,6 +19,7 @@ class ExecutionManagementServiceBinanceUsdsFuturesTest : public ::testing::Test this->timestamp = 1499827319559; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/bitmex/test.cpp b/test/test_unit/src/execution_management/bitmex/test.cpp index b330ca43..400fb4be 100644 --- a/test/test_unit/src/execution_management/bitmex/test.cpp +++ b/test/test_unit/src/execution_management/bitmex/test.cpp @@ -10,8 +10,7 @@ class ExecutionManagementServiceBitmexTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_BITMEX_API_KEY, "LAqUlngMIQkIUjXMUreyu3qn"}, {CCAPI_BITMEX_API_SECRET, "chNOOS4KvNXR_Xq4k4c9qsfoKWvnDecLATCRlcBwyKDYnWgO"}, @@ -19,6 +18,7 @@ class ExecutionManagementServiceBitmexTest : public ::testing::Test { this->timestamp = 1499827319; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp * 1000LL); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/coinbase/test.cpp b/test/test_unit/src/execution_management/coinbase/test.cpp index 587504ef..9fc82ec5 100644 --- a/test/test_unit/src/execution_management/coinbase/test.cpp +++ b/test/test_unit/src/execution_management/coinbase/test.cpp @@ -10,8 +10,8 @@ class ExecutionManagementServiceCoinbaseTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = + std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_COINBASE_API_KEY, "a53c4a1d047bddd07e6d4b5783ae18b0"}, {CCAPI_COINBASE_API_SECRET, "+xT7GWTDRHi09EZEhkOC8S7ktzngKtoT1ZoZ6QclGURlq3ePfUd7kLQzK4+P54685NEqYDaIerYj9cuYFILOhQ=="}, @@ -20,6 +20,7 @@ class ExecutionManagementServiceCoinbaseTest : public ::testing::Test { this->timestamp = 1499827319; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp * 1000LL); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/erisx/test.cpp b/test/test_unit/src/execution_management/erisx/test.cpp index dcb98f49..c35be615 100644 --- a/test/test_unit/src/execution_management/erisx/test.cpp +++ b/test/test_unit/src/execution_management/erisx/test.cpp @@ -10,8 +10,7 @@ class ExecutionManagementServiceErisxTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = - std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_ERISX_API_KEY, "6e010dda31cc2f301c82de1eb82d0998gbbec9fe6f9438d788416d23fc56b14d4"}, {CCAPI_ERISX_API_SECRET, "3zMnjHV5B1nxsfh6b8Jx7AdHZHiw"}, @@ -19,6 +18,7 @@ class ExecutionManagementServiceErisxTest : public ::testing::Test { this->timestamp = 1499827319; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp * 1000LL); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/gateio/test.cpp b/test/test_unit/src/execution_management/gateio/test.cpp index 64eb771d..d2045231 100644 --- a/test/test_unit/src/execution_management/gateio/test.cpp +++ b/test/test_unit/src/execution_management/gateio/test.cpp @@ -10,8 +10,7 @@ class ExecutionManagementServiceGateioTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_GATEIO_API_KEY, "f897ef1d2bbdca43de0c624d6b4fee7f"}, {CCAPI_GATEIO_API_SECRET, "55de8bdbfca4f783979559baaa079f1cde28795e1b8b4527e7c22c8978c3f44c"}, @@ -19,6 +18,7 @@ class ExecutionManagementServiceGateioTest : public ::testing::Test { this->timestamp = 1499827319; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp * 1000LL); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/gemini/test.cpp b/test/test_unit/src/execution_management/gemini/test.cpp index aeb2a38c..75d79386 100644 --- a/test/test_unit/src/execution_management/gemini/test.cpp +++ b/test/test_unit/src/execution_management/gemini/test.cpp @@ -10,8 +10,7 @@ class ExecutionManagementServiceGeminiTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_GEMINI_API_KEY, "account-DgM6GKGlzWtjOrdWiUyh"}, {CCAPI_GEMINI_API_SECRET, "3zMnjHV5B1nxsfh6b8Jx7AdHZHiw"}, @@ -19,6 +18,7 @@ class ExecutionManagementServiceGeminiTest : public ::testing::Test { this->timestamp = 1499827319; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp * 1000LL); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/huobi/test.cpp b/test/test_unit/src/execution_management/huobi/test.cpp index 247f2278..9ee5e048 100644 --- a/test/test_unit/src/execution_management/huobi/test.cpp +++ b/test/test_unit/src/execution_management/huobi/test.cpp @@ -10,8 +10,7 @@ class ExecutionManagementServiceHuobiTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = - std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_HUOBI_API_KEY, "7f72bbdb-d3fa3d40-uymylwhfeg-17388"}, {CCAPI_HUOBI_API_SECRET, "3e02e507-e8f8f2ae-a543363d-d2037"}, @@ -19,6 +18,7 @@ class ExecutionManagementServiceHuobiTest : public ::testing::Test { this->timestamp = "2017-05-11T15:19:30"; this->now = UtilTime::parse(this->timestamp + "Z"); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; std::string timestamp; diff --git a/test/test_unit/src/execution_management/huobi_coin_swap/test.cpp b/test/test_unit/src/execution_management/huobi_coin_swap/test.cpp index 3f6a04ab..d8302951 100644 --- a/test/test_unit/src/execution_management/huobi_coin_swap/test.cpp +++ b/test/test_unit/src/execution_management/huobi_coin_swap/test.cpp @@ -10,8 +10,8 @@ class ExecutionManagementServiceHuobiCoinSwapTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = + std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_HUOBI_COIN_SWAP_API_KEY, "b33ff154-e02e01af-mjlpdje3ld-87508"}, {CCAPI_HUOBI_COIN_SWAP_API_SECRET, "968df5e1-790fa852-ce124901-9ccc5"}, @@ -19,6 +19,7 @@ class ExecutionManagementServiceHuobiCoinSwapTest : public ::testing::Test { this->timestamp = "2017-05-11T15:19:30"; this->now = UtilTime::parse(this->timestamp + "Z"); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; std::string timestamp; diff --git a/test/test_unit/src/execution_management/huobi_usdt_swap/test.cpp b/test/test_unit/src/execution_management/huobi_usdt_swap/test.cpp index f1d83378..0a595b09 100644 --- a/test/test_unit/src/execution_management/huobi_usdt_swap/test.cpp +++ b/test/test_unit/src/execution_management/huobi_usdt_swap/test.cpp @@ -10,8 +10,8 @@ class ExecutionManagementServiceHuobiUsdtSwapTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = + std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_HUOBI_USDT_SWAP_API_KEY, "b33ff154-e02e01af-mjlpdje3ld-87508"}, {CCAPI_HUOBI_USDT_SWAP_API_SECRET, "968df5e1-790fa852-ce124901-9ccc5"}, @@ -19,6 +19,7 @@ class ExecutionManagementServiceHuobiUsdtSwapTest : public ::testing::Test { this->timestamp = "2017-05-11T15:19:30"; this->now = UtilTime::parse(this->timestamp + "Z"); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; std::string timestamp; diff --git a/test/test_unit/src/execution_management/kraken/test.cpp b/test/test_unit/src/execution_management/kraken/test.cpp index ef99a20e..cbf9825b 100644 --- a/test/test_unit/src/execution_management/kraken/test.cpp +++ b/test/test_unit/src/execution_management/kraken/test.cpp @@ -10,8 +10,7 @@ class ExecutionManagementServiceKrakenTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_KRAKEN_API_KEY, "uvgK51G7bnksHUgrU++Cib03e15cCRJQA9e1f30TPuhZ+BagVrb2WUNi"}, {CCAPI_KRAKEN_API_SECRET, "q+INlIikVemcqFtJu9CZk0QIXBMYRFpwKblA/N9iP61uGCMpsMa06ycI8VuwdxeqAvXnGPAnMIBYeiY1AoG67w=="}, @@ -19,6 +18,7 @@ class ExecutionManagementServiceKrakenTest : public ::testing::Test { this->timestamp = 1499827319000; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/kraken_futures/test.cpp b/test/test_unit/src/execution_management/kraken_futures/test.cpp index 3ee0a2e1..3fef6a3e 100644 --- a/test/test_unit/src/execution_management/kraken_futures/test.cpp +++ b/test/test_unit/src/execution_management/kraken_futures/test.cpp @@ -10,8 +10,8 @@ class ExecutionManagementServiceKrakenFuturesTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = + std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_KRAKEN_FUTURES_API_KEY, "Bx0+DtmSNWLNXQVaJ6dcvaWwEKitPU4MadMhEltVe9aSY/nfhkab46IJ"}, {CCAPI_KRAKEN_FUTURES_API_SECRET, "oMpjprZZIUvn8+0B55zgO3ncp448AI+a7KFwo5lHSmf650mawBQ7ez5pNvDkhRlsHDZuPM+gvPs6dDB8k+Skr9gw"}, @@ -19,6 +19,7 @@ class ExecutionManagementServiceKrakenFuturesTest : public ::testing::Test { this->timestamp = 1499827319000; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/kucoin/test.cpp b/test/test_unit/src/execution_management/kucoin/test.cpp index fcb01c83..bbf2114a 100644 --- a/test/test_unit/src/execution_management/kucoin/test.cpp +++ b/test/test_unit/src/execution_management/kucoin/test.cpp @@ -10,8 +10,7 @@ class ExecutionManagementServiceKucoinTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), - std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_KUCOIN_API_KEY, "60bb01032f6e210006b760a9"}, {CCAPI_KUCOIN_API_SECRET, "2ebbd3aa-35af-4b5e-b2e5-df94bb940f83"}, @@ -21,6 +20,7 @@ class ExecutionManagementServiceKucoinTest : public ::testing::Test { this->timestamp = 1499827319; this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp * 1000LL); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/execution_management/okx/test.cpp b/test/test_unit/src/execution_management/okx/test.cpp index d044a423..5b856edf 100644 --- a/test/test_unit/src/execution_management/okx/test.cpp +++ b/test/test_unit/src/execution_management/okx/test.cpp @@ -10,8 +10,7 @@ class ExecutionManagementServiceOkxTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = - std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); this->credential = { {CCAPI_OKX_API_KEY, "a53c4a1d047bddd07e6d4b5783ae18b0"}, {CCAPI_OKX_API_SECRET, "+xT7GWTDRHi09EZEhkOC8S7ktzngKtoT1ZoZ6QclGURlq3ePfUd7kLQzK4+P54685NEqYDaIerYj9cuYFILOhQ=="}, @@ -21,6 +20,7 @@ class ExecutionManagementServiceOkxTest : public ::testing::Test { this->now = UtilTime::makeTimePointFromMilliseconds(this->timestamp * 1000LL); this->timestampStr = "2017-07-12T02:41:59.000Z"; } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; std::map credential; long long timestamp{}; diff --git a/test/test_unit/src/market_data/generic/test.cpp b/test/test_unit/src/market_data/generic/test.cpp index 8548e7b5..1f4f89a8 100644 --- a/test/test_unit/src/market_data/generic/test.cpp +++ b/test/test_unit/src/market_data/generic/test.cpp @@ -10,9 +10,9 @@ class MarketDataServiceTest : public ::testing::Test { public: typedef Service::ServiceContextPtr ServiceContextPtr; void SetUp() override { - this->service = - std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), std::make_shared()); + this->service = std::make_shared([](Event&, Queue*) {}, SessionOptions(), SessionConfigs(), &this->serviceContext); } + ServiceContext serviceContext; std::shared_ptr service{nullptr}; };