Skip to content

Your First Project in 10 Minutes (Go)¶

Hands-on Quick Start - Create a working trading project with MetaTrader 4 and GoMT4 from scratch.


Step 0: Obtain Your API Key¶

To connect to MetaRPC endpoints (mt4.mrpc.pro:443), obtain your API key: 1. Register for free at https://mrpc.pro/signup. 2. Generate your API token in your dashboard at https://mrpc.pro/my. 3. Set your token in your environment or connection config.


Step 1: Create Your Project¶

Create a new directory for your trading bot:

mkdir my_gomt4_bot
cd my_gomt4_bot

Install the package:

go get github.com/MetaRPC/GoMT4

Step 2: Write Your Trading Code¶

Create your main application file and paste the following snippet:

import (
    "context"
    "fmt"
    "time"
    mt "github.com/MetaRPC/GoMT4"
)

// Session ID generation on Connect and authentication are handled automatically
client, err := mt.NewMT4AccountWithApiKey(user, password, grpcServer, apiKey)
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)

Step 3: Run the Program¶

Run your application:

# Verify connection output
# Balance: 10000.00, Equity: 10000.00

🚀 Next Steps¶

Congratulations! You have successfully established a direct gRPC connection to MetaTrader 4. Next: - Explore gRPC Streaming to listen to live ticks. - Check the API Reference for all 40+ available terminal methods. - Learn about high-level risk management and auto-normalization in MT4Sugar.