diff --git a/src/api/common/src/exchangepublicapi.cpp b/src/api/common/src/exchangepublicapi.cpp index 0edc4dbe..6eff220b 100644 --- a/src/api/common/src/exchangepublicapi.cpp +++ b/src/api/common/src/exchangepublicapi.cpp @@ -259,7 +259,7 @@ std::optional ExchangePublic::determineMarketFromMarketStr(std::string_v break; } } - if (ret->quote().size() < kMinimalCryptoAcronymLen) { + if (!ret || ret->quote().size() < kMinimalCryptoAcronymLen) { log::error("Cannot determine market for {}, skipping", marketStr); ret = std::nullopt; } diff --git a/src/api/common/test/exchangeprivateapi_test.cpp b/src/api/common/test/exchangeprivateapi_test.cpp index f9951ae2..f8347f28 100644 --- a/src/api/common/test/exchangeprivateapi_test.cpp +++ b/src/api/common/test/exchangeprivateapi_test.cpp @@ -104,7 +104,7 @@ TEST_F(ExchangePrivateTest, TakerTradeQuoteToBase) { tradeBaseExpectCalls(); MonetaryAmount from(5000, market.quote()); - MonetaryAmount pri(*marketOrderBook1.computeAvgPriceForTakerAmount(from)); + MonetaryAmount pri(marketOrderBook1.computeAvgPriceForTakerAmount(from).value_or(MonetaryAmount{-1})); MonetaryAmount vol(from / pri, market.base()); PriceOptions priceOptions(PriceStrategy::kTaker); @@ -127,7 +127,7 @@ TEST_F(ExchangePrivateTest, TradeAsyncPolicyTaker) { tradeBaseExpectCalls(); MonetaryAmount from(5000, market.quote()); - MonetaryAmount pri(*marketOrderBook1.computeAvgPriceForTakerAmount(from)); + MonetaryAmount pri(marketOrderBook1.computeAvgPriceForTakerAmount(from).value_or(MonetaryAmount{-1})); MonetaryAmount vol(from / pri, market.base()); PriceOptions priceOptions(PriceStrategy::kTaker); @@ -350,7 +350,7 @@ TEST_F(ExchangePrivateTest, MakerTradeQuoteToBaseEmergencyTakerTrade) { // Place taker order tradeInfo.options.switchToTakerStrategy(); - MonetaryAmount pri2 = *marketOrderBook1.computeAvgPriceForTakerAmount(from); + MonetaryAmount pri2 = marketOrderBook1.computeAvgPriceForTakerAmount(from).value_or(MonetaryAmount{-1}); MonetaryAmount vol2(from / pri2, market.base()); PlaceOrderInfo matchedPlacedOrderInfo2(OrderInfo(TradedAmounts(from, vol2), true), OrderId("Order # 1")); @@ -675,7 +675,7 @@ TEST_F(ExchangePrivateDustSweeperTest, DustSweeper2StepsSameMarket) { expectTakerSell(from, pri, 0); // no selling possible - MonetaryAmount xrpDustThreshold = *dustThreshold(dustCur); + MonetaryAmount xrpDustThreshold = dustThreshold(dustCur).value_or(MonetaryAmount{-1}); TradedAmounts tradedAmounts1 = expectTakerBuy(xrpDustThreshold, xrpbtcAskPri, xrpbtcBidPri, xrpbtcMarket); TradedAmounts tradedAmounts2 = expectTakerSell(from + tradedAmounts1.tradedTo, pri); @@ -728,7 +728,7 @@ TEST_F(ExchangePrivateDustSweeperTest, DustSweeper5Steps) { expectTakerSell(from, priBtc, 0); // no selling possible expectTakerSell(from, priEur, 0); // no selling possible - MonetaryAmount xrpDustThreshold = *dustThreshold(dustCur); + MonetaryAmount xrpDustThreshold = dustThreshold(dustCur).value_or(MonetaryAmount{-1}); TradedAmounts tradedAmounts1 = expectTakerBuy(xrpDustThreshold, xrpbtcAskPri, xrpbtcBidPri, xrpbtcMarket); from += tradedAmounts1.tradedTo; diff --git a/src/api/common/test/exchangepublicapi_test.cpp b/src/api/common/test/exchangepublicapi_test.cpp index 0a6676bc..ec5686de 100644 --- a/src/api/common/test/exchangepublicapi_test.cpp +++ b/src/api/common/test/exchangepublicapi_test.cpp @@ -90,9 +90,7 @@ TEST_F(ExchangePublicConvertTest, ConvertImpossible) { CurrencyCode toCurrency{"BTC"}; MarketsPath conversionPath; - std::optional ret = - exchangePublic.convert(from, toCurrency, conversionPath, fiats, marketOrderBookMap, priceOptions); - ASSERT_FALSE(ret.has_value()); + ASSERT_FALSE(exchangePublic.convert(from, toCurrency, conversionPath, fiats, marketOrderBookMap, priceOptions)); } TEST_F(ExchangePublicConvertTest, ConvertSimple) { @@ -103,9 +101,9 @@ TEST_F(ExchangePublicConvertTest, ConvertSimple) { std::optional ret = exchangePublic.convert(from, toCurrency, conversionPath, fiats, marketOrderBookMap, priceOptions); ASSERT_TRUE(ret.has_value()); - MonetaryAmount res = exchangePublic.exchangeInfo().applyFee(*marketOrderBook1.convert(from, priceOptions), - ExchangeInfo::FeeType::kMaker); - EXPECT_EQ(*ret, res); + MonetaryAmount res = exchangePublic.exchangeInfo().applyFee( + marketOrderBook1.convert(from, priceOptions).value_or(MonetaryAmount{-1}), ExchangeInfo::FeeType::kMaker); + EXPECT_EQ(ret, std::optional(res)); } TEST_F(ExchangePublicConvertTest, ConvertDouble) { @@ -115,11 +113,11 @@ TEST_F(ExchangePublicConvertTest, ConvertDouble) { std::optional ret = exchangePublic.convert(from, toCurrency, conversionPath, fiats, marketOrderBookMap, priceOptions); ASSERT_TRUE(ret.has_value()); - MonetaryAmount res = exchangePublic.exchangeInfo().applyFee(*marketOrderBook1.convert(from, priceOptions), - ExchangeInfo::FeeType::kMaker); - res = exchangePublic.exchangeInfo().applyFee(*marketOrderBook2.convert(res, priceOptions), + MonetaryAmount res = exchangePublic.exchangeInfo().applyFee( + marketOrderBook1.convert(from, priceOptions).value_or(MonetaryAmount{-1}), ExchangeInfo::FeeType::kMaker); + res = exchangePublic.exchangeInfo().applyFee(marketOrderBook2.convert(res, priceOptions).value_or(MonetaryAmount{-1}), ExchangeInfo::FeeType::kMaker); - EXPECT_EQ(*ret, res); + EXPECT_EQ(ret, std::optional(res)); } } // namespace cct::api \ No newline at end of file diff --git a/src/api/exchanges/src/huobipublicapi.cpp b/src/api/exchanges/src/huobipublicapi.cpp index 229c7283..890847c8 100644 --- a/src/api/exchanges/src/huobipublicapi.cpp +++ b/src/api/exchanges/src/huobipublicapi.cpp @@ -197,7 +197,7 @@ std::pair HuobiPublic::Marke // value = vol * pri in quote currency MarketInfo marketInfo; - marketInfo.volAndPriNbDecimals = VolAndPriNbDecimals(volNbDec, priNbDec); + marketInfo.volAndPriNbDecimals = {volNbDec, priNbDec}; marketInfo.minOrderValue = MonetaryAmount(marketDetails["min-order-value"].get(), quote); auto maxOrderValueIt = marketDetails.find("max-order-value"); diff --git a/src/api/exchanges/src/krakenpublicapi.cpp b/src/api/exchanges/src/krakenpublicapi.cpp index a3687a64..39e096c3 100644 --- a/src/api/exchanges/src/krakenpublicapi.cpp +++ b/src/api/exchanges/src/krakenpublicapi.cpp @@ -383,8 +383,7 @@ std::pair KrakenPublic::Mar auto mkIt = ret.first.emplace(base, quote).first; log::debug("Retrieved Kraken market {}", *mkIt); MonetaryAmount orderMin(value["ordermin"].get(), base); - ret.second.insert_or_assign( - *mkIt, MarketInfo{VolAndPriNbDecimals(value["lot_decimals"], value["pair_decimals"]), orderMin}); + ret.second.insert_or_assign(*mkIt, MarketInfo{{value["lot_decimals"], value["pair_decimals"]}, orderMin}); } log::info("Retrieved {} markets from Kraken", ret.first.size()); return ret; diff --git a/src/api/exchanges/test/commonapi_test.hpp b/src/api/exchanges/test/commonapi_test.hpp index 302e9ac5..3f471c63 100644 --- a/src/api/exchanges/test/commonapi_test.hpp +++ b/src/api/exchanges/test/commonapi_test.hpp @@ -81,7 +81,7 @@ class TestAPI { // for (const auto &c : currencies) { // d[string(c.standardStr())] = exchangePrivateOpt->queryWithdrawalFee(c.standardCode()).amountStr(); // } - // std::cout << d.dump(2) << std::endl; + // std::cout << d.dump(2) << '\n'; // } } diff --git a/src/engine/include/commandlineoptionsparser.hpp b/src/engine/include/commandlineoptionsparser.hpp index 3382ee53..98aab356 100644 --- a/src/engine/include/commandlineoptionsparser.hpp +++ b/src/engine/include/commandlineoptionsparser.hpp @@ -82,22 +82,22 @@ class CommandLineOptionsParser { } void displayHelp(std::string_view programName, std::ostream& stream) const { - stream << "usage: " << programName << " " << std::endl; + stream << "usage: " << programName << " \n"; if (_opts.empty()) { return; } - stream << "Options:" << std::endl; + stream << "Options:\n"; const int lenTabRow = computeLenTabRow(); std::string_view previousGroup; for (const auto& [opt, pm] : _opts) { std::string_view currentGroup = opt.commandHeader().groupName(); if (currentGroup != previousGroup) { - stream << std::endl << ' ' << currentGroup << std::endl; + stream << '\n' << ' ' << currentGroup << '\n'; previousGroup = currentGroup; } if (opt.fullName()[0] != '-') { - stream << std::endl; + stream << '\n'; } RowPrefix(opt, lenTabRow, stream); @@ -109,14 +109,14 @@ class CommandLineOptionsParser { auto breakPos = descr.find_first_of(kSpaceOrNewLine); if (breakPos == std::string_view::npos) { if (linePos + descr.size() > kMaxCharLine) { - stream << std::endl; + stream << '\n'; Spaces(lenTabRow, stream); } - stream << descr << std::endl; + stream << descr << '\n'; break; } if (linePos + breakPos > kMaxCharLine) { - stream << std::endl; + stream << '\n'; Spaces(lenTabRow, stream); linePos = lenTabRow; } diff --git a/src/engine/src/coincenteroptions.cpp b/src/engine/src/coincenteroptions.cpp index 7b171ba5..8bfb7256 100644 --- a/src/engine/src/coincenteroptions.cpp +++ b/src/engine/src/coincenteroptions.cpp @@ -22,10 +22,10 @@ bool CoincenterCmdLineOptions::isSmartTrade() const noexcept { } void CoincenterCmdLineOptions::PrintVersion(std::string_view programName) noexcept { - std::cout << programName << " version " << CCT_VERSION << std::endl; - std::cout << "compiled with " << CCT_COMPILER_VERSION << " on " << __DATE__ << " at " << __TIME__ << std::endl; - std::cout << " " << GetCurlVersionInfo() << std::endl; - std::cout << " " << ssl::GetOpenSSLVersion() << std::endl; + std::cout << programName << " version " << CCT_VERSION << '\n'; + std::cout << "compiled with " << CCT_COMPILER_VERSION << " on " << __DATE__ << " at " << __TIME__ << '\n'; + std::cout << " " << GetCurlVersionInfo() << '\n'; + std::cout << " " << ssl::GetOpenSSLVersion() << '\n'; } void CoincenterCmdLineOptions::mergeGlobalWith(const CoincenterCmdLineOptions& other) { diff --git a/src/engine/src/queryresultprinter.cpp b/src/engine/src/queryresultprinter.cpp index 985bbee2..23252d2e 100644 --- a/src/engine/src/queryresultprinter.cpp +++ b/src/engine/src/queryresultprinter.cpp @@ -1075,7 +1075,7 @@ void QueryResultPrinter::printTable(const SimpleTable &simpleTable) const { os << simpleTable; if (_pOs != nullptr) { - *_pOs << std::endl; + *_pOs << '\n'; } else { // logger library automatically adds a newline as suffix _outputLogger->info(ss.view()); @@ -1085,7 +1085,7 @@ void QueryResultPrinter::printTable(const SimpleTable &simpleTable) const { void QueryResultPrinter::printJson(const json &jsonData) const { string jsonStr = jsonData.dump(); if (_pOs != nullptr) { - *_pOs << jsonStr << std::endl; + *_pOs << jsonStr << '\n'; } else { _outputLogger->info(jsonStr); } diff --git a/src/engine/test/commandlineoptionsparser_test.cpp b/src/engine/test/commandlineoptionsparser_test.cpp index 15e1312f..759786e1 100644 --- a/src/engine/test/commandlineoptionsparser_test.cpp +++ b/src/engine/test/commandlineoptionsparser_test.cpp @@ -116,8 +116,8 @@ TEST_F(CommandLineOptionsParserTest, OptStringViewEmpty) { } TEST_F(CommandLineOptionsParserTest, OptStringViewNotEmpty) { - EXPECT_EQ(*createOptions({"--optSV2", "I need to save the world"}).optSV, - std::string_view("I need to save the world")); + EXPECT_EQ(createOptions({"--optSV2", "I need to save the world"}).optSV, + std::optional("I need to save the world")); } TEST_F(CommandLineOptionsParserTest, AlternativeOptionName) { @@ -130,15 +130,16 @@ TEST_F(CommandLineOptionsParserTest, String) { } TEST_F(CommandLineOptionsParserTest, OptStringNotEmpty) { - EXPECT_EQ(*createOptions({"--opt4", "2000 EUR, kraken"}).optStr, "2000 EUR, kraken"); + EXPECT_EQ(createOptions({"--opt4", "2000 EUR, kraken"}).optStr, std::optional("2000 EUR, kraken")); } TEST_F(CommandLineOptionsParserTest, OptStringEmpty1) { - EXPECT_EQ(*createOptions({"--opt4", "--opt1", "Opt1 value"}).optStr, std::string_view()); + EXPECT_EQ(createOptions({"--opt4", "--opt1", "Opt1 value"}).optStr, + std::optional(std::string_view{})); } TEST_F(CommandLineOptionsParserTest, OptStringEmpty2) { - EXPECT_EQ(*createOptions({"--opt4"}).optStr, std::string_view()); + EXPECT_EQ(createOptions({"--opt4"}).optStr, std::optional(std::string_view{})); } TEST_F(CommandLineOptionsParserTest, OptStringEmpty3) { EXPECT_EQ(createOptions({"--help"}).optStr, std::nullopt); } diff --git a/src/objects/src/file.cpp b/src/objects/src/file.cpp index 409ff15b..34bf3a8e 100644 --- a/src/objects/src/file.cpp +++ b/src/objects/src/file.cpp @@ -69,12 +69,12 @@ int File::write(const json& data, Writer::Mode mode) const { try { if (data.empty()) { static constexpr std::string_view kEmptyJsonStr = "{}"; - fileOfStream << kEmptyJsonStr << std::endl; + fileOfStream << kEmptyJsonStr << '\n'; return kEmptyJsonStr.length() + 1; } const int indent = mode == Writer::Mode::FromStart ? 2 : -1; string outStr = data.dump(indent); - fileOfStream << outStr << std::endl; + fileOfStream << outStr << '\n'; return outStr.length() + 1; } catch (const std::exception& e) { if (_ifError == IfError::kThrow) { diff --git a/src/objects/src/marketorderbook.cpp b/src/objects/src/marketorderbook.cpp index ef4357c0..c7c34140 100644 --- a/src/objects/src/marketorderbook.cpp +++ b/src/objects/src/marketorderbook.cpp @@ -37,10 +37,14 @@ MarketOrderBook::MarketOrderBook(Market market, OrderBookLineSpan orderLines, Vo // Just ignore empty lines continue; } - AmountPrice::AmountType amountIntegral = *orderBookLine._amount.amount(_volAndPriNbDecimals.volNbDecimals); - AmountPrice::AmountType priceIntegral = *orderBookLine._price.amount(_volAndPriNbDecimals.priNbDecimals); - _orders.emplace_back(amountIntegral, priceIntegral); + const auto amountIntegral = orderBookLine._amount.amount(_volAndPriNbDecimals.volNbDecimals); + const auto priceIntegral = orderBookLine._price.amount(_volAndPriNbDecimals.priNbDecimals); + + assert(amountIntegral.has_value()); + assert(priceIntegral.has_value()); + + _orders.emplace_back(*amountIntegral, *priceIntegral); } std::ranges::sort(_orders, [](AmountPrice lhs, AmountPrice rhs) { return lhs.price < rhs.price; }); diff --git a/src/objects/test/monetaryamount_test.cpp b/src/objects/test/monetaryamount_test.cpp index d80d579b..a6731af8 100644 --- a/src/objects/test/monetaryamount_test.cpp +++ b/src/objects/test/monetaryamount_test.cpp @@ -50,12 +50,12 @@ TEST(MonetaryAmountTest, TenDecimals) { mamount1 = MonetaryAmount("0.0620089", btcCode); EXPECT_NE(mamount1, 0); EXPECT_EQ(mamount1.nbDecimals(), 7); - EXPECT_EQ(*MonetaryAmount("-314.451436574563", btcCode).amount(nbDecimals), -3144514365745); + EXPECT_EQ(MonetaryAmount("-314.451436574563", btcCode).amount(nbDecimals).value_or(-1), -3144514365745); mamount1 = MonetaryAmount("-314.451436574563", btcCode); EXPECT_EQ(mamount1.nbDecimals(), 12); mamount1 = MonetaryAmount("2.0036500", btcCode); - EXPECT_EQ(*mamount1.amount(2), 200); + EXPECT_EQ(mamount1.amount(2).value_or(-1), 200); EXPECT_EQ(mamount1.integerPart(), 2); EXPECT_EQ(mamount1.nbDecimals(), 5); } @@ -73,9 +73,10 @@ TEST(MonetaryAmountTest, NoDecimals) { MonetaryAmount mamount3(0, krwCode, nbDecimals); EXPECT_EQ(mamount3.str(), "0 KRW"); - EXPECT_EQ(*MonetaryAmount("0.620089", krwCode).amount(nbDecimals), 0); - EXPECT_EQ(*MonetaryAmount("-31415.0", krwCode).amount(nbDecimals), -31415); - EXPECT_EQ(*MonetaryAmount(3, krwCode).amount(nbDecimals), 3); + EXPECT_EQ(MonetaryAmount("0.620089", krwCode).amount(nbDecimals).value_or(-1), 0); + EXPECT_EQ(MonetaryAmount("-31415.0", krwCode).amount(nbDecimals).value_or(-1), -31415); + + EXPECT_EQ(MonetaryAmount(3, krwCode).amount(nbDecimals).value_or(-1), 3); EXPECT_EQ(MonetaryAmount("35.620089", krwCode).amount(18), std::nullopt); } diff --git a/src/tech/src/simpletable.cpp b/src/tech/src/simpletable.cpp index 9fade7e0..2eedee8c 100644 --- a/src/tech/src/simpletable.cpp +++ b/src/tech/src/simpletable.cpp @@ -71,7 +71,7 @@ void SimpleTable::Row::print(std::ostream &os, std::span maxWidt for (const Cell &cell : _cells) { cell.print(os, maxWidthPerColumn[columnPos++]); } - os << std::endl; + os << '\n'; } SimpleTable::MaxWidthPerColumnVector SimpleTable::computeMaxWidthPerColumn() const { @@ -112,17 +112,17 @@ std::ostream &operator<<(std::ostream &os, const SimpleTable &table) { const auto maxWidthPerColumnVector = table.computeMaxWidthPerColumn(); const auto lineSep = SimpleTable::ComputeLineSep(maxWidthPerColumnVector); - os << lineSep << std::endl; + os << lineSep << '\n'; bool printHeader = table._rows.size() > 1U; for (const auto &row : table._rows) { if (row.isDivider()) { - os << lineSep << std::endl; + os << lineSep << '\n'; } else { row.print(os, maxWidthPerColumnVector); } if (printHeader) { - os << lineSep << std::endl; + os << lineSep << '\n'; printHeader = false; } } diff --git a/src/tech/test/flatkeyvaluestring_test.cpp b/src/tech/test/flatkeyvaluestring_test.cpp index 9e1cb52c..00611d5c 100644 --- a/src/tech/test/flatkeyvaluestring_test.cpp +++ b/src/tech/test/flatkeyvaluestring_test.cpp @@ -116,6 +116,8 @@ TEST(FlatKeyValueStringTest, WithNullTerminatingCharAsSeparator) { case 2: ASSERT_STREQ(kvPairPtr, "&newField:&&newValue&&"); break; + default: + ASSERT_TRUE(false); } } EXPECT_EQ(kvPairPos, 3); @@ -125,9 +127,6 @@ TEST(FlatKeyValueStringTest, EmptyConvertToJson) { EXPECT_EQ(KvPairs().toJson(), class CurlOptionsCase1 : public ::testing::Test { protected: - void SetUp() override {} - void TearDown() override {} - KvPairs kvPairs{{"units", "0.11176"}, {"price", "357.78"}, {"777", "encoredutravail?"}, {"hola", "quetal"}, {"array1", "val1,,"}, {"array2", ",val1,val2,value,"}, {"emptyArray", ","}}; @@ -177,6 +176,8 @@ TEST_F(CurlOptionsCase1, Iterator) { EXPECT_EQ(key, "emptyArray"); EXPECT_EQ(val, ","); break; + default: + EXPECT_TRUE(false); } } EXPECT_EQ(itPos, 7);