Interface IPersistCandleInstance

Per-context candle cache persistence instance interface. Scoped to a specific (symbol, interval, exchangeName) triple.

Each candle is keyed by its timestamp inside the context-scoped storage. readCandlesData returns null when ANY of the expected timestamps is missing (cache miss), so the caller can refetch from the exchange.

Custom adapters should implement this interface to override the default file-based candle cache behavior.

interface IPersistCandleInstance {
    readCandlesData(
        limit: number,
        sinceTimestamp: number,
        untilTimestamp: number,
    ): Promise<ICandleData[]>;
    waitForInit(initial: boolean): Promise<void>;
    writeCandlesData(candles: ICandleData[]): Promise<void>;
}

Implemented by

Methods

  • Read cached candles for the requested time window. Returns null if any candle in the window is missing (cache miss).

    Parameters

    • limit: number

      Number of candles requested

    • sinceTimestamp: number

      Aligned start timestamp (openTime of first candle)

    • untilTimestamp: number

      Reserved for API compatibility, not used by default

    Returns Promise<ICandleData[]>

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

  • Initialize storage for this candle context.

    Parameters

    • initial: boolean

      Whether this is the first initialization

    Returns Promise<void>

    Promise that resolves when initialization is complete

  • Write candles to cache. Implementations may skip incomplete candles (closeTime > now) and existing keys to avoid overwriting fully closed candles.

    Parameters

    Returns Promise<void>

    Promise that resolves when all writes are complete