One order sheet
phase_text names a phase. sheet_open stores a local id, a side, a price, and a quantity on a sheet the caller owns. A zero id, an unknown side, or a non-positive price or quantity is refused, and the previous sheet stays. sheet_bind stores a counter id once. A second, different id is refused.
sheet_apply moves the sheet through the life table. An event the table refuses leaves every field unchanged. A fill larger than the quantity still open is refused the same way. A fill that takes the whole remainder lands on partial, with nothing left. Finish is a separate event. Reject stores the cause the caller passes. The first non-negative stamp is kept for send, accept, and the finishing events. A negative stamp does not write. sheet_ack_ns and sheet_done_ns subtract those stamps. sheet_line replaces a text buffer with one line of id, side, phase, cause, quantity, filled, and left. A local id that does not fit a signed 64-bit value is refused, and the previous line stays.
gate_ask runs the checks for one enter or one pull and returns the first cause. A null list, rule, wash table, cash row, lot book, risk caps, watch, or flow window is skipped. An enter with a limit price requires a positive price and quantity. A symbol on the list is blocked. A channel that refuses a pull returns the pull-cap cause. A channel that refuses the price mode returns the price cause. Any other channel refusal is blocked. Deviation runs for a limit enter when the cap is zero or positive. Wash runs for an enter when the table is present. When cash and cash_need are set, cash_enough must hold. When lots and lock_qty are set, inventory is checked read-only (lock_future_ok or lock_cash_sell_ok). A short today book returns NoToday. A short yesterday book returns NoYday. A short total returns NoPos. The name list is the block list. When fee_den is positive on a limit enter, the freeze is notional plus the class fee (prelock_ok). When risk is set, qty / notional / live caps are applied (via BrokerWatch::screen when watch is set). The flow window is updated only after those checks pass; any earlier failure leaves the flow window and inflight side state unchanged. A window that is already at the limit returns the order-flow cause, or the pull-flow cause for a pull, and is left unchanged. The call does not send the order.
risk_merge takes the stricter positive limit on each axis (zero means that axis is off). AcctRiskTab stores per-account caps; a miss is fail-closed. sign_begin(need) resets a slip and sets how many modules must sign_pass before sign_ready (typical need=3 for global / account / lane). A reject sticks until reset.