Skip to content

Getting Started with GoMT4ΒΆ

Quick Setup & Overview - Start automating your trading with GoMT4 (Go for MetaTrader 4) in minutes.


🎯 What is GoMT4?¢

GoMT4 is an industrial-grade, type-safe Go client library for interacting with MetaTrader 4 terminals via high-performance gRPC. It eliminates complex C++ DLL wrappers and provides direct, reliable programmatic trading.

🌟 Key Advantages¢

  • πŸš€ High Throughput: Native gRPC streaming for sub-millisecond price ticks and trade execution.
  • πŸ›‘οΈ Three-Layer Architecture: Low-level gRPC (MT4Account), typed wrapper methods (MT4Service), and high-level convenience (MT4Sugar).
  • πŸ”„ Resilient Connection: Auto-reconnect, exponential backoff, and transparent channel healing.
  • πŸ’Ό Production Ready: Fully verified across institutional accounts, hedge fund systems, and automated retail bots.

πŸ“¦ InstallationΒΆ

Install GoMT4 via your standard Go package manager:

go get github.com/MetaRPC/GoMT4

πŸ”‘ API Key & AuthenticationΒΆ

Connecting to MetaRPC production endpoints (mt4.mrpc.pro:443) requires an API key:

  1. Sign Up: Create an account for free at https://mrpc.pro/signup.
  2. Generate API Key: In your MetaRPC Portal dashboard at https://mrpc.pro/my, go to API Keys to generate and copy your personal API token.
  3. Configure Connection: Pass your API key / token along with the server address (mt4.mrpc.pro:443) in your connection settings.


πŸ†” Automatic Account ID & AuthenticationΒΆ

MetaRPC endpoints require authentication and session management: 1. APIKey: Your personal authentication token from https://mrpc.pro/my (obtained by registering at https://mrpc.pro/signup). Sent in the APIKey header. 2. id: A terminal session GUID returned by Connect / ConnectEx (terminalInstanceGuid).

πŸ’‘ Seamless Automation: You do not need to call GetId or provide an id header when connecting. The server automatically generates a session GUID upon connection and returns it to the caller. The SDK automatically captures this session ID and attaches it alongside your APIKey to all subsequent requests and streaming subscriptions.

πŸ”Œ Minimal Connection ExampleΒΆ

Here is how easy it is to initialize MT4Account, connect to your MetaTrader terminal, and retrieve your account balance:

client, err := mt.NewMT4Account(user, password, grpcServer)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
err = client.ConnectByServerName(ctx, serverName, "EURUSD")
summary, err := client.AccountSummary(ctx)
fmt.Printf("Balance: %.2f, Equity: %.2f\n", summary.Balance, summary.Equity)

πŸ—ΊοΈ Documentation Road MapΒΆ

To get the most out of GoMT4, follow this suggested reading order:

  1. πŸš€ Your First Project - Build and run a working project in 10 minutes.
  2. πŸ—ΊοΈ Project Map - Understand the 3 architectural layers and interaction flow.
  3. πŸ“– Glossary - Essential MetaTrader 4 and algorithmic trading terminology.
  4. 🐣 MT4 for Beginners - Step-by-step terminal setup and demo account guide.
  5. πŸ“‘ gRPC Streaming - Subscribe to ticks, trades, DOM, and position updates.
  6. πŸ“Š Return Codes - Complete reference of broker and gateway return codes.