# erfaniaa/crypto-trading-strategy-backtester architecture

> Architecture diagram of the GitHub repository erfaniaa/crypto-trading-strategy-backtester, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/erfaniaa/crypto-trading-strategy-backtester
- Repository: https://github.com/erfaniaa/crypto-trading-strategy-backtester

## Overview

This is a configurable cryptocurrency strategy backtester. The user runs `main.py`, which initializes the backtester from `config.py`; it obtains candle history, iterates market data to open and close long/short positions, then produces statistical reports, plots, position exports, and train/test datasets. The README also documents cached data for offline reuse and interactive position charts. The sampled excerpts show the main execution and several output calls; other connections rely on the SOURCE INDEX or README, so uncertain links are omitted.

Main entry points: [`backtester.py`](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.py) (Backtest engine), [`main.py`](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/main.py) (Run entry point), [`binance_api.py`](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/binance_api.py) (Binance candle API), [`plot_maker.py`](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/plot_maker.py) (Plots and charts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Run and configuration"]
  node_main["Run entry point<br/>[main.py]"]
  node_config["Strategy settings<br/>[config.py]"]
end

subgraph group_market["Market data"]
  node_exchange["Binance candle API<br/>[binance_api.py]"]
  node_candle["Candle model<br/>[candle.py]"]
  node_utils["Timeframe utilities<br/>[utils.py]"]
  node_cache["Offline candle cache<br/>[backtester.py]"]
end

subgraph group_simulation["Backtest simulation"]
  node_engine["Backtest engine<br/>[backtester.py]"]
  node_indicators["Indicator calculations<br/>[indicators.py]"]
  node_position["Position model<br/>[position.py]"]
  node_position_result["Position result data"]
end

subgraph group_outputs["Analysis and outputs"]
  node_statistics["Candle statistics<br/>[backtester.py]"]
  node_reports["Reports and exports<br/>[report_maker.py]"]
  node_datasets["Research datasets<br/>[backtester.py]"]
  node_plotting["Plots and charts<br/>[plot_maker.py]"]
end

node_user(("User"))
node_binance["Binance"]
node_interactive_chart["Interactive chart library"]

node_user -->|"runs"| node_main
node_main -->|"reads settings"| node_config
node_main -->|"starts backtest"| node_engine
node_engine -->|"uses settings"| node_config
node_engine -->|"requests candles"| node_exchange
node_exchange -->|"fetches history"| node_binance
node_exchange -->|"creates candles"| node_candle
node_engine -->|"processes candles"| node_candle
node_engine -->|"uses timeframes"| node_utils
node_engine -->|"calculates indicators"| node_indicators
node_engine -->|"opens positions"| node_position
node_engine -->|"builds result data"| node_position_result
node_engine -->|"collects statistics"| node_statistics
node_engine -->|"generates reports"| node_reports
node_engine -->|"generates datasets"| node_datasets
node_engine -->|"renders plots"| node_plotting
node_plotting -.->|"supports charting"| node_interactive_chart
node_engine -.->|"reuses saved data"| node_cache

click node_main "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/main.py"
click node_config "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/config.py"
click node_engine "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.py"
click node_exchange "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/binance_api.py"
click node_candle "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/candle.py"
click node_indicators "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/indicators.py"
click node_position "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/position.py"
click node_position_result "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/position_result_and_candles.py"
click node_utils "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/utils.py"
click node_statistics "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.py"
click node_reports "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/report_maker.py"
click node_datasets "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.py"
click node_plotting "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/plot_maker.py"
click node_cache "https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.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_main,node_config,node_user toneBlue
class node_exchange,node_candle,node_utils,node_cache toneAmber
class node_engine,node_indicators,node_position,node_position_result toneMint
class node_statistics,node_reports,node_datasets,node_plotting toneRose
class node_binance,node_interactive_chart toneIndigo
```

## Components

### Run and configuration

- [Run entry point](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/main.py): `main.py`
- [Strategy settings](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/config.py): `config.py`

### Market data

- [Binance candle API](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/binance_api.py): `binance_api.py`
- [Candle model](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/candle.py): `candle.py`
- [Timeframe utilities](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/utils.py): `utils.py`
- [Offline candle cache](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.py): `backtester.py`

### Backtest simulation

- [Backtest engine](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.py): `backtester.py`
- [Indicator calculations](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/indicators.py): `indicators.py`
- [Position model](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/position.py): `position.py`
- [Position result data](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/position_result_and_candles.py): `position_result_and_candles.py`

### Analysis and outputs

- [Candle statistics](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.py): `backtester.py`
- [Reports and exports](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/report_maker.py): `report_maker.py`
- [Research datasets](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/backtester.py): `backtester.py`
- [Plots and charts](https://github.com/erfaniaa/crypto-trading-strategy-backtester/blob/main/plot_maker.py): `plot_maker.py`

### Other components

- **User**
- **Binance**
- **Interactive chart library**

## Connections

- User → Run entry point: runs (evidence: `README.md`)
- Run entry point → Strategy settings: reads settings (evidence: `main.py`)
- Run entry point → Backtest engine: starts backtest (evidence: `main.py`)
- Backtest engine → Strategy settings: uses settings (evidence: `backtester.py`)
- Backtest engine → Binance candle API: requests candles (evidence: `backtester.py`)
- Binance candle API → Binance: fetches history (evidence: `binance_api.py`)
- Binance candle API → Candle model: creates candles (evidence: `binance_api.py`)
- Backtest engine → Candle model: processes candles (evidence: `backtester.py`)
- Backtest engine → Timeframe utilities: uses timeframes (evidence: `backtester.py`)
- Backtest engine → Indicator calculations: calculates indicators (evidence: `backtester.py`)
- Backtest engine → Position model: opens positions (evidence: `backtester.py`)
- Backtest engine → Position result data: builds result data (evidence: `backtester.py`)
- Backtest engine → Candle statistics: collects statistics (evidence: `backtester.py`)
- Backtest engine → Reports and exports: generates reports (evidence: `backtester.py`)
- Backtest engine → Research datasets: generates datasets (evidence: `README.md`)
- Backtest engine → Plots and charts: renders plots (evidence: `backtester.py`)
- Plots and charts → Interactive chart library: supports charting (evidence: `README.md`)
- Backtest engine → Offline candle cache: reuses saved data (evidence: `README.md`)
