Class PersistCandleInstance

Default file-based implementation of IPersistCandleInstance.

Features:

  • Each candle stored as a separate JSON file keyed by its timestamp
  • Read returns null on any missing timestamp (cache miss → refetch)
  • Write skips incomplete candles (closeTime > now) and existing keys
  • Invalid cached candles emit warnings via errorEmitter and treated as miss
const instance = new PersistCandleInstance("BTCUSDT", "1m", "binance");
await instance.waitForInit(true);
await instance.writeCandlesData(candles);
const cached = await instance.readCandlesData(100, since, until);

Implements

Constructors

Properties

exchangeName: string
interval: CandleInterval
symbol: string

Methods

  • Reads cached candles for the requested window. Computes expected timestamps (sinceTimestamp + i * stepMs) and reads each by timestamp key. Returns null on ANY missing timestamp (cache miss). Invalid cached candles emit a warning via errorEmitter and are treated as miss.

    Parameters

    • limit: number

      Number of candles requested

    • sinceTimestamp: number

      Aligned start timestamp (openTime of first candle)

    • _untilTimestamp: number

      Reserved for API compatibility, unused

    Returns Promise<ICandleData[]>

    Promise resolving to candles in order, or null on cache miss

  • Initializes the underlying PersistBase storage.

    Parameters

    • initial: boolean

      Whether this is the first initialization

    Returns Promise<void>

    Promise that resolves when initialization is complete

  • Writes candles to cache. Skips incomplete candles (closeTime > now) and existing keys to keep the cache append-only for fully closed candles.

    Parameters

    Returns Promise<void>

    Promise that resolves when all writes are complete