Function runInMockContext

  • Runs a function inside a mock method and execution context.

    Useful in tests and scripts that need to call context-dependent services (e.g. getBacktestTimeframe) without a real backtest runner.

    All context fields are optional; the defaults produce a minimal live-mode environment pointing at placeholder schema names:

    • exchangeName"mock-exchange"
    • strategyName"mock-strategy"
    • frameName"mock-frame"
    • symbol"BTCUSDT"
    • backtestfalse (live mode)
    • when → current minute boundary (alignToInterval(new Date(), "1m"))

    Type Parameters

    • T extends unknown = any

    Parameters

    • run: Function$2<T>

      Zero-argument function to execute within the context.

    • context: Partial<IRunContext>

      Partial IRunContext; any omitted field falls back to its default.

    Returns Promise<T>

    Promise resolving to the return value of run.

    const price = await runInMockContext(
    () => getEffectivePrice("BTCUSDT"),
    { exchangeName: "binance", strategyName: "my-strategy", frameName: "1d" },
    );