Skip to content

Commit

Permalink
Merge pull request #361 from crypto-chassis/fix/mexc
Browse files Browse the repository at this point in the history
fix: small fixes for mexc
  • Loading branch information
cryptochassis authored Jan 12, 2023
2 parents 0f1a865 + c99199a commit 1f8c543
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
3 changes: 3 additions & 0 deletions include/ccapi_cpp/ccapi_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@
#ifndef CCAPI_EM_ORDER_CUMULATIVE_FILLED_PRICE_TIMES_QUANTITY
#define CCAPI_EM_ORDER_CUMULATIVE_FILLED_PRICE_TIMES_QUANTITY "CUMULATIVE_FILLED_PRICE_TIMES_QUANTITY"
#endif
#ifndef CCAPI_EM_ORDER_AVERAGE_FILLED_PRICE
#define CCAPI_EM_ORDER_AVERAGE_FILLED_PRICE "AVERAGE_FILLED_PRICE"
#endif
#ifndef CCAPI_EM_ORDER_INSTRUMENT
#define CCAPI_EM_ORDER_INSTRUMENT "INSTRUMENT"
#endif
Expand Down
27 changes: 16 additions & 11 deletions include/ccapi_cpp/service/ccapi_execution_management_service_mexc.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,17 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService {
if (document.IsObject() && document.HasMember("code") && std::string(document["code"].GetString()) == "0") {
event.setType(Event::Type::SUBSCRIPTION_STATUS);
std::string msg = document["msg"].GetString();
bool success = msg != "no subscription success";
Message message;
message.setTimeReceived(timeReceived);
message.setCorrelationIdList({subscription.getCorrelationId()});
message.setType(success ? Message::Type::SUBSCRIPTION_STARTED : Message::Type::SUBSCRIPTION_FAILURE);
Element element;
element.insert(success ? CCAPI_INFO_MESSAGE : CCAPI_ERROR_MESSAGE, textMessage);
message.setElementList({element});
messageList.emplace_back(std::move(message));
if (msg != "PONG") {
bool success = msg != "no subscription success";
Message message;
message.setTimeReceived(timeReceived);
message.setCorrelationIdList({subscription.getCorrelationId()});
message.setType(success ? Message::Type::SUBSCRIPTION_STARTED : Message::Type::SUBSCRIPTION_FAILURE);
Element element;
element.insert(success ? CCAPI_INFO_MESSAGE : CCAPI_ERROR_MESSAGE, textMessage);
message.setElementList({element});
messageList.emplace_back(std::move(message));
}
} else {
const auto& fieldSet = subscription.getFieldSet();
const auto& instrumentSet = subscription.getInstrumentSet();
Expand Down Expand Up @@ -401,14 +403,17 @@ class ExecutionManagementServiceMexc : public ExecutionManagementService {
const std::map<std::string, std::pair<std::string, JsonDataType> >& extractionFieldNameMap = {
{CCAPI_EM_ORDER_ID, std::make_pair("i", JsonDataType::STRING)},
{CCAPI_EM_CLIENT_ORDER_ID, std::make_pair("c", JsonDataType::STRING)},
{CCAPI_EM_ORDER_SIDE, std::make_pair("v", JsonDataType::STRING)},
{CCAPI_EM_ORDER_LIMIT_PRICE, std::make_pair("p", JsonDataType::STRING)},
{CCAPI_EM_ORDER_QUANTITY, std::make_pair("size", JsonDataType::STRING)},
{CCAPI_EM_ORDER_QUANTITY, std::make_pair("v", JsonDataType::STRING)},
{CCAPI_EM_ORDER_CUMULATIVE_FILLED_QUANTITY, std::make_pair("cv", JsonDataType::STRING)},
{CCAPI_EM_ORDER_CUMULATIVE_FILLED_PRICE_TIMES_QUANTITY, std::make_pair("ca", JsonDataType::STRING)},
{CCAPI_EM_ORDER_AVERAGE_FILLED_PRICE, std::make_pair("ap", JsonDataType::STRING)},
{CCAPI_EM_ORDER_REMAINING_QUANTITY, std::make_pair("V", JsonDataType::STRING)},
{CCAPI_EM_ORDER_STATUS, std::make_pair("s", JsonDataType::STRING)},
};
Element info;
info.insert(CCAPI_EM_ORDER_INSTRUMENT, instrument);
info.insert(CCAPI_EM_ORDER_SIDE, std::string(d["S"].GetString()) == "1" ? CCAPI_EM_ORDER_SIDE_BUY : CCAPI_EM_ORDER_SIDE_SELL);
this->extractOrderInfo(info, d, extractionFieldNameMap);
std::vector<Element> elementList;
elementList.emplace_back(std::move(info));
Expand Down
2 changes: 2 additions & 0 deletions include/ccapi_cpp/service/ccapi_market_data_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,8 @@ class MarketDataService : public Service {
const auto& correlationIdList = that->correlationIdListByConnectionIdChannelIdSymbolIdMap.at(wsConnection.id).at(channelId).at(symbolId);
std::map<Decimal, std::string>& snapshotBid = that->snapshotBidByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId];
std::map<Decimal, std::string>& snapshotAsk = that->snapshotAskByConnectionIdChannelIdSymbolIdMap[wsConnection.id][channelId][symbolId];
snapshotBid.clear();
snapshotAsk.clear();
MarketDataMessage::TypeForData input;
that->extractOrderBookInitialData(input, document);
for (const auto& x : input) {
Expand Down
9 changes: 8 additions & 1 deletion include/ccapi_cpp/service/ccapi_market_data_service_mexc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ class MarketDataServiceMexc : public MarketDataService {
protected:
#endif
// bool doesHttpBodyContainError(const std::string& body) override { return body.find(R"("code":0)") == std::string::npos; }
void pingOnApplicationLevel(wspp::connection_hdl hdl, ErrorCode& ec) override { this->send(hdl, R"({"method":"PING"})", wspp::frame::opcode::text, ec); }
void pingOnApplicationLevel(wspp::connection_hdl hdl, ErrorCode& ec) override {
WsConnection& wsConnection = this->getWsConnectionFromConnectionPtr(this->serviceContextPtr->tlsClientPtr->get_con_from_hdl(hdl));
this->send(hdl, R"({"id":)" + std::to_string(this->exchangeJsonPayloadIdByConnectionIdMap[wsConnection.id]) + R"(,"method":"PING"})",
wspp::frame::opcode::text, ec);
this->exchangeJsonPayloadIdByConnectionIdMap[wsConnection.id] += 1;
}
std::vector<std::string> createSendStringList(const WsConnection& wsConnection) override {
std::vector<std::string> sendStringList;
rj::Document document;
Expand Down Expand Up @@ -250,6 +255,8 @@ class MarketDataServiceMexc : public MarketDataService {
element.insert(CCAPI_ORDER_PRICE_INCREMENT, "1" + std::string(-quotePrecision, '0'));
}
element.insert(CCAPI_ORDER_QUANTITY_INCREMENT, x["baseSizePrecision"].GetString());
element.insert(CCAPI_ORDER_QUANTITY_MIN, x["baseSizePrecision"].GetString());
element.insert(CCAPI_ORDER_PRICE_TIMES_QUANTITY_MIN, x["quoteAmountPrecision"].GetString());
}
void convertTextMessageToMarketDataMessage(const Request& request, const std::string& textMessage, const TimePoint& timeReceived, Event& event,
std::vector<MarketDataMessage>& marketDataMessageList) override {
Expand Down

0 comments on commit 1f8c543

Please sign in to comment.