One analysis cycle, step by step
What happens between two closed candles, in the order it happens — and which parts of the decision the code enforces rather than the prompt.
Timing
The engine runs one cycle per closed candle; the public deployment uses 4h candles. In the 48 cycles recorded between 2026-10-19 and 2026-10-26 the median cycle took 266 seconds and cost $0.0121 in model usage — almost all of it spent waiting on the multimodal model, not on the local work. That is a small, single-instrument window, and it is the only latency figure this site quotes.
The order of stages is fixed:
- fetch market data and account state;
- compute the indicator stack;
- render the chart image;
- collect news and fundamentals;
- retrieve trade memory;
- call the model and parse its JSON;
- validate claims, size the position and apply the guards;
- record the decision and route it to the executor.
1. Market data
One cycle pulls, through CCXT: 999 OHLCV candles on the configured timeframe, a 50-level order book, the funding rate, 24-hour volume and the last 500 trades. The order book is there because price and volume alone do not show where resting orders are — depth by level, bid/ask imbalance and spread are computed from it before anything is sent to the model.
This is a single-exchange view of a market that trades on many venues. The bot does not aggregate books across exchanges, so its picture of liquidity is as good as one venue's book.
2. Indicators
src/indicators/ holds 65 functions compiled with Numba (@njit(cache=True)) — EMA, ADX, Supertrend, Ichimoku, Parabolic SAR, CMF, OBV, RSI, support/resistance and volatility work. The same functions appear 107 times across src/, and there are no external technical-analysis dependencies.
Two reasons for that choice: the numbers are computed deterministically and can be re-checked line by line, and a model's numeric claims can be compared against values the engine already has. Indicator values describe the past; the entry decision does not follow from any single threshold.
3. The chart image
Plotly renders a 1920×1080 candlestick chart with SMA, RSI, CMF and OBV panels plus swing-point annotations. The PNG goes to the multimodal model next to the numeric stack, so it gets both a picture and the numbers behind it.
Chart export (Plotly + Kaleido) is the least reliable local step. It runs in a thread with a hard timeout and three retries; if it fails, the cycle continues text-only instead of aborting. Code: src/analyzer/pattern_engine/chart_generator.py.
4. News and fundamentals
Up to 5 articles are read from RSS feeds (CoinDesk, CoinTelegraph, Decrypt, CryptoSlate) with feedparser and defusedxml, optionally enriched with the article body through trafilatura over plain HTTP. Market fundamentals come from CoinGecko and DeFiLlama, and the mood index from Alternative.me. Relevance scoring is local; no sentiment API is paid for.
X/Twitter is not included: without paid authentication it is not reliably scrapeable, so the bot runs on Reddit and RSS instead of describing a feed it cannot read. RSS headlines vary in quality, and the model is told that this block is context rather than evidence.
5. Trade memory
The prompt carries the 3 nearest past trades, win rate and average P&L over the 20 nearest trades, the 3 most relevant learned rules and up to 5 recent post-mortems. Prompt size is capped by [prompt_budget]: 100,000 estimated tokens per request, 16,384 tokens reserved for the image, and lower-priority blocks dropped whole when the budget is exceeded. The memory article covers what is stored and retrieved.
6. The model call and the prompt
This deployment runs provider = opencode with deepseek-v4.1-flash on the OpenCode Go endpoint; a configured provider = all instead walks a fixed chain (Google Gemini 3.8 Flash → DeepSeek → OpenCode Go → LM Studio → OpenRouter → BlockRun for text, the same without LM Studio for charts), and a cycle in which every provider fails becomes HOLD rather than an exception (src/managers/provider_orchestrator.py). Each provider call is retried with a named reason, so the log says whether a reply was empty, cut by the output cap, blocked by a content filter or malformed.
The model returns structured JSON: signal, confidence, entry, stop, target, size, reasoning, and an explicit invalidation condition — the price or indicator state that would prove the thesis wrong. That invalidation step is a prompt instruction, not a tested gate: a model can write a vague one, or skip the discipline the prompt asks for.
The expected-value rule works the same way. EV = (win rate × average win) − ((1 − win rate) × average loss) − fees is injected as a decision rule, computed from the bot's own closed trades, with fees taken from the configured transaction_fee_percent (0.075% per side, so a round trip costs twice that). The repository does not reject a signal on arithmetic alone.
Prompt construction, including that rule and the falsification request, lives in src/analyzer/prompts/template_manager.py; the fee arithmetic is src/analyzer/formatters/ev_formatter.py.
7. What the code enforces instead
A smaller, testable set of checks runs outside the model:
- Configured symbol guard — outside the configured pair nothing is traded (
src/trading/guards/configured_symbol.py); - Position-size cap — a requested size above
MAX_POSITION_SIZEis rejected, and a missing or invalid size falls back to risk-manager sizing (src/trading/guards/max_position_size.py); - Entry R/R policy — one resolver,
resolve_entry_rr_floor()insrc/trading/rr_policy.py, takes the stricter of the configuredmin_rr_entryand the brain's learned threshold. It starts at0.0, so there is no fixed 1.5 floor by default, and the learned value can only raise it; - Claim validation — reported trend strength is compared with computed ADX (
src/analyzer/trend_validator.py), and pattern quality is replaced by a deterministic scorer (src/analyzer/pattern_quality_scorer.py); - Dynamic SL/TP — stop and target distances scale with ATR and the regime profile, not with a percentage typed into a config;
- Fail closed — if governance or risk validation cannot decide safely, no order is produced.
What this does not prove
- A working pipeline says nothing about returns. It was built to be inspectable, not to be profitable by construction.
- Prompt-level rules (expected value, falsification) are instructions, not constraints. Only the guards and the R/R policy are enforced by code.
- The market view is single-venue and single-instrument by design; the cycle has no cross-exchange or cross-asset context.
- The latency and cost figures come from one week of recorded cycles and will not match other periods or providers.
Every cycle is recorded: the prompt, the model answer and the parsed decision are visible on the dashboard.
Live dashboard ↗Next: trade memory →