Skip to content

Commit

Permalink
[Upbit] - Fix markets endpoint, some json field is sometimes absent
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Nov 22, 2024
1 parent 1d25e51 commit be2cad7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/api/exchanges/src/bithumbprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ bool LoadCurrencyInfoField(const json::container& currencyOrderInfoJson, std::st
}
if constexpr (std::is_same_v<ValueType, MonetaryAmount>) {
val = MonetaryAmount(valIt->get<std::string_view>());
log::debug("Loaded {} for '{}' from cache file", val.str(), keyStr);
log::trace("Loaded {} for '{}' from cache file", val.str(), keyStr);
} else {
val = valIt->get<ValueType>();
log::debug("Loaded {} for '{}' from cache file", val, keyStr);
log::trace("Loaded {} for '{}' from cache file", val, keyStr);
}
ts = TimePoint(seconds(tsIt->get<int64_t>()));
return true;
Expand Down
25 changes: 9 additions & 16 deletions src/api/exchanges/src/upbitpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,20 @@ MarketSet UpbitPublic::MarketsFunc::operator()() {
ret.reserve(static_cast<MarketSet::size_type>(result.size()));
for (const json::container& marketDetails : result) {
std::string_view marketStr = marketDetails["market"].get<std::string_view>();
std::string_view marketWarningStr = marketDetails["market_warning"].get<std::string_view>();
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<std::string_view>() != "NONE") {
log::error("Discard Upbit market {} as it has no warning", marketStr, marketWarningIt->get<std::string_view>());
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;
Expand Down

0 comments on commit be2cad7

Please sign in to comment.