Refactor.

This commit is contained in:
Pedro Pinto committed 2021-01-08 14:06:00 -05:00
1 parent c119b4b6ef
commit d3ad5ee823
13 files changed
+41 -27

No files matched your search

+1 -1
View File
@@ -252,7 +252,7 @@ void stats(std::string const &pcap) {
StatPrinter(std::ostream &out) : out{out} {}
std::ostream &out;
void on_event_end(MDP3Event const &ev) override {
for (auto s : ev.affected_securities) {
for (auto s : ev.affected_securities()) {
total_orders += s->orders().size();
}
}
@@ -90,7 +90,7 @@ void _sync_orders(
bool _has_multiple_aggressor_secs(const MDP3Event &ev) {
bool aggr_sec_found = false;
for (auto *s : ev.affected_securities) {
for (auto *s : ev.affected_securities()) {
for (auto f : s->fills()) {
switch (f.aggressor) {
case MDP3Fill::Aggressor::THIS_BUY:
@@ -279,7 +279,7 @@ struct MatcherValidationObserver::PImpl {
EventFlags flags = EventFlags::None;
if (_has_multiple_aggressor_secs(ev))
flags |= EventFlags::MultipleSecurityAggressors;
for (const auto *s : ev.affected_securities) {
for (const auto *s : ev.affected_securities()) {
for (auto &f : s->fills()) {
if (icebergs.find(f.key) != icebergs.end())
flags |= EventFlags::IcebergOrders;
@@ -334,14 +334,14 @@ bool MatcherValidationObserver::_is_ready_to_trade(
}
void MatcherValidationObserver::_sync_current_orders(MDP3Event const &ev) {
for (auto s : ev.affected_securities) {
for (auto s : ev.affected_securities()) {
auto &new_orders = _me->get_security_data(*s, ev.event_id).current_orders;
_sync_orders(ev.event_id, *s, new_orders, _me->icebergs);
}
}
void MatcherValidationObserver::_sync_previous_orders(const MDP3Event &ev) {
for (auto s : ev.affected_securities) {
for (auto s : ev.affected_securities()) {
auto &old_orders =
_me->get_security_data(*s, ev.event_id).previous_orders;
_sync_orders(ev.event_id, *s, old_orders, _me->icebergs);
@@ -413,7 +413,7 @@ void MatcherValidationObserver::on_event_end(MDP3Event const &ev) {
// in a particular order, sorted hierarchically by symbol, then expiration.
// 'sorted_secs' will contain the proper order of securities.
std::vector<const InstrumentSnapshot *> sorted_secs;
for (auto *s : ev.affected_securities) {
for (auto *s : ev.affected_securities()) {
if (_is_interesting_sec(*s))
sorted_secs.push_back(s);
}
@@ -91,7 +91,7 @@ void PCapEventGenerator::on_event_end(MDP3Event const &ev_in) {
ev.first_packet_sn = ev.first_packet_sn;
ev.last_packet_sn = ev.last_packet_sn;
for (auto snap_ptr : ev_in.affected_securities) {
for (auto snap_ptr : ev_in.affected_securities()) {
auto &snap_cpy = ev.affected_securities.emplace_back();
// light_copy() does not copy the orders, just the order changes
// Observers of this class should see a continuous stream of
@@ -19,7 +19,7 @@ void DefinitionCollector::on_recovery_complete(
}
void DefinitionCollector::on_event_end(MDP3Event const &ev) {
for (auto s : ev.affected_securities) {
for (auto s : ev.affected_securities()) {
auto it = result.find(s->security_id());
if (it == result.end())
result.insert({s->security_id(), s->definition()});
@@ -34,7 +34,7 @@ void FillCounter::on_recovery_complete(
}
void FillCounter::on_event_end(MDP3Event const &ev) {
for (auto snap : ev.affected_securities) {
for (auto snap : ev.affected_securities()) {
auto &c = me->counts[snap->security_id()];
if (c.sec_id.value() == 0) {
c.sec_id = snap->security_id();
@@ -189,7 +189,7 @@ void IcebergFinder::on_recovery_complete(InitialSnapshot const &snap) {
void IcebergFinder::on_event_end(MDP3Event const &ev) {
me->fills.clear();
for (auto s : ev.affected_securities) {
for (auto s : ev.affected_securities()) {
_on_fills(s->fills());
_on_security_changed(ev.event_id, *s);
}
@@ -312,7 +312,7 @@ void PolygonOpportunityFinder::on_event_end(MDP3Event const &ev) {
std::unordered_set<size_t> to_recalc = me->active_polygons;
me->active_polygons.clear();
for (auto &s : ev.affected_securities) {
for (auto &s : ev.affected_securities()) {
me->all_snapshots[s->security_id()] = {s, ev.event_id};
auto &these_dependencies = me->dependencies[s->security_id()];
to_recalc.insert(these_dependencies.begin(), these_dependencies.end());
@@ -219,8 +219,8 @@ void SyntheticBookRecorder::on_recovery_complete(const InitialSnapshot &snap) {
void SyntheticBookRecorder::on_event_end(const MDP3Event &ev) {
on_securities_changed(
ev.event_id, ev.affected_securities.begin(),
ev.affected_securities.end(), _me->synthetic_defs(), _me->reverse_legs(),
ev.event_id, ev.affected_securities().begin(),
ev.affected_securities().end(), _me->synthetic_defs(), _me->reverse_legs(),
_me->mbooks(), _me->msynthetic_book_history());
}
void SyntheticBookRecorder::on_packet_loss() {}
@@ -5,34 +5,48 @@
#include "lib/md/IntPrice.h"
#include "lib/utils/ValueWrapper.h"
#include "lib/utils/overloaded.h"
#include "server/sparkd/cmds/spartan/common/TimeStamp.h"
#include "server/sparkd/cmds/spartan/common/OrderKey.h"
#include "server/sparkd/cmds/spartan/common/SecurityID.h"
#include "server/sparkd/cmds/spartan/common/Quantity.h"
#include "server/sparkd/cmds/spartan/common/IcebergQuantity.h"
#include "server/sparkd/cmds/spartan/common/OrderKey.h"
#include "server/sparkd/cmds/spartan/common/Price.h"
#include "server/sparkd/cmds/spartan/common/Quantity.h"
#include "server/sparkd/cmds/spartan/common/SecurityID.h"
#include "server/sparkd/cmds/spartan/common/TimeStamp.h"
#include <boost/container/flat_set.hpp>
#include <boost/container/small_vector.hpp>
#include <variant>
namespace bts::spartan::mdp3 {
class InstrumentSnapshot;
class MDP3Event {
public:
TimeStamp transact_time = TimeStamp{0};
size_t event_id = 0;
TimeStamp transact_time = TimeStamp{0};
TimeStamp first_packet_send_time;
TimeStamp last_packet_send_time;
uint32_t first_packet_sn;
uint32_t last_packet_sn;
boost::container::flat_set<InstrumentSnapshot const *> affected_securities;
std::vector<InstrumentSnapshot const *> const &affected_securities() const {
return _affected_securities;
}
bool add(InstrumentSnapshot const *sec) {
for (auto s : _affected_securities)
if (s == sec)
return false;
_affected_securities.push_back(sec);
return true;
}
void reset() {
transact_time = TimeStamp{0};
affected_securities.clear();
_affected_securities.clear();
}
private:
std::vector<InstrumentSnapshot const *> _affected_securities;
};
inline std::string str_from_fixed_array(const char *ptr, size_t max_len) {
@@ -104,7 +104,7 @@ struct RealTimeHandler::EventGuard {
void record_security_change(InstrumentSnapshot *s) {
auto &info = owner.me->current_event;
s->set_last_msg_processed_sn(owner.me->current_packet_sn);
info.affected_securities.insert(s);
info.add(s);
}
RealTimeHandler &owner;
@@ -654,7 +654,7 @@ void RealTimeHandler::on_end_of_event() {
me->current_event.event_id++;
me->observer.on_event_end(me->current_event);
for (auto s : me->current_event.affected_securities) {
for (auto s : me->current_event.affected_securities()) {
const_cast<InstrumentSnapshot *>(s)->clear_fills();
const_cast<InstrumentSnapshot *>(s)->clear_order_changes();
}
@@ -58,7 +58,7 @@ TEST_CASE("spartan_md", "[spartan_md]") {
}
void on_event_end(MDP3Event const &ev) override {
real_time = true;
for (auto i : ev.affected_securities)
for (auto i : ev.affected_securities())
instruments[i->security_id()] = i;
}
void on_packet_loss() override { REQUIRE(false); }
@@ -111,7 +111,7 @@ TEST_CASE("spartan_md", "[spartan_md]") {
}
}
void on_event_end(MDP3Event const &ev) override {
for (auto is : ev.affected_securities) {
for (auto is : ev.affected_securities()) {
if (is->trading_status() ==
::mdp3::SecurityTradingStatus::ReadyToTrade) {
auto buy_ok = is->build_book_from_orders(api::SIDE_BUY) ==
@@ -592,7 +592,7 @@ struct CSVObs : IChannelObserver {
<< ev.last_packet_send_time // last packet send time
<< std::endl;
for (auto s : ev.affected_securities) {
for (auto s : ev.affected_securities()) {
if (known_securities.count(s->security_id()) == 0) {
known_securities.insert(s->security_id());
@@ -185,7 +185,7 @@ void BookStatRecorder::on_event_end(MDP3Event const &ev) {
case bts::spartan::EventOrdinal::Interesting:
_me->event_id = ev.event_id;
record_data(
ev.affected_securities, ev.event_id, _me->block_size, _me->num_blocks,
ev.affected_securities(), ev.event_id, _me->block_size, _me->num_blocks,
_me->out);
break;
case bts::spartan::EventOrdinal::Done: