# codedpro/mt5-trade-split-manager architecture

> Architecture diagram of the GitHub repository codedpro/mt5-trade-split-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codedpro/mt5-trade-split-manager
- Repository: https://github.com/codedpro/mt5-trade-split-manager

## Overview

MT5 Trade Split Manager accepts trading requests through a REST API or optional MCP tools, relays commands over TCP to a MetaTrader 5 Expert Advisor (EA), and returns results. Its principal workflow is request validation and order-split preparation, queued TCP dispatch, then EA-side validation and trade execution. The EA also manages trailing stops, risk controls, recovery, position queries, and safe shutdown. The README documents these EA capabilities, but its source was not excerpted; those feature links are therefore cited to the README rather than inferred from inspected EA code.

Main entry points: [`bulk-add-signals.mq5`](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5) (Expert Advisor), [`server.py`](https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py) (REST API), [`mcp_server.py`](https://github.com/codedpro/mt5-trade-split-manager/blob/main/mcp_server.py) (MCP Tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Request Interfaces"]
  node_rest_api["REST API<br/>[server.py]"]
  node_order_prep["Order Validation<br/>[server.py]"]
end

subgraph group_bridge["TCP Bridge"]
  node_request_queue["Command Queue<br/>[server.py]"]
  node_tcp_server["TCP Server<br/>[server.py]"]
end

subgraph group_trading["MT5 Trading"]
  node_ea["Expert Advisor"]
  node_order_split["Order Splitting"]
  node_trade_execution["Trade Execution"]
  node_trailing["Trailing Stops"]
  node_risk["Risk Controls"]
  node_recovery[("Position Recovery")]
  node_safe_shutdown["Safe Shutdown"]
  node_position_queries["Position Queries"]
end

subgraph group_agent["Agent Integration"]
  node_mcp_tools["MCP Tools<br/>[mcp_server.py]"]
  node_mcp_http["HTTP Adapter<br/>[mcp_server.py]"]
end

node_client(("External Client"))
node_mcp_client(("MCP Client"))
node_mt5["MetaTrader 5"]

node_client -->|"submits requests"| node_rest_api
node_rest_api -->|"validates orders"| node_order_prep
node_rest_api -->|"queues commands"| node_request_queue
node_request_queue -->|"hands off commands"| node_tcp_server
node_tcp_server -->|"sends JSON commands"| node_ea
node_ea -->|"returns responses"| node_tcp_server
node_ea -->|"validates and executes"| node_trade_execution
node_trade_execution -->|"places trades"| node_mt5
node_ea -->|"splits orders"| node_order_split
node_ea -->|"manages stops"| node_trailing
node_ea -->|"checks trading limits"| node_risk
node_ea -->|"persists and rebuilds state"| node_recovery
node_ea -->|"consolidates targets"| node_safe_shutdown
node_ea -->|"serves account queries"| node_position_queries
node_mcp_client -->|"invokes tools"| node_mcp_tools
node_mcp_tools -->|"calls adapter"| node_mcp_http
node_mcp_http -->|"sends HTTP requests"| node_rest_api

click node_rest_api "https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py"
click node_order_prep "https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py"
click node_mcp_tools "https://github.com/codedpro/mt5-trade-split-manager/blob/main/mcp_server.py"
click node_mcp_http "https://github.com/codedpro/mt5-trade-split-manager/blob/main/mcp_server.py"
click node_request_queue "https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py"
click node_tcp_server "https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py"
click node_ea "https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5"
click node_order_split "https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5"
click node_trade_execution "https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5"
click node_trailing "https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5"
click node_risk "https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5"
click node_recovery "https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5"
click node_safe_shutdown "https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5"
click node_position_queries "https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5"

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_rest_api,node_order_prep,node_client,node_mcp_client toneBlue
class node_request_queue,node_tcp_server toneAmber
class node_ea,node_order_split,node_trade_execution,node_trailing,node_risk,node_recovery,node_safe_shutdown,node_position_queries toneMint
class node_mcp_tools,node_mcp_http toneRose
class node_mt5 toneIndigo
```

## Components

### Request Interfaces

- [REST API](https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py): `server.py`
- [Order Validation](https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py): `server.py`

### TCP Bridge

- [Command Queue](https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py): `server.py`
- [TCP Server](https://github.com/codedpro/mt5-trade-split-manager/blob/main/server.py): `server.py`

### MT5 Trading

- [Expert Advisor](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5): `bulk-add-signals.mq5`
- [Order Splitting](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5): `bulk-add-signals.mq5`
- [Trade Execution](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5): `bulk-add-signals.mq5`
- [Trailing Stops](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5): `bulk-add-signals.mq5`
- [Risk Controls](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5): `bulk-add-signals.mq5`
- [Position Recovery](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5): `bulk-add-signals.mq5`
- [Safe Shutdown](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5): `bulk-add-signals.mq5`
- [Position Queries](https://github.com/codedpro/mt5-trade-split-manager/blob/main/bulk-add-signals.mq5): `bulk-add-signals.mq5`

### Agent Integration

- [MCP Tools](https://github.com/codedpro/mt5-trade-split-manager/blob/main/mcp_server.py): `mcp_server.py`
- [HTTP Adapter](https://github.com/codedpro/mt5-trade-split-manager/blob/main/mcp_server.py): `mcp_server.py`

### Other components

- **External Client**
- **MCP Client**
- **MetaTrader 5**

## Connections

- External Client → REST API: submits requests (evidence: `README.md`)
- REST API → Order Validation: validates orders (evidence: `server.py`)
- REST API → Command Queue: queues commands (evidence: `server.py`)
- Command Queue → TCP Server: hands off commands (evidence: `server.py`)
- TCP Server → Expert Advisor: sends JSON commands (evidence: `README.md`)
- Expert Advisor → TCP Server: returns responses (evidence: `README.md`)
- Expert Advisor → Trade Execution: validates and executes (evidence: `README.md`)
- Trade Execution → MetaTrader 5: places trades (evidence: `README.md`)
- Expert Advisor → Order Splitting: splits orders (evidence: `README.md`)
- Expert Advisor → Trailing Stops: manages stops (evidence: `README.md`)
- Expert Advisor → Risk Controls: checks trading limits (evidence: `README.md`)
- Expert Advisor → Position Recovery: persists and rebuilds state (evidence: `README.md`)
- Expert Advisor → Safe Shutdown: consolidates targets (evidence: `README.md`)
- Expert Advisor → Position Queries: serves account queries (evidence: `README.md`)
- MCP Client → MCP Tools: invokes tools (evidence: `mcp_server.py`)
- MCP Tools → HTTP Adapter: calls adapter (evidence: `mcp_server.py`)
- HTTP Adapter → REST API: sends HTTP requests (evidence: `mcp_server.py`)
