SP-184 Revenge of Mapping Part IV
This commit is contained in:
1 parent
632a86f670
commit
8e3a83d314
10 files changed
+145
-19
No files matched your search
@@ -0,0 +1,72 @@
|
||||
#include "SecurityMapper.h"
|
||||
#include "UserSymbol.h"
|
||||
#include "PriceSize.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/MarketData.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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SecurityMapper::SecurityMapper(bool enabled): _impl() {
|
||||
if (enabled) {
|
||||
_impl.push_back(std::make_unique<DisplayFactorMapper>());
|
||||
// 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
|
||||
Reference in new issue
Block a user