Skip to content

Commit

Permalink
Code cleaning - rename LastTradesVectors into TradesVector
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Feb 19, 2024
1 parent 9052cf1 commit b350080
Show file tree
Hide file tree
Showing 36 changed files with 142 additions and 138 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ if(CCT_ENABLE_TESTS)
enable_testing()
endif()

# nlohmann_json - coincenter json library
find_package(nlohmann_json CONFIG)
if(NOT nlohmann_json_FOUND)
FetchContent_Declare(
Expand All @@ -94,6 +95,7 @@ if(NOT nlohmann_json_FOUND)
FetchContent_MakeAvailable(nlohmann_json)
endif()

# spdlog - coincenter logging library
find_package(spdlog CONFIG)
if(NOT spdlog_FOUND)
FetchContent_Declare(
Expand All @@ -115,7 +117,7 @@ if(CCT_BUILD_PROMETHEUS_FROM_SRC)
FetchContent_Declare(
prometheus-cpp
GIT_REPOSITORY https://github.com/jupp0r/prometheus-cpp.git
GIT_TAG v1.2.0
GIT_TAG v1.2.3
)

FetchContent_MakeAvailable(prometheus-cpp)
Expand Down
2 changes: 1 addition & 1 deletion alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Multi stage build to separate docker build image from executable (to make the latter smaller)
FROM alpine:3.19.0 AS build
FROM alpine:3.19.1 AS build

# Install base & build dependencies, needed certificates for curl to work with https
RUN apk add --update --upgrade --no-cache g++ libc-dev curl-dev cmake ninja git ca-certificates
Expand Down
2 changes: 1 addition & 1 deletion src/api-objects/include/exchangepublicapitypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ using MarketSet = FlatSet<Market>;
using MarketOrderBookMap = std::unordered_map<Market, MarketOrderBook>;
using MarketPriceMap = std::unordered_map<Market, MonetaryAmount>;
using MarketsPath = SmallVector<Market, 3>;
using LastTradesVector = vector<PublicTrade>;
using TradesVector = vector<PublicTrade>;
} // namespace cct
1 change: 0 additions & 1 deletion src/api-objects/include/order.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Order {

Market market() const { return Market(_matchedVolume.currencyCode(), _price.currencyCode()); }

/// default ordering by place time first, then matched volume, etc
std::strong_ordering operator<=>(const Order &) const noexcept = default;

using trivially_relocatable = is_trivially_relocatable<OrderId>::type;
Expand Down
2 changes: 1 addition & 1 deletion src/api/common/include/exchangepublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ExchangePublic : public ExchangeBase {
virtual MonetaryAmount queryLast24hVolume(Market mk) = 0;

/// Retrieve an ordered vector of recent last trades
virtual LastTradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) = 0;
virtual TradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) = 0;

/// Retrieve the last price of given market.
virtual MonetaryAmount queryLastPrice(Market mk) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/api/common/include/exchangepublicapi_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MockExchangePublic : public ExchangePublic {
MOCK_METHOD(MarketOrderBookMap, queryAllApproximatedOrderBooks, (int depth), (override));
MOCK_METHOD(MarketOrderBook, queryOrderBook, (Market mk, int depth), (override));
MOCK_METHOD(MonetaryAmount, queryLast24hVolume, (Market mk), (override));
MOCK_METHOD(LastTradesVector, queryLastTrades, (Market mk, int nbTrades), (override));
MOCK_METHOD(TradesVector, queryLastTrades, (Market mk, int nbTrades), (override));
MOCK_METHOD(MonetaryAmount, queryLastPrice, (Market mk), (override));
};
} // namespace cct::api
2 changes: 1 addition & 1 deletion src/api/exchanges/include/binancepublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class BinancePublic : public ExchangePublic {

MonetaryAmount queryLast24hVolume(Market mk) override { return _tradedVolumeCache.get(mk); }

LastTradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;
TradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;

MonetaryAmount queryLastPrice(Market mk) override { return _tickerCache.get(mk); }

Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/include/bithumbpublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class BithumbPublic : public ExchangePublic {

MonetaryAmount queryLast24hVolume(Market mk) override { return _tradedVolumeCache.get(mk); }

LastTradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;
TradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;

MonetaryAmount queryLastPrice(Market mk) override;

Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/include/huobipublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class HuobiPublic : public ExchangePublic {

MonetaryAmount queryLast24hVolume(Market mk) override { return _tradedVolumeCache.get(mk); }

LastTradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;
TradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;

MonetaryAmount queryLastPrice(Market mk) override { return _tickerCache.get(mk); }

Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/include/krakenpublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class KrakenPublic : public ExchangePublic {

MonetaryAmount queryLast24hVolume(Market mk) override { return _tickerCache.get(mk).first; }

LastTradesVector queryLastTrades(Market mk, int nbLastTrades = kNbLastTradesDefault) override;
TradesVector queryLastTrades(Market mk, int nbLastTrades = kNbLastTradesDefault) override;

MonetaryAmount queryLastPrice(Market mk) override { return _tickerCache.get(mk).second; }

Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/include/kucoinpublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class KucoinPublic : public ExchangePublic {

MonetaryAmount queryLast24hVolume(Market mk) override { return _tradedVolumeCache.get(mk); }

LastTradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;
TradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;

MonetaryAmount queryLastPrice(Market mk) override { return _tickerCache.get(mk); }

Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/include/upbitpublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class UpbitPublic : public ExchangePublic {

MonetaryAmount queryLast24hVolume(Market mk) override { return _tradedVolumeCache.get(mk); }

LastTradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;
TradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) override;

MonetaryAmount queryLastPrice(Market mk) override { return _tickerCache.get(mk); }

Expand Down
8 changes: 4 additions & 4 deletions src/api/exchanges/src/binancepublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ MonetaryAmount BinancePublic::sanitizePrice(Market mk, MonetaryAmount pri) {
MonetaryAmount BinancePublic::computePriceForNotional(Market mk, int avgPriceMins) {
if (avgPriceMins == 0) {
// price should be the last matched price
LastTradesVector lastTrades = queryLastTrades(mk, 1);
TradesVector lastTrades = queryLastTrades(mk, 1);
if (!lastTrades.empty()) {
return lastTrades.front().price();
}
Expand Down Expand Up @@ -517,16 +517,16 @@ MonetaryAmount BinancePublic::TradedVolumeFunc::operator()(Market mk) {
return {last24hVol, mk.base()};
}

LastTradesVector BinancePublic::queryLastTrades(Market mk, int nbTrades) {
TradesVector BinancePublic::queryLastTrades(Market mk, int nbTrades) {
if (nbTrades > kMaxNbLastTrades) {
log::warn("{} is larger than maximum number of last trades of {} on {}", nbTrades, kMaxNbLastTrades, _name);
nbTrades = kMaxNbLastTrades;
}
json result = PublicQuery(_commonInfo._curlHandle, "/api/v3/trades",
{{"symbol", mk.assetsPairStrUpper()}, {"limit", nbTrades}});

LastTradesVector ret;
ret.reserve(static_cast<LastTradesVector::size_type>(result.size()));
TradesVector ret;
ret.reserve(static_cast<TradesVector::size_type>(result.size()));
for (const json& detail : result) {
MonetaryAmount amount(detail["qty"].get<std::string_view>(), mk.base());
MonetaryAmount price(detail["price"].get<std::string_view>(), mk.quote());
Expand Down
4 changes: 2 additions & 2 deletions src/api/exchanges/src/bithumbpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ TimePoint EpochTime(std::string&& dateStr) {
}
} // namespace

LastTradesVector BithumbPublic::queryLastTrades(Market mk, [[maybe_unused]] int nbTrades) {
TradesVector BithumbPublic::queryLastTrades(Market mk, [[maybe_unused]] int nbTrades) {
json result = PublicQuery(_curlHandle, "/public/transaction_history/", mk.base(), mk.quote());
LastTradesVector ret;
TradesVector ret;
ret.reserve(result.size());
for (const json& detail : result) {
MonetaryAmount amount(detail["units_traded"].get<std::string_view>(), mk.base());
Expand Down
4 changes: 2 additions & 2 deletions src/api/exchanges/src/huobipublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,12 @@ MonetaryAmount HuobiPublic::TradedVolumeFunc::operator()(Market mk) {
return MonetaryAmount(last24hVol, mk.base());
}

LastTradesVector HuobiPublic::queryLastTrades(Market mk, int nbTrades) {
TradesVector HuobiPublic::queryLastTrades(Market mk, int nbTrades) {
nbTrades = std::min(nbTrades, 2000); // max authorized
nbTrades = std::max(nbTrades, 1); // min authorized
json result =
PublicQuery(_curlHandle, "/market/history/trade", {{"symbol", mk.assetsPairStrLower()}, {"size", nbTrades}});
LastTradesVector ret;
TradesVector ret;
for (const json& detail : result) {
auto dataDetails = detail.find("data");
if (dataDetails != detail.end()) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/exchanges/src/krakenpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ KrakenPublic::TickerFunc::Last24hTradedVolumeAndLatestPricePair KrakenPublic::Ti
throw exception("Invalid data retrieved from ticker information");
}

LastTradesVector KrakenPublic::queryLastTrades(Market mk, int nbLastTrades) {
TradesVector KrakenPublic::queryLastTrades(Market mk, int nbLastTrades) {
Market krakenMarket(_tradableCurrenciesCache.get().getOrThrow(mk.base()).altCode(),
_tradableCurrenciesCache.get().getOrThrow(mk.quote()).altCode());
LastTradesVector ret;
TradesVector ret;
json result = PublicQuery(_curlHandle, "/public/Trades",
{{"pair", krakenMarket.assetsPairStrUpper()}, {"count", nbLastTrades}});
if (!result.empty()) {
Expand Down
6 changes: 3 additions & 3 deletions src/api/exchanges/src/kucoinpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ MonetaryAmount KucoinPublic::TradedVolumeFunc::operator()(Market mk) {
return {amountStr, mk.base()};
}

LastTradesVector KucoinPublic::queryLastTrades(Market mk, [[maybe_unused]] int nbTrades) {
TradesVector KucoinPublic::queryLastTrades(Market mk, [[maybe_unused]] int nbTrades) {
json result = PublicQuery(_curlHandle, "/api/v1/market/histories", GetSymbolPostData(mk));
LastTradesVector ret;
ret.reserve(static_cast<LastTradesVector::size_type>(result.size()));
TradesVector ret;
ret.reserve(static_cast<TradesVector::size_type>(result.size()));
for (const json& detail : result) {
MonetaryAmount amount(detail["size"].get<std::string_view>(), mk.base());
MonetaryAmount price(detail["price"].get<std::string_view>(), mk.quote());
Expand Down
6 changes: 3 additions & 3 deletions src/api/exchanges/src/upbitpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ MonetaryAmount UpbitPublic::TradedVolumeFunc::operator()(Market mk) {
return MonetaryAmount(last24hVol, mk.base());
}

LastTradesVector UpbitPublic::queryLastTrades(Market mk, int nbTrades) {
TradesVector UpbitPublic::queryLastTrades(Market mk, int nbTrades) {
json result = PublicQuery(_curlHandle, "/v1/trades/ticks", {{"count", nbTrades}, {"market", ReverseMarketStr(mk)}});
LastTradesVector ret;
ret.reserve(static_cast<LastTradesVector::size_type>(result.size()));
TradesVector ret;
ret.reserve(static_cast<TradesVector::size_type>(result.size()));
for (const json& detail : result) {
MonetaryAmount amount(detail["trade_volume"].get<double>(), mk.base());
MonetaryAmount price(detail["trade_price"].get<double>(), mk.quote());
Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/test/exchangecommonapi_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class TestAPI {
}
if (!sampleMarkets.empty()) {
Market mk = sampleMarkets.front();
LastTradesVector lastTrades = exchangePublic.queryLastTrades(mk);
TradesVector lastTrades = exchangePublic.queryLastTrades(mk);
if (!lastTrades.empty() && exchangePrivateOpt) {
auto compareTradedVolume = [](const PublicTrade &lhs, const PublicTrade &rhs) {
return lhs.amount() < rhs.amount();
Expand Down
2 changes: 1 addition & 1 deletion src/api/interface/include/exchange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Exchange {
MonetaryAmount queryLast24hVolume(Market mk) { return _exchangePublic.queryLast24hVolume(mk); }

/// Retrieve an ordered vector of recent last trades
LastTradesVector queryLastTrades(Market mk, int nbTrades = ExchangePublic::kNbLastTradesDefault) {
TradesVector queryLastTrades(Market mk, int nbTrades = ExchangePublic::kNbLastTradesDefault) {
return _exchangePublic.queryLastTrades(mk, nbTrades);
}

Expand Down
3 changes: 2 additions & 1 deletion src/engine/include/coincenter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Coincenter {
MonetaryAmountPerExchange getLast24hTradedVolumePerExchange(Market mk, ExchangeNameSpan exchangeNames);

/// Retrieve the last trades for each queried exchange
LastTradesPerExchange getLastTradesPerExchange(Market mk, ExchangeNameSpan exchangeNames, int nbLastTrades);
TradesPerExchange getLastTradesPerExchange(Market mk, ExchangeNameSpan exchangeNames, int nbLastTrades);

/// Retrieve the last price for exchanges supporting given market.
MonetaryAmountPerExchange getLastPricePerExchange(Market mk, ExchangeNameSpan exchangeNames);
Expand All @@ -69,6 +69,7 @@ class Coincenter {
BalancePerExchange getBalance(std::span<const ExchangeName> privateExchangeNames,
const BalanceOptions &balanceOptions);

/// Get deposit information for given accounts
WalletPerExchange getDepositInfo(std::span<const ExchangeName> privateExchangeNames, CurrencyCode depositCurrency);

/// Get opened orders on given list of exchanges following given order constraints
Expand Down
2 changes: 1 addition & 1 deletion src/engine/include/exchangesorchestrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ExchangesOrchestrator {

MonetaryAmountPerExchange getLast24hTradedVolumePerExchange(Market mk, ExchangeNameSpan exchangeNames);

LastTradesPerExchange getLastTradesPerExchange(Market mk, ExchangeNameSpan exchangeNames, int nbLastTrades);
TradesPerExchange getLastTradesPerExchange(Market mk, ExchangeNameSpan exchangeNames, int nbLastTrades);

MonetaryAmountPerExchange getLastPricePerExchange(Market mk, ExchangeNameSpan exchangeNames);

Expand Down
2 changes: 1 addition & 1 deletion src/engine/include/metricsexporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MetricsExporter {

void exportOrderbookMetrics(Market mk, const MarketOrderBookConversionRates &marketOrderBookConversionRates);

void exportLastTradesMetrics(Market mk, const LastTradesPerExchange &lastTradesPerExchange);
void exportLastTradesMetrics(Market mk, const TradesPerExchange &lastTradesPerExchange);

private:
void createSummariesAndHistograms();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/include/queryresultprinter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class QueryResultPrinter {

void printLast24hTradedVolume(Market mk, const MonetaryAmountPerExchange &tradedVolumePerExchange) const;

void printLastTrades(Market mk, int nbLastTrades, const LastTradesPerExchange &lastTradesPerExchange) const;
void printLastTrades(Market mk, int nbLastTrades, const TradesPerExchange &lastTradesPerExchange) const;

void printLastPrice(Market mk, const MonetaryAmountPerExchange &pricePerExchange) const;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/include/queryresulttypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using MonetaryAmountPerExchange = FixedCapacityVector<ExchangeWith<MonetaryAmoun
using MonetaryAmountByCurrencySetPerExchange =
FixedCapacityVector<ExchangeWith<MonetaryAmountByCurrencySet>, kNbSupportedExchanges>;

using LastTradesPerExchange = FixedCapacityVector<ExchangeWith<LastTradesVector>, kNbSupportedExchanges>;
using TradesPerExchange = FixedCapacityVector<ExchangeWith<TradesVector>, kNbSupportedExchanges>;

using TradeResultPerExchange = SmallVector<ExchangeWith<TradeResult>, kTypicalNbPrivateAccounts>;

Expand Down
3 changes: 1 addition & 2 deletions src/engine/src/coincenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ MonetaryAmountPerExchange Coincenter::getLast24hTradedVolumePerExchange(Market m
return _exchangesOrchestrator.getLast24hTradedVolumePerExchange(mk, exchangeNames);
}

LastTradesPerExchange Coincenter::getLastTradesPerExchange(Market mk, ExchangeNameSpan exchangeNames,
int nbLastTrades) {
TradesPerExchange Coincenter::getLastTradesPerExchange(Market mk, ExchangeNameSpan exchangeNames, int nbLastTrades) {
const auto ret = _exchangesOrchestrator.getLastTradesPerExchange(mk, exchangeNames, nbLastTrades);

_metricsExporter.exportLastTradesMetrics(mk, ret);
Expand Down
6 changes: 3 additions & 3 deletions src/engine/src/exchangesorchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,13 +840,13 @@ MonetaryAmountPerExchange ExchangesOrchestrator::getLast24hTradedVolumePerExchan
return tradedVolumePerExchange;
}

LastTradesPerExchange ExchangesOrchestrator::getLastTradesPerExchange(Market mk, ExchangeNameSpan exchangeNames,
int nbLastTrades) {
TradesPerExchange ExchangesOrchestrator::getLastTradesPerExchange(Market mk, ExchangeNameSpan exchangeNames,
int nbLastTrades) {
log::info("Query {} last trades on {} volume from {}", nbLastTrades, mk,
ConstructAccumulatedExchangeNames(exchangeNames));
UniquePublicSelectedExchanges selectedExchanges = getExchangesTradingMarket(mk, exchangeNames);

LastTradesPerExchange ret(selectedExchanges.size());
TradesPerExchange ret(selectedExchanges.size());
_threadPool.parallelTransform(
selectedExchanges.begin(), selectedExchanges.end(), ret.begin(), [mk, nbLastTrades](Exchange *exchange) {
return std::make_pair(static_cast<const Exchange *>(exchange), exchange->queryLastTrades(mk, nbLastTrades));
Expand Down
2 changes: 1 addition & 1 deletion src/engine/src/metricsexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void MetricsExporter::exportOrderbookMetrics(Market mk,
}
}

void MetricsExporter::exportLastTradesMetrics(Market mk, const LastTradesPerExchange &lastTradesPerExchange) {
void MetricsExporter::exportLastTradesMetrics(Market mk, const TradesPerExchange &lastTradesPerExchange) {
RETURN_IF_NO_MONITORING;
MetricKey key = CreateMetricKey("", "All public trades that occurred on the market");
string marketLowerCase = mk.assetsPairStrLower('-');
Expand Down
4 changes: 2 additions & 2 deletions src/engine/src/queryresultprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ json Last24hTradedVolumeJson(Market mk, const MonetaryAmountPerExchange &tradedV
return ToJson(CoincenterCommandType::kLast24hTradedVolume, std::move(in), std::move(out));
}

json LastTradesJson(Market mk, int nbLastTrades, const LastTradesPerExchange &lastTradesPerExchange) {
json LastTradesJson(Market mk, int nbLastTrades, const TradesPerExchange &lastTradesPerExchange) {
json in;
json inOpt;
inOpt.emplace("market", mk.str());
Expand Down Expand Up @@ -1115,7 +1115,7 @@ void QueryResultPrinter::printLast24hTradedVolume(Market mk,
}

void QueryResultPrinter::printLastTrades(Market mk, int nbLastTrades,
const LastTradesPerExchange &lastTradesPerExchange) const {
const TradesPerExchange &lastTradesPerExchange) const {
json jsonData = LastTradesJson(mk, nbLastTrades, lastTradesPerExchange);
switch (_apiOutputType) {
case ApiOutputType::kFormattedTable: {
Expand Down
Loading

0 comments on commit b350080

Please sign in to comment.