🛠️ Troubleshooting & FAQ (GoMT4)¶
Short, practical answers. Each item points to real code paths where relevant.
❓ 1) “No quotes / symbol not found (EURUSD)”¶
Symptoms: symbol not found, empty quotes, or RPC returns OK but payload is empty.
Likely causes:
- Broker uses a suffix (e.g.,
EURUSD.m,EURUSD.pro). - Symbol is hidden in MT4 Market Watch.
Fix:
- Open MT4 → Market Watch → Show All → note exact symbol name → put into
examples/config/config.json→DefaultSymbol. - If available, call
EnsureSymbolVisible(symbol)before requests. Otherwise, add one (seeexamples/mt4/MT4Account.go).
💡 Tip: print Digits, Point, LotStep in logs when selecting a symbol.
⏱️ 2) “Timeout / context deadline exceeded” on simple reads¶
Symptoms: context deadline exceeded on read-only calls (quotes, account summary).
Causes:
- MT4 not fully connected or just launched.
- Network latency spikes.
Fix:
- Start MT4 manually once and wait until connected.
- Use per-call timeout (2–5s) and retry only transport errors.
- Reference: 3s health-check with
AccountSummaryinexamples/mt4/MT4Account.go.
🔁 3) “Max retries reached” / frequent reconnects in streams¶
Symptoms: stream stops with error after reconnect attempts; logs mention io.EOF or codes.Unavailable.
Causes:
- Unstable connection; too aggressive backoff; context canceled early.
Fix:
- Increase
backoffMaxorbackoffBase(seeexamples/mt4/MT4Account.go). - Ensure parent
ctxis not canceled prematurely. - Consumer loop: always select on
dataCh,errCh,<-ctx.Done().
🚫 4) “Can’t connect to gRPC: connection refused”¶
Checklist:
- Server running? (
go run ./examples/main.go) - Listening on correct address? (
127.0.0.1:50051default) - Check listener:
netstat -ano | findstr LISTENING | findstr :50051 - Windows Firewall: allow port if bound externally:
New-NetFirewallRule -DisplayName "GoMT4 gRPC" -Direction Inbound -Protocol TCP -LocalPort 50051 -Action Allow
📊 5) “Invalid volume / invalid price” when sending orders¶
Symptoms: invalid volume, invalid price, or broker rejects order.
Causes:
- Volume misaligned with
LotStep. - Price/SL/TP not aligned to
Digits/Pointor too close to market.
Fix:
-
Query symbol params first, then round:
-
volume →
LotStep(clamp toMinLot…MaxLot). - prices → round to
DigitsusingPoint. - Print logs: price,
Digits,Point,LotStep. - Create helper in
examples/mt4/MT4Account.gofor rounding.
💤 6) “Quotes freeze after a while”¶
Symptoms: stream stops emitting data; no errors.
Causes:
- Consumer stopped reading from
dataCh. ctxcanceled elsewhere.
Fix:
- Ensure consumer loop never blocks (use bounded queue/backpressure).
- Always monitor
errChand<-ctx.Done()>.
📦 7) “module … not found / checksum mismatch” (Go modules)¶
Symptoms: during go mod tidy or build.
Fix:
- Ensure pb import path matches module path:
import pb "git.mtapi.io/root/mrpc-proto/mt4/libraries/go"
go get -u git.mtapi.io/root/mrpc-proto/mt4/libraries/go@latest
go mod tidy
go mod vendor + build with -mod=vendor.
🔐 8) “TLS handshake / certificate” issues¶
Fix:
- For local dev, prefer plaintext on
127.0.0.1. - If TLS, use consistent creds:
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ ... })). - Ensure CN/SAN matches host.
📉 9) “No history / partial history returned”¶
Symptoms: history calls return fewer records.
Causes:
- MT4 hasn’t downloaded range yet.
- Request range too large.
Fix:
- Open symbol chart in MT4 to preload.
- Use paging (day-by-day / month-by-month).
🔥 10) “High CPU / goroutine leak”¶
Symptoms: CPU climbs; goroutines accumulate.
Causes:
- Missing
defer cancel(). - Streams not canceled.
- Consumer loop busy-spins.
Fix:
- Always
defer cancel(). - On shutdown: cancel parent
ctx, wait for goroutines, thenDisconnect().
📝 11) Quick reference (commands)¶
- Verify listener:
netstat -ano | findstr LISTENING | findstr :50051
Test-NetConnection -ComputerName 127.0.0.1 -Port 50051
go mod tidy
go get -u git.mtapi.io/root/mrpc-proto/mt4/libraries/go@latest
go mod vendor
go build -mod=vendor ./...
📂 12) Where in code¶
- Retry/backoff & helpers →
examples/mt4/MT4Account.go - Streaming wrappers (ticks/orders/history) →
examples/mt4/MT4Account.go - Entrypoint & cleanup →
examples/main.go - Config shape →
examples/config/config.json