|
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
|
#include <fastmm/core/strategy_context.hpp>
Public Types | |
| using | Book = typename Engine::Book |
Public Member Functions | |
| StrategyContext (Engine *e) noexcept | |
| Timestamp | now () const noexcept |
| const Instrument & | instrument (InstrumentId id) const noexcept |
| const InstrumentTable & | instruments () const noexcept |
| bool | contains (InstrumentId id) const noexcept |
| const Book & | book (InstrumentId id) const noexcept |
| Qty | own_qty (InstrumentId id, Side side, Price px) const noexcept |
| Our resting quantity that the venue's feed shows at (id, side, px): the book and the tickers of a live venue include our own orders. | |
| Qty | own_qty (InstrumentId id, Side side, Price px, Timestamp at) const noexcept |
| Level | best_ex_self (InstrumentId id, Side side) const noexcept |
| The book's best level on one side with own_qty taken out; a level that was only ours is skipped. | |
| const Position & | position (InstrumentId id) const noexcept |
| Portfolio | portfolio () const noexcept |
| PnL totals over every instrument (a loop over all positions; not for every event). | |
| bool | set_quotes (InstrumentId id, const DesiredQuotes &q) noexcept |
| Returns false when the quotes were ignored: quoting is disabled (control pull, kill switch, reconciliation; on_quoting reports the changes) or the instrument is not in the table. | |
| void | pull_quotes (InstrumentId id) noexcept |
| void | watch (InstrumentId id, bool on) noexcept |
| market-data hooks only for what the strategy watches, and needs no more: a multiverse hands an engine only the messages it needs (backtest/multiverse.hpp). | |
| void | quiet_book (InstrumentId id, Price lo, Price hi) noexcept |
on_book of id is called only once its mid is at or beyond lo or hi, or the book is not valid: a strategy that would return at once inside (lo, hi) says so. | |
| void | quiet_book (InstrumentId id) noexcept |
| void | note_quote (InstrumentId id, Side side, std::string_view reason, Notional budget={}) noexcept |
| Why the strategy asks what it asks on a side, for the operator: a short reason ("inventory_cap", "model_off"; empty clears it, at most 23 bytes kept) and the budget it gave the side in the settlement currency. | |
| void | metric (std::string_view name, double value) noexcept |
| A number the strategy publishes by name, for the status file (a budget split, a model's state): the first 32 names are kept, a name at most 23 bytes. | |
| void | quote_context (InstrumentId id, Side side, std::initializer_list< double > values) noexcept |
| What the strategy knows about its quotes on a side, for the record of their fills: up to kQuoteContextSize numbers (its fair value, the quote's distance from it, a signal), NaN for a slot not given. | |
| void | quote_context (InstrumentId id, Side side, std::span< const double > values) noexcept |
| void | quote_context (InstrumentId id, std::initializer_list< double > values) noexcept |
| Both sides at once. | |
| const QuoteContext & | quote_context (InstrumentId id, Side side) const noexcept |
| The side's values as they stand. | |
| void | quote_context_names (std::initializer_list< std::string_view > names) noexcept |
| Names for the values, in slot order (at most 23 bytes each), for the store and the tools that show them; call once, from on_start. | |
| void | quote_context_names (std::span< const std::string_view > names) noexcept |
| void | pull_all_quotes () noexcept |
| const Order * | working_quote (InstrumentId id, Side side, std::uint32_t level=0) const noexcept |
| The open order in a quote slot (level 0 is closest to the mid), or nullptr. | |
| Result< ClientOrderId, RejectReason > | send (const NewOrderRequest &req) noexcept |
| RejectReason::InvalidTag: user_tag lies in the QuoteManager's tag range. | |
| Result< void, RejectReason > | cancel (ClientOrderId id) noexcept |
| Result< void, RejectReason > | replace (ClientOrderId id, Price px, Qty qty) noexcept |
| const Order * | order (ClientOrderId id) const noexcept |
| An open order by id, or nullptr once it is terminal. Valid until the next context call. | |
| std::optional< Qty > | queue_ahead (ClientOrderId id) const noexcept |
| Estimated quantity resting ahead of an open order at its price: the l2_queue fill model's queue model on the market data the strategy sees, with [engine] queue_conservatism, from the order's ack. | |
| const OrderTimes * | order_times (ClientOrderId id) const noexcept |
| Send and ack times of an open order, or nullptr (OmsUpdate::times has them in on_order_update and, through Fill::update, in on_fill). | |
| Qty | open_qty (InstrumentId id, Side side) const noexcept |
| Unfilled quantity of our open orders (quotes included) on one side. | |
| const Oms & | oms () const noexcept |
| TimerId | every (Duration period, std::uint64_t tag=0) noexcept |
| TimerId | once (Duration delay, std::uint64_t tag=0) noexcept |
| bool | cancel_timer (TimerId id) noexcept |
| bool | quoting_enabled () const noexcept |
| bool | reconciling () const noexcept |
| A venue's orders and position are being reconciled, or have not been yet since the session started (a live session waits for every venue that replays executions; new orders are refused with NotReconciled until then). | |
| bool | killed () const noexcept |
| bool | reduce_only (InstrumentId id) const noexcept |
| Reduce-only mode holds the instrument (fastmm-ctl reduce-only, [risk] reduce_only): an order or replace that would leave its position no nearer zero is refused with RejectReason::ReduceOnly. | |
| bool | venue_killed (VenueId v) const noexcept |
| One venue's kill switch: new orders to it are refused and set_quotes ignores its instruments. | |
| std::string_view | venue_name (VenueId v) const noexcept |
| The venue's [venues.<name>], for log lines ("venue \<id\>" when the session names none). | |
| void | request_stop () noexcept |
| void | request_batch_end () noexcept |
| Asks for one on_batch_end call once the engine has handled every event that is waiting now (the feed is empty or the step's max_events_per_step is used up). | |
| void | request_checkpoint () noexcept |
| Asks for a checkpoint in the journal once the events waiting now are handled: state(), the positions and the open orders, as [engine] checkpoint_s writes. | |
| void | trip_kill (KillReason reason) noexcept |
| Trips the global kill switch: quoting stops, quotes are pulled and every working order is cancelled. | |
| const FeeRates & | fees (InstrumentId id) const noexcept |
| Maker and taker rates of the instrument, in cbps of the notional (positive: a fee). | |
| RiskHeadroom | risk_headroom (InstrumentId id) const noexcept |
| What each [risk] limit still admits on the instrument now: the next check uses the same inputs, so an order of exactly a room passes that limit. | |
| VenueHealthView | venue_health (VenueId v) const noexcept |
| Feed lag and order round trip of a venue (core/venue_health.hpp), and whether the feed-lag gate ([risk] max_feed_lag_ms) holds it now. | |
| FillClusterView | fill_cluster () const noexcept |
| The fill-cluster guard ([risk] fill_cluster_names, core/fill_cluster.hpp): which sides it holds now, until when, and how often it has engaged. | |
| std::uint32_t | hazard_groups () const noexcept |
| The hazard groups ([[risk.hazard]], core/hazard.hpp), numbered in the order of the configuration. | |
| std::uint32_t | hazard_group (InstrumentId id) const noexcept |
| HazardView | hazard (std::uint32_t group) const noexcept |
| void | hazard_add (std::uint32_t group, Side side, double amount) noexcept |
| OrderBudget | order_budget (VenueId v) const noexcept |
| What the [risk] rate limit and the venue's own limits still admit (core/order_budget.hpp): the local token bucket, and the venue's order counts and request weight by window as its connector last published them (live only; venue_known is false elsewhere). | |
| CapacityQuote | capacity (VenueId v) const noexcept |
What an order slot on account v costs now ([capacity], core/capacity_price.hpp): a new order or a move is sent when its value covers price. | |
| Balance | balance (VenueId v, std::string_view asset) const noexcept |
| One asset of a venue's account: the venue's last report (on_balance) less what this engine's orders hold and its fills moved since. | |
| Margin | margin (VenueId v) const noexcept |
| The venue's margin: its account-wide margin where it reports one, else the settlement asset of its first derivative. | |
| bool | balances_live () const noexcept |
| A venue has reported balances (before that, balance() is unknown everywhere). | |
| Qty | balance_room (InstrumentId id, Side side, Price px) const noexcept |
Largest quantity of id on side at px the balance covers (a spot buy's quote with the taker fee, a spot sell's base, a derivative's initial margin), rounded down to the lot. | |
| Qty | balance_room (InstrumentId id, Side side, Price px, VenueId account) const noexcept |
... on one account of the instrument's pool (its own venue when account is not one). | |
| PoolMembers | pool (VenueId primary) const noexcept |
| The accounts that take orders for a venue's instruments ([venues. | |
| VenueId | pool_primary (VenueId v) const noexcept |
The venue whose instruments v takes orders for: its primary, or v itself. | |
| bool | account_usable (VenueId v) const noexcept |
The automatic routing would send to v now: its order link is live and its kill switch is not engaged (its balance and window are the order's to decide). | |
| VenueId | home (InstrumentId id) const noexcept |
| The account the instrument's position lives on; invalid when its pool has no [venues. | |
| Placement | placement (VenueId primary) const noexcept |
| The pool's placement: Placement::Home sends adding orders to the home and reducing orders to the accounts holding the instrument; Placement::Balance (the default) routes by balance and window, and the homes are only kept. | |
| Qty | holding (InstrumentId id, VenueId account) const noexcept |
| What one account of the pool holds of the instrument: a spot instrument's base balance there, a derivative's position on that account. | |
| std::uint32_t | pieces (InstrumentId id) const noexcept |
| Accounts other than the home that hold a tradable amount of the instrument. | |
| bool | sweeping (VenueId primary) const noexcept |
| The pool sweeps now ([venues. | |
| bool | set_home (InstrumentId id, VenueId account) noexcept |
Moves the instrument's home to account (journaled). | |
| void | set_funding_need (InstrumentId id, Notional quote) noexcept |
| The quote the instrument's bids want resting (a spot instrument's quote asset, a derivative's settlement asset; 0: none). | |
| Notional | funding_need (InstrumentId id) const noexcept |
| RefPrice | mark (InstrumentId id) const noexcept |
| The venue's mark and index price of a derivative (on_perp_state), with the time each arrived. | |
| RefPrice | index (InstrumentId id) const noexcept |
| FundingView | funding (InstrumentId id) const noexcept |
The venue's funding of a perpetual: the rate it will apply at next, per interval, and over(d), the rate over a holding time d. | |
| const PerpRow & | perp_state (InstrumentId id) const noexcept |
| Every field as last reported, open interest included, without the staleness applied. | |
| Xoshiro256ss & | rng () noexcept |
| using fastmm::StrategyContext< Engine >::Book = typename Engine::Book |
|
inlineexplicitnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Our resting quantity that the venue's feed shows at (id, side, px): the book and the tickers of a live venue include our own orders.
As of the book's last update, or of venue time at (a BookTicker's exch_ts). An order counts from its ack's venue time to its end's, less its fills, so a depth update stamped before our cancel still includes it. Zero in the simulator, whose feed does not contain our orders.
|
inlinenoexcept |
|
inlinenoexcept |
The book's best level on one side with own_qty taken out; a level that was only ours is skipped.
Level{} when none is left.
|
inlinenoexcept |
|
inlinenoexcept |
PnL totals over every instrument (a loop over all positions; not for every event).
|
inlinenoexcept |
Returns false when the quotes were ignored: quoting is disabled (control pull, kill switch, reconciliation; on_quoting reports the changes) or the instrument is not in the table.
|
inlinenoexcept |
|
inlinenoexcept |
market-data hooks only for what the strategy watches, and needs no more: a multiverse hands an engine only the messages it needs (backtest/multiverse.hpp).
Alone or there, a backtest gives the same result; declaring less only makes a sweep faster.
watch(id, false): on_book, on_book_ticker, on_trade and on_option_ticker are not called for id until watch(id, true); ctx.book(id) stays current. Every instrument is watched at start.
|
inlinenoexcept |
on_book of id is called only once its mid is at or beyond lo or hi, or the book is not valid: a strategy that would return at once inside (lo, hi) says so.
quiet_book(id): every update again.
|
inlinenoexcept |
|
inlinenoexcept |
Why the strategy asks what it asks on a side, for the operator: a short reason ("inventory_cap", "model_off"; empty clears it, at most 23 bytes kept) and the budget it gave the side in the settlement currency.
The status file shows it next to what the engine finds in the way (core/quote_diag.hpp); the store records each change. No allocation.
|
inlinenoexcept |
A number the strategy publishes by name, for the status file (a budget split, a model's state): the first 32 names are kept, a name at most 23 bytes.
No allocation.
|
inlinenoexcept |
What the strategy knows about its quotes on a side, for the record of their fills: up to kQuoteContextSize numbers (its fair value, the quote's distance from it, a signal), NaN for a slot not given.
The side keeps them until the next call. Each order sent or moved on the side takes a copy, and the store keeps, with every fill, the copy its order took when it last went out and the side's values when the fill arrived (fastmm-pnl fill-context). Call it before set_quotes or send for the orders it explains. No allocation.
ctx.quote_context(id, Side::Buy, {fair.to_double(), bid_distance_bps});
|
inlinenoexcept |
|
inlinenoexcept |
Both sides at once.
|
inlinenoexcept |
The side's values as they stand.
|
inlinenoexcept |
Names for the values, in slot order (at most 23 bytes each), for the store and the tools that show them; call once, from on_start.
No allocation.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
The open order in a quote slot (level 0 is closest to the mid), or nullptr.
|
inlinenoexcept |
RejectReason::InvalidTag: user_tag lies in the QuoteManager's tag range.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
An open order by id, or nullptr once it is terminal. Valid until the next context call.
|
inlinenoexcept |
Estimated quantity resting ahead of an open order at its price: the l2_queue fill model's queue model on the market data the strategy sees, with [engine] queue_conservatism, from the order's ack.
nullopt while it is not acknowledged or once it is terminal. The engine tracks queues from the first call on (call it in on_start to cover every order from its ack); an order already resting at the first call starts at the back of its level as the book shows it.
|
inlinenoexcept |
Send and ack times of an open order, or nullptr (OmsUpdate::times has them in on_order_update and, through Fill::update, in on_fill).
|
inlinenoexcept |
Unfilled quantity of our open orders (quotes included) on one side.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
A venue's orders and position are being reconciled, or have not been yet since the session started (a live session waits for every venue that replays executions; new orders are refused with NotReconciled until then).
Positions may be missing fills while this holds.
|
inlinenoexcept |
|
inlinenoexcept |
Reduce-only mode holds the instrument (fastmm-ctl reduce-only, [risk] reduce_only): an order or replace that would leave its position no nearer zero is refused with RejectReason::ReduceOnly.
A strategy that reads it quotes only the side that reduces.
|
inlinenoexcept |
One venue's kill switch: new orders to it are refused and set_quotes ignores its instruments.
|
inlinenoexcept |
The venue's [venues.<name>], for log lines ("venue \<id\>" when the session names none).
|
inlinenoexcept |
|
inlinenoexcept |
Asks for one on_batch_end call once the engine has handled every event that is waiting now (the feed is empty or the step's max_events_per_step is used up).
Work a burst of events would each trigger (a requote after every balance report) is done once, after the burst. Repeated requests before the call make one call.
|
inlinenoexcept |
Asks for a checkpoint in the journal once the events waiting now are handled: state(), the positions and the open orders, as [engine] checkpoint_s writes.
A backtest or a replay can start from it. No allocation; nothing without a journal.
|
inlinenoexcept |
Trips the global kill switch: quoting stops, quotes are pulled and every working order is cancelled.
The adapter for Python hot hooks uses KillReason::StrategyError.
|
inlinenoexcept |
Maker and taker rates of the instrument, in cbps of the notional (positive: a fee).
The configuration's ([[instruments]] maker_bps / taker_bps, else [venues.<x>.fees]), or the account's own where the connector fetched them (fetch_fees). A backtest charges these.
|
inlinenoexcept |
What each [risk] limit still admits on the instrument now: the next check uses the same inputs, so an order of exactly a room passes that limit.
RiskHeadroom::kUnlimited (or the type's max()) where the limit is off.
|
inlinenoexcept |
Feed lag and order round trip of a venue (core/venue_health.hpp), and whether the feed-lag gate ([risk] max_feed_lag_ms) holds it now.
|
inlinenoexcept |
The fill-cluster guard ([risk] fill_cluster_names, core/fill_cluster.hpp): which sides it holds now, until when, and how often it has engaged.
While a side is held, set_quotes places nothing on it; the engine puts the last quotes back when the hold ends.
|
inlinenoexcept |
The hazard groups ([[risk.hazard]], core/hazard.hpp), numbered in the order of the configuration.
hazard_group: the group an instrument is a member of, Hazard::kNoGroup for none. hazard: a group's score, held sides and counts. hazard_add: evidence for one side of a group, in the units of its threshold; a negative amount takes evidence back. Evidence that takes the score to the threshold pulls the side before the call returns, and set_quotes places nothing on it until the hold ends.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
What the [risk] rate limit and the venue's own limits still admit (core/order_budget.hpp): the local token bucket, and the venue's order counts and request weight by window as its connector last published them (live only; venue_known is false elsewhere).
|
inlinenoexcept |
What an order slot on account v costs now ([capacity], core/capacity_price.hpp): a new order or a move is sent when its value covers price.
on is false without [capacity].
|
inlinenoexcept |
One asset of a venue's account: the venue's last report (on_balance) less what this engine's orders hold and its fills moved since.
Balance::known is false until the venue reports it, and for an asset no instrument of the venue names.
|
inlinenoexcept |
The venue's margin: its account-wide margin where it reports one, else the settlement asset of its first derivative.
|
inlinenoexcept |
A venue has reported balances (before that, balance() is unknown everywhere).
|
inlinenoexcept |
Largest quantity of id on side at px the balance covers (a spot buy's quote with the taker fee, a spot sell's base, a derivative's initial margin), rounded down to the lot.
Qty::max() while the venue has not reported the balance that side draws on.
|
inlinenoexcept |
... on one account of the instrument's pool (its own venue when account is not one).
|
inlinenoexcept |
The accounts that take orders for a venue's instruments ([venues.
<x>] pool_of), the primary first; just the venue itself without a pool. Each has its own balance(), margin() and order_budget(); an order goes to the one NewOrderRequest::account names, else to the usable member whose balance covers it with the most order window left, and Order::venue keeps it.
|
inlinenoexcept |
The venue whose instruments v takes orders for: its primary, or v itself.
|
inlinenoexcept |
The automatic routing would send to v now: its order link is live and its kill switch is not engaged (its balance and window are the order's to decide).
|
inlinenoexcept |
The account the instrument's position lives on; invalid when its pool has no [venues.
<primary>.pool] table, or before it has a home.
|
inlinenoexcept |
The pool's placement: Placement::Home sends adding orders to the home and reducing orders to the accounts holding the instrument; Placement::Balance (the default) routes by balance and window, and the homes are only kept.
|
inlinenoexcept |
What one account of the pool holds of the instrument: a spot instrument's base balance there, a derivative's position on that account.
Without a pool, the position.
|
inlinenoexcept |
Accounts other than the home that hold a tradable amount of the instrument.
|
inlinenoexcept |
The pool sweeps now ([venues.
<primary>.pool] sweep, core/transfer_lane.hpp): its pieces go home by internal transfer and its spot sells go to the home, so selling each account's part separately gains nothing. False in a dry run, while its breaker is open and once the day's transfers are used.
|
inlinenoexcept |
Moves the instrument's home to account (journaled).
With placement = "home" its adding orders on other accounts are cancelled; the quotes go to the new home at the next requote. False when its pool keeps no homes or account is not of the pool.
|
inlinenoexcept |
The quote the instrument's bids want resting (a spot instrument's quote asset, a derivative's settlement asset; 0: none).
A pool treasury with targets = "demand" funds each account for the needs of the instruments whose home it is. Declare it when the sizes change.
|
inlinenoexcept |
|
inlinenoexcept |
The venue's mark and index price of a derivative (on_perp_state), with the time each arrived.
stale: older than [accounting] stale_mark_ms, or never reported; usable() is neither.
|
inlinenoexcept |
|
inlinenoexcept |
The venue's funding of a perpetual: the rate it will apply at next, per interval, and over(d), the rate over a holding time d.
stale against [accounting] stale_funding_ms.
|
inlinenoexcept |
Every field as last reported, open interest included, without the staleness applied.
|
inlinenoexcept |