FastMM documentation
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
quote_manager.hpp File Reference

QuoteManager (5.6): diffs the strategy's DesiredQuotes against the orders resting at the venue and emits the minimal set of New / Cancel / Replace actions. More...

#include "fastmm/core/capacity_price.hpp"
#include "fastmm/core/config_macros.hpp"
#include "fastmm/core/containers/ring_buffer.hpp"
#include "fastmm/core/containers/static_vector.hpp"
#include "fastmm/core/instrument.hpp"
#include "fastmm/core/messages.hpp"
#include "fastmm/core/oms.hpp"
#include "fastmm/core/time.hpp"
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <limits>

Go to the source code of this file.

Classes

struct  fastmm::DesiredQuotes
 
struct  fastmm::QuoteParams
 
struct  fastmm::QuoteAction
 
struct  fastmm::QuoteStats
 
class  fastmm::QuoteManager
 

Namespaces

namespace  fastmm
 

Enumerations

enum class  fastmm::QuoteActionKind : std::uint8_t { fastmm::New , fastmm::Cancel , fastmm::Replace }
 

Variables

constexpr std::size_t fastmm::kMaxQuoteLevels = 8
 

Detailed Description

QuoteManager (5.6): diffs the strategy's DesiredQuotes against the orders resting at the venue and emits the minimal set of New / Cancel / Replace actions.

Rules:

  • level i of a side maps to slot i (one order per slot);
  • hysteresis: keep an order whose price is within min_requote_ticks of the desired price and whose leaves cover min_qty_bps of the desired quantity;
  • never re-quote a slot within min_requote_interval of its last change;
  • orders in a Pending* state are never touched: the slot records the target instead and applies it when the order's ack or terminal update arrives via on_order_update() (dropped if the instrument is pulled first);
  • a slot only counts an order as its own if it is live and carries the slot's tag (order slots are reused, and a replace changes the order's id);
  • while an instrument is pulled, an order that becomes working late (its ack arrived after the pull) is cancelled at once;
  • a New or Replace refused by the venue (other than a post-only cross, or an order the venue no longer has) blocks new orders and replaces on that side for reject_backoff, doubling on each further refusal up to reject_backoff_max and reset by an ack on that side, so a side the venue keeps refusing (no balance, a price outside its band during a move) is not resent on every requote; a requote that meets a working order meanwhile cancels it, as on a venue without replace, and the New waits for the backoff to end. A New or Replace the engine's own checks refuse for its price (price collar, fat-finger band: QuoteAction::refused) backs off the same way, since the next requote during a move asks for a price just as far out;
  • an instrument whose venue supports replace (set_replace(), with supports_replace) gets a single Replace; otherwise Cancel now and New only once the cancel's terminal update arrives via on_order_update() (cancel-then-new keeps momentary exposure down and never double-quotes a level, and the New is checked against the balance once the old order's hold is released);
  • such a deferred New (QuoteAction::deferred) that the balance no longer covers -- the order it replaced filled instead of cancelling -- is withheld (QuoteAction::withheld, kept_balance) rather than refused by risk: the target predates the fill, the strategy's next quotes decide;
  • pause_quotes() holds an instrument's orders where they rest (the engine during a reconciliation): nothing is sent, moved or cancelled until resume(), which re-applies the last desired quotes against them, so an order that still matches is kept rather than cancelled and sent again; pull_quotes(keep_desired) does the same with the orders cancelled;
  • a move towards the touch (a bid up, an ask down) that the placer holds (QuoteAction::held: the account the order rests on has no more than QuoteParams::room_reserve orders left in its venue order windows) keeps the resting order where it is: the move would spend one of the last orders, and with cancel-then-new a New the window then refuses leaves the level empty. Moves away from the touch and pulls still go. The strategy's next quotes try the move again;
  • a New or a move the placer prices out (QuoteAction::priced_out: [capacity], its value is below the price of the order slot it takes, core/capacity_price.hpp) is neither a reject nor a backoff: a move keeps the resting order where it is, a New leaves the level empty, and the instrument joins a queue the engine re-applies (retry_priced()) when the price falls. A move towards the touch buys its gain (the level's value less its keep value); a move away from it cancels for free and buys its New as a new order;
  • hold_side() holds one side on every instrument (the engine's fill-cluster guard, core/fill_cluster.hpp) or on one (its hazard groups, core/hazard.hpp): pull_side() cancels what rests there, reconcile() and every retry treat the side's levels as empty while the desired quotes keep them, a target recorded for a pending order on the side is not placed, and reapply() puts the last desired quotes back when the hold ends;
  • a New or Replace the placer holds back for want of an order token (QuoteAction::rate_limited) is neither a reject nor a backoff: the instrument joins a FIFO of starved instruments, and the engine re-applies their last desired quotes (retry()) in that order as tokens come back, so a burst of requotes on many instruments is served in turn instead of refused event by event.

Actions are executed by the caller through a Placer callable so the QuoteManager stays independent of risk/OMS/transport wiring: bool place(QuoteAction& a); // New: sets a.handle on success; returns false on reject