Added expiration to instrument definition.

This commit is contained in:
Pedro Pinto committed 2020-12-24 10:44:08 -05:00
1 parent 189cb66daf
commit 02fa07552b
6 files changed
+35 -16

No files matched your search

@@ -6,7 +6,10 @@
#include "server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.h"
#include "server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.h"
#include "server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.h"
#include "server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.h"
#include <boost/container/small_vector.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
namespace bts::spartan::mdp3 {
@@ -63,14 +66,7 @@ struct SniperModel::PImpl {
double max_shot_loss;
EventHeader current_event;
size_t streak_id = 0;
double get_min_cumm_edge(api::Side side) {
if (side == api::SIDE_BUY)
return -min_cumm_edge;
else
return min_cumm_edge;
}
State state = State::WAIT_OPPORTUNITY;
std::unordered_map<MDP3SecurityID, DependentTargets> books = {};
std::vector<std::unique_ptr<Target>> targets = {};
@@ -351,7 +347,7 @@ bool SniperModel::within_safety_margin(Target const &t) const {
std::tuple_size<Book>::value);
auto cumm_qty = 0ul;
auto min_price = me->get_min_cumm_edge(t.side);
auto min_price = me->min_cumm_edge;
// This is not right, exactly, we are assuming all the legs are
// expressed in the same terms as the first.
@@ -751,7 +751,7 @@ Sim::calculate_trading_window(std::string const &mkt_date,
auto start_time = adjust_day(start);
auto stop_time = adjust_day(stop);
bts_assert(stop_time > start_time);
return {cme_ts_from_ptime(start_time), cme_ts_from_ptime(stop_time)};
return {to_mdp3time(start_time), to_mdp3time(stop_time)};
}
}
@@ -4,6 +4,9 @@
#include "lib/config/protos/cme_reference_data.pb.h"
#include "lib/logging/logging.h"
#include "lib/utils/helper_macros.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include "lib/utils/datetime.h"
#include "server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.h"
namespace bts::spartan::mdp3 {
@@ -38,9 +41,14 @@ struct InstrumentDefinition::PImpl {
cme_security_type = str_from_fixed_array(m.securityType(),
m.securityTypeEncodingLength());
m.noEvents().forEach([&](auto const &ev) {
if (ev.eventType() == ::mdp3::EventType::LastEligibleTradeDate) {
expiration = MDP3TimeStamp(ev.eventTime());
}
});
// As in the constructor we have to skip over all the arrays
// that preceed ours
m.noEvents().forEach([](auto const &) {});
m.noMDFeedTypes().forEach([](auto const &) {});
m.noInstAttrib().forEach([this](auto &attr) {
implied_matching = attr.instAttribValue().impliedMatchingEligibility();
@@ -53,7 +61,6 @@ struct InstrumentDefinition::PImpl {
std::string symbol;
std::string security_group;
std::string asset;
MDP3TimeStamp last_update_time;
MDP3SecurityID security_id;
std::string match_algorithm;
md::IntPrice min_price_increment;
@@ -61,6 +68,7 @@ struct InstrumentDefinition::PImpl {
bool implied_matching = false;
api::SecurityType security_type;
std::string cme_security_type;
std::optional<MDP3TimeStamp> expiration;
};
InstrumentDefinition::InstrumentDefinition() : me (new PImpl()) {}
@@ -148,6 +156,8 @@ std::string const &InstrumentDefinition::security_group() const {
}
std::string const &InstrumentDefinition::asset() const { return me->asset; }
std::optional<MDP3TimeStamp> InstrumentDefinition::expiration() const {return me->expiration;}
std::string InstrumentDefinition::match_algorithm() const {
return me->match_algorithm;
}
@@ -33,6 +33,7 @@ class InstrumentDefinition {
std::string const &symbol() const ;
std::string const &security_group() const ;
std::string const &asset() const ;
std::optional<MDP3TimeStamp> expiration() const;
std::string match_algorithm() const ;
double display_factor() const {return display_factor_;}
double min_price_increment() const;
@@ -48,8 +48,9 @@ std::string drop_extensions(std::string const &str) {
return result;
}
auto one_billion = 1000000000;
void cme_ts_to_time_str(uint64_t cme_ts, std::stringstream *out) {
auto one_billion = 1000000000;
time_t unix_ts = cme_ts / one_billion;
auto boost_ts = boost::posix_time::from_time_t(unix_ts);
int hours = boost_ts.time_of_day().hours();
@@ -62,7 +63,6 @@ void cme_ts_to_time_str(uint64_t cme_ts, std::stringstream *out) {
}
void cme_ts_to_date_time_str(uint64_t cme_ts, std::stringstream *out) {
auto one_billion = 1000000000;
time_t unix_ts = cme_ts / one_billion;
auto boost_ts = boost::posix_time::from_time_t(unix_ts);
auto year = boost_ts.date().year();
@@ -79,13 +79,24 @@ void cme_ts_to_date_time_str(uint64_t cme_ts, std::stringstream *out) {
<< cme_ts - (unix_ts * one_billion);
}
MDP3TimeStamp cme_ts_from_ptime(datetime::PTime const &pt) {
MDP3TimeStamp to_mdp3time(datetime::PTime const &pt) {
using namespace boost::posix_time;
static ptime epoch(boost::gregorian::date(1970, 1, 1));
auto tns = (pt - epoch).total_nanoseconds();
return MDP3TimeStamp{(size_t)tns};
}
datetime::PTime to_ptime(MDP3TimeStamp cme_ts) {
time_t unix_ts = cme_ts.value() / one_billion;
long residual_nano_seconds = cme_ts.value() - (unix_ts * one_billion);
auto temp_result = boost::posix_time::from_time_t(unix_ts);
auto t_of_day_secs = temp_result.time_of_day();
auto t_of_day_nsecs = datetime::PDuration {t_of_day_secs.hours(),t_of_day_secs.minutes(),
t_of_day_secs.seconds(), residual_nano_seconds };
return datetime::PTime {temp_result.date(), t_of_day_nsecs};
}
std::string to_time_string(MDP3TimeStamp ts) {
std::stringstream str;
cme_ts_to_time_str(ts.value(), &str);
@@ -14,7 +14,8 @@ namespace bts::spartan::mdp3 {
// CME time stamps to friendly strings
std::string to_time_string(MDP3TimeStamp ts);
std::string to_datetime_string(MDP3TimeStamp ts);
MDP3TimeStamp cme_ts_from_ptime(datetime::PTime const &) ;
MDP3TimeStamp to_mdp3time(datetime::PTime const &) ;
datetime::PTime to_ptime(MDP3TimeStamp) ;
// Details the ip/port used for each of the incremental a/b, snapshot
// and instrument feeds in a pcap.