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"
91struct VenueFeedStatus {
199 [[nodiscard]] virtual std::string_view
name() const noexcept = 0;
222 return std::vector<VenueFee>{};
235 MsgRing* outbound) = 0;
249 virtual void subscribe(std::span<const InstrumentId> instruments) = 0;
265 virtual void on_timer(std::int64_t now_ns) = 0;
272 virtual void send_now(std::span<const EventHeader* const> batch) = 0;
275 virtual void poll() noexcept {}
311 const std::vector<std::string>& ) {}
317 const std::vector<std::pair<InstrumentId, std::int64_t>>& ) {}
323 const std::vector<std::pair<
InstrumentId, std::vector<std::int64_t>>>& ) {}
334 std::function<
void(
bool, std::vector<AuditFill>)> ) {
381 return tsc_source_ !=
nullptr ? tsc_source_->load() :
TscCalibration{};
392 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:147
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:376
virtual bool refresh_rules()
Reads the rules load_reference_data() read again, now and asynchronously, and emits an InstrumentRule...
Definition venue.hpp:217
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:386
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 std::uint32_t md_copies_requested() const noexcept
Copies the connector's own keys ask for (binance_usdm md_ticker_conns, the older spelling of md_copie...
Definition venue.hpp:262
virtual VenueStatus status() const noexcept=0
Seqlocked< OrderBudget > budget_pub_
Definition venue.hpp:383
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:312
virtual void resync_books()
Every book starts over from a fresh snapshot: a ConnectionState{Resyncing} or Stale on the md sink,...
Definition venue.hpp:283
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:306
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:318
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:249
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:339
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:387
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:356
virtual std::unique_ptr< MdCopy > make_md_copy(EventSink &sink, UpdateFilter &filter)
Redundant market data ([venues.
virtual void poll() noexcept
Called by the network thread after every reactor iteration.
Definition venue.hpp:277
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:229
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:333
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:370
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:222
virtual void enable_private()
Definition venue.hpp:250
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:345
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:359
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:324
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:351
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:380
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:54
constexpr std::string_view to_string(ChannelState s) noexcept
Definition venue.hpp:55
OrderCommandKind
Definition order_commands.hpp:15
FeedState
Multicast feed (nasdaq_itch, ADR-0015 section 5); zero for the WebSocket venues.
Definition venue.hpp:70
@ 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:182
@ 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:56
Definition transfer.hpp:71
Definition order_commands.hpp:28
venues/md_copy.hpp
Definition venue.hpp:44
bool supports_post_only
LIMIT_MAKER / PostOnly.
Definition venue.hpp:46
bool internal_transfer
Moves an asset between accounts of the same exchange (Venue::transfer): the connector has the credent...
Definition venue.hpp:51
bool ws_order_entry
orders over WebSocket (REST fallback otherwise)
Definition venue.hpp:47
bool supports_replace
Binance cancelReplace / Bybit amend.
Definition venue.hpp:45
bool user_stream
private order/fill stream available (false in dry-run)
Definition venue.hpp:48
The account's own fee rates on one instrument (Venue::account_fees).
Definition venue.hpp:175
FeeRates rates
Definition venue.hpp:177
InstrumentId instrument
Definition venue.hpp:176
std::uint64_t malformed
datagrams that are not MoldUDP64 packets, bad frames (af_xdp)
Definition venue.hpp:110
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:118
std::uint64_t requests
MoldUDP64 request packets sent.
Definition venue.hpp:109
std::uint64_t bytes
datagram payload bytes received
Definition venue.hpp:98
std::uint8_t backend
0 kernel, 1 af_xdp, 2 dpdk
Definition venue.hpp:95
WireLatencyStats kernel_to_t0
t0_wall_ns - sw_ts_ns (kernel backend only)
Definition venue.hpp:115
std::int64_t line_skew_max_ns[2]
Definition venue.hpp:102
std::uint64_t recovery_overflows
recovery buffer full during a snapshot
Definition venue.hpp:107
std::uint64_t unrecovered
sequences given up
Definition venue.hpp:105
std::uint64_t packets
MoldUDP64 packets accepted (all lines, retransmissions included)
Definition venue.hpp:97
std::uint64_t book_recentres
L3 price-window moves summed over the books, and the moves skipped for a full overflow store.
Definition venue.hpp:113
std::uint64_t gaps
gaps declared
Definition venue.hpp:103
std::uint64_t xdp_fill_ring_empty
Definition venue.hpp:121
std::int64_t line_skew_mean_ns[2]
arrival of a duplicate after the first copy
Definition venue.hpp:101
std::uint64_t reorder_high_water
Definition venue.hpp:108
std::uint64_t line_duplicates[2]
copies that arrived after the first
Definition venue.hpp:100
std::uint64_t line_packets[2]
lines A, B
Definition venue.hpp:99
std::uint8_t xdp_mode
net::XdpMode the first interface settled on (af_xdp)
Definition venue.hpp:96
std::uint64_t snapshot_recoveries
GLIMPSE snapshots applied after the first.
Definition venue.hpp:106
std::uint64_t xdp_rx_invalid_descs
Definition venue.hpp:119
std::uint64_t book_errors
L3 inconsistencies (each starts a resync)
Definition venue.hpp:111
std::uint64_t xdp_rx_ring_full
Definition venue.hpp:120
std::uint64_t recovered
messages delivered from retransmissions
Definition venue.hpp:104
std::uint64_t book_recentre_failures
Definition venue.hpp:114
std::uint64_t xdp_fallback
Definition venue.hpp:122
FeedState state
Definition venue.hpp:94
Snapshot for the stats line; every field is a plain counter so it can be copied out from the control ...
Definition venue.hpp:127
std::uint64_t executions_fetched
trade-history rows replayed into the order sink
Definition venue.hpp:159
WireLatencyWindow wire_1m
the same three over the last minute (60-70 s)
Definition venue.hpp:169
std::uint64_t refused_orders_1d
Definition venue.hpp:155
std::uint64_t order_events
Definition venue.hpp:140
std::uint32_t books_synced
Definition venue.hpp:131
std::uint32_t books_total
Definition venue.hpp:132
std::uint64_t refused_orders_1m
Definition venue.hpp:154
std::uint64_t md_malformed
Definition venue.hpp:134
WireLatencyStats order_encode
JSON encoding + signing.
Definition venue.hpp:167
std::uint64_t funding_fetched
funding payments replayed from the venue
Definition venue.hpp:162
std::uint64_t refused_weight
Orders and replaces the connector's rate limiter refused (VenueRateLimit, never sent),...
Definition venue.hpp:152
std::uint64_t shadows
order shadows held: orders working, in flight, or not yet swept
Definition venue.hpp:142
std::int64_t clock_offset_ms
venue - local
Definition venue.hpp:157
WireLatencyStats wire_tick_to_trade
Network-thread order latency (wire_latency.hpp), cumulative for the session.
Definition venue.hpp:166
std::uint64_t refused_orders_10s
Definition venue.hpp:153
std::uint64_t replaces_sent
Definition venue.hpp:139
std::uint64_t resyncs
Definition venue.hpp:136
std::uint64_t rest_errors
Definition venue.hpp:147
std::uint64_t order_send_failures
Definition venue.hpp:141
std::int64_t last_md_rx_ns
reactor clock
Definition venue.hpp:163
VenueFeedStatus feed
multicast venues only
Definition venue.hpp:171
ChannelState order
Definition venue.hpp:130
std::uint64_t cancels_sent
Definition venue.hpp:138
ChannelState md
Definition venue.hpp:128
WireLatencyWindow wire_1h
and over the last hour (60-70 min)
Definition venue.hpp:170
std::uint64_t rest_requests
Definition venue.hpp:146
std::uint64_t rate_limit_cooldowns
Definition venue.hpp:148
std::uint64_t md_messages
Definition venue.hpp:133
ChannelState user
Definition venue.hpp:129
std::uint64_t md_dropped
ring overflow
Definition venue.hpp:135
std::uint64_t shadows_swept
order shadows a reconciliation proved dead (lost terminal events)
Definition venue.hpp:143
std::uint64_t reconnects
Definition venue.hpp:158
WireLatencyStats order_send
WebSocket write / REST request call.
Definition venue.hpp:168
std::uint64_t shadows_refused
orders not sent: no room for a shadow (OrderTableFull)
Definition venue.hpp:145
std::uint64_t orders_sent
Definition venue.hpp:137
std::uint64_t execution_queries
Definition venue.hpp:160
std::uint64_t refused_paused
Definition venue.hpp:156
std::uint64_t execution_query_errors
a reconciliation that could not be made exact
Definition venue.hpp:161
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...