Documentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-ollama-crontab/llms.txt
Use this file to discover all available pages before exploring further.
backtest-ollama-crontab uses the Cron.register API from backtest-kit to drive data ingestion in two distinct modes without duplicating logic. The same strategy file, jan_2026.strategy.ts, registers two cron handlers: one that fires once at startup for backtest data preparation, and one that polls every 15 minutes when running live. The backtest boolean parameter passed to each handler is the gating mechanism — each handler checks it and returns early if the mode is wrong. This keeps live and backtest code paths in the same file while guaranteeing they never execute simultaneously.
The Cron.register API
Cron.register accepts a single options object with three properties:
| Property | Type | Required | Effect |
|---|---|---|---|
name | string | Yes | Unique identifier for this cron registration |
handler | async (symbol, when, backtest) => void | Yes | Async callback invoked on each trigger |
interval | string (e.g. "15m") | No | If provided, the handler runs on this schedule in live mode; if omitted, the handler runs once at startup |
interval is omitted, backtest-kit treats the registration as a one-shot prepare handler that fires once when the backtest or live session initialises. This is the mechanism used to pre-fetch historical data before the strategy’s getSignal callback begins receiving ticks.
Two registrations in jan_2026.strategy.ts
In backtest mode, the
"live-fetch-data" handler registered with interval: "15m" never runs. The if (backtest) return guard at the top of its handler exits immediately on every invocation. All data fetching in backtest mode is done exclusively by the one-shot "backtest-prepare-data" handler.crawlLiveFrame — 15-minute live polling
CrawlerMainService.crawlLiveFrame(when) is called on every 15-minute tick in live mode. It converts the when: Date parameter to a day stamp using getMomentStamp(when), crawls only that single day via CrawlerService.crawlDay(stamp), then fires signalJobSubject.next() to trigger the LLM processing queue.
CrawlerService.crawlDay calls ParserDbService.create() with a (channel, messageId) unique index, re-crawling the same day on the next 15-minute tick is idempotent — duplicate messages are silently ignored and only new messages produce new parser-items records.
crawlBacktestFrame — one-shot full-range fetch
CrawlerMainService.crawlBacktestFrame(when) is the backtest counterpart. It reads the active frame’s startDate and endDate from listFrameSchema(), converts both to stamps, and calls CrawlerService.crawlRange(fromStamp, toStamp) to fetch the entire date range in one pass.
crawlRange completes, signalJobSubject.next() fires and SignalJobService processes all newly inserted parser-items rows through the LLM risk gate before any strategy ticks begin.
Mode detection
getMode() from backtest-kit returns "backtest" or "live" depending on how the CLI was invoked. The --backtest flag sets backtest mode; absence of the flag sets live mode. Both CrawlerMainService methods and SignalJobService.run() call getMode() internally as an additional safety check, so even if a handler guard were accidentally removed, the underlying service would still no-op in the wrong mode.
- Live Mode Flow
- Backtest Mode Flow
Every 15 minutes
backtest-kit invokes the "live-fetch-data" handler:backtest === false→ handler proceedscrawlerMainService.crawlLiveFrame(when)is calledgetMomentStamp(when)converts the current date to a day stampcrawlerService.crawlDay(stamp)scrapes today’s messages from the Telegram channel viaCryptoYodaScreenService.screenDay(date)→ScraperService.scrapeDay()- New messages are upserted into
parser-items(duplicates ignored) signalJobSubject.next()fires —SignalJobServiceprocesses unvisited rows through the LLM and writes results toscreen-items- On the next price tick,
getSignal()queriesscreen-itemsand opens a position ifriskAction === "follow"and price is inside the entry zone
"backtest-prepare-data" handler fires but exits immediately at if (!backtest) return.