diff --git a/linux/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h b/linux/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h index e660f276f..7caa81743 100644 --- a/linux/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h +++ b/linux/include/ccapi_cpp/service/ccapi_market_data_service_deribit.h @@ -199,45 +199,6 @@ class MarketDataServiceDeribit : public MarketDataService { template static std::pair readJson(rapidjson::Document &doc, const std::string &key); - template <> - std::pair readJson(rapidjson::Document &doc, const std::string &key) { - auto member = doc.FindMember(key.c_str()); - if (member == doc.MemberEnd() || !member->value.IsString()) { - return {{}, false}; - } - return {member->value.GetString(), true}; - } - - template <> - std::pair readJson(rapidjson::Document &doc, const std::string &key) { - auto member = doc.FindMember(key.c_str()); - if (member == doc.MemberEnd()) { - return {0, false}; - } - const auto &v = member->value; - if (v.IsInt64()) { - return {v.GetInt64(), true}; - } - if (v.IsInt()) { - return {v.GetInt(), true}; - } - if (v.IsUint64()) { - return {static_cast(v.GetUint64()), true}; - } - if (v.IsUint()) { - return {static_cast(v.GetUint()), true}; - } - if (v.IsString()) { - const char *cstr = v.GetString(); - char* endPtr; - const std::int64_t result = std::strtol(cstr, &endPtr, 10); - if (*endPtr == '\0') { - return {result, true}; - } - } - return {0, false}; - } - static bool isHeartbeatRequest(const std::string &textMessage) { rj::Document doc; doc.Parse(textMessage.c_str()); @@ -289,30 +250,7 @@ class MarketDataServiceDeribit : public MarketDataService { } } - void onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) override { - if (isHeartbeatRequest(textMessage)) { - sendHeartbeat(hdl); - return; - } - rj::Document doc; - doc.Parse(textMessage.c_str()); - const auto [rpcId, hasRpcId] = readJson(doc, "id"); - if (hasRpcId) { - if (activeHeartbeatReqs.erase(rpcId) != 0) { - return; - } - const auto [resStr, hasResStr] = readJson(doc, "result"); - if (hasResStr && resStr == "ok") { - if (activeReqs.erase(rpcId) == 0) { - CCAPI_LOGGER_ERROR("MarketDataServiceDeribit::onTextMessage. Received rpc response with unknown id:\n{}" + textMessage); - } else { - CCAPI_LOGGER_DEBUG("MarketDataServiceDeribit::onTextMessage. Received rpc response:\n{}" + textMessage); - } - return; - } - } - MarketDataService::onTextMessage(hdl, textMessage, timeReceived); - } + void onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) override; ////////////////////////////////////////////////// // END - BTS Custom Code @@ -662,6 +600,79 @@ class MarketDataServiceDeribit : public MarketDataService { std::map> subscriptionJsonrpcIdSetByConnectionIdMap; std::string restTarget; }; + +////////////////////////////////////////////////// +// BEGIN - BTS Custom Code +////////////////////////////////////////////////// + +template <> +inline std::pair MarketDataServiceDeribit::readJson(rapidjson::Document &doc, const std::string &key) { + auto member = doc.FindMember(key.c_str()); + if (member == doc.MemberEnd() || !member->value.IsString()) { + return {{}, false}; + } + return {member->value.GetString(), true}; +} + +template <> +inline std::pair MarketDataServiceDeribit::readJson(rapidjson::Document &doc, const std::string &key) { + auto member = doc.FindMember(key.c_str()); + if (member == doc.MemberEnd()) { + return {0, false}; + } + const auto &v = member->value; + if (v.IsInt64()) { + return {v.GetInt64(), true}; + } + if (v.IsInt()) { + return {v.GetInt(), true}; + } + if (v.IsUint64()) { + return {static_cast(v.GetUint64()), true}; + } + if (v.IsUint()) { + return {static_cast(v.GetUint()), true}; + } + if (v.IsString()) { + const char *cstr = v.GetString(); + char* endPtr; + const std::int64_t result = std::strtol(cstr, &endPtr, 10); + if (*endPtr == '\0') { + return {result, true}; + } + } + return {0, false}; +} + +inline void MarketDataServiceDeribit::onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) { + if (isHeartbeatRequest(textMessage)) { + sendHeartbeat(hdl); + return; + } + rj::Document doc; + doc.Parse(textMessage.c_str()); + const auto [rpcId, hasRpcId] = readJson(doc, "id"); + if (hasRpcId) { + if (activeHeartbeatReqs.erase(rpcId) != 0) { + return; + } + const auto [resStr, hasResStr] = readJson(doc, "result"); + if (hasResStr && resStr == "ok") { + if (activeReqs.erase(rpcId) == 0) { + CCAPI_LOGGER_ERROR("MarketDataServiceDeribit::onTextMessage. Received rpc response with unknown id:\n{}" + textMessage); + } else { + CCAPI_LOGGER_DEBUG("MarketDataServiceDeribit::onTextMessage. Received rpc response:\n{}" + textMessage); + } + return; + } + } + MarketDataService::onTextMessage(hdl, textMessage, timeReceived); +} + +////////////////////////////////////////////////// +// END - BTS Custom Code +////////////////////////////////////////////////// + } /* namespace ccapi */ #endif #endif diff --git a/linux/include/websocketpp/endpoint.hpp b/linux/include/websocketpp/endpoint.hpp index c124b1d9a..9ce8a6261 100644 --- a/linux/include/websocketpp/endpoint.hpp +++ b/linux/include/websocketpp/endpoint.hpp @@ -109,7 +109,7 @@ public: /// Destructor - ~endpoint() {} + ~endpoint() {} #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ // no copy constructor because endpoints are not copyable diff --git a/linux/include/websocketpp/logger/basic.hpp b/linux/include/websocketpp/logger/basic.hpp index 84514130e..f0e490e6d 100644 --- a/linux/include/websocketpp/logger/basic.hpp +++ b/linux/include/websocketpp/logger/basic.hpp @@ -58,33 +58,33 @@ namespace log { template class basic { public: - basic(channel_type_hint::value h = + basic(channel_type_hint::value h = channel_type_hint::access) : m_static_channels(0xffffffff) , m_dynamic_channels(0) , m_out(h == channel_type_hint::error ? &std::cerr : &std::cout) {} - basic(std::ostream * out) + basic(std::ostream * out) : m_static_channels(0xffffffff) , m_dynamic_channels(0) , m_out(out) {} - basic(level c, channel_type_hint::value h = + basic(level c, channel_type_hint::value h = channel_type_hint::access) : m_static_channels(c) , m_dynamic_channels(0) , m_out(h == channel_type_hint::error ? &std::cerr : &std::cout) {} - basic(level c, std::ostream * out) + basic(level c, std::ostream * out) : m_static_channels(c) , m_dynamic_channels(0) , m_out(out) {} /// Destructor - ~basic() {} + ~basic() {} /// Copy constructor - basic(basic const & other) + basic(basic const & other) : m_static_channels(other.m_static_channels) , m_dynamic_channels(other.m_dynamic_channels) , m_out(other.m_out) @@ -92,12 +92,12 @@ public: #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ // no copy assignment operator because of const member variables - basic & operator=(basic const &) = delete; + basic & operator=(basic const &) = delete; #endif // _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_ /// Move constructor - basic(basic && other) + basic(basic && other) : m_static_channels(other.m_static_channels) , m_dynamic_channels(other.m_dynamic_channels) , m_out(other.m_out) @@ -105,7 +105,7 @@ public: #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ // no move assignment operator because of const member variables - basic & operator=(basic &&) = delete; + basic & operator=(basic &&) = delete; #endif // _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ #endif // _WEBSOCKETPP_MOVE_SEMANTICS_ diff --git a/linux/include/websocketpp/roles/server_endpoint.hpp b/linux/include/websocketpp/roles/server_endpoint.hpp index 9cc652f75..63b200a54 100644 --- a/linux/include/websocketpp/roles/server_endpoint.hpp +++ b/linux/include/websocketpp/roles/server_endpoint.hpp @@ -72,11 +72,11 @@ public: } /// Destructor - ~server() {} + ~server() {} #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ // no copy constructor because endpoints are not copyable - server(server &) = delete; + server(server &) = delete; // no copy assignment operator because endpoints are not copyable server & operator=(server const &) = delete; @@ -84,7 +84,7 @@ public: #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_ /// Move constructor - server(server && o) : endpoint,config>(std::move(o)) {} + server(server && o) : endpoint,config>(std::move(o)) {} #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ // no move assignment operator because of const member variables