# collomut/trading-lab-bot architecture

> Architecture diagram of the GitHub repository collomut/trading-lab-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/collomut/trading-lab-bot
- Repository: https://github.com/collomut/trading-lab-bot

## Overview

Trading Lab is a crypto-market research and paper/Testnet trading application, with live order placement explicitly disabled. Its principal workflow is a CLI or dashboard-started worker that fetches market candles, evaluates strategy signals, applies risk controls, and submits protected orders; state and trade history are persisted. Separate research scripts run historical strategy evaluations. The graph follows documented capabilities and shown references; some unsampled implementation details and dashboard routes are not expanded.

Main entry points: [`dashboard.py`](https://github.com/collomut/trading-lab-bot/blob/main/dashboard.py) (Web dashboard), [`bot_engine.py`](https://github.com/collomut/trading-lab-bot/blob/main/bot_engine.py) (Trading cycle), [`main.py`](https://github.com/collomut/trading-lab-bot/blob/main/main.py) (CLI entrypoint), [`exchange.py`](https://github.com/collomut/trading-lab-bot/blob/main/exchange.py) (Exchange connector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Trading runtime"]
  node_cli["CLI entrypoint<br/>[main.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_engine["Trading cycle<br/>[bot_engine.py]"]
  node_strategies["Signal strategies<br/>[strategies.py]"]
  node_shadow["Shadow candidate<br/>[shadow_strategy.py]"]
  node_exchange["Exchange connector<br/>[exchange.py]"]
end

subgraph group_controls["Risk and state"]
  node_risk["Risk manager<br/>[risk_manager.py]"]
  node_sqlite[("SQLite state<br/>[state_store.py]")]
  node_postgres[("Postgres state")]
  node_startup["Startup wrapper<br/>[start.py]"]
  node_migration["SQLite import"]
end

subgraph group_dashboard["Dashboard"]
  node_web["Web dashboard<br/>[dashboard.py]"]
  node_overview["Overview view<br/>[overview.html]"]
  node_history["History view<br/>[history.html]"]
  node_logs["Logs view<br/>[logs.html]"]
  node_positions["Positions view<br/>[positions.html]"]
  node_strategyview["Strategy view<br/>[strategy.html]"]
end

subgraph group_research["Strategy research"]
  node_backtest["Backtest engine"]
  node_frequency["Frequency analysis"]
  node_macro["Macro Donchian study"]
end

node_operator(("Operator"))
node_binance{{"Binance Testnet"}}
node_browser(("Dashboard user"))
node_researcher(("Researcher"))
node_marketdata[("Historical candles")]

node_operator -->|"runs"| node_cli
node_cli -->|"loads"| node_config
node_cli -->|"starts"| node_engine
node_cli -->|"starts"| node_web
node_engine -->|"fetches candles"| node_exchange
node_engine -->|"evaluates signals"| node_strategies
node_engine -->|"evaluates candidate"| node_shadow
node_engine -->|"checks risk"| node_risk
node_engine -->|"submits orders"| node_exchange
node_exchange -->|"requests market and orders"| node_binance
node_risk -->|"persists state"| node_sqlite
node_risk -->|"persists state"| node_postgres
node_startup -->|"checks import"| node_migration
node_migration -->|"imports SQLite"| node_postgres
node_startup -->|"starts dashboard worker"| node_web
node_browser -->|"views and controls"| node_web
node_web -->|"reads bot status"| node_engine
node_web -->|"requests balance"| node_exchange
node_web -.->|"renders"| node_overview
node_web -.->|"renders"| node_history
node_web -.->|"renders"| node_logs
node_web -.->|"renders"| node_positions
node_web -.->|"renders"| node_strategyview
node_researcher -->|"runs study"| node_frequency
node_researcher -->|"runs study"| node_macro
node_frequency -->|"uses replay"| node_backtest
node_macro -->|"uses replay"| node_backtest
node_backtest -.->|"replays candles"| node_marketdata

click node_cli "https://github.com/collomut/trading-lab-bot/blob/main/main.py"
click node_config "https://github.com/collomut/trading-lab-bot/blob/main/config.py"
click node_engine "https://github.com/collomut/trading-lab-bot/blob/main/bot_engine.py"
click node_strategies "https://github.com/collomut/trading-lab-bot/blob/main/strategies.py"
click node_shadow "https://github.com/collomut/trading-lab-bot/blob/main/shadow_strategy.py"
click node_exchange "https://github.com/collomut/trading-lab-bot/blob/main/exchange.py"
click node_risk "https://github.com/collomut/trading-lab-bot/blob/main/risk_manager.py"
click node_sqlite "https://github.com/collomut/trading-lab-bot/blob/main/state_store.py"
click node_postgres "https://github.com/collomut/trading-lab-bot/blob/main/postgres_state_store.py"
click node_startup "https://github.com/collomut/trading-lab-bot/blob/main/start.py"
click node_migration "https://github.com/collomut/trading-lab-bot/blob/main/migrate_sqlite_to_postgres.py"
click node_web "https://github.com/collomut/trading-lab-bot/blob/main/dashboard.py"
click node_overview "https://github.com/collomut/trading-lab-bot/blob/main/templates/overview.html"
click node_history "https://github.com/collomut/trading-lab-bot/blob/main/templates/history.html"
click node_logs "https://github.com/collomut/trading-lab-bot/blob/main/templates/logs.html"
click node_positions "https://github.com/collomut/trading-lab-bot/blob/main/templates/positions.html"
click node_strategyview "https://github.com/collomut/trading-lab-bot/blob/main/templates/strategy.html"
click node_backtest "https://github.com/collomut/trading-lab-bot/blob/main/research/backtest_strategy.py"
click node_frequency "https://github.com/collomut/trading-lab-bot/blob/main/research/backtest_frequency.py"
click node_macro "https://github.com/collomut/trading-lab-bot/blob/main/research/backtest_macro_donchian.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_config,node_engine,node_strategies,node_shadow,node_exchange,node_browser toneBlue
class node_risk,node_sqlite,node_postgres,node_startup,node_migration,node_marketdata toneAmber
class node_web,node_overview,node_history,node_logs,node_positions,node_strategyview toneMint
class node_backtest,node_frequency,node_macro toneRose
class node_operator,node_binance,node_researcher toneIndigo
```

## Components

### Trading runtime

- [CLI entrypoint](https://github.com/collomut/trading-lab-bot/blob/main/main.py): `main.py`
- [Configuration](https://github.com/collomut/trading-lab-bot/blob/main/config.py): `config.py`
- [Trading cycle](https://github.com/collomut/trading-lab-bot/blob/main/bot_engine.py): `bot_engine.py`
- [Signal strategies](https://github.com/collomut/trading-lab-bot/blob/main/strategies.py): `strategies.py`
- [Shadow candidate](https://github.com/collomut/trading-lab-bot/blob/main/shadow_strategy.py): `shadow_strategy.py`
- [Exchange connector](https://github.com/collomut/trading-lab-bot/blob/main/exchange.py): `exchange.py`

### Risk and state

- [Risk manager](https://github.com/collomut/trading-lab-bot/blob/main/risk_manager.py): `risk_manager.py`
- [SQLite state](https://github.com/collomut/trading-lab-bot/blob/main/state_store.py): `state_store.py`
- [Postgres state](https://github.com/collomut/trading-lab-bot/blob/main/postgres_state_store.py): `postgres_state_store.py`
- [Startup wrapper](https://github.com/collomut/trading-lab-bot/blob/main/start.py): `start.py`
- [SQLite import](https://github.com/collomut/trading-lab-bot/blob/main/migrate_sqlite_to_postgres.py): `migrate_sqlite_to_postgres.py`

### Dashboard

- [Web dashboard](https://github.com/collomut/trading-lab-bot/blob/main/dashboard.py): `dashboard.py`
- [Overview view](https://github.com/collomut/trading-lab-bot/blob/main/templates/overview.html): `templates/overview.html`
- [History view](https://github.com/collomut/trading-lab-bot/blob/main/templates/history.html): `templates/history.html`
- [Logs view](https://github.com/collomut/trading-lab-bot/blob/main/templates/logs.html): `templates/logs.html`
- [Positions view](https://github.com/collomut/trading-lab-bot/blob/main/templates/positions.html): `templates/positions.html`
- [Strategy view](https://github.com/collomut/trading-lab-bot/blob/main/templates/strategy.html): `templates/strategy.html`

### Strategy research

- [Backtest engine](https://github.com/collomut/trading-lab-bot/blob/main/research/backtest_strategy.py): `research/backtest_strategy.py`
- [Frequency analysis](https://github.com/collomut/trading-lab-bot/blob/main/research/backtest_frequency.py): `research/backtest_frequency.py`
- [Macro Donchian study](https://github.com/collomut/trading-lab-bot/blob/main/research/backtest_macro_donchian.py): `research/backtest_macro_donchian.py`

### Other components

- **Operator**
- **Binance Testnet**
- **Dashboard user**
- **Researcher**
- **Historical candles**

## Connections

- Operator → CLI entrypoint: runs (evidence: `README.md`)
- CLI entrypoint → Configuration: loads (evidence: `main.py`)
- CLI entrypoint → Trading cycle: starts (evidence: `main.py`)
- CLI entrypoint → Web dashboard: starts (evidence: `main.py`)
- Trading cycle → Exchange connector: fetches candles (evidence: `bot_engine.py`)
- Trading cycle → Signal strategies: evaluates signals (evidence: `bot_engine.py`)
- Trading cycle → Shadow candidate: evaluates candidate (evidence: `bot_engine.py`)
- Trading cycle → Risk manager: checks risk (evidence: `bot_engine.py`)
- Trading cycle → Exchange connector: submits orders (evidence: `bot_engine.py`)
- Exchange connector → Binance Testnet: requests market and orders (evidence: `exchange.py`)
- Risk manager → SQLite state: persists state (evidence: `risk_manager.py`)
- Risk manager → Postgres state: persists state (evidence: `risk_manager.py`)
- Startup wrapper → SQLite import: checks import (evidence: `README.md`)
- SQLite import → Postgres state: imports SQLite (evidence: `migrate_sqlite_to_postgres.py`)
- Startup wrapper → Web dashboard: starts dashboard worker (evidence: `README.md`)
- Dashboard user → Web dashboard: views and controls (evidence: `dashboard.py`)
- Web dashboard → Trading cycle: reads bot status (evidence: `dashboard.py`)
- Web dashboard → Exchange connector: requests balance (evidence: `dashboard.py`)
- Web dashboard → Overview view: renders
- Web dashboard → History view: renders
- Web dashboard → Logs view: renders
- Web dashboard → Positions view: renders
- Web dashboard → Strategy view: renders
- Researcher → Frequency analysis: runs study (evidence: `research/backtest_frequency.py`)
- Researcher → Macro Donchian study: runs study (evidence: `research/backtest_macro_donchian.py`)
- Frequency analysis → Backtest engine: uses replay (evidence: `research/backtest_frequency.py`)
- Macro Donchian study → Backtest engine: uses replay (evidence: `research/backtest_macro_donchian.py`)
- Backtest engine → Historical candles: replays candles
