diff --git a/src/lib/io/JsonMacros.h b/src/lib/io/JsonMacros.h index c32ea6727..4c1456326 100644 --- a/src/lib/io/JsonMacros.h +++ b/src/lib/io/JsonMacros.h @@ -3,18 +3,14 @@ #define _TO_JSON_FIELD(field) j[#field] = t.field; #define _FROM_JSON_FIELD(field) bts::io::JsonReader{&j, #field}.read(t.field); -#define SPARK_TO_JSON_IMPL(type, for_each) \ - inline void to_json(nlohmann::json &j, const type &t) { \ - FOR_EACH(_TO_JSON_FIELD) \ - } +#define SPARK_TO_JSON_IMPL(type, fields) \ + void to_json(nlohmann::json &j, const type &t) { fields(_TO_JSON_FIELD) } -#define SPARK_FROM_JSON_IMPL(type, for_each) \ - inline void from_json(const nlohmann::json &j, type &t) { \ - FOR_EACH(_FROM_JSON_FIELD) \ - } +#define SPARK_FROM_JSON_IMPL(type, fields) \ + void from_json(const nlohmann::json &j, type &t) { fields(_FROM_JSON_FIELD) } #define OSTREAM_JSON_IMPL(type) \ - inline std::ostream &operator<<(std::ostream &out, const type &t) { \ + std::ostream &operator<<(std::ostream &out, const type &t) { \ nlohmann::json j; \ to_json(j, t); \ out << j.dump(2); \ diff --git a/src/server/sparkd/md/binance/BinanceIcebergPartsFilter.cpp b/src/server/sparkd/md/binance/BinanceIcebergPartsFilter.cpp new file mode 100644 index 000000000..84d510677 --- /dev/null +++ b/src/server/sparkd/md/binance/BinanceIcebergPartsFilter.cpp @@ -0,0 +1,15 @@ +#include "BinanceIcebergPartsFilter.h" +#include "lib/io/JsonMacros.h" +#include "lib/io/JsonReader.h" + +namespace bts::md::binance { + +#define BINANCE_ICEBERG_PARTS_FILTER_FIELDS(op) op(filterType) op(limit) + +SPARK_TO_JSON_IMPL( + BinanceIcebergPartsFilter, BINANCE_ICEBERG_PARTS_FILTER_FIELDS); +SPARK_FROM_JSON_IMPL( + BinanceIcebergPartsFilter, BINANCE_ICEBERG_PARTS_FILTER_FIELDS); +OSTREAM_JSON_IMPL(BinanceIcebergPartsFilter); + +} // namespace bts::md::binance diff --git a/src/server/sparkd/md/binance/BinanceIcebergPartsFilter.h b/src/server/sparkd/md/binance/BinanceIcebergPartsFilter.h index 0e442f92b..d9424e957 100644 --- a/src/server/sparkd/md/binance/BinanceIcebergPartsFilter.h +++ b/src/server/sparkd/md/binance/BinanceIcebergPartsFilter.h @@ -1,7 +1,5 @@ #pragma once -#include "lib/io/JsonMacros.h" -#include "lib/io/JsonReader.h" #include "server/sparkd/md/binance/BinanceFilterType.h" #include @@ -20,16 +18,4 @@ void to_json(nlohmann::json &j, const BinanceIcebergPartsFilter &f); std::ostream &operator<<(std::ostream &out, const BinanceIcebergPartsFilter &f); -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -#define FOR_EACH(op) op(filterType) op(limit) - -SPARK_TO_JSON_IMPL(BinanceIcebergPartsFilter, FOR_EACH); -SPARK_FROM_JSON_IMPL(BinanceIcebergPartsFilter, FOR_EACH); -OSTREAM_JSON_IMPL(BinanceIcebergPartsFilter); - -#undef FOR_EACH - } // namespace bts::md::binance diff --git a/src/server/sparkd/md/binance/BinanceMinNotionalFilter.cpp b/src/server/sparkd/md/binance/BinanceMinNotionalFilter.cpp new file mode 100644 index 000000000..1fdeed9e7 --- /dev/null +++ b/src/server/sparkd/md/binance/BinanceMinNotionalFilter.cpp @@ -0,0 +1,23 @@ +#include "BinanceMinNotionalFilter.h" +#include "lib/io/JsonMacros.h" +#include "lib/io/JsonReader.h" + +#include + +namespace bts::md::binance { + +// clang-format off +#define BINANCE_MIN_NOTIONAL_FILTER_FIELDS(op) \ + op(filterType) \ + op(applyToMarket) \ + op(minNotional) \ + op(avgPriceMins) +// clang-format on + +SPARK_TO_JSON_IMPL( + BinanceMinNotionalFilter, BINANCE_MIN_NOTIONAL_FILTER_FIELDS); +SPARK_FROM_JSON_IMPL( + BinanceMinNotionalFilter, BINANCE_MIN_NOTIONAL_FILTER_FIELDS); +OSTREAM_JSON_IMPL(BinanceMinNotionalFilter); + +} // namespace bts::md::binance diff --git a/src/server/sparkd/md/binance/BinanceMinNotionalFilter.h b/src/server/sparkd/md/binance/BinanceMinNotionalFilter.h index 5c33d2f43..956383ee9 100644 --- a/src/server/sparkd/md/binance/BinanceMinNotionalFilter.h +++ b/src/server/sparkd/md/binance/BinanceMinNotionalFilter.h @@ -1,12 +1,9 @@ #pragma once -#include "lib/io/JsonMacros.h" -#include "lib/io/JsonReader.h" #include "server/sparkd/md/binance/BinanceFilterType.h" #include -#include -#include +#include namespace bts::md::binance { @@ -31,22 +28,4 @@ void to_json(nlohmann::json &j, const BinanceMinNotionalFilter &f); std::ostream &operator<<(std::ostream &out, const BinanceMinNotionalFilter &f); -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -// clang-format off -#define FOR_EACH(op) \ - op(filterType) \ - op(applyToMarket) \ - op(minNotional) \ - op(avgPriceMins) -// clang-format on - -SPARK_TO_JSON_IMPL(BinanceMinNotionalFilter, FOR_EACH); -SPARK_FROM_JSON_IMPL(BinanceMinNotionalFilter, FOR_EACH); -OSTREAM_JSON_IMPL(BinanceMinNotionalFilter); - -#undef FOR_EACH - } // namespace bts::md::binance diff --git a/src/server/sparkd/md/binance/BinanceNotionalFilter.cpp b/src/server/sparkd/md/binance/BinanceNotionalFilter.cpp new file mode 100644 index 000000000..c1fa6d975 --- /dev/null +++ b/src/server/sparkd/md/binance/BinanceNotionalFilter.cpp @@ -0,0 +1,22 @@ +#include "BinanceNotionalFilter.h" +#include "lib/io/JsonMacros.h" +#include "lib/io/JsonReader.h" + +#include + +namespace bts::md::binance { + +// clang-format off +#define FOR_EACH(op) \ + op(filterType) \ + op(applyMaxToMarket) \ + op(applyMinToMarket) \ + op(avgPriceMins) \ + op(maxNotional) \ + op(minNotional) // clang-format on + +SPARK_TO_JSON_IMPL(BinanceNotionalFilter, FOR_EACH); +SPARK_FROM_JSON_IMPL(BinanceNotionalFilter, FOR_EACH); +OSTREAM_JSON_IMPL(BinanceNotionalFilter); + +} // namespace bts::md::binance diff --git a/src/server/sparkd/md/binance/BinanceNotionalFilter.h b/src/server/sparkd/md/binance/BinanceNotionalFilter.h index 56add9963..031096f27 100644 --- a/src/server/sparkd/md/binance/BinanceNotionalFilter.h +++ b/src/server/sparkd/md/binance/BinanceNotionalFilter.h @@ -1,11 +1,8 @@ #pragma once -#include "lib/io/JsonMacros.h" -#include "lib/io/JsonReader.h" #include "server/sparkd/md/binance/BinanceFilterType.h" -#include -#include +#include namespace bts::md::binance { @@ -28,24 +25,4 @@ void from_json(const nlohmann::json &j, BinanceNotionalFilter &f); void to_json(nlohmann::json &j, const BinanceNotionalFilter &f); std::ostream &operator<<(std::ostream &out, const BinanceNotionalFilter &f); -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -// clang-format off -#define FOR_EACH(op) \ - op(filterType) \ - op(applyMaxToMarket) \ - op(applyMinToMarket) \ - op(avgPriceMins) \ - op(maxNotional) \ - op(minNotional) \ -// clang-format on - -SPARK_TO_JSON_IMPL(BinanceNotionalFilter, FOR_EACH); -SPARK_FROM_JSON_IMPL(BinanceNotionalFilter, FOR_EACH); -OSTREAM_JSON_IMPL(BinanceNotionalFilter); - -#undef FOR_EACH - } // namespace bts::md::binance diff --git a/src/server/sparkd/md/binance/BinanceSpot.cpp b/src/server/sparkd/md/binance/BinanceSpot.cpp index f12553e2b..1a0d44475 100644 --- a/src/server/sparkd/md/binance/BinanceSpot.cpp +++ b/src/server/sparkd/md/binance/BinanceSpot.cpp @@ -1,12 +1,13 @@ #include "BinanceSpot.h" -#include "lib/api/domain/Venue.pb.h" #include "lib/domain/Quantity.h" #include "lib/domain/Security.h" +#include "lib/io/JsonMacros.h" #include "lib/io/JsonReader.h" #include "lib/logging/logging.h" #include #include +#include #include #include @@ -90,4 +91,29 @@ void BinanceSpot::parse( } } +// clang-format off +#define BINANCE_SPOT_FIELDS(f) \ + f(symbol) \ + f(status) \ + f(baseAsset) \ + f(baseAssetPrecision) \ + f(quoteAsset) \ + f(quotePrecision) \ + f(quoteAssetPrecision) \ + f(orderTypes) \ + f(icebergAllowed) \ + f(ocoAllowed) \ + f(quoteOrderQtyMarketAllowed) \ + f(allowTrailingStop) \ + f(cancelReplaceAllowed) \ + f(isSpotTradingAllowed) \ + f(isMarginTradingAllowed) \ + f(permissions) \ + f(filters) +// clang-format on + +SPARK_FROM_JSON_IMPL(BinanceSpot, BINANCE_SPOT_FIELDS); +SPARK_TO_JSON_IMPL(BinanceSpot, BINANCE_SPOT_FIELDS); +OSTREAM_JSON_IMPL(BinanceSpot); + } // namespace bts::md::binance diff --git a/src/server/sparkd/md/binance/BinanceSpot.h b/src/server/sparkd/md/binance/BinanceSpot.h index 97f781e19..6f85b8986 100644 --- a/src/server/sparkd/md/binance/BinanceSpot.h +++ b/src/server/sparkd/md/binance/BinanceSpot.h @@ -2,14 +2,13 @@ #include "lib/api/domain/Venue.h" #include "lib/core/FMT_IMPL.h" -#include "lib/io/JsonMacros.h" #include "server/sparkd/md/binance/BinanceFilterTuple.h" #include "server/sparkd/md/binance/BinanceInstrumentStatus.h" #include "server/sparkd/md/binance/BinanceOrderType.h" #include "server/sparkd/md/binance/BinancePermission.h" #include "server/sparkd/md/binance/BinanceQuoteAsset.h" -#include +#include #include #include #include @@ -62,37 +61,6 @@ void from_json(const nlohmann::json &j, BinanceSpot &spot); void to_json(nlohmann::json &j, const BinanceSpot &spot); std::ostream &operator<<(std::ostream &out, const BinanceSpot &spot); -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -// clang-format off -#define FOR_EACH(op) \ - op(symbol) \ - op(status) \ - op(baseAsset) \ - op(baseAssetPrecision) \ - op(quoteAsset) \ - op(quotePrecision) \ - op(quoteAssetPrecision) \ - op(orderTypes) \ - op(icebergAllowed) \ - op(ocoAllowed) \ - op(quoteOrderQtyMarketAllowed) \ - op(allowTrailingStop) \ - op(cancelReplaceAllowed) \ - op(isSpotTradingAllowed) \ - op(isMarginTradingAllowed) \ - op(permissions) \ - op(filters) -// clang-format on - -SPARK_FROM_JSON_IMPL(BinanceSpot, FOR_EACH); -SPARK_TO_JSON_IMPL(BinanceSpot, FOR_EACH); -OSTREAM_JSON_IMPL(BinanceSpot); - -#undef FOR_EACH - } // namespace bts::md::binance FMT_IMPL(bts::md::binance::BinanceSpot, s, "{}", s.symbol); diff --git a/src/server/sparkd/md/binance_coin_futures/binance_coin_futures_price_statistics.cpp b/src/server/sparkd/md/binance_coin_futures/binance_coin_futures_price_statistics.cpp index edb87d18d..7328f9c3d 100644 --- a/src/server/sparkd/md/binance_coin_futures/binance_coin_futures_price_statistics.cpp +++ b/src/server/sparkd/md/binance_coin_futures/binance_coin_futures_price_statistics.cpp @@ -2,11 +2,13 @@ #include "lib/domain/Price.h" #include "lib/domain/Quantity.h" #include "lib/domain/SecurityMarketDataStatistics.h" +#include "lib/io/JsonMacros.h" #include "lib/io/JsonReader.h" #include "server/sparkd/md/ccapi/CCApiReader.h" #include #include +#include #include namespace bts::md::binance_coin_futures { @@ -66,4 +68,33 @@ void BinanceCoinFuturesPriceStatistics::to_security_statistics( result.volume.value() = static_cast(volume); } +// clang-format off +#define BINANCE_COIN_FUTURES_PRICE_STATISTICS_FIELDS(f) \ + f(symbol) \ + f(pair) \ + f(priceChange) \ + f(priceChangePercent) \ + f(weightedAvgPrice) \ + f(lastPrice) \ + f(lastQty) \ + f(openPrice) \ + f(highPrice) \ + f(lowPrice) \ + f(volume) \ + f(baseVolume) \ + f(openTime) \ + f(closeTime) \ + f(firstId) \ + f(lastId) \ + f(count) +// clang-format on + +SPARK_TO_JSON_IMPL( + BinanceCoinFuturesPriceStatistics, + BINANCE_COIN_FUTURES_PRICE_STATISTICS_FIELDS); +SPARK_FROM_JSON_IMPL( + BinanceCoinFuturesPriceStatistics, + BINANCE_COIN_FUTURES_PRICE_STATISTICS_FIELDS); +OSTREAM_JSON_IMPL(BinanceCoinFuturesPriceStatistics) + } // namespace bts::md::binance_coin_futures diff --git a/src/server/sparkd/md/binance_coin_futures/binance_coin_futures_price_statistics.h b/src/server/sparkd/md/binance_coin_futures/binance_coin_futures_price_statistics.h index 2b33a11b9..b21fbffe9 100644 --- a/src/server/sparkd/md/binance_coin_futures/binance_coin_futures_price_statistics.h +++ b/src/server/sparkd/md/binance_coin_futures/binance_coin_futures_price_statistics.h @@ -1,9 +1,6 @@ #pragma once -#include "lib/io/JsonMacros.h" -#include "lib/io/JsonReader.h" - -#include +#include #include #include @@ -53,29 +50,4 @@ class BinanceCoinFuturesPriceStatistics { domain::SecurityMarketDataStatistics &result) const; }; -// clang-format off -#define FOR_EACH(op) \ - op(symbol) \ - op(pair) \ - op(priceChange) \ - op(priceChangePercent) \ - op(weightedAvgPrice) \ - op(lastPrice) \ - op(lastQty) \ - op(openPrice) \ - op(highPrice) \ - op(lowPrice) \ - op(volume) \ - op(baseVolume) \ - op(openTime) \ - op(closeTime) \ - op(firstId) \ - op(lastId) \ - op(count) -// clang-format on - -SPARK_TO_JSON_IMPL(BinanceCoinFuturesPriceStatistics, FOR_EACH); -SPARK_FROM_JSON_IMPL(BinanceCoinFuturesPriceStatistics, FOR_EACH); -OSTREAM_JSON_IMPL(BinanceCoinFuturesPriceStatistics) - } // namespace bts::md::binance_coin_futures diff --git a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesMinNotionalFilter.cpp b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesMinNotionalFilter.cpp new file mode 100644 index 000000000..ec5fe2e7e --- /dev/null +++ b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesMinNotionalFilter.cpp @@ -0,0 +1,23 @@ +#include "BinanceUsdsFuturesMinNotionalFilter.h" +#include "lib/io/JsonMacros.h" +#include "lib/io/JsonReader.h" + +#include + +namespace bts::md::binance_usds_futures { + +// clang-format off +#define BINANCE_USDS_FUTURES_MIN_NOTIONAL_FILTER_FIELDS(f) \ + f(filterType) \ + f(notional) +// clang-format on + +SPARK_TO_JSON_IMPL( + BinanceUsdsFuturesMinNotionalFilter, + BINANCE_USDS_FUTURES_MIN_NOTIONAL_FILTER_FIELDS); +SPARK_FROM_JSON_IMPL( + BinanceUsdsFuturesMinNotionalFilter, + BINANCE_USDS_FUTURES_MIN_NOTIONAL_FILTER_FIELDS); +OSTREAM_JSON_IMPL(BinanceUsdsFuturesMinNotionalFilter); + +} // namespace bts::md::binance_usds_futures diff --git a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesMinNotionalFilter.h b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesMinNotionalFilter.h index e78831a93..d888e797d 100644 --- a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesMinNotionalFilter.h +++ b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesMinNotionalFilter.h @@ -1,12 +1,9 @@ #pragma once -#include "lib/io/JsonMacros.h" -#include "lib/io/JsonReader.h" #include "server/sparkd/md/binance/BinanceFilterType.h" #include -#include -#include +#include namespace bts::md::binance_usds_futures { @@ -31,20 +28,4 @@ void to_json(nlohmann::json &j, const BinanceUsdsFuturesMinNotionalFilter &f); std::ostream &operator<<( std::ostream &out, const BinanceUsdsFuturesMinNotionalFilter &f); -////////////////////////////////////////////////// -// Definition -////////////////////////////////////////////////// - -// clang-format off -#define FOR_EACH(op) \ - op(filterType) \ - op(notional) -// clang-format on - -SPARK_TO_JSON_IMPL(BinanceUsdsFuturesMinNotionalFilter, FOR_EACH); -SPARK_FROM_JSON_IMPL(BinanceUsdsFuturesMinNotionalFilter, FOR_EACH); -OSTREAM_JSON_IMPL(BinanceUsdsFuturesMinNotionalFilter); - -#undef FOR_EACH - } // namespace bts::md::binance_usds_futures diff --git a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesPriceStatistics.cpp b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesPriceStatistics.cpp index 348c3b70e..886600b40 100644 --- a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesPriceStatistics.cpp +++ b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesPriceStatistics.cpp @@ -2,11 +2,13 @@ #include "lib/domain/Price.h" #include "lib/domain/Quantity.h" #include "lib/domain/SecurityMarketDataStatistics.h" +#include "lib/io/JsonMacros.h" #include "lib/io/JsonReader.h" #include "server/sparkd/md/ccapi/CCApiReader.h" #include #include +#include #include namespace bts::md::binance_usds_futures { @@ -67,4 +69,32 @@ void BinanceUsdsFuturesPriceStatistics::to_security_statistics( result.volume.value() = static_cast(volume); } +// clang-format off +#define BINANCE_USDS_FUTURES_PRICE_STATISTICS_FIELDS(f) \ + f(symbol) \ + f(priceChange) \ + f(priceChangePercent) \ + f(weightedAvgPrice) \ + f(lastPrice) \ + f(lastQty) \ + f(openPrice) \ + f(highPrice) \ + f(lowPrice) \ + f(volume) \ + f(quoteVolume) \ + f(openTime) \ + f(closeTime) \ + f(firstId) \ + f(lastId) \ + f(count) +// clang-format on + +SPARK_TO_JSON_IMPL( + BinanceUsdsFuturesPriceStatistics, + BINANCE_USDS_FUTURES_PRICE_STATISTICS_FIELDS); +SPARK_FROM_JSON_IMPL( + BinanceUsdsFuturesPriceStatistics, + BINANCE_USDS_FUTURES_PRICE_STATISTICS_FIELDS); +OSTREAM_JSON_IMPL(BinanceUsdsFuturesPriceStatistics) + } // namespace bts::md::binance_usds_futures diff --git a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesPriceStatistics.h b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesPriceStatistics.h index 3dffbe257..3f3ac7ce5 100644 --- a/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesPriceStatistics.h +++ b/src/server/sparkd/md/binance_usds_futures/BinanceUsdsFuturesPriceStatistics.h @@ -1,9 +1,6 @@ #pragma once -#include "lib/io/JsonMacros.h" -#include "lib/io/JsonReader.h" - -#include +#include #include #include @@ -51,29 +48,4 @@ class BinanceUsdsFuturesPriceStatistics { void to_security_statistics( domain::SecurityMarketDataStatistics &result) const; }; - -// clang-format off -#define FOR_EACH(op) \ - op(symbol) \ - op(priceChange) \ - op(priceChangePercent) \ - op(weightedAvgPrice) \ - op(lastPrice) \ - op(lastQty) \ - op(openPrice) \ - op(highPrice) \ - op(lowPrice) \ - op(volume) \ - op(quoteVolume) \ - op(openTime) \ - op(closeTime) \ - op(firstId) \ - op(lastId) \ - op(count) -// clang-format on - -SPARK_TO_JSON_IMPL(BinanceUsdsFuturesPriceStatistics, FOR_EACH); -SPARK_FROM_JSON_IMPL(BinanceUsdsFuturesPriceStatistics, FOR_EACH); -OSTREAM_JSON_IMPL(BinanceUsdsFuturesPriceStatistics) - } // namespace bts::md::binance_usds_futures