From f5f49045b69f8cd47064d4e0638777d088204c1f Mon Sep 17 00:00:00 2001 From: Stephane Janel Date: Tue, 19 Mar 2024 18:42:38 +0100 Subject: [PATCH] Use std::unique_ptr instead of forward_list to hold ExchangePrivate memory --- src/api/interface/include/exchange.hpp | 46 +++--- src/api/interface/include/exchangepool.hpp | 19 --- src/api/interface/src/exchange.cpp | 28 ++-- src/api/interface/src/exchangepool.cpp | 18 +- .../interface/test/exchangeretriever_test.cpp | 72 ++++---- src/engine/test/exchangedata_test.hpp | 50 +++--- .../exchangesorchestrator_private_test.cpp | 59 ++++--- .../exchangesorchestrator_public_test.cpp | 4 +- .../test/exchangesorchestrator_trade_test.cpp | 154 +++++++++--------- src/tech/include/simpletable.hpp | 13 ++ 10 files changed, 233 insertions(+), 230 deletions(-) diff --git a/src/api/interface/include/exchange.hpp b/src/api/interface/include/exchange.hpp index 51306bbe..05e24a0a 100644 --- a/src/api/interface/include/exchange.hpp +++ b/src/api/interface/include/exchange.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -29,9 +30,10 @@ class Exchange { Exchange(const ExchangeConfig &exchangeConfig, ExchangePublic &exchangePublic); /// Build a Exchange with both private and public exchanges - Exchange(const ExchangeConfig &exchangeConfig, ExchangePublic &exchangePublic, ExchangePrivate &exchangePrivate); + Exchange(const ExchangeConfig &exchangeConfig, ExchangePublic &exchangePublic, + std::unique_ptr exchangePrivate); - std::string_view name() const { return _exchangePublic.name(); } + std::string_view name() const { return apiPublic().name(); } std::string_view keyName() const { return apiPrivate().keyName(); } ExchangeName createExchangeName() const { @@ -41,63 +43,63 @@ class Exchange { return ExchangeName(name()); } - ExchangePublic &apiPublic() { return _exchangePublic; } - const ExchangePublic &apiPublic() const { return _exchangePublic; } + ExchangePublic &apiPublic() { return *_pExchangePublic; } + const ExchangePublic &apiPublic() const { return *_pExchangePublic; } ExchangePrivate &apiPrivate() { if (hasPrivateAPI()) { - return *_pExchangePrivate; + return *_exchangePrivate; } throw exception("No private key associated to exchange {}", name()); } const ExchangePrivate &apiPrivate() const { if (hasPrivateAPI()) { - return *_pExchangePrivate; + return *_exchangePrivate; } throw exception("No private key associated to exchange {}", name()); } - const ExchangeConfig &exchangeConfig() const { return _exchangeConfig; } + const ExchangeConfig &exchangeConfig() const { return *_pExchangeConfig; } - bool hasPrivateAPI() const { return _pExchangePrivate != nullptr; } + bool hasPrivateAPI() const { return static_cast(_exchangePrivate); } - bool healthCheck() { return _exchangePublic.healthCheck(); } + bool healthCheck() { return apiPublic().healthCheck(); } CurrencyExchangeFlatSet queryTradableCurrencies() { - return hasPrivateAPI() ? _pExchangePrivate->queryTradableCurrencies() : _exchangePublic.queryTradableCurrencies(); + return hasPrivateAPI() ? _exchangePrivate->queryTradableCurrencies() : apiPublic().queryTradableCurrencies(); } CurrencyExchange convertStdCurrencyToCurrencyExchange(CurrencyCode currencyCode) { - return _exchangePublic.convertStdCurrencyToCurrencyExchange(currencyCode); + return apiPublic().convertStdCurrencyToCurrencyExchange(currencyCode); } - MarketSet queryTradableMarkets() { return _exchangePublic.queryTradableMarkets(); } + MarketSet queryTradableMarkets() { return apiPublic().queryTradableMarkets(); } - MarketPriceMap queryAllPrices() { return _exchangePublic.queryAllPrices(); } + MarketPriceMap queryAllPrices() { return apiPublic().queryAllPrices(); } MonetaryAmountByCurrencySet queryWithdrawalFees() { - return hasPrivateAPI() ? _pExchangePrivate->queryWithdrawalFees() : _exchangePublic.queryWithdrawalFees(); + return hasPrivateAPI() ? _exchangePrivate->queryWithdrawalFees() : apiPublic().queryWithdrawalFees(); } std::optional queryWithdrawalFee(CurrencyCode currencyCode) { - return hasPrivateAPI() ? _pExchangePrivate->queryWithdrawalFee(currencyCode) - : _exchangePublic.queryWithdrawalFee(currencyCode); + return hasPrivateAPI() ? _exchangePrivate->queryWithdrawalFee(currencyCode) + : apiPublic().queryWithdrawalFee(currencyCode); } MarketOrderBookMap queryAllApproximatedOrderBooks(int depth = ExchangePublic::kDefaultDepth) { - return _exchangePublic.queryAllApproximatedOrderBooks(depth); + return apiPublic().queryAllApproximatedOrderBooks(depth); } MarketOrderBook queryOrderBook(Market mk, int depth = ExchangePublic::kDefaultDepth); - MonetaryAmount queryLast24hVolume(Market mk) { return _exchangePublic.queryLast24hVolume(mk); } + MonetaryAmount queryLast24hVolume(Market mk) { return apiPublic().queryLast24hVolume(mk); } /// Retrieve an ordered vector of recent last trades PublicTradeVector queryLastTrades(Market mk, int nbTrades = ExchangePublic::kNbLastTradesDefault); /// Retrieve the last price of given market. - MonetaryAmount queryLastPrice(Market mk) { return _exchangePublic.queryLastPrice(mk); } + MonetaryAmount queryLastPrice(Market mk) { return apiPublic().queryLastPrice(mk); } bool canWithdraw(CurrencyCode currencyCode, const CurrencyExchangeFlatSet ¤cyExchangeSet) const; @@ -110,9 +112,9 @@ class Exchange { void updateCacheFile() const; private: - ExchangePublic &_exchangePublic; - ExchangePrivate *_pExchangePrivate = nullptr; - const ExchangeConfig &_exchangeConfig; + ExchangePublic *_pExchangePublic; + std::unique_ptr _exchangePrivate; + const ExchangeConfig *_pExchangeConfig; }; } // namespace cct diff --git a/src/api/interface/include/exchangepool.hpp b/src/api/interface/include/exchangepool.hpp index 925624c9..a3cde88f 100644 --- a/src/api/interface/include/exchangepool.hpp +++ b/src/api/interface/include/exchangepool.hpp @@ -1,8 +1,6 @@ #pragma once -#include #include -#include #include "binancepublicapi.hpp" #include "bithumbpublicapi.hpp" @@ -21,13 +19,6 @@ class CoincenterInfo; class FiatConverter; namespace api { -class BinancePrivate; -class BithumbPrivate; -class HuobiPrivate; -class KrakenPrivate; -class KucoinPrivate; -class UpbitPrivate; - class CommonAPI; class APIKeysProvider; } // namespace api @@ -63,16 +54,6 @@ class ExchangePool { api::KucoinPublic _kucoinPublic; api::UpbitPublic _upbitPublic; - // Private exchanges (based on provided keys) - // Use std::forward_list to guarantee validity of the iterators and pointers, as we give them to Exchange object as - // pointers - std::forward_list _binancePrivates; - std::forward_list _bithumbPrivates; - std::forward_list _huobiPrivates; - std::forward_list _krakenPrivates; - std::forward_list _kucoinPrivates; - std::forward_list _upbitPrivates; - ExchangeVector _exchanges; }; diff --git a/src/api/interface/src/exchange.cpp b/src/api/interface/src/exchange.cpp index f252693d..cb86645b 100644 --- a/src/api/interface/src/exchange.cpp +++ b/src/api/interface/src/exchange.cpp @@ -8,22 +8,20 @@ #include "exchangeconfig.hpp" #include "exchangeprivateapi.hpp" #include "exchangepublicapi.hpp" -#include "marketorderbook.hpp" -#include "public-trade-vector.hpp" namespace cct { -Exchange::Exchange(const ExchangeConfig &exchangeConfig, api::ExchangePublic &exchangePublic, - api::ExchangePrivate &exchangePrivate) - : _exchangePublic(exchangePublic), - _pExchangePrivate(std::addressof(exchangePrivate)), - _exchangeConfig(exchangeConfig) {} +Exchange::Exchange(const ExchangeConfig &exchangeConfig, ExchangePublic &exchangePublic) + : Exchange(exchangeConfig, exchangePublic, std::unique_ptr()) {} -Exchange::Exchange(const ExchangeConfig &exchangeConfig, api::ExchangePublic &exchangePublic) - : _exchangePublic(exchangePublic), _exchangeConfig(exchangeConfig) {} +Exchange::Exchange(const ExchangeConfig &exchangeConfig, ExchangePublic &exchangePublic, + std::unique_ptr exchangePrivate) + : _pExchangePublic(std::addressof(exchangePublic)), + _exchangePrivate(std::move(exchangePrivate)), + _pExchangeConfig(std::addressof(exchangeConfig)) {} bool Exchange::canWithdraw(CurrencyCode currencyCode, const CurrencyExchangeFlatSet ¤cyExchangeSet) const { - if (_exchangeConfig.excludedCurrenciesWithdrawal().contains(currencyCode)) { + if (_pExchangeConfig->excludedCurrenciesWithdrawal().contains(currencyCode)) { return false; } auto lb = currencyExchangeSet.find(currencyCode); @@ -43,17 +41,17 @@ bool Exchange::canDeposit(CurrencyCode currencyCode, const CurrencyExchangeFlatS return lb->canDeposit(); } -MarketOrderBook Exchange::queryOrderBook(Market mk, int depth) { return _exchangePublic.queryOrderBook(mk, depth); } +MarketOrderBook Exchange::queryOrderBook(Market mk, int depth) { return apiPublic().queryOrderBook(mk, depth); } /// Retrieve an ordered vector of recent last trades PublicTradeVector Exchange::queryLastTrades(Market mk, int nbTrades) { - return _exchangePublic.queryLastTrades(mk, nbTrades); + return apiPublic().queryLastTrades(mk, nbTrades); } void Exchange::updateCacheFile() const { - _exchangePublic.updateCacheFile(); - if (_pExchangePrivate != nullptr) { - _pExchangePrivate->updateCacheFile(); + apiPublic().updateCacheFile(); + if (_exchangePrivate) { + _exchangePrivate->updateCacheFile(); } } } // namespace cct diff --git a/src/api/interface/src/exchangepool.cpp b/src/api/interface/src/exchangepool.cpp index 1d04d5ef..61379d19 100644 --- a/src/api/interface/src/exchangepool.cpp +++ b/src/api/interface/src/exchangepool.cpp @@ -1,11 +1,13 @@ #include "exchangepool.hpp" +#include #include #include "apikey.hpp" #include "apikeysprovider.hpp" #include "binanceprivateapi.hpp" #include "bithumbprivateapi.hpp" +#include "bithumbpublicapi.hpp" #include "cct_const.hpp" #include "cct_exception.hpp" #include "cct_log.hpp" @@ -53,21 +55,21 @@ ExchangePool::ExchangePool(const CoincenterInfo& coincenterInfo, FiatConverter& const ExchangeConfig& exchangeConfig = _coincenterInfo.exchangeConfig(exchangePublic->name()); if (canUsePrivateExchange) { for (std::string_view keyName : _apiKeyProvider.getKeyNames(exchangeStr)) { - api::ExchangePrivate* exchangePrivate; + std::unique_ptr exchangePrivate; ExchangeName exchangeName(exchangeStr, keyName); const api::APIKey& apiKey = _apiKeyProvider.get(exchangeName); if (exchangePublic == &_binancePublic) { - exchangePrivate = &_binancePrivates.emplace_front(_coincenterInfo, _binancePublic, apiKey); + exchangePrivate = std::make_unique(_coincenterInfo, _binancePublic, apiKey); } else if (exchangePublic == &_bithumbPublic) { - exchangePrivate = &_bithumbPrivates.emplace_front(_coincenterInfo, _bithumbPublic, apiKey); + exchangePrivate = std::make_unique(_coincenterInfo, _bithumbPublic, apiKey); } else if (exchangePublic == &_huobiPublic) { - exchangePrivate = &_huobiPrivates.emplace_front(_coincenterInfo, _huobiPublic, apiKey); + exchangePrivate = std::make_unique(_coincenterInfo, _huobiPublic, apiKey); } else if (exchangePublic == &_krakenPublic) { - exchangePrivate = &_krakenPrivates.emplace_front(_coincenterInfo, _krakenPublic, apiKey); + exchangePrivate = std::make_unique(_coincenterInfo, _krakenPublic, apiKey); } else if (exchangePublic == &_kucoinPublic) { - exchangePrivate = &_kucoinPrivates.emplace_front(_coincenterInfo, _kucoinPublic, apiKey); + exchangePrivate = std::make_unique(_coincenterInfo, _kucoinPublic, apiKey); } else if (exchangePublic == &_upbitPublic) { - exchangePrivate = &_upbitPrivates.emplace_front(_coincenterInfo, _upbitPublic, apiKey); + exchangePrivate = std::make_unique(_coincenterInfo, _upbitPublic, apiKey); } else { throw exception("Unsupported platform {}", exchangeStr); } @@ -81,7 +83,7 @@ ExchangePool::ExchangePool(const CoincenterInfo& coincenterInfo, FiatConverter& } } - _exchanges.emplace_back(exchangeConfig, *exchangePublic, *exchangePrivate); + _exchanges.emplace_back(exchangeConfig, *exchangePublic, std::move(exchangePrivate)); } } else { _exchanges.emplace_back(exchangeConfig, *exchangePublic); diff --git a/src/api/interface/test/exchangeretriever_test.cpp b/src/api/interface/test/exchangeretriever_test.cpp index 3411f956..6fd6cf3a 100644 --- a/src/api/interface/test/exchangeretriever_test.cpp +++ b/src/api/interface/test/exchangeretriever_test.cpp @@ -3,9 +3,12 @@ #include #include +#include +#include #include #include +#include "cct_const.hpp" #include "cct_exception.hpp" #include "cct_string.hpp" #include "coincenterinfo.hpp" @@ -41,22 +44,13 @@ class ExchangeRetrieverTest : public ::testing::Test { api::APIKey key3{"test3", "user3", "", "", ""}; api::APIKey key4{"test4", "user4", "", "", ""}; api::APIKey key5{"test5", "user5", "", "", ""}; - api::MockExchangePrivate exchangePrivate1{exchangePublic1, coincenterInfo, key1}; - api::MockExchangePrivate exchangePrivate2{exchangePublic2, coincenterInfo, key1}; - api::MockExchangePrivate exchangePrivate3{exchangePublic3, coincenterInfo, key1}; - api::MockExchangePrivate exchangePrivate4{exchangePublic3, coincenterInfo, key2}; - api::MockExchangePrivate exchangePrivate5{exchangePublic3, coincenterInfo, key3}; - api::MockExchangePrivate exchangePrivate6{exchangePublic3, coincenterInfo, key4}; - api::MockExchangePrivate exchangePrivate7{exchangePublic3, coincenterInfo, key5}; - api::MockExchangePrivate exchangePrivate8{exchangePublic1, coincenterInfo, key2}; - Exchange exchange1{coincenterInfo.exchangeConfig(exchangePublic1.name()), exchangePublic1, exchangePrivate1}; - Exchange exchange2{coincenterInfo.exchangeConfig(exchangePublic2.name()), exchangePublic2, exchangePrivate2}; - Exchange exchange3{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate3}; - Exchange exchange4{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate4}; - Exchange exchange5{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate5}; - Exchange exchange6{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate6}; - Exchange exchange7{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3}; - Exchange exchange8{coincenterInfo.exchangeConfig(exchangePublic1.name()), exchangePublic1, exchangePrivate8}; + Exchange exchange1{coincenterInfo.exchangeConfig(exchangePublic1.name()), exchangePublic1, + std::make_unique(exchangePublic1, coincenterInfo, key1)}; + Exchange exchange2{coincenterInfo.exchangeConfig(exchangePublic2.name()), exchangePublic2, + std::make_unique(exchangePublic2, coincenterInfo, key1)}; + Exchange exchange3{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3}; + Exchange exchange4{coincenterInfo.exchangeConfig(exchangePublic1.name()), exchangePublic1, + std::make_unique(exchangePublic1, coincenterInfo, key2)}; }; TEST_F(ExchangeRetrieverTest, Empty) { @@ -65,7 +59,7 @@ TEST_F(ExchangeRetrieverTest, Empty) { } TEST_F(ExchangeRetrieverTest, EmptySelection) { - Exchange kAllExchanges[] = {exchange1, exchange2, exchange7, exchange8}; + Exchange kAllExchanges[] = {std::move(exchange1), std::move(exchange2), std::move(exchange3), std::move(exchange4)}; ExchangeRetriever exchangeRetriever(kAllExchanges); @@ -80,7 +74,7 @@ TEST_F(ExchangeRetrieverTest, EmptySelection) { } TEST_F(ExchangeRetrieverTest, RetrieveUniqueCandidate) { - Exchange kAllExchanges[] = {exchange1, exchange2, exchange7, exchange8}; + Exchange kAllExchanges[] = {std::move(exchange1), std::move(exchange2), std::move(exchange3), std::move(exchange4)}; ExchangeRetriever exchangeRetriever(kAllExchanges); @@ -98,7 +92,7 @@ TEST_F(ExchangeRetrieverTest, RetrieveUniqueCandidate) { } TEST_F(ExchangeRetrieverTest, RetrieveSelectedExchangesInitialOrder) { - Exchange kAllExchanges[] = {exchange1, exchange2, exchange7, exchange8}; + Exchange kAllExchanges[] = {std::move(exchange1), std::move(exchange2), std::move(exchange3), std::move(exchange4)}; ExchangeRetriever exchangeRetriever(kAllExchanges); @@ -123,7 +117,7 @@ TEST_F(ExchangeRetrieverTest, RetrieveSelectedExchangesInitialOrder) { } TEST_F(ExchangeRetrieverTest, RetrieveSelectedExchangesFilterWhenAccountNotPresent) { - Exchange kAllExchanges[] = {exchange1, exchange2, exchange7, exchange8}; + Exchange kAllExchanges[] = {std::move(exchange1), std::move(exchange2), std::move(exchange3), std::move(exchange4)}; ExchangeRetriever exchangeRetriever(kAllExchanges); @@ -152,14 +146,10 @@ TEST_F(ExchangeRetrieverTest, RetrieveSelectedExchangesFilterWhenAccountNotPrese } TEST_F(ExchangeRetrieverTest, RetrieveSelectedExchangesSelectedOrder) { - Exchange kAllExchanges1[] = {exchange1, exchange2, exchange8}; - Exchange kAllExchanges2[] = {exchange8, exchange1, exchange2}; + Exchange kAllExchanges[] = {std::move(exchange1), std::move(exchange2), std::move(exchange4)}; - std::span exchangesSpan1 = kAllExchanges1; - std::span exchangesSpan2 = kAllExchanges2; - - for (auto exchangesSpan : {exchangesSpan1, exchangesSpan2}) { - ExchangeRetriever exchangeRetriever(exchangesSpan); + for (int pos = 0; pos < 2; ++pos) { + ExchangeRetriever exchangeRetriever(kAllExchanges); ExchangeNames names{ExchangeName("kraken"), ExchangeName("bithumb")}; ExchangeRetriever::SelectedExchanges selectedExchanges = exchangeRetriever.select(ExchangeRetriever::Order::kSelection, names); @@ -167,18 +157,16 @@ TEST_F(ExchangeRetrieverTest, RetrieveSelectedExchangesSelectedOrder) { EXPECT_EQ(selectedExchanges[0]->name(), "kraken"); EXPECT_EQ(selectedExchanges[1]->name(), "bithumb"); EXPECT_EQ(selectedExchanges[2]->name(), "bithumb"); + + std::rotate(std::begin(kAllExchanges), std::begin(kAllExchanges) + 2, std::end(kAllExchanges)); } } TEST_F(ExchangeRetrieverTest, RetrieveAtMostOneAccountSelectedExchanges) { - Exchange kAllExchanges1[] = {exchange1, exchange2, exchange8}; - Exchange kAllExchanges2[] = {exchange8, exchange1, exchange2}; - - std::span exchangesSpan1 = kAllExchanges1; - std::span exchangesSpan2 = kAllExchanges2; + Exchange kAllExchanges[] = {std::move(exchange1), std::move(exchange2), std::move(exchange4)}; - for (auto exchangesSpan : {exchangesSpan1, exchangesSpan2}) { - ExchangeRetriever exchangeRetriever(exchangesSpan); + for (int pos = 0; pos < 2; ++pos) { + ExchangeRetriever exchangeRetriever(kAllExchanges); ExchangeNames names{ExchangeName("kraken"), ExchangeName("bithumb")}; ExchangeRetriever::UniquePublicSelectedExchanges selectedExchanges = exchangeRetriever.selectOneAccount(names); @@ -192,24 +180,24 @@ TEST_F(ExchangeRetrieverTest, RetrieveAtMostOneAccountSelectedExchanges) { ASSERT_EQ(exchangesInitialOrder.size(), 2U); EXPECT_EQ(exchangesInitialOrder.front()->name(), "bithumb"); EXPECT_EQ(exchangesInitialOrder.back()->name(), "kraken"); + + std::rotate(std::begin(kAllExchanges), std::begin(kAllExchanges) + 2, std::end(kAllExchanges)); } } TEST_F(ExchangeRetrieverTest, RetrieveUniquePublicExchange) { - Exchange kAllExchanges1[] = {exchange1, exchange2, exchange8}; - Exchange kAllExchanges2[] = {exchange8, exchange1, exchange2}; - - std::span exchangesSpan1 = kAllExchanges1; - std::span exchangesSpan2 = kAllExchanges2; + Exchange kAllExchanges[] = {std::move(exchange1), std::move(exchange2), std::move(exchange4)}; - for (auto exchangesSpan : {exchangesSpan1, exchangesSpan2}) { - ExchangeRetriever exchangeRetriever(exchangesSpan); + for (int pos = 0; pos < 2; ++pos) { + ExchangeRetriever exchangeRetriever(kAllExchanges); ExchangeNames names{ExchangeName("kraken"), ExchangeName("bithumb")}; ExchangeRetriever::PublicExchangesVec selectedExchanges = exchangeRetriever.selectPublicExchanges(names); ASSERT_EQ(selectedExchanges.size(), 2U); EXPECT_EQ(selectedExchanges.front()->name(), "kraken"); EXPECT_EQ(selectedExchanges.back()->name(), "bithumb"); + + std::rotate(std::begin(kAllExchanges), std::begin(kAllExchanges) + 2, std::end(kAllExchanges)); } } -} // namespace cct \ No newline at end of file +} // namespace cct diff --git a/src/engine/test/exchangedata_test.hpp b/src/engine/test/exchangedata_test.hpp index 7c98f6da..3df34d68 100644 --- a/src/engine/test/exchangedata_test.hpp +++ b/src/engine/test/exchangedata_test.hpp @@ -2,6 +2,8 @@ #include +#include + #include "coincenterinfo.hpp" #include "commonapi.hpp" #include "exchange.hpp" @@ -13,11 +15,19 @@ namespace cct { class ExchangesBaseTest : public ::testing::Test { protected: + static api::MockExchangePrivate &ExchangePrivate(Exchange &exchange) { + return dynamic_cast(exchange.apiPrivate()); + } + void SetUp() override { - EXPECT_CALL(exchangePrivate5, queryAccountBalance(testing::_)).WillRepeatedly(testing::Return(emptyBalance)); - EXPECT_CALL(exchangePrivate6, queryAccountBalance(testing::_)).WillRepeatedly(testing::Return(emptyBalance)); - EXPECT_CALL(exchangePrivate7, queryAccountBalance(testing::_)).WillRepeatedly(testing::Return(emptyBalance)); - EXPECT_CALL(exchangePrivate8, queryAccountBalance(testing::_)).WillRepeatedly(testing::Return(emptyBalance)); + EXPECT_CALL(ExchangePrivate(exchange5), queryAccountBalance(testing::_)) + .WillRepeatedly(testing::Return(emptyBalance)); + EXPECT_CALL(ExchangePrivate(exchange6), queryAccountBalance(testing::_)) + .WillRepeatedly(testing::Return(emptyBalance)); + EXPECT_CALL(ExchangePrivate(exchange7), queryAccountBalance(testing::_)) + .WillRepeatedly(testing::Return(emptyBalance)); + EXPECT_CALL(ExchangePrivate(exchange8), queryAccountBalance(testing::_)) + .WillRepeatedly(testing::Return(emptyBalance)); } LoadConfiguration loadConfiguration{kDefaultDataDir, LoadConfiguration::ExchangeConfigFileType::kTest}; @@ -34,22 +44,22 @@ class ExchangesBaseTest : public ::testing::Test { api::APIKey key3{"test3", "testuser3", "", "", ""}; api::APIKey key4{"test4", "testuser4", "", "", ""}; api::APIKey key5{"test5", "testuser5", "", "", ""}; - api::MockExchangePrivate exchangePrivate1{exchangePublic1, coincenterInfo, key1}; - api::MockExchangePrivate exchangePrivate2{exchangePublic2, coincenterInfo, key1}; - api::MockExchangePrivate exchangePrivate3{exchangePublic3, coincenterInfo, key1}; - api::MockExchangePrivate exchangePrivate4{exchangePublic3, coincenterInfo, key2}; - api::MockExchangePrivate exchangePrivate5{exchangePublic3, coincenterInfo, key3}; - api::MockExchangePrivate exchangePrivate6{exchangePublic3, coincenterInfo, key4}; - api::MockExchangePrivate exchangePrivate7{exchangePublic3, coincenterInfo, key5}; - api::MockExchangePrivate exchangePrivate8{exchangePublic1, coincenterInfo, key2}; - Exchange exchange1{coincenterInfo.exchangeConfig(exchangePublic1.name()), exchangePublic1, exchangePrivate1}; - Exchange exchange2{coincenterInfo.exchangeConfig(exchangePublic2.name()), exchangePublic2, exchangePrivate2}; - Exchange exchange3{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate3}; - Exchange exchange4{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate4}; - Exchange exchange5{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate5}; - Exchange exchange6{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate6}; - Exchange exchange7{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, exchangePrivate7}; - Exchange exchange8{coincenterInfo.exchangeConfig(exchangePublic1.name()), exchangePublic1, exchangePrivate8}; + Exchange exchange1{coincenterInfo.exchangeConfig(exchangePublic1.name()), exchangePublic1, + std::make_unique(exchangePublic1, coincenterInfo, key1)}; + Exchange exchange2{coincenterInfo.exchangeConfig(exchangePublic2.name()), exchangePublic2, + std::make_unique(exchangePublic2, coincenterInfo, key1)}; + Exchange exchange3{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, + std::make_unique(exchangePublic3, coincenterInfo, key1)}; + Exchange exchange4{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, + std::make_unique(exchangePublic3, coincenterInfo, key2)}; + Exchange exchange5{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, + std::make_unique(exchangePublic3, coincenterInfo, key3)}; + Exchange exchange6{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, + std::make_unique(exchangePublic3, coincenterInfo, key4)}; + Exchange exchange7{coincenterInfo.exchangeConfig(exchangePublic3.name()), exchangePublic3, + std::make_unique(exchangePublic3, coincenterInfo, key5)}; + Exchange exchange8{coincenterInfo.exchangeConfig(exchangePublic1.name()), exchangePublic1, + std::make_unique(exchangePublic1, coincenterInfo, key2)}; static constexpr Market m1{"ETH", "EUR"}; static constexpr Market m2{"BTC", "EUR"}; diff --git a/src/engine/test/exchangesorchestrator_private_test.cpp b/src/engine/test/exchangesorchestrator_private_test.cpp index f8793943..5e9ca1ce 100644 --- a/src/engine/test/exchangesorchestrator_private_test.cpp +++ b/src/engine/test/exchangesorchestrator_private_test.cpp @@ -40,7 +40,8 @@ class ExchangeOrchestratorTest : public ExchangesBaseTest { }; TEST_F(ExchangeOrchestratorTest, BalanceNoEquivalentCurrencyUniqueExchange) { - EXPECT_CALL(exchangePrivate1, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(balanceOptions)) + .WillOnce(testing::Return(balancePortfolio1)); const ExchangeName privateExchangeNames[1] = {ExchangeName(exchange1.name(), exchange1.keyName())}; BalancePerExchange ret{{&exchange1, balancePortfolio1}}; @@ -48,9 +49,12 @@ TEST_F(ExchangeOrchestratorTest, BalanceNoEquivalentCurrencyUniqueExchange) { } TEST_F(ExchangeOrchestratorTest, BalanceNoEquivalentCurrencySeveralExchanges) { - EXPECT_CALL(exchangePrivate1, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(balanceOptions)) + .WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(balanceOptions)) + .WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(balanceOptions)) + .WillOnce(testing::Return(balancePortfolio3)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange3.name(), exchange3.keyName()), ExchangeName(exchange1.name(), exchange1.keyName()), @@ -70,11 +74,11 @@ TEST_F(ExchangeOrchestratorTest, DepositInfoUniqueExchanges) { CurrencyExchange::Withdraw::kAvailable, Type::kCrypto), CurrencyExchange("XRP", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate2, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); + EXPECT_CALL(ExchangePrivate(exchange2), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); Wallet wallet2{privateExchangeNames[0], depositCurrency, "address1", "", WalletCheck(), AccountOwner("en_name", "ko_name")}; - EXPECT_CALL(exchangePrivate2, queryDepositWallet(depositCurrency)).WillOnce(testing::Return(wallet2)); + EXPECT_CALL(ExchangePrivate(exchange2), queryDepositWallet(depositCurrency)).WillOnce(testing::Return(wallet2)); WalletPerExchange ret{{&exchange2, wallet2}}; EXPECT_EQ(exchangesOrchestrator.getDepositInfo(privateExchangeNames, depositCurrency), ret); @@ -92,11 +96,11 @@ TEST_F(ExchangeOrchestratorTest, DepositInfoSeveralExchangesWithUnavailableDepos CurrencyExchange::Withdraw::kAvailable, Type::kCrypto), CurrencyExchange("SHIB", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate1, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies1)); + EXPECT_CALL(ExchangePrivate(exchange1), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies1)); CurrencyExchangeFlatSet tradableCurrencies2{CurrencyExchangeVector{CurrencyExchange( "XLM", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate2, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); + EXPECT_CALL(ExchangePrivate(exchange2), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); CurrencyExchangeFlatSet tradableCurrencies3{CurrencyExchangeVector{ CurrencyExchange("BTC", CurrencyExchange::Deposit::kUnavailable, CurrencyExchange::Withdraw::kUnavailable, @@ -108,16 +112,16 @@ TEST_F(ExchangeOrchestratorTest, DepositInfoSeveralExchangesWithUnavailableDepos CurrencyExchange("EUR", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kFiat), }}; - EXPECT_CALL(exchangePrivate3, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies3)); - EXPECT_CALL(exchangePrivate4, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies3)); + EXPECT_CALL(ExchangePrivate(exchange3), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies3)); Wallet wallet31{privateExchangeNames[2], depositCurrency, "address2", "tag2", WalletCheck(), AccountOwner("en_name", "ko_name")}; - EXPECT_CALL(exchangePrivate3, queryDepositWallet(depositCurrency)).WillOnce(testing::Return(wallet31)); + EXPECT_CALL(ExchangePrivate(exchange3), queryDepositWallet(depositCurrency)).WillOnce(testing::Return(wallet31)); Wallet wallet32{privateExchangeNames[3], depositCurrency, "address3", "tag3", WalletCheck(), AccountOwner("en_name", "ko_name")}; - EXPECT_CALL(exchangePrivate4, queryDepositWallet(depositCurrency)).WillOnce(testing::Return(wallet32)); + EXPECT_CALL(ExchangePrivate(exchange4), queryDepositWallet(depositCurrency)).WillOnce(testing::Return(wallet32)); WalletPerExchange ret{{&exchange3, wallet31}, {&exchange4, wallet32}}; EXPECT_EQ(exchangesOrchestrator.getDepositInfo(privateExchangeNames, depositCurrency), ret); @@ -134,16 +138,16 @@ TEST_F(ExchangeOrchestratorTest, GetOpenedOrders) { MonetaryAmount("0.14BTC"), Clock::now(), TradeSide::kBuy), OpenedOrder("Id2", MonetaryAmount("15XLM"), MonetaryAmount("76XLM"), MonetaryAmount("0.5EUR"), Clock::now(), TradeSide::kSell)}; - EXPECT_CALL(exchangePrivate2, queryOpenedOrders(noConstraints)).WillOnce(testing::Return(openedOrders2)); + EXPECT_CALL(ExchangePrivate(exchange2), queryOpenedOrders(noConstraints)).WillOnce(testing::Return(openedOrders2)); OpenedOrderVector openedOrders3{}; - EXPECT_CALL(exchangePrivate3, queryOpenedOrders(noConstraints)).WillOnce(testing::Return(openedOrders3)); + EXPECT_CALL(ExchangePrivate(exchange3), queryOpenedOrders(noConstraints)).WillOnce(testing::Return(openedOrders3)); OpenedOrderVector openedOrders4{OpenedOrder("Id37", MonetaryAmount("0.7ETH"), MonetaryAmount("0.9ETH"), MonetaryAmount("0.14BTC"), Clock::now(), TradeSide::kSell), OpenedOrder("Id2", MonetaryAmount("15XLM"), MonetaryAmount("19XLM"), MonetaryAmount("0.5EUR"), Clock::now(), TradeSide::kBuy)}; - EXPECT_CALL(exchangePrivate4, queryOpenedOrders(noConstraints)).WillOnce(testing::Return(openedOrders4)); + EXPECT_CALL(ExchangePrivate(exchange4), queryOpenedOrders(noConstraints)).WillOnce(testing::Return(openedOrders4)); OpenedOrdersPerExchange ret{{&exchange2, OpenedOrderSet(openedOrders2.begin(), openedOrders2.end())}, {&exchange3, OpenedOrderSet(openedOrders3.begin(), openedOrders3.end())}, @@ -169,13 +173,13 @@ TEST_F(ExchangeOrchestratorTest, WithdrawImpossibleFrom) { CurrencyExchange::Withdraw::kUnavailable, Type::kCrypto), CurrencyExchange("SHIB", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate1, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies1)); + EXPECT_CALL(ExchangePrivate(exchange1), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies1)); CurrencyExchangeFlatSet tradableCurrencies2{ CurrencyExchangeVector{CurrencyExchange(grossAmount.currencyCode(), CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto), CurrencyExchange("SHIB", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate2, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); + EXPECT_CALL(ExchangePrivate(exchange2), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); auto [exchanges, deliveredWithdrawInfo] = exchangesOrchestrator.withdraw(grossAmount, false, fromExchange, toExchange, withdrawOptions); @@ -192,13 +196,13 @@ TEST_F(ExchangeOrchestratorTest, WithdrawImpossibleTo) { CurrencyExchange::Withdraw::kAvailable, Type::kCrypto), CurrencyExchange("SHIB", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate1, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies1)); + EXPECT_CALL(ExchangePrivate(exchange1), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies1)); CurrencyExchangeFlatSet tradableCurrencies2{ CurrencyExchangeVector{CurrencyExchange(grossAmount.currencyCode(), CurrencyExchange::Deposit::kUnavailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto), CurrencyExchange("SHIB", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate2, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); + EXPECT_CALL(ExchangePrivate(exchange2), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); auto [exchanges, deliveredWithdrawInfo] = exchangesOrchestrator.withdraw(grossAmount, false, fromExchange, toExchange, withdrawOptions); @@ -233,30 +237,31 @@ class ExchangeOrchestratorWithdrawTest : public ExchangeOrchestratorTest { CurrencyExchange("SHIB", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate1, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies1)); - EXPECT_CALL(exchangePrivate2, queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); + EXPECT_CALL(ExchangePrivate(exchange1), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryTradableCurrencies()).WillOnce(testing::Return(tradableCurrencies2)); } DeliveredWithdrawInfo createWithdrawInfo(MonetaryAmount grossAmount, bool isPercentageWithdraw) { if (isPercentageWithdraw) { - EXPECT_CALL(exchangePrivate1, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(balanceOptions)) + .WillOnce(testing::Return(balancePortfolio1)); grossAmount = (grossAmount.toNeutral() * balancePortfolio1.get(cur)) / 100; } else { - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).Times(0); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).Times(0); } MonetaryAmount netEmittedAmount = grossAmount - fee; Wallet receivingWallet{toExchange, cur, "TestAddress", "TestTag", WalletCheck(), AccountOwner("SmithJohn", "스미스존")}; - EXPECT_CALL(exchangePrivate2, queryDepositWallet(cur)).WillOnce(testing::Return(receivingWallet)); + EXPECT_CALL(ExchangePrivate(exchange2), queryDepositWallet(cur)).WillOnce(testing::Return(receivingWallet)); api::InitiatedWithdrawInfo initiatedWithdrawInfo{receivingWallet, withdrawId, grossAmount}; - EXPECT_CALL(exchangePrivate1, launchWithdraw(grossAmount, std::move(receivingWallet))) + EXPECT_CALL(ExchangePrivate(exchange1), launchWithdraw(grossAmount, std::move(receivingWallet))) .WillOnce(testing::Return(initiatedWithdrawInfo)); api::SentWithdrawInfo sentWithdrawInfo{netEmittedAmount, fee, Withdraw::Status::kSuccess}; - EXPECT_CALL(exchangePrivate1, queryRecentWithdraws(testing::_)) + EXPECT_CALL(ExchangePrivate(exchange1), queryRecentWithdraws(testing::_)) .WillOnce(testing::Return( WithdrawsSet{Withdraw{withdrawId, withdrawTimestamp, netEmittedAmount, Withdraw::Status::kSuccess, fee}})); - EXPECT_CALL(exchangePrivate2, queryWithdrawDelivery(initiatedWithdrawInfo, sentWithdrawInfo)) + EXPECT_CALL(ExchangePrivate(exchange2), queryWithdrawDelivery(initiatedWithdrawInfo, sentWithdrawInfo)) .WillOnce(testing::Return(netEmittedAmount)); return {std::move(initiatedWithdrawInfo), netEmittedAmount}; } diff --git a/src/engine/test/exchangesorchestrator_public_test.cpp b/src/engine/test/exchangesorchestrator_public_test.cpp index 0bc06b7e..b5c0f047 100644 --- a/src/engine/test/exchangesorchestrator_public_test.cpp +++ b/src/engine/test/exchangesorchestrator_public_test.cpp @@ -185,7 +185,7 @@ TEST_F(ExchangeOrchestratorTest, GetExchangesTradingCurrency) { CurrencyExchange::Withdraw::kAvailable, Type::kCrypto), CurrencyExchange("SHIB", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kCrypto)}}; - EXPECT_CALL(exchangePrivate1, queryTradableCurrencies()) + EXPECT_CALL(ExchangePrivate(exchange1), queryTradableCurrencies()) .Times(2) .WillRepeatedly(testing::Return(tradableCurrencies1)); @@ -199,7 +199,7 @@ TEST_F(ExchangeOrchestratorTest, GetExchangesTradingCurrency) { CurrencyExchange("EUR", CurrencyExchange::Deposit::kAvailable, CurrencyExchange::Withdraw::kAvailable, Type::kFiat), }}; - EXPECT_CALL(exchangePrivate3, queryTradableCurrencies()) + EXPECT_CALL(ExchangePrivate(exchange3), queryTradableCurrencies()) .Times(2) .WillRepeatedly(testing::Return(tradableCurrencies3)); diff --git a/src/engine/test/exchangesorchestrator_trade_test.cpp b/src/engine/test/exchangesorchestrator_trade_test.cpp index 46657ecd..5efd1482 100644 --- a/src/engine/test/exchangesorchestrator_trade_test.cpp +++ b/src/engine/test/exchangesorchestrator_trade_test.cpp @@ -180,28 +180,28 @@ class ExchangeOrchestratorTradeTest : public ExchangeOrchestratorTest { // EXPECT_CALL does not allow references. Or I did not found the way to make it work, so we use ugly macros here switch (exchangePrivateNum) { case 1: - EXPECT_TRADE(exchangePublic1, exchangePrivate1) + EXPECT_TRADE(exchangePublic1, ExchangePrivate(exchange1)) break; case 2: - EXPECT_TRADE(exchangePublic2, exchangePrivate2) + EXPECT_TRADE(exchangePublic2, ExchangePrivate(exchange2)) break; case 3: - EXPECT_TRADE(exchangePublic3, exchangePrivate3) + EXPECT_TRADE(exchangePublic3, ExchangePrivate(exchange3)) break; case 4: - EXPECT_TRADE(exchangePublic3, exchangePrivate4) + EXPECT_TRADE(exchangePublic3, ExchangePrivate(exchange4)) break; case 5: - EXPECT_TRADE(exchangePublic3, exchangePrivate5) + EXPECT_TRADE(exchangePublic3, ExchangePrivate(exchange5)) break; case 6: - EXPECT_TRADE(exchangePublic3, exchangePrivate6) + EXPECT_TRADE(exchangePublic3, ExchangePrivate(exchange6)) break; case 7: - EXPECT_TRADE(exchangePublic3, exchangePrivate7) + EXPECT_TRADE(exchangePublic3, ExchangePrivate(exchange7)) break; case 8: - EXPECT_TRADE(exchangePublic1, exchangePrivate8) + EXPECT_TRADE(exchangePublic1, ExchangePrivate(exchange8)) break; default: throw exception("Unexpected exchange number "); @@ -271,28 +271,28 @@ class ExchangeOrchestratorTradeTest : public ExchangeOrchestratorTest { // EXPECT_CALL does not allow references. Or I did not found the way to make it work, so we use ugly macros here switch (exchangePrivateNum) { case 1: - EXPECT_TWO_STEP_TRADE(exchangePublic1, exchangePrivate1, market1, market2) + EXPECT_TWO_STEP_TRADE(exchangePublic1, ExchangePrivate(exchange1), market1, market2) break; case 2: - EXPECT_TWO_STEP_TRADE(exchangePublic2, exchangePrivate2, market1, market2) + EXPECT_TWO_STEP_TRADE(exchangePublic2, ExchangePrivate(exchange2), market1, market2) break; case 3: - EXPECT_TWO_STEP_TRADE(exchangePublic3, exchangePrivate3, market1, market2) + EXPECT_TWO_STEP_TRADE(exchangePublic3, ExchangePrivate(exchange3), market1, market2) break; case 4: - EXPECT_TWO_STEP_TRADE(exchangePublic3, exchangePrivate4, market1, market2) + EXPECT_TWO_STEP_TRADE(exchangePublic3, ExchangePrivate(exchange4), market1, market2) break; case 5: - EXPECT_TWO_STEP_TRADE(exchangePublic3, exchangePrivate5, market1, market2) + EXPECT_TWO_STEP_TRADE(exchangePublic3, ExchangePrivate(exchange5), market1, market2) break; case 6: - EXPECT_TWO_STEP_TRADE(exchangePublic3, exchangePrivate6, market1, market2) + EXPECT_TWO_STEP_TRADE(exchangePublic3, ExchangePrivate(exchange6), market1, market2) break; case 7: - EXPECT_TWO_STEP_TRADE(exchangePublic3, exchangePrivate7, market1, market2) + EXPECT_TWO_STEP_TRADE(exchangePublic3, ExchangePrivate(exchange7), market1, market2) break; case 8: - EXPECT_TWO_STEP_TRADE(exchangePublic1, exchangePrivate8, market1, market2) + EXPECT_TWO_STEP_TRADE(exchangePublic1, ExchangePrivate(exchange8), market1, market2) break; default: throw exception("Unexpected exchange number "); @@ -335,8 +335,10 @@ TEST_F(ExchangeOrchestratorTradeTest, NoAvailableAmountToSell) { const ExchangeName privateExchangeNames[] = {ExchangeName(exchange1.name(), exchange1.keyName()), ExchangeName(exchange2.name(), exchange2.keyName())}; - EXPECT_CALL(exchangePrivate1, queryAccountBalance(BalanceOptions())).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(BalanceOptions())).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(BalanceOptions())) + .WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(BalanceOptions())) + .WillOnce(testing::Return(balancePortfolio2)); MonetaryAmount zero(0, from.currencyCode()); expectSingleTrade(2, zero, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectNoCall, @@ -357,10 +359,12 @@ TEST_F(ExchangeOrchestratorTradeTest, TwoAccountsSameExchangeSell) { ExchangeName(exchange4.name(), exchange4.keyName())}; // 1.5ETH - EXPECT_CALL(exchangePrivate3, queryAccountBalance(BalanceOptions())).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(BalanceOptions())) + .WillOnce(testing::Return(balancePortfolio1)); // 0.6ETH - EXPECT_CALL(exchangePrivate4, queryAccountBalance(BalanceOptions())).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(BalanceOptions())) + .WillOnce(testing::Return(balancePortfolio3)); MonetaryAmount traded1("1.5 ETH"); MonetaryAmount traded2("0.5 ETH"); @@ -380,10 +384,10 @@ TEST_F(ExchangeOrchestratorTradeTest, ThreeExchangesBuy) { CurrencyCode toCurrency("LUNA"); TradeSide side = TradeSide::kBuy; - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); MonetaryAmount from1(5000, fromCurrency); MonetaryAmount from2(6750, fromCurrency); @@ -409,10 +413,10 @@ TEST_F(ExchangeOrchestratorTradeTest, ThreeExchangesBuyNotEnoughAmount) { CurrencyCode toCurrency("LUNA"); TradeSide side = TradeSide::kBuy; - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); MonetaryAmount from1(0, fromCurrency); MonetaryAmount from2(6750, fromCurrency); @@ -441,15 +445,15 @@ TEST_F(ExchangeOrchestratorTradeTest, ManyAccountsTrade) { CurrencyCode toCurrency("LUNA"); TradeSide side = TradeSide::kBuy; - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); - EXPECT_CALL(exchangePrivate5, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate6, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate7, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate8, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange5), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange6), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange7), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange8), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); MonetaryAmount from1(5000, fromCurrency); MonetaryAmount from2(6750, fromCurrency); @@ -492,7 +496,7 @@ TEST_F(ExchangeOrchestratorTradeTest, SingleExchangeBuyAll) { const ExchangeName privateExchangeNames[] = {ExchangeName(exchange3.name(), exchange3.keyName())}; - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); MonetaryAmount from(1500, fromCurrency); TradedAmounts tradedAmounts3 = expectSingleTrade(3, from, toCurrency, side, TradableMarkets::kExpectCall, @@ -514,9 +518,9 @@ TEST_F(ExchangeOrchestratorTradeTest, TwoExchangesSellAll) { ExchangeName(exchange2.name(), exchange2.keyName()), ExchangeName(exchange3.name(), exchange3.keyName())}; - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); const auto from1 = balancePortfolio1.get(fromCurrency); const auto from3 = balancePortfolio3.get(fromCurrency); @@ -542,10 +546,10 @@ TEST_F(ExchangeOrchestratorTradeTest, AllExchangesBuyAllOneMarketUnavailable) { ExchangeName(exchange1.name(), exchange1.keyName()), ExchangeName(exchange3.name(), exchange3.keyName()), ExchangeName(exchange2.name(), exchange2.keyName()), ExchangeName(exchange4.name(), exchange4.keyName())}; - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); expectSingleTrade(1, MonetaryAmount(0, fromCurrency), toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectNoCall, AllOrderBooks::kExpectNoCall, false); @@ -580,7 +584,7 @@ TEST_F(ExchangeOrchestratorTradeTest, SingleExchangeSmartBuy) { TradedAmounts tradedAmounts1 = expectSingleTrade(1, from1, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectCall, AllOrderBooks::kExpectCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange1.name(), exchange1.keyName())}; @@ -600,7 +604,7 @@ TEST_F(ExchangeOrchestratorTradeTest, SingleExchangeSmartBuyTwoSteps) { TradedAmounts tradedAmounts1 = expectTwoStepTrade(1, from1, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectCall, AllOrderBooks::kExpectCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange1.name(), exchange1.keyName())}; @@ -624,8 +628,8 @@ TEST_F(ExchangeOrchestratorTradeTest, TwoExchangesSmartBuy) { TradedAmounts tradedAmounts32 = expectSingleTrade(3, from32, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectCall, AllOrderBooks::kExpectCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange3.name(), exchange3.keyName()), ExchangeName(exchange1.name(), exchange1.keyName())}; @@ -649,8 +653,8 @@ TEST_F(ExchangeOrchestratorTradeTest, TwoExchangesSmartBuyNoMarketOnOneExchange) TradedAmounts tradedAmounts3 = expectSingleTrade(3, from3, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectCall, AllOrderBooks::kExpectCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange3.name(), exchange3.keyName()), ExchangeName(exchange1.name(), exchange1.keyName())}; @@ -683,9 +687,9 @@ TEST_F(ExchangeOrchestratorTradeTest, ThreeExchangesSmartBuy) { TradedAmounts tradedAmounts4 = expectSingleTrade(4, from42, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectCall, AllOrderBooks::kExpectCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange4.name(), exchange4.keyName()), ExchangeName(exchange2.name(), exchange2.keyName()), @@ -721,10 +725,10 @@ TEST_F(ExchangeOrchestratorTradeTest, SmartBuyAllExchanges) { TradedAmounts tradedAmounts42 = expectSingleTrade(4, from42, toCurrency, side, TradableMarkets::kNoExpectation, OrderBook::kNoExpectation, AllOrderBooks::kNoExpectation, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); TradeResultPerExchange tradeResultPerExchange{std::make_pair(&exchange2, TradeResult(tradedAmounts2, from2)), std::make_pair(&exchange1, TradeResult(tradedAmounts1, from1)), @@ -745,7 +749,7 @@ TEST_F(ExchangeOrchestratorTradeTest, SingleExchangeSmartSell) { TradedAmounts tradedAmounts1 = expectSingleTrade(1, from1, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectCall, AllOrderBooks::kExpectNoCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange1.name(), exchange1.keyName())}; @@ -761,10 +765,10 @@ TEST_F(ExchangeOrchestratorTradeTest, SmartSellAllNoAvailableAmount) { EXPECT_CALL(exchangePublic2, queryTradableMarkets()).Times(0); EXPECT_CALL(exchangePublic3, queryTradableMarkets()).Times(0); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); EXPECT_TRUE(exchangesOrchestrator.smartSell(startAmount, true, ExchangeNames{}, tradeOptions).empty()); } @@ -783,8 +787,8 @@ TEST_F(ExchangeOrchestratorTradeTest, TwoExchangesSmartSell) { TradedAmounts tradedAmounts2 = expectSingleTrade(2, from2, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectCall, AllOrderBooks::kExpectNoCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange1.name(), exchange1.keyName()), ExchangeName(exchange2.name(), exchange2.keyName())}; @@ -809,8 +813,8 @@ TEST_F(ExchangeOrchestratorTradeTest, TwoExchangesSmartSellPercentage) { expectSingleTrade(3, from3, toCurrency, side, TradableMarkets::kExpectNoCall, OrderBook::kExpectNoCall, AllOrderBooks::kExpectNoCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange1.name(), exchange1.keyName()), ExchangeName(exchange3.name(), exchange3.keyName())}; @@ -833,8 +837,8 @@ TEST_F(ExchangeOrchestratorTradeTest, TwoExchangesSmartSellNoMarketOnOneExchange TradedAmounts tradedAmounts2 = expectSingleTrade(2, from2, toCurrency, side, TradableMarkets::kExpectCall, OrderBook::kExpectCall, AllOrderBooks::kExpectNoCall, true); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange2.name(), exchange2.keyName()), ExchangeName(exchange3.name(), exchange3.keyName())}; @@ -860,9 +864,9 @@ TEST_F(ExchangeOrchestratorTradeTest, ThreeExchangesSmartSellFromAnotherPreferre TradedAmounts tradedAmounts4 = expectSingleTrade(4, from4, toCurrency, side, TradableMarkets::kNoExpectation, OrderBook::kNoExpectation, AllOrderBooks::kExpectNoCall, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); const ExchangeName privateExchangeNames[] = {ExchangeName(exchange4.name(), exchange4.keyName()), ExchangeName(exchange1.name(), exchange1.keyName()), @@ -893,10 +897,10 @@ TEST_F(ExchangeOrchestratorTradeTest, SmartSellAllExchanges) { expectSingleTrade(4, from4, toCurrency, side, TradableMarkets::kNoExpectation, OrderBook::kNoExpectation, AllOrderBooks::kNoExpectation, true); - EXPECT_CALL(exchangePrivate1, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); - EXPECT_CALL(exchangePrivate2, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); - EXPECT_CALL(exchangePrivate3, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); - EXPECT_CALL(exchangePrivate4, queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); + EXPECT_CALL(ExchangePrivate(exchange1), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio1)); + EXPECT_CALL(ExchangePrivate(exchange2), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio2)); + EXPECT_CALL(ExchangePrivate(exchange3), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio3)); + EXPECT_CALL(ExchangePrivate(exchange4), queryAccountBalance(testing::_)).WillOnce(testing::Return(balancePortfolio4)); TradeResultPerExchange tradeResultPerExchange{std::make_pair(&exchange1, TradeResult(tradedAmounts1, from1))}; EXPECT_EQ(tradeResultPerExchange, exchangesOrchestrator.smartSell(startAmount, false, ExchangeNames{}, tradeOptions)); diff --git a/src/tech/include/simpletable.hpp b/src/tech/include/simpletable.hpp index 565b00c3..c5764f24 100644 --- a/src/tech/include/simpletable.hpp +++ b/src/tech/include/simpletable.hpp @@ -31,6 +31,19 @@ namespace cct { /// It is also possible to force a line separator between any row in the print. For that, you can insert the special Row /// Row::kDivider at the desired place in the SimpleTable. /// See the unit test to have an overview of its usage and the look and feel of the print. +/// Example: +/// +/// +---------------+----------+-----------------------+ +/// | Amount | Currency | This header is longer | +/// +---------------+----------+-----------------------+ +/// | 1235 | EUR | Nothing here | +/// | 3456.78 | USD | 42 | +/// | -677234.67 | SUSHI | -12 | +/// | -677256340000 | KEBAB | -34.09 | +/// |~~~~~~~~~~~~~~~|~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~| +/// | 12 | | Nothing here | +/// | -4 | | | +/// +---------------+----------+-----------------------+ class SimpleTable { public: class Row;