# tharitthaveekittikul/ea-trader architecture

> Architecture diagram of the GitHub repository tharitthaveekittikul/ea-trader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tharitthaveekittikul/ea-trader
- Repository: https://github.com/tharitthaveekittikul/ea-trader

## Overview

##### Main Components
- Main Entry Point (main.py): This is where the program’s execution starts and where overall coordination takes place.
- Trading Module (trading.py): This module is responsible for interacting directly with the MetaTrader 5 terminal, sending trade orders, and handling account communications.
- Strategy Module (strategy.py): Contains the trading strategy logic and decisions based on market data.
- Utilities (utils.py): Provides helper functions to support common operations across the application.
- Configuration (config.py – as referenced in the README): Although it isn’t explicitly in the file tree, it is critical for setting up the MT5 account credentials, symbol settings, and trade parameters.
- External Dependencies and Libraries:
- MetaTrader5: For communicating with the MT5 terminal.
- pandas, pytz, and ta: For data processing, timezone handling, and technical analysis which influence the strategy module.
- External System (MetaTrader 5 Terminal): Represent this as an external component, as the bot communicates with it using the MetaTrader5 API.

##### Structural Relationships and Interactions
- The Main Component (main.py) should be depicted at the top, coordinating application startup.
- Initialization of configuration settings (from config.py) that feed into both trading and strategy modules.
- Invocation of the Strategy Module (strategy.py) to determine trading signals.
- Use of the Trading Module (trading.py) to send orders/commands, relying on the established configuration.
- The Utilities Module (utils.py) should have directional links to both the strategy and trading components, providing supporting functions.

##### Architectural Patterns and Design Principles
- Modularity: Each major concern (configuration, trading, strategy, and utilities) is separated into its own module for single-responsibility.
- External API integration: Highlight how the trading module encapsulates all MetaTrader 5 communications.
- Data Flow: Emphasize the sequential processing – configuration is loaded, a strategy is computed, and then trading actions are executed.

##### Relevant Technologies, Frameworks, and Libraries
- Python 3.x is the core language.
- Specific libraries shown in requirements.txt (MetaTrader5, pandas, pytz, ta) which should be visually grouped with an “External Dependencies” label.
- (Optional) Although not present, configuration management (config.py) can be represented as a distinct component.

##### Detail and Clarity
- Avoid overly combining modules; instead, separate them clearly (even if some contain only a few lines of code) to allow an understanding of the system’s overall modular architecture.
- Finally, include annotations that explain key design decisions, such as why the trading decisions are isolated into one module or how the configuration settings govern the behavior of multiple modules.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Internal Modules
    subgraph "Internal Modules"
        Main["Main Application (main.py)"]:::internal
        Config["Configuration (config.py)"]:::internal
        Strategy["Strategy Module (strategy.py)"]:::internal
        Trading["Trading Module (trading.py)"]:::internal
        Utils["Util Functions (utils.py)"]:::internal
    end

    %% External Component
    MT5["MetaTrader 5 Terminal"]:::external

    %% Relationships
    Main -->|"initializes"| Config
    Main -->|"invokesStrategy"| Strategy
    Main -->|"executesTrading"| Trading
    Config -->|"configures"| Strategy
    Config -->|"configures"| Trading
    Strategy -->|"tradingSignal"| Trading
    Strategy -->|"uses"| Utils
    Trading -->|"uses"| Utils
    Trading -->|"sendsOrder"| MT5
    MT5 -->|"providesMarketData"| Trading

    %% Click Events
    click Main "https://github.com/tharitthaveekittikul/ea-trader/blob/main/main.py"
    click Strategy "https://github.com/tharitthaveekittikul/ea-trader/blob/main/strategy.py"
    click Trading "https://github.com/tharitthaveekittikul/ea-trader/blob/main/trading.py"
    click Utils "https://github.com/tharitthaveekittikul/ea-trader/blob/main/utils.py"

    %% Styles
    classDef internal fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef external fill:#F5B041,stroke:#B03A2E,stroke-width:2px;
```
