diff --git a/src/api-objects/src/tradeoptions.cpp b/src/api-objects/src/tradeoptions.cpp index 04e85f22..cbe35b99 100644 --- a/src/api-objects/src/tradeoptions.cpp +++ b/src/api-objects/src/tradeoptions.cpp @@ -12,6 +12,15 @@ namespace cct { +namespace { +auto ComputeTimeoutAction(TradeTimeoutAction tradeTimeoutAction, bool timeoutMatch) { + if (tradeTimeoutAction != TradeTimeoutAction::kDefault) { + return tradeTimeoutAction; + } + return timeoutMatch ? TradeTimeoutAction::kMatch : TradeTimeoutAction::kCancel; +} +} // namespace + TradeOptions::TradeOptions(const PriceOptions &priceOptions, TradeTimeoutAction timeoutAction, TradeMode tradeMode, Duration maxTradeTime, Duration minTimeBetweenPriceUpdates, TradeTypePolicy tradeTypePolicy, TradeSyncPolicy tradeSyncPolicy) @@ -29,9 +38,7 @@ TradeOptions::TradeOptions(const TradeOptions &rhs, const schema::ExchangeQueryT ? exchangeTradeConfig.minPriceUpdateDuration.duration : rhs._minTimeBetweenPriceUpdates), _priceOptions(rhs._priceOptions.isDefault() ? PriceOptions(exchangeTradeConfig) : rhs._priceOptions), - _timeoutAction(rhs._timeoutAction == TradeTimeoutAction::kDefault - ? (exchangeTradeConfig.timeoutMatch ? TradeTimeoutAction::kMatch : TradeTimeoutAction::kCancel) - : rhs._timeoutAction), + _timeoutAction(ComputeTimeoutAction(rhs._timeoutAction, exchangeTradeConfig.timeoutMatch)), _tradeMode(rhs._tradeMode), _tradeTypePolicy(rhs._tradeTypePolicy), _tradeSyncPolicy(rhs._tradeSyncPolicy) {} diff --git a/src/basic-objects/include/coincentercommandtype.hpp b/src/basic-objects/include/coincentercommandtype.hpp index 8add1443..f61798d3 100644 --- a/src/basic-objects/include/coincentercommandtype.hpp +++ b/src/basic-objects/include/coincentercommandtype.hpp @@ -1,41 +1,21 @@ #pragma once #include +#include // IWYU pragma: export #include -#include "cct_json-serialization.hpp" - namespace cct { -enum class CoincenterCommandType : int8_t { - HealthCheck, - Currencies, - Markets, - Conversion, - ConversionPath, - LastPrice, - Ticker, - Orderbook, - LastTrades, - Last24hTradedVolume, - WithdrawFees, - - Balance, - DepositInfo, - OrdersClosed, - OrdersOpened, - OrdersCancel, - RecentDeposits, - RecentWithdraws, - Trade, - Buy, - Sell, - Withdraw, - DustSweeper, - MarketData, - Replay, - ReplayMarkets -}; +#define CCT_COINCENTER_COMMAND_TYPES \ + HealthCheck, Currencies, Markets, Conversion, ConversionPath, LastPrice, Ticker, Orderbook, LastTrades, \ + Last24hTradedVolume, WithdrawFees, \ + \ + Balance, DepositInfo, OrdersClosed, OrdersOpened, OrdersCancel, RecentDeposits, RecentWithdraws, Trade, Buy, \ + Sell, Withdraw, DustSweeper, \ + \ + MarketData, Replay, ReplayMarkets + +enum class CoincenterCommandType : int8_t { CCT_COINCENTER_COMMAND_TYPES }; std::string_view CoincenterCommandTypeToString(CoincenterCommandType coincenterCommandType); @@ -45,12 +25,7 @@ bool IsAnyTrade(CoincenterCommandType coincenterCommandType); template <> struct glz::meta<::cct::CoincenterCommandType> { using enum ::cct::CoincenterCommandType; - static constexpr auto value = - enumerate(HealthCheck, Currencies, Markets, Conversion, ConversionPath, LastPrice, Ticker, Orderbook, LastTrades, - Last24hTradedVolume, WithdrawFees, - - Balance, DepositInfo, OrdersClosed, OrdersOpened, OrdersCancel, RecentDeposits, RecentWithdraws, Trade, - Buy, Sell, Withdraw, DustSweeper, MarketData, Replay, ReplayMarkets); + static constexpr auto value = enumerate(CCT_COINCENTER_COMMAND_TYPES); }; #undef CCT_COINCENTER_COMMAND_TYPES \ No newline at end of file diff --git a/src/basic-objects/src/coincentercommandtype.cpp b/src/basic-objects/src/coincentercommandtype.cpp index 2f3d24cb..70d5454c 100644 --- a/src/basic-objects/src/coincentercommandtype.cpp +++ b/src/basic-objects/src/coincentercommandtype.cpp @@ -6,12 +6,10 @@ #include "cct_json-serialization.hpp" namespace cct { -namespace { -constexpr auto kCommandTypeNames = json::reflect::keys; -} // namespace std::string_view CoincenterCommandTypeToString(CoincenterCommandType coincenterCommandType) { - return kCommandTypeNames[static_cast>(coincenterCommandType)]; + return json::reflect::keys[static_cast>( + coincenterCommandType)]; } bool IsAnyTrade(CoincenterCommandType coincenterCommandType) { diff --git a/src/schema/test/exchange-config_test.cpp b/src/schema/test/exchange-config_test.cpp index 02689444..07fe5c91 100644 --- a/src/schema/test/exchange-config_test.cpp +++ b/src/schema/test/exchange-config_test.cpp @@ -169,16 +169,24 @@ TEST_F(ExchangeConfigTest, DirectRead) { EXPECT_EQ(exchangeConfigOptional.query.def.acceptEncoding, ""); EXPECT_EQ(exchangeConfigOptional.query.def.dustAmountsThreshold.size(), 5); EXPECT_EQ(exchangeConfigOptional.query.def.dustSweeperMaxNbTrades, 7); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) EXPECT_EQ(exchangeConfigOptional.query.def.http->timeout->duration, std::chrono::seconds(15)); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) EXPECT_EQ(exchangeConfigOptional.query.def.logLevels->requestsCall, log::level::level_enum::info); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) EXPECT_EQ(exchangeConfigOptional.query.def.logLevels->requestsAnswer, log::level::level_enum::trace); EXPECT_EQ(exchangeConfigOptional.query.def.marketDataSerialization, true); EXPECT_EQ(exchangeConfigOptional.query.def.multiTradeAllowedByDefault, false); EXPECT_EQ(exchangeConfigOptional.query.def.placeSimulateRealOrder, false); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) EXPECT_EQ(exchangeConfigOptional.query.def.trade->minPriceUpdateDuration->duration, std::chrono::seconds(5)); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) EXPECT_EQ(exchangeConfigOptional.query.def.trade->strategy, PriceStrategy::maker); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) EXPECT_EQ(exchangeConfigOptional.query.def.trade->timeout->duration, std::chrono::seconds(30)); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) EXPECT_EQ(exchangeConfigOptional.query.def.trade->timeoutMatch, false); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) EXPECT_EQ(exchangeConfigOptional.query.def.updateFrequency->size(), 9); EXPECT_EQ(exchangeConfigOptional.query.def.validateApiKey, false); EXPECT_EQ(exchangeConfigOptional.query.exchange.size(), 6); diff --git a/src/tech/src/levenshteindistancecalculator.cpp b/src/tech/src/levenshteindistancecalculator.cpp index 348f863f..d9f81d35 100644 --- a/src/tech/src/levenshteindistancecalculator.cpp +++ b/src/tech/src/levenshteindistancecalculator.cpp @@ -10,21 +10,23 @@ int LevenshteinDistanceCalculator::operator()(std::string_view word1, std::strin std::swap(word1, word2); } - const auto l1 = static_cast(word1.size()) + 1; - if (l1 > static_cast(_minDistance.size())) { + using size_type = std::string_view::size_type; + + const auto l1 = word1.size() + static_cast(1); + if (l1 > _minDistance.size()) { // Favor insert instead of resize to ensure reallocations are exponential _minDistance.insert(_minDistance.end(), l1 - _minDistance.size(), 0); } std::iota(_minDistance.begin(), _minDistance.end(), 0); - const auto l2 = static_cast(word2.size()) + 1; - for (auto word2Pos = 1; word2Pos < l2; ++word2Pos) { + const auto l2 = word2.size() + static_cast(1); + for (size_type word2Pos = 1; word2Pos < l2; ++word2Pos) { auto previousDiagonal = _minDistance[0]; ++_minDistance[0]; - for (auto word1Pos = 1; word1Pos < l1; ++word1Pos) { + for (size_type word1Pos = 1; word1Pos < l1; ++word1Pos) { const auto previousDiagonalSave = _minDistance[word1Pos]; if (word1[word1Pos - 1] == word2[word2Pos - 1]) { _minDistance[word1Pos] = previousDiagonal; diff --git a/src/tech/test/utf8_test.cpp b/src/tech/test/utf8_test.cpp index 4830f894..e15c2deb 100644 --- a/src/tech/test/utf8_test.cpp +++ b/src/tech/test/utf8_test.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "cct_string.hpp" #include "cct_vector.hpp"