100 lines
3.7 KiB
C++
100 lines
3.7 KiB
C++
#include "InstrumentDefinition.h"
|
|
|
|
#include "lib/config/config.h"
|
|
#include "lib/config/protos/cme_reference_data.pb.h"
|
|
#include "lib/logging/logging.h"
|
|
#include "lib/utils/datetime.h"
|
|
#include "lib/utils/helper_macros.h"
|
|
#include "server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.h"
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
|
|
namespace bts::spartan::mdp3 {
|
|
|
|
template <class M> void InstrumentDefinition::init(M m) {
|
|
symbol_ = str_from_fixed_array(m.symbol(), m.symbolEncodingLength());
|
|
security_group_ =
|
|
str_from_fixed_array(m.securityGroup(), m.securityGroupEncodingLength());
|
|
asset_ = str_from_fixed_array(m.asset(), m.assetEncodingLength());
|
|
display_factor_ =
|
|
md::IntPrice(m.displayFactor().mantissa(), m.displayFactor().exponent())
|
|
.price();
|
|
|
|
auto &cpp_map = config::get<config::CppConfig>();
|
|
if (asset_[0] == '0') {
|
|
cash_per_point_ = 1.0; // test products
|
|
} else {
|
|
auto it = cpp_map.cpp_entry().find(asset_);
|
|
if (it == cpp_map.cpp_entry().end()) {
|
|
LOG(Spartan, Error, "Cannot find CPP for {}. Returning 0", asset_);
|
|
cash_per_point_ = 0.0;
|
|
} else
|
|
cash_per_point_ = it->second;
|
|
}
|
|
|
|
security_id_.value() = m.securityID();
|
|
match_algorithm_ = std::string(1, m.matchAlgorithm());
|
|
min_price_increment_ = md::IntPrice(
|
|
m.minPriceIncrement().mantissa(), m.minPriceIncrement().exponent());
|
|
|
|
cme_security_type_ =
|
|
str_from_fixed_array(m.securityType(), m.securityTypeEncodingLength());
|
|
|
|
m.noEvents().forEach([&](auto const &ev) {
|
|
if (ev.eventType() == ::mdp3::EventType::LastEligibleTradeDate) {
|
|
expiration_ = TimeStamp(ev.eventTime());
|
|
}
|
|
});
|
|
// As in the constructor we have to skip over all the arrays
|
|
// that preceed ours
|
|
m.noMDFeedTypes().forEach([](auto const &) {});
|
|
m.noInstAttrib().forEach([this](auto &attr) {
|
|
implied_matching_ = attr.instAttribValue().impliedMatchingEligibility();
|
|
});
|
|
}
|
|
|
|
InstrumentDefinition::InstrumentDefinition(
|
|
::mdp3::MDInstrumentDefinitionOption55 option)
|
|
{
|
|
init(option);
|
|
security_type_ = api::SECURITYTYPE_OPTION;
|
|
min_price_increment_ammount_ = md::IntPrice(
|
|
option.minPriceIncrement().mantissa(),
|
|
option.minPriceIncrement().exponent())
|
|
.price();
|
|
}
|
|
|
|
InstrumentDefinition::InstrumentDefinition(
|
|
::mdp3::MDInstrumentDefinitionFuture54 future) {
|
|
init(future);
|
|
security_type_ = api::SECURITYTYPE_FUTURE;
|
|
min_price_increment_ammount_ = md::IntPrice(
|
|
future.minPriceIncrement().mantissa(),
|
|
future.minPriceIncrement().exponent())
|
|
.price();
|
|
}
|
|
|
|
InstrumentDefinition::InstrumentDefinition(
|
|
::mdp3::MDInstrumentDefinitionSpread56 spread) {
|
|
init(spread);
|
|
security_type_ = api::SECURITYTYPE_SPREAD;
|
|
// The generated code offers a streaming
|
|
// interface. Though you can randomly access
|
|
// the fixed size fields, the arrays have to
|
|
// be transversed in order, even if we do
|
|
// nothing to them.
|
|
spread.noEvents().forEach([](auto const &) {});
|
|
spread.noMDFeedTypes().forEach([](auto const &) {});
|
|
spread.noInstAttrib().forEach([](auto const &) {});
|
|
spread.noLotTypeRules().forEach([](auto const &) {});
|
|
spread.noLegs().forEach([this](auto const &l) {
|
|
LegDef ll{
|
|
SecurityID{l.legSecurityID()},
|
|
l.legSide() == ::mdp3::LegSide::BuySide ? api::SIDE_BUY
|
|
: api::SIDE_SELL,
|
|
Quantity{l.legRatioQty()}};
|
|
legs_.push_back(ll);
|
|
});
|
|
}
|
|
|
|
} // namespace bts::spartan::mdp3
|