Skip to main content

Documentation 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.

Getting backtest-ollama-crontab running locally takes four steps: build the npm workspace packages, authenticate a Telegram MTProto session, copy the session file into the strategy folder, and fire the backtest command. The entire pipeline — Telegram crawl, LLM risk filter, position engine — runs on your machine with no external cloud services required, as long as Ollama, MongoDB, and Redis are already up.
The repository ships with demo Telegram credentials (CC_TELEGRAM_API_ID=31861455, CC_TELEGRAM_API_HASH=ca60446c67ce250ee4e789c730163449). These are provided for quick evaluation only. For any sustained or production use, register your own application at my.telegram.org and replace these values in your .env file. Using shared demo credentials may result in rate limiting or account restrictions from Telegram.

Prerequisites

Before running any commands, confirm the following are available on your machine:
  • Node.js 18+ and npm with workspaces support (npm 7+)
  • MongoDB running on localhost:27017 (default connection string: mongodb://localhost:27017/backtest-pro?wtimeoutMS=15000)
  • Redis running on localhost:6379
  • Ollama installed and the gpt-oss:120b model pulled (ollama pull gpt-oss:120b), reachable at http://localhost:11434
  • A Telegram account on a phone that can scan QR codes within the Telegram app
A docker/ directory is included in the repository with a Docker Compose file that starts MongoDB and Redis together. Run docker compose -f docker/docker-compose.yml up -d to skip manual service setup.

Setup Steps

1

Build the workspace packages

From the repository root, run the build script for your platform. The script iterates every package under packages/, runs npm install and npm run build inside each one:
npm run build:x
Each package emits two artifacts into its build/ directory:
  • build/index.cjs — CommonJS bundle consumed at runtime by the CLI
  • types.d.ts — rolled-up TypeScript declarations that the root tsconfig.json path aliases expose as globalThis.core
You must re-run this step any time you modify source files inside packages/core or packages/main.
2

Authenticate the Telegram MTProto session

The Telegram crawler uses GramJS (MTProto) rather than the Bot API, so it needs a full user-account session. Change into packages/main and run the auth helper:
cd packages/main
npm run auth
A QR code is printed directly in the terminal. Open the Telegram app on your phone, navigate to Settings → Devices → Link Desktop Device, and scan the code. Once authentication succeeds, a session.txt file is written into the packages/main/ directory.
The session file encodes an encrypted MTProto session string. It does not contain your password or 2FA secrets. Keep it out of version control — session.txt is already listed in .gitignore.
3

Copy the session into the strategy folder

The January 2026 strategy reads session.txt from its own directory at runtime so it can subscribe to the configured Telegram channel without re-authenticating. Copy the file you just created:
cp packages/main/session.txt content/jan_2026.strategy/session.txt
If you create additional strategies under content/, each one needs its own copy of session.txt in its folder.
4

Run the January 2026 backtest

Return to the repository root and start the backtest:
npm start -- --backtest --ui --entry ./content/jan_2026.strategy/jan_2026.strategy.ts
What happens under the hood:
  1. @backtest-kit/cli loads the strategy file at the path given by --entry.
  2. The backtest-prepare-data cron handler fires once (no interval set) and calls core.crawlerMainService.crawlBacktestFrame(when), which uses GramJS iterMessages to pull the January 2026 message history from the configured channel into MongoDB.
  3. ChannelScreenService (Parse layer) runs regex extraction on each raw message, saving direction, entry, targets, and stoploss to the parser-items collection.
  4. SignalJobService picks up each unvisited row and calls risk.outline.ts, which sends the signal plus pre-computed candle metrics to Ollama. The model returns a zod-validated riskAction: "skip" | "follow" verdict stored in screen-items.
  5. For each symbol/timestamp pair in the frame, getSignal checks whether riskAction === "follow" and whether the current close price falls inside the signal’s entryFromentryTo range. Qualifying signals open positions with priceTakeProfit = targets[2] and priceStopLoss = signal.stoploss.
  6. The --ui flag opens the backtest-kit web UI so you can inspect the equity curve and individual trade details in real time.

Running in Live Mode

Once you are satisfied with the backtest results, switch to live mode to have the pipeline poll the Telegram channel on a recurring schedule:
npm start -- --live --entry ./content/jan_2026.strategy/jan_2026.strategy.ts
In live mode the live-fetch-data cron handler runs every 15 minutes (interval: "15m"), calling core.crawlerMainService.crawlLiveFrame(when) to fetch the latest channel messages. Each new signal that has not been visited is passed through the LLM risk outline, and getSignal is queried by the backtest-kit engine on its normal tick cycle. The backtest-prepare-data handler is still registered but immediately returns when backtest === false, so there is no interference between the two cron jobs.
Live mode does not execute real orders — it relies on whichever exchange schema you have registered (the default uses ccxt with Binance in spot mode with enableRateLimit: true). Wire up an actual exchange connector and order-management layer before treating live-mode signals as executable trades.

Environment Variables

All configuration is read from a .env file in the repository root (loaded via dotenv-cli before each npm script). The table below lists every variable with its default value:
VariableDefaultPurpose
CC_MONGO_CONNECTION_STRINGmongodb://localhost:27017/backtest-pro?wtimeoutMS=15000MongoDB connection string
CC_TELEGRAM_API_ID31861455Telegram MTProto API ID (replace with your own)
CC_TELEGRAM_API_HASHca60446c67ce250ee4e789c730163449Telegram MTProto API hash (replace with your own)
CC_SYMBOL_LISTBTCUSDT,POLUSDT,ZECUSDT,HYPEUSDT,...Comma-separated list of symbols the crawler processes per run
CC_OLLAMA_URLhttp://localhost:11434Ollama HTTP endpoint

Build docs developers (and LLMs) love