Function waitForReady

  • Blocks until the schema registries needed to start trading are populated.

    Polls exchangeValidationService, frameValidationService and strategyValidationService once per second for up to MAX_WAIT_SECONDS seconds. The loop exits as soon as the required registries are non-empty for the given mode:

    • Backtest mode (isBacktest = true): exchange, frame and strategy schemas must all be registered (frames define the historical window).
    • Live mode (isBacktest = false): only exchange and strategy schemas are required — frames are unused.

    Useful at startup when schemas are registered asynchronously (lazy imports, remote config, plugin loading) and the caller wants to delay Backtest/ Live invocation until everything is ready. If the timeout elapses without the registries filling in, the function returns silently — the caller is expected to surface a clearer error from the subsequent Backtest/Live call (e.g. "no strategy registered").

    Parameters

    • OptionalisBacktest: boolean

      Whether to additionally require a registered frame schema. Defaults to true.

    Returns Promise<void>

    Promise that resolves when the registries are ready or the timeout elapses.

    import { waitForReady, Backtest } from "backtest-kit";

    import "./schemas/exchange";
    import "./schemas/strategy";
    import "./schemas/frame";

    await waitForReady();
    Backtest.background("BTCUSDT", { strategyName, exchangeName, frameName });