Skip to content

Commit

Permalink
Avoid useless warning log of too many digits truncating integral part…
Browse files Browse the repository at this point in the history
… from Huobi market info creation
  • Loading branch information
sjanel committed Oct 24, 2022
1 parent 0bf4357 commit d6637ee
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/api/exchanges/include/huobipublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class HuobiPublic : public ExchangePublic {
VolAndPriNbDecimals volAndPriNbDecimals;

MonetaryAmount minOrderValue;
MonetaryAmount maxOrderValueUSDT{std::numeric_limits<MonetaryAmount::AmountType>::max(), "USDT"};
MonetaryAmount maxOrderValueUSDT;

MonetaryAmount limitMinOrderAmount;
MonetaryAmount limitMaxOrderAmount;
Expand Down
17 changes: 9 additions & 8 deletions src/api/exchanges/src/huobipublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,22 @@ std::pair<MarketSet, HuobiPublic::MarketsFunc::MarketInfoMap> HuobiPublic::Marke

marketInfo.volAndPriNbDecimals = VolAndPriNbDecimals(volNbDec, priNbDec);

marketInfo.minOrderValue = MonetaryAmount(marketDetails["min-order-value"].get<double>(), m.quote());
if (marketDetails.contains("max-order-value")) { // in USDT
marketInfo.maxOrderValueUSDT = MonetaryAmount(marketDetails["max-order-value"].get<double>(), "USDT");
marketInfo.minOrderValue = MonetaryAmount(marketDetails["min-order-value"].get<double>(), quote);
auto maxOrderValueIt = marketDetails.find("max-order-value");
if (maxOrderValueIt != marketDetails.end()) { // in USDT
marketInfo.maxOrderValueUSDT = MonetaryAmount(maxOrderValueIt->get<double>(), "USDT");
}

marketInfo.limitMinOrderAmount = MonetaryAmount(marketDetails["limit-order-min-order-amt"].get<double>(), m.base());
marketInfo.limitMaxOrderAmount = MonetaryAmount(marketDetails["limit-order-max-order-amt"].get<double>(), m.base());
marketInfo.limitMinOrderAmount = MonetaryAmount(marketDetails["limit-order-min-order-amt"].get<double>(), base);
marketInfo.limitMaxOrderAmount = MonetaryAmount(marketDetails["limit-order-max-order-amt"].get<double>(), base);

marketInfo.sellMarketMinOrderAmount =
MonetaryAmount(marketDetails["sell-market-min-order-amt"].get<double>(), m.base());
MonetaryAmount(marketDetails["sell-market-min-order-amt"].get<double>(), base);
marketInfo.sellMarketMaxOrderAmount =
MonetaryAmount(marketDetails["sell-market-max-order-amt"].get<double>(), m.base());
MonetaryAmount(marketDetails["sell-market-max-order-amt"].get<double>(), base);

marketInfo.buyMarketMaxOrderValue =
MonetaryAmount(marketDetails["buy-market-max-order-value"].get<double>(), m.quote());
MonetaryAmount(marketDetails["buy-market-max-order-value"].get<double>(), quote);

marketInfoMap.insert_or_assign(m, std::move(marketInfo));
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/src/krakenprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ PlaceOrderInfo KrakenPrivate::placeOrder(MonetaryAmount /*from*/, MonetaryAmount
const MonetaryAmount orderMin = krakenPublic.queryVolumeOrderMin(m);
CurrencyExchange krakenCurrencyBase = _exchangePublic.convertStdCurrencyToCurrencyExchange(m.base());
CurrencyExchange krakenCurrencyQuote = _exchangePublic.convertStdCurrencyToCurrencyExchange(m.quote());
Market krakenMarket(krakenCurrencyBase.altStr(), krakenCurrencyQuote.altStr());
Market krakenMarket(krakenCurrencyBase.altCode(), krakenCurrencyQuote.altCode());
const std::string_view orderType = fromCurrencyCode == m.base() ? "sell" : "buy";

auto volAndPriNbDecimals = krakenPublic._marketsCache.get().second.find(m)->second.volAndPriNbDecimals;
Expand Down
14 changes: 7 additions & 7 deletions src/api/exchanges/src/krakenpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ MarketOrderBookMap KrakenPublic::AllOrderBooksFunc::operator()(int depth) {
throw exception("Cannot find " + string(m.quoteStr()) + " in Kraken currencies");
}
CurrencyExchange krakenCurrencyExchangeQuote = *lb;
Market krakenMarket(krakenCurrencyExchangeBase.altStr(), krakenCurrencyExchangeQuote.altStr());
Market krakenMarket(krakenCurrencyExchangeBase.altCode(), krakenCurrencyExchangeQuote.altCode());
string assetPairStr = krakenMarket.assetsPairStrUpper();
if (!allAssetPairs.empty()) {
allAssetPairs.push_back(',');
Expand All @@ -395,8 +395,8 @@ MarketOrderBookMap KrakenPublic::AllOrderBooksFunc::operator()(int depth) {
}

Market m = krakenAssetPairToStdMarketMap.find(krakenAssetPair)->second;
m = Market(CurrencyCode(_coincenterInfo.standardizeCurrencyCode(m.baseStr())),
CurrencyCode(_coincenterInfo.standardizeCurrencyCode(m.quoteStr())));
m = Market(CurrencyCode(_coincenterInfo.standardizeCurrencyCode(m.base())),
CurrencyCode(_coincenterInfo.standardizeCurrencyCode(m.quote())));
// a = ask array(<price>, <whole lot volume>, <lot volume>)
// b = bid array(<price>, <whole lot volume>, <lot volume>)
const json& askDetails = assetPairDetails["a"];
Expand Down Expand Up @@ -456,8 +456,8 @@ MarketOrderBook KrakenPublic::OrderBookFunc::operator()(Market m, int count) {
}

KrakenPublic::TickerFunc::Last24hTradedVolumeAndLatestPricePair KrakenPublic::TickerFunc::operator()(Market m) {
Market krakenMarket(_tradableCurrenciesCache.get().getOrThrow(m.base()).altStr(),
_tradableCurrenciesCache.get().getOrThrow(m.quote()).altStr());
Market krakenMarket(_tradableCurrenciesCache.get().getOrThrow(m.base()).altCode(),
_tradableCurrenciesCache.get().getOrThrow(m.quote()).altCode());
json result = PublicQuery(_curlHandle, "/public/Ticker", {{"pair", krakenMarket.assetsPairStrUpper()}});
for (const auto& [krakenAssetPair, details] : result.items()) {
std::string_view last24hVol = details["v"][1].get<std::string_view>();
Expand All @@ -468,8 +468,8 @@ KrakenPublic::TickerFunc::Last24hTradedVolumeAndLatestPricePair KrakenPublic::Ti
}

LastTradesVector KrakenPublic::queryLastTrades(Market m, int) {
Market krakenMarket(_tradableCurrenciesCache.get().getOrThrow(m.base()).altStr(),
_tradableCurrenciesCache.get().getOrThrow(m.quote()).altStr());
Market krakenMarket(_tradableCurrenciesCache.get().getOrThrow(m.base()).altCode(),
_tradableCurrenciesCache.get().getOrThrow(m.quote()).altCode());
json result = PublicQuery(_curlHandle, "/public/Trades", {{"pair", krakenMarket.assetsPairStrUpper()}});
LastTradesVector ret;
for (const json& det : result.front()) {
Expand Down
2 changes: 1 addition & 1 deletion src/objects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ add_unit_test(
wallet_test
test/wallet_test.cpp
LIBRARIES
coincenter_objects
coincenter_objects
DEFINITIONS
CCT_DISABLE_SPDLOG
)
1 change: 1 addition & 0 deletions src/tech/include/mathhelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ template <class T>
concept UnsignedIntegral = std::integral<T> && !std::is_signed_v<T>;

/// Return the number of digits of given integral.
/// The minus sign is not counted.
/// Uses dichotomy for highest performance as possible.
constexpr int ndigits(SignedIntegral auto n) noexcept {
using T = decltype(n);
Expand Down

0 comments on commit d6637ee

Please sign in to comment.