|
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
|
#include <fastmm/strategies/hedge_executor.hpp>
Classes | |
| struct | Config |
| struct | Stats |
| struct | Status |
Public Types | |
| enum class | State : std::uint8_t { Idle , Flat , Waiting , InFlight , Reconciling , Holding , Held , Unavailable , Halted , Inside , Resting } |
| What the last evaluation found. More... | |
| enum class | Reason : std::uint8_t { Usable , Down , Killed , NoBook , Stale , Gated , Benched } |
| Why a hedge instrument is not usable now. More... | |
Public Member Functions | |
| void | reset () noexcept |
| Forgets the legs and every state but the stats. Call before adding legs in on_start. | |
| bool | add_source (InstrumentId id) noexcept |
| bool | add_hedge (InstrumentId id, Ratio tolerance) noexcept |
| template<class Ctx > | |
| bool | start (Ctx &ctx, const Config &cfg) noexcept |
| Checks the legs against the instrument table: each is configured, linear, used once, and there is at least one of each. | |
| void | set_config (const Config &cfg) noexcept |
| Parameters may change while running (on_params); the legs may not. | |
| void | set_tolerance (std::size_t hedge, Ratio tolerance) noexcept |
| void | set_target (Qty base) noexcept |
| The net base position the strategy wants to hold; the residual is measured from it. | |
| void | restart () noexcept |
| Clears a halt, the benches and the failure counts; hedging resumes from the positions. | |
| template<class Ctx > | |
| bool | on_fill (Ctx &ctx, const Fill &fill) noexcept |
| A fill of any leg: the residual moved. False for another instrument. | |
| template<class Ctx > | |
| bool | on_order_update (Ctx &ctx, const OmsUpdate &u) noexcept |
| The end of a hedge or de-risk order: counts a failure or holds, then looks again. | |
| template<class Ctx > | |
| void | on_book (Ctx &ctx, InstrumentId id) noexcept |
| A hedge instrument's book: a new touch to price against. | |
| template<class Ctx > | |
| bool | on_book_ticker (Ctx &ctx, InstrumentId id, const BookTickerMsg &m) noexcept |
| A hedge instrument's book ticker: its touch, newer than the depth book's until the book updates. | |
| template<class Ctx > | |
| void | on_timer (Ctx &ctx) noexcept |
| template<class Ctx > | |
| void | on_connection (Ctx &, const ConnectionStateMsg &m) noexcept |
| Order channels (channel != 0) of the legs' venues. | |
| template<class Ctx > | |
| bool | on_balance (Ctx &ctx, const BalanceMsg &m) noexcept |
| A balance report of a leg's venue: a held hedge may fit now. False for another venue. | |
| template<class Ctx > | |
| void | update (Ctx &ctx) noexcept |
| Looks at the positions and sends what they call for; the hooks above end here. | |
| bool | ready () const noexcept |
| bool | halted () const noexcept |
| bool | held () const noexcept |
| The last hedge the positions asked for fits no usable instrument's balance. | |
| bool | derisking () const noexcept |
| State | state () const noexcept |
| const Stats & | stats () const noexcept |
| std::size_t | hedge_count () const noexcept |
| InstrumentId | hedge_id (std::size_t i) const noexcept |
| std::size_t | active () const noexcept |
| Qty | target () const noexcept |
| bool | is_hedge (InstrumentId id) const noexcept |
| bool | is_source (InstrumentId id) const noexcept |
| bool | is_leg (InstrumentId id) const noexcept |
| bool | involves (VenueId v) const noexcept |
| A venue of any leg. | |
| template<class Ctx > | |
| Qty | residual (const Ctx &ctx) const noexcept |
| Sources plus hedges minus the target, base units. | |
| template<class Ctx > | |
| bool | under_minimum (const Ctx &ctx, Qty residual) const noexcept |
| The residual rounds under the lot or min_qty of every hedge instrument: no hedge order can take it, whichever instrument is usable. | |
| template<class Ctx > | |
| Reason | why (const Ctx &ctx, std::size_t i, std::int64_t now) const noexcept |
Why hedge instrument i cannot take a hedge now (Reason::Usable: it can). | |
| template<class Ctx > | |
| bool | can_hedge (const Ctx &ctx) const noexcept |
| Some hedge instrument can take a hedge now, and hedging is not halted. | |
| template<class Ctx > | |
| Status | status (const Ctx &ctx) const noexcept |
Static Public Member Functions | |
| static constexpr Qty | to_base (const Instrument &inst, Qty contracts) noexcept |
| Contracts to base units and back (linear: qty * multiplier). | |
| static constexpr Qty | to_contracts (const Instrument &inst, Qty base) noexcept |
| static std::optional< NewOrderRequest > | hedge_order (const Instrument &inst, Qty residual, Price best_bid, Price best_ask, Ratio tolerance, std::uint32_t tag) noexcept |
The order on inst that brings residual (base units) back towards zero: an IOC of -residual in contracts, rounded down to the lot and capped at max_qty, priced tolerance through the touch and rounded towards it. | |
| static std::optional< NewOrderRequest > | maker_order (const Instrument &inst, Qty residual, Price bid, Price ask, std::uint32_t tag) noexcept |
The maker hedge of residual on inst: a post-only limit of -residual in contracts, rounded down to the lot and capped at max_qty, at the touch of its own side (bid for a buy, ask for a sell). | |
| static constexpr Qty | qty_within (const Instrument &inst, Price price, Notional cap) noexcept |
The largest quantity of inst whose notional at price is at most cap, rounded down to the lot (zero when not even one lot fits, or price is not positive). | |
| static constexpr Qty | risk_room (const RiskHeadroom &h, const Instrument &inst, Side side, Price price) noexcept |
The largest order of side on inst at price that [risk] admits now: max_order_qty, max_order_notional at that price, that side's room of max_position and of [risk.underlying] max_net, and what max_gross_notional and max_net_notional leave for it at that price. | |
| static constexpr bool | fit_risk (const RiskHeadroom &h, const Instrument &inst, NewOrderRequest &r) noexcept |
Cuts r to risk_room() when that is less and still an order the instrument takes (the lot, min_qty, min_notional). | |
| static bool | uncertain (const OmsUpdate &u) noexcept |
| A terminal update whose outcome the venue did not report: the ack timeout cancelled an order the venue never acknowledged, reconciliation found it gone with quantity unaccounted for, or a connector turned a request whose outcome it does not know into a generic reject. | |
| static constexpr std::string_view | to_string (Reason r) noexcept |
| static constexpr std::string_view | to_string (State s) noexcept |
Static Public Attributes | |
| static constexpr std::size_t | kMaxSources = 4 |
| static constexpr std::size_t | kMaxHedges = 4 |
| static constexpr std::size_t | kMaxFailures = 16 |
| template<class Ctx > | |
| static constexpr bool | works_orders |
| Maker mode looks its order up and cancels it (StrategyContext::order, cancel). | |
|
strong |
What the last evaluation found.
| Enumerator | |
|---|---|
| Idle | not started, or nothing evaluated yet |
| Flat | the residual is zero |
| Waiting | the residual rounds under the hedge instrument's minimum |
| InFlight | a hedge or de-risk order is open |
| Reconciling | a venue reconciles |
| Holding | retry backoff or uncertain hold |
| Held | no usable instrument's balance or margin covers the hedge |
| Unavailable | no hedge instrument is usable |
| Halted | every hedge instrument failed max_failures times; restart() clears it |
| Inside | the residual is inside Config::band |
| Resting | a maker hedge rests at the touch |
|
strong |
|
inlinenoexcept |
Forgets the legs and every state but the stats. Call before adding legs in on_start.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Checks the legs against the instrument table: each is configured, linear, used once, and there is at least one of each.
Logs the reason and stays idle when not.
|
inlinenoexcept |
Parameters may change while running (on_params); the legs may not.
|
inlinenoexcept |
|
inlinenoexcept |
The net base position the strategy wants to hold; the residual is measured from it.
|
inlinenoexcept |
Clears a halt, the benches and the failure counts; hedging resumes from the positions.
|
inlinenoexcept |
A fill of any leg: the residual moved. False for another instrument.
|
inlinenoexcept |
The end of a hedge or de-risk order: counts a failure or holds, then looks again.
False for anything else (another instrument, or an update that is not terminal).
Our own cancel ends most maker hedges: only a refusal is a failure, and a post-only one only means the touch moved.
|
inlinenoexcept |
A hedge instrument's book: a new touch to price against.
|
inlinenoexcept |
A hedge instrument's book ticker: its touch, newer than the depth book's until the book updates.
False for another instrument.
|
inlinenoexcept |
|
inlinenoexcept |
Order channels (channel != 0) of the legs' venues.
Market data is covered by the books' validity: the engine clears a venue's books when its channel drops, and a book resync is a Resyncing followed by snapshots with no Live. Does not send: the next event does.
|
inlinenoexcept |
A balance report of a leg's venue: a held hedge may fit now. False for another venue.
|
inlinenoexcept |
Looks at the positions and sends what they call for; the hooks above end here.
The first usable instrument decides the size; a hedge its balance cannot cover goes to the next usable instrument that can take it.
< past the band: hedged until flat
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
The last hedge the positions asked for fits no usable instrument's balance.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
A venue of any leg.
|
inlinenoexcept |
Sources plus hedges minus the target, base units.
|
inlinenoexcept |
The residual rounds under the lot or min_qty of every hedge instrument: no hedge order can take it, whichever instrument is usable.
|
inlinenoexcept |
Why hedge instrument i cannot take a hedge now (Reason::Usable: it can).
|
inlinenoexcept |
Some hedge instrument can take a hedge now, and hedging is not halted.
A quoting strategy pulls its quotes while this is false: a fill could not be hedged, and a de-risk order may be working.
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
Contracts to base units and back (linear: qty * multiplier).
|
inlinestaticconstexprnoexcept |
|
inlinestaticnoexcept |
The order on inst that brings residual (base units) back towards zero: an IOC of -residual in contracts, rounded down to the lot and capped at max_qty, priced tolerance through the touch and rounded towards it.
None when it rounds under the lot or min_qty, its notional is under min_notional, or the touch it needs is empty: a hedge the venue (or the risk check) must refuse would only count as a failure.
|
inlinestaticnoexcept |
The maker hedge of residual on inst: a post-only limit of -residual in contracts, rounded down to the lot and capped at max_qty, at the touch of its own side (bid for a buy, ask for a sell).
None under the lot, min_qty or min_notional, or without that touch.
|
inlinestaticconstexprnoexcept |
The largest quantity of inst whose notional at price is at most cap, rounded down to the lot (zero when not even one lot fits, or price is not positive).
The notional rounds at each step: never over the cap.
|
inlinestaticconstexprnoexcept |
The largest order of side on inst at price that [risk] admits now: max_order_qty, max_order_notional at that price, that side's room of max_position and of [risk.underlying] max_net, and what max_gross_notional and max_net_notional leave for it at that price.
Qty::max() when none of them is set.
|
inlinestaticconstexprnoexcept |
Cuts r to risk_room() when that is less and still an order the instrument takes (the lot, min_qty, min_notional).
True when it was cut. An order the limits leave no such room for stays whole: the engine's refusal is then what the caller counts.
|
inlinestaticnoexcept |
A terminal update whose outcome the venue did not report: the ack timeout cancelled an order the venue never acknowledged, reconciliation found it gone with quantity unaccounted for, or a connector turned a request whose outcome it does not know into a generic reject.
|
inlinestaticconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
Maker mode looks its order up and cancels it (StrategyContext::order, cancel).