|
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
|
Classes | |
| class | BatchedOrders |
| The orders a venue encoded into a corked connection. More... | |
| class | BlockingHttp |
| struct | BlockingHttpOptions |
| class | ConnectionSlot |
| class | CountdownDriver |
| What a connector does with a countdown switch, the same for every venue that has one (Binance USDⓈ-M countdownCancelAll, OKX cancel-all-after). More... | |
| class | CountdownSwitch |
| Refresh clock for a countdown dead man's switch. More... | |
| class | DecimalText |
Stack formatting buffer: DecimalText t(px); send(t.view()); - no heap, no locale. More... | |
| struct | DecodeResult |
| struct | ErrorMapping |
| class | EventSink |
| struct | HttpReply |
| class | JsonWriter |
| struct | OrderCommand |
| class | OutboundBatch |
| The engine's batch handed over directly (run-to-completion, Venue::send_now) behind the consumer side of MsgRing, so drain_outbound_coalesced takes either. More... | |
| class | PaddedJson |
| struct | RateBucket |
| struct | RateCheck |
| class | RateLimiter |
| class | RawRecorder |
| class | RecentSpend |
| What was sent in the last couple of seconds (RateLimiter::kHeaderLagNs), in 125 ms slots. More... | |
| class | RestChannel |
| struct | RestChannelConfig |
| class | SentWatermark |
| The watermark stamped into an open-order snapshot's ReconcileMsg Begin: the engine's orders at or below it can be judged by the snapshot, the ones above it cannot. More... | |
| struct | SharedRate |
| One IP's request weight, shared by every account that sends from it (RateLimiter::share_ip). More... | |
| class | SymbolTable |
| class | Venue |
| struct | VenueCapabilities |
| What a connector declares about itself before one exists. More... | |
| struct | VenueCaps |
| struct | VenueEntry |
| struct | VenueFactoryOptions |
| struct | VenueFee |
| The account's own fee rates on one instrument (Venue::account_fees). More... | |
| struct | VenueFeedStatus |
| struct | VenueKeySpec |
One [venues. More... | |
| class | VenueRegistry |
| struct | VenueStatus |
| Snapshot for the stats line; every field is a plain counter so it can be copied out from the control thread (the venue publishes it through a Seqlocked). More... | |
| class | WireLatencyRecorder |
| struct | WireLatencyStats |
| struct | WireLatencyWindow |
| The three over one window (WireLatencyRecorder::summarize). More... | |
Concepts | |
| concept | MarketDataFeed |
| concept | OrderGateway |
Typedefs | |
| using | RequestId = FixedString< 16 > |
Enumerations | |
| enum class | ChannelState : std::uint8_t { Down = 0 , Connecting = 1 , Live = 2 , Stale = 3 } |
| enum class | FeedState : std::uint8_t { None = 0 , Down = 1 , Snapshot = 2 , Live = 3 , Lost = 4 } |
| Multicast feed (nasdaq_itch, ADR-0015 section 5); zero for the WebSocket venues. More... | |
| enum class | AddResult : std::uint8_t { Added , AlreadyPresent , Conflict , Invalid } |
| enum class | ParseStatus : std::uint8_t { Ok = 0 , Ignored = 1 , Malformed = 2 , UnknownSymbol = 3 , Overflow = 4 , Error = 5 } |
| enum class | MdKind : std::uint8_t { None = 0 , BookDelta = 1 , BookSnapshot = 2 , BookTicker = 3 , Trade = 4 , PerpState = 5 } |
| What a decoder produced into the caller's scratch buffer. More... | |
| enum class | OrderEventKind : std::uint8_t { None = 0 , Ack = 1 , Reject = 2 , CancelAck = 3 , CancelReject = 4 , Fill = 5 , Expired = 6 , Position = 7 } |
| enum class | SinkPolicy : std::uint8_t { Drop = 0 , Spin = 1 } |
| enum class | OrderCommandKind : std::uint8_t { New = 0 , Cancel = 1 , Replace = 2 } |
| enum class | VenueAction : std::uint8_t { None = 0 , Backoff = 1 , RateLimit = 2 , ResyncClock = 3 , Reconcile = 4 , DisableInstrument = 5 , HardStop = 6 , Fatal = 7 } |
| What the connector does beyond reporting the reject to the engine. More... | |
| enum class | RateRefusal : std::uint8_t { None , Paused , Weight , Orders } |
| Why can_send refused (RateLimiter::check): the IP or account is paused (429 cooldown, 418), a weight window is at its share, or an order-count window is (RateCheck::window_ns says which). More... | |
| enum class | DecimalError : std::uint8_t { Empty = 1 , Malformed = 2 , Overflow = 3 } |
| enum class | RequestKind : char { New = 'n' , Cancel = 'c' , Replace = 'r' , Amend = 'a' , Other = 'x' } |
| Amend: a replace the venue applies to the resting order (Binance Spot keepPriority); its response has a different shape from a cancel-replace, so it needs its own kind. More... | |
Functions | |
| constexpr std::string_view | to_string (ChannelState s) noexcept |
| constexpr std::string_view | to_string (FeedState s) noexcept |
| void | unsend (VenueStatus &s, OrderCommandKind k) noexcept |
| An order counted as sent whose batch was then never written (the connection failed at uncork()): the connector rejects it, so it is taken back out of the sent counters. | |
| net::SourceAddress | source_address (const VenueSection &s) |
| Runtime knobs every connector honours, passed to the factory. | |
| constexpr std::string_view | to_string (AddResult r) noexcept |
| void | register_builtin_venues (VenueRegistry &r=VenueRegistry::instance()) |
| Adds the connectors FastMM ships (binance_spot, binance_usdm, bybit, deribit, nasdaq_itch). | |
| void | validate_venues (const Config &cfg, const VenueRegistry &r=VenueRegistry::instance()) |
Checks every [venues. | |
| std::unique_ptr< Venue > | make_venue (VenueId id, const VenueSection §ion, const VenueFactoryOptions &opts) |
Builds the connector section.kind names. | |
| std::unique_ptr< Venue > | make_venue (VenueId id, const VenueSection §ion, const VenueFactoryOptions &opts, const VenueRegistry &r) |
| constexpr std::string_view | to_string (ParseStatus s) noexcept |
| constexpr std::string_view | to_string (OrderCommandKind k) noexcept |
| bool | is_reconcile_request (const EventHeader &h) noexcept |
| The engine asks for a reconciliation (ControlCommand::Reconcile on the outbound ring). | |
| void | emit_order_reject (EventSink &sink, VenueId venue, InstrumentId inst, ClientOrderId id, RejectReason reason, int code, std::string_view text) noexcept |
| void | emit_cancel_reject (EventSink &sink, VenueId venue, InstrumentId inst, ClientOrderId id, RejectReason reason, int code, std::string_view text) noexcept |
| void | emit_order_ack (EventSink &sink, VenueId venue, InstrumentId inst, ClientOrderId id, std::string_view venue_order_id, std::uint8_t flags=0, Timestamp venue_ts=Timestamp{}) noexcept |
flags: OrderAckMsg::kAmendedInPlace when the venue amended the resting order rather than creating a new one. | |
| void | emit_cancel_ack (EventSink &sink, VenueId venue, InstrumentId inst, ClientOrderId id, std::string_view venue_order_id, Qty cum_qty, Timestamp venue_ts=Timestamp{}) noexcept |
venue_ts as for emit_order_ack. | |
| void | emit_replayed_fill (EventSink &sink, VenueId venue, InstrumentId inst, ClientOrderId id, std::string_view venue_order_id, std::string_view exec_id, Side side, Price price, Qty qty, Notional fee, FeeAsset fee_asset, Liquidity liquidity, std::int64_t trade_time_ms, std::uint8_t extra_flags=0) noexcept |
| An execution from the venue's trade history (Venue::request_executions), not from the private stream. | |
| void | emit_funding (EventSink &sink, VenueId venue, InstrumentId inst, std::string_view funding_id, Notional amount, std::string_view asset, std::int64_t time_ms, bool replayed) noexcept |
A funding payment (FundingMsg): amount signed in asset, negative paid. | |
| void | emit_venue_kill (EventSink &sink, VenueId venue, KillReason reason) noexcept |
The connector cannot trade on this venue any more (error map HardStop / Fatal, failed authentication): asks the engine to trip this venue's kill switch only (ControlCommand::TripVenueKill, the reason in arg). | |
| void | emit_connection_state (EventSink &sink, VenueId venue, std::uint8_t channel, ConnState state, std::int32_t reason=0) noexcept |
| channel: 0 = market data, 1 = order/user stream (ConnectionStateMsg contract). | |
| constexpr std::string_view | to_string (VenueAction a) noexcept |
| constexpr bool | contains_ci (std::string_view hay, std::string_view needle) noexcept |
| Case-insensitive substring search (venue error messages vary in case). | |
| constexpr char | ascii_upper (char c) noexcept |
| constexpr char | ascii_lower (char c) noexcept |
| constexpr std::uint64_t | symbol_hash (std::string_view s) noexcept |
| FNV-1a over the upper-cased bytes. | |
| constexpr bool | iequals_symbol (std::string_view a, std::string_view b) noexcept |
| std::string | ip_weight_key (std::string_view kind, std::string_view rest_url, std::string_view source) |
| The key of one IP's weight at one venue: the connector kind, its REST host and the address its connections leave from (net::source_label; empty: the host's default), so accounts sending from different addresses count apart and those sending from the same one count together. | |
| std::shared_ptr< SharedRate > | shared_rate (std::string_view key) |
The SharedRate of key (ip_weight_key), made on first use; process-wide. | |
| template<class Sleep > | |
| void | wait_for_weight (RateLimiter &r, std::uint32_t weight, std::int64_t now_ns, std::int64_t max_wait_ns, Sleep &&sleep_ns) noexcept |
A blocking start-up request (reference data, account settings, one per symbol) waits for its weight to fit the bulk share instead of spending what the connections about to open will need; at most max_wait_ns, since nothing trades yet and a window is a minute. | |
| constexpr std::size_t | rest_queue_for (std::size_t symbols) noexcept |
Queue room for a connector's REST channel with symbols subscribed: every connector fans some requests out per symbol (cancel-all, the USDⓈ-M countdown, execution and funding replays), and those can overlap, on top of a fixed set (reconciliation, clock, listen key, the dead man's switch, orders falling back to REST). | |
| template<class Cfg > | |
| RestChannelConfig | rest_channel_config (const Cfg &cfg, std::size_t symbols) |
| The RestChannelConfig every connector config spells the same way. | |
| constexpr std::string_view | to_string (DecimalError e) noexcept |
| template<class F > | |
| Result< F, DecimalError > | parse_fixed (std::string_view s) noexcept |
| Result< Price, DecimalError > | parse_price (std::string_view s) noexcept |
| template<class F > | |
| Result< F, DecimalError > | parse_rounded (std::string_view s) noexcept |
| A value the venue computed rather than one an order carries can have more fraction digits than 8: Binance USDⓈ-M's positionRisk and ACCOUNT_UPDATE give an entry price of "83954.61851851852", OKX a spot commission of "-0.00000192834" BTC (fillSz times the fee rate). | |
| Result< Price, DecimalError > | parse_avg_price (std::string_view s) noexcept |
| A position's entry price, an average fill price. | |
| Result< Notional, DecimalError > | parse_fee (std::string_view s) noexcept |
| A commission, which the venue computes from the fill. | |
| Result< Qty, DecimalError > | parse_qty (std::string_view s) noexcept |
| Result< Notional, DecimalError > | parse_notional (std::string_view s) noexcept |
| Result< std::int64_t, DecimalError > | parse_int64 (std::string_view s) noexcept |
| "[-]digits" -> int64; rejects empty, signs other than a leading '-', overflow. | |
| constexpr Timestamp | ts_from_ms (std::int64_t ms) noexcept |
| Milliseconds since the Unix epoch -> Timestamp (ns). | |
| Result< Timestamp, DecimalError > | parse_ts_ms (std::string_view s) noexcept |
| constexpr std::size_t | format_int64 (std::int64_t v, char *out) noexcept |
| Formats an int64 into a caller buffer (>= 21 chars); returns the length. | |
| RequestId | make_request_id (RequestKind kind, ClientOrderId id) noexcept |
| std::optional< std::pair< RequestKind, ClientOrderId > > | parse_request_id (std::string_view id) noexcept |
| Returns the kind and id encoded by make_request_id, or nullopt for foreign ids. | |
| template<class Ring , class Cork , class OnMessage , class Uncork > | |
| void | drain_outbound_coalesced (Ring &ring, WireLatencyRecorder &wire, Cork &&cork, OnMessage &&on_message, Uncork &&uncork) |
| Drains the engine's outbound ring (or an OutboundBatch) in batches of at most kMaxBatch messages: cork() holds the connection's writes back, on_message(header) encodes and "sends" each message into the connection's buffer, uncork() writes the batch with one system call and returns false when the connection failed (the venue rejects the batch's orders there, see BatchedOrders). | |
Variables | |
| constexpr std::uint32_t | kDecoderScratchBytes = kMaxMsgBytes |
| Every decoder needs a scratch area for the largest message it can produce. | |
| constexpr std::size_t | kJsonPadding = 64 |
| Parsers that hand raw text frames to simdjson need SIMDJSON_PADDING (64) readable bytes after the payload; RecvBuffer::kPadding guarantees it for WebSocket frames and PaddedJson (padded_json.hpp) for fixtures/tests. | |
| using fastmm::venues::RequestId = typedef FixedString<16> |
|
strong |
|
strong |
Multicast feed (nasdaq_itch, ADR-0015 section 5); zero for the WebSocket venues.
|
strong |
|
strong |
| Enumerator | |
|---|---|
| Ok | |
| Ignored | valid message we do not consume (subscription acks, pongs, ...) |
| Malformed | JSON error or missing/invalid field. |
| UnknownSymbol | symbol not in the SymbolTable |
| Overflow | ring full (market data) or output buffer too small |
| Error | venue-level error payload |
|
strong |
What a decoder produced into the caller's scratch buffer.
| Enumerator | |
|---|---|
| None | |
| BookDelta | |
| BookSnapshot | |
| BookTicker | |
| Trade | |
| PerpState | PerpStateMsg (venues/perp_state.hpp) |
|
strong |
|
strong |
|
strong |
|
strong |
What the connector does beyond reporting the reject to the engine.
| Enumerator | |
|---|---|
| None | |
| Backoff | transient venue-side failure: retry later |
| RateLimit | enter RateLimiter cooldown |
| ResyncClock | timestamp outside the window: fetch server time, recompute offset |
| Reconcile | unknown order / status unknown: request open orders |
| DisableInstrument | precision/filter failure: config is wrong for this symbol |
| HardStop | IP ban: stop REST. |
| Fatal | bad key/signature/permissions: cannot continue |
|
strong |
Why can_send refused (RateLimiter::check): the IP or account is paused (429 cooldown, 418), a weight window is at its share, or an order-count window is (RateCheck::window_ns says which).
| Enumerator | |
|---|---|
| None | |
| Paused | |
| Weight | |
| Orders | |
|
strong |
|
strong |
|
constexprnoexcept |
|
constexprnoexcept |
|
inlinenoexcept |
An order counted as sent whose batch was then never written (the connection failed at uncork()): the connector rejects it, so it is taken back out of the sent counters.
|
inline |
Runtime knobs every connector honours, passed to the factory.
Anything venue-specific is a config key the venue owns instead. [venues.<x>] source_ip / source_interface as a net::SourceAddress.
|
constexprnoexcept |
| void fastmm::venues::register_builtin_venues | ( | VenueRegistry & | r = VenueRegistry::instance() | ) |
Adds the connectors FastMM ships (binance_spot, binance_usdm, bybit, deribit, nasdaq_itch).
Idempotent; make_venue() and validate_venues() call it for the default registry.
| void fastmm::venues::validate_venues | ( | const Config & | cfg, |
| const VenueRegistry & | r = VenueRegistry::instance() |
||
| ) |
Checks every [venues.
<name>] section against the key table of the venue its kind names, the way the central schema checks the generic keys: a key the venue does not own, a key of the wrong type or a missing required key throws ConfigError with the line. An unknown kind throws too. Call it once after loading a configuration; fastmm-live does.
| std::unique_ptr< Venue > fastmm::venues::make_venue | ( | VenueId | id, |
| const VenueSection & | section, | ||
| const VenueFactoryOptions & | opts | ||
| ) |
Builds the connector section.kind names.
Throws std::invalid_argument for an unknown kind, ConfigError for a key of the wrong type and whatever the connector throws for a bad value.
| std::unique_ptr< Venue > fastmm::venues::make_venue | ( | VenueId | id, |
| const VenueSection & | section, | ||
| const VenueFactoryOptions & | opts, | ||
| const VenueRegistry & | r | ||
| ) |
|
constexprnoexcept |
|
constexprnoexcept |
|
inlinenoexcept |
The engine asks for a reconciliation (ControlCommand::Reconcile on the outbound ring).
|
inlinenoexcept |
< truncates to capacity
|
inlinenoexcept |
< truncates to capacity
|
inlinenoexcept |
flags: OrderAckMsg::kAmendedInPlace when the venue amended the resting order rather than creating a new one.
venue_ts: a venue time the response carries, stamped as hdr.exch_ts (invalid: unstamped). The balance estimate tells from it whether a report that came first already had the order (core/balance_book.hpp), so it must not be earlier than the order's effect on the balance: a later one at worst leaves the order held twice until the next report, an earlier one could give back a hold the report did not have.
|
inlinenoexcept |
venue_ts as for emit_order_ack.
|
inlinenoexcept |
An execution from the venue's trade history (Venue::request_executions), not from the private stream.
It carries the venue's execution id, which is what lets the OMS drop the ones it already booked, and no cumulative quantity: the venue's trade history does not report one, so the OMS works out how much of the execution is new. cl_ord_id may be empty when the connector cannot map the venue's order id back to one of its own (a restarted session): the fill still reaches the position, as an unknown fill. trade_time_ms is the venue's time of the trade (Unix ms), stamped as hdr.exch_ts: fastmm-gateway tells from it whether an execution naming no live order is older than what a strategy's store holds.
< the venue's time of the trade
|
inlinenoexcept |
A funding payment (FundingMsg): amount signed in asset, negative paid.
replayed when it comes from the venue's history rather than its private stream.
|
inlinenoexcept |
The connector cannot trade on this venue any more (error map HardStop / Fatal, failed authentication): asks the engine to trip this venue's kill switch only (ControlCommand::TripVenueKill, the reason in arg).
Travels with the order events, so it is journaled and replayed like them. Connectors send it once, on the first such error.
|
inlinenoexcept |
channel: 0 = market data, 1 = order/user stream (ConnectionStateMsg contract).
|
constexprnoexcept |
|
constexprnoexcept |
Case-insensitive substring search (venue error messages vary in case).
|
constexprnoexcept |
|
constexprnoexcept |
|
constexprnoexcept |
FNV-1a over the upper-cased bytes.
|
constexprnoexcept |
|
inline |
The key of one IP's weight at one venue: the connector kind, its REST host and the address its connections leave from (net::source_label; empty: the host's default), so accounts sending from different addresses count apart and those sending from the same one count together.
|
inline |
The SharedRate of key (ip_weight_key), made on first use; process-wide.
|
noexcept |
A blocking start-up request (reference data, account settings, one per symbol) waits for its weight to fit the bulk share instead of spending what the connections about to open will need; at most max_wait_ns, since nothing trades yet and a window is a minute.
|
constexprnoexcept |
Queue room for a connector's REST channel with symbols subscribed: every connector fans some requests out per symbol (cancel-all, the USDⓈ-M countdown, execution and funding replays), and those can overlap, on top of a fixed set (reconciliation, clock, listen key, the dead man's switch, orders falling back to REST).
The queue is a deque: room costs nothing until used.
| RestChannelConfig fastmm::venues::rest_channel_config | ( | const Cfg & | cfg, |
| std::size_t | symbols | ||
| ) |
The RestChannelConfig every connector config spells the same way.
|
constexprnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
A value the venue computed rather than one an order carries can have more fraction digits than 8: Binance USDⓈ-M's positionRisk and ACCOUNT_UPDATE give an entry price of "83954.61851851852", OKX a spot commission of "-0.00000192834" BTC (fillSz times the fee rate).
Rounded half away from zero to 8 decimals; anything else parse_fixed refuses is refused here too.
|
inlinenoexcept |
A position's entry price, an average fill price.
|
inlinenoexcept |
A commission, which the venue computes from the fill.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
"[-]digits" -> int64; rejects empty, signs other than a leading '-', overflow.
|
constexprnoexcept |
Milliseconds since the Unix epoch -> Timestamp (ns).
|
inlinenoexcept |
|
constexprnoexcept |
Formats an int64 into a caller buffer (>= 21 chars); returns the length.
|
inlinenoexcept |
|
inlinenoexcept |
Returns the kind and id encoded by make_request_id, or nullopt for foreign ids.
| void fastmm::venues::drain_outbound_coalesced | ( | Ring & | ring, |
| WireLatencyRecorder & | wire, | ||
| Cork && | cork, | ||
| OnMessage && | on_message, | ||
| Uncork && | uncork | ||
| ) |
Drains the engine's outbound ring (or an OutboundBatch) in batches of at most kMaxBatch messages: cork() holds the connection's writes back, on_message(header) encodes and "sends" each message into the connection's buffer, uncork() writes the batch with one system call and returns false when the connection failed (the venue rejects the batch's orders there, see BatchedOrders).
Every order of a batch gets the stamp taken after uncork() returned.
|
inlineconstexpr |
Every decoder needs a scratch area for the largest message it can produce.
|
inlineconstexpr |
Parsers that hand raw text frames to simdjson need SIMDJSON_PADDING (64) readable bytes after the payload; RecvBuffer::kPadding guarantees it for WebSocket frames and PaddedJson (padded_json.hpp) for fixtures/tests.