Better logging for sniper.

This commit is contained in:
Pedro Pinto committed 2020-11-10 10:47:34 -05:00
1 parent 63a2ba032d
commit 95d8d8a42d
1 file changed
+26 -5
@@ -70,6 +70,7 @@ struct Sniper::PImpl {
MDP3TimeStamp transact_time;
MDP3TimeStamp observable_time;
AlgoEventID current_event;
size_t streak_id = 0;
};
Sniper::Sniper() : me(new PImpl()) {}
@@ -242,6 +243,9 @@ Sniper::MaybeShot Sniper::pick() {
void Sniper::fire(Shot const &s) {
auto &shot = me->current_shot.emplace(s);
me->sim->log("shot_begin", me->current_event.first, me->current_event.second,
s.target.descriptor, s.value_at_observation_ts,
s.quantity.value(), me->streak_id);
if (me->ms_to_work_shot == 0) {
shot.forced_completion = true;
@@ -329,6 +333,7 @@ void Sniper::operator()(const MBPUpdate &mbp) {
case State::WAIT_OPPORTUNITY: {
auto best_shot = pick();
if (best_shot) {
me->streak_id++;
fire(best_shot.value());
transition(State::WAIT_FILLS);
}
@@ -343,6 +348,7 @@ void Sniper::operator()(const MBPUpdate &mbp) {
me->state = State::WAIT_OPPORTUNITY;
auto best_shot = pick();
if (best_shot) {
me->streak_id++;
fire(best_shot.value());
transition(State::WAIT_FILLS);
}
@@ -386,14 +392,20 @@ void Sniper::operator()(const OrderUpdate &update) {
in_flight.observed_event_id.first, in_flight.observed_event_id.second,
me->current_event.first, me->current_event.second,
in_flight.value_at_observation_ts * in_flight.quantity.value(),
pandl.net_cash(all_fills));
pandl.net_cash(all_fills), me->streak_id);
me->sim->log_pandl();
if (!me->double_dip)
transition(State::WAIT_CLEAR);
else {
auto best_shot = pick();
if (best_shot)
if (best_shot) {
me->sim->log(
"double_dip",
me->current_event.first,
me->current_event.second,
me->streak_id);
fire(best_shot.value());
}
else
transition(State::WAIT_OPPORTUNITY);
}
@@ -403,15 +415,24 @@ void Sniper::operator()(const OrderUpdate &update) {
const char *Sniper::state_name(State s) {
switch (s) {
case State::WAIT_FILLS:
return "WAIT";
return "WAIT_FILLS";
case State::WAIT_OPPORTUNITY:
return "WATCH";
return "WAIT_OPPORTUNITY";
case State::WAIT_CLEAR:
return "WAIT_CLEAR";
}
return nullptr;
}
void Sniper::transition(State new_state) { me->state = new_state; }
void Sniper::transition(State new_state) {
me->sim->log(
"transition",
state_name(new_state),
me->current_event.first,
me->current_event.second,
me->streak_id);
me->state = new_state;
}
} // namespace bts::spartan::mdp3