From be2cad7715440aa4a357bc876a0c0da2e25108dd Mon Sep 17 00:00:00 2001 From: Stephane Janel Date: Fri, 22 Nov 2024 23:14:34 +0100 Subject: [PATCH] [Upbit] - Fix markets endpoint, some json field is sometimes absent --- src/api/exchanges/src/bithumbprivateapi.cpp | 4 ++-- src/api/exchanges/src/upbitpublicapi.cpp | 25 ++++++++------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/api/exchanges/src/bithumbprivateapi.cpp b/src/api/exchanges/src/bithumbprivateapi.cpp index 03652e7a..98bd9130 100644 --- a/src/api/exchanges/src/bithumbprivateapi.cpp +++ b/src/api/exchanges/src/bithumbprivateapi.cpp @@ -134,10 +134,10 @@ bool LoadCurrencyInfoField(const json::container& currencyOrderInfoJson, std::st } if constexpr (std::is_same_v) { val = MonetaryAmount(valIt->get()); - log::debug("Loaded {} for '{}' from cache file", val.str(), keyStr); + log::trace("Loaded {} for '{}' from cache file", val.str(), keyStr); } else { val = valIt->get(); - log::debug("Loaded {} for '{}' from cache file", val, keyStr); + log::trace("Loaded {} for '{}' from cache file", val, keyStr); } ts = TimePoint(seconds(tsIt->get())); return true; diff --git a/src/api/exchanges/src/upbitpublicapi.cpp b/src/api/exchanges/src/upbitpublicapi.cpp index fcb34ac2..4749841b 100644 --- a/src/api/exchanges/src/upbitpublicapi.cpp +++ b/src/api/exchanges/src/upbitpublicapi.cpp @@ -146,27 +146,20 @@ MarketSet UpbitPublic::MarketsFunc::operator()() { ret.reserve(static_cast(result.size())); for (const json::container& marketDetails : result) { std::string_view marketStr = marketDetails["market"].get(); - std::string_view marketWarningStr = marketDetails["market_warning"].get(); - if (marketWarningStr != "NONE") { - log::debug("Discard Upbit market {} as it has warning {}", marketStr, marketWarningStr); + auto marketWarningIt = marketDetails.find("market_warning"); + if (marketWarningIt != marketDetails.end() && marketWarningIt->get() != "NONE") { + log::error("Discard Upbit market {} as it has no warning", marketStr, marketWarningIt->get()); continue; } // Upbit markets are inverted - std::size_t dashPos = marketStr.find('-'); - if (dashPos == std::string_view::npos) { - log::error("Discard Upbit market {} as unable to parse the currency codes in it", marketStr); - continue; - } - CurrencyCode quote(std::string_view(marketStr.begin(), marketStr.begin() + dashPos)); - if (!CheckCurrencyCode(quote, excludedCurrencies)) { - continue; - } - CurrencyCode base(std::string_view(marketStr.begin() + dashPos + 1, marketStr.end())); - if (!CheckCurrencyCode(base, excludedCurrencies)) { + Market market(marketStr, '-'); + market = market.reverse(); + if (!CheckCurrencyCode(market.base(), excludedCurrencies) || + !CheckCurrencyCode(market.quote(), excludedCurrencies)) { continue; } - auto mkIt = ret.emplace(base, quote).first; - log::debug("Retrieved Upbit market {}", *mkIt); + log::debug("Retrieved Upbit market {}", market); + ret.emplace(std::move(market)); } log::info("Retrieved {} markets from Upbit", ret.size()); return ret;