Merge branch 'spartan_tas' of bitbucket.org:bluetradesys/spark into spartan_tas
This commit is contained in:
commit
927cd60d41
6 files changed
+74
-40
No files matched your search
@@ -4,7 +4,9 @@
|
||||
#include "../gen/MDInstrumentDefinitionOption55.h"
|
||||
#include "../gen/MDInstrumentDefinitionSpread56.h"
|
||||
#include "../parsing/MDP3MsgBox.h"
|
||||
#include "mdp3_common.h"
|
||||
#include "../common/mdp3_common.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
|
||||
@@ -22,7 +24,7 @@ class InstrumentDefinition {
|
||||
InstrumentDefinition &operator=(InstrumentDefinition const &other) = default;
|
||||
|
||||
template <class M>
|
||||
InstrumentDefinition(M const &d) : _def(MDP3MsgBox<M>(d)) {}
|
||||
explicit InstrumentDefinition(M const &d) : _def(MDP3MsgBox<M>(d)) {}
|
||||
|
||||
// Visit specific type in this definition
|
||||
template <class Visitor> void visit(Visitor v) const {
|
||||
@@ -69,7 +71,6 @@ class InstrumentDefinition {
|
||||
return get([](auto const &m) { return m.mDSecurityTradingStatus(); });
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
using DefVar =
|
||||
std::variant<MDP3MsgBox<::mdp3::MDInstrumentDefinitionFuture54>,
|
||||
@@ -78,6 +79,12 @@ class InstrumentDefinition {
|
||||
mutable DefVar _def;
|
||||
};
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &out,
|
||||
InstrumentDefinition const &d) {
|
||||
d.visit([&out](auto const &m) { out << m; });
|
||||
return out;
|
||||
}
|
||||
|
||||
using MaybeInstrumentDefinition = std::optional<InstrumentDefinition>;
|
||||
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -10,7 +10,9 @@ struct InstrumentSnapshot::PImpl {
|
||||
electronic_volume(), fixing_price(), open_interest(), open_price(),
|
||||
high_bid(), low_offer(), settlement_price(), high_trade_price(),
|
||||
low_trade_price(), definition(def),
|
||||
trading_status(definition.trading_status()) {}
|
||||
trading_status(definition.trading_status()),
|
||||
implied_matching_status(false)
|
||||
{}
|
||||
|
||||
PImpl(InstrumentDefinition &&def)
|
||||
: security_id(def.security_id()), books(), implied_books(), orders(),
|
||||
@@ -19,7 +21,9 @@ struct InstrumentSnapshot::PImpl {
|
||||
electronic_volume(), fixing_price(), open_interest(), open_price(),
|
||||
high_bid(), low_offer(), settlement_price(), high_trade_price(),
|
||||
low_trade_price(), definition(std::move(def)),
|
||||
trading_status(definition.trading_status()) {}
|
||||
trading_status(definition.trading_status()),
|
||||
implied_matching_status(false)
|
||||
{}
|
||||
|
||||
// Books
|
||||
const MDP3SecurityID security_id;
|
||||
@@ -52,6 +56,7 @@ struct InstrumentSnapshot::PImpl {
|
||||
InstrumentDefinition definition;
|
||||
|
||||
::mdp3::SecurityTradingStatus::Value trading_status;
|
||||
bool implied_matching_status;
|
||||
};
|
||||
|
||||
InstrumentSnapshot::InstrumentSnapshot(InstrumentDefinition const &def)
|
||||
@@ -87,11 +92,19 @@ InstrumentSnapshot::trading_status() const {
|
||||
return me->trading_status;
|
||||
}
|
||||
|
||||
bool InstrumentSnapshot::implied_matching_status() const {
|
||||
return me->implied_matching_status;
|
||||
}
|
||||
|
||||
void InstrumentSnapshot::set_trading_status(
|
||||
::mdp3::SecurityTradingStatus::Value t) const {
|
||||
me->trading_status = t;
|
||||
}
|
||||
|
||||
void InstrumentSnapshot::set_implied_matching_status(bool v) {
|
||||
me->implied_matching_status = v;
|
||||
}
|
||||
|
||||
md::IntPrice InstrumentSnapshot::high_limit_price() const {
|
||||
return me->high_limit_price;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ class InstrumentSnapshot {
|
||||
InstrumentDefinition definition() const;
|
||||
const char *symbol() const { return definition().symbol(); }
|
||||
::mdp3::SecurityTradingStatus::Value trading_status() const;
|
||||
bool implied_matching_status() const;
|
||||
size_t last_processed_sn() const;
|
||||
Book const &book(api::Side) const;
|
||||
ImpliedBook const &implied_book(api::Side) const;
|
||||
@@ -53,11 +54,13 @@ class InstrumentSnapshot {
|
||||
md::IntPrice settlement_price() const;
|
||||
md::IntPrice high_trade_price() const;
|
||||
md::IntPrice low_trade_price() const;
|
||||
|
||||
|
||||
// Mutators ------------------------------------------------------------
|
||||
void set_definition(InstrumentDefinition const &);
|
||||
void set_last_msg_processed_sn(size_t);
|
||||
void set_trading_status(::mdp3::SecurityTradingStatus::Value) const;
|
||||
void set_implied_matching_status(bool);
|
||||
|
||||
void insert_book_level(api::Side, size_t idx, BookLevel const &);
|
||||
void update_book_level(api::Side, size_t idx, BookLevel const &);
|
||||
void remove_book_level(api::Side, size_t idx);
|
||||
@@ -88,7 +91,7 @@ class InstrumentSnapshot {
|
||||
void set_settlement_price(md::IntPrice);
|
||||
void set_high_trade_price(md::IntPrice);
|
||||
void set_low_trade_price(md::IntPrice);
|
||||
|
||||
|
||||
private:
|
||||
template <class A>
|
||||
void insert(api::Side, std::array<A, 2> &, size_t idx, BookLevel const &);
|
||||
|
||||
@@ -475,7 +475,8 @@ template <class Def> void RealTimeHandler::on_instrument_definition(Def &d) {
|
||||
// because otherwise we cannot guarantee that the incremental
|
||||
// book updates we receive can be applied to the instrument.
|
||||
if (d.securityUpdateAction() == ::mdp3::SecurityUpdateAction::Add) {
|
||||
auto new_snapshot = std::make_unique<InstrumentSnapshot>(d);
|
||||
auto new_snapshot =
|
||||
std::make_unique<InstrumentSnapshot>(InstrumentDefinition{d});
|
||||
iptr = new_snapshot.get();
|
||||
me->instruments[sid] = std::move(new_snapshot);
|
||||
ev.record_security_change(iptr);
|
||||
@@ -485,7 +486,7 @@ template <class Def> void RealTimeHandler::on_instrument_definition(Def &d) {
|
||||
// instrument and add it via add_snapshot()
|
||||
}
|
||||
} else {
|
||||
iptr->set_definition(d);
|
||||
iptr->set_definition(InstrumentDefinition{d});
|
||||
ev.record_security_change(iptr);
|
||||
}
|
||||
}
|
||||
@@ -509,6 +510,15 @@ void RealTimeHandler::operator()(::mdp3::QuoteRequest39 &qr) {
|
||||
void RealTimeHandler::operator()(::mdp3::SecurityStatus30 &ss) {
|
||||
EventGuard ev(*this, ss);
|
||||
|
||||
auto update_implied_matching = [&ss](auto &iptr) {
|
||||
if (ss.securityTradingEvent() ==
|
||||
::mdp3::SecurityTradingEvent::ImpliedMatchingON)
|
||||
iptr.set_implied_matching_status(true);
|
||||
else if (ss.securityTradingEvent() ==
|
||||
::mdp3::SecurityTradingEvent::ImpliedMatchingOFF)
|
||||
iptr.set_implied_matching_status(false);
|
||||
};
|
||||
|
||||
// This applies only to the security
|
||||
if (ss.securityID() != ss.securityIDNullValue()) {
|
||||
|
||||
@@ -517,8 +527,8 @@ void RealTimeHandler::operator()(::mdp3::SecurityStatus30 &ss) {
|
||||
if (!iptr)
|
||||
return;
|
||||
ev.record_security_change(iptr);
|
||||
|
||||
iptr->set_trading_status(ss.securityTradingStatus());
|
||||
update_implied_matching(*iptr);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -530,6 +540,7 @@ void RealTimeHandler::operator()(::mdp3::SecurityStatus30 &ss) {
|
||||
if (strcmp(def.security_group(), ss.securityGroup()) == 0) {
|
||||
ev.record_security_change(iptr.get());
|
||||
iptr->set_trading_status(ss.securityTradingStatus());
|
||||
update_implied_matching(*iptr);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -543,6 +554,7 @@ void RealTimeHandler::operator()(::mdp3::SecurityStatus30 &ss) {
|
||||
if (strcmp(def.asset(), ss.asset()) == 0) {
|
||||
ev.record_security_change(iptr.get());
|
||||
iptr->set_trading_status(ss.securityTradingStatus());
|
||||
update_implied_matching(*iptr);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -584,8 +596,7 @@ void RealTimeHandler::on_end_of_event() {
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
switch (summary.aggressor) {
|
||||
case ::mdp3::AggressorSide::NoAggressor:
|
||||
f.aggressor = MDP3Fill::IMPLIED;
|
||||
|
||||
@@ -13,6 +13,7 @@ CREATE TABLE event_items(
|
||||
t_time numeric,
|
||||
sid numeric,
|
||||
status TEXT,
|
||||
implied_matching_status numeric,
|
||||
type TEXT,
|
||||
change TEXT,
|
||||
ok numeric,
|
||||
@@ -29,6 +30,7 @@ CREATE TABLE books(
|
||||
t_time numeric,
|
||||
sid numeric,
|
||||
status TEXT,
|
||||
implied_matching_status numeric,
|
||||
|
||||
bid_p_0 numeric,
|
||||
bid_q_0 numeric,
|
||||
|
||||
@@ -416,19 +416,7 @@ struct CSVObs : IChannelObserver {
|
||||
: events(out_dir + "/events.csv"),
|
||||
event_items(out_dir + "/event_items.csv"),
|
||||
securities(out_dir + "/securities.csv"),
|
||||
books(out_dir + "/books.csv") {
|
||||
|
||||
events << "eid, t_time,first_sn,last_sn,"
|
||||
"first_st,last_st"
|
||||
<< std::endl;
|
||||
|
||||
event_items << "eid, t_time,sid,status,type,"
|
||||
"change,ok,side,"
|
||||
"pri,price,qty,tid,agg"
|
||||
<< std::endl;
|
||||
|
||||
securities << "sid,symbol,group,asset,last_t" << std::endl;
|
||||
}
|
||||
books(out_dir + "/books.csv") {}
|
||||
|
||||
std::ofstream events;
|
||||
std::ofstream event_items;
|
||||
@@ -460,7 +448,8 @@ struct CSVObs : IChannelObserver {
|
||||
books << 0 << "," // event_id
|
||||
<< 0 << "," // transact time
|
||||
<< s->security_id().value() << "," // security id
|
||||
<< s->trading_status(); // trading status
|
||||
<< s->trading_status() << "," // trading status
|
||||
<< s->implied_matching_status(); // implied matching status
|
||||
print_book(s->book(api::SIDE_BUY));
|
||||
print_book(s->book(api::SIDE_SELL));
|
||||
print_book(s->implied_book(api::SIDE_BUY));
|
||||
@@ -468,13 +457,15 @@ struct CSVObs : IChannelObserver {
|
||||
books << std::endl;
|
||||
|
||||
for (auto const &[id, order] : s->orders())
|
||||
event_items << 0 << "," // event_id
|
||||
<< 0 << "," // transact time
|
||||
<< s->security_id().value() << "," // security id
|
||||
<< s->trading_status() << "," // trading status
|
||||
<< "order_change," // type
|
||||
<< "init," // change
|
||||
<< id << "," // order key
|
||||
event_items << 0 << "," // event_id
|
||||
<< 0 << "," // transact time
|
||||
<< s->security_id().value() << "," // security id
|
||||
<< s->trading_status() << "," // trading status
|
||||
<< s->implied_matching_status()
|
||||
<< "," // implied matching status
|
||||
<< "order_change," // type
|
||||
<< "init," // change
|
||||
<< id << "," // order key
|
||||
<< api::Side_Name(order.side) << "," // side
|
||||
<< order.priority.value() << "," // priority
|
||||
<< order.price.price() << "," // price
|
||||
@@ -510,7 +501,8 @@ struct CSVObs : IChannelObserver {
|
||||
books << event_id << "," // event id
|
||||
<< ev.transact_time.value() << "," // transact time
|
||||
<< s->security_id().value() << "," // security id
|
||||
<< s->trading_status(); // trading status
|
||||
<< s->trading_status() << "," // trading status
|
||||
<< s->implied_matching_status(); // implied matching status
|
||||
print_book(s->book(api::SIDE_BUY));
|
||||
print_book(s->book(api::SIDE_SELL));
|
||||
print_book(s->implied_book(api::SIDE_BUY));
|
||||
@@ -518,12 +510,14 @@ struct CSVObs : IChannelObserver {
|
||||
books << std::endl;
|
||||
|
||||
for (auto const &change : s->order_changes())
|
||||
event_items << event_id << "," // event id
|
||||
<< ev.transact_time.value() // transact time
|
||||
<< "," // transact time
|
||||
<< s->security_id().value() << "," // security id
|
||||
<< s->trading_status() << "," // trading status
|
||||
<< "order_change," // type
|
||||
event_items << event_id << "," // event id
|
||||
<< ev.transact_time.value() // transact time
|
||||
<< "," // transact time
|
||||
<< s->security_id().value() << "," // security id
|
||||
<< s->trading_status() << "," // trading status
|
||||
<< s->implied_matching_status()
|
||||
<< "," // implied matching status
|
||||
<< "order_change," // type
|
||||
<< change_name(change.change) << "," // change type
|
||||
<< change.order.key.value() << "," // order key
|
||||
<< api::Side_Name(change.order.side) << "," // side
|
||||
@@ -539,6 +533,8 @@ struct CSVObs : IChannelObserver {
|
||||
<< ev.transact_time.value() << "," // transact time
|
||||
<< s->security_id().value() << "," // security id
|
||||
<< s->trading_status() << "," // trading status
|
||||
<< s->implied_matching_status()
|
||||
<< "," // implied matching status
|
||||
<< "fill," // type
|
||||
<< "," // null
|
||||
<< f.key.value() << "," // order key
|
||||
@@ -556,6 +552,8 @@ struct CSVObs : IChannelObserver {
|
||||
<< ev.transact_time.value() << "," // transact time
|
||||
<< s->security_id().value() << "," // security id
|
||||
<< s->trading_status() << "," // trading status
|
||||
<< s->implied_matching_status()
|
||||
<< "," // implied matching status
|
||||
<< "deduced_order," // type
|
||||
<< change_name(deduced_order->change) << ","
|
||||
<< deduced_order->order.key.value() << "," // order key
|
||||
|
||||
Reference in new issue
Block a user