diff --git a/include/ccapi_cpp/ccapi_macro.h b/include/ccapi_cpp/ccapi_macro.h index 90cbda2c..f3a2f78a 100644 --- a/include/ccapi_cpp/ccapi_macro.h +++ b/include/ccapi_cpp/ccapi_macro.h @@ -1143,4 +1143,7 @@ #ifndef CCAPI_GATEIO_API_CHANNEL_ID #define CCAPI_GATEIO_API_CHANNEL_ID "cryptochassis" #endif +#ifndef CCAPI_MEXC_API_SOURCE +#define CCAPI_MEXC_API_SOURCE "CHAS" +#endif #endif // INCLUDE_CCAPI_CPP_CCAPI_MACRO_H_ 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 810707e9..0d79f321 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h @@ -93,6 +93,7 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService { ExecutionManagementService::convertRequestForRestGenericPrivateRequest(req, request, now, symbolId, credential); } break; case Request::Operation::CREATE_ORDER: { + req.set("source", CCAPI_MEXC_API_SOURCE); req.method(http::verb::post); std::string queryString; const std::map param = request.getFirstParamWithDefault(); diff --git a/include/ccapi_cpp/service/ccapi_market_data_service.h b/include/ccapi_cpp/service/ccapi_market_data_service.h index a4854828..bf1e2a6b 100644 --- a/include/ccapi_cpp/service/ccapi_market_data_service.h +++ b/include/ccapi_cpp/service/ccapi_market_data_service.h @@ -1215,6 +1215,22 @@ class MarketDataService : public Service { marketDataMessage.data; } } + void buildOrderBookInitialOnFail(const WsConnection& wsConnection, const std::string& exchangeSubscriptionId, long delayMilliSeconds) { + auto thisDelayMilliSeconds = delayMilliSeconds * 2; + if (thisDelayMilliSeconds > 0) { + this->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnection.id][exchangeSubscriptionId] = + this->serviceContextPtr->tlsClientPtr->set_timer(thisDelayMilliSeconds, + [wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds, that = this](ErrorCode const& ec) { + if (ec) { + that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + } else { + that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds); + } + }); + } else { + this->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds); + } + } void buildOrderBookInitial(const WsConnection& wsConnection, const std::string& exchangeSubscriptionId, long delayMilliSeconds) { auto now = UtilTime::now(); http::request req; @@ -1227,20 +1243,7 @@ class MarketDataService : public Service { this->sendRequest( req, [wsConnection, exchangeSubscriptionId, delayMilliSeconds, that = shared_from_base()](const beast::error_code& ec) { - auto thisDelayMilliSeconds = delayMilliSeconds * 2; - if (thisDelayMilliSeconds > 0) { - that->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnection.id][exchangeSubscriptionId] = - that->serviceContextPtr->tlsClientPtr->set_timer(thisDelayMilliSeconds, - [wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds, that](ErrorCode const& ec) { - if (ec) { - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); - } else { - that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds); - } - }); - } else { - that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, thisDelayMilliSeconds); - } + that->buildOrderBookInitialOnFail(wsConnection, exchangeSubscriptionId, delayMilliSeconds); }, [wsConnection, exchangeSubscriptionId, delayMilliSeconds, that = shared_from_base()](const http::response& res) { auto timeReceived = UtilTime::now(); @@ -1365,27 +1368,29 @@ class MarketDataService : public Service { that->eventHandler(event, nullptr); that->processedInitialSnapshotByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId] = true; } else { - if (delayMilliSeconds > 0) { - that->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnection.id][exchangeSubscriptionId] = - that->serviceContextPtr->tlsClientPtr->set_timer( - delayMilliSeconds, [wsConnection, exchangeSubscriptionId, delayMilliSeconds, that](ErrorCode const& ec) { - if (ec) { - that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); - } else { - that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, delayMilliSeconds); - } - }); - } else { - that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, delayMilliSeconds); - } + that->buildOrderBookInitialOnFail(wsConnection, exchangeSubscriptionId, delayMilliSeconds); + // if (delayMilliSeconds > 0) { + // that->fetchMarketDepthInitialSnapshotTimerByConnectionIdExchangeSubscriptionIdMap[wsConnection.id][exchangeSubscriptionId] = + // that->serviceContextPtr->tlsClientPtr->set_timer( + // delayMilliSeconds, [wsConnection, exchangeSubscriptionId, delayMilliSeconds, that](ErrorCode const& ec) { + // if (ec) { + // that->onError(Event::Type::SUBSCRIPTION_STATUS, Message::Type::GENERIC_ERROR, ec, "timer"); + // } else { + // that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, delayMilliSeconds); + // } + // }); + // } else { + // that->buildOrderBookInitial(wsConnection, exchangeSubscriptionId, delayMilliSeconds); + // } } return; } catch (const std::runtime_error& e) { CCAPI_LOGGER_ERROR(std::string("e.what() = ") + e.what()); } } - WsConnection thisWsConnection = wsConnection; - that->onFail_(thisWsConnection); + that->buildOrderBookInitialOnFail(wsConnection, exchangeSubscriptionId, delayMilliSeconds); + // WsConnection thisWsConnection = wsConnection; + // that->onFail_(thisWsConnection); }, this->sessionOptions.httpRequestTimeoutMilliSeconds); }