Skip to content

GoMT4 The documentary BASE


πŸ“‘ Table of Contents

πŸ“Š Account

πŸ“ˆ Market Info

πŸ“¦ Orders

πŸ”§ Reliability & Connection

🧰 Utils & Helpers


✨ Introduction

What is GoMT4? A small, pragmatic bridge between MT4 Terminal and your Go code via gRPC.

Who is it for? Beginners , algo developers, ops teams who need a scriptable MT4 integration.

After reading you can:

  • Run a local demo.
  • Connect to MT4.
  • Subscribe to quotes.
  • Place & close an order safely.

Quick links: πŸ‘‰ Your Easy Start Β· πŸ‘‰ Beginner Run Guide Β· πŸ‘‰ CLI Usage


βš™οΈ Setup & Environment

Goal: Run everything on Windows with MT4 installed.

Prerequisites

  • Windows 10/11, MT4 Terminal.
  • Go β‰₯ 1.21.
  • (Optional) VS Code + Go extension.

Install (draft)

  1. Clone the repo, run go mod tidy in examples/.
  2. Configure credentials (see Config Example).
  3. Open in VS Code and launch the debug profile.

πŸ—οΈ Architecture & Data Flow

Make the system non-magical:

  • πŸ’» MT4 Terminal ⇄ GoMT4 gRPC server ⇄ πŸ§‘β€πŸ’» client code.
  • Lifecycles: connect β†’ use β†’ disconnect.
  • Streams: Quotes, Orders; buffering & backpressure.
  • Where retries/backoff kick in.

See details: Architecture & Data Flow


πŸ”’ Reliability: Timeouts, Reconnects, Backoff

  • context.WithTimeout for unary calls (2–5s baseline).
  • Treat io.EOF as transient on streams; reconnect with jitter.
  • Ensure cancelation closes goroutines.
  • Don’t leak streams; add health checks.

See recipes:


πŸ› οΈ Troubleshooting & FAQ

  • β€œSymbol not found EURUSD” β†’ Try broker suffix EURUSD.m.
  • β€œInvalid volume” β†’ Respect LotStep/LotMin and round.
  • β€œDigits mismatch” β†’ Format prices using Digits.
  • β€œNo connection” β†’ Firewall/UAC, terminal path, server reachability.

Full page: Troubleshooting & FAQ


πŸ“š Cookbook (Recipes)

Jump into ready-made snippets:

Full list: Cookbook index


πŸ–₯️ CLI Usage (Playground)

  • Subscribe to quotes
  • Dump symbol params
  • Close orders by filter

See: CLI Usage


πŸ“– API Reference (Types & Enums)

Autogenerated types index with human-readable notes, units, ranges, and gotchas ⚠️.


⚑ Performance Notes

  • Batch calls when possible
  • Avoid per-tick RPCs
  • Track expected latencies
  • Simple load test plan

Performance Notes


πŸ”‘ Security & Secrets

  • .env handling (do not commit secrets)
  • Windows credentials vault tips

Security & Secrets


πŸ“Š Observability (Logs & Metrics)

  • Log format and levels
  • Metrics: latency, reconnects, dropped ticks

Observability


πŸ“˜ Glossary (MT4 Terms)

  • Digits, Point, TickSize, TickValue, Lot, ContractSize
  • Hedging vs Netting (MT5 nuances)

Glossary

πŸ“Š Whoosh-and-it-works: get a quote, open an order, subscribe to ticks.

Quick start: Get one quote (Go)
// examples/mt4/MT4_service.go has ShowQuote(ctx, symbol string)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

price, err := svc.ShowQuote(ctx, "EURUSD")
if err != nil {
    log.Fatalf("quote error: %v", err)
}
fmt.Printf("EURUSD  Bid: %.5f  Ask: %.5f  Time: %s\n",
    price.Bid, price.Ask, price.Time.Format(time.RFC3339))
Place market order safely (uses rounding & symbol params)
// See Cookbook/Orders/PlaceMarketOrder.md and ShowOrderSendExample in MT4_service.go
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

ticket, err := svc.ShowOrderSendExample(ctx, "EURUSD")
if err != nil {
    log.Fatalf("order send failed: %v", err)
}
fmt.Println("βœ… Order ticket:", ticket)
Stream live quotes (local terminal)
// Based on StreamQuotes in MT4_service.go
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

updates, errCh := svc.StreamQuotes(ctx, []string{"EURUSD","GBPUSD"})
for {
    select {
    case q := <-updates:
        fmt.Printf("[Tick] %s  Bid: %.5f  Ask: %.5f\n", q.Symbol, q.Bid, q.Ask)
    case err := <-errCh:
        log.Printf("stream error: %v (reconnect logic in cookbook)", err)
        return
    }
}