Open a section from the left

Match on the paper venue

PaperVenue handles 48 names, kNames, and 192 live orders, kTickets. A name must be less than 48. An order is judged only after its send delay has elapsed, against the book at that moment. A cancel waits for its cancel delay.


pitlane::VenueCfg cfg{};
cfg.lot = 1;
pitlane::PaperVenue venue(cfg);
const pitlane::Rung asks[] = {{100, 5}};
venue.set_levels(1, nullptr, 0, asks, 1);

pitlane::Report reps[4]{};
pitlane::VenueOut out = venue.admit(in, in.stamp_us, reps, 4);

on_ext matches resting orders to prints that carry a sequence and bid/ask order numbers. print_hits requires the print to be at or after the order, and strictly through the slipped limit when rigid is set. same_side_print is true when that side's order number is the later one. A same-direction print still counts, filled at the print price. The other direction counts at the order price. match_quote is the active path: a buy that reaches the ask, or a sell that reaches the bid, takes shown size. One print's quantity is shared across resting orders.

admit writes reports into the caller buffer and sets out.why. With VenueCfg::trade_open=0, new enters fail with Why::Closed. on_clock promotes staged orders whose delay has elapsed and completes cancels that are due (skipped while hang sticky). on_print and on_tape reduce the quantity ahead of a resting order; with VenueCfg::rigid set, tape_keep drops same-side aggressor prints. force_fill / force_pull / force_deny / drill_apply cover forced injects via DrillCue (Closed = 10, NotTrading). TouchMode / resolve_px pick opp/own/last/mid/best5. Aggressor 0 keeps every print. on_shown applies later displayed-size changes without double-counting a trade.

PitConf [venue] mirrors the paper matcher's match.ini: nine go/pull lags (go_usN / pull_usN, or fractional-second delayN / cancel_delayN), rigid_rule→rigid, use_ext→tape_first, plus lot/rate/notional/cancel_pow_x1000. Use conf_venue_cfg to build a VenueCfg.

Center::step is the trading-center loop (trading-center process role): optional TapeMd or a live MdEngine, quote tops into PaperVenue, StratEngine, then a ready TdEngine or TradeLane. It stores now_us on the desk clock. RouteAllow with zero bits is NoFilter. A heartbeat publishes a Pulse on topic hb. TapeMd replays a caller-owned quote array.

Engine is the shared process role: set_up, pre_run, loop_task, post_run, timers, control notes, a symbol table, and housekeep. MdEngine drains subs (quote, signal, rebuild, market order, market trade). Five failed subscribes in a row stop further sends. copy_subs copies the id list before a later send. write_quote, write_print, write_signal, write_factor, write_mkt, and write_rebuild are the gateway writes. TdClient is the counter surface a gateway implements (insert, cancel, on_algo, query_asset, query_position). TdEngine runs orders, then asset and position queries, then algo jobs, then BrokerWatch timeouts. risk_filter can deny an enter before the client is called. StratEngine is the strategy and its context: it picks reports, quotes, rebuilds, market orders, prints, algo jobs, query replies, and signals, and it publishes orders, subscriptions, and queries. order_precheck drops a child with a bad size, side, id, or time. Broker sockets are not in this library. A CTP gateway belongs in the program that subclasses these types, as examples/simnow/ctp does.

SimRole names the four paper roles (tape, quote adapter, trader, matcher). order_delay and tape_speed follow the replay notes. timer_due runs due matches and cancels. adjust_offset is the derivative close-then-open split.

Composition helpers (still allocation-free on the hot path): FeedHub into Yard/Desk; TradeLane::lane_beat for paper TD; StratHook onto DeskLoop (including algo/package/log/pause); seed_cash / seed_hold for account rows; seed_facts / seed_hours / seed_holidays plus cold load_facts / load_hours / load_holidays for local basic-data tables; TopicBus for same-machine topic pub/sub; RouteBook for strategy→algo binding. pulse_bridge fans PulseBoard into desk pulses.

Style::Day fills the whole remainder at its limit, even past the size shown there. Style::Passive expires if it would cross. Style::Immediate keeps only the shown size. Style::All expires the whole order when the shown size is short. A self-trade against the same account stops the order.

Before 09:30 the delay tables are zero. After that, session_band splits the day at 10:00, 10:30, 11:00, 11:30, 13:30, 14:00, 14:30, and 15:00. SimClock uses those nine bands unless sample points are loaded. A negative result from SimClock::go means the order did not reach the book. The caller applies that result. admit does not read the clock itself.

auction_clear picks the price with the largest matched quantity. tie_higher selects the higher price on a tie. Otherwise the price closer to the reference is used.