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
14 changes: 14 additions & 0 deletions include/ccapi_cpp/ccapi_util_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,16 @@ class Decimal {
public:
Decimal() {}

template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
Decimal(T value) {
if (value < 0) {
this->sign = false;
this->before = -value;
} else if (value > 0) {
this->before = value;
}
}

explicit Decimal(std::string_view originalValue) {
if (originalValue.empty()) {
throw std::invalid_argument("Decimal constructor input value cannot be empty");
Expand Down Expand Up @@ -1340,6 +1350,8 @@ class Decimal {

return result;
}

static const Decimal zero;
#ifndef CCAPI_EXPOSE_INTERNAL

private:
Expand All @@ -1354,6 +1366,8 @@ class Decimal {
mutable std::optional<double> cachedToDouble;
};

inline const Decimal Decimal::zero = Decimal(0); // define after full class body

inline std::string ConvertDecimalToString(const Decimal& input, bool normalize = true) {
// constexpr unsigned precision = GetCppDecFloatDigits<Decimal::backend_type>::value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,56 +374,73 @@ class ExecutionManagementServiceBinanceBase : public ExecutionManagementService
const auto& marginType = request.getMarginType();
if (this->isDerivatives) {
for (const auto& x : document["assets"].GetArray()) {
Element element;
element.insert(CCAPI_EM_ASSET, x["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, x["walletBalance"].GetString());
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, x["availableBalance"].GetString());
if (this->isDerivatives) {
element.insert(CCAPI_LAST_UPDATED_TIME_SECONDS, UtilTime::convertMillisecondsStrToSecondsStr(x["updateTime"].GetString()));
const auto& quantityTotalDecimal = Decimal(x["walletBalance"].GetString());
if (quantityTotalDecimal != Decimal::zero) {
Element element;
element.insert(CCAPI_EM_ASSET, x["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(quantityTotalDecimal));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, x["availableBalance"].GetString());
if (this->isDerivatives) {
element.insert(CCAPI_LAST_UPDATED_TIME_SECONDS, UtilTime::convertMillisecondsStrToSecondsStr(x["updateTime"].GetString()));
}
elementList.emplace_back(std::move(element));
}
elementList.emplace_back(std::move(element));
}
} else {
if (marginType == CCAPI_EM_MARGIN_TYPE_CROSS_MARGIN) {
for (const auto& x : document["userAssets"].GetArray()) {
Element element;
element.insert(CCAPI_EM_ASSET, x["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(Decimal(x["free"].GetString()) + (Decimal(x["locked"].GetString()))));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, x["free"].GetString());
element.insert(CCAPI_EM_QUANTITY_LIABILITY, ConvertDecimalToString(Decimal(x["borrowed"].GetString()) + (Decimal(x["interest"].GetString()))));
elementList.emplace_back(std::move(element));
const auto& quantityTotalDecimal = Decimal(x["free"].GetString()) + Decimal(x["locked"].GetString());
if (quantityTotalDecimal != Decimal::zero) {
Element element;
element.insert(CCAPI_EM_ASSET, x["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(quantityTotalDecimal));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, x["free"].GetString());
element.insert(CCAPI_EM_QUANTITY_LIABILITY, ConvertDecimalToString(Decimal(x["borrowed"].GetString()) + (Decimal(x["interest"].GetString()))));
elementList.emplace_back(std::move(element));
}
}
} else if (marginType == CCAPI_EM_MARGIN_TYPE_ISOLATED_MARGIN) {
for (const auto& x : document["assets"].GetArray()) {
std::string symbol = x["symbol"].GetString();
{
const auto& y = x["baseAsset"];
Element element;
element.insert(CCAPI_EM_INSTRUMENT, symbol);
element.insert(CCAPI_EM_ASSET, y["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(Decimal(y["free"].GetString()) + (Decimal(y["locked"].GetString()))));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, y["free"].GetString());
element.insert(CCAPI_EM_QUANTITY_LIABILITY, ConvertDecimalToString(Decimal(y["borrowed"].GetString()) + (Decimal(y["interest"].GetString()))));
elementList.emplace_back(std::move(element));
const auto& quantityTotalDecimal = Decimal(y["free"].GetString()) + Decimal(y["locked"].GetString());
if (quantityTotalDecimal != Decimal::zero) {
Element element;
element.insert(CCAPI_EM_INSTRUMENT, symbol);
element.insert(CCAPI_EM_ASSET, y["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(quantityTotalDecimal));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, y["free"].GetString());
element.insert(CCAPI_EM_QUANTITY_LIABILITY,
ConvertDecimalToString(Decimal(y["borrowed"].GetString()) + (Decimal(y["interest"].GetString()))));
elementList.emplace_back(std::move(element));
}
}
{
const auto& y = x["quoteAsset"];
Element element;
element.insert(CCAPI_EM_INSTRUMENT, symbol);
element.insert(CCAPI_EM_ASSET, y["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(Decimal(y["free"].GetString()) + (Decimal(y["locked"].GetString()))));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, y["free"].GetString());
element.insert(CCAPI_EM_QUANTITY_LIABILITY, ConvertDecimalToString(Decimal(y["borrowed"].GetString()) + (Decimal(y["interest"].GetString()))));
elementList.emplace_back(std::move(element));
const auto& quantityTotalDecimal = Decimal(y["free"].GetString()) + Decimal(y["locked"].GetString());
if (quantityTotalDecimal != Decimal::zero) {
Element element;
element.insert(CCAPI_EM_INSTRUMENT, symbol);
element.insert(CCAPI_EM_ASSET, y["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(quantityTotalDecimal));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, y["free"].GetString());
element.insert(CCAPI_EM_QUANTITY_LIABILITY,
ConvertDecimalToString(Decimal(y["borrowed"].GetString()) + (Decimal(y["interest"].GetString()))));
elementList.emplace_back(std::move(element));
}
}
}
} else {
for (const auto& x : document["balances"].GetArray()) {
Element element;
element.insert(CCAPI_EM_ASSET, x["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(Decimal(x["free"].GetString()) + (Decimal(x["locked"].GetString()))));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, x["free"].GetString());
elementList.emplace_back(std::move(element));
const auto& quantityTotalDecimal = Decimal(x["free"].GetString()) + Decimal(x["locked"].GetString());
if (quantityTotalDecimal != Decimal::zero) {
Element element;
element.insert(CCAPI_EM_ASSET, x["asset"].GetString());
element.insert(CCAPI_EM_QUANTITY_TOTAL, ConvertDecimalToString(quantityTotalDecimal));
element.insert(CCAPI_EM_QUANTITY_AVAILABLE_FOR_TRADING, x["free"].GetString());
elementList.emplace_back(std::move(element));
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions include/ccapi_cpp/service/ccapi_market_data_service_bybit.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class MarketDataServiceBybit : public MarketDataService {

protected:
#endif
void pingOnApplicationLevel(std::shared_ptr<WsConnection> wsConnectionPtr, ErrorCode& ec) override { this->send(wsConnectionPtr, R"({"op":"ping"})", ec); }

std::string getInstrumentGroup(const Subscription& subscription) override {
const auto& instrumentTypeSubstitute = subscription.getInstrumentType();
std::string url = MarketDataService::getInstrumentGroup(subscription);
Expand Down
Loading