π± GetQuote (GoMT4)¶
Goal: fetch the latest quote (Bid/Ask/Spread) for a symbol.
Real code refs:
- Account methods:
examples/mt4/MT4Account.go(Quote)- Example:
examples/mt4/MT4_service.go(ShowQuote)
β 1) Preconditions¶
- Symbol exists and is visible in MT4 (Market Watch β Show All).
config.jsonhas a validDefaultSymbolor you specify a symbol manually.
π 2) Request one quote¶
q, err := account.Quote(ctx, symbol)
if err != nil { return err }
fmt.Printf("%s: Bid=%.5f Ask=%.5f Spread=%.1f pips Time=%s\n",
symbol,
q.GetBid(),
q.GetAsk(),
(q.GetAsk()-q.GetBid())/q.GetPoint(),
q.GetTime().AsTime().Format(time.RFC3339))
π 3) Inspect fields¶
q (*pb.Quote) contains:
Bidβ brokerβs buy price.Askβ brokerβs sell price.Pointβ 10^-Digits (used to compute spread in points/pips).Digitsβ precision for price rounding.Timeβ server timestamp.
β οΈ Pitfalls¶
- symbol not found β check suffix (
EURUSD.m, etc.) or ensure visible in MT4. - timeout β wrap in
context.WithTimeout(2β3s) and retry on transient errors only. - spread mismatch β some brokers quote in fractional pips; always divide
(Ask-Bid)byPoint.
π Variations¶
- Default symbol from config:
sym := cfg.DefaultSymbol
q, _ := account.Quote(ctx, sym)
- Loop for multiple quotes: see
GetMultipleQuotes.mdrecipe. - Subscribe stream: see
StreamQuotes.mdrecipe.
π See also¶
GetMultipleQuotes.mdβ batch query for multiple symbols.StreamQuotes.mdβ live stream of quotes.SymbolParams.mdβ detailed info about Digits/LotStep/MinLot.