Skip to content

πŸ’± 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.json has a valid DefaultSymbol or 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) by Point.

πŸ”„ Variations

  • Default symbol from config:
sym := cfg.DefaultSymbol
q, _ := account.Quote(ctx, sym)
  • Loop for multiple quotes: see GetMultipleQuotes.md recipe.
  • Subscribe stream: see StreamQuotes.md recipe.

πŸ“Ž See also

  • GetMultipleQuotes.md β€” batch query for multiple symbols.
  • StreamQuotes.md β€” live stream of quotes.
  • SymbolParams.md β€” detailed info about Digits/LotStep/MinLot.