14#include "fastmm/core/fill_audit.hpp"
16#include "fastmm/core/msg_ring.hpp"
17#include "fastmm/core/order_budget.hpp"
19#include "fastmm/core/seqlock.hpp"
87struct VenueFeedStatus {
192 [[nodiscard]] virtual std::string_view
name() const noexcept = 0;
206 return std::vector<VenueFee>{};
219 MsgRing* outbound) = 0;
233 virtual void subscribe(std::span<const InstrumentId> instruments) = 0;
238 virtual void on_timer(std::int64_t now_ns) = 0;
245 virtual void send_now(std::span<const EventHeader* const> batch) = 0;
248 virtual void poll() noexcept {}
284 const std::vector<std::string>& ) {}
290 const std::vector<std::pair<InstrumentId, std::int64_t>>& ) {}
296 const std::vector<std::pair<
InstrumentId, std::vector<std::int64_t>>>& ) {}
307 std::function<
void(
bool, std::vector<AuditFill>)> ) {
354 return tsc_source_ !=
nullptr ? tsc_source_->load() :
TscCalibration{};
365 const Seqlocked<TscCalibration>* tsc_source_ =
nullptr;
Dense-by-id table built at startup; symbol lookup is a sorted FlatMap keyed by (venue,...
Definition instrument.hpp:141
Definition reactor.hpp:72
Definition event_sink.hpp:34
Definition symbology.hpp:46
const Seqlocked< OrderBudget > & budget_source() const noexcept
The order budget the connector publishes from its rate limiter (core/order_budget....
Definition venue.hpp:349
virtual VenueCaps caps() const noexcept=0
std::uint64_t orders_taken_
New orders and replaces taken off the engine's ring (send_command), sent or refused: published with t...
Definition venue.hpp:359
virtual void connect(net::Reactor &reactor)=0
Opens every channel (market data, user stream, order entry) on reactor.
virtual void on_timer(std::int64_t now_ns)=0
Periodic housekeeping (listenKey keepalive, app-level pings, clock offset refresh,...
virtual VenueStatus status() const noexcept=0
Seqlocked< OrderBudget > budget_pub_
Definition venue.hpp:356
virtual void resume_executions(std::int64_t, const std::vector< std::string > &)
Where the first execution replay starts, for a session that carries a position over from an earlier o...
Definition venue.hpp:285
virtual void resync_books()
Every book starts over from a fresh snapshot: a ConnectionState{Resyncing} or Stale on the md sink,...
Definition venue.hpp:256
virtual bool request_executions(std::int64_t=0)
The account's executions from since_venue_ms (the venue's clock, inclusive) onwards,...
Definition venue.hpp:279
virtual Result< void, std::string > load_reference_data(InstrumentTable &instruments)=0
Fetches exchangeInfo / instruments-info for every instrument of this venue and overwrites tick/lot/mi...
virtual void send_now(std::span< const EventHeader *const > batch)=0
Run-to-completion ([engine] threading = "single"): the engine runs on the reactor thread and hands it...
virtual void resume_trade_ids(const std::vector< std::pair< InstrumentId, std::int64_t > > &)
An exact start where the venue's trade ids increase per instrument (Binance): the first trade id to a...
Definition venue.hpp:291
virtual VenueId id() const noexcept=0
virtual bool defer_private()
Warm standby (fastmm-live --standby while another process holds the instance lock).
Definition venue.hpp:233
virtual void request_open_orders()=0
Venue view of open orders -> ReconcileMsg Begin/OpenOrder*/End into the order sink.
virtual bool can_audit_executions() const noexcept
Whether audit_executions() is implemented. Any thread.
Definition venue.hpp:312
virtual bool cancel_all()=0
Kill switch: cancel every open order on every subscribed symbol via an independent REST connection.
void note_taken(const OrderCommand &cmd) noexcept
Definition venue.hpp:360
virtual std::string transfer_account() const
This account's name in a transfer request (a Binance sub-account's email; empty for the exchange's ma...
Definition venue.hpp:329
virtual void poll() noexcept
Called by the network thread after every reactor iteration.
Definition venue.hpp:250
virtual std::string_view name() const noexcept=0
virtual bool refused_account_settings() const noexcept
After load_reference_data() failed: true when it refused a setting of the account (a position mode th...
Definition venue.hpp:213
virtual bool audit_executions(std::int64_t, std::int64_t, std::function< void(bool, std::vector< AuditFill >)>)
Fill audit (live/fill_auditor.hpp): the account's executions with the venue's time in [start_ms,...
Definition venue.hpp:306
void set_tsc_calibration_source(const Seqlocked< TscCalibration > *src) noexcept
Published TSC calibrations used to convert the network thread's cycle histograms to ns when the statu...
Definition venue.hpp:343
virtual Result< std::vector< VenueFee >, std::string > account_fees(const InstrumentTable &)
The account's fee rates on this venue's instruments in instruments, fetched from the venue (Binance S...
Definition venue.hpp:206
virtual void enable_private()
Definition venue.hpp:234
virtual TransferResult transfer(const TransferRequest &)
Moves req.amount of req.asset from account req.from_account to req.to_account, both accounts of this ...
Definition venue.hpp:318
virtual void request_balances()
Asks the venue for the account's balances now, emitted as a BalanceMsg snapshot on the order sink (th...
Definition venue.hpp:332
virtual void resume_known_trade_ids(const std::vector< std::pair< InstrumentId, std::vector< std::int64_t > > > &)
The trade ids at or after an instrument's start (resume_trade_ids) that are booked already,...
Definition venue.hpp:297
virtual void disconnect()=0
virtual void on_wake()=0
The engine pushed Out*Msg into the outbound ring: drain, encode, send.
virtual TransferResult transfer_status(const TransferRequest &)
The state of the transfer named req.client_id (the same request transfer() was given).
Definition venue.hpp:324
virtual void attach(const SymbolTable &symbols, const InstrumentTable &instruments, EventSink &md_sink, EventSink &order_sink, MsgRing *outbound)=0
Wires the sinks (md: lossy, orders: never dropped) and the outbound ring the engine writes Out*Msg in...
TscCalibration tsc_calibration() const noexcept
Latest published calibration, or a calibration with use_tsc == false without a source.
Definition venue.hpp:353
virtual void subscribe(std::span< const InstrumentId > instruments)=0
Minimal expected<T, E>: the hot path never throws, it returns Result.
EventSink (5.15): the net -> engine seam.
Fee rates per instrument, in centi-basis-points (integer) of the fill notional.
Instrument: the single definition of a tradable contract (5.3 / 5.15).
ChannelState
Definition venue.hpp:50
constexpr std::string_view to_string(ChannelState s) noexcept
Definition venue.hpp:51
OrderCommandKind
Definition order_commands.hpp:15
FeedState
Multicast feed (nasdaq_itch, ADR-0015 section 5); zero for the WebSocket venues.
Definition venue.hpp:66
@ None
not a multicast venue
@ Live
books built, messages applied as they arrive
@ Lost
cannot rebuild the books: the venue's kill switch is tripped (FeedLost)
@ Snapshot
joined and buffering; waiting for GLIMPSE (or sequence 1)
void unsend(VenueStatus &s, OrderCommandKind k) noexcept
An order counted as sent whose batch was then never written (the connection failed at uncork()): the ...
Definition venue.hpp:175
@ Unknown
no usable answer (a transport error, a timeout, a 5xx): it may have happened
@ Failed
the venue refused it or gave up: nothing moved
Single-threaded event loop with a timer min-heap and a thread-safe mailbox (post/wake via eventfd),...
Strongly typed identifiers.
One maker/taker pair. 1 cbps == 0.01 bps == 1e-6 of the notional.
Definition fees.hpp:26
Definition transfer.hpp:44
Definition transfer.hpp:59
Definition order_commands.hpp:28
bool supports_post_only
LIMIT_MAKER / PostOnly.
Definition venue.hpp:42
bool internal_transfer
Moves an asset between accounts of the same exchange (Venue::transfer): the connector has the credent...
Definition venue.hpp:47
bool ws_order_entry
orders over WebSocket (REST fallback otherwise)
Definition venue.hpp:43
bool supports_replace
Binance cancelReplace / Bybit amend.
Definition venue.hpp:41
bool user_stream
private order/fill stream available (false in dry-run)
Definition venue.hpp:44
The account's own fee rates on one instrument (Venue::account_fees).
Definition venue.hpp:168
FeeRates rates
Definition venue.hpp:170
InstrumentId instrument
Definition venue.hpp:169
std::uint64_t malformed
datagrams that are not MoldUDP64 packets, bad frames (af_xdp)
Definition venue.hpp:106
std::uint64_t xdp_rx_dropped
af_xdp: XDP_STATISTICS summed over the sockets, and packets passed to the kernel because their RX que...
Definition venue.hpp:111
std::uint64_t requests
MoldUDP64 request packets sent.
Definition venue.hpp:105
std::uint64_t bytes
datagram payload bytes received
Definition venue.hpp:94
std::uint8_t backend
0 kernel, 1 af_xdp, 2 dpdk
Definition venue.hpp:91
WireLatencyStats kernel_to_t0
t0_wall_ns - sw_ts_ns (kernel backend only)
Definition venue.hpp:108
std::int64_t line_skew_max_ns[2]
Definition venue.hpp:98
std::uint64_t recovery_overflows
recovery buffer full during a snapshot
Definition venue.hpp:103
std::uint64_t unrecovered
sequences given up
Definition venue.hpp:101
std::uint64_t packets
MoldUDP64 packets accepted (all lines, retransmissions included)
Definition venue.hpp:93
std::uint64_t gaps
gaps declared
Definition venue.hpp:99
std::uint64_t xdp_fill_ring_empty
Definition venue.hpp:114
std::int64_t line_skew_mean_ns[2]
arrival of a duplicate after the first copy
Definition venue.hpp:97
std::uint64_t reorder_high_water
Definition venue.hpp:104
std::uint64_t line_duplicates[2]
copies that arrived after the first
Definition venue.hpp:96
std::uint64_t line_packets[2]
lines A, B
Definition venue.hpp:95
std::uint8_t xdp_mode
net::XdpMode the first interface settled on (af_xdp)
Definition venue.hpp:92
std::uint64_t snapshot_recoveries
GLIMPSE snapshots applied after the first.
Definition venue.hpp:102
std::uint64_t xdp_rx_invalid_descs
Definition venue.hpp:112
std::uint64_t book_errors
L3 inconsistencies (each starts a resync)
Definition venue.hpp:107
std::uint64_t xdp_rx_ring_full
Definition venue.hpp:113
std::uint64_t recovered
messages delivered from retransmissions
Definition venue.hpp:100
std::uint64_t xdp_fallback
Definition venue.hpp:115
FeedState state
Definition venue.hpp:90
Snapshot for the stats line; every field is a plain counter so it can be copied out from the control ...
Definition venue.hpp:120
std::uint64_t executions_fetched
trade-history rows replayed into the order sink
Definition venue.hpp:152
WireLatencyWindow wire_1m
the same three over the last minute (60-70 s)
Definition venue.hpp:162
std::uint64_t refused_orders_1d
Definition venue.hpp:148
std::uint64_t order_events
Definition venue.hpp:133
std::uint32_t books_synced
Definition venue.hpp:124
std::uint32_t books_total
Definition venue.hpp:125
std::uint64_t refused_orders_1m
Definition venue.hpp:147
std::uint64_t md_malformed
Definition venue.hpp:127
WireLatencyStats order_encode
JSON encoding + signing.
Definition venue.hpp:160
std::uint64_t funding_fetched
funding payments replayed from the venue
Definition venue.hpp:155
std::uint64_t refused_weight
Orders and replaces the connector's rate limiter refused (VenueRateLimit, never sent),...
Definition venue.hpp:145
std::uint64_t shadows
order shadows held: orders working, in flight, or not yet swept
Definition venue.hpp:135
std::int64_t clock_offset_ms
venue - local
Definition venue.hpp:150
WireLatencyStats wire_tick_to_trade
Network-thread order latency (wire_latency.hpp), cumulative for the session.
Definition venue.hpp:159
std::uint64_t refused_orders_10s
Definition venue.hpp:146
std::uint64_t replaces_sent
Definition venue.hpp:132
std::uint64_t resyncs
Definition venue.hpp:129
std::uint64_t rest_errors
Definition venue.hpp:140
std::uint64_t order_send_failures
Definition venue.hpp:134
std::int64_t last_md_rx_ns
reactor clock
Definition venue.hpp:156
VenueFeedStatus feed
multicast venues only
Definition venue.hpp:164
ChannelState order
Definition venue.hpp:123
std::uint64_t cancels_sent
Definition venue.hpp:131
ChannelState md
Definition venue.hpp:121
WireLatencyWindow wire_1h
and over the last hour (60-70 min)
Definition venue.hpp:163
std::uint64_t rest_requests
Definition venue.hpp:139
std::uint64_t rate_limit_cooldowns
Definition venue.hpp:141
std::uint64_t md_messages
Definition venue.hpp:126
ChannelState user
Definition venue.hpp:122
std::uint64_t md_dropped
ring overflow
Definition venue.hpp:128
std::uint64_t shadows_swept
order shadows a reconciliation proved dead (lost terminal events)
Definition venue.hpp:136
std::uint64_t reconnects
Definition venue.hpp:151
WireLatencyStats order_send
WebSocket write / REST request call.
Definition venue.hpp:161
std::uint64_t shadows_refused
orders not sent: no room for a shadow (OrderTableFull)
Definition venue.hpp:138
std::uint64_t orders_sent
Definition venue.hpp:130
std::uint64_t execution_queries
Definition venue.hpp:153
std::uint64_t refused_paused
Definition venue.hpp:149
std::uint64_t execution_query_errors
a reconciliation that could not be made exact
Definition venue.hpp:154
Definition wire_latency.hpp:36
The three over one window (WireLatencyRecorder::summarize).
Definition wire_latency.hpp:45
SymbolTable (6.2): venue symbol <-> InstrumentId.
An internal transfer: an amount of one asset moved between two accounts of the same exchange (the acc...
Network-thread order latency: what happens to an outbound order after the engine pushed it into the v...