Class Dictionary<Value>

Per-signal Map-like storage scoped by dictionary name.

Works like new Map() but the entries are bound to the CURRENT pending or scheduled signal: new Dictionary({ name: "llm" }).set("key", value) inside any strategy lifecycle callback. Unlike State, no context is passed through arguments — every instance method resolves the signal, mode and timestamp itself from backtest.methodContextService / backtest.executionContextService, so the class is unavailable outside async_hooks lifecycle callbacks by design.

Look-ahead bias protection: every entry is stamped with the logical when it was written at; a read happening at an earlier when does not see it, and a write with a smaller when overwrites (a restarted backtest resets live-written entries).

Requires an explicit Dictionary.enable() call before use — the subscription it creates disposes per-signal instances when the signal is cancelled or closed, preventing stale instances from accumulating.

Dictionary.enable();

const dictionary = new Dictionary<{ note: string }>({ name: "llm" });

// inside a strategy callback:
await dictionary.set("thesis", { note: "breakout confirmed" });
const thesis = await dictionary.get("thesis");

Type Parameters

  • Value = unknown

Constructors

Properties

_clear: (
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
) => Promise<void>

Context-free removal of all entries (hard delete). Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Error if Dictionary is not enabled

_delete: (
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
    key: string,
) => Promise<boolean>

Context-free removal of the entry under key (hard delete). Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Type declaration

    • (
          dto: {
              backtest: boolean;
              dictionaryName: string;
              signalId: string;
              when: Date;
          },
          key: string,
      ): Promise<boolean>
    • Parameters

      • dto: { backtest: boolean; dictionaryName: string; signalId: string; when: Date }
        • backtest: boolean

          Flag indicating if the context is backtest or live

        • dictionaryName: string

          Dictionary name

        • signalId: string

          Signal identifier

        • when: Date

          Logical timestamp at which the delete is happening

      • key: string

        Entry key

      Returns Promise<boolean>

      true if an entry existed and was removed

Error if Dictionary is not enabled

_entries: <Value_1 = unknown>(
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
) => Promise<[string, Value_1][]>

Context-free listing of visible [key, value] pairs (look-ahead-guarded). Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Type declaration

    • <Value_1 = unknown>(
          dto: {
              backtest: boolean;
              dictionaryName: string;
              signalId: string;
              when: Date;
          },
      ): Promise<[string, Value_1][]>
    • Type Parameters

      • Value_1 = unknown

      Parameters

      • dto: { backtest: boolean; dictionaryName: string; signalId: string; when: Date }
        • backtest: boolean

          Flag indicating if the context is backtest or live

        • dictionaryName: string

          Dictionary name

        • signalId: string

          Signal identifier

        • when: Date

          Logical timestamp at which the read is happening (look-ahead guard)

      Returns Promise<[string, Value_1][]>

      Array of [key, value] tuples

Error if Dictionary is not enabled

_get: <Value_1 = unknown>(
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
    key: string,
) => Promise<Value_1>

Context-free read of the value stored under key. Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Type declaration

    • <Value_1 = unknown>(
          dto: {
              backtest: boolean;
              dictionaryName: string;
              signalId: string;
              when: Date;
          },
          key: string,
      ): Promise<Value_1>
    • Type Parameters

      • Value_1 = unknown

      Parameters

      • dto: { backtest: boolean; dictionaryName: string; signalId: string; when: Date }
        • backtest: boolean

          Flag indicating if the context is backtest or live

        • dictionaryName: string

          Dictionary name

        • signalId: string

          Signal identifier

        • when: Date

          Logical timestamp at which the read is happening (look-ahead guard)

      • key: string

        Entry key

      Returns Promise<Value_1>

      Stored value, or null

Error if Dictionary is not enabled

_has: (
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
    key: string,
) => Promise<boolean>

Context-free check whether a visible entry exists under key. Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Type declaration

    • (
          dto: {
              backtest: boolean;
              dictionaryName: string;
              signalId: string;
              when: Date;
          },
          key: string,
      ): Promise<boolean>
    • Parameters

      • dto: { backtest: boolean; dictionaryName: string; signalId: string; when: Date }
        • backtest: boolean

          Flag indicating if the context is backtest or live

        • dictionaryName: string

          Dictionary name

        • signalId: string

          Signal identifier

        • when: Date

          Logical timestamp at which the check is happening (look-ahead guard)

      • key: string

        Entry key

      Returns Promise<boolean>

      true if a visible entry exists

Error if Dictionary is not enabled

_keys: (
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
) => Promise<string[]>

Context-free listing of visible entry keys (look-ahead-guarded). Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Type declaration

    • (
          dto: {
              backtest: boolean;
              dictionaryName: string;
              signalId: string;
              when: Date;
          },
      ): Promise<string[]>
    • Parameters

      • dto: { backtest: boolean; dictionaryName: string; signalId: string; when: Date }
        • backtest: boolean

          Flag indicating if the context is backtest or live

        • dictionaryName: string

          Dictionary name

        • signalId: string

          Signal identifier

        • when: Date

          Logical timestamp at which the read is happening (look-ahead guard)

      Returns Promise<string[]>

      Array of keys

Error if Dictionary is not enabled

_set: <Value_1 = unknown>(
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
    key: string,
    value: Value_1,
) => Promise<void>

Context-free write of value under key. Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Type declaration

    • <Value_1 = unknown>(
          dto: {
              backtest: boolean;
              dictionaryName: string;
              signalId: string;
              when: Date;
          },
          key: string,
          value: Value_1,
      ): Promise<void>
    • Type Parameters

      • Value_1 = unknown

      Parameters

      • dto: { backtest: boolean; dictionaryName: string; signalId: string; when: Date }
        • backtest: boolean

          Flag indicating if the context is backtest or live

        • dictionaryName: string

          Dictionary name

        • signalId: string

          Signal identifier

        • when: Date

          Logical timestamp this value belongs to

      • key: string

        Entry key

      • value: Value_1

        Value to store

      Returns Promise<void>

Error if Dictionary is not enabled

_size: (
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
) => Promise<number>

Context-free count of visible entries (look-ahead-guarded). Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Type declaration

    • (
          dto: {
              backtest: boolean;
              dictionaryName: string;
              signalId: string;
              when: Date;
          },
      ): Promise<number>
    • Parameters

      • dto: { backtest: boolean; dictionaryName: string; signalId: string; when: Date }
        • backtest: boolean

          Flag indicating if the context is backtest or live

        • dictionaryName: string

          Dictionary name

        • signalId: string

          Signal identifier

        • when: Date

          Logical timestamp at which the read is happening (look-ahead guard)

      Returns Promise<number>

      Number of visible entries

Error if Dictionary is not enabled

_values: <Value_1 = unknown>(
    dto: {
        backtest: boolean;
        dictionaryName: string;
        signalId: string;
        when: Date;
    },
) => Promise<Value_1[]>

Context-free listing of visible entry values (look-ahead-guarded). Routes to DictionaryBacktest or DictionaryLive based on dto.backtest.

Type declaration

    • <Value_1 = unknown>(
          dto: {
              backtest: boolean;
              dictionaryName: string;
              signalId: string;
              when: Date;
          },
      ): Promise<Value_1[]>
    • Type Parameters

      • Value_1 = unknown

      Parameters

      • dto: { backtest: boolean; dictionaryName: string; signalId: string; when: Date }
        • backtest: boolean

          Flag indicating if the context is backtest or live

        • dictionaryName: string

          Dictionary name

        • signalId: string

          Signal identifier

        • when: Date

          Logical timestamp at which the read is happening (look-ahead guard)

      Returns Promise<Value_1[]>

      Array of values

Error if Dictionary is not enabled

clear: () => Promise<void>

Remove all entries for the active pending or scheduled signal (hard delete). Resolves the signal, mode and timestamp from execution context — no context arguments required.

Error if no execution/method context or no pending/scheduled signal exists

delete: (key: string) => Promise<boolean>

Remove the entry under key for the active pending or scheduled signal (hard delete). Resolves the signal, mode and timestamp from execution context — no context arguments required.

Type declaration

    • (key: string): Promise<boolean>
    • Parameters

      • key: string

        Entry key

      Returns Promise<boolean>

      true if an entry existed and was removed

Error if no execution/method context or no pending/scheduled signal exists

disable: () => void

Disables dictionary storage by unsubscribing from signal lifecycle events. Safe to call multiple times.

enable: () => (...args: any[]) => any & ISingleshotClearable<
    () => (...args: any[]) => any,
>

Enables dictionary storage by subscribing to signal lifecycle events. Clears memoized instances in DictionaryBacktest and DictionaryLive when a signal is cancelled or closed, preventing stale instances from accumulating. Uses singleshot to ensure one-time subscription.

Cleanup function that unsubscribes from all emitters

entries: () => Promise<[string, Value][]>

List [key, value] pairs of visible entries for the active pending or scheduled signal. Resolves the signal, mode and timestamp from execution context — no context arguments required.

Type declaration

    • (): Promise<[string, Value][]>
    • Returns Promise<[string, Value][]>

      Array of [key, value] tuples

Error if no execution/method context or no pending/scheduled signal exists

get: (key: string) => Promise<Value>

Read the value stored under key for the active pending or scheduled signal. Resolves the signal, mode and timestamp from execution context — no context arguments required.

Type declaration

    • (key: string): Promise<Value>
    • Parameters

      • key: string

        Entry key

      Returns Promise<Value>

      Stored value, or null

Error if no execution/method context or no pending/scheduled signal exists

has: (key: string) => Promise<boolean>

Check whether a visible entry exists under key for the active pending or scheduled signal. Resolves the signal, mode and timestamp from execution context — no context arguments required.

Type declaration

    • (key: string): Promise<boolean>
    • Parameters

      • key: string

        Entry key

      Returns Promise<boolean>

      true if a visible entry exists

Error if no execution/method context or no pending/scheduled signal exists

keys: () => Promise<string[]>

List keys of visible entries for the active pending or scheduled signal. Resolves the signal, mode and timestamp from execution context — no context arguments required.

Type declaration

    • (): Promise<string[]>
    • Returns Promise<string[]>

      Array of keys

Error if no execution/method context or no pending/scheduled signal exists

set: (key: string, value: Value) => Promise<void>

Write value under key for the active pending or scheduled signal. Resolves the signal, mode and timestamp from execution context — no context arguments required.

Type declaration

    • (key: string, value: Value): Promise<void>
    • Parameters

      • key: string

        Entry key

      • value: Value

        Value to store

      Returns Promise<void>

Error if no execution/method context or no pending/scheduled signal exists

size: () => Promise<number>

Count visible entries for the active pending or scheduled signal. Resolves the signal, mode and timestamp from execution context — no context arguments required.

Type declaration

    • (): Promise<number>
    • Returns Promise<number>

      Number of visible entries

Error if no execution/method context or no pending/scheduled signal exists

values: () => Promise<Value[]>

List values of visible entries for the active pending or scheduled signal. Resolves the signal, mode and timestamp from execution context — no context arguments required.

Type declaration

    • (): Promise<Value[]>
    • Returns Promise<Value[]>

      Array of values

Error if no execution/method context or no pending/scheduled signal exists