Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions include/ccapi_cpp/ccapi_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ class Request {
return output;
}

Request() {}

explicit Request(Operation operation, const std::string& exchange = "", const std::string& instrument = "", const std::string& correlationId = "",
const std::map<std::string, std::string>& credential = {})
explicit Request(Operation operation = Operation::UNKNOWN, const std::string& exchange = "", const std::string& instrument = "",
const std::string& correlationId = "", const std::map<std::string, std::string>& credential = {})
: operation(operation), exchange(exchange), instrument(instrument), correlationId(correlationId), credential(credential) {
if (operation == Operation::CUSTOM) {
this->serviceName = CCAPI_UNKNOWN;
Expand Down
12 changes: 8 additions & 4 deletions include/ccapi_cpp/ccapi_subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ namespace ccapi {
*/
class Subscription {
public:
Subscription() {}

Subscription(const std::string& exchange, const std::string& instrument, const std::string& field, const std::string& options = "",
const std::string& correlationId = "", const std::map<std::string, std::string>& credential = {})
explicit Subscription(const std::string& exchange = "", const std::string& instrument = "", const std::string& field = "", const std::string& options = "",
const std::string& correlationId = "", const std::map<std::string, std::string>& credential = {})
: exchange(exchange), instrument(instrument), field(field), correlationId(correlationId), credential(credential) {
auto originalInstrumentSet = UtilString::splitToSet(instrument, ",");
std::copy_if(originalInstrumentSet.begin(), originalInstrumentSet.end(), std::inserter(this->instrumentSet, this->instrumentSet.end()),
Expand Down Expand Up @@ -127,6 +125,12 @@ class Subscription {

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

void setExchange(const std::string& exchange) { this->exchange = exchange; }

void setInstrument(const std::string& instrument) { this->instrument = instrument; }

void setField(const std::string& field) { this->field = field; }

void setTimeSent(TimePoint timeSent) { this->timeSent = timeSent; }

void setInstrumentType(const std::string& instrumentType) { this->instrumentType = instrumentType; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,30 @@ class ExecutionManagementServiceBinanceDerivativesBase : public ExecutionManagem
switch (request.getOperation()) {
case Request::Operation::GET_ACCOUNT_POSITIONS: {
for (const auto& x : document.GetArray()) {
Element element;
element.insert(CCAPI_INSTRUMENT, x["symbol"].GetString());
element.insert(CCAPI_EM_POSITION_SIDE, x["positionSide"].GetString());
std::string positionAmt;
auto it = x.FindMember("positionAmt");
if (it != x.MemberEnd()) {
positionAmt = it->value.GetString();
} else {
positionAmt = x["maxQty"].GetString();
}
element.insert(CCAPI_EM_POSITION_QUANTITY, positionAmt);
element.insert(CCAPI_EM_POSITION_ENTRY_PRICE, x["entryPrice"].GetString());
element.insert(CCAPI_EM_POSITION_LEVERAGE, x["leverage"].GetString());
if (x.HasMember("unrealizedProfit")) {
element.insert(CCAPI_EM_UNREALIZED_PNL, x["unrealizedProfit"].GetString());
} else {
element.insert(CCAPI_EM_UNREALIZED_PNL, x["unRealizedProfit"].GetString());
if (!positionAmt.empty()) {
const auto& positionAmtDecimal = Decimal(positionAmt);
if (positionAmtDecimal != Decimal::zero) {
Element element;
element.insert(CCAPI_INSTRUMENT, x["symbol"].GetString());
element.insert(CCAPI_EM_POSITION_SIDE, x["positionSide"].GetString());
element.insert(CCAPI_EM_POSITION_QUANTITY, positionAmt);
element.insert(CCAPI_EM_POSITION_ENTRY_PRICE, x["entryPrice"].GetString());
if (x.HasMember("unrealizedProfit")) {
element.insert(CCAPI_EM_UNREALIZED_PNL, x["unrealizedProfit"].GetString());
} else {
element.insert(CCAPI_EM_UNREALIZED_PNL, x["unRealizedProfit"].GetString());
}
element.insert(CCAPI_LAST_UPDATED_TIME_SECONDS, UtilTime::convertMillisecondsStrToSecondsStr(x["updateTime"].GetString()));
elementList.emplace_back(std::move(element));
}
}
element.insert(CCAPI_LAST_UPDATED_TIME_SECONDS, UtilTime::convertMillisecondsStrToSecondsStr(x["updateTime"].GetString()));
elementList.emplace_back(std::move(element));
}
} break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ExecutionManagementServiceBinanceUsdsFutures : public ExecutionManagementS
this->cancelOpenOrdersTarget = "/fapi/v1/allOpenOrders";
this->isDerivatives = true;
this->listenKeyTarget = CCAPI_BINANCE_USDS_FUTURES_LISTEN_KEY_PATH;
this->getAccountBalancesTarget = "/fapi/v2/account";
this->getAccountPositionsTarget = "/fapi/v2/positionRisk";
this->getAccountBalancesTarget = "/fapi/v3/account";
this->getAccountPositionsTarget = "/fapi/v3/positionRisk";
}

virtual ~ExecutionManagementServiceBinanceUsdsFutures() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertRequestGetAccoun
EXPECT_EQ(req.method(), http::verb::get);
verifyApiKey(req, this->credential.at(CCAPI_BINANCE_USDS_FUTURES_API_KEY));
auto splitted = UtilString::split(std::string(req.target()), "?");
EXPECT_EQ(splitted.at(0), "/fapi/v2/account");
EXPECT_EQ(splitted.at(0), "/fapi/v3/account");
auto paramMap = Url::convertQueryStringToMap(splitted.at(1));
EXPECT_EQ(paramMap.at("timestamp"), std::to_string(this->timestamp));
verifySignature(splitted.at(1), this->credential.at(CCAPI_BINANCE_USDS_FUTURES_API_SECRET));
Expand Down Expand Up @@ -421,7 +421,7 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertRequestGetAccoun
EXPECT_EQ(req.method(), http::verb::get);
verifyApiKey(req, this->credential.at(CCAPI_BINANCE_USDS_FUTURES_API_KEY));
auto splitted = UtilString::split(std::string(req.target()), "?");
EXPECT_EQ(splitted.at(0), "/fapi/v2/positionRisk");
EXPECT_EQ(splitted.at(0), "/fapi/v3/positionRisk");
auto paramMap = Url::convertQueryStringToMap(splitted.at(1));
EXPECT_EQ(paramMap.at("timestamp"), std::to_string(this->timestamp));
verifySignature(splitted.at(1), this->credential.at(CCAPI_BINANCE_USDS_FUTURES_API_SECRET));
Expand All @@ -439,12 +439,11 @@ TEST_F(ExecutionManagementServiceBinanceUsdsFuturesTest, convertTextMessageToMes
"unrealizedProfit": "0.00000000",
"positionInitialMargin": "0",
"openOrderInitialMargin": "0",
"leverage": "100",
"isolated": true,
"entryPrice": "0.00000",
"maxNotional": "250000",
"positionSide": "BOTH",
"positionAmt": "0",
"positionAmt": "10",
"updateTime": 0
}
]
Expand All @@ -459,9 +458,8 @@ 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), "10");
EXPECT_DOUBLE_EQ(std::stod(element.getValue(CCAPI_EM_POSITION_ENTRY_PRICE)), 0);
EXPECT_EQ(element.getValue(CCAPI_EM_POSITION_LEVERAGE), "100");
}

} /* namespace ccapi */
Expand Down
Loading