FastMM documentation
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
venue.hpp
Go to the documentation of this file.
1#pragma once
2// Venue: the control-path interface every exchange connector implements (6.2). Nothing here
3// is on the hot path; the hot path lives in the connector's feed/gateway objects that the
4// concrete Venue owns and drives from its reactor thread.
5//
6// Threading contract (see include/fastmm/live/session.hpp):
7// * load_reference_data() and attach() run once on the main thread before any reactor
8// thread starts (blocking REST allowed).
9// * connect/disconnect/subscribe/on_timer/on_wake/request_open_orders run on the venue's
10// reactor thread (the backend posts them there).
11// * cancel_all() must be callable from ANY thread, including when the reactor thread is
12// wedged: implementations use an independent blocking REST connection (6.7 kill switch).
13#include "fastmm/core/fees.hpp"
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"
21#include "fastmm/core/time.hpp"
27
28#include <cstdint>
29#include <functional>
30#include <memory>
31#include <span>
32#include <string>
33#include <string_view>
34#include <utility>
35#include <vector>
36
37namespace fastmm::venues {
38
39class MdCopy; // venues/md_copy.hpp
40class UpdateFilter; // venues/md_copy.hpp
41
42struct VenueCaps {
43 bool supports_replace = false; // Binance cancelReplace / Bybit amend
44 bool supports_post_only = true; // LIMIT_MAKER / PostOnly
45 bool ws_order_entry = true; // orders over WebSocket (REST fallback otherwise)
46 bool user_stream = true; // private order/fill stream available (false in dry-run)
47 // Moves an asset between accounts of the same exchange (Venue::transfer): the connector has the
48 // credentials for it (Binance: a master-account key, transfer_api_key_env).
49 bool internal_transfer = false;
50};
52enum class ChannelState : std::uint8_t { Down = 0, Connecting = 1, Live = 2, Stale = 3 };
53[[nodiscard]] constexpr std::string_view to_string(ChannelState s) noexcept {
54 switch (s) {
56 return "Down";
58 return "Connecting";
60 return "Live";
62 return "Stale";
63 }
64 return "?";
65}
66
67// Multicast feed (nasdaq_itch, ADR-0015 section 5); zero for the WebSocket venues.
68enum class FeedState : std::uint8_t {
69 None = 0, // not a multicast venue
70 Down = 1, // not joined yet
71 Snapshot = 2, // joined and buffering; waiting for GLIMPSE (or sequence 1)
72 Live = 3, // books built, messages applied as they arrive
73 Lost = 4, // cannot rebuild the books: the venue's kill switch is tripped (FeedLost)
74};
75[[nodiscard]] constexpr std::string_view to_string(FeedState s) noexcept {
76 switch (s) {
78 return "none";
79 case FeedState::Down:
80 return "down";
82 return "snapshot";
83 case FeedState::Live:
84 return "live";
85 case FeedState::Lost:
86 return "lost";
87 }
88 return "?";
89}
90
91struct VenueFeedStatus {
93 std::uint8_t backend = 0; // 0 kernel, 1 af_xdp, 2 dpdk
94 std::uint8_t xdp_mode = 0; // net::XdpMode the first interface settled on (af_xdp)
95 std::uint64_t packets = 0; // MoldUDP64 packets accepted (all lines, retransmissions included)
96 std::uint64_t bytes = 0; // datagram payload bytes received
97 std::uint64_t line_packets[2] = {0, 0}; // lines A, B
98 std::uint64_t line_duplicates[2] = {0, 0}; // copies that arrived after the first
99 std::int64_t line_skew_mean_ns[2] = {0, 0}; // arrival of a duplicate after the first copy
100 std::int64_t line_skew_max_ns[2] = {0, 0};
101 std::uint64_t gaps = 0; // gaps declared
102 std::uint64_t recovered = 0; // messages delivered from retransmissions
103 std::uint64_t unrecovered = 0; // sequences given up
104 std::uint64_t snapshot_recoveries = 0; // GLIMPSE snapshots applied after the first
105 std::uint64_t recovery_overflows = 0; // recovery buffer full during a snapshot
106 std::uint64_t reorder_high_water = 0;
107 std::uint64_t requests = 0; // MoldUDP64 request packets sent
108 std::uint64_t malformed = 0; // datagrams that are not MoldUDP64 packets, bad frames (af_xdp)
109 std::uint64_t book_errors = 0; // L3 inconsistencies (each starts a resync)
110 // L3 price-window moves summed over the books, and the moves skipped for a full overflow store.
111 std::uint64_t book_recentres = 0;
112 std::uint64_t book_recentre_failures = 0;
113 WireLatencyStats kernel_to_t0; // t0_wall_ns - sw_ts_ns (kernel backend only)
114 // af_xdp: XDP_STATISTICS summed over the sockets, and packets passed to the kernel because
115 // their RX queue had no socket.
116 std::uint64_t xdp_rx_dropped = 0;
117 std::uint64_t xdp_rx_invalid_descs = 0;
118 std::uint64_t xdp_rx_ring_full = 0;
119 std::uint64_t xdp_fill_ring_empty = 0;
120 std::uint64_t xdp_fallback = 0;
123// Snapshot for the stats line; every field is a plain counter so it can be copied out from
124// the control thread (the venue publishes it through a Seqlocked).
125struct VenueStatus {
129 std::uint32_t books_synced = 0;
130 std::uint32_t books_total = 0;
131 std::uint64_t md_messages = 0;
132 std::uint64_t md_malformed = 0;
133 std::uint64_t md_dropped = 0; // ring overflow
134 std::uint64_t resyncs = 0;
135 std::uint64_t orders_sent = 0;
136 std::uint64_t cancels_sent = 0;
137 std::uint64_t replaces_sent = 0;
138 std::uint64_t order_events = 0;
139 std::uint64_t order_send_failures = 0;
140 std::uint64_t shadows = 0; // order shadows held: orders working, in flight, or not yet swept
141 std::uint64_t shadows_swept =
142 0; // order shadows a reconciliation proved dead (lost terminal events)
143 std::uint64_t shadows_refused = 0; // orders not sent: no room for a shadow (OrderTableFull)
144 std::uint64_t rest_requests = 0;
145 std::uint64_t rest_errors = 0;
146 std::uint64_t rate_limit_cooldowns = 0;
147 // Orders and replaces the connector's rate limiter refused (VenueRateLimit, never sent), by
148 // the limit that refused them (RateLimiter::check): the IP's request weight, the order-count
149 // windows of up to 10 s, up to a minute and longer (the day), and a pause (429, 418).
150 std::uint64_t refused_weight = 0;
151 std::uint64_t refused_orders_10s = 0;
152 std::uint64_t refused_orders_1m = 0;
153 std::uint64_t refused_orders_1d = 0;
154 std::uint64_t refused_paused = 0;
155 std::int64_t clock_offset_ms = 0; // venue - local
156 std::uint64_t reconnects = 0;
157 std::uint64_t executions_fetched = 0; // trade-history rows replayed into the order sink
158 std::uint64_t execution_queries = 0;
159 std::uint64_t execution_query_errors = 0; // a reconciliation that could not be made exact
160 std::uint64_t funding_fetched = 0; // funding payments replayed from the venue
161 std::int64_t last_md_rx_ns = 0; // reactor clock
162 // Network-thread order latency (wire_latency.hpp), cumulative for the session. The ns
163 // percentiles need a calibration source (Venue::set_tsc_calibration_source); counts do not.
164 WireLatencyStats wire_tick_to_trade; // inbound receive (t0_cycles) -> send call returned
165 WireLatencyStats order_encode; // JSON encoding + signing
166 WireLatencyStats order_send; // WebSocket write / REST request call
167 WireLatencyWindow wire_1m; // the same three over the last minute (60-70 s)
168 WireLatencyWindow wire_1h; // and over the last hour (60-70 min)
169 VenueFeedStatus feed; // multicast venues only
172// The account's own fee rates on one instrument (Venue::account_fees).
173struct VenueFee {
178// An order counted as sent whose batch was then never written (the connection failed at
179// uncork()): the connector rejects it, so it is taken back out of the sent counters.
180inline void unsend(VenueStatus& s, OrderCommandKind k) noexcept {
181 switch (k) {
183 --s.orders_sent;
184 break;
186 --s.cancels_sent;
187 break;
189 --s.replaces_sent;
190 break;
191 }
192}
193
194class Venue {
195 public:
196 virtual ~Venue() = default;
197
198 [[nodiscard]] virtual VenueId id() const noexcept = 0;
199 [[nodiscard]] virtual std::string_view name() const noexcept = 0;
200 [[nodiscard]] virtual VenueCaps caps() const noexcept = 0;
202 // Fetches exchangeInfo / instruments-info for every instrument of this venue and
203 // overwrites tick/lot/min_qty/max_qty/min_notional with the venue's values (config values
204 // are a fallback when the venue is unreachable and `allow_offline` is set), and the trading
205 // status where the venue states one (Instrument::status). Fatal on mismatch of a required
206 // symbol. fastmm-live then compares the result with the configuration ([venues.<name>]
207 // rules_mismatch).
208 virtual Result<void, std::string> load_reference_data(InstrumentTable& instruments) = 0;
209 // Reads the rules load_reference_data() read again, now and asynchronously, and emits an
210 // InstrumentRulesMsg into the order sink for each instrument whose tick, lot, limits or trading
211 // status differ from the last the connector reported (venues/instrument_rules.hpp). A connector
212 // that implements it also reads them every [venues.<name>] rules_refresh_s and soon after the
213 // venue refused an order or a cancel for an instrument's rules or status. Reactor thread. False
214 // when the connector cannot read them while it runs (the default) or a read is in flight.
215 virtual bool refresh_rules() { return false; }
216 // The account's fee rates on this venue's instruments in `instruments`, fetched from the venue
217 // (Binance Spot with fetch_fees = true: GET /api/v3/account/commission per symbol). Main thread,
218 // after load_reference_data(), blocking REST allowed. Empty when the connector does not fetch
219 // them; an error when it was asked to and could not.
220 virtual Result<std::vector<VenueFee>, std::string> account_fees(
221 const InstrumentTable& /*instruments*/) {
222 return std::vector<VenueFee>{};
223 }
224 // After load_reference_data() failed: true when it refused a setting of the account (a position
225 // mode the connector does not trade in), which a retry does not fix. fastmm-live then exits 3,
226 // like a configuration error, instead of 4.
227 [[nodiscard]] virtual bool refused_account_settings() const noexcept { return false; }
228
229 // Wires the sinks (md: lossy, orders: never dropped) and the outbound ring the engine
230 // writes Out*Msg into. Must be called before connect().
231 virtual void attach(const SymbolTable& symbols,
232 const InstrumentTable& instruments,
233 EventSink& md_sink,
234 EventSink& order_sink,
235 MsgRing* outbound) = 0;
236
237 // Opens every channel (market data, user stream, order entry) on `reactor`.
238 virtual void connect(net::Reactor& reactor) = 0;
239 virtual void disconnect() = 0;
240 // Warm standby (fastmm-live --standby while another process holds the instance lock). Called
241 // before connect(); true when the connector takes it: connect() then opens only what public
242 // market data needs (a pool member, which reads none, opens nothing), and enable_private(), on
243 // the network thread, opens the rest: order entry, the private stream, the execution replay and
244 // the start-up sweep of open orders. Nothing in between sends, cancels or reads anything of the
245 // account. False: the connector cannot split, and the session waits for the lock before it
246 // connects at all.
247 virtual bool defer_private() { return false; }
248 virtual void enable_private() {}
249 virtual void subscribe(std::span<const InstrumentId> instruments) = 0;
251 // Redundant market data ([venues.<name>] md_copies, venues/md_copy.hpp): one more connection
252 // carrying the subscribed instruments' top-of-book (and trade) streams, which pushes into `sink`
253 // what `filter` lets through. From the first call on, the venue's own feed asks `filter` too, so
254 // each update reaches the engine once, from whichever connection delivered it first. Main
255 // thread, after subscribe() and before connect(); the copy is connected on the thread that runs
256 // it. nullptr: the connector has no copies (the default), or none in its present configuration.
257 virtual std::unique_ptr<MdCopy> make_md_copy(EventSink& sink, UpdateFilter& filter);
258 // Copies the connector's own keys ask for (binance_usdm md_ticker_conns, the older spelling of
259 // md_copies); the session opens the larger of this and md_copies.
260 [[nodiscard]] virtual std::uint32_t md_copies_requested() const noexcept { return 0; }
261
262 // Periodic housekeeping (listenKey keepalive, app-level pings, clock offset refresh,
263 // snapshot retries). The backend calls it about once per second; venues may also arm
264 // their own reactor timers.
265 virtual void on_timer(std::int64_t now_ns) = 0;
266 // The engine pushed Out*Msg into the outbound ring: drain, encode, send.
267 virtual void on_wake() = 0;
268 // Run-to-completion ([engine] threading = "single"): the engine runs on the reactor thread and
269 // hands its Out*Msg batch over here instead of the outbound ring. Encode and write them now, as
270 // on_wake() does; a message that cannot go out is refused through the order sink. Called from
271 // inside the venue's own callbacks (a market-data event reaches the engine as it is decoded).
272 virtual void send_now(std::span<const EventHeader* const> batch) = 0;
273 // Called by the network thread after every reactor iteration. Venues whose sockets are not
274 // registered with the reactor poll them here (nasdaq_itch with [engine] spin_mode = "busy").
275 virtual void poll() noexcept {}
276 // Every book starts over from a fresh snapshot: a ConnectionState{Resyncing} or Stale on the md
277 // sink, then a snapshot per instrument. fastmm-gateway calls it when its own copies of the books
278 // were lost (an attaching strategy gets snapshots of those copies instead). Reactor thread. The
279 // default does nothing: a venue that cannot resync on demand (nasdaq_itch) leaves the books to
280 // its next natural resync.
281 virtual void resync_books() {}
282
283 // Venue view of open orders -> ReconcileMsg Begin/OpenOrder*/End into the order sink. A
284 // connector that can fetch executions (VenueCapabilities::executions) replays everything the
285 // account traded since the watermark first, as ordinary OrderFillMsg carrying the venue's
286 // execution id and OrderFillMsg::kReplayed, and only then emits the snapshot with
287 // ReconcileMsg::kExecutionsExact on its Begin. That order is what closes the hole: a fill that
288 // finished an order is booked from the execution itself, so the snapshot - which no longer
289 // mentions the order at all - has nothing left to explain.
290 virtual void request_open_orders() = 0;
291 // The account's executions from `since_venue_ms` (the venue's clock, inclusive) onwards, for
292 // every subscribed instrument: the venue's trade-history query (myTrades / userTrades /
293 // execution/list / get_user_trades_by_currency_and_time). Each one is emitted into the order sink
294 // as an ordinary OrderFillMsg carrying the venue's execution id and OrderFillMsg::kReplayed, so
295 // the OMS books only the ones it has not seen. Zero means "from wherever this connector last got
296 // to", which is what a reconciliation uses; a caller that knows better - the time of the last
297 // execution the engine booked, which the store and the journal both hold - passes it.
298 //
299 // Asynchronous and part of a reconciliation: the connector runs it before the open-order snapshot
300 // and stamps ReconcileMsg::kExecutionsExact on the snapshot's Begin when every instrument
301 // answered in full. Returns false when this connector cannot ask (VenueCapabilities::executions
302 // is false) or has nowhere to send the query, which is the only case where a fill the private
303 // stream missed stays an estimate.
304 virtual bool request_executions(std::int64_t /*since_venue_ms*/ = 0) { return false; }
305 // Where the first execution replay starts, for a session that carries a position over from an
306 // earlier one (fastmm-live restores it from the store before connect()): executions from
307 // `since_venue_ms` onwards are booked, except those whose venue trade id is in `known`, which the
308 // earlier session booked already. A connector that cannot replay executions ignores it, and the
309 // session does not restore a position for it (VenueCapabilities::executions).
310 virtual void resume_executions(std::int64_t /*since_venue_ms*/,
311 const std::vector<std::string>& /*known*/) {}
312 // An exact start where the venue's trade ids increase per instrument (Binance): the first trade
313 // id to ask for, per instrument - one past the last the earlier session booked. Called after
314 // resume_executions(); an instrument listed here replays from its id and ignores the time and
315 // the known ids, the others go on from `since_venue_ms`. Connectors without such ids ignore it.
316 virtual void resume_trade_ids(
317 const std::vector<std::pair<InstrumentId, std::int64_t>>& /*next_ids*/) {}
318 // The trade ids at or after an instrument's start (resume_trade_ids) that are booked already,
319 // ascending: a session that died inside its replay stored them, and the start stays before
320 // them because that replay had not read everything below them. Called after
321 // resume_trade_ids(); the replay skips them.
322 virtual void resume_known_trade_ids(
323 const std::vector<std::pair<InstrumentId, std::vector<std::int64_t>>>& /*known*/) {}
324 // Fill audit (live/fill_auditor.hpp): the account's executions with the venue's time in
325 // [start_ms, end_ms] on every subscribed instrument, read from the same trade history as
326 // request_executions() but apart from it (venues/execution_audit.hpp): nothing is emitted into
327 // the order sink, and the replay's watermark does not move. AuditFill::symbol is the instrument's
328 // symbol. `done` runs once on the reactor thread, complete = false when a query failed or the
329 // connection went down. Returns false, and never calls `done`, when the connector has no such
330 // read, is not connected, or one is running. Reactor thread. By value: a connector keeps it.
331 virtual bool audit_executions(std::int64_t /*start_ms*/,
332 std::int64_t /*end_ms*/,
333 // NOLINTNEXTLINE(performance-unnecessary-value-param)
334 std::function<void(bool, std::vector<AuditFill>)> /*done*/) {
335 return false;
336 }
337 // Whether audit_executions() is implemented. Any thread.
338 [[nodiscard]] virtual bool can_audit_executions() const noexcept { return false; }
339 // ---- internal transfers (VenueCaps::internal_transfer, core/transfer.hpp) --------------------
340 // Moves req.amount of req.asset from account req.from_account to req.to_account, both accounts
341 // of this exchange (the venues of one pool), under req.client_id. Blocking, over a REST
342 // connection of its own: callable from any thread but the venue's reactor thread (the pool
343 // treasury calls it from its own). Pending or Done: the venue took it; Failed: it refused,
344 // nothing moved; Unknown: no usable answer, ask transfer_status(). The default refuses (Failed).
345 virtual TransferResult transfer(const TransferRequest& /*req*/) {
346 return {TransferState::Failed, {}, "this connector has no internal transfers"};
347 }
348 // The state of the transfer named req.client_id (the same request transfer() was given). A
349 // transfer the connector carries out in several steps is finished from here when an earlier call
350 // left a step unsent. Blocking, like transfer().
352 return {TransferState::Unknown, {}, "this connector has no internal transfers"};
353 }
354 // This account's name in a transfer request (a Binance sub-account's email; empty for the
355 // exchange's master account).
356 [[nodiscard]] virtual std::string transfer_account() const { return {}; }
357 // Asks the venue for the account's balances now, emitted as a BalanceMsg snapshot on the order
358 // sink (the balance leg of the reconciliation). Reactor thread. The default does nothing.
359 virtual void request_balances() {}
360
361 // Kill switch: cancel every open order on every subscribed symbol via an independent
362 // REST connection. Blocking; safe from any thread. Returns false if the venue refused.
363 virtual bool cancel_all() = 0;
364
365 [[nodiscard]] virtual VenueStatus status() const noexcept = 0;
366
367 // Published TSC calibrations used to convert the network thread's cycle histograms to ns
368 // when the status is published. Set before connect(); the source must outlive the venue's
369 // reactor thread.
370 void set_tsc_calibration_source(const Seqlocked<TscCalibration>* src) noexcept {
371 tsc_source_ = src;
372 }
373 // The order budget the connector publishes from its rate limiter (core/order_budget.hpp): its
374 // reactor thread writes it with the status and after each response that reported the venue's
375 // counts; the engine reads it through LiveTransport (ctx.order_budget). Lives with the venue.
376 [[nodiscard]] const Seqlocked<OrderBudget>& budget_source() const noexcept { return budget_pub_; }
377
378 protected:
379 // Latest published calibration, or a calibration with use_tsc == false without a source.
380 [[nodiscard]] TscCalibration tsc_calibration() const noexcept {
381 return tsc_source_ != nullptr ? tsc_source_->load() : TscCalibration{};
382 }
383 Seqlocked<OrderBudget> budget_pub_;
384 // New orders and replaces taken off the engine's ring (send_command), sent or refused: published
385 // with the budget (OrderBudget::orders_taken). Reactor thread only.
386 std::uint64_t orders_taken_ = 0;
387 void note_taken(const OrderCommand& cmd) noexcept {
388 if (cmd.kind != OrderCommandKind::Cancel) ++orders_taken_;
389 }
390
391 private:
392 const Seqlocked<TscCalibration>* tsc_source_ = nullptr;
393};
394
395} // namespace fastmm::venues
Dense-by-id table built at startup; symbol lookup is a sorted FlatMap keyed by (venue,...
Definition instrument.hpp:147
Definition result.hpp:30
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 ~Venue()=default
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).
Definition venue.hpp:39
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 time.hpp:89
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
Definition venue.hpp:93
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.
Time primitives.
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...