7#include "fastmm/core/fill_audit.hpp"
9#include "fastmm/store/ab_readout.hpp"
20struct BookedFillQuery {
29 std::vector<std::string>
columns;
30 std::vector<std::vector<std::string>>
rows;
245 const std::string& ) {
246 return fail(std::string(
"this storage backend does not read [ab] tests"));
267 return fail(std::string(
"this store backend has no fill ledger"));
278 return fail(std::string(
"this store backend keeps no fill decision records"));
283 return fail(std::string(
"this store backend has no order timeline"));
291 return fail(std::string(
"this store backend cannot list booked fills"));
300 return fail(std::string(
"this store backend keeps no parameter history"));
305 return fail(std::string(
"this store backend keeps no parameter history"));
312 return fail(std::string(
"this store backend keeps no parameter history"));
319 return fail(std::string(
"this store backend keeps no rejects"));
325 return fail(std::string(
"this store backend keeps no limit changes"));
329 return fail(std::string(
"this store backend keeps no rejects"));
333 return fail(std::string(
"this store backend keeps no configuration"));
Storage backend interface: what a session's fills, orders, positions, PnL and kill events are handed ...
Definition reader.hpp:217
virtual Result< Rows, std::string > rejects(const QueryFilter &)
One row per refused order the engine recorded (count with the ones folded into it): when,...
Definition reader.hpp:320
virtual Result< Rows, std::string > param_changes(const QueryFilter &)
Every parameter update, one row per value it carried, in order: the starting set (origin initial) and...
Definition reader.hpp:306
virtual Result< Rows, std::string > funding(const QueryFilter &)
One row per funding payment. The default has none (a backend without the table).
Definition reader.hpp:251
virtual Result< Rows, std::string > ledger(const QueryFilter &, bool)
The economic fill ledger: one row per execution (the venue's id of it on an account,...
Definition reader.hpp:268
Reader & operator=(const Reader &)=delete
virtual Result< Rows, std::string > fills(const QueryFilter &f)=0
One row per execution.
virtual Result< Rows, std::string > reject_summary(const QueryFilter &)
The same summed: one row per account, instrument, side, reduces, reason and source.
Definition reader.hpp:330
virtual Result< Recovery, std::string > recovery(const QueryFilter &f)=0
The newest session of f.engine, summarised.
virtual Result< Rows, std::string > duplicates(const QueryFilter &)
One row per venue execution or funding payment stored more than once (by venue, symbol and the venue'...
Definition reader.hpp:257
virtual Result< Rows, std::string > positions(const QueryFilter &f)=0
The last position snapshot per session and instrument.
virtual Result< Rows, std::string > param_diff(std::uint64_t, std::uint64_t)
The parameters session a ended with against those session b started with: one row per parameter and s...
Definition reader.hpp:312
virtual Result< std::string, std::string > session_config(const ParamQuery &)
The effective configuration (TOML, secrets omitted) of the session q picks as params() does.
Definition reader.hpp:334
virtual Result< Rows, std::string > books_pnl(const QueryFilter &f)
The engine's day roll-up of its own position records, as it booked them: one row per UTC day,...
Definition reader.hpp:243
virtual Result< Rows, std::string > params(const ParamQuery &)
The strategy parameters in effect at q.at_ns (0: the session's last update) in the session q....
Definition reader.hpp:301
virtual Result< std::vector< AuditFill >, std::string > booked_fills(const BookedFillQuery &)
The executions stored for q.venue, of every session of q.engine, by the venue's time of the trade: th...
Definition reader.hpp:291
virtual Result< Rows, std::string > pnl(const QueryFilter &f)=0
One row per UTC day, account and symbol: realised (funding included, funding says how much),...
virtual Result< Rows, std::string > limit_changes(const QueryFilter &)
Every risk limit change an operator made at run time (fastmm-ctl limits), one row per key: when,...
Definition reader.hpp:326
virtual Result< Rows, std::string > sessions(const QueryFilter &f)=0
One row per session: id, engine, strategy, start, stop, PnL, fills, exit.
virtual Result< Rows, std::string > orders(const QueryFilter &f)=0
One row per order, in its last known state.
virtual Result< void, std::string > open(const BackendOptions &opts)=0
virtual Result< Rows, std::string > order_timeline(const QueryFilter &)
Everything stored about one client order (f.order), in time order: sent, each refusal,...
Definition reader.hpp:284
virtual Result< Rows, std::string > fill_context(const QueryFilter &)
One row per execution with its decision record (schema 16): the order's state when the fill arrived,...
Definition reader.hpp:279
virtual Result< AbData, std::string > ab_data(const QueryFilter &, const std::string &)
fastmm-pnl ab: the fills, markouts and arm assignments of the [ab] test test (empty: the newest sessi...
Definition reader.hpp:246
virtual ~Reader()=default
Minimal expected<T, E>: the hot path never throws, it returns Result.
Definition backend.hpp:40
constexpr Unexpected< std::decay_t< E > > fail(E &&e) noexcept
Definition result.hpp:25
What a backend is built with.
Definition backend.hpp:44
The executions an engine stored for one venue (Reader::booked_fills): the engine's side of a fill aud...
Definition reader.hpp:22
std::string instrument
symbol (empty: every instrument)
Definition reader.hpp:25
std::int64_t from_ms
the venue's time of the trade, inclusive (0: from the beginning)
Definition reader.hpp:26
std::string engine
[engine] name (empty: every engine)
Definition reader.hpp:23
std::string venue
[venues.<name>] (empty: every venue)
Definition reader.hpp:24
std::int64_t to_ms
inclusive (0: to the end)
Definition reader.hpp:27
Every query takes the same filter; a backend ignores the fields its query has no use for.
Definition reader.hpp:38
std::string engine
[engine] name (empty: every engine)
Definition reader.hpp:39
std::uint64_t session_id
0: the newest session that started by at_ns
Definition reader.hpp:40
std::string instrument
symbol: its own values and the shared ones (empty: every scope)
Definition reader.hpp:42
std::int64_t at_ns
wall clock; 0: now (the session's last update)
Definition reader.hpp:41
std::string from
inclusive UTC day, "YYYY-MM-DD" (empty: from the beginning)
Definition reader.hpp:49
std::string engine
[engine] name (empty: every engine)
Definition reader.hpp:46
std::uint64_t session_id
0: every session
Definition reader.hpp:47
std::string to
inclusive UTC day (empty: to the end)
Definition reader.hpp:50
std::string instrument
symbol (empty: every instrument)
Definition reader.hpp:48
std::string order
client order id (order_timeline; empty: none)
Definition reader.hpp:52
std::size_t limit
0: no limit
Definition reader.hpp:51
The executions the newest session stored a copy of though the store already held one (or stored twice...
Definition reader.hpp:209
std::uint64_t executions
Definition reader.hpp:212
std::string venue
its [venues.<name>]; "\#<id>" when the store predates schema 3
Definition reader.hpp:210
std::string symbol
Definition reader.hpp:211
Executions and funding payments the engine's store holds more than once (Reader::duplicates): a resta...
Definition reader.hpp:193
std::uint32_t copies
Definition reader.hpp:200
std::string side
empty for a funding payment
Definition reader.hpp:198
std::string sessions
the sessions holding it, oldest first, space separated
Definition reader.hpp:199
std::string id
the venue's trade id or funding id
Definition reader.hpp:196
std::string symbol
Definition reader.hpp:195
std::string venue
its [venues.<name>]; "\#<id>" when the store predates schema 3
Definition reader.hpp:194
bool funding
Definition reader.hpp:201
std::string qty
decimal: the execution's quantity, the funding payment's amount
Definition reader.hpp:197
The orders of those sessions that were not terminal at their last record and that the venue had ackno...
Definition reader.hpp:105
std::string cl_ord_id
Definition reader.hpp:109
std::string symbol
Definition reader.hpp:107
std::string venue
its [venues.<name>]; empty when the store predates schema 3
Definition reader.hpp:106
std::string venue_order_id
Definition reader.hpp:108
The positions a session carries over (fastmm-live restores them before it connects; see Venue::resume...
Definition reader.hpp:88
std::string symbol
Definition reader.hpp:91
std::int64_t qty_raw
Definition reader.hpp:92
std::int64_t avg_px_raw
Definition reader.hpp:93
std::uint8_t venue_id
in the session that recorded it
Definition reader.hpp:89
std::string venue
its [venues.<name>]; empty when the store predates schema 3
Definition reader.hpp:90
The highest numeric trade id per (venue, symbol) the store holds up to the newest session that got pa...
Definition reader.hpp:162
std::string venue
empty when the store predates schema 3
Definition reader.hpp:164
std::vector< std::int64_t > known_after
ascending
Definition reader.hpp:167
std::uint8_t venue_id
Definition reader.hpp:163
std::int64_t last_id
Definition reader.hpp:166
std::string symbol
Definition reader.hpp:165
Definition reader.hpp:145
std::int64_t since_ms
the replay's start, venue time, inclusive
Definition reader.hpp:150
bool shrunk
since_ms moved later than last_fill_ms - kResumeOverlapMs
Definition reader.hpp:153
std::uint8_t venue_id
the session's VenueId
Definition reader.hpp:146
std::vector< std::string > known_exec_ids
Stored fills and funding at or after since_ms, of every session of the engine.
Definition reader.hpp:152
std::int64_t last_fill_ms
Venue time of the stored fill or funding payment the start is taken from (see above).
Definition reader.hpp:149
std::string venue
its [venues.
Definition reader.hpp:147
What the previous session left behind, for the operator who is about to start a new one.
Definition reader.hpp:56
std::vector< Duplicate > duplicates
Definition reader.hpp:204
std::vector< std::string > journals
Definition reader.hpp:78
static constexpr std::size_t kMaxPastOrders
Definition reader.hpp:111
bool clean_shutdown
Definition reader.hpp:68
std::uint64_t fills
Definition reader.hpp:75
std::uint64_t records_dropped
Definition reader.hpp:76
std::string started_utc
Definition reader.hpp:59
std::vector< DoubleBooked > double_booked
Definition reader.hpp:214
std::vector< std::uint16_t > session_epochs
Definition reader.hpp:100
std::int64_t fallback_since_ms
0: no replay
Definition reader.hpp:179
std::vector< VenueResume > venue_resume
One entry per venue that recorded a fill with a venue time.
Definition reader.hpp:156
bool found
Definition reader.hpp:57
bool max_loss_tripped
The newest session ended on a max-loss trip: it shut down with the trip latched, or it never recorded...
Definition reader.hpp:67
static constexpr std::int64_t kResumeOverlapMs
Where each venue's execution replay resumes (Venue::resume_executions): from the venue time of the la...
Definition reader.hpp:139
std::vector< std::string > fallback_exec_ids
of every session that ran inside kFallbackIdsNs
Definition reader.hpp:180
std::vector< TradeIdMark > last_trade_ids
Definition reader.hpp:169
std::string stopped_utc
empty: the session never recorded a close (it was killed)
Definition reader.hpp:60
std::string unrealized
Definition reader.hpp:72
std::string fees
Definition reader.hpp:73
std::vector< PositionState > position_state
Definition reader.hpp:95
std::string funding
the part of realized that is funding (schema 4; "0" before)
Definition reader.hpp:71
std::string net
Definition reader.hpp:74
std::uint64_t duplicate_count
Definition reader.hpp:205
std::string kill_reason
Definition reader.hpp:62
bool journal_complete
Definition reader.hpp:77
static constexpr std::size_t kMaxSessionEpochs
The session epochs (the high bits of their client order ids) of the sessions a restart carries over,...
Definition reader.hpp:99
bool kill_latched
Definition reader.hpp:63
static constexpr std::size_t kMaxKnownExecIds
The most trade ids a venue's resume carries (the gateway's attach request holds gw::kMaxKnownExecIds ...
Definition reader.hpp:144
std::vector< std::string > positions
"SYMBOL qty \@ avg_px realized=... fees=..." per instrument with a position or a fill.
Definition reader.hpp:80
static constexpr std::int64_t kFallbackOverlapNs
The fallback for a venue with no entry above (a store from before schema 3, or a venue whose fills ca...
Definition reader.hpp:176
std::string strategy
Definition reader.hpp:61
static constexpr std::size_t kMaxDuplicates
Definition reader.hpp:203
std::vector< std::string > open_orders
"cl_ord_id SYMBOL side qty \@ price state" per order that was not terminal at the last record.
Definition reader.hpp:82
std::vector< PastOrder > past_orders
Definition reader.hpp:112
std::int64_t unbooked_since_ms
Where the replay of a venue with no stored fill starts (no venue_resume entry, in a store whose fills...
Definition reader.hpp:187
static constexpr std::int64_t kFallbackIdsNs
Definition reader.hpp:177
std::string realized
decimal, settlement currency
Definition reader.hpp:70
std::uint64_t session_id
Definition reader.hpp:58
int exit_code
Definition reader.hpp:69
std::int64_t last_fill_ns
engine time of the newest session's last fill (0: none)
Definition reader.hpp:178
std::vector< std::string > columns
Definition reader.hpp:31
std::vector< std::vector< std::string > > rows
Definition reader.hpp:32
bool empty() const noexcept
Definition reader.hpp:33