#include "SecurityMapper.h" #include "UserSymbol.h" #include "PriceSize.h" #include "lib/config/config.h" #include "lib/config/protos/MarketData.pb.h" #include "lib/config/protos/cme_reference_data.pb.h" #include "lib/domain_model/Security.h" #include "lib/utils/parse_enum.h" #ifndef _WIN32 #include "google/btree/btree_map.h" namespace bts { namespace md { struct DisplayFactorMapper : public ISecurityMapper { btree::btree_map _mapped; DisplayFactorMapper() : _mapped() { for (const auto& ov : config::get().override()) { if (ov.has_price_multiplier()) { auto venue = parse_enum(ov.exchange(), "VENUE", api::Venue_Parse); bts_assert_msg(venue, fmt::format("Invalid venue `{}`", ov.exchange())); auto type = parse_enum(ov.type(), "SECURITYTYPE", api::SecurityType_Parse); if (type) { _mapped.insert( std::make_pair( UserSymbol { uppercase_copy(ov.symbol()), *venue, *type }, -to_exponent(ov.price_multiplier()))); } else { for (auto t : { SecurityType::SECURITYTYPE_FUTURE, SecurityType::SECURITYTYPE_SPREAD, SecurityType::SECURITYTYPE_OPTION }) { _mapped.insert( std::make_pair( UserSymbol { uppercase_copy(ov.symbol()), *venue, t }, -to_exponent(ov.price_multiplier()))); } } } } } void apply(FixedSecurity& f) const override { UserSymbol key { f.symbol(), f.exchange, f.type }; auto iter = _mapped.find(key); if (iter != _mapped.end()) { f.display_factor = iter->second; } } }; struct CppOverride : public ISecurityMapper { btree::btree_map _map; CppOverride() : _map() { for (const auto& p : config::get().cpp_entry()) { _map.insert(p); } } void apply(FixedSecurity& f) const override { auto iter = _map.find(f.symbol()); if (iter != _map.end()) { f.cash_per_point = iter->second; } } }; SecurityMapper::SecurityMapper(bool enabled): _impl() { if (enabled) { _impl.push_back(std::make_unique()); _impl.push_back(std::make_unique()); // Register more mappers HERE } } #else namespace bts { namespace md { SecurityMapper::SecurityMapper(bool): _impl() {} #endif SecurityMapper::~SecurityMapper() { } void SecurityMapper::apply(FixedSecurity& security) { for (const auto& m : _impl) { m->apply(security); } } }} //namespace