/** * The strategy's own order and fill ledger, `stdlib.md` 17.7. * * **Each strategy owns one.** It is the strategy's record of what it has * actually done, it is what every position figure in the language is folded * from, and it is per strategy rather than per account because an account * position is shared with every other strategy and every manual trade in the * same contract. * * **Nothing is read from a host's position row.** The engine is neither handed * one nor asks for one. What it reads back is what it sent and what the * destination said became of it, which is the only record whose owner is this * strategy. * * **Frames fold at a bar boundary**, never during an execution. A frame that * arrived while bar four hundred was still moving is folded before bar four * hundred and one begins, so every position fact is constant for the length of * one execution and a re-execution of a moving bar sees exactly what the first * execution saw (`host-interface.md` 7.4). */ import type { Diagnostic } from '../../diagnostics/index.js'; import type { Span } from '../../span/index.js'; import type { Identity, IntentBar, OrderFrame, OrderIntent } from './intent.js'; import type { FrameOutcome, LedgerRow } from './row.js'; /** What the declaration and the chart fix before bar 0. */ export interface LedgerOptions { readonly instrument: Identity; readonly product: string; readonly qtyType: string; readonly declaredQty: number; /** The instrument's tick size, absent where the host states none. */ readonly tickSize: number | null; /** Entries allowed in one direction before one is refused. */ readonly pyramiding: number; } /** * What one order call sent, or why it sent nothing. * * The two are exclusive, and that is the shape rather than an accident: a * refused call mints no id, appends no row and returns no intent, so there is * nothing for a host to send and nothing to take back afterwards. */ export interface PlacedCall { readonly intents: readonly OrderIntent[]; /** Why the call was refused, `errors.md` OS7002 to OS7013 and OS7017. */ readonly refusal: Diagnostic | undefined; } export declare class Ledger { private readonly byIntent; private readonly placed; private readonly positions; private waiting; private next; private readonly options; /** The bar `sent` describes, so the list empties when a new one begins. */ private at; /** * The orders this bar has sent, which is what OS7013 is asked about. * * The bar is the right scope for that one rule and for nothing else. What a * reducing order is measured against used to be read from here too, and the * defect that made obvious was the plainest one there is: a close still * working when the next bar closed again was invisible, because this list is * emptied the moment the bar index changes. The rows below outlive the bar * and say which orders the destination still has, so that reading moved to * `closable.ts` and this list kept the question that really is a bar's. */ private sent; constructor(options: LedgerOptions); /** * Step 9 sent an order call. It becomes intents, and each becomes a row. * * A row is appended when the order is sent, at `placed`, which is the * engine's own status: an intent has left and nothing has come back, and a * host cannot report a state the destination has never described. * * **The whole call is read, mapped and refused before any of it is sent.** * Every order the call produces is held against `refuse.ts` first, and only * then does any of them take an id, so a refused call appends no row and * returns no intent: there is nothing for a host to send and nothing to take * back afterwards. A call that sends two orders sends both or neither. * * **The bar is the same promise one scope up**, and `discard` below is how * it is kept. A refusal anywhere on a bar hands none of the bar's orders to a * destination, so none of the bar's rows may survive it either, including the * rows of calls that had already been mapped when the refusal happened. That * is not the ledger rewriting a record backwards: nothing was handed over, so * there is no record of a hand-over to rewrite. */ place(name: string, params: readonly string[], args: readonly unknown[], bar: IntentBar, at: Span): PlacedCall; /** * The bar sent nothing after all: every row it appended is taken back. * * A refusal anywhere on a bar hands none of the bar's orders over, because * every call is mapped before any of them is routed (`orders.ts`). Until this * existed, the rows of the calls that had already been mapped stayed: a bar * that placed an order and then met a refusal left `orders()` reporting an * order at `placed` that no destination was ever handed, and a host * reconciling after a stopped run saw an order it never received. 17.7 says a * row is appended when the order is sent, and nothing had been sent. * * **Taken back rather than never written.** A row has to be there while the * rest of the bar is mapped: `cancel` asks whether a tag names a working * order, pyramiding counts the entries a position already holds, and a close * measures what one tag entered, all from rows this same bar may have * appended. Deferring the append would make an entry and a cancellation of it * on one bar into OS7009. So the bar writes its rows and a refused bar undoes * them, which is the same shape the moving bar already uses on the cells. * * The intent ids the bar minted are not reissued. An id is unique within a * run (`stdlib.md` 17.7), a frame that quoted one must never match a later * order, and a gap in the numbering is invisible to a host, so the cheap * invariant is the one worth keeping. * * **`from` is the row count the routing pass began at**, and it is held by * that pass rather than by a bar index kept here. A bar declared * `onUnconfirmed` applies its effects on every execution of itself, so one bar * can route more than once, and a mark taken when the bar index last changed * would take back rows whose orders a previous execution really did hand over. * The promise belongs to the pass that made it, so the mark does too. */ discard(from: number): void; /** A frame from the destination, held until the next bar boundary. */ deliver(frame: OrderFrame): void; /** * Folds every frame that has arrived, in the order it arrived in. * * A host does not have to put its frames in order before it sends them. A * repeat, a pair that crossed in flight and one that arrives after the order * ended are ordinary traffic, and the fold is what says what each of them * does. */ settle(): readonly FrameOutcome[]; /** The leg's net position in units, `0` while flat. */ size(): number; /** The average price of the open position, absent while flat. */ avgPrice(): number | null; /** Every row, oldest first, for a host that reports what the run did. */ rows(): readonly LedgerRow[]; private append; private contextFor; } //# sourceMappingURL=ledger.d.ts.map