GoMT4 The documentary BASE¶
-
Getting Started --- First launch, environment, shortcut.
Your Easy Start Setup -
Architecture --- How everything works, data flows, timeouts, and reconnects.
Architecture Reliability -
Market Info --- Quotes, symbol parameters, history.
ShowQuote QuotesMany -
Orders --- Opening/modification/closing, examples.
Place Market Modify -
Streaming --- Ticks, order updates, flow history.
Stream Quotes Order Profits -
Cookbook --- Recipes from real code.
All Recipes -
API Reference --- Types, messages, and streams from .proto.
Enums Streaming -
Ops --- Performance, secrets, logging.
Performance Security
π Table of Contents¶
π Account
π Market Info
π¦ Orders
- π Place Market Order
- π Place Pending Order
- βοΈ Modify Order
- β Close Order
- π Close By Orders
- ποΈ Delete Pending
- π History 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)¶
- Clone the repo, run
go mod tidyinexamples/. - Configure credentials (see Config Example).
- 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.WithTimeoutfor unary calls (2β5s baseline).- Treat
io.EOFas 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/LotMinand 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:
- π Watchlist & Quotes β Get Quote, Multiple Quotes, Stream
- π Place Order Safely β Place Market / Pending / Modify / Close
- πΉ Compute PnL Correctly β Symbol Params
- ποΈ Stream History to DB β History Orders
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
π Security & Secrets¶
.envhandling (do not commit secrets)- Windows credentials vault tips
π Observability (Logs & Metrics)¶
- Log format and levels
- Metrics: latency, reconnects, dropped ticks
π Glossary (MT4 Terms)¶
- Digits, Point, TickSize, TickValue, Lot, ContractSize
- Hedging vs Netting (MT5 nuances)
π 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
}
}