# enarjord/passivbot architecture

> Architecture diagram of the GitHub repository enarjord/passivbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/enarjord/passivbot
- Repository: https://github.com/enarjord/passivbot

## Overview

Passivbot is a cryptocurrency perpetual-futures trading system. A user invokes the CLI with configuration; configuration is loaded and compiled, market data and account state are gathered from exchange adapters, and the shared Rust orchestrator computes entries, re-entries, trailing/grid closes, risk actions, and protective orders. Live execution submits and reconciles orders, while the same orchestration supports backtests and evolutionary optimization. OHLCV, fills, events, and monitoring provide durable analysis. Some live wiring is inferred from documented capabilities and directory structure because sampled excerpts are partial.

Main entry points: [`src/passivbot.py`](https://github.com/enarjord/passivbot/blob/master/src/passivbot.py) (Live Runtime), [`passivbot-rust/src/orchestrator.rs`](https://github.com/enarjord/passivbot/blob/master/passivbot-rust/src/orchestrator.rs) (Rust Order Orchestrator), [`src/exchanges/ccxt_bot.py`](https://github.com/enarjord/passivbot/blob/master/src/exchanges/ccxt_bot.py) (Exchange Adapters), [`src/optimize.py`](https://github.com/enarjord/passivbot/blob/master/src/optimize.py) (Evolutionary Optimizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["Configuration &amp; Strategies"]
  node_cli["CLI Dispatch<br/>[main.py]"]
  node_config["Config Pipeline<br/>[load.py]"]
  node_strategy["Strategy Engine<br/>[mod.rs]"]
  node_orchestrator["Rust Order Orchestrator<br/>[orchestrator.rs]"]
  node_coin_selection["Forager Selection<br/>[coin_selection.rs]"]
end

subgraph group_live["Live Trading"]
  node_live_runtime["Live Runtime<br/>[passivbot.py]"]
  node_market_data["Live Market Data<br/>[market_data.py]"]
  node_executor["Order Executor<br/>[executor.py]"]
  node_reconciler["State Reconciler<br/>[reconciler.py]"]
  node_risk["Risk Controls<br/>[hsl_protection.py]"]
  node_exchange_adapters["Exchange Adapters<br/>[ccxt_bot.py]"]
end

subgraph group_data["Market Data"]
  node_ohlcv["OHLCV Acquisition<br/>[ohlcv_download.py]"]
  node_ohlcv_store[("OHLCV Store<br/>[ohlcv_store.py]")]
  node_fills[("Fill Event Cache")]
end

subgraph group_research["Backtesting &amp; Optimization"]
  node_backtest["Backtest Engine<br/>[backtest.py]"]
  node_dataset["Backtest Datasets"]
  node_optimizer["Evolutionary Optimizer<br/>[optimize.py]"]
  node_gpu_backend["GPU Evaluation<br/>[gpu_backend.py]"]
  node_pareto[("Pareto Results<br/>[pareto_store.py]")]
end

subgraph group_observability["Events &amp; Monitoring"]
  node_events["Live Event Bus<br/>[event_bus.py]"]
  node_monitor["Monitoring Interfaces<br/>[monitor_web.py]"]
  node_event_query["Event Query"]
end

node_user(("Trader"))
node_exchange(("Exchange APIs"))

node_user -->|"invokes"| node_cli
node_cli -->|"loads config"| node_config
node_cli -->|"starts live"| node_live_runtime
node_config -->|"provides inputs"| node_orchestrator
node_orchestrator -->|"computes strategy"| node_strategy
node_orchestrator -->|"selects markets"| node_coin_selection
node_live_runtime -->|"requests data"| node_market_data
node_market_data -->|"fetches streams"| node_exchange_adapters
node_live_runtime -->|"plans orders"| node_orchestrator
node_live_runtime -->|"applies controls"| node_risk
node_live_runtime -->|"dispatches orders"| node_executor
node_executor -->|"submits orders"| node_exchange_adapters
node_reconciler -->|"reads account state"| node_exchange_adapters
node_live_runtime -->|"reconciles state"| node_reconciler
node_exchange_adapters -->|"returns fills"| node_fills
node_live_runtime -->|"emits events"| node_events
node_events -->|"publishes status"| node_monitor
node_event_query -->|"queries events"| node_events
node_ohlcv -->|"downloads candles"| node_exchange_adapters
node_ohlcv -->|"stores candles"| node_ohlcv_store
node_dataset -->|"reads candles"| node_ohlcv_store
node_backtest -->|"loads datasets"| node_dataset
node_backtest -->|"plans orders"| node_orchestrator
node_optimizer -->|"evaluates candidates"| node_backtest
node_optimizer -.->|"accelerates evaluation"| node_gpu_backend
node_optimizer -->|"stores frontiers"| node_pareto

click node_cli "https://github.com/enarjord/passivbot/blob/master/src/passivbot_cli/main.py"
click node_config "https://github.com/enarjord/passivbot/blob/master/src/config/load.py"
click node_strategy "https://github.com/enarjord/passivbot/blob/master/passivbot-rust/src/strategies/mod.rs"
click node_orchestrator "https://github.com/enarjord/passivbot/blob/master/passivbot-rust/src/orchestrator.rs"
click node_coin_selection "https://github.com/enarjord/passivbot/blob/master/passivbot-rust/src/coin_selection.rs"
click node_live_runtime "https://github.com/enarjord/passivbot/blob/master/src/passivbot.py"
click node_market_data "https://github.com/enarjord/passivbot/blob/master/src/live/market_data.py"
click node_executor "https://github.com/enarjord/passivbot/blob/master/src/live/executor.py"
click node_reconciler "https://github.com/enarjord/passivbot/blob/master/src/live/reconciler.py"
click node_risk "https://github.com/enarjord/passivbot/blob/master/src/live/hsl_protection.py"
click node_exchange_adapters "https://github.com/enarjord/passivbot/blob/master/src/exchanges/ccxt_bot.py"
click node_ohlcv "https://github.com/enarjord/passivbot/blob/master/src/ohlcv_download.py"
click node_ohlcv_store "https://github.com/enarjord/passivbot/blob/master/src/ohlcv_store.py"
click node_fills "https://github.com/enarjord/passivbot/blob/master/src/fill_events_manager.py"
click node_backtest "https://github.com/enarjord/passivbot/blob/master/src/backtest.py"
click node_dataset "https://github.com/enarjord/passivbot/blob/master/src/backtest_dataset.py"
click node_optimizer "https://github.com/enarjord/passivbot/blob/master/src/optimize.py"
click node_gpu_backend "https://github.com/enarjord/passivbot/blob/master/src/optimization/backends/gpu_backend.py"
click node_pareto "https://github.com/enarjord/passivbot/blob/master/src/pareto_store.py"
click node_events "https://github.com/enarjord/passivbot/blob/master/src/live/event_bus.py"
click node_monitor "https://github.com/enarjord/passivbot/blob/master/src/monitor_web.py"
click node_event_query "https://github.com/enarjord/passivbot/blob/master/src/tools/live_event_query.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_strategy,node_orchestrator,node_coin_selection toneBlue
class node_live_runtime,node_market_data,node_executor,node_reconciler,node_risk,node_exchange_adapters toneAmber
class node_ohlcv,node_ohlcv_store,node_fills,node_exchange toneMint
class node_backtest,node_dataset,node_optimizer,node_gpu_backend,node_pareto toneRose
class node_events,node_monitor,node_event_query,node_user toneIndigo
```

## Components

### Configuration & Strategies

- [CLI Dispatch](https://github.com/enarjord/passivbot/blob/master/src/passivbot_cli/main.py): `src/passivbot_cli/main.py`
- [Config Pipeline](https://github.com/enarjord/passivbot/blob/master/src/config/load.py): `src/config/load.py`
- [Strategy Engine](https://github.com/enarjord/passivbot/blob/master/passivbot-rust/src/strategies/mod.rs): `passivbot-rust/src/strategies/mod.rs`
- [Rust Order Orchestrator](https://github.com/enarjord/passivbot/blob/master/passivbot-rust/src/orchestrator.rs): `passivbot-rust/src/orchestrator.rs`
- [Forager Selection](https://github.com/enarjord/passivbot/blob/master/passivbot-rust/src/coin_selection.rs): `passivbot-rust/src/coin_selection.rs`

### Live Trading

- [Live Runtime](https://github.com/enarjord/passivbot/blob/master/src/passivbot.py): `src/passivbot.py`
- [Live Market Data](https://github.com/enarjord/passivbot/blob/master/src/live/market_data.py): `src/live/market_data.py`
- [Order Executor](https://github.com/enarjord/passivbot/blob/master/src/live/executor.py): `src/live/executor.py`
- [State Reconciler](https://github.com/enarjord/passivbot/blob/master/src/live/reconciler.py): `src/live/reconciler.py`
- [Risk Controls](https://github.com/enarjord/passivbot/blob/master/src/live/hsl_protection.py): `src/live/hsl_protection.py`
- [Exchange Adapters](https://github.com/enarjord/passivbot/blob/master/src/exchanges/ccxt_bot.py): `src/exchanges/ccxt_bot.py`

### Market Data

- [OHLCV Acquisition](https://github.com/enarjord/passivbot/blob/master/src/ohlcv_download.py): `src/ohlcv_download.py`
- [OHLCV Store](https://github.com/enarjord/passivbot/blob/master/src/ohlcv_store.py): `src/ohlcv_store.py`
- [Fill Event Cache](https://github.com/enarjord/passivbot/blob/master/src/fill_events_manager.py): `src/fill_events_manager.py`

### Backtesting & Optimization

- [Backtest Engine](https://github.com/enarjord/passivbot/blob/master/src/backtest.py): `src/backtest.py`
- [Backtest Datasets](https://github.com/enarjord/passivbot/blob/master/src/backtest_dataset.py): `src/backtest_dataset.py`
- [Evolutionary Optimizer](https://github.com/enarjord/passivbot/blob/master/src/optimize.py): `src/optimize.py`
- [GPU Evaluation](https://github.com/enarjord/passivbot/blob/master/src/optimization/backends/gpu_backend.py): `src/optimization/backends/gpu_backend.py`
- [Pareto Results](https://github.com/enarjord/passivbot/blob/master/src/pareto_store.py): `src/pareto_store.py`

### Events & Monitoring

- [Live Event Bus](https://github.com/enarjord/passivbot/blob/master/src/live/event_bus.py): `src/live/event_bus.py`
- [Monitoring Interfaces](https://github.com/enarjord/passivbot/blob/master/src/monitor_web.py): `src/monitor_web.py`
- [Event Query](https://github.com/enarjord/passivbot/blob/master/src/tools/live_event_query.py): `src/tools/live_event_query.py`

### Other components

- **Trader**
- **Exchange APIs**

## Connections

- Trader → CLI Dispatch: invokes
- CLI Dispatch → Config Pipeline: loads config
- CLI Dispatch → Live Runtime: starts live
- Config Pipeline → Rust Order Orchestrator: provides inputs
- Rust Order Orchestrator → Strategy Engine: computes strategy
- Rust Order Orchestrator → Forager Selection: selects markets
- Live Runtime → Live Market Data: requests data
- Live Market Data → Exchange Adapters: fetches streams
- Live Runtime → Rust Order Orchestrator: plans orders
- Live Runtime → Risk Controls: applies controls
- Live Runtime → Order Executor: dispatches orders
- Order Executor → Exchange Adapters: submits orders
- State Reconciler → Exchange Adapters: reads account state
- Live Runtime → State Reconciler: reconciles state
- Exchange Adapters → Fill Event Cache: returns fills
- Live Runtime → Live Event Bus: emits events
- Live Event Bus → Monitoring Interfaces: publishes status
- Event Query → Live Event Bus: queries events
- OHLCV Acquisition → Exchange Adapters: downloads candles
- OHLCV Acquisition → OHLCV Store: stores candles
- Backtest Datasets → OHLCV Store: reads candles
- Backtest Engine → Backtest Datasets: loads datasets
- Backtest Engine → Rust Order Orchestrator: plans orders
- Evolutionary Optimizer → Backtest Engine: evaluates candidates
- Evolutionary Optimizer → GPU Evaluation: accelerates evaluation
- Evolutionary Optimizer → Pareto Results: stores frontiers
