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 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;
- collect news and fundamentals;
- retrieve trade memory;
- call the model and parse its JSON, while the dashboard chart renders in parallel;
- 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. What the model reads
The request is text: the indicator stack, the price action, the deterministic pattern list, the news block and the trade memory. No image is attached.
It also carries the raw candles: the last 183 closed candles of the analysis frame, the daily frame and the weekly frame as a CSV block. The numeric block describes the market but never shows it — it has a 30-day range and a 365-day change, and no 180-day high or low at all. An 8-cycle reading test asked the model for the last close, the 180-day high and low, the position inside that range and the 30-candle direction: with the numeric prompt alone it scored 47% of fields and 0/8 on the 180-day high, with the tables 92% and 8/8. That measures whether the model can answer from data it is given — without the tables those numbers were not in the prompt at all — not whether the tables improve a decision: a 13-cycle ablation found the signal changed no more often than sending the same prompt twice. The tables cost ~18k prompt tokens per cycle and are the first section the prompt budget drops.
Swing structure arrives as text too: higher highs and higher lows, lower highs and lower lows, a break of structure, or a double top/bottom, each with the levels it compared. Candlestick patterns were implemented and then measured — 8,108 BTC 4h candles, forward 6/12/24-bar hit rate against the base rate, Bonferroni-corrected — and none survived, so none are in the prompt.
That is a measured decision. On 2026-11-22 a 16-cycle, four-arm ablation replayed the logged cycle prompts text-only twice and with the chart. The same prompt sent twice changed the signal in 5 of 16 cycles; adding the chart changed it in 3 (old render) and 5 (current render), with a smaller mean confidence gap than the repeat. A separate 8-point reading test showed the model does read the image accurately — 91% of fields, last price to the cent — so the image was redundant rather than unreadable: its "P1–P4" citations restated numbers already in the numeric block.
The chart is still rendered, for the dashboard and the Discord post, as its own task started before the model call and awaited after it, so its ~12 s overlaps the inference. Export runs in a thread with a hard timeout and three retries; a failed render keeps the previous dashboard image. 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, 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 = commandcode with deepseek/deepseek-v4.1-flash on the Command Code Provider API; a configured provider = all instead walks a fixed chain (Google Gemini 3.8 Flash → DeepSeek → OpenCode Go → Command Code → LM Studio → OpenRouter → BlockRun), 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 →