TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-ollama-crontab/llms.txt
Use this file to discover all available pages before exploring further.
packages/core library exposes several services injected via di-kit. They are accessed through the global core object (typed via globalThis.core in the root tsconfig.json paths). Each service is a singleton — instantiated once by the DI container and reused for the lifetime of the process. The container is initialised at startup when the packages/core/src/index.ts entry point is imported.
Dependency Injection
Services are registered and resolved usingdi-kit, exposed through the three functions exported by packages/core/src/lib/core/di.ts:
Registers a service factory under a Symbol token. The factory is called lazily on first
inject() call and the result is cached as a singleton.Resolves and returns the singleton instance registered under
token. Throws if the token has not been registered. Type parameter T narrows the return type.Forces eager initialisation of all registered services. Called once at application startup.
packages/core/src/lib/core/types.ts and grouped into the TYPES registry (see TYPES Registry below).
CrawlerMainService
CrawlerMainService is the entry point for the data-ingestion half of the pipeline. It is called by cron triggers and is responsible for driving CrawlerService to scrape Telegram channel data and then emitting signalJobSubject to kick off signal processing.
crawlLiveFrame
The reference timestamp for the crawl, typically the current wall-clock time supplied by the cron trigger. Converted to a
momentStamp integer via getMomentStamp(when) and passed to CrawlerService.crawlDay().signalJobSubject to trigger the signal job. If the runtime mode is "backtest", the method returns immediately without crawling — backtest data is sourced separately via crawlBacktestFrame.
crawlBacktestFrame
The timestamp provided by the backtest runner. The actual date range is read from the frame schema via
listFrameSchema() — when is used only for logging context.listFrameSchema(), converts startDate and endDate to momentStamp integers, and calls CrawlerService.crawlRange(fromStamp, toStamp) to bulk-ingest the full frame. Then emits signalJobSubject to process the ingested rows.
SignalMainService
SignalMainService provides read-only query access to the pipeline’s two collections for use by downstream consumers (e.g., strategy evaluation code in backtest-kit).
getLast4HourSignal
Trading symbol with USDT suffix (e.g.,
"BTCUSDT").The reference timestamp. The method looks back exactly 4 hours from this point.
ScreenDbService.findLast4HourRow(symbol, when). Returns the most recent screen-items document for the symbol published within the 4-hour window [when − 4h, when], sorted by publishedAt DESC. Returns null if no matching document exists.
getLast4HourScreen
Trading symbol with USDT suffix.
The reference timestamp. The method looks back exactly 4 hours from this point.
ParserDbService.findLast4HourRow(symbol, when). Returns the most recent parser-items document (regardless of visited state) for the symbol within the 4-hour window. Returns null if none found. Useful for checking whether a raw signal exists even before LLM processing has completed.
SignalJobService
SignalJobService manages the lifecycle of the background signal-processing loop. It subscribes to the signalJobSubject event and processes all unvisited parser-items rows whenever the subject emits.
enable
Subscribes SignalJobService.run() to signalJobSubject. Decorated with singleshot from functools-kit, which means calling enable() a second time before calling disable() returns the same subscription handle without creating a second subscriber.
Returns a composed unsubscribe function. Calling it unsubscribes from signalJobSubject and resets the singleshot cache so enable() can be called again later.
disable
Calls the unsubscribe function returned by the last enable() invocation. Safe to call even if enable() was never called — the hasValue() guard prevents a no-op from throwing.
Internal run (queue semantics)
The private run method is wrapped with queued from functools-kit, which serialises concurrent invocations into a FIFO queue. This prevents overlapping LLM calls when signalJobSubject emits faster than the LLM responds.
In live mode run calls parserDbService.findAllByVisited(false) and processes each pending row sequentially. In backtest mode it resolves the current frame’s date range and uses parserDbService.findAllByPublishedAt(startDate, endDate) instead.
Both modes perform the same deduplication check before calling the LLM:
screenDbService.findByParserItem(row.id). If a screen-items document already exists, the row is skipped even if visited is still false.SignalLogicService
SignalLogicService contains the single business-logic step that bridges the raw parser data and the LLM output.
execute
A fully-populated
parser-items document as returned by ParserDbService.json<RiskOutlineContract, Args>(OutlineName.RiskOutline, symbol, direction, targets, stoploss) from agent-swarm-kit. The json() function routes the call through the registered RiskOutline outline, runs the Ollama completion, and validates the response against RiskOutlineFormat. If isValid is false, execute throws with the validation error message.
On success, maps the five RiskOutlineContract fields onto IScreenDto. The actual LLM call is delegated to the module-level RUN_OUTLINE_FN helper (which wraps json() from agent-swarm-kit):
CrawlerService
CrawlerService is the lower-level crawling primitive that fetches raw Telegram channel data and persists it to parser-items. Both methods accept integer momentStamp values — a compact day-level timestamp produced by the get-moment-stamp library (getMomentStamp(date) → number, fromMomentStamp(stamp) → Date).
crawlDay
A
momentStamp integer representing a single calendar day. Internally calls crawlRange(stamp, stamp).crawlRange for single-day crawls. Returns the flat array of raw screen items produced for that day.
crawlRange
Start of the date range (inclusive), as a
momentStamp integer.End of the date range (inclusive), as a
momentStamp integer.fromStamp to toStamp, calls CryptoYodaScreenService.screenDay(day) for each date, and collects all results via Promise.all. For each returned message with a non-null data field and type === "crypto_yoda_channel", it calls parserDbService.create() to upsert a parser-items document. Messages with data === null are logged and skipped.
Returns the full flat list of raw screen items (both stored and skipped).
TYPES Registry
All DI tokens are defined inpackages/core/src/lib/core/types.ts and exported as the TYPES object. Pass these Symbols to inject<T>() to resolve the corresponding singleton:
| Token | Service class |
|---|---|
TYPES.loggerService | LoggerService — structured console logger |
TYPES.scraperService | ScraperService — low-level HTTP / Telegram scraper |
TYPES.crawlerService | CrawlerService — day/range crawl orchestrator |
TYPES.parserService | ParserService — signal extraction from raw messages |
TYPES.parserDbService | ParserDbService — CRUD for parser-items collection |
TYPES.screenDbService | ScreenDbService — CRUD for screen-items collection |
TYPES.cryptoYodaScreenService | CryptoYodaScreenService — channel-specific screen adapter |
TYPES.signalJobService | SignalJobService — LLM processing job lifecycle |
TYPES.signalLogicService | SignalLogicService — single-row LLM enrichment logic |
TYPES.crawlerMainService | CrawlerMainService — top-level crawl entry point |
TYPES.signalMainService | SignalMainService — top-level signal query entry point |