Files
spark/src/lib/md/SecurityMapper.cpp
T

93 lines
2.8 KiB
C++

#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<UserSymbol, int> _mapped;
DisplayFactorMapper() : _mapped() {
for (const auto& ov : config::get<DisplayFactorOverride>().override()) {
if (ov.has_price_multiplier()) {
auto venue = parse_enum<api::Venue>(ov.exchange(), "VENUE", api::Venue_Parse);
bts_assert_msg(venue, fmt::format("Invalid venue `{}`", ov.exchange()));
auto type = parse_enum<SecurityType>(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<std::string, double> _map;
CppOverride() : _map() {
for (const auto& p : config::get<config::CppConfig>().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<DisplayFactorMapper>());
_impl.push_back(std::make_unique<CppOverride>());
// 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