Skip to content

Commit

Permalink
ci: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptochassis committed Oct 23, 2023
1 parent 66fe535 commit a75b2fb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions test/test_unit/src/common/util/ccapi_util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -205,4 +200,9 @@ TEST(UtilTimeTest, getISOTimestamp_11) {
std::string str("2019-11-21T01:38:23Z");
EXPECT_EQ(UtilTime::getISOTimestamp<std::chrono::milliseconds>(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 */
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit a75b2fb

Please sign in to comment.