diff --git a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h index 894e3d7b..3e429046 100644 --- a/include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h +++ b/include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h @@ -34,19 +34,32 @@ class ExecutionManagementServiceBinanceDerivativesBase : public ExecutionManagem for (const auto& x : document.GetArray()) { Element element; element.insert(CCAPI_INSTRUMENT, x["symbol"].GetString()); + std::cout << __LINE__ << std::endl; element.insert(CCAPI_EM_POSITION_SIDE, x["positionSide"].GetString()); + std::cout << __LINE__ << std::endl; std::string positionAmt; + std::cout << __LINE__ << std::endl; auto it = x.FindMember("positionAmt"); + std::cout << __LINE__ << std::endl; if (it != x.MemberEnd()) { + std::cout << __LINE__ << std::endl; positionAmt = it->value.GetString(); + std::cout << __LINE__ << std::endl; } else { + std::cout << __LINE__ << std::endl; positionAmt = x["maxQty"].GetString(); + std::cout << __LINE__ << std::endl; } element.insert(CCAPI_EM_POSITION_QUANTITY, positionAmt); + std::cout << __LINE__ << std::endl; element.insert(CCAPI_EM_POSITION_ENTRY_PRICE, x["entryPrice"].GetString()); + std::cout << __LINE__ << std::endl; element.insert(CCAPI_EM_POSITION_LEVERAGE, x["leverage"].GetString()); - element.insert(CCAPI_EM_UNREALIZED_PNL, x["unRealizedProfit"].GetString()); + std::cout << __LINE__ << std::endl; + element.insert(CCAPI_EM_UNREALIZED_PNL, x["unrealizedProfit"].GetString()); + std::cout << __LINE__ << std::endl; element.insert(CCAPI_LAST_UPDATED_TIME_SECONDS, UtilTime::convertMillisecondsStrToSecondsStr(x["updateTime"].GetString())); + std::cout << __LINE__ << std::endl; elementList.emplace_back(std::move(element)); } } break; diff --git a/test/test_unit/src/common/util/ccapi_util_test.cpp b/test/test_unit/src/common/util/ccapi_util_test.cpp index 0c1de478..ad991edf 100644 --- a/test/test_unit/src/common/util/ccapi_util_test.cpp +++ b/test/test_unit/src/common/util/ccapi_util_test.cpp @@ -29,11 +29,6 @@ TEST(UtilAlgorithmTest, base64FromBase64Url) { auto result = UtilAlgorithm::base64FromBase64Url(original); EXPECT_EQ(result, "TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ="); } -TEST(UtilStringTest, convertMillisecondsStrToSecondsStr) { - EXPECT_EQ("169782573039", "169782573.039"); - EXPECT_EQ("169782573030", "169782573.03"); - EXPECT_EQ("0", "0"); -} TEST(UtilStringTest, roundInputBySignificantFigure) { EXPECT_EQ(UtilString::roundInputBySignificantFigure(12345.01, 5, 1), "12346"); EXPECT_EQ(UtilString::roundInputBySignificantFigure(12345.01, 5, -1), "12345"); @@ -205,4 +200,9 @@ TEST(UtilTimeTest, getISOTimestamp_11) { std::string str("2019-11-21T01:38:23Z"); EXPECT_EQ(UtilTime::getISOTimestamp(UtilTime::parse(str)), "2019-11-21T01:38:23.000Z"); } +TEST(UtilTimeTest, convertMillisecondsStrToSecondsStr) { + EXPECT_EQ(UtilTime::convertMillisecondsStrToSecondsStr("169782573039"), "169782573.039"); + EXPECT_EQ(UtilTime::convertMillisecondsStrToSecondsStr("169782573030"), "169782573.030"); + EXPECT_EQ(UtilTime::convertMillisecondsStrToSecondsStr("0"), "0"); +} } /* namespace ccapi */ 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 f87dff35..35825a55 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 @@ -71,7 +71,7 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertTextMessageToMes EXPECT_EQ(elementList.size(), 1); Element element = elementList.at(0); EXPECT_EQ(element.getValue(CCAPI_EM_ORDER_CUMULATIVE_FILLED_PRICE_TIMES_QUANTITY), "0.01"); - EXPECT_EQ(element.getValue(LAST_UPDATED_TIME_SECONDS), "1579276756075"); + EXPECT_EQ(element.getValue(CCAPI_LAST_UPDATED_TIME_SECONDS), "1579276756.075"); } TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, createEventExecutionTypeTrade) { @@ -321,21 +321,24 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertTextMessageToMes std::string textMessage = R"( [ - { - "symbol": "BTCUSDT", - "initialMargin": "0", - "maintMargin": "0", - "unrealizedProfit": "0.00000000", - "positionInitialMargin": "0", - "openOrderInitialMargin": "0", - "leverage": "100", - "isolated": true, - "entryPrice": "0.00000", - "maxNotional": "250000", - "positionSide": "BOTH", - "positionAmt": "0", - "updateTime": 0 - } + { + "entryPrice": "0.00000", + "breakEvenPrice": "0.0", + "marginType": "isolated", + "isAutoAddMargin": "false", + "isolatedMargin": "0.00000000", + "leverage": "10", + "liquidationPrice": "0", + "markPrice": "6679.50671178", + "maxNotionalValue": "20000000", + "positionAmt": "0.000", + "notional": "0", + "isolatedWallet": "0", + "symbol": "BTCUSDT", + "unrealizedProfit": "0.00000000", + "positionSide": "BOTH", + "updateTime": 0 + } ] )"; auto messageList = this->service->convertTextMessageToMessageRest(request, textMessage, this->now); @@ -348,9 +351,9 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertTextMessageToMes Element element = elementList.at(0); EXPECT_EQ(element.getValue(CCAPI_INSTRUMENT), "BTCUSDT"); EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_SIDE), "BOTH"); - EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_QUANTITY), "0"); + EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_QUANTITY), "0.000"); EXPECT_DOUBLE_EQ(std::stod(element.getValue(CCAPI_EM_POSITION_ENTRY_PRICE)), 0); - EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_LEVERAGE), "100"); + EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_LEVERAGE), "10"); EXPECT_EQ(element.getValue(CCAPI_LAST_UPDATED_TIME_SECONDS), "0"); } } /* namespace ccapi */