From 9782f537d96d0885387f7c275827d1589ad8843c Mon Sep 17 00:00:00 2001 From: Stephane Janel Date: Sat, 9 Nov 2024 21:45:43 +0100 Subject: [PATCH] [Code cleaning] - Fix shadow warnings --- cmake/CoincenterUtils.cmake | 6 +- src/api-objects/include/tradeinfo.hpp | 12 ++-- .../exchange-permanent-curl-options.hpp | 2 + src/api/common/include/fiatconverter.hpp | 12 ++-- .../src/exchange-permanent-curl-options.cpp | 1 + src/api/common/src/exchangeprivateapi.cpp | 2 +- src/api/common/src/fiatconverter.cpp | 56 +++++++++---------- .../common/test/exchangeprivateapi_test.cpp | 2 +- src/api/exchanges/src/binanceprivateapi.cpp | 4 +- src/api/exchanges/src/bithumbprivateapi.cpp | 23 ++++---- src/api/exchanges/src/huobiprivateapi.cpp | 4 +- src/api/exchanges/src/huobipublicapi.cpp | 10 ++-- src/api/exchanges/src/krakenprivateapi.cpp | 14 ++--- src/api/exchanges/src/krakenpublicapi.cpp | 6 +- src/api/exchanges/src/kucoinprivateapi.cpp | 4 +- src/api/exchanges/src/kucoinpublicapi.cpp | 6 +- src/api/exchanges/src/upbitprivateapi.cpp | 6 +- src/engine/src/queryresultprinter.cpp | 30 +++++----- .../test/exchangesorchestrator_trade_test.cpp | 1 - src/objects/src/marketorderbook.cpp | 6 +- src/tech/include/cachedresult.hpp | 18 +++--- src/tech/test/threadpool_test.cpp | 2 +- 22 files changed, 113 insertions(+), 114 deletions(-) diff --git a/cmake/CoincenterUtils.cmake b/cmake/CoincenterUtils.cmake index 30b53f07..19932696 100644 --- a/cmake/CoincenterUtils.cmake +++ b/cmake/CoincenterUtils.cmake @@ -16,13 +16,13 @@ function (target_set_coincenter_options name) if(MSVC) target_compile_options(${name} PRIVATE /W3) else() - target_compile_options(${name} PRIVATE -Wall -Wextra -pedantic -Wshadow -Winline) + target_compile_options(${name} PRIVATE -Wall -Wextra -pedantic -Wshadow) endif() else() if(MSVC) - + target_compile_options(${name} PRIVATE /W1) else() - target_compile_options(${name} PRIVATE -Wdisabled-optimization) + target_compile_options(${name} PRIVATE -Wdisabled-optimization -Winline) endif() endif() diff --git a/src/api-objects/include/tradeinfo.hpp b/src/api-objects/include/tradeinfo.hpp index e93289e1..c551127c 100644 --- a/src/api-objects/include/tradeinfo.hpp +++ b/src/api-objects/include/tradeinfo.hpp @@ -14,14 +14,12 @@ namespace cct::api { using UserRefInt = int32_t; struct TradeContext { - TradeContext(Market market, TradeSide s, UserRefInt userRef = 0) : mk(market), side(s), userRef(userRef) {} + CurrencyCode fromCur() const { return side == TradeSide::kSell ? market.base() : market.quote(); } + CurrencyCode toCur() const { return side == TradeSide::kBuy ? market.base() : market.quote(); } - CurrencyCode fromCur() const { return side == TradeSide::kSell ? mk.base() : mk.quote(); } - CurrencyCode toCur() const { return side == TradeSide::kBuy ? mk.base() : mk.quote(); } - - Market mk; - TradeSide side; - UserRefInt userRef; // Used by Kraken for instance, used to group orders queries context + Market market; + TradeSide side{}; + UserRefInt userRef{}; // Used by Kraken for instance, used to group orders queries context }; struct TradeInfo { diff --git a/src/api/common/include/exchange-permanent-curl-options.hpp b/src/api/common/include/exchange-permanent-curl-options.hpp index 0944e996..22c6c4a9 100644 --- a/src/api/common/include/exchange-permanent-curl-options.hpp +++ b/src/api/common/include/exchange-permanent-curl-options.hpp @@ -9,6 +9,7 @@ namespace cct { class ExchangeConfig; namespace api { + class ExchangePermanentCurlOptions { public: explicit ExchangePermanentCurlOptions(const ExchangeConfig &exchangeConfig); @@ -20,6 +21,7 @@ class ExchangePermanentCurlOptions { private: const ExchangeConfig &_exchangeConfig; }; + } // namespace api } // namespace cct \ No newline at end of file diff --git a/src/api/common/include/fiatconverter.hpp b/src/api/common/include/fiatconverter.hpp index dd6a5243..7b16d8c3 100644 --- a/src/api/common/include/fiatconverter.hpp +++ b/src/api/common/include/fiatconverter.hpp @@ -67,16 +67,16 @@ class FiatConverter : public CacheFileUpdatorInterface { TimePoint lastUpdatedTime; }; - std::optional queryCurrencyRate(Market mk); + std::optional queryCurrencyRate(Market market); - std::optional queryCurrencyRateSource1(Market mk); - std::optional queryCurrencyRateSource2(Market mk); + std::optional queryCurrencyRateSource1(Market market); + std::optional queryCurrencyRateSource2(Market market); - std::optional retrieveRateFromCache(Market mk) const; + std::optional retrieveRateFromCache(Market market) const; - void store(Market mk, double rate); + void store(Market market, double rate); - void refreshLastUpdatedTime(Market mk); + void refreshLastUpdatedTime(Market market); using PricesMap = std::unordered_map; diff --git a/src/api/common/src/exchange-permanent-curl-options.cpp b/src/api/common/src/exchange-permanent-curl-options.cpp index 0ff74c29..b7351825 100644 --- a/src/api/common/src/exchange-permanent-curl-options.cpp +++ b/src/api/common/src/exchange-permanent-curl-options.cpp @@ -1,6 +1,7 @@ #include "exchange-permanent-curl-options.hpp" #include "exchangeconfig.hpp" +#include "permanentcurloptions.hpp" namespace cct::api { diff --git a/src/api/common/src/exchangeprivateapi.cpp b/src/api/common/src/exchangeprivateapi.cpp index 66bc2b21..bae4b54d 100644 --- a/src/api/common/src/exchangeprivateapi.cpp +++ b/src/api/common/src/exchangeprivateapi.cpp @@ -551,7 +551,7 @@ TradedAmountsVectorWithFinalAmount ExchangePrivate::queryDustSweeper(CurrencyCod PlaceOrderInfo ExchangePrivate::placeOrderProcess(MonetaryAmount &from, MonetaryAmount price, const TradeInfo &tradeInfo) { - const Market mk = tradeInfo.tradeContext.mk; + const Market mk = tradeInfo.tradeContext.market; const bool isSell = tradeInfo.tradeContext.side == TradeSide::kSell; const MonetaryAmount volume(isSell ? from : MonetaryAmount(from / price, mk.base())); diff --git a/src/api/common/src/fiatconverter.cpp b/src/api/common/src/fiatconverter.cpp index 694690e1..cbb92d1f 100644 --- a/src/api/common/src/fiatconverter.cpp +++ b/src/api/common/src/fiatconverter.cpp @@ -89,17 +89,17 @@ void FiatConverter::updateCacheFile() const { GetRatesCacheFile(_dataDir).writeJson(data); } -std::optional FiatConverter::queryCurrencyRate(Market mk) { - auto ret = queryCurrencyRateSource1(mk); +std::optional FiatConverter::queryCurrencyRate(Market market) { + auto ret = queryCurrencyRateSource1(market); if (ret) { return ret; } - ret = queryCurrencyRateSource2(mk); + ret = queryCurrencyRateSource2(market); return ret; } -std::optional FiatConverter::queryCurrencyRateSource1(Market mk) { - const auto qStr = mk.assetsPairStrUpper('_'); +std::optional FiatConverter::queryCurrencyRateSource1(Market market) { + const auto qStr = market.assetsPairStrUpper('_'); const CurlOptions opts(HttpRequestType::kGet, {{"q", qStr}, {"apiKey", _apiKey}}); @@ -111,17 +111,17 @@ std::optional FiatConverter::queryCurrencyRateSource1(Market mk) { //{"query":{"count":1},"results":{"EUR_KRW":{"id":"EUR_KRW","val":1329.475323,"to":"KRW","fr":"EUR"}}} const auto resultsIt = data.find("results"); if (data.is_discarded() || resultsIt == data.end() || !resultsIt->contains(qStr)) { - log::warn("No JSON data received from fiat currency converter service's first source for pair '{}'", mk); - refreshLastUpdatedTime(mk); + log::warn("No JSON data received from fiat currency converter service's first source for pair '{}'", market); + refreshLastUpdatedTime(market); return std::nullopt; } const auto& rates = (*resultsIt)[qStr]; const double rate = rates["val"]; - store(mk, rate); + store(market, rate); return rate; } -std::optional FiatConverter::queryCurrencyRateSource2(Market mk) { +std::optional FiatConverter::queryCurrencyRateSource2(Market market) { const auto dataStr = _curlHandle2.query("", CurlOptions(HttpRequestType::kGet)); static constexpr bool kAllowExceptions = false; const json::container jsonData = json::container::parse(dataStr, nullptr, kAllowExceptions); @@ -132,7 +132,7 @@ std::optional FiatConverter::queryCurrencyRateSource2(Market mk) { const auto baseIt = jsonData.find("base"); const auto ratesIt = jsonData.find("rates"); if (baseIt == jsonData.end() || ratesIt == jsonData.end()) { - log::warn("No JSON data received from fiat currency converter service's second source", mk); + log::warn("No JSON data received from fiat currency converter service's second source", market); return {}; } @@ -145,25 +145,25 @@ std::optional FiatConverter::queryCurrencyRateSource2(Market mk) { _pricesMap.insert_or_assign(Market(_baseRateSource2, currencyCode), PriceTimedValue(rateDouble, nowTime)); } - return retrieveRateFromCache(mk); + return retrieveRateFromCache(market); } -void FiatConverter::store(Market mk, double rate) { - log::debug("Stored rate {} for {}", rate, mk); +void FiatConverter::store(Market market, double rate) { + log::debug("Stored rate {} for {}", rate, market); const TimePoint nowTime = Clock::now(); - _pricesMap.insert_or_assign(mk.reverse(), PriceTimedValue(static_cast(1) / rate, nowTime)); - _pricesMap.insert_or_assign(std::move(mk), PriceTimedValue(rate, nowTime)); + _pricesMap.insert_or_assign(market.reverse(), PriceTimedValue(static_cast(1) / rate, nowTime)); + _pricesMap.insert_or_assign(std::move(market), PriceTimedValue(rate, nowTime)); } -void FiatConverter::refreshLastUpdatedTime(Market mk) { - const auto it = _pricesMap.find(mk); +void FiatConverter::refreshLastUpdatedTime(Market market) { + const auto it = _pricesMap.find(market); if (it != _pricesMap.end()) { // Update cache time anyway to avoid querying too much the service const TimePoint nowTime = Clock::now(); it->second.lastUpdatedTime = nowTime; - _pricesMap[mk.reverse()].lastUpdatedTime = nowTime; + _pricesMap[market.reverse()].lastUpdatedTime = nowTime; } } @@ -171,27 +171,27 @@ std::optional FiatConverter::convert(double amount, CurrencyCode from, C if (from == to) { return amount; } - const Market mk(from, to); + const Market market(from, to); double rate; std::lock_guard guard(_pricesMutex); - const auto optRate = retrieveRateFromCache(mk); + const auto optRate = retrieveRateFromCache(market); if (optRate) { rate = *optRate; } else { if (_ratesUpdateFrequency == Duration::max()) { - log::error("Unable to query fiat currency rates and no rate found in cache for {}", mk); + log::error("Unable to query fiat currency rates and no rate found in cache for {}", market); return {}; } - std::optional queriedRate = queryCurrencyRate(mk); + std::optional queriedRate = queryCurrencyRate(market); if (queriedRate) { rate = *queriedRate; } else { - const auto it = _pricesMap.find(mk); + const auto it = _pricesMap.find(market); if (it == _pricesMap.end()) { - log::error("Unable to query fiat currency rates and no rate found in cache for {}", mk); + log::error("Unable to query fiat currency rates and no rate found in cache for {}", market); return {}; } log::warn("Fiat currency rate service unavailable, use not up to date currency rate in cache"); @@ -202,7 +202,7 @@ std::optional FiatConverter::convert(double amount, CurrencyCode from, C return amount * rate; } -std::optional FiatConverter::retrieveRateFromCache(Market mk) const { +std::optional FiatConverter::retrieveRateFromCache(Market market) const { const auto rateIfYoung = [this, nowTime = Clock::now()](Market mk) -> std::optional { const auto it = _pricesMap.find(mk); if (it != _pricesMap.end() && nowTime - it->second.lastUpdatedTime < _ratesUpdateFrequency) { @@ -210,15 +210,15 @@ std::optional FiatConverter::retrieveRateFromCache(Market mk) const { } return {}; }; - const auto directRate = rateIfYoung(mk); + const auto directRate = rateIfYoung(market); if (directRate) { return directRate; } if (_baseRateSource2.isDefined()) { // Try with dual rates from base source. - const auto rateBase1 = rateIfYoung(Market(_baseRateSource2, mk.base())); + const auto rateBase1 = rateIfYoung(Market(_baseRateSource2, market.base())); if (rateBase1) { - const auto rateBase2 = rateIfYoung(Market(_baseRateSource2, mk.quote())); + const auto rateBase2 = rateIfYoung(Market(_baseRateSource2, market.quote())); if (rateBase2) { return *rateBase2 / *rateBase1; } diff --git a/src/api/common/test/exchangeprivateapi_test.cpp b/src/api/common/test/exchangeprivateapi_test.cpp index 655c5b6f..49b9d45b 100644 --- a/src/api/common/test/exchangeprivateapi_test.cpp +++ b/src/api/common/test/exchangeprivateapi_test.cpp @@ -68,7 +68,7 @@ namespace cct::api { static inline bool operator==(const TradeContext &lhs, const TradeContext &rhs) { // We don't compare on value userRef which is set from a timestamp - return lhs.mk == rhs.mk && lhs.side == rhs.side; + return lhs.market == rhs.market && lhs.side == rhs.side; } static inline bool operator==(const TradeInfo &lhs, const TradeInfo &rhs) { diff --git a/src/api/exchanges/src/binanceprivateapi.cpp b/src/api/exchanges/src/binanceprivateapi.cpp index 8b941578..ee5be48c 100644 --- a/src/api/exchanges/src/binanceprivateapi.cpp +++ b/src/api/exchanges/src/binanceprivateapi.cpp @@ -672,7 +672,7 @@ PlaceOrderInfo BinancePrivate::placeOrder(MonetaryAmount from, MonetaryAmount vo BinancePublic& binancePublic = dynamic_cast(_exchangePublic); const CurrencyCode fromCurrencyCode(tradeInfo.tradeContext.fromCur()); const CurrencyCode toCurrencyCode(tradeInfo.tradeContext.toCur()); - const Market mk = tradeInfo.tradeContext.mk; + const Market mk = tradeInfo.tradeContext.market; const std::string_view buyOrSell = fromCurrencyCode == mk.base() ? "SELL" : "BUY"; const bool placeSimulatedRealOrder = binancePublic.exchangeConfig().placeSimulateRealOrder(); const bool isTakerStrategy = tradeInfo.options.isTakerStrategy(placeSimulatedRealOrder); @@ -743,7 +743,7 @@ PlaceOrderInfo BinancePrivate::placeOrder(MonetaryAmount from, MonetaryAmount vo OrderInfo BinancePrivate::queryOrder(OrderIdView orderId, const TradeContext& tradeContext, HttpRequestType requestType) { - const Market mk = tradeContext.mk; + const Market mk = tradeContext.market; const CurrencyCode fromCurrencyCode = tradeContext.side == TradeSide::kSell ? mk.base() : mk.quote(); const CurrencyCode toCurrencyCode = tradeContext.side == TradeSide::kBuy ? mk.base() : mk.quote(); const string assetsStr = mk.assetsPairStrUpper(); diff --git a/src/api/exchanges/src/bithumbprivateapi.cpp b/src/api/exchanges/src/bithumbprivateapi.cpp index bd019166..c92ced3f 100644 --- a/src/api/exchanges/src/bithumbprivateapi.cpp +++ b/src/api/exchanges/src/bithumbprivateapi.cpp @@ -265,22 +265,22 @@ json::container PrivateQueryProcessWithRetries(CurlHandle& curlHandle, const API json::container ret = requestRetry.queryJson( endpoint, - [endpoint](json::container& ret) { - const auto errorCode = BithumbPublic::StatusCodeFromJsonResponse(ret); + [endpoint](json::container& jsonResponse) { + const auto errorCode = BithumbPublic::StatusCodeFromJsonResponse(jsonResponse); if (errorCode == 0 || errorCode == BithumbPublic::kStatusNotPresentError) { return RequestRetry::Status::kResponseOK; } std::string_view msg; - auto messageIt = ret.find("message"); - if (messageIt != ret.end()) { + auto messageIt = jsonResponse.find("message"); + if (messageIt != jsonResponse.end()) { msg = messageIt->get(); switch (errorCode) { case kBadRequestErrorCode: CheckAndLogSynchronizedTime(msg); break; case kOrderRelatedErrorCode: - if (CheckOrderErrors(endpoint, msg, ret)) { + if (CheckOrderErrors(endpoint, msg, jsonResponse)) { return RequestRetry::Status::kResponseOK; } break; @@ -290,12 +290,11 @@ json::container PrivateQueryProcessWithRetries(CurlHandle& curlHandle, const API } return RequestRetry::Status::kResponseError; }, - [endpoint, &apiKey](CurlOptions& opts) { - auto [strData, nonce] = GetStrData(endpoint, opts.postData().str()); - + [endpoint, &apiKey](CurlOptions& curlOptions) { + auto [strData, nonce] = GetStrData(endpoint, curlOptions.postData().str()); auto signature = B64Encode(ssl::Sha512Hex(strData, apiKey.privateKey())); - SetHttpHeaders(opts, apiKey, signature, nonce); + SetHttpHeaders(curlOptions, apiKey, signature, nonce); }); return ret; @@ -851,7 +850,7 @@ PlaceOrderInfo BithumbPrivate::placeOrder(MonetaryAmount /*from*/, MonetaryAmoun const CurrencyCode toCurrencyCode(tradeInfo.tradeContext.toCur()); PlaceOrderInfo placeOrderInfo(OrderInfo(TradedAmounts(fromCurrencyCode, toCurrencyCode)), OrderId("UndefinedId")); - const Market mk = tradeInfo.tradeContext.mk; + const Market mk = tradeInfo.tradeContext.market; // It seems Bithumb uses "standard" currency codes, no need to translate them CurlPostData placePostData{{kOrderCurrencyParamStr, mk.base().str()}, {kPaymentCurParamStr, mk.quote().str()}}; @@ -1041,14 +1040,14 @@ CurlPostData OrderInfoPostData(Market mk, TradeSide side, OrderIdView orderId) { void BithumbPrivate::cancelOrderProcess(OrderIdView orderId, const TradeContext& tradeContext) { json::container ret = PrivateQuery(_curlHandle, _apiKey, "/trade/cancel", - OrderInfoPostData(tradeContext.mk, tradeContext.side, orderId)); + OrderInfoPostData(tradeContext.market, tradeContext.side, orderId)); if (ret.is_discarded()) { log::error("Cancel order process failed for {}, assuming order cancelled", exchangeName()); } } OrderInfo BithumbPrivate::queryOrderInfo(OrderIdView orderId, const TradeContext& tradeContext) { - const Market mk = tradeContext.mk; + const Market mk = tradeContext.market; const CurrencyCode fromCurrencyCode = tradeContext.fromCur(); const CurrencyCode toCurrencyCode = tradeContext.toCur(); diff --git a/src/api/exchanges/src/huobiprivateapi.cpp b/src/api/exchanges/src/huobiprivateapi.cpp index f5ab8ec9..2b80219d 100644 --- a/src/api/exchanges/src/huobiprivateapi.cpp +++ b/src/api/exchanges/src/huobiprivateapi.cpp @@ -604,7 +604,7 @@ PlaceOrderInfo HuobiPrivate::placeOrder(MonetaryAmount from, MonetaryAmount volu PlaceOrderInfo placeOrderInfo(OrderInfo(TradedAmounts(fromCurrencyCode, toCurrencyCode)), OrderId("UndefinedId")); - const Market mk = tradeInfo.tradeContext.mk; + const Market mk = tradeInfo.tradeContext.market; string lowerCaseMarket = mk.assetsPairStrLower(); const bool placeSimulatedRealOrder = _exchangePublic.exchangeConfig().placeSimulateRealOrder(); @@ -672,7 +672,7 @@ OrderInfo HuobiPrivate::cancelOrder(OrderIdView orderId, const TradeContext& tra OrderInfo HuobiPrivate::queryOrderInfo(OrderIdView orderId, const TradeContext& tradeContext) { const CurrencyCode fromCurrencyCode = tradeContext.fromCur(); const CurrencyCode toCurrencyCode = tradeContext.toCur(); - const Market mk = tradeContext.mk; + const Market mk = tradeContext.market; string endpoint(kBaseUrlOrders); endpoint.append(orderId); diff --git a/src/api/exchanges/src/huobipublicapi.cpp b/src/api/exchanges/src/huobipublicapi.cpp index f1da6dde..2fff5c0c 100644 --- a/src/api/exchanges/src/huobipublicapi.cpp +++ b/src/api/exchanges/src/huobipublicapi.cpp @@ -57,7 +57,7 @@ json::container PublicQuery(CurlHandle& curlHandle, std::string_view endpoint, RequestRetry requestRetry(curlHandle, CurlOptions(HttpRequestType::kGet)); - json::container jsonResponse = requestRetry.queryJson(method, [](const json::container& jsonResponse) { + json::container baseRet = requestRetry.queryJson(method, [](const json::container& jsonResponse) { const auto dataIt = jsonResponse.find("data"); if (dataIt == jsonResponse.end()) { const auto tickIt = jsonResponse.find("tick"); @@ -69,12 +69,12 @@ json::container PublicQuery(CurlHandle& curlHandle, std::string_view endpoint, return RequestRetry::Status::kResponseOK; }); json::container ret; - const auto dataIt = jsonResponse.find("data"); - if (dataIt != jsonResponse.end()) { + const auto dataIt = baseRet.find("data"); + if (dataIt != baseRet.end()) { ret.swap(*dataIt); } else { - const auto tickIt = jsonResponse.find("tick"); - if (tickIt != jsonResponse.end()) { + const auto tickIt = baseRet.find("tick"); + if (tickIt != baseRet.end()) { ret.swap(*tickIt); } } diff --git a/src/api/exchanges/src/krakenprivateapi.cpp b/src/api/exchanges/src/krakenprivateapi.cpp index 4492d2b2..833b78ed 100644 --- a/src/api/exchanges/src/krakenprivateapi.cpp +++ b/src/api/exchanges/src/krakenprivateapi.cpp @@ -99,12 +99,12 @@ auto PrivateQuery(CurlHandle& curlHandle, const APIKey& apiKey, std::string_view } return RequestRetry::Status::kResponseOK; }, - [&apiKey, method](CurlOptions& opts) { + [&apiKey, method](CurlOptions& curlOptions) { Nonce noncePostData = Nonce_TimeSinceEpochInMs(); - opts.mutablePostData().set("nonce", noncePostData); + curlOptions.mutablePostData().set("nonce", noncePostData); // concatenate nonce and postdata and compute SHA256 - noncePostData.append(opts.postData().str()); + noncePostData.append(curlOptions.postData().str()); // concatenate path and nonce_postdata (path + ComputeSha256(nonce + postdata)) auto sha256 = ssl::Sha256(noncePostData); @@ -116,8 +116,8 @@ auto PrivateQuery(CurlHandle& curlHandle, const APIKey& apiKey, std::string_view static constexpr std::string_view kSignatureKey = "API-Sign"; // and compute HMAC - opts.mutableHttpHeaders().set_back(kSignatureKey, - B64Encode(ssl::Sha512Bin(path, B64Decode(apiKey.privateKey())))); + curlOptions.mutableHttpHeaders().set_back(kSignatureKey, + B64Encode(ssl::Sha512Bin(path, B64Decode(apiKey.privateKey())))); }); auto resultIt = ret.find("result"); @@ -533,7 +533,7 @@ PlaceOrderInfo KrakenPrivate::placeOrder([[maybe_unused]] MonetaryAmount from, M const bool isTakerStrategy = tradeInfo.options.isTakerStrategy(_exchangePublic.exchangeConfig().placeSimulateRealOrder()); const bool isSimulation = tradeInfo.options.isSimulation(); - const Market mk = tradeInfo.tradeContext.mk; + const Market mk = tradeInfo.tradeContext.market; KrakenPublic& krakenPublic = dynamic_cast(_exchangePublic); const MonetaryAmount orderMin = krakenPublic.queryVolumeOrderMin(mk); CurrencyExchange krakenCurrencyBase = _exchangePublic.convertStdCurrencyToCurrencyExchange(mk.base()); @@ -622,7 +622,7 @@ void KrakenPrivate::cancelOrderProcess(OrderIdView orderId) { OrderInfo KrakenPrivate::queryOrderInfo(OrderIdView orderId, const TradeContext& tradeContext, QueryOrder queryOrder) { const CurrencyCode fromCurrencyCode = tradeContext.fromCur(); const CurrencyCode toCurrencyCode = tradeContext.toCur(); - const Market mk = tradeContext.mk; + const Market mk = tradeContext.market; json::container ordersRes = queryOrdersData(tradeContext.userRef, orderId, queryOrder); auto openIt = ordersRes.find("open"); diff --git a/src/api/exchanges/src/krakenpublicapi.cpp b/src/api/exchanges/src/krakenpublicapi.cpp index 3bb7a02a..f301dde2 100644 --- a/src/api/exchanges/src/krakenpublicapi.cpp +++ b/src/api/exchanges/src/krakenpublicapi.cpp @@ -42,7 +42,7 @@ namespace { json::container PublicQuery(CurlHandle& curlHandle, std::string_view method, CurlPostData&& postData = CurlPostData()) { RequestRetry requestRetry(curlHandle, CurlOptions(HttpRequestType::kGet, std::move(postData))); - json::container jsonResponse = requestRetry.queryJson(method, [](const json::container& jsonResponse) { + json::container baseRet = requestRetry.queryJson(method, [](const json::container& jsonResponse) { const auto errorIt = jsonResponse.find("error"); if (errorIt != jsonResponse.end() && !errorIt->empty()) { log::warn("Full Kraken error: '{}'", jsonResponse.dump()); @@ -51,9 +51,9 @@ json::container PublicQuery(CurlHandle& curlHandle, std::string_view method, Cur return RequestRetry::Status::kResponseOK; }); - const auto resultIt = jsonResponse.find("result"); + const auto resultIt = baseRet.find("result"); json::container ret; - if (resultIt != jsonResponse.end()) { + if (resultIt != baseRet.end()) { ret.swap(*resultIt); } return ret; diff --git a/src/api/exchanges/src/kucoinprivateapi.cpp b/src/api/exchanges/src/kucoinprivateapi.cpp index 927a40bb..04c05b01 100644 --- a/src/api/exchanges/src/kucoinprivateapi.cpp +++ b/src/api/exchanges/src/kucoinprivateapi.cpp @@ -484,7 +484,7 @@ PlaceOrderInfo KucoinPrivate::placeOrder(MonetaryAmount from, MonetaryAmount vol return placeOrderInfo; } - const Market mk = tradeInfo.tradeContext.mk; + const Market mk = tradeInfo.tradeContext.market; bool isTakerStrategy = tradeInfo.options.isTakerStrategy(_exchangePublic.exchangeConfig().placeSimulateRealOrder()); @@ -539,7 +539,7 @@ void KucoinPrivate::cancelOrderProcess(OrderIdView orderId) { OrderInfo KucoinPrivate::queryOrderInfo(OrderIdView orderId, const TradeContext& tradeContext) { const CurrencyCode fromCurrencyCode(tradeContext.fromCur()); - const Market mk = tradeContext.mk; + const Market mk = tradeContext.market; string endpoint("/api/v1/orders/"); endpoint.append(orderId); diff --git a/src/api/exchanges/src/kucoinpublicapi.cpp b/src/api/exchanges/src/kucoinpublicapi.cpp index 5ad0c598..912f242c 100644 --- a/src/api/exchanges/src/kucoinpublicapi.cpp +++ b/src/api/exchanges/src/kucoinpublicapi.cpp @@ -49,7 +49,7 @@ json::container PublicQuery(CurlHandle& curlHandle, std::string_view endpoint, const CurlPostData& curlPostData = CurlPostData()) { RequestRetry requestRetry(curlHandle, CurlOptions(HttpRequestType::kGet, curlPostData)); - json::container jsonResponse = requestRetry.queryJson(endpoint, [](const json::container& jsonResponse) { + json::container baseRet = requestRetry.queryJson(endpoint, [](const json::container& jsonResponse) { const auto errorIt = jsonResponse.find("code"); if (errorIt != jsonResponse.end() && errorIt->get() != "200000") { log::warn("Full Kucoin error ({}): '{}'", errorIt->get(), jsonResponse.dump()); @@ -58,8 +58,8 @@ json::container PublicQuery(CurlHandle& curlHandle, std::string_view endpoint, return RequestRetry::Status::kResponseOK; }); json::container ret; - const auto dataIt = jsonResponse.find("data"); - if (dataIt != jsonResponse.end()) { + const auto dataIt = baseRet.find("data"); + if (dataIt != baseRet.end()) { ret.swap(*dataIt); } return ret; diff --git a/src/api/exchanges/src/upbitprivateapi.cpp b/src/api/exchanges/src/upbitprivateapi.cpp index f0aaada0..b8d46b93 100644 --- a/src/api/exchanges/src/upbitprivateapi.cpp +++ b/src/api/exchanges/src/upbitprivateapi.cpp @@ -571,7 +571,7 @@ PlaceOrderInfo UpbitPrivate::placeOrder(MonetaryAmount from, MonetaryAmount volu const CurrencyCode toCurrencyCode(tradeInfo.tradeContext.toCur()); const bool placeSimulatedRealOrder = _exchangePublic.exchangeConfig().placeSimulateRealOrder(); const bool isTakerStrategy = tradeInfo.options.isTakerStrategy(placeSimulatedRealOrder); - const Market mk = tradeInfo.tradeContext.mk; + const Market mk = tradeInfo.tradeContext.market; const std::string_view askOrBid = fromCurrencyCode == mk.base() ? "ask" : "bid"; const std::string_view marketOrPrice = fromCurrencyCode == mk.base() ? "market" : "price"; @@ -634,14 +634,14 @@ OrderInfo UpbitPrivate::cancelOrder(OrderIdView orderId, const TradeContext& tra orderRes = PrivateQuery(_curlHandle, _apiKey, HttpRequestType::kGet, "/v1/order", postData); cancelledOrderClosed = IsOrderClosed(orderRes); } - return ParseOrderJson(orderRes, tradeContext.fromCur(), tradeContext.mk); + return ParseOrderJson(orderRes, tradeContext.fromCur(), tradeContext.market); } OrderInfo UpbitPrivate::queryOrderInfo(OrderIdView orderId, const TradeContext& tradeContext) { json::container orderRes = PrivateQuery(_curlHandle, _apiKey, HttpRequestType::kGet, "/v1/order", {{"uuid", orderId}}); const CurrencyCode fromCurrencyCode(tradeContext.fromCur()); - return ParseOrderJson(orderRes, fromCurrencyCode, tradeContext.mk); + return ParseOrderJson(orderRes, fromCurrencyCode, tradeContext.market); } std::optional UpbitPrivate::WithdrawFeesFunc::operator()(CurrencyCode currencyCode) { diff --git a/src/engine/src/queryresultprinter.cpp b/src/engine/src/queryresultprinter.cpp index bfd11cf5..86e37a9a 100644 --- a/src/engine/src/queryresultprinter.cpp +++ b/src/engine/src/queryresultprinter.cpp @@ -779,11 +779,14 @@ json::container MarketTradingResultsJson(TimeWindow inputTimeWindow, const Repla CoincenterCommandType commandType) { json::container inOpt; - json::container timeStats; - timeStats.emplace("from", TimeToString(inputTimeWindow.from())); - timeStats.emplace("to", TimeToString(inputTimeWindow.to())); + const auto createTimeStats = [](TimeWindow timeWindow) { + json::container ret; + ret.emplace("from", TimeToString(timeWindow.from())); + ret.emplace("to", TimeToString(timeWindow.to())); + return ret; + }; - inOpt.emplace("time", std::move(timeStats)); + inOpt.emplace("time", createTimeStats(inputTimeWindow)); json::container in; in.emplace("opt", std::move(inOpt)); @@ -798,18 +801,15 @@ json::container MarketTradingResultsJson(TimeWindow inputTimeWindow, const Repla const auto &marketTradingResult = marketGlobalTradingResult.result; const auto &stats = marketGlobalTradingResult.stats; - const auto computeTradeRangeResultsStats = [](const TradeRangeResultsStats &tradeRangeResultsStats) { - json::container stats; - stats.emplace("nb-successful", tradeRangeResultsStats.nbSuccessful); - stats.emplace("nb-error", tradeRangeResultsStats.nbError); + const auto computeTradeRangeResultsStats = + [&createTimeStats](const TradeRangeResultsStats &tradeRangeResultsStats) { + json::container ret; + ret.emplace("nb-successful", tradeRangeResultsStats.nbSuccessful); + ret.emplace("nb-error", tradeRangeResultsStats.nbError); - json::container timeStats; - timeStats.emplace("from", TimeToString(tradeRangeResultsStats.timeWindow.from())); - timeStats.emplace("to", TimeToString(tradeRangeResultsStats.timeWindow.to())); - - stats.emplace("time", std::move(timeStats)); - return stats; - }; + ret.emplace("time", createTimeStats(tradeRangeResultsStats.timeWindow)); + return ret; + }; json::container startAmounts; startAmounts.emplace("base", marketTradingResult.startBaseAmount().str()); diff --git a/src/engine/test/exchangesorchestrator_trade_test.cpp b/src/engine/test/exchangesorchestrator_trade_test.cpp index 72b1d431..cd47785b 100644 --- a/src/engine/test/exchangesorchestrator_trade_test.cpp +++ b/src/engine/test/exchangesorchestrator_trade_test.cpp @@ -246,7 +246,6 @@ class ExchangeOrchestratorTradeTest : public ExchangeOrchestratorTest { MonetaryAmount askPri2 = side == TradeSide::kBuy ? pri2 : pri2 + deltaPri2; MonetaryAmount bidPri1 = side == TradeSide::kSell ? pri1 : pri1 - deltaPri1; MonetaryAmount bidPri2 = side == TradeSide::kSell ? pri2 : pri2 - deltaPri2; - TimePoint time; MarketOrderBook marketOrderbook1{ time, askPri1, maxVol1, bidPri1, maxVol1, volAndPriDec1, MarketOrderBook::kDefaultDepth}; MarketOrderBook marketOrderbook2{ diff --git a/src/objects/src/marketorderbook.cpp b/src/objects/src/marketorderbook.cpp index b4fd14fa..8bdc6959 100644 --- a/src/objects/src/marketorderbook.cpp +++ b/src/objects/src/marketorderbook.cpp @@ -482,12 +482,12 @@ MarketOrderBook::AmountPerPriceVec MarketOrderBook::computeMatchedParts(TradeSid } AmountType integralTotalAmount = *integralTotalAmountOpt; const auto countAmount = [volumeNbDecimals, &ret, &integralTotalAmount, cur = amount.currencyCode()]( - MonetaryAmount price, const AmountType intAmount) { + MonetaryAmount linePrice, const AmountType intAmount) { if (intAmount < integralTotalAmount) { - ret.emplace_back(MonetaryAmount(intAmount, cur, volumeNbDecimals), price); + ret.emplace_back(MonetaryAmount(intAmount, cur, volumeNbDecimals), linePrice); integralTotalAmount -= intAmount; } else { - ret.emplace_back(MonetaryAmount(integralTotalAmount, cur, volumeNbDecimals), price); + ret.emplace_back(MonetaryAmount(integralTotalAmount, cur, volumeNbDecimals), linePrice); integralTotalAmount = 0; } }; diff --git a/src/tech/include/cachedresult.hpp b/src/tech/include/cachedresult.hpp index add13030..fdd0bfed 100644 --- a/src/tech/include/cachedresult.hpp +++ b/src/tech/include/cachedresult.hpp @@ -54,14 +54,14 @@ class CachedResultWithArgs : public CachedResultBase struct Value { template - Value(R &&result, TimePoint lastUpdatedTs) : result(std::forward(result)), lastUpdatedTs(lastUpdatedTs) {} + Value(R &&result, TimePoint lastUpdatedTs) : _result(std::forward(result)), _lastUpdatedTs(lastUpdatedTs) {} template Value(F &func, K &&key, TimePoint lastUpdatedTs) - : result(std::apply(func, std::forward(key))), lastUpdatedTs(lastUpdatedTs) {} + : _result(std::apply(func, std::forward(key))), _lastUpdatedTs(lastUpdatedTs) {} - ResultType result; - TimePoint lastUpdatedTs; + ResultType _result; + TimePoint _lastUpdatedTs; }; public: @@ -90,7 +90,7 @@ class CachedResultWithArgs : public CachedResultBase auto [it, isInserted] = _data.try_emplace(TKey(std::forward(funcArgs)...), std::forward(val), timePoint); - if (!isInserted && it->second.lastUpdatedTs < timePoint) { + if (!isInserted && it->second._lastUpdatedTs < timePoint) { it->second = Value(std::forward(val), timePoint); } } @@ -114,10 +114,10 @@ class CachedResultWithArgs : public CachedResultBase auto [it, isInserted] = _data.try_emplace(key, flattenTuple, key, nowTime); if (!isInserted && this->_state != State::kForceCache && // less or equal to make sure value is always refreshed for a zero refresh period - this->_refreshPeriod <= nowTime - it->second.lastUpdatedTs) { + this->_refreshPeriod <= nowTime - it->second._lastUpdatedTs) { it->second = Value(flattenTuple, std::move(key), nowTime); } - return it->second.result; + return it->second._result; } /// Retrieve a {pointer, lastUpdateTime} to latest value associated to the key built with given parameters. @@ -128,7 +128,7 @@ class CachedResultWithArgs : public CachedResultBase if (it == _data.end()) { return {}; } - return {std::addressof(it->second.result), it->second.lastUpdatedTs}; + return {std::addressof(it->second._result), it->second._lastUpdatedTs}; } private: @@ -142,7 +142,7 @@ class CachedResultWithArgs : public CachedResultBase const auto nowTime = ClockT::now(); for (auto it = _data.begin(); it != _data.end();) { - if (this->_refreshPeriod < nowTime - it->second.lastUpdatedTs) { + if (this->_refreshPeriod < nowTime - it->second._lastUpdatedTs) { // Data has expired, remove it it = _data.erase(it); } else { diff --git a/src/tech/test/threadpool_test.cpp b/src/tech/test/threadpool_test.cpp index 0a91aa64..15b2963a 100644 --- a/src/tech/test/threadpool_test.cpp +++ b/src/tech/test/threadpool_test.cpp @@ -31,7 +31,7 @@ int SlowAdd(const int &lhs, const int &rhs) { } struct NonCopyable { - NonCopyable(int val = 0) : val(val) {} + NonCopyable(int value = 0) : val(value) {} NonCopyable(const NonCopyable &) = delete; NonCopyable(NonCopyable &&) = default;