Interface IStateInstance

Interface for state instance implementations. Defines the contract for local, persist, and dummy backends.

Intended use: per-signal mutable state for LLM-driven strategies that track trade confirmation metrics across the position lifetime — e.g. peak unrealised PnL, minutes since entry, and capitulation thresholds.

Example shape:

{ peakPercent: number; minutesOpen: number }

Profitable trades endure -0.5–2.5% drawdown yet still reach peak 2–3%+. SL trades either never go positive (Feb25) or show peak < 0.15% (Feb08, Feb13). Capitulation rule: if position open N minutes and peak < threshold (e.g. 0.3%) — LLM thesis was not confirmed by market, exit immediately.

interface IStateInstance {
    dispose(): Promise<void>;
    getState<Value extends object = object>(): Promise<Value>;
    setState<Value extends object = object>(
        dispatch: Value | Dispatch<Value>,
    ): Promise<Value>;
    waitForInit(initial: boolean): Promise<void>;
}

Methods

  • Releases any resources held by this instance.

    Returns Promise<void>

  • Read the current state value.

    Type Parameters

    • Value extends object = object

    Returns Promise<Value>

    Current state value

  • Update the state value.

    Type Parameters

    • Value extends object = object

    Parameters

    • dispatch: Value | Dispatch<Value>

      New value or updater function receiving current value

    Returns Promise<Value>

    Updated state value

  • Initialize the state instance.

    Parameters

    • initial: boolean

      Whether this is the first initialization

    Returns Promise<void>