PersistBreakevenUtils

Persistence utility class for breakeven state management.

Handles reading and writing breakeven state to disk. Uses memoized PersistBase instances per symbol-strategy pair.

Features:

  • Atomic file writes via PersistBase.writeValue()
  • Lazy initialization on first access
  • Singleton pattern for global access
  • Custom adapter support via usePersistBreakevenAdapter()

File structure:

./dump/data/breakeven/
├── BTCUSDT_my-strategy/
│ └── state.json // { "signal-id-1": { reached: true }, ... }
└── ETHUSDT_other-strategy/
└── state.json
constructor();
PersistBreakevenFactory: any

Factory for creating PersistBase instances. Can be replaced via usePersistBreakevenAdapter().

getBreakevenStorage: any

Memoized storage factory for breakeven data. Creates one PersistBase instance per symbol-strategy-exchange combination. Key format: "symbol:strategyName:exchangeName"

readBreakevenData: (symbol: string, strategyName: string, signalId: string, exchangeName: string) => Promise<BreakevenData>

Reads persisted breakeven data for a symbol and strategy.

Called by ClientBreakeven.waitForInit() to restore state. Returns empty object if no breakeven data exists.

writeBreakevenData: (breakevenData: BreakevenData, symbol: string, strategyName: string, signalId: string, exchangeName: string) => Promise<void>

Writes breakeven data to disk.

Called by ClientBreakeven._persistState() after state changes. Creates directory and file if they don't exist. Uses atomic writes to prevent data corruption.

usePersistBreakevenAdapter(Ctor: TPersistBaseCtor<string, BreakevenData>): void;

Registers a custom persistence adapter.

useJson(): void;

Switches to the default JSON persist adapter. All future persistence writes will use JSON storage.

useDummy(): void;

Switches to a dummy persist adapter that discards all writes. All future persistence writes will be no-ops.