# fabioo29/telegram-trading-bot architecture

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

- Interactive diagram: https://gitdiagram.com/fabioo29/telegram-trading-bot
- Repository: https://github.com/fabioo29/telegram-trading-bot

## Overview

##### Project type and purpose
- This is a MetaTrader 5 Expert Advisor (EA) written in MQL5 that connects to the Telegram Bot API.
- Purpose: allow a trader to send simple Telegram commands on their mobile device to open, modify, close, or alert on Forex trades via MetaTrader.

##### File structure
- Top-level:
- trader-bot.mq5           → main EA source
- assets/                  → images/documentation (mockups)
- /                 → reusable modules
– Comment.mqh            → helper for formatted output/logging
– Common.mqh             → shared constants, utility functions
– Telegram.mqh           → wrapper around HTTP requests to Telegram API
– jason.mqh              → JSON parsing/serialization
- No separate frontend/backend folders; EA code runs inside MetaTrader’s runtime.
- No build scripts beyond MetaEditor compile; deployment is loading the compiled .ex5 into the terminal.

##### README for additional insights
- Describes setup steps inside MetaEditor/MetaTrader and Telegram URL whitelisting.
- Enumerates all bot commands (buy/sell, list, alerts, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef internal fill:#D0E6FF,stroke:#4A90E2;
    classDef external fill:#D0F5D0,stroke:#3CB043;

    tgApp["Trader's Telegram App"]:::external
    tgApp -->|"HTTPS GET/POST"| extAPI["Telegram Bot API"]:::external
    extAPI -->|"send/receive messages"| TC["Telegram Client Module"]:::internal

    subgraph "MetaTrader Terminal"
        subgraph "Expert Advisor (EA)"
            CMD["Command Handler"]:::internal
            TM["Trade Manager"]:::internal
            AL["Alert Scheduler"]:::internal
            TC
            JP["JSON Parser/Serializer"]:::internal
            LG["Logging & Output Helper"]:::internal
            CM["Shared Constants & Utilities"]:::internal
        end
    end

    TC -->|"parse/serialize JSON"| JP
    CMD -->|"routes commands"| TM
    CMD -->|"schedules alerts"| AL
    CMD -->|"uses logging"| LG
    CMD -->|"uses constants/utilities"| CM
    CMD -->|"JSON parse/serialize"| JP

    TM -->|"OrderSend/OrderModify"| extBroker["Broker & Market Data"]:::external
    extBroker -->|"Market data callback"| CMD
    AL -->|"OnTimer events"| CMD

    extAPI -.->|whitelist setup in| README["Project Documentation (README.md)"]:::external
    assets["Assets (mockups, images)"]:::external

    click CMD "https://github.com/fabioo29/telegram-trading-bot/blob/main/trader-bot.mq5"
    click TM "https://github.com/fabioo29/telegram-trading-bot/blob/main/trader-bot.mq5"
    click AL "https://github.com/fabioo29/telegram-trading-bot/blob/main/trader-bot.mq5"
    click TC "https://github.com/fabioo29/telegram-trading-bot/blob/main/include/Telegram.mqh"
    click JP "https://github.com/fabioo29/telegram-trading-bot/blob/main/include/jason.mqh"
    click LG "https://github.com/fabioo29/telegram-trading-bot/blob/main/include/Comment.mqh"
    click CM "https://github.com/fabioo29/telegram-trading-bot/blob/main/include/Common.mqh"
    click assets "https://github.com/fabioo29/telegram-trading-bot/tree/main/assets/"
    click README "https://github.com/fabioo29/telegram-trading-bot/blob/main/README.md"
```
