๐งฐ Using GoMT4 via CLI (No GUI)¶
This section demonstrates how to use GoMT4 directly from the terminal, without any graphical user interface (GUI). Ideal for developers, DevOps, and command-line enthusiasts who prefer full control.
๐ง Requirements¶
| Tool | Purpose |
|---|---|
| Go 1.20+ | For building and running the project |
| MetaTrader 4 | Terminal with gRPC plugin enabled |
config.json |
Login credentials and default symbol |
| Terminal | All operations are executed via command-line |
๐ Project Structure¶
GoMT4/
โโโ examples/ # Example usage and main executable code
โ โโโ config/
โ โ โโโ config.go # Loads configuration from a JSON file
โ โ โโโ config.json # Connection settings: login, password, server, etc.
โ โ
โ โโโ mt4/
โ โ โโโ MT4Account.go # Handles MT4 connection and account-level operations
โ โ โโโ MT4_service.go # Provides service methods for orders, streaming, etc.
โ โ
โ โโโ go.mod # Go module definition for the examples package
โ โโโ go.sum # Dependency checksums
โ โโโ main.go # Entry point demonstrating MT4Service usage
โ
โ
โโโ .gitignore # Files/folders to be excluded from Git
โโโ mkdocs.yml # Documentation config file (for mkdocs or similar tools)
๐งฉ Example config.json¶
{
"Login": 501401178,
"Password": "v8gctta",
"Server": "RoboForex-Demo",
"DefaultSymbol": "EURUSD"
}
๐ Running the App¶
go run main.go
If all goes well, youโll see:
โ Connected to MT4 serverand other output depending on the enabled functions.
๐งช Available Functions¶
๐งพ Account Information¶
| Function | Description |
|---|---|
ShowAccountSummary |
Print balance, equity, and currency |
ShowOpenedOrders |
List current open orders |
ShowOrdersHistory |
View closed trades from last 7 days |
ShowOpenedOrderTickets |
Print open order ticket numbers |
๐ฆ Order Operations¶
| Function | Description |
|---|---|
ShowOrderSendExample("EURUSD") |
Submit a sample Buy order |
ShowOrderModifyExample(ticket) |
Modify SL/TP for a ticket |
ShowOrderCloseExample(ticket) |
Close an order by ticket |
ShowOrderDeleteExample(ticket) |
Delete a pending order |
ShowOrderCloseByExample(t1, t2) |
Close one order with its opposite |
โ ๏ธ Real order execution (even on demo) โ use carefully.
๐ Market Info & Symbols¶
| Function | Description |
|---|---|
ShowQuote("EURUSD") |
Get live bid/ask quote |
ShowQuotesMany([...]) |
Get quotes for multiple symbols |
ShowQuoteHistory("EURUSD") |
Get last 5 days of OHLC candles |
ShowAllSymbols() |
List all available trading instruments |
ShowSymbolParams("EURUSD") |
Get full symbol metadata |
ShowTickValues([...]) |
Get tick/contract values for symbols |
๐ Streaming / Subscriptions¶
| Function | Description |
|---|---|
StreamQuotes() |
Subscribe to live tick updates |
StreamOpenedOrderProfits() |
Real-time profit updates per open order |
StreamOpenedOrderTickets() |
Monitor currently open order tickets |
StreamTradeUpdates() |
Subscribe to all trading events |
StreamOrdersHistoryExample() |
Page-by-page stream of order history (demo; last 30 days, close-time DESC) |
StreamQuoteHistoryExample() |
Time-chunked OHLC history stream (demo; H1, last 90 days, weekly chunks) |
Example output:
[Tick] EURUSD | Bid: 1.09876 | Ask: 1.09889 | Time: 2025-07-29 18:00:01
๐งโ๐ป How to Enable a Function¶
In main.go, uncomment the desired method:
svc.ShowQuote(ctx, "EURUSD")
svc.StreamQuotes(ctx)
You can call multiple methods one after another โ for example, open an order and immediately monitor it.
๐ง Tips¶
- Use
context.WithTimeout(...)to limit long operations. - Stop the MT4 terminal gracefully to avoid lingering gRPC connections.
- Even on demo, actions like sending orders are real.
๐ Quick Example¶
svc.ShowAccountSummary(ctx)
svc.ShowQuote(ctx, "EURUSD")
svc.ShowOrderSendExample(ctx, "EURUSD")
svc.ShowOpenedOrders(ctx)
svc.StreamQuotes(ctx)
This is your terminal-powered trading dashboard โ minimal, fast, and fully controlled by code.