From ed48ba54b22c1af65123ef02e4f90607c3cfdbac Mon Sep 17 00:00:00 2001 From: Stephane Janel Date: Fri, 1 Mar 2024 19:46:32 +0100 Subject: [PATCH] [Feature] - New CLI option market-data --- src/api/interface/src/exchange.cpp | 6 ++-- src/engine/include/coincenter.hpp | 4 +++ src/engine/include/coincentercommand.hpp | 3 +- src/engine/include/coincenteroptions.hpp | 5 +-- src/engine/include/coincenteroptionsdef.hpp | 11 +++--- src/engine/include/exchangesorchestrator.hpp | 2 ++ src/engine/include/queryresulttypes.hpp | 3 +- src/engine/src/coincenter.cpp | 34 +++++++++++++++++-- src/engine/src/coincentercommands.cpp | 11 ++++-- src/engine/src/exchangesorchestrator.cpp | 28 ++++++++++++--- src/engine/test/coincenteroptions_test.cpp | 2 +- src/objects/include/coincentercommandtype.hpp | 1 + src/objects/src/coincentercommandtype.cpp | 2 +- 13 files changed, 87 insertions(+), 25 deletions(-) diff --git a/src/api/interface/src/exchange.cpp b/src/api/interface/src/exchange.cpp index 2f8ffc5b..5a3bddf4 100644 --- a/src/api/interface/src/exchange.cpp +++ b/src/api/interface/src/exchange.cpp @@ -63,7 +63,7 @@ bool Exchange::canWithdraw(CurrencyCode currencyCode, const CurrencyExchangeFlat } bool Exchange::canDeposit(CurrencyCode currencyCode, const CurrencyExchangeFlatSet ¤cyExchangeSet) const { - auto lb = currencyExchangeSet.find(currencyCode); + const auto lb = currencyExchangeSet.find(currencyCode); if (lb == currencyExchangeSet.end()) { log::trace("{} cannot be deposited on {}", currencyCode, name()); return false; @@ -72,7 +72,7 @@ bool Exchange::canDeposit(CurrencyCode currencyCode, const CurrencyExchangeFlatS } MarketOrderBook Exchange::queryOrderBook(Market mk, int depth) { - auto marketOrderBook = _exchangePublic.queryOrderBook(mk, depth); + const auto marketOrderBook = _exchangePublic.queryOrderBook(mk, depth); if (_marketDataSerializerPtr) { _marketDataSerializerPtr->push(marketOrderBook); } @@ -81,7 +81,7 @@ MarketOrderBook Exchange::queryOrderBook(Market mk, int depth) { /// Retrieve an ordered vector of recent last trades TradesVector Exchange::queryLastTrades(Market mk, int nbTrades) { - auto lastTrades = _exchangePublic.queryLastTrades(mk, nbTrades); + const auto lastTrades = _exchangePublic.queryLastTrades(mk, nbTrades); if (_marketDataSerializerPtr) { _marketDataSerializerPtr->push(lastTrades); } diff --git a/src/engine/include/coincenter.hpp b/src/engine/include/coincenter.hpp index 05dd5dc8..ce0b8492 100644 --- a/src/engine/include/coincenter.hpp +++ b/src/engine/include/coincenter.hpp @@ -49,6 +49,10 @@ class Coincenter { CurrencyCode equiCurrencyCode, std::optional depth = std::nullopt); + /// Query market data without returning it. + /// This method is especially useful for serialization and metric exports. + void queryMarketDataPerExchange(Market mk, ExchangeNameSpan exchangeNames); + /// Retrieve the last 24h traded volume for exchanges supporting given market. MonetaryAmountPerExchange getLast24hTradedVolumePerExchange(Market mk, ExchangeNameSpan exchangeNames); diff --git a/src/engine/include/coincentercommand.hpp b/src/engine/include/coincentercommand.hpp index 6e0dad96..60cd2668 100644 --- a/src/engine/include/coincentercommand.hpp +++ b/src/engine/include/coincentercommand.hpp @@ -44,7 +44,6 @@ class CoincenterCommand { CoincenterCommand& setAmount(MonetaryAmount amount); CoincenterCommand& setDepth(int depth); - CoincenterCommand& setNbLastTrades(int nbTrades) { return setDepth(nbTrades); } CoincenterCommand& setMarket(Market market); @@ -70,7 +69,7 @@ class CoincenterCommand { MonetaryAmount amount() const { return _amount; } - int nbLastTrades() const { return _n; } + int depth() const { return _n; } std::optional optDepth() const { return _n == -1 ? std::nullopt : std::optional(_n); } Market market() const { return _market; } diff --git a/src/engine/include/coincenteroptions.hpp b/src/engine/include/coincenteroptions.hpp index 6b16a8c7..1ffe7d6d 100644 --- a/src/engine/include/coincenteroptions.hpp +++ b/src/engine/include/coincenteroptions.hpp @@ -97,13 +97,14 @@ class CoincenterCmdLineOptions { std::string_view lastTrades; + std::string_view marketData; + std::optional replay; std::optional replayMarkets; CommandLineOptionalInt repeats; - int nbLastTrades = api::ExchangePublic::kNbLastTradesDefault; int monitoringPort = CoincenterCmdLineOptionsDefinitions::kDefaultMonitoringPort; - int orderbookDepth = 0; + int depth = 0; bool forceMultiTrade = false; bool forceSingleTrade = false; diff --git a/src/engine/include/coincenteroptionsdef.hpp b/src/engine/include/coincenteroptionsdef.hpp index 5ec85a52..0b0d52f5 100644 --- a/src/engine/include/coincenteroptionsdef.hpp +++ b/src/engine/include/coincenteroptionsdef.hpp @@ -208,8 +208,7 @@ struct CoincenterAllowedOptions : private CoincenterCmdLineOptionsDefinitions { "If conversion of cur2 into cur is possible (for each exchange), " "prints additional column converted to given asset"}, &OptValueType::orderbookCur}, - {{{"Public queries", 2300}, "--depth", "", "Override default depth of order book"}, - &OptValueType::orderbookDepth}, + {{{"Public queries", 2300}, "--depth", "", "Override default depth of order book"}, &OptValueType::depth}, {{{"Public queries", 2400}, "ticker", "<[exch1,...]>", @@ -239,7 +238,7 @@ struct CoincenterAllowedOptions : private CoincenterCmdLineOptionsDefinitions { "Print last trades for market 'cur1'-'cur2' " "for all exchanges (or specified one)"}, &OptValueType::lastTrades}, - {{{"Public queries", 2800}, "--n", "", kLastTradesN}, &OptValueType::nbLastTrades}, + {{{"Public queries", 2800}, "--n", "", kLastTradesN}, &OptValueType::depth}, {{{"Public queries", 2900}, "price", "", @@ -406,15 +405,15 @@ struct CoincenterAllowedOptions : private CoincenterCmdLineOptionsDefinitions { &OptValueType::async}, {{{"Withdraw and deposit", 6010}, "--refresh-time", "