Skip to content

Commit fe94c83

Browse files
Merge pull request #534 from crypto-chassis/develop
Release
2 parents 02a965a + 80b167e commit fe94c83

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

include/ccapi_cpp/ccapi_request.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@ class Request {
139139
return output;
140140
}
141141

142-
Request() {}
143-
144-
explicit Request(Operation operation, const std::string& exchange = "", const std::string& instrument = "", const std::string& correlationId = "",
145-
const std::map<std::string, std::string>& credential = {})
142+
explicit Request(Operation operation = Operation::UNKNOWN, const std::string& exchange = "", const std::string& instrument = "",
143+
const std::string& correlationId = "", const std::map<std::string, std::string>& credential = {})
146144
: operation(operation), exchange(exchange), instrument(instrument), correlationId(correlationId), credential(credential) {
147145
if (operation == Operation::CUSTOM) {
148146
this->serviceName = CCAPI_UNKNOWN;

include/ccapi_cpp/ccapi_subscription.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ namespace ccapi {
1515
*/
1616
class Subscription {
1717
public:
18-
Subscription() {}
19-
20-
Subscription(const std::string& exchange, const std::string& instrument, const std::string& field, const std::string& options = "",
21-
const std::string& correlationId = "", const std::map<std::string, std::string>& credential = {})
18+
explicit Subscription(const std::string& exchange = "", const std::string& instrument = "", const std::string& field = "", const std::string& options = "",
19+
const std::string& correlationId = "", const std::map<std::string, std::string>& credential = {})
2220
: exchange(exchange), instrument(instrument), field(field), correlationId(correlationId), credential(credential) {
2321
auto originalInstrumentSet = UtilString::splitToSet(instrument, ",");
2422
std::copy_if(originalInstrumentSet.begin(), originalInstrumentSet.end(), std::inserter(this->instrumentSet, this->instrumentSet.end()),
@@ -127,6 +125,12 @@ class Subscription {
127125

128126
const std::string& getMarginType() const { return marginType; }
129127

128+
void setExchange(const std::string& exchange) { this->exchange = exchange; }
129+
130+
void setInstrument(const std::string& instrument) { this->instrument = instrument; }
131+
132+
void setField(const std::string& field) { this->field = field; }
133+
130134
void setTimeSent(TimePoint timeSent) { this->timeSent = timeSent; }
131135

132136
void setInstrumentType(const std::string& instrumentType) { this->instrumentType = instrumentType; }

include/ccapi_cpp/service/ccapi_execution_management_service_binance_derivatives_base.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,30 @@ class ExecutionManagementServiceBinanceDerivativesBase : public ExecutionManagem
3737
switch (request.getOperation()) {
3838
case Request::Operation::GET_ACCOUNT_POSITIONS: {
3939
for (const auto& x : document.GetArray()) {
40-
Element element;
41-
element.insert(CCAPI_INSTRUMENT, x["symbol"].GetString());
42-
element.insert(CCAPI_EM_POSITION_SIDE, x["positionSide"].GetString());
4340
std::string positionAmt;
4441
auto it = x.FindMember("positionAmt");
4542
if (it != x.MemberEnd()) {
4643
positionAmt = it->value.GetString();
4744
} else {
4845
positionAmt = x["maxQty"].GetString();
4946
}
50-
element.insert(CCAPI_EM_POSITION_QUANTITY, positionAmt);
51-
element.insert(CCAPI_EM_POSITION_ENTRY_PRICE, x["entryPrice"].GetString());
52-
element.insert(CCAPI_EM_POSITION_LEVERAGE, x["leverage"].GetString());
53-
if (x.HasMember("unrealizedProfit")) {
54-
element.insert(CCAPI_EM_UNREALIZED_PNL, x["unrealizedProfit"].GetString());
55-
} else {
56-
element.insert(CCAPI_EM_UNREALIZED_PNL, x["unRealizedProfit"].GetString());
47+
if (!positionAmt.empty()) {
48+
const auto& positionAmtDecimal = Decimal(positionAmt);
49+
if (positionAmtDecimal != Decimal::zero) {
50+
Element element;
51+
element.insert(CCAPI_INSTRUMENT, x["symbol"].GetString());
52+
element.insert(CCAPI_EM_POSITION_SIDE, x["positionSide"].GetString());
53+
element.insert(CCAPI_EM_POSITION_QUANTITY, positionAmt);
54+
element.insert(CCAPI_EM_POSITION_ENTRY_PRICE, x["entryPrice"].GetString());
55+
if (x.HasMember("unrealizedProfit")) {
56+
element.insert(CCAPI_EM_UNREALIZED_PNL, x["unrealizedProfit"].GetString());
57+
} else {
58+
element.insert(CCAPI_EM_UNREALIZED_PNL, x["unRealizedProfit"].GetString());
59+
}
60+
element.insert(CCAPI_LAST_UPDATED_TIME_SECONDS, UtilTime::convertMillisecondsStrToSecondsStr(x["updateTime"].GetString()));
61+
elementList.emplace_back(std::move(element));
62+
}
5763
}
58-
element.insert(CCAPI_LAST_UPDATED_TIME_SECONDS, UtilTime::convertMillisecondsStrToSecondsStr(x["updateTime"].GetString()));
59-
elementList.emplace_back(std::move(element));
6064
}
6165
} break;
6266
default:

include/ccapi_cpp/service/ccapi_execution_management_service_binance_usds_futures.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class ExecutionManagementServiceBinanceUsdsFutures : public ExecutionManagementS
3333
this->cancelOpenOrdersTarget = "/fapi/v1/allOpenOrders";
3434
this->isDerivatives = true;
3535
this->listenKeyTarget = CCAPI_BINANCE_USDS_FUTURES_LISTEN_KEY_PATH;
36-
this->getAccountBalancesTarget = "/fapi/v2/account";
37-
this->getAccountPositionsTarget = "/fapi/v2/positionRisk";
36+
this->getAccountBalancesTarget = "/fapi/v3/account";
37+
this->getAccountPositionsTarget = "/fapi/v3/positionRisk";
3838
}
3939

4040
virtual ~ExecutionManagementServiceBinanceUsdsFutures() {}

test/test_unit/src/execution_management/binance_usds_futures/test.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertRequestGetAccoun
323323
EXPECT_EQ(req.method(), http::verb::get);
324324
verifyApiKey(req, this->credential.at(CCAPI_BINANCE_USDS_FUTURES_API_KEY));
325325
auto splitted = UtilString::split(std::string(req.target()), "?");
326-
EXPECT_EQ(splitted.at(0), "/fapi/v2/account");
326+
EXPECT_EQ(splitted.at(0), "/fapi/v3/account");
327327
auto paramMap = Url::convertQueryStringToMap(splitted.at(1));
328328
EXPECT_EQ(paramMap.at("timestamp"), std::to_string(this->timestamp));
329329
verifySignature(splitted.at(1), this->credential.at(CCAPI_BINANCE_USDS_FUTURES_API_SECRET));
@@ -421,7 +421,7 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertRequestGetAccoun
421421
EXPECT_EQ(req.method(), http::verb::get);
422422
verifyApiKey(req, this->credential.at(CCAPI_BINANCE_USDS_FUTURES_API_KEY));
423423
auto splitted = UtilString::split(std::string(req.target()), "?");
424-
EXPECT_EQ(splitted.at(0), "/fapi/v2/positionRisk");
424+
EXPECT_EQ(splitted.at(0), "/fapi/v3/positionRisk");
425425
auto paramMap = Url::convertQueryStringToMap(splitted.at(1));
426426
EXPECT_EQ(paramMap.at("timestamp"), std::to_string(this->timestamp));
427427
verifySignature(splitted.at(1), this->credential.at(CCAPI_BINANCE_USDS_FUTURES_API_SECRET));
@@ -439,12 +439,11 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertTextMessageToMes
439439
"unrealizedProfit": "0.00000000",
440440
"positionInitialMargin": "0",
441441
"openOrderInitialMargin": "0",
442-
"leverage": "100",
443442
"isolated": true,
444443
"entryPrice": "0.00000",
445444
"maxNotional": "250000",
446445
"positionSide": "BOTH",
447-
"positionAmt": "0",
446+
"positionAmt": "10",
448447
"updateTime": 0
449448
}
450449
]
@@ -459,9 +458,8 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertTextMessageToMes
459458
Element element = elementList.at(0);
460459
EXPECT_EQ(element.getValue(CCAPI_INSTRUMENT), "BTCUSDT");
461460
EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_SIDE), "BOTH");
462-
EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_QUANTITY), "0");
461+
EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_QUANTITY), "10");
463462
EXPECT_DOUBLE_EQ(std::stod(element.getValue(CCAPI_EM_POSITION_ENTRY_PRICE)), 0);
464-
EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_LEVERAGE), "100");
465463
}
466464

467465
} /* namespace ccapi */

0 commit comments

Comments
 (0)