Make security 'formattable'
So it can be used as a param in LOG statements
This commit is contained in:
1 parent
b13725bc09
commit
b1f1987922
2 files changed
+54
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include "spark/domain_model/Side.h"
|
||||
#include "spark/domain_model/Venue.h"
|
||||
#include "spark/domain_model/common.h"
|
||||
#include "spark/domain_model/security_type.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/datetime.h"
|
||||
#include "system/FMT_IMPL.h"
|
||||
@@ -29,6 +30,7 @@ SecurityKey security_key(api::Security const &);
|
||||
std::string to_str(api::Security const &);
|
||||
std::pair<bool, api::Security> from_str(std::string const &);
|
||||
std::string descriptor(api::Security const &);
|
||||
const std::string &exchange_descriptor(const api::Security &sec);
|
||||
api::SecurityType security_type(api::Security const &);
|
||||
|
||||
inline std::string const &side_name(api::Side side) {
|
||||
@@ -236,6 +238,38 @@ inline Price tick_size(api::Security const &sec) {
|
||||
return Price(sec.contract_spec().low_tick());
|
||||
}
|
||||
|
||||
inline const std::string &exchange_descriptor(const api::Security &sec) {
|
||||
switch (sec.ExchangeData_case()) {
|
||||
case api::Security::kGlbx:
|
||||
return sec.glbx().security_desc();
|
||||
case api::Security::kCboe:
|
||||
return sec.cboe().security_desc();
|
||||
case api::Security::kCfe:
|
||||
return sec.cfe().security_desc();
|
||||
case api::Security::kIce:
|
||||
return sec.ice().security_desc();
|
||||
case api::Security::kDeribit:
|
||||
return sec.deribit().security_desc();
|
||||
case api::Security::kFtx:
|
||||
return sec.ftx().security_desc();
|
||||
case api::Security::kBinance:
|
||||
return sec.binance().security_desc();
|
||||
case api::Security::kBinanceUsdsFutures:
|
||||
return sec.binance_usds_futures().security_desc();
|
||||
case api::Security::kBinanceUs:
|
||||
return sec.binance_us().security_desc();
|
||||
case api::Security::kCoinbase:
|
||||
return sec.coinbase().security_desc();
|
||||
case api::Security::kOkx:
|
||||
return sec.okx().security_desc();
|
||||
case api::Security::kTaifex:
|
||||
return sec.taifex().security_desc();
|
||||
case api::Security::EXCHANGEDATA_NOT_SET: {
|
||||
static std::string default_rv = "EXCHANGEDATA_NOT_SET";
|
||||
return default_rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Looking to round md::IntPrice? Look in IntPrice.h
|
||||
|
||||
// computes price_2 - price_1 in ticks
|
||||
@@ -316,3 +350,5 @@ inline bool is_spread_of_strips(const bts::api::Security &sec) {
|
||||
|
||||
} // namespace securities
|
||||
} // namespace bts
|
||||
|
||||
FMT_IMPL(bts::api::Security, s, "{}", bts::securities::exchange_descriptor(s));
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "system/FMT_IMPL.h"
|
||||
#include "system/enum_macros.h"
|
||||
#include "system/json/json_reader.h"
|
||||
#include "system/logging/logging.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace bts::api {
|
||||
|
||||
PB_ENUM_FROM_JSON(SecurityType)
|
||||
PB_ENUM_TO_JSON(SecurityType)
|
||||
|
||||
} // namespace bts::api
|
||||
|
||||
FMT_IMPL(bts::api::SecurityType, t, "{}", bts::api::SecurityType_Name(t));
|
||||
Reference in new issue
Block a user