diff --git a/src/api-objects/src/apikeysprovider.cpp b/src/api-objects/src/apikeysprovider.cpp index ccafbaf7..2491373f 100644 --- a/src/api-objects/src/apikeysprovider.cpp +++ b/src/api-objects/src/apikeysprovider.cpp @@ -9,6 +9,7 @@ #include "apikey.hpp" #include "cct_const.hpp" #include "cct_exception.hpp" +#include "cct_json.hpp" #include "cct_log.hpp" #include "cct_string.hpp" #include "exchangename.hpp" diff --git a/src/api-objects/src/closed-order.cpp b/src/api-objects/src/closed-order.cpp index 92cd5cdb..e3dc2e05 100644 --- a/src/api-objects/src/closed-order.cpp +++ b/src/api-objects/src/closed-order.cpp @@ -6,7 +6,6 @@ #include "order.hpp" #include "orderid.hpp" #include "timedef.hpp" -#include "timestring.hpp" #include "tradeside.hpp" namespace cct { diff --git a/src/api/common/src/commonapi.cpp b/src/api/common/src/commonapi.cpp index d1ef723c..abf7412b 100644 --- a/src/api/common/src/commonapi.cpp +++ b/src/api/common/src/commonapi.cpp @@ -25,6 +25,7 @@ #include "read-json.hpp" #include "timedef.hpp" #include "withdrawalfees-crawler.hpp" +#include "write-json.hpp" namespace cct::api { namespace { @@ -152,10 +153,10 @@ CurrencyCodeVector CommonAPI::FiatsFunc::retrieveFiatsSource1() { // data is UTF-8 encoded - but the relevant data that we will parse is ASCII normally CurrencyCSV currencies; - auto ec = json::read(currencies, data); + auto ec = json::read(currencies, data); if (ec || currencies.AlphabeticCode.size() != currencies.WithdrawalDate.size()) { - log::warn("Error parsing json data of currency codes from source 1: {}", glz::format_error(ec, data)); + log::warn("Error parsing json data of currency codes from source 1: {}", json::format_error(ec, data)); return fiatsVec; } diff --git a/src/api/common/src/withdrawalfees-crawler.cpp b/src/api/common/src/withdrawalfees-crawler.cpp index d162c74e..69d8b775 100644 --- a/src/api/common/src/withdrawalfees-crawler.cpp +++ b/src/api/common/src/withdrawalfees-crawler.cpp @@ -1,9 +1,7 @@ #include "withdrawalfees-crawler.hpp" -#include #include #include -#include #include #include @@ -12,6 +10,7 @@ #include "cct_cctype.hpp" #include "cct_const.hpp" #include "cct_exception.hpp" +#include "cct_json.hpp" #include "cct_log.hpp" #include "cct_string.hpp" #include "coincenterinfo.hpp" diff --git a/src/api/common/test/exchangeprivateapi_test.cpp b/src/api/common/test/exchangeprivateapi_test.cpp index a3c715c4..86ca08d7 100644 --- a/src/api/common/test/exchangeprivateapi_test.cpp +++ b/src/api/common/test/exchangeprivateapi_test.cpp @@ -46,13 +46,16 @@ namespace cct { -static inline BalancePortfolio operator+(const BalancePortfolio &balancePortfolio, const TradedAmounts &tradedAmounts) { +namespace { +BalancePortfolio addTradedAmounts(const BalancePortfolio &balancePortfolio, const TradedAmounts &tradedAmounts) { BalancePortfolio ret = balancePortfolio; ret += tradedAmounts.to; ret += -tradedAmounts.from; return ret; } +} // namespace + static inline bool operator==(const TradedAmountsVectorWithFinalAmount &lhs, const TradedAmountsVectorWithFinalAmount &rhs) { return lhs.finalAmount == rhs.finalAmount && lhs.tradedAmountsVector == rhs.tradedAmountsVector; @@ -444,11 +447,11 @@ TEST_F(ExchangePrivateTest, MakerTradeQuoteToBaseTimeout) { EXPECT_EQ(exchangePrivate.trade(from, market.base(), tradeOptions), partialMatchedTradedAmounts); } -static inline bool operator==(const InitiatedWithdrawInfo &lhs, const InitiatedWithdrawInfo &rhs) { +inline bool operator==(const InitiatedWithdrawInfo &lhs, const InitiatedWithdrawInfo &rhs) { return lhs.withdrawId() == rhs.withdrawId(); } -static inline bool operator==(const SentWithdrawInfo &lhs, const SentWithdrawInfo &rhs) { +inline bool operator==(const SentWithdrawInfo &lhs, const SentWithdrawInfo &rhs) { return lhs.withdrawStatus() == rhs.withdrawStatus() && lhs.netEmittedAmount() == rhs.netEmittedAmount(); } @@ -788,7 +791,7 @@ TEST_F(ExchangePrivateDustSweeperTest, DustSweeper5Steps) { TradedAmounts tradedAmounts1 = expectTakerBuy(xrpDustThreshold, xrpbtcAskPri, xrpbtcBidPri, xrpbtcMarket); from += tradedAmounts1.to; - BalancePortfolio balance2 = balance1 + tradedAmounts1; + BalancePortfolio balance2 = addTradedAmounts(balance1, tradedAmounts1); EXPECT_CALL(exchangePrivate, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balance2)); @@ -796,7 +799,7 @@ TEST_F(ExchangePrivateDustSweeperTest, DustSweeper5Steps) { TradedAmounts tradedAmounts2 = expectTakerSell(from, priBtc, percentXRPSoldSecondStep); from -= tradedAmounts2.from; - BalancePortfolio balance3 = balance2 + tradedAmounts2; + BalancePortfolio balance3 = addTradedAmounts(balance2, tradedAmounts2); EXPECT_CALL(exchangePrivate, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balance3)); @@ -810,13 +813,13 @@ TEST_F(ExchangePrivateDustSweeperTest, DustSweeper5Steps) { TradedAmounts tradedAmounts3 = expectTakerBuy((3 * xrpDustThreshold) / 2, xrpeurAskPri, xrpeurBidPri, xrpeurMarket); from += tradedAmounts3.to; - BalancePortfolio balance4 = balance3 + tradedAmounts3; + BalancePortfolio balance4 = addTradedAmounts(balance3, tradedAmounts3); EXPECT_CALL(exchangePrivate, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balance4)); // Final sell that works TradedAmounts tradedAmounts4 = expectTakerSell(from, priEur); - BalancePortfolio balance5 = balance4 + tradedAmounts4; + BalancePortfolio balance5 = addTradedAmounts(balance4, tradedAmounts4); EXPECT_CALL(exchangePrivate, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balance5)); diff --git a/src/api/common/test/fiatconverter_test.cpp b/src/api/common/test/fiatconverter_test.cpp index 350becce..ffc425bf 100644 --- a/src/api/common/test/fiatconverter_test.cpp +++ b/src/api/common/test/fiatconverter_test.cpp @@ -8,10 +8,12 @@ #include "../src/fiats-converter-responses-schema.hpp" #include "besturlpicker.hpp" +#include "cct_string.hpp" #include "coincenterinfo.hpp" #include "curlhandle.hpp" #include "curloptions.hpp" #include "permanentcurloptions.hpp" +#include "reader.hpp" #include "runmodes.hpp" #include "timedef.hpp" #include "write-json.hpp" diff --git a/src/api/exchanges/src/binancepublicapi.cpp b/src/api/exchanges/src/binancepublicapi.cpp index e969b3c9..4002865a 100644 --- a/src/api/exchanges/src/binancepublicapi.cpp +++ b/src/api/exchanges/src/binancepublicapi.cpp @@ -19,7 +19,6 @@ #include "cachedresult.hpp" #include "cct_const.hpp" #include "cct_exception.hpp" -#include "cct_json.hpp" #include "cct_log.hpp" #include "cct_string.hpp" #include "coincenterinfo.hpp" diff --git a/src/api/exchanges/src/bithumbprivateapi.cpp b/src/api/exchanges/src/bithumbprivateapi.cpp index 0eba1908..6b3fed03 100644 --- a/src/api/exchanges/src/bithumbprivateapi.cpp +++ b/src/api/exchanges/src/bithumbprivateapi.cpp @@ -24,7 +24,6 @@ #include "cachedresult.hpp" #include "cct_exception.hpp" #include "cct_fixedcapacityvector.hpp" -#include "cct_json.hpp" #include "cct_log.hpp" #include "cct_smallvector.hpp" #include "cct_string.hpp" diff --git a/src/api/exchanges/src/bithumbpublicapi.cpp b/src/api/exchanges/src/bithumbpublicapi.cpp index c8ef50e2..b68cca68 100644 --- a/src/api/exchanges/src/bithumbpublicapi.cpp +++ b/src/api/exchanges/src/bithumbpublicapi.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "apiquerytypeenum.hpp" #include "bithumb-schema.hpp" diff --git a/src/api/exchanges/src/huobiprivateapi.cpp b/src/api/exchanges/src/huobiprivateapi.cpp index 23473d64..1bf82e29 100644 --- a/src/api/exchanges/src/huobiprivateapi.cpp +++ b/src/api/exchanges/src/huobiprivateapi.cpp @@ -1,6 +1,7 @@ #include "huobiprivateapi.hpp" #include +#include #include #include #include diff --git a/src/api/exchanges/src/huobipublicapi.cpp b/src/api/exchanges/src/huobipublicapi.cpp index 901cbd02..d6c7d5cd 100644 --- a/src/api/exchanges/src/huobipublicapi.cpp +++ b/src/api/exchanges/src/huobipublicapi.cpp @@ -14,6 +14,7 @@ #include "apiquerytypeenum.hpp" #include "cachedresult.hpp" #include "cct_const.hpp" +#include "cct_json.hpp" #include "cct_log.hpp" #include "cct_string.hpp" #include "coincenterinfo.hpp" @@ -26,6 +27,7 @@ #include "currencycodeset.hpp" #include "currencyexchange.hpp" #include "currencyexchangeflatset.hpp" +#include "exchange-asset-config.hpp" #include "exchangepublicapi.hpp" #include "exchangepublicapitypes.hpp" #include "fiatconverter.hpp" @@ -130,13 +132,14 @@ schema::huobi::V2ReferenceCurrency HuobiPublic::TradableCurrenciesFunc::operator return PublicQuery(_curlHandle, "/v2/reference/currencies"); } +namespace { CurrencyChainPicker CreateCurrencyChainPicker( const schema::ExchangeAssetConfig& assetConfig) { - return CurrencyChainPicker( - assetConfig, [](const schema::huobi::V2ReferenceCurrencyDetails::Chain& chain) -> std::string_view { - return chain.displayName; - }); + return {assetConfig, [](const schema::huobi::V2ReferenceCurrencyDetails::Chain& chain) -> std::string_view { + return chain.displayName; + }}; } +} // namespace HuobiPublic::WithdrawParams HuobiPublic::getWithdrawParams(CurrencyCode cur) { WithdrawParams withdrawParams; diff --git a/src/api/exchanges/src/krakenprivateapi.cpp b/src/api/exchanges/src/krakenprivateapi.cpp index eb4ceaa9..14029725 100644 --- a/src/api/exchanges/src/krakenprivateapi.cpp +++ b/src/api/exchanges/src/krakenprivateapi.cpp @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include "apikey.hpp" #include "apiquerytypeenum.hpp" @@ -228,7 +230,7 @@ Wallet KrakenPrivate::DepositWalletFunc::operator()(CurrencyCode currencyCode) { [&tag](auto&& field) { using T = std::decay_t; if constexpr (std::is_same_v) { - tag = std::move(field); + tag = std::forward(field); } else if constexpr (std::is_same_v) { tag = IntegralToString(field); } else { @@ -242,7 +244,7 @@ Wallet KrakenPrivate::DepositWalletFunc::operator()(CurrencyCode currencyCode) { [&tag](auto&& field) { using T = std::decay_t; if constexpr (std::is_same_v) { - tag = std::move(field); + tag = std::forward(field); } else if constexpr (std::is_same_v) { tag = IntegralToString(field); } else { diff --git a/src/api/exchanges/src/krakenpublicapi.cpp b/src/api/exchanges/src/krakenpublicapi.cpp index dc494785..b77e5133 100644 --- a/src/api/exchanges/src/krakenpublicapi.cpp +++ b/src/api/exchanges/src/krakenpublicapi.cpp @@ -1,6 +1,7 @@ #include "krakenpublicapi.hpp" #include +#include #include #include #include diff --git a/src/api/exchanges/src/kucoinprivateapi.cpp b/src/api/exchanges/src/kucoinprivateapi.cpp index 6e5ec9da..c02dc8f2 100644 --- a/src/api/exchanges/src/kucoinprivateapi.cpp +++ b/src/api/exchanges/src/kucoinprivateapi.cpp @@ -1,6 +1,7 @@ #include "kucoinprivateapi.hpp" #include +#include #include #include #include @@ -39,6 +40,7 @@ #include "orderid.hpp" #include "ordersconstraints.hpp" #include "permanentcurloptions.hpp" +#include "query-retry-policy.hpp" #include "request-retry.hpp" #include "ssl_sha.hpp" #include "stringconv.hpp" diff --git a/src/api/exchanges/src/kucoinpublicapi.cpp b/src/api/exchanges/src/kucoinpublicapi.cpp index 7e63a418..4fcd8e9c 100644 --- a/src/api/exchanges/src/kucoinpublicapi.cpp +++ b/src/api/exchanges/src/kucoinpublicapi.cpp @@ -1,6 +1,7 @@ #include "kucoinpublicapi.hpp" #include +#include #include #include #include @@ -116,9 +117,11 @@ KucoinPublic::TradableCurrenciesFunc::CurrencyInfoSet KucoinPublic::TradableCurr continue; } + const auto& chains = *curDetail.chains; + bool foundChain = false; - for (const auto& curChain : *curDetail.chains) { - if (curDetail.chains->size() > 1U && curChain.chainName != curStr && + for (const auto& curChain : chains) { + if (chains.size() > 1U && curChain.chainName != curStr && (curChain.chainId.size() > CurrencyCode::kMaxLen || CurrencyCode(curChain.chainId) != cur)) { log::debug("Discard {} as chain name is different from currency code", curStr); continue; diff --git a/src/api/exchanges/src/upbit-schema.hpp b/src/api/exchanges/src/upbit-schema.hpp index 9dad7fa8..80b88cfc 100644 --- a/src/api/exchanges/src/upbit-schema.hpp +++ b/src/api/exchanges/src/upbit-schema.hpp @@ -231,6 +231,13 @@ struct V1Deposit { enum class State : int8_t { PROCESSING, REFUNDING, ACCEPTED, CANCELLED, REJECTED, TRAVEL_RULE_SUSPECTED, REFUNDED }; + std::string_view timeStr() const { + if (done_at) { + return *done_at; + } + return created_at; + } + string currency; string txid; string created_at; @@ -252,6 +259,13 @@ struct V1Withdraw { // Let's support both spellings to avoid issues. enum class State : int8_t { WAITING, PROCESSING, DONE, FAILED, CANCELLED, CANCELED, REJECTED }; + std::string_view timeStr() const { + if (done_at) { + return *done_at; + } + return created_at; + } + string currency; string txid; string created_at; diff --git a/src/api/exchanges/src/upbitprivateapi.cpp b/src/api/exchanges/src/upbitprivateapi.cpp index aaa3c41c..040418ed 100644 --- a/src/api/exchanges/src/upbitprivateapi.cpp +++ b/src/api/exchanges/src/upbitprivateapi.cpp @@ -7,9 +7,9 @@ #include #include #include -#include #include #include +#include #include "apikey.hpp" #include "apiquerytypeenum.hpp" @@ -31,7 +31,6 @@ #include "currencyexchangeflatset.hpp" #include "deposit.hpp" #include "depositsconstraints.hpp" -#include "durationstring.hpp" #include "exchange-tradefees-config.hpp" #include "exchangename.hpp" #include "exchangeprivateapi.hpp" @@ -45,6 +44,7 @@ #include "orderid.hpp" #include "ordersconstraints.hpp" #include "permanentcurloptions.hpp" +#include "query-retry-policy.hpp" #include "request-retry.hpp" #include "ssl_sha.hpp" #include "timedef.hpp" @@ -235,7 +235,11 @@ Wallet UpbitPrivate::DepositWalletFunc::operator()(CurrencyCode currencyCode) { "/v1/deposits/coin_address", postData, 10) .first; } - std::string_view tag = result.secondary_address.value_or(""); + + std::string_view tag; + if (result.secondary_address) { + tag = *result.secondary_address; + } const CoincenterInfo& coincenterInfo = _exchangePublic.coincenterInfo(); bool doCheckWallet = @@ -453,7 +457,7 @@ DepositsSet UpbitPrivate::queryRecentDeposits(const DepositsConstraints& deposit // 'done_at' string is in this format: "2019-01-04T13:48:09+09:00" // It can be empty for deposits that failed - take the start time instead of the end time in this case - std::string_view timeStr = trx.done_at.value_or(trx.created_at); + std::string_view timeStr = trx.timeStr(); TimePoint timestamp = StringToTime(timeStr, kTimeYearToSecondTSeparatedFormat); if (!depositsConstraints.validateTime(timestamp)) { @@ -529,7 +533,8 @@ WithdrawsSet UpbitPrivate::queryRecentWithdraws(const WithdrawsConstraints& with MonetaryAmount withdrawFee(trx.fee, currencyCode); // 'done_at' string is in this format: "2019-01-04T13:48:09+09:00" // It can be empty for withdraws that failed - take the start time instead of the end time in this case - std::string_view timeStr = trx.done_at.value_or(trx.created_at); + std::string_view timeStr = trx.timeStr(); + TimePoint timestamp = StringToTime(timeStr, kTimeYearToSecondTSeparatedFormat); if (!withdrawsConstraints.validateTime(timestamp)) { continue; diff --git a/src/api/exchanges/src/upbitpublicapi.cpp b/src/api/exchanges/src/upbitpublicapi.cpp index 4f1395b0..a5c15a9b 100644 --- a/src/api/exchanges/src/upbitpublicapi.cpp +++ b/src/api/exchanges/src/upbitpublicapi.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include "apiquerytypeenum.hpp" #include "cachedresult.hpp" diff --git a/src/api/interface/include/exchange.hpp b/src/api/interface/include/exchange.hpp index 879132ad..2298c18b 100644 --- a/src/api/interface/include/exchange.hpp +++ b/src/api/interface/include/exchange.hpp @@ -23,7 +23,7 @@ namespace cct { -class Exchange : public CacheFileUpdatorInterface { +class Exchange final : public CacheFileUpdatorInterface { public: using ExchangePublic = api::ExchangePublic; using ExchangePrivate = api::ExchangePrivate; diff --git a/src/api/interface/src/exchange.cpp b/src/api/interface/src/exchange.cpp index 3d4edfb0..ad5ec280 100644 --- a/src/api/interface/src/exchange.cpp +++ b/src/api/interface/src/exchange.cpp @@ -7,7 +7,6 @@ #include "cct_log.hpp" #include "currencycode.hpp" #include "currencyexchangeflatset.hpp" -#include "exchangename.hpp" #include "exchangeprivateapi.hpp" #include "exchangepublicapi.hpp" #include "marketorderbook.hpp" diff --git a/src/basic-objects/src/coincentercommandtype.cpp b/src/basic-objects/src/coincentercommandtype.cpp index 9a654b64..67fbb2a2 100644 --- a/src/basic-objects/src/coincentercommandtype.cpp +++ b/src/basic-objects/src/coincentercommandtype.cpp @@ -1,8 +1,5 @@ #include "coincentercommandtype.hpp" -#include -#include - namespace cct { bool IsAnyTrade(CoincenterCommandType coincenterCommandType) { diff --git a/src/engine/src/coincenter.cpp b/src/engine/src/coincenter.cpp index e5c8e1f1..8ccfe301 100644 --- a/src/engine/src/coincenter.cpp +++ b/src/engine/src/coincenter.cpp @@ -11,6 +11,7 @@ #include "algorithm-name-iterator.hpp" #include "balanceoptions.hpp" #include "cct_const.hpp" +#include "cct_json.hpp" #include "cct_log.hpp" #include "coincenterinfo.hpp" #include "currencycode.hpp" diff --git a/src/engine/src/exchangesorchestrator.cpp b/src/engine/src/exchangesorchestrator.cpp index d78dc663..52356ea2 100644 --- a/src/engine/src/exchangesorchestrator.cpp +++ b/src/engine/src/exchangesorchestrator.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -203,6 +204,7 @@ BalancePerExchange ExchangesOrchestrator::getBalance(ExchangeNameSpan privateExc BalancePerExchange ret; ret.reserve(selectedExchanges.size()); + // Note: we can use std::ranges::transform with balancePortfolios | std::views::as_rvalues in C++23 std::transform(selectedExchanges.begin(), selectedExchanges.end(), std::make_move_iterator(balancePortfolios.begin()), std::back_inserter(ret), [](Exchange *exchange, BalancePortfolio &&balancePortfolio) { return std::make_pair(exchange, std::move(balancePortfolio)); @@ -405,7 +407,7 @@ MarketsPerExchange ExchangesOrchestrator::getMarketsPerExchange(CurrencyCode cur auto marketsWithCur = [cur1, cur2](Exchange *exchange) { MarketSet markets = exchange->queryTradableMarkets(); MarketSet ret; - std::copy_if(markets.begin(), markets.end(), std::inserter(ret, ret.end()), [cur1, cur2](Market mk) { + std::ranges::copy_if(markets, std::inserter(ret, ret.end()), [cur1, cur2](Market mk) { return (cur1.isNeutral() || mk.canTrade(cur1)) && (cur2.isNeutral() || mk.canTrade(cur2)); }); return std::make_pair(exchange, std::move(ret)); @@ -465,14 +467,12 @@ MarketSetsPtrPerExchange MapMarketSetsPtrInExchangesOrder(const ExchangeAmountPa const ExchangeRetriever::PublicExchangesVec &publicExchanges, MarketSetsPerPublicExchange &marketSetsPerExchange) { MarketSetsPtrPerExchange marketSetsPtrFromExchange(exchangeAmountPairVector.size()); - std::transform(exchangeAmountPairVector.begin(), exchangeAmountPairVector.end(), marketSetsPtrFromExchange.begin(), - [&](const auto &exchangePair) { - auto posIt = - std::ranges::find_if(publicExchanges, [&exchangePair](api::ExchangePublic *publicExchange) { - return exchangePair.first->name() == publicExchange->name(); - }); - return marketSetsPerExchange.data() + (posIt - publicExchanges.begin()); - }); + std::ranges::transform(exchangeAmountPairVector, marketSetsPtrFromExchange.begin(), [&](const auto &exchangePair) { + auto posIt = std::ranges::find_if(publicExchanges, [&exchangePair](api::ExchangePublic *publicExchange) { + return exchangePair.first->name() == publicExchange->name(); + }); + return marketSetsPerExchange.data() + (posIt - publicExchanges.begin()); + }); return marketSetsPtrFromExchange; } diff --git a/src/engine/src/metricsexporter.cpp b/src/engine/src/metricsexporter.cpp index 1cb28fcb..8b3dfb08 100644 --- a/src/engine/src/metricsexporter.cpp +++ b/src/engine/src/metricsexporter.cpp @@ -3,7 +3,7 @@ #include #include "abstractmetricgateway.hpp" -#include "cct_const.hpp" +#include "cct_json.hpp" #include "curlmetrics.hpp" #include "currencycode.hpp" #include "exchange.hpp" diff --git a/src/engine/src/queryresultprinter.cpp b/src/engine/src/queryresultprinter.cpp index 01a01d63..dad7374c 100644 --- a/src/engine/src/queryresultprinter.cpp +++ b/src/engine/src/queryresultprinter.cpp @@ -8,11 +8,14 @@ #include #include #include +#include #include #include "apioutputtype.hpp" #include "balanceperexchangeportfolio.hpp" +#include "balanceportfolio.hpp" #include "cct_const.hpp" +#include "cct_json.hpp" #include "cct_log.hpp" #include "cct_string.hpp" #include "closed-order.hpp" @@ -22,20 +25,16 @@ #include "currencyexchange.hpp" #include "deposit.hpp" #include "depositsconstraints.hpp" -#include "durationstring.hpp" #include "exchange.hpp" #include "exchangepublicapitypes.hpp" -#include "file.hpp" #include "logginginfo.hpp" #include "market-timestamp.hpp" #include "market.hpp" #include "marketorderbook.hpp" #include "monetaryamount.hpp" #include "opened-order.hpp" -#include "orderid.hpp" #include "ordersconstraints.hpp" #include "priceoptions.hpp" -#include "priceoptionsdef.hpp" #include "publictrade.hpp" #include "query-result-schema.hpp" #include "query-result-type-helpers.hpp" @@ -46,7 +45,6 @@ #include "timestring.hpp" #include "trade-range-stats.hpp" #include "tradedamounts.hpp" -#include "tradedefinitions.hpp" #include "tradeside.hpp" #include "unreachable.hpp" #include "withdraw.hpp" @@ -54,8 +52,6 @@ #include "withdrawoptions.hpp" #include "withdrawsconstraints.hpp" #include "withdrawsordepositsconstraints.hpp" -#include "write-json.hpp" -#include "writer.hpp" namespace cct { namespace { @@ -64,8 +60,8 @@ auto HealthCheckJson(const ExchangeHealthCheckStatus &healthCheckPerExchange) { schema::queryresult::HealthCheck obj; obj.out.reserve(healthCheckPerExchange.size()); - for (const auto &[e, healthCheckValue] : healthCheckPerExchange) { - obj.out.emplace_back(e->exchangeNameEnum(), healthCheckValue); + for (const auto &[exchange, healthCheckValue] : healthCheckPerExchange) { + obj.out.emplace_back(exchange->exchangeNameEnum(), healthCheckValue); } return obj; @@ -74,13 +70,13 @@ auto HealthCheckJson(const ExchangeHealthCheckStatus &healthCheckPerExchange) { auto CurrenciesJson(const CurrenciesPerExchange ¤ciesPerExchange) { schema::queryresult::CurrenciesPerExchange obj; - for (const auto &[e, currencies] : currenciesPerExchange) { + for (const auto &[exchange, currencies] : currenciesPerExchange) { using ExchangePartType = decltype(obj.out)::value_type::second_type; - auto &p = obj.out.emplace_back(e->exchangeNameEnum(), ExchangePartType{}); + auto &pair = obj.out.emplace_back(exchange->exchangeNameEnum(), ExchangePartType{}); - p.second.reserve(currencies.size()); + pair.second.reserve(currencies.size()); for (const CurrencyExchange &cur : currencies) { - auto ¤cy = p.second.emplace_back(); + auto ¤cy = pair.second.emplace_back(); currency.code = cur.standardCode(); currency.exchangeCode = cur.exchangeCode(); @@ -104,8 +100,8 @@ auto MarketsJson(CurrencyCode cur1, CurrencyCode cur2, const MarketsPerExchange obj.in.opt.cur2 = cur2; } obj.out.reserve(marketsPerExchange.size()); - for (const auto &[e, markets] : marketsPerExchange) { - obj.out.emplace_back(e->exchangeNameEnum(), markets); + for (const auto &[exchange, markets] : marketsPerExchange) { + obj.out.emplace_back(exchange->exchangeNameEnum(), markets); } return obj; @@ -118,9 +114,9 @@ auto MarketsForReplayJson(TimeWindow timeWindow, const MarketTimestampSetsPerExc obj.in.opt.timeWindow = timeWindow; } - for (const auto &[e, marketTimestampSets] : marketTimestampSetsPerExchange) { + for (const auto &[exchange, marketTimestampSets] : marketTimestampSetsPerExchange) { using ExchangePartType = decltype(obj.out)::value_type::second_type; - auto &exchangePart = obj.out.emplace_back(e->exchangeNameEnum(), ExchangePartType{}).second; + auto &exchangePart = obj.out.emplace_back(exchange->exchangeNameEnum(), ExchangePartType{}).second; exchangePart.orderBooks.reserve(marketTimestampSets.orderBooksMarkets.size()); for (const MarketTimestamp &marketTimestamp : marketTimestampSets.orderBooksMarkets) { @@ -138,9 +134,9 @@ auto MarketsForReplayJson(TimeWindow timeWindow, const MarketTimestampSetsPerExc auto TickerInformationJson(const ExchangeTickerMaps &exchangeTickerMaps) { schema::queryresult::TickerInformation obj; - for (const auto &[e, marketOrderBookMap] : exchangeTickerMaps) { + for (const auto &[exchange, marketOrderBookMap] : exchangeTickerMaps) { using ExchangePartType = decltype(obj.out)::value_type::second_type; - auto &exchangePart = obj.out.emplace_back(e->exchangeNameEnum(), ExchangePartType{}).second; + auto &exchangePart = obj.out.emplace_back(exchange->exchangeNameEnum(), ExchangePartType{}).second; exchangePart.reserve(marketOrderBookMap.size()); for (const auto &[mk, marketOrderBook] : marketOrderBookMap) { @@ -199,12 +195,12 @@ auto MarketOrderBooksJson(Market mk, CurrencyCode equiCurrencyCode, std::optiona return obj; } -auto &GetExchangePart(const Exchange *e, auto &out) { +auto &GetExchangePart(const Exchange *exchange, auto &out) { using ExchangePart = std::remove_cvref_t::value_type::second_type; - auto it = - std::ranges::find_if(out, [e](const auto &exchangePart) { return exchangePart.first == e->exchangeNameEnum(); }); + auto it = std::ranges::find_if( + out, [exchange](const auto &exchangePart) { return exchangePart.first == exchange->exchangeNameEnum(); }); if (it == out.end()) { - return out.emplace_back(e->exchangeNameEnum(), ExchangePart{}).second; + return out.emplace_back(exchange->exchangeNameEnum(), ExchangePart{}).second; } return it->second; } @@ -224,9 +220,9 @@ auto BalanceJson(const BalancePerExchange &balancePerExchange, CurrencyCode equi obj.in.opt.equiCurrency = equiCurrency; } - for (const auto &[e, balance] : balancePerExchange) { - auto &exchangePart = GetExchangePart(e, obj.out.exchange); - auto &exchangeKeyPart = exchangePart.emplace_back(e->keyName(), ExchangeKeyPart{}).second; + for (const auto &[exchange, balance] : balancePerExchange) { + auto &exchangePart = GetExchangePart(exchange, obj.out.exchange); + auto &exchangeKeyPart = exchangePart.emplace_back(exchange->keyName(), ExchangeKeyPart{}).second; for (const auto &[amount, equiAmount] : balance) { auto ¤cyPart = exchangeKeyPart.emplace_back(amount.currencyCode(), CurrencyPart{}).second; @@ -263,9 +259,9 @@ auto DepositInfoJson(CurrencyCode depositCurrencyCode, const WalletPerExchange & using ExchangePart = decltype(obj.out)::value_type::second_type; using ExchangeKeyPart = ExchangePart::value_type::second_type; - for (const auto &[e, wallet] : walletPerExchange) { - auto &exchangePart = GetExchangePart(e, obj.out); - auto &exchangeKeyPart = exchangePart.emplace_back(e->keyName(), ExchangeKeyPart{}).second; + for (const auto &[exchange, wallet] : walletPerExchange) { + auto &exchangePart = GetExchangePart(exchange, obj.out); + auto &exchangeKeyPart = exchangePart.emplace_back(exchange->keyName(), ExchangeKeyPart{}).second; exchangeKeyPart.address = wallet.address(); if (wallet.hasTag()) { @@ -323,9 +319,9 @@ auto TradesJson(const TradeResultPerExchange &tradeResultPerExchange, MonetaryAm using ExchangePart = decltype(obj.out)::value_type::second_type; using ExchangeKeyPart = ExchangePart::value_type::second_type; - for (const auto &[e, tradeResult] : tradeResultPerExchange) { - auto &exchangePart = GetExchangePart(e, obj.out); - auto &exchangeKeyPart = exchangePart.emplace_back(e->keyName(), ExchangeKeyPart{}).second; + for (const auto &[exchange, tradeResult] : tradeResultPerExchange) { + auto &exchangePart = GetExchangePart(exchange, obj.out); + auto &exchangeKeyPart = exchangePart.emplace_back(exchange->keyName(), ExchangeKeyPart{}).second; exchangeKeyPart.from = tradeResult.from().toNeutral(); exchangeKeyPart.status = tradeResult.state(); @@ -394,9 +390,9 @@ auto OrdersJson(CoincenterCommandType coincenterCommandType, const OrdersPerExch using ExchangePart = decltype(obj.out)::value_type::second_type; using ExchangeKeyPart = ExchangePart::value_type::second_type; - for (const auto &[e, ordersData] : ordersPerExchange) { - auto &exchangePart = GetExchangePart(e, obj.out); - auto &exchangeKeyPart = exchangePart.emplace_back(e->keyName(), ExchangeKeyPart{}).second; + for (const auto &[exchange, ordersData] : ordersPerExchange) { + auto &exchangePart = GetExchangePart(exchange, obj.out); + auto &exchangeKeyPart = exchangePart.emplace_back(exchange->keyName(), ExchangeKeyPart{}).second; exchangeKeyPart.reserve(ordersData.size()); for (const auto &orderData : ordersData) { @@ -418,9 +414,9 @@ auto OrdersCancelledJson(const NbCancelledOrdersPerExchange &nbCancelledOrdersPe using ExchangePart = decltype(obj.out)::value_type::second_type; using ExchangeKeyPart = ExchangePart::value_type::second_type; - for (const auto &[e, nbCancelledOrders] : nbCancelledOrdersPerExchange) { - auto &exchangePart = GetExchangePart(e, obj.out); - auto &exchangeKeyPart = exchangePart.emplace_back(e->keyName(), ExchangeKeyPart{}).second; + for (const auto &[exchange, nbCancelledOrders] : nbCancelledOrdersPerExchange) { + auto &exchangePart = GetExchangePart(exchange, obj.out); + auto &exchangeKeyPart = exchangePart.emplace_back(exchange->keyName(), ExchangeKeyPart{}).second; exchangeKeyPart.nb = nbCancelledOrders; } @@ -473,9 +469,9 @@ auto RecentDepositsJson(const DepositsPerExchange &depositsPerExchange, using ExchangePart = decltype(obj.out)::value_type::second_type; using ExchangeKeyPart = ExchangePart::value_type::second_type; - for (const auto &[e, deposits] : depositsPerExchange) { - auto &exchangePart = GetExchangePart(e, obj.out); - auto &exchangeKeyPart = exchangePart.emplace_back(e->keyName(), ExchangeKeyPart{}).second; + for (const auto &[exchange, deposits] : depositsPerExchange) { + auto &exchangePart = GetExchangePart(exchange, obj.out); + auto &exchangeKeyPart = exchangePart.emplace_back(exchange->keyName(), ExchangeKeyPart{}).second; exchangeKeyPart.reserve(deposits.size()); for (const Deposit &deposit : deposits) { @@ -499,9 +495,9 @@ auto RecentWithdrawsJson(const WithdrawsPerExchange &withdrawsPerExchange, using ExchangePart = decltype(obj.out)::value_type::second_type; using ExchangeKeyPart = ExchangePart::value_type::second_type; - for (const auto &[e, withdraws] : withdrawsPerExchange) { - auto &exchangePart = GetExchangePart(e, obj.out); - auto &exchangeKeyPart = exchangePart.emplace_back(e->keyName(), ExchangeKeyPart{}).second; + for (const auto &[exchange, withdraws] : withdrawsPerExchange) { + auto &exchangePart = GetExchangePart(exchange, obj.out); + auto &exchangeKeyPart = exchangePart.emplace_back(exchange->keyName(), ExchangeKeyPart{}).second; exchangeKeyPart.reserve(withdraws.size()); for (const Withdraw &withdraw : withdraws) { @@ -526,11 +522,11 @@ auto ConversionJson(MonetaryAmount amount, CurrencyCode targetCurrencyCode, obj.in.opt.fromCurrency = amount.currencyCode(); obj.in.opt.toCurrency = targetCurrencyCode; - for (const auto &[e, convertedAmount] : conversionPerExchange) { + for (const auto &[exchange, convertedAmount] : conversionPerExchange) { if (convertedAmount != 0) { using ExchangePart = decltype(obj.out)::value_type::second_type; - obj.out.emplace_back(e->exchangeNameEnum(), ExchangePart{.convertedAmount = convertedAmount.toNeutral()}); + obj.out.emplace_back(exchange->exchangeNameEnum(), ExchangePart{.convertedAmount = convertedAmount.toNeutral()}); } } @@ -555,11 +551,11 @@ auto ConversionJson(std::span startAmountPerExchangePos, C ++publicExchangePos; } - for (const auto &[e, convertedAmount] : conversionPerExchange) { + for (const auto &[exchange, convertedAmount] : conversionPerExchange) { if (convertedAmount != 0) { using ExchangePart = decltype(obj.out)::value_type::second_type; - obj.out.emplace_back(e->exchangeNameEnum(), ExchangePart{.convertedAmount = convertedAmount.toNeutral()}); + obj.out.emplace_back(exchange->exchangeNameEnum(), ExchangePart{.convertedAmount = convertedAmount.toNeutral()}); } } @@ -571,9 +567,9 @@ auto ConversionPathJson(Market mk, const ConversionPathPerExchange &conversionPa obj.in.opt.market = mk; - for (const auto &[e, conversionPath] : conversionPathsPerExchange) { + for (const auto &[exchange, conversionPath] : conversionPathsPerExchange) { if (!conversionPath.empty()) { - obj.out.emplace_back(e->exchangeNameEnum(), conversionPath); + obj.out.emplace_back(exchange->exchangeNameEnum(), conversionPath); } } @@ -587,8 +583,8 @@ auto WithdrawFeesJson(const MonetaryAmountByCurrencySetPerExchange &withdrawFeeP obj.in.opt.cur = cur; } - for (const auto &[e, withdrawFees] : withdrawFeePerExchange) { - obj.out.emplace_back(e->exchangeNameEnum(), withdrawFees); + for (const auto &[exchange, withdrawFees] : withdrawFeePerExchange) { + obj.out.emplace_back(exchange->exchangeNameEnum(), withdrawFees); } return obj; @@ -598,8 +594,8 @@ auto Last24hTradedVolumeJson(Market mk, const MonetaryAmountPerExchange &tradedV schema::queryresult::Last24hTradedVolume obj; obj.in.opt.market = mk; - for (const auto &[e, tradedVolume] : tradedVolumePerExchange) { - obj.out.emplace_back(e->exchangeNameEnum(), tradedVolume.toNeutral()); + for (const auto &[exchange, tradedVolume] : tradedVolumePerExchange) { + obj.out.emplace_back(exchange->exchangeNameEnum(), tradedVolume.toNeutral()); } return obj; @@ -611,10 +607,10 @@ auto LastTradesJson(Market mk, std::optional nbLastTrades, const TradesPerE obj.in.opt.market = mk; obj.in.opt.nb = nbLastTrades; - for (const auto &[e, lastTrades] : lastTradesPerExchange) { + for (const auto &[exchange, lastTrades] : lastTradesPerExchange) { using ExchangePart = decltype(obj.out)::value_type::second_type; - auto &exchangePart = obj.out.emplace_back(e->exchangeNameEnum(), ExchangePart{}).second; + auto &exchangePart = obj.out.emplace_back(exchange->exchangeNameEnum(), ExchangePart{}).second; exchangePart.reserve(lastTrades.size()); for (const PublicTrade &trade : lastTrades) { @@ -635,8 +631,8 @@ auto LastPriceJson(Market mk, const MonetaryAmountPerExchange &pricePerExchange) obj.in.opt.market = mk; - for (const auto &[e, lastPrice] : pricePerExchange) { - obj.out.emplace_back(e->exchangeNameEnum(), lastPrice.toNeutral()); + for (const auto &[exchange, lastPrice] : pricePerExchange) { + obj.out.emplace_back(exchange->exchangeNameEnum(), lastPrice.toNeutral()); } return obj; @@ -679,9 +675,9 @@ auto DustSweeperJson(const TradedAmountsVectorWithFinalAmountPerExchange &traded using ExchangePart = decltype(obj.out)::value_type::second_type; using ExchangeKeyPart = ExchangePart::value_type::second_type; - for (const auto &[e, tradedAmountsVectorWithFinalAmount] : tradedAmountsVectorWithFinalAmountPerExchange) { - auto &exchangePart = GetExchangePart(e, obj.out); - auto &exchangeKeyPart = exchangePart.emplace_back(e->keyName(), ExchangeKeyPart{}).second; + for (const auto &[exchange, tradedAmountsVectorWithFinalAmount] : tradedAmountsVectorWithFinalAmountPerExchange) { + auto &exchangePart = GetExchangePart(exchange, obj.out); + auto &exchangeKeyPart = exchangePart.emplace_back(exchange->keyName(), ExchangeKeyPart{}).second; exchangeKeyPart.trades.reserve(tradedAmountsVectorWithFinalAmount.tradedAmountsVector.size()); for (const auto &tradedAmounts : tradedAmountsVectorWithFinalAmount.tradedAmountsVector) { @@ -714,7 +710,7 @@ auto MarketTradingResultsJson(TimeWindow inputTimeWindow, const ReplayResults &r auto &allResults = algorithmNameResults.emplace_back(); allResults.reserve(marketTradingResultPerExchange.size()); - for (const auto &[e, marketGlobalTradingResult] : marketTradingResultPerExchange) { + for (const auto &[exchange, marketGlobalTradingResult] : marketTradingResultPerExchange) { const auto &marketTradingResult = marketGlobalTradingResult.result; const auto &stats = marketGlobalTradingResult.stats; @@ -723,7 +719,7 @@ auto MarketTradingResultsJson(TimeWindow inputTimeWindow, const ReplayResults &r using MarketTradingResult = AllResults::value_type::value_type::second_type; auto &marketTradingResultPart = - exchangeMarketResults.emplace_back(e->exchangeNameEnum(), MarketTradingResult{}).second; + exchangeMarketResults.emplace_back(exchange->exchangeNameEnum(), MarketTradingResult{}).second; marketTradingResultPart.algorithm = marketTradingResult.algorithmName(); marketTradingResultPart.market = marketTradingResult.market(); @@ -776,8 +772,8 @@ void QueryResultPrinter::printHealthCheck(const ExchangeHealthCheckStatus &healt SimpleTable table; table.reserve(1U + healthCheckPerExchange.size()); table.emplace_back("Exchange", "Health Check status"); - for (const auto &[e, healthCheckValue] : healthCheckPerExchange) { - table.emplace_back(e->name(), healthCheckValue ? "OK" : "Not OK!"); + for (const auto &[exchange, healthCheckValue] : healthCheckPerExchange) { + table.emplace_back(exchange->name(), healthCheckValue ? "OK" : "Not OK!"); } printTable(table); break; @@ -898,9 +894,9 @@ void QueryResultPrinter::printMarkets(CurrencyCode cur1, CurrencyCode cur2, } SimpleTable table; table.emplace_back("Exchange", std::move(marketsCol)); - for (const auto &[e, markets] : marketsPerExchange) { + for (const auto &[exchange, markets] : marketsPerExchange) { for (Market mk : markets) { - table.emplace_back(e->name(), mk.str()); + table.emplace_back(exchange->name(), mk.str()); } } printTable(table); @@ -921,9 +917,9 @@ void QueryResultPrinter::printTickerInformation(const ExchangeTickerMaps &exchan case ApiOutputType::table: { SimpleTable table; table.emplace_back("Exchange", "Market", "Bid price", "Bid volume", "Ask price", "Ask volume"); - for (const auto &[e, marketOrderBookMap] : exchangeTickerMaps) { + for (const auto &[exchange, marketOrderBookMap] : exchangeTickerMaps) { for (const auto &[mk, marketOrderBook] : marketOrderBookMap) { - table.emplace_back(e->name(), mk.str(), marketOrderBook.highestBidPrice().str(), + table.emplace_back(exchange->name(), mk.str(), marketOrderBook.highestBidPrice().str(), marketOrderBook.amountAtBidPrice().str(), marketOrderBook.lowestAskPrice().str(), marketOrderBook.amountAtAskPrice().str()); } @@ -1181,9 +1177,9 @@ void QueryResultPrinter::printConversion(MonetaryAmount amount, CurrencyCode tar SimpleTable table; table.reserve(1U + conversionPerExchange.size()); table.emplace_back("Exchange", std::move(conversionStrHeader)); - for (const auto &[e, convertedAmount] : conversionPerExchange) { + for (const auto &[exchange, convertedAmount] : conversionPerExchange) { if (convertedAmount != 0) { - table.emplace_back(e->name(), convertedAmount.str()); + table.emplace_back(exchange->name(), convertedAmount.str()); } } printTable(table); @@ -1207,9 +1203,10 @@ void QueryResultPrinter::printConversion(std::span startAm SimpleTable table; table.reserve(1U + conversionPerExchange.size()); table.emplace_back("Exchange", "From", "To"); - for (const auto &[e, convertedAmount] : conversionPerExchange) { + for (const auto &[exchange, convertedAmount] : conversionPerExchange) { if (convertedAmount != 0) { - table.emplace_back(e->name(), startAmountPerExchangePos[e->publicExchangePos()].str(), convertedAmount.str()); + table.emplace_back(exchange->name(), startAmountPerExchangePos[exchange->publicExchangePos()].str(), + convertedAmount.str()); } } printTable(table); @@ -1234,7 +1231,7 @@ void QueryResultPrinter::printConversionPath(Market mk, SimpleTable table; table.reserve(1U + conversionPathsPerExchange.size()); table.emplace_back("Exchange", std::move(conversionPathStrHeader)); - for (const auto &[e, conversionPath] : conversionPathsPerExchange) { + for (const auto &[exchange, conversionPath] : conversionPathsPerExchange) { if (conversionPath.empty()) { continue; } @@ -1245,7 +1242,7 @@ void QueryResultPrinter::printConversionPath(Market mk, } conversionPathStr.append(market.str()); } - table.emplace_back(e->name(), std::move(conversionPathStr)); + table.emplace_back(exchange->name(), std::move(conversionPathStr)); } printTable(table); break; @@ -1266,8 +1263,8 @@ void QueryResultPrinter::printWithdrawFees(const MonetaryAmountByCurrencySetPerE case ApiOutputType::table: { table::Row header("Withdraw fee currency"); CurrencyCodeVector allCurrencyCodes; - for (const auto &[e, withdrawFees] : withdrawFeesPerExchange) { - header.emplace_back(e->name()); + for (const auto &[exchange, withdrawFees] : withdrawFeesPerExchange) { + header.emplace_back(exchange->name()); for (MonetaryAmount ma : withdrawFees) { allCurrencyCodes.push_back(ma.currencyCode()); } @@ -1281,7 +1278,7 @@ void QueryResultPrinter::printWithdrawFees(const MonetaryAmountByCurrencySetPerE table.emplace_back(std::move(header)); for (CurrencyCode cur : allCurrencyCodes) { auto &row = table.emplace_back(cur.str()); - for (const auto &[e, withdrawFees] : withdrawFeesPerExchange) { + for (const auto &[exchange, withdrawFees] : withdrawFeesPerExchange) { auto it = withdrawFees.find(cur); if (it == withdrawFees.end()) { row.emplace_back(""); @@ -1313,8 +1310,8 @@ void QueryResultPrinter::printLast24hTradedVolume(Market mk, SimpleTable table; table.reserve(1U + tradedVolumePerExchange.size()); table.emplace_back("Exchange", std::move(headerTradedVolume)); - for (const auto &[e, tradedVolume] : tradedVolumePerExchange) { - table.emplace_back(e->name(), tradedVolume.str()); + for (const auto &[exchange, tradedVolume] : tradedVolumePerExchange) { + table.emplace_back(exchange->name(), tradedVolume.str()); } printTable(table); break; @@ -1400,8 +1397,8 @@ void QueryResultPrinter::printLastPrice(Market mk, const MonetaryAmountPerExchan SimpleTable table; table.reserve(1U + pricePerExchange.size()); table.emplace_back("Exchange", std::move(headerLastPrice)); - for (const auto &[e, lastPrice] : pricePerExchange) { - table.emplace_back(e->name(), lastPrice.str()); + for (const auto &[exchange, lastPrice] : pricePerExchange) { + table.emplace_back(exchange->name(), lastPrice.str()); } printTable(table); break; @@ -1496,7 +1493,7 @@ void QueryResultPrinter::printMarketsForReplay(TimeWindow timeWindow, for (const Market market : allMarkets) { table::Cell orderBookCell; table::Cell tradesCell; - for (const auto &[e, marketTimestamps] : marketTimestampSetsPerExchange) { + for (const auto &[exchange, marketTimestamps] : marketTimestampSetsPerExchange) { const auto &orderBooksMarkets = marketTimestamps.orderBooksMarkets; const auto &tradesMarkets = marketTimestamps.tradesMarkets; const auto marketPartitionPred = [market](const auto &marketTimestamp) { @@ -1508,7 +1505,7 @@ void QueryResultPrinter::printMarketsForReplay(TimeWindow timeWindow, if (orderBooksIt != orderBooksMarkets.end() && orderBooksIt->market == market) { string str = TimeToString(orderBooksIt->timePoint); str.append(" @ "); - str.append(e->name()); + str.append(exchange->name()); orderBookCell.emplace_back(std::move(str)); } @@ -1516,7 +1513,7 @@ void QueryResultPrinter::printMarketsForReplay(TimeWindow timeWindow, if (tradesIt != tradesMarkets.end() && tradesIt->market == market) { string str = TimeToString(tradesIt->timePoint); str.append(" @ "); - str.append(e->name()); + str.append(exchange->name()); tradesCell.emplace_back(std::move(str)); } diff --git a/src/engine/src/traderesult.cpp b/src/engine/src/traderesult.cpp index 23bdfdf8..294b9f21 100644 --- a/src/engine/src/traderesult.cpp +++ b/src/engine/src/traderesult.cpp @@ -1,9 +1,5 @@ #include "traderesult.hpp" -#include - -#include "cct_exception.hpp" - namespace cct { TradeResult::State TradeResult::state() const { // from could be lower than actually traded from amount if rounding issues diff --git a/src/engine/test/exchangesorchestrator_private_test.cpp b/src/engine/test/exchangesorchestrator_private_test.cpp index 5cfcc614..66e52561 100644 --- a/src/engine/test/exchangesorchestrator_private_test.cpp +++ b/src/engine/test/exchangesorchestrator_private_test.cpp @@ -206,21 +206,21 @@ TEST_F(ExchangeOrchestratorTest, WithdrawImpossibleTo) { CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; EXPECT_CALL(ExchangePrivate(exchange2), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); - auto [exchanges, deliveredWithdrawInfo] = + const auto [exchanges, deliveredWithdrawInfo] = exchangesOrchestrator.withdraw(grossAmount, false, fromExchange, toExchange, withdrawOptions); EXPECT_FALSE(deliveredWithdrawInfo.hasBeenInitiated()); } -static inline bool operator==(const DeliveredWithdrawInfo &lhs, const DeliveredWithdrawInfo &rhs) { +inline bool operator==(const DeliveredWithdrawInfo &lhs, const DeliveredWithdrawInfo &rhs) { return lhs.withdrawId() == rhs.withdrawId(); } namespace api { -static inline bool operator==(const InitiatedWithdrawInfo &lhs, const InitiatedWithdrawInfo &rhs) { +inline bool operator==(const InitiatedWithdrawInfo &lhs, const InitiatedWithdrawInfo &rhs) { return lhs.withdrawId() == rhs.withdrawId(); } -static inline bool operator==(const SentWithdrawInfo &lhs, const SentWithdrawInfo &rhs) { +inline bool operator==(const SentWithdrawInfo &lhs, const SentWithdrawInfo &rhs) { return lhs.withdrawStatus() == rhs.withdrawStatus() && lhs.netEmittedAmount() == rhs.netEmittedAmount(); } } // namespace api diff --git a/src/engine/test/exchangesorchestrator_public_test.cpp b/src/engine/test/exchangesorchestrator_public_test.cpp index bc92dd6f..fed2f364 100644 --- a/src/engine/test/exchangesorchestrator_public_test.cpp +++ b/src/engine/test/exchangesorchestrator_public_test.cpp @@ -5,6 +5,7 @@ #include #include "cct_const.hpp" +#include "cct_json.hpp" #include "currencycode.hpp" #include "currencyexchange.hpp" #include "currencyexchangeflatset.hpp" diff --git a/src/engine/test/stringoptionparser_test.cpp b/src/engine/test/stringoptionparser_test.cpp index 7746e8a6..19c67a29 100644 --- a/src/engine/test/stringoptionparser_test.cpp +++ b/src/engine/test/stringoptionparser_test.cpp @@ -5,6 +5,7 @@ #include #include +#include "cct_const.hpp" #include "cct_invalid_argument_exception.hpp" #include "cct_string.hpp" #include "cct_vector.hpp" diff --git a/src/objects/include/amount-price.hpp b/src/objects/include/amount-price.hpp index ded5d9cc..5d5e4ad2 100644 --- a/src/objects/include/amount-price.hpp +++ b/src/objects/include/amount-price.hpp @@ -5,6 +5,8 @@ namespace cct { struct AmountPrice { + bool operator==(const AmountPrice &) const noexcept = default; + MonetaryAmount amount; MonetaryAmount price; }; diff --git a/src/objects/include/exchange-names.hpp b/src/objects/include/exchange-names.hpp index 0211ca43..0b313a77 100644 --- a/src/objects/include/exchange-names.hpp +++ b/src/objects/include/exchange-names.hpp @@ -18,6 +18,6 @@ using ExchangeNameEnumVector = FixedCapacityVector(capacity)); - } + void reserve(size_type capacity) { _orderBookLines.reserve(capacity); } void push(MonetaryAmount amount, MonetaryAmount price, OrderBookLine::Type type) { if (amount != 0) { diff --git a/src/objects/src/exchange-names.cpp b/src/objects/src/exchange-names.cpp index d6530a27..f6da7164 100644 --- a/src/objects/src/exchange-names.cpp +++ b/src/objects/src/exchange-names.cpp @@ -1,6 +1,6 @@ #include "exchange-names.hpp" -#include "cct_const.hpp" +#include "cct_json.hpp" #include "cct_string.hpp" namespace cct { diff --git a/src/objects/src/exchangename.cpp b/src/objects/src/exchangename.cpp index d7d6c2c4..55b7865d 100644 --- a/src/objects/src/exchangename.cpp +++ b/src/objects/src/exchangename.cpp @@ -3,9 +3,11 @@ #include #include #include +#include #include "cct_const.hpp" #include "cct_invalid_argument_exception.hpp" +#include "cct_json.hpp" #include "cct_string.hpp" #include "toupperlower-string.hpp" #include "toupperlower.hpp" diff --git a/src/objects/src/logginginfo.cpp b/src/objects/src/logginginfo.cpp index 3a672ff0..e8a3fd67 100644 --- a/src/objects/src/logginginfo.cpp +++ b/src/objects/src/logginginfo.cpp @@ -1,6 +1,7 @@ #include "logginginfo.hpp" #include +#include #include #include diff --git a/src/objects/src/marketorderbook.cpp b/src/objects/src/marketorderbook.cpp index e902e35f..0ec067c9 100644 --- a/src/objects/src/marketorderbook.cpp +++ b/src/objects/src/marketorderbook.cpp @@ -14,6 +14,7 @@ #include "amount-price.hpp" #include "cct_const.hpp" #include "cct_exception.hpp" +#include "cct_json.hpp" #include "cct_log.hpp" #include "cct_string.hpp" #include "currencycode.hpp" diff --git a/src/objects/src/time-window.cpp b/src/objects/src/time-window.cpp index 319622d6..b632b759 100644 --- a/src/objects/src/time-window.cpp +++ b/src/objects/src/time-window.cpp @@ -1,6 +1,7 @@ #include "time-window.hpp" #include +#include #include "cct_invalid_argument_exception.hpp" #include "cct_string.hpp" diff --git a/src/objects/test/marketorderbook_test.cpp b/src/objects/test/marketorderbook_test.cpp index f925ade8..b88a5e04 100644 --- a/src/objects/test/marketorderbook_test.cpp +++ b/src/objects/test/marketorderbook_test.cpp @@ -34,10 +34,6 @@ MarketOrderBookLines CreateMarketOrderBookLines(std::initializer_list #include +#include #include "cct_invalid_argument_exception.hpp" #include "timedef.hpp" diff --git a/src/schema/src/exchange-config.cpp b/src/schema/src/exchange-config.cpp index b00776cf..5f35d7d3 100644 --- a/src/schema/src/exchange-config.cpp +++ b/src/schema/src/exchange-config.cpp @@ -1,5 +1,6 @@ #include "exchange-config.hpp" +#include #include #include "cct_const.hpp" diff --git a/src/schema/src/exchange-query-update-frequency-config.cpp b/src/schema/src/exchange-query-update-frequency-config.cpp index 112d55c6..de81b6ed 100644 --- a/src/schema/src/exchange-query-update-frequency-config.cpp +++ b/src/schema/src/exchange-query-update-frequency-config.cpp @@ -15,7 +15,8 @@ void MergeWith(ExchangeQueryUpdateFrequencyConfig &src, ExchangeQueryUpdateFrequ if (desIt == des.end()) { des.insert(des.end(), srcIt, srcEnd); break; - } else if (srcIt == srcEnd) { + } + if (srcIt == srcEnd) { break; } if (desIt->first == srcIt->first) { diff --git a/src/schema/test/exchange-config_test.cpp b/src/schema/test/exchange-config_test.cpp index 4a959b4c..37d38b85 100644 --- a/src/schema/test/exchange-config_test.cpp +++ b/src/schema/test/exchange-config_test.cpp @@ -2,6 +2,7 @@ #include +#include #include #include "cct_const.hpp" diff --git a/src/schema/test/exchange-query-update-frequency-config_test.cpp b/src/schema/test/exchange-query-update-frequency-config_test.cpp index 05330b5b..81dea7ac 100644 --- a/src/schema/test/exchange-query-update-frequency-config_test.cpp +++ b/src/schema/test/exchange-query-update-frequency-config_test.cpp @@ -2,6 +2,11 @@ #include +#include + +#include "apiquerytypeenum.hpp" +#include "duration-schema.hpp" + namespace cct::schema { class ExchangeQueryUpdateFrequencyConfigTest : public ::testing::Test { diff --git a/src/tech/include/cct_json.hpp b/src/tech/include/cct_json.hpp index 36c8a7ac..ba38d4c0 100644 --- a/src/tech/include/cct_json.hpp +++ b/src/tech/include/cct_json.hpp @@ -7,6 +7,8 @@ namespace cct { namespace json { +using glz::colwise; +using glz::CSV; using glz::error_ctx; using glz::format_error; using glz::meta;