Skip to content

Quickstart: the system on one page

Part of the User Guide. One diagram, one scoreboard, three commands; everything else on this page is folded away.

The system, end to end

the path feed L2 book strategy risk gate venue ledger the loop record replay [RECON] parity

Two rows, and each is a claim. The top row is the path a market event takes -- a feed, a book with an explicit queue, a strategy, a pre-trade gate, one venue interface with three engines behind it (the matcher, the paper broker, the live venue), and one ledger. The bottom row is what makes the numbers re-derivable: a run records both legs, replays offline, and has to reconcile -- so a live venue and a replay are the same program with a different plug.

What eight markets said

line what a fill captured what it cost why it ended
crypto perpetuals (Deribit, Binance, OKX) 0.088 ticks a 2.57-tick fee the fee is 29x the edge, and no lever moves a ratio like that
micro E-mini futures 0.0131 ticks a 0.5-tick commission the same wall one market over: a fee a tick can cover is not a capture a fee can pay for
SPY, the window that started the fee question 0.268 ticks a 0.35-tick fee the fee first, then 1 ms of order latency took +262 USD to +1.89
US large caps (MU, MSTR, AMD) 941 USD a window a 10,588 USD position sigma 506 windows to separate them, and the fee floor binds on 79% of order instances
options, 1 day to expiry the spread is payment for tail risk a 1.00 USD floor a contract the premium can be smaller than the floor: insurance, not a quoting edge
options, 15 days and out the fee axis passed for the first time 56 prints a fill against 71 needed the print count, not the fee, is what binds
funding carry, BTC, two venues, twelve months 0 of 12 months clear a 36 USD round trip no month's differential earns the round trip
a low-turnover reversion rule +149.76 cents a share, best window -980.38 cents, worst window it wins small and loses big: the sign does not replicate

Every figure in this table is the Retrospective's, and the quotients behind it are the fixture tests/fixtures/verdicts.json, which tools/study/viability.py re-derives in tier 1 of the gate.

The same numbers as a picture, and the two lines measured after the eight
0.0 0.5 1.0 1.5 2.0 2.5 3.0 captured spread (ticks) fill cost (ticks) 0.088 2.57 crypto perpetual 0.013 0.50 micro E-mini 0.27 0.35 SPY

Two bars a market: what a fill captured, and what it cost. Where the fee bar is taller, no quote width pays. The labels round to fit (0.088, 0.0131 and 0.268 ticks captured; 2.57, 0.5 and 0.35 ticks of fee); the table above carries the exact figures.

line what the measurement said why it stopped there
an EWMA trend rule (trend_l2) +1.54 USD on 1 April over 90 fills, and negative on 1 June closed by non-replication: the edge existed on one day and not the other
a volatility floor (standby when the market is quiet) the quiet half loses 0.00410 USD a fill, the busy half 0.00515 both halves lose, the quiet half loses less: a floor would keep the expensive minutes

Three commands

Build once, then the three paths this repository has: the replay, the same session over a socket, and the carry.

cmake --preset linux-debug && cmake --build --preset linux-debug

# 1 one replay, and the market leg recorded for command 2
bash tools/gate/verify_l2.sh smoke
./out/build/linux-debug/toy_quant l2_replay \
    data/v2/crypto/deribit_trades_2020-04-01_BTC-PERPETUAL.csv.gz \
    /tmp/depth_200k_base.csv BTC-PERPETUAL 0 active_l2 1 prorata --fast-validation --record=/tmp/one

# 2 the same engine over a socket: a local sender streams what 1 wrote
python3 tools/live/websocket_sender.py --port 8765 --trades /tmp/one_trades.csv --depth /tmp/one_depth.csv &
./out/build/linux-debug/toy_quant ws 127.0.0.1:8765 BTC-PERPETUAL active_l2 1 prorata --fast-validation

# 3 the carry branch, closed by its own number
./out/build/linux-debug/toy_quant carry \
    data/v2/funding/BTCUSDT-fundingRate-2024-03.csv \
    data/v2/funding/okx_funding_2024-03-01_2024-03-31_BTC-USDT-SWAP.csv \
    --symbol-a=BTCUSDT --symbol-b=BTC-USDT-SWAP --notional-usd=10000

1 prints [PNL] and writes the market leg; 2 feeds the same engine from a socket, so a replay and a live session are the same program with a different reader; 3 prints [CARRY], and the carry did not pay. The order leg to a venue, the relay's flags and the recorded order leg are the live page's.

The recording loop, and the equality the gate checks

Command 1's recording replays as a file, and the [PNL] line has to be the one the recording run printed: that equality is the loop in the diagram, and fast asserts it on this slice every run.

./out/build/linux-debug/toy_quant l2_replay \
    data/v2/crypto/deribit_trades_2020-04-01_BTC-PERPETUAL.csv.gz \
    /tmp/depth_200k_base.csv BTC-PERPETUAL 0 active_l2 1 prorata --fast-validation \
    --record=/tmp/session --record-orders=/tmp/session
./out/build/linux-debug/toy_quant l2_replay \
    /tmp/session_trades.csv /tmp/session_depth.csv BTC-PERPETUAL 0 active_l2 1 prorata --fast-validation

The order leg is <prefix>_orders.csv: what [ORDER-LOG] reports, and what --replay-orders=PREFIX replays as the venue on the clock it was recorded with (the live page).

Every flag, folded

Every l2_replay flag, grouped by what it changes
purpose flags what to know
which data the six positional arguments, --fast-validation --fast-validation skips the per-event checks a replay of known-good files does not need, and is what every recorded run uses
quiet --no-output suppresses the per-event lines, not the summary
quoting --base-spread-ticks, --refresh-price-ticks, --inventory-shift-ticks, --edge-cover-ticks, --min-spread-ticks 0 leaves each at the strategy's own setting; --base-spread-ticks=1 quotes at the touch. --advance-debounce-ms=D holds back only the side that would move towards the market, for D ms after the fair price last moved, while the side that retreats goes out at once -- measured at 10 ms it turned a -4.61 bps closed median into +12.40 on 6 of 7 days and halved the fills, and at 80 ms it changed nothing. --close-side-ticks=N brings the side that reduces the position in to N ticks while it is not flat, and at 10 ms with the debounce it read +11.41 on 4 of 7 days against the debounce's +12.40 on 6: it trades capture for turnover and does not pay here. --extra-layers=L quotes L further passive layers one tick behind the first, and at 10 ms with one contract it lifted the fills from 17 to 26 a window and the closed median from +12.40 to +26.18 on 5 of 7 days (recorded; the re-derivation reads +9.83, and the recorded value is archived 2026-11-26 as unreachable -- the layer buys fills and gives up capture) -- the inventory goes from 3-9 contracts to 4-10, so it is a sized decision rather than a free one. --jump-window-ms/--jump-ticks/--jump-cooldown-ms pull the quotes when the mid crosses --jump-ticks inside the window and hold them off for the cooldown; at 10 ms that fires often enough that the fills fall to 0-1 a window, which is why all of these default to off. The first version of this table explained it as "two ticks in 40 ms is normal on a half-basis-point tick", which was 10x low on the tick (5.2 bps here) and is not the mechanism; the measurement is the fills, the cause is not established
quote geometry --quote-distance-bps, --onesided-inventory-frac, --throttle-adverse-bps, --throttle-units --quote-distance-bps=D sets the half width in basis points of the reference price and the strategy turns it into max(2, round(D / tick_bps)) ticks, one tick being worth tick / price -- the same economic distance on every instrument, where a fixed tick count is 3 ticks (16 bps) on UP and 3 ticks (22 bps) on DNA. It and --base-spread-ticks set one distance and are refused together. --onesided-inventory-frac=F stops the adding side at F of the inventory cap, so the position is worked down by the closing side alone; the cap is the same rule at 1.0 and F acts earlier. Both default to off, so every recorded number stands
the halt --pause-ticks-per-second=D the threshold of ActiveL2MarketMaker's volatility halt, which is 9.0 and always on in every recorded run. Measured 2026-11-28 UTC after the divisor fix, the parameter is a lever and the frozen value is the best of the three tested: on the frozen cell over 2026-11-16..22 the closed medians read +16.82 at 9, +13.85 at 20 and +11.79 at 50 (about off), positive days 6 of 7 against 6 and 5, and the pause counts 45 / 8 / 0 say the lever is what moved them -- so loosening it costs 5 bps of median, and the sentence this row used to carry ("every value from 1.0 to 50.0 lands in the same place") was a property of the divisor defect and is withdrawn. What the sample does not say is where the optimum is below 9. A large value is what turns it off, and 0 leaves the strategy's own 9.0 so a run that does not ask for it is unchanged
the halt on the price's ruler --pause-bps-per-second=B the same threshold in bps a second, converted at the current mid: the form that can travel between instruments, since a tick speed cannot (6 ticks a second is 31.6 bps/s on UP at 0.19, 9 bps/s on a 1.5-bps tick and 72 bps/s on a 12-bps tick). The two flags are mutually exclusive -- the parser refuses a command line that names both, because a row has to say which ruler its number was measured on. Built 2026-11-29 and not yet measured: the bar is Tier 1 #10's, the registered 6-against-9 ordering re-derived in bps/s on UP's sixty days, then one threshold carried across BLUR/DNA/BABY with no pause count exploding on one instrument and vanishing on another
the reduction slice --inv-above-frac=F how long the position sat at or above F of the --inventory-limit cap, and what the marked net did in that time: [EXECUTION] prints inv_above_frac, seconds_above_inv_frac and pnl_bps_above_cap when the flag is above zero, and nothing when it is not, so every recorded line stands. The sample is taken after each event's own effects, on all three entry points (the generic reader, the L2 view and the L2 trade -- a fill arrives on the last and a slice hooked only on the first measures nothing on the mainline, found by its own test). The PnL is a difference of two marks of the run's own net, marked by the slice itself because advance_mid marks only for an armed kill switch, so a carried position is priced as a carry rather than at its entry. --inv-above-frac without --inventory-limit is refused: a fraction of no cap is a fraction of nothing. Built 2026-11-30; the two-value smoke on 2026-11-26 at 100 ms read 41.8 book seconds and -9.57 bps above the 50-contract cap against 242.8 seconds and +14.05 bps above the 100-contract one -- the same day, both signs
repricing --amend-instead-of-cancel, --amend-deadband-ticks=N move a quote in place instead of pulling it and placing it again: one round trip instead of two, and the order never leaves the book. What it costs is the queue position at the old price, because the amended order lands at the back of the level it moves to; a layer behind a primary keeps the cancel path, since folding it onto the primary would collapse the ladder. The venue leg was measured at 83.2 ms p50 against cancel-and-place's 163.1, and this replay's engine amends in place, so the request is a queue reset rather than a cancel. For the maker, --amend-deadband-ticks is how far the target must retreat before the amend fires: 2.0 by default, which is the deadband the recorded arm was taken with, and 1 is the arm registered against it because the symmetric version amended on a single tick, took fills from 26 to 49 a window and the closed median from +9.83 to -5.92. On execution_l2 the same flag is the resting child's follow: it moves with the near touch, both directions, at 1.0 tick by default, because a child that does not follow a tick is not at the touch and the parent still has to be worked -- and an engine without an amend answers with the cancel it replaced, after which the slice is posted again rather than crossed
the state --amend-on-toxicity, --toxicity-imbalance=N the switch between the two measured repricing arms: the cancel path while the book is calm and the two-tick retreat amend while it is toxic, where toxic is the mid's range over --jump-window-ms past --jump-ticks (active_l2's detector, no cooldown needed) or the recent flow past N of one side (default 0.9, i.e. 95 per cent of the last thirty-two prints). Off by default; the two branch counters are in the strategy's own metrics, because a state that never fires reads exactly like a switch that does nothing. Measured 2026-11-26: on UP 11-16 the arm took 9,571 amends against 13,707 cancel-path refreshes, and across UP, NES and PROS it lifts the per-fill capture (+0.37 bps of closed median on UP, +5.16 of net on NES, +1.39 of closed median on PROS) without losing a fifth of the fills and without converting a day -- PROS stays at 4 of 7 and UP's positive closed days fall 5 to 4. At ten contracts on UP (2026-11-26) it buys the tail and pays the median: the worst net day goes from -202.88 to -76.38 bps -- 126 bps, the widest tail improvement any arm in the family has read, because the carried inventory falls from a -168.76 bps mark to -6.38 and the loss becomes a quote loss -- while the closed median falls to +2.05 on 4 of 7, the settled median turns -9.42 and the dispersion gate fails on both conditions. Refused at that size, and the next registration is a stricter definition with both halves in its bar
the wind-down --wind-down-skew-minutes=M, --wind-down-end=HH:MM, --wind-down-skew-ticks=T, --wind-down-adverse-bps=X the maker's own inventory skew for the last minutes of a named session: the adding side stops opening and the closing side walks in towards the touch, up to T ticks (one by default), in whole ticks as the clock advances. The end is a UTC clock because a strategy inside a replay cannot see where the replay stops -- --close-out only runs when the input ends. Both are off by default and both are refused on a strategy that does not carry the layer. The closing side is exempt from --advance-debounce-ms: a deadline outranks a debounce. X makes the skew conditional: it starts only when the carried position is marked against us by at least X bps, and a favourably marked tail is left to settle. Measured 2026-11-26: the median absolute residual falls from 50M and 20M units to zero on both seats at a settled median of +6.00 against +12.75 (UP) and -10.24 against +0.51 (NES) -- the tail can be worked, and this week's mark did not repay it. The condition was then wired and asked at ten contracts (2026-11-26) and it is refused too: it selects the adverse days exactly (three of them reproduce the unconditional arm bit for bit) and the arm still reads a closed median of -2.13 on 3 of 7 against the control's +10.32 on 5, with the worst day at -123.02 against -34.12 -- the skew sells into the run rather than avoiding it, and the carried mark does not predict the tail's direction (11-16 and 11-21 were both marked in our favour; the skew helped one and cost 27 bps on the other)
the hold-timer --max-hold-seconds=S, --hold-skew-ticks=T once a position has been carried past S seconds, the side that closes it walks in towards the touch by T ticks -- the position-age analogue of the wind-down, keyed to how long the tail has sat rather than the clock. Both off by default (S=0); the point is to cut the inventory carry's variance, the window's 10x term, by shedding a stale tail before its carry keeps compounding. Not yet measured -- the bar is a shallower tail with the median not below the control
sizing --max-depth-ratio=F, --depth-ladder-max=N no rung larger than F of the same side's displayed touch size, and a quote above that cap split into up to N rungs one tick apart, with the excess dropped and counted (depth_capped_rungs, depth_unquoted_quantity). The case is the size wall the fine-tick branch hit -- BLUR at thirteen ticks reads +31.74 bps closed at one contract, +23.66 at ten and +9.32 with a net of -2.87 at a hundred. Off by default, refused together with --extra-layers (two ladders), and refused on a strategy that does not quote. Measured 2026-11-26: at a 0.15 cap with one rung BLUR's hundred-contract cell reads a closed median of +43.76 on 5 of 7 days, identically under conservative, against the uncapped arm's +9.32; four rungs instead of one destroys the cell (38 fills to 6, +9.32 to -2.15) because the rungs sit behind the quote the sweep reaches, and NES at ten contracts is worse than its uncapped control either way -- so the lever is a fine-tick one
layer geometry --layer-step-bps the step between extra layers in basis points of the reference price; 0 leaves one tick a layer, which on a 0.76 bps tick puts the second layer almost on the first layer's price
the trend line's signal --trend-signal=ewma\|burst, --trend-burst=ticks=T,window_ms=W,obi=F,hold=VIEWS ewma is the recorded fast/slow cross of the midpoint and the default; burst replaces it with the event the maker's halt fires on -- a mid range of T ticks inside W milliseconds of book time -- taken only when the displayed-depth imbalance is F of one side on the same sign as the move, and held for hold views with the framework's stop, time stop and cooldown still above it. Its entry stays --trend-entry=side=own --post-only, where the fee reads exactly 2.00. Measured 2026-11-26: NES 5 of 7 positive days at +2.12 closed, UP 1 of 7 at -5.18, both under the +4.00 round trip, and the family is sealed
risk --max-position, --max-exposure-usd, --kill-switch-loss-usd, --fat-finger-bps, --max-orders-per-second with --order-burst --max-exposure-usd is enforced once named and reported either way
account --starting-cash the cash the account opens with (default 1000), which is also the exposure ceiling; a live run against a funded account passes the venue's balance, or venue to read it off the account at start (which makes the at-start [RECON] a tautology, so the at-end line is the accounting check)
fills --participation-limit, --time-in-force, --post-only, --arrival-share, --queue-chunks, --queue-seed the queue model is the seventh positional argument, not a flag; the kind of order is what the venue's ordType says, so --post-only is post_only and an IOC is ioc rather than a limit that rests
latency --order-latency-us, --cancel-latency-us holds the order or the cancel for N microseconds, converted into the market clock's own unit (clock_units_per_second), so 100000 is 100 ms on a millisecond cut: the flag's unit is the flag's and the clock's is the clock's, and adding the number raw made every OKX run a thousand times slower than it said (measured 2026-11-28 UTC). Without a latency --post-only changes nothing in a replay, because the quote and the book are the same event and nothing is marketable on arrival. With a latency a quote that lands in a book that moved is declined, which is the whole of the flag's effect -- and why a replay without one cannot measure it. A cancel naming an order the venue has not received yet is held and applied when the order lands, which is the case a market maker's requote meets on any link where the two legs share the delay
fees --maker-fee-rate, --fee-schedule a schedule names min, regulatory, clearing, audit, rebate, commission; every term is zero unless named
gates --markout-cover, --flatten-band, --markout-horizon --markout-cover needs active_l2; --markout-horizon moves the cycle count behind the markout itself
output --metrics, --trace-order, --record each adds a line or a file and changes no number
the one that does change a number --close-out, --close-out-cross-bps flattens the carried position at the touch and prints [WIND-DOWN], so [PNL] becomes realisable instead of a mark; the band puts the closing IOC through the midpoint for a live venue whose book is not the market leg's last snapshot
the reduce-only exit --reduce-only-exit inside the wind-down the closing side becomes a taker at the touch, for what is carried and never more: it flattens instead of walking, never opens the other side and never flips, and --close-out stays the fallback for a partial fill. Off by default, so every recorded wind-down row stands. Measured 2026-12-01 on the seat's 28 days at 01:30-04:30, (19,70), clip 1, 100 ms, the L4-open 26: the exit leaves a median position of 1 contract against 3 and costs +3.07 bps on the settle line, -0.40 net bps and +0.0065 USD a day against the passive wind-down -- cheaper than the recorded market close (10 contracts -7.67 bps, 50 -11.55 at 04:30) but not free
the handover a replay cannot fill --settle-residual, --settle-taker-bps, --settle-slippage-ticks prices the leftover position against the far touch plus N ticks with a taker fee and prints [SETTLE] beside [PNL]; needs one book, and off by default leaves every recorded line where it was
session --snapshot-out, --snapshot-in l2_replay only: a session is written and resumed against a replay's own clock, and ws refuses both -- a live session reconciles against the venue instead ([RECON]). See below: the account comes back, the strategy's own state does not
order leg --record-orders, --replay-orders see below: one file per venue, the reader that replays it, and the clock it replays on
live order leg --live-orders, --venue-endpoint, --venue-max-orders, --venue-orders-per-second see below: the venue becomes the relay's order channel; the first three are required together and only l2_replay and ws take them, and the rate is optional beside the session cap
signals --trend-params, --trend-entry --trend-params is the non-market-making line's EWMA cross and its exits, and --inventory-limit doubles as the size of a full signal; --trend-entry=side=own prices its clip on our own side of the book so it rests and pays the maker rate, and max_age=VIEWS cancels an entry nobody hit
threads and pacing --feed-thread, --ring-capacity, --profile-stages, --live-pacing see below: the first three report the hand-off; pacing replays against the wall clock and reports [LIVE]
paper trading --paper-broker and its five fault flags, --order-gateway and its two see below: they put a component between the strategy and the venue
execution --parent, --algo, --algo-entry needs the execution_l2 strategy
two books --symbol-b, --trades-b, --depth-b see below: one account, two venues, three extra lines

Seven flags need a paragraph each rather than a line -- the recorder, the session snapshot, the order leg, the feed thread, the paper broker, the order gateway and the live order leg. Those are on the flag reference.

Build, tests and the sanitizer tier
cmake --preset linux-debug && cmake --build --preset linux-debug
ctest --preset linux-debug

The same code builds and tests under AddressSanitizer and UndefinedBehaviorSanitizer, which is the gate's tier 3 (bash tools/gate/verify_l2.sh asan):

cmake --preset linux-asan && cmake --build out/build/linux-asan && ctest --preset linux-asan

out/build/linux-debug/toy_quant is the simulator and replay binary; out/build/linux-debug/backtest_main computes legacy metrics from recorded tick data.

The tour's last two commands, with the output to expect

bash tools/gate/verify_l2.sh fast prints one line a tier:

tier0 OK
tier1 OK

bash tools/sweep/risk_check.sh isolates the pre-trade controls and must end with risk OK:

risk baseline: submitted=55 risk_line=0 recon=ok
risk permissive: submitted=55 execution_same=yes recon=ok
risk fat: submitted=38 fat_finger_rejections=13 recon=ok
risk rate: submitted=6 rate_limited_orders=15 recon=ok
risk OK

The baseline and permissive runs submit the same 55 orders and print the same [EXECUTION] line, which is the point: enabling a permissive control must not change the run. The 1 bp band refuses 13 orders and the 0.01-per-second bucket refuses 15, and every run still reconciles. A single cell of the signal grid, which is negative on purpose:

FAST_SLOW="5:30" ENTRIES="3" STOPS="4" bash tools/sweep/trend_sweep.sh
fast  slow  entry_ticks  exit_ticks  stop_ticks  fills  net_pnl_usd  fees_paid  risk_pauses  max_abs_inventory  recon
5     30    3            0.5         4           106    -6.04458     5.3        3            100                ok

106 taker clips pay 5.3 USD of fees against a gross loss of 0.74, so the signal has no forecast that covers the cost of taking liquidity. The full 27-cell grid and the rest of that table are in Performance History.