Names, signals, and the counter
NameBook stores at most 256 instruments. insert writes an id starting at 1, and returns false when the symbol already exists or the book is full. link records a relation: 0 related, 1 underlying, 2 derived, 3 track underlying, 4 track derived. set_session allows the open minute to be later than the close minute for a session that crosses midnight.
PulseBoard keeps 128 subscriptions and a queue of 256. watch starts a subscription. offer fails when nothing matches or the queue is full. drain copies the queued pulses out.
BrokerWatch::screen checks quantity, side, notional, and the number of live orders. remember tracks a sent order. expire drops orders that missed their acknowledgement limit, passed their lifetime, or waited too long after a cancel. A limit of 0 or less turns that check off.
QueryFold accepts at most 32 engines and 64 accounts, with 16 queued requests per engine and 8 query kinds. push(engine, acct) keeps the old acct-only path. push(engine, acct, kind, page) stores an optional page token; out-of-range engine, account, kind, or a full queue fails closed. fold merges the queues. pending lists each account once. pending_kind lists distinct (acct, kind) rows with the last page token; a short output buffer returns -1. The library does not sleep between pages. The caller decides when to query again.
session_date moves a clock reading onto its trading day. From 08:00 through 18:00 the shift is 0. After 18:00, Monday shifts back 3 days and other days shift back 1. In the early morning, Monday shifts back 2 days and other days shift back 1. Weekends and days in ClosedDays are then skipped.