Documentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit/llms.txt
Use this file to discover all available pages before exploring further.
Cron is a built-in scheduler that fires handlers on candle-interval boundaries in virtual time — the same time stream your strategies see during backtesting. Registered jobs are coordinated across all parallel Backtest.background() runs: when multiple symbol backtests reach the same interval boundary simultaneously, only one handler invocation fires and all parallel waiters share the same in-flight promise. This singleshot coordination prevents double-firing without any external locking mechanism.
Call Cron.enable() once at startup to subscribe to the engine’s lifecycle subjects. After that, every strategy tick is automatically forwarded to Cron — no manual wiring needed.
Types
CronCallback
In global mode: the symbol of the first parallel backtest to reach this boundary. In fan-out mode: the whitelisted symbol whose tick triggered this invocation.
The aligned virtual time at which the entry fires. Already aligned to the entry’s
interval boundary.Execution mode from the originating lifecycle event.
CronEntry
CronHandle
A disposer function returned byCron.register. Calling it removes the entry — equivalent to Cron.unregister(name).
Cron.register
Register a periodic or fire-once cron job. Re-registering the samename replaces the previous entry and bumps an internal generation counter, so late writes from an in-flight old handler are silently ignored.
Unique job name. Used as the deduplication key. Must not contain
: (reserved as a slot-key segment separator).Candle interval at whose boundaries the handler fires (e.g.,
"1h", "4h", "1d"). Omit for fire-once mode: the handler fires on the very first matching tick and never again until clear() or unregister.Symbol whitelist. Omit for global mode (handler fires once per boundary across all parallel backtests). Provide for fan-out mode (handler fires once per boundary per listed symbol).
Async function to execute. Errors are caught and logged — a failed fire-once handler is not marked as fired and will retry on the next tick.
CronHandle disposer.
Cron.enable
Subscribe Cron to the engine lifecycle:beforeStartSubject, idlePingSubject, activePingSubject, schedulePingSubject. All four subjects are merged into a single serial singlerun queue so concurrent ticks on the same virtual minute cannot race.
singleshot — calling it multiple times is a no-op. Returns the same cleanup function on every call. Must be called before running any backtest or live session.
Cron.disable
Tear down the subscriptions installed byenable(). Does not unregister entries or clear fire-once marks.
Cron.unregister
Remove a registered job by name. In-flight handler promises are not cancelled — they settle on their own.The
name passed to register.Cron.clear
Reset fire-once marks so that fire-once jobs can fire again.When provided, clears only fan-out fire-once marks for that symbol. Global fire-once marks are left intact. Omit to clear all fire-once marks across all jobs and symbols.
clear() does not touch _inFlight promises. An in-flight handler completing after clear() will re-add its mark — use unregister + register to hard-reset a specific job (bumps the generation counter and invalidates any late writes).Two Modes: Periodic vs Fire-Once
interval set | Mode | When fires |
|---|---|---|
| ✅ | Periodic | Once per aligned boundary of that interval |
| ❌ omitted | Fire-once | On the very first matching tick, never again |
Two Scopes: Global vs Fan-out
symbols set | Scope | Invocation cardinality |
|---|---|---|
| ❌ omitted / empty | Global | Once per boundary total (first symbol wins the slot) |
✅ ["BTC", "ETH"] | Fan-out | Once per boundary per whitelisted symbol |