FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::venues::Venue Class Referenceabstract

#include <fastmm/venues/venue.hpp>

Public Member Functions

virtual ~Venue ()=default
 
virtual VenueId id () const noexcept=0
 
virtual std::string_view name () const noexcept=0
 
virtual VenueCaps caps () const noexcept=0
 
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/min_qty/max_qty/min_notional with the venue's values (config values are a fallback when the venue is unreachable and allow_offline is set).
 
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 Spot with fetch_fees = true: GET /api/v3/account/commission per symbol).
 
virtual bool refused_account_settings () const noexcept
 After load_reference_data() failed: true when it refused a setting of the account (a position mode the connector does not trade in), which a retry does not fix.
 
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 into.
 
virtual void connect (net::Reactor &reactor)=0
 Opens every channel (market data, user stream, order entry) on reactor.
 
virtual void disconnect ()=0
 
virtual bool defer_private ()
 Warm standby (fastmm-live --standby while another process holds the instance lock).
 
virtual void enable_private ()
 
virtual void subscribe (std::span< const InstrumentId > instruments)=0
 
virtual void on_timer (std::int64_t now_ns)=0
 Periodic housekeeping (listenKey keepalive, app-level pings, clock offset refresh, snapshot retries).
 
virtual void on_wake ()=0
 The engine pushed Out*Msg into the outbound ring: drain, encode, send.
 
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 its Out*Msg batch over here instead of the outbound ring.
 
virtual void poll () noexcept
 Called by the network thread after every reactor iteration.
 
virtual void resync_books ()
 Every book starts over from a fresh snapshot: a ConnectionState{Resyncing} or Stale on the md sink, then a snapshot per instrument.
 
virtual void request_open_orders ()=0
 Venue view of open orders -> ReconcileMsg Begin/OpenOrder*‍/End into the order sink.
 
virtual bool request_executions (std::int64_t=0)
 The account's executions from since_venue_ms (the venue's clock, inclusive) onwards, for every subscribed instrument: the venue's trade-history query (myTrades / userTrades / execution/list / get_user_trades_by_currency_and_time).
 
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 one (fastmm-live restores it from the store before connect()): executions from since_venue_ms onwards are booked, except those whose venue trade id is in known, which the earlier session booked already.
 
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 ask for, per instrument - one past the last the earlier session booked.
 
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, ascending: a session that died inside its replay stored them, and the start stays before them because that replay had not read everything below them.
 
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, end_ms] on every subscribed instrument, read from the same trade history as request_executions() but apart from it (venues/execution_audit.hpp): nothing is emitted into the order sink, and the replay's watermark does not move.
 
virtual bool can_audit_executions () const noexcept
 Whether audit_executions() is implemented. Any thread.
 
virtual TransferResult transfer (const TransferRequest &)
 Moves req.amount of req.asset from account req.from_account to req.to_account, both accounts of this exchange (the venues of one pool), under req.client_id.
 
virtual TransferResult transfer_status (const TransferRequest &)
 The state of the transfer named req.client_id (the same request transfer() was given).
 
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 master account).
 
virtual void request_balances ()
 Asks the venue for the account's balances now, emitted as a BalanceMsg snapshot on the order sink (the balance leg of the reconciliation).
 
virtual bool cancel_all ()=0
 Kill switch: cancel every open order on every subscribed symbol via an independent REST connection.
 
virtual VenueStatus status () const noexcept=0
 
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 status is published.
 
const Seqlocked< OrderBudget > & budget_source () const noexcept
 The order budget the connector publishes from its rate limiter (core/order_budget.hpp): its reactor thread writes it with the status and after each response that reported the venue's counts; the engine reads it through LiveTransport (ctx.order_budget).
 

Protected Member Functions

TscCalibration tsc_calibration () const noexcept
 Latest published calibration, or a calibration with use_tsc == false without a source.
 
void note_taken (const OrderCommand &cmd) noexcept
 

Protected Attributes

Seqlocked< OrderBudget > budget_pub_
 
std::uint64_t orders_taken_ = 0
 New orders and replaces taken off the engine's ring (send_command), sent or refused: published with the budget (OrderBudget::orders_taken).
 

Constructor & Destructor Documentation

◆ ~Venue()

virtual fastmm::venues::Venue::~Venue ( )
virtualdefault

Member Function Documentation

◆ id()

virtual VenueId fastmm::venues::Venue::id ( ) const
pure virtualnoexcept

◆ name()

virtual std::string_view fastmm::venues::Venue::name ( ) const
pure virtualnoexcept

◆ caps()

virtual VenueCaps fastmm::venues::Venue::caps ( ) const
pure virtualnoexcept

◆ load_reference_data()

virtual Result< void, std::string > fastmm::venues::Venue::load_reference_data ( InstrumentTable &  instruments)
pure virtual

Fetches exchangeInfo / instruments-info for every instrument of this venue and overwrites tick/lot/min_qty/max_qty/min_notional with the venue's values (config values are a fallback when the venue is unreachable and allow_offline is set).

Fatal on mismatch of a required symbol.

◆ account_fees()

virtual Result< std::vector< VenueFee >, std::string > fastmm::venues::Venue::account_fees ( const InstrumentTable &  )
inlinevirtual

The account's fee rates on this venue's instruments in instruments, fetched from the venue (Binance Spot with fetch_fees = true: GET /api/v3/account/commission per symbol).

Main thread, after load_reference_data(), blocking REST allowed. Empty when the connector does not fetch them; an error when it was asked to and could not.

◆ refused_account_settings()

virtual bool fastmm::venues::Venue::refused_account_settings ( ) const
inlinevirtualnoexcept

After load_reference_data() failed: true when it refused a setting of the account (a position mode the connector does not trade in), which a retry does not fix.

fastmm-live then exits 3, like a configuration error, instead of 4.

◆ attach()

virtual void fastmm::venues::Venue::attach ( const SymbolTable &  symbols,
const InstrumentTable &  instruments,
EventSink &  md_sink,
EventSink &  order_sink,
MsgRing *  outbound 
)
pure virtual

Wires the sinks (md: lossy, orders: never dropped) and the outbound ring the engine writes Out*Msg into.

Must be called before connect().

◆ connect()

virtual void fastmm::venues::Venue::connect ( net::Reactor &  reactor)
pure virtual

Opens every channel (market data, user stream, order entry) on reactor.

◆ disconnect()

virtual void fastmm::venues::Venue::disconnect ( )
pure virtual

◆ defer_private()

virtual bool fastmm::venues::Venue::defer_private ( )
inlinevirtual

Warm standby (fastmm-live --standby while another process holds the instance lock).

Called before connect(); true when the connector takes it: connect() then opens only what public market data needs (a pool member, which reads none, opens nothing), and enable_private(), on the network thread, opens the rest: order entry, the private stream, the execution replay and the start-up sweep of open orders. Nothing in between sends, cancels or reads anything of the account. False: the connector cannot split, and the session waits for the lock before it connects at all.

◆ enable_private()

virtual void fastmm::venues::Venue::enable_private ( )
inlinevirtual

◆ subscribe()

virtual void fastmm::venues::Venue::subscribe ( std::span< const InstrumentId >  instruments)
pure virtual

◆ on_timer()

virtual void fastmm::venues::Venue::on_timer ( std::int64_t  now_ns)
pure virtual

Periodic housekeeping (listenKey keepalive, app-level pings, clock offset refresh, snapshot retries).

The backend calls it about once per second; venues may also arm their own reactor timers.

◆ on_wake()

virtual void fastmm::venues::Venue::on_wake ( )
pure virtual

The engine pushed Out*Msg into the outbound ring: drain, encode, send.

◆ send_now()

virtual void fastmm::venues::Venue::send_now ( std::span< const EventHeader *const >  batch)
pure virtual

Run-to-completion ([engine] threading = "single"): the engine runs on the reactor thread and hands its Out*Msg batch over here instead of the outbound ring.

Encode and write them now, as on_wake() does; a message that cannot go out is refused through the order sink. Called from inside the venue's own callbacks (a market-data event reaches the engine as it is decoded).

◆ poll()

virtual void fastmm::venues::Venue::poll ( )
inlinevirtualnoexcept

Called by the network thread after every reactor iteration.

Venues whose sockets are not registered with the reactor poll them here (nasdaq_itch with [engine] spin_mode = "busy").

◆ resync_books()

virtual void fastmm::venues::Venue::resync_books ( )
inlinevirtual

Every book starts over from a fresh snapshot: a ConnectionState{Resyncing} or Stale on the md sink, then a snapshot per instrument.

fastmm-gateway calls it when its own copies of the books were lost (an attaching strategy gets snapshots of those copies instead). Reactor thread. The default does nothing: a venue that cannot resync on demand (nasdaq_itch) leaves the books to its next natural resync.

◆ request_open_orders()

virtual void fastmm::venues::Venue::request_open_orders ( )
pure virtual

Venue view of open orders -> ReconcileMsg Begin/OpenOrder*‍/End into the order sink.

A connector that can fetch executions (VenueCapabilities::executions) replays everything the account traded since the watermark first, as ordinary OrderFillMsg carrying the venue's execution id and OrderFillMsg::kReplayed, and only then emits the snapshot with ReconcileMsg::kExecutionsExact on its Begin. That order is what closes the hole: a fill that finished an order is booked from the execution itself, so the snapshot - which no longer mentions the order at all - has nothing left to explain.

◆ request_executions()

virtual bool fastmm::venues::Venue::request_executions ( std::int64_t  = 0)
inlinevirtual

The account's executions from since_venue_ms (the venue's clock, inclusive) onwards, for every subscribed instrument: the venue's trade-history query (myTrades / userTrades / execution/list / get_user_trades_by_currency_and_time).

Each one is emitted into the order sink as an ordinary OrderFillMsg carrying the venue's execution id and OrderFillMsg::kReplayed, so the OMS books only the ones it has not seen. Zero means "from wherever this connector last got to", which is what a reconciliation uses; a caller that knows better - the time of the last execution the engine booked, which the store and the journal both hold - passes it.

Asynchronous and part of a reconciliation: the connector runs it before the open-order snapshot and stamps ReconcileMsg::kExecutionsExact on the snapshot's Begin when every instrument answered in full. Returns false when this connector cannot ask (VenueCapabilities::executions is false) or has nowhere to send the query, which is the only case where a fill the private stream missed stays an estimate.

◆ resume_executions()

virtual void fastmm::venues::Venue::resume_executions ( std::int64_t  ,
const std::vector< std::string > &   
)
inlinevirtual

Where the first execution replay starts, for a session that carries a position over from an earlier one (fastmm-live restores it from the store before connect()): executions from since_venue_ms onwards are booked, except those whose venue trade id is in known, which the earlier session booked already.

A connector that cannot replay executions ignores it, and the session does not restore a position for it (VenueCapabilities::executions).

◆ resume_trade_ids()

virtual void fastmm::venues::Venue::resume_trade_ids ( const std::vector< std::pair< InstrumentId, std::int64_t > > &  )
inlinevirtual

An exact start where the venue's trade ids increase per instrument (Binance): the first trade id to ask for, per instrument - one past the last the earlier session booked.

Called after resume_executions(); an instrument listed here replays from its id and ignores the time and the known ids, the others go on from since_venue_ms. Connectors without such ids ignore it.

◆ resume_known_trade_ids()

virtual void fastmm::venues::Venue::resume_known_trade_ids ( const std::vector< std::pair< InstrumentId, std::vector< std::int64_t > > > &  )
inlinevirtual

The trade ids at or after an instrument's start (resume_trade_ids) that are booked already, ascending: a session that died inside its replay stored them, and the start stays before them because that replay had not read everything below them.

Called after resume_trade_ids(); the replay skips them.

◆ audit_executions()

virtual bool fastmm::venues::Venue::audit_executions ( std::int64_t  ,
std::int64_t  ,
std::function< void(bool, std::vector< AuditFill >)>   
)
inlinevirtual

Fill audit (live/fill_auditor.hpp): the account's executions with the venue's time in [start_ms, end_ms] on every subscribed instrument, read from the same trade history as request_executions() but apart from it (venues/execution_audit.hpp): nothing is emitted into the order sink, and the replay's watermark does not move.

AuditFill::symbol is the instrument's symbol. done runs once on the reactor thread, complete = false when a query failed or the connection went down. Returns false, and never calls done, when the connector has no such read, is not connected, or one is running. Reactor thread. By value: a connector keeps it.

◆ can_audit_executions()

virtual bool fastmm::venues::Venue::can_audit_executions ( ) const
inlinevirtualnoexcept

Whether audit_executions() is implemented. Any thread.

◆ transfer()

virtual TransferResult fastmm::venues::Venue::transfer ( const TransferRequest &  )
inlinevirtual

Moves req.amount of req.asset from account req.from_account to req.to_account, both accounts of this exchange (the venues of one pool), under req.client_id.

Blocking, over a REST connection of its own: callable from any thread but the venue's reactor thread (the pool treasury calls it from its own). Pending or Done: the venue took it; Failed: it refused, nothing moved; Unknown: no usable answer, ask transfer_status(). The default refuses (Failed).

◆ transfer_status()

virtual TransferResult fastmm::venues::Venue::transfer_status ( const TransferRequest &  )
inlinevirtual

The state of the transfer named req.client_id (the same request transfer() was given).

A transfer the connector carries out in several steps is finished from here when an earlier call left a step unsent. Blocking, like transfer().

◆ transfer_account()

virtual std::string fastmm::venues::Venue::transfer_account ( ) const
inlinevirtual

This account's name in a transfer request (a Binance sub-account's email; empty for the exchange's master account).

◆ request_balances()

virtual void fastmm::venues::Venue::request_balances ( )
inlinevirtual

Asks the venue for the account's balances now, emitted as a BalanceMsg snapshot on the order sink (the balance leg of the reconciliation).

Reactor thread. The default does nothing.

◆ cancel_all()

virtual bool fastmm::venues::Venue::cancel_all ( )
pure virtual

Kill switch: cancel every open order on every subscribed symbol via an independent REST connection.

Blocking; safe from any thread. Returns false if the venue refused.

◆ status()

virtual VenueStatus fastmm::venues::Venue::status ( ) const
pure virtualnoexcept

◆ set_tsc_calibration_source()

void fastmm::venues::Venue::set_tsc_calibration_source ( const Seqlocked< TscCalibration > *  src)
inlinenoexcept

Published TSC calibrations used to convert the network thread's cycle histograms to ns when the status is published.

Set before connect(); the source must outlive the venue's reactor thread.

◆ budget_source()

const Seqlocked< OrderBudget > & fastmm::venues::Venue::budget_source ( ) const
inlinenoexcept

The order budget the connector publishes from its rate limiter (core/order_budget.hpp): its reactor thread writes it with the status and after each response that reported the venue's counts; the engine reads it through LiveTransport (ctx.order_budget).

Lives with the venue.

◆ tsc_calibration()

TscCalibration fastmm::venues::Venue::tsc_calibration ( ) const
inlineprotectednoexcept

Latest published calibration, or a calibration with use_tsc == false without a source.

◆ note_taken()

void fastmm::venues::Venue::note_taken ( const OrderCommand &  cmd)
inlineprotectednoexcept

Member Data Documentation

◆ budget_pub_

Seqlocked<OrderBudget> fastmm::venues::Venue::budget_pub_
protected

◆ orders_taken_

std::uint64_t fastmm::venues::Venue::orders_taken_ = 0
protected

New orders and replaces taken off the engine's ring (send_command), sent or refused: published with the budget (OrderBudget::orders_taken).

Reactor thread only.