PersistStorageUtils

Utility class for managing signal storage persistence.

Features:

  • Memoized storage instances
  • Custom adapter support
  • Atomic read/write operations for StorageData
  • Each signal stored as separate file keyed by id
  • Crash-safe signal state management

Used by SignalLiveUtils for live mode persistence of signals.

constructor();
PersistStorageInstanceCtor: any

Constructor used to create per-mode signal storage instances. Replaceable via usePersistStorageAdapter() / useJson() / useDummy().

getStorage: any

Memoized factory creating one IPersistStorageInstance per mode (backtest/live). Key: "backtest" or "live".

readStorageData: (backtest: boolean) => Promise<StorageData>

Reads all persisted signals for the given mode. Lazily initializes the instance on first access.

writeStorageData: (signalData: StorageData, backtest: boolean) => Promise<void>

Writes signals for the given mode. Lazily initializes the instance on first access.

usePersistStorageAdapter(Ctor: TPersistStorageInstanceCtor): void;

Registers a custom IPersistStorageInstance constructor. Clears the memoization cache so subsequent calls use the new adapter.

clear(): void;

Clears the memoized instance cache. Call when process.cwd() changes between strategy iterations.

useJson(): void;

Switches to the default file-based PersistStorageInstance.

useDummy(): void;

Switches to PersistStorageDummyInstance (all operations are no-ops).