Skip to content

๐Ÿงฐ 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 server and 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.