Skip to content

MT4Service — 3. Symbols & Quotes

Symbols, Market Watch, contract params and prices — Symbols unwrapped to a slice, SymbolSelect to a plain bool, the rest returned as typed data.


Symbols(ctx)

func (s *MT4Service) Symbols(ctx context.Context) ([]*pb.SymbolNameInfo, error)

Every symbol the terminal knows, unwrapped to []*pb.SymbolNameInfo (GetSymbolName(), GetSymbolIndex()).

all, _ := svc.Symbols(ctx)
fmt.Println("symbols:", len(all))

SymbolSelect(ctx, symbol, selected)

func (s *MT4Service) SymbolSelect(ctx context.Context, symbol string, selected bool) (bool, error)

Add (selected=true) or remove (false) a symbol in Market Watch. Returns the terminal's success flag directly.

ok, _ := svc.SymbolSelect(ctx, "EURUSD", true)

SymbolParamsMany(ctx, symbols)

func (s *MT4Service) SymbolParamsMany(ctx context.Context, symbols []string) (*pb.SymbolParamsManyData, error)

Full contract params for the given symbols.

Returns: *pb.SymbolParamsManyData → GetSymbolInfos() ([]*SymbolParamsManyInfo): GetDigits(), GetPoint(), GetVolumeMin/Max/Step(), GetTradeTickValue(), GetTradeTickSize(), GetTradeStopsLevel().

d, _ := svc.SymbolParamsMany(ctx, []string{"EURUSD"})
si := d.GetSymbolInfos()[0]
fmt.Printf("digits=%d point=%.5f step=%.2f\n", si.GetDigits(), si.GetPoint(), si.GetVolumeStep())

TickValueWithSize(ctx, symbols)

func (s *MT4Service) TickValueWithSize(ctx context.Context, symbols []string) (*pb.TickValueWithSizeData, error)

Tick value / size / contract size per symbol — the inputs for risk sizing (GetInfos()).

d, _ := svc.TickValueWithSize(ctx, []string{"EURUSD", "GBPUSD"})
fmt.Println("infos:", len(d.GetInfos()))

Quote(ctx, symbol) / QuoteMany(ctx, symbols)

func (s *MT4Service) Quote(ctx context.Context, symbol string) (*pb.QuoteData, error)
func (s *MT4Service) QuoteMany(ctx context.Context, symbols []string) (*pb.QuoteManyData, error)

Latest tick for one symbol, or several at once. QuoteData: GetBid(), GetAsk(), GetHigh(), GetLow(), GetDateTime(). QuoteManyData.GetQuotes() → []*QuoteData.

q, _ := svc.Quote(ctx, "EURUSD")
fmt.Printf("spread %.5f\n", q.GetAsk()-q.GetBid())

QuoteHistory(ctx, symbol, timeframe, from, to)

func (s *MT4Service) QuoteHistory(ctx context.Context, symbol string, timeframe pb.ENUM_QUOTE_HISTORY_TIMEFRAME, from, to time.Time) (*pb.QuoteHistoryData, error)

OHLC bars. timeframe is a pb.ENUM_QUOTE_HISTORY_TIMEFRAME constant (…_QH_PERIOD_H1, …). Returns GetHistoricalQuotes() ([]*HistoryQuote with OHLC).

import (
    "time"
    pb "github.com/MetaRPC/GoMT4/package"
)

now := time.Now()
h, _ := svc.QuoteHistory(ctx, "EURUSD", pb.ENUM_QUOTE_HISTORY_TIMEFRAME_QH_PERIOD_H1, now.Add(-24*time.Hour), now)
fmt.Println("bars:", len(h.GetHistoricalQuotes()))

ServerTimezone(ctx)

func (s *MT4Service) ServerTimezone(ctx context.Context) (*pb.ServerTimezoneData, error)

The broker server's UTC offset — GetServer(), GetUtcOffsetSeconds().

tz, _ := svc.ServerTimezone(ctx)
fmt.Printf("%s UTC%+d\n", tz.GetServer(), tz.GetUtcOffsetSeconds()/3600)

See also: MT4Service — Overview · 4. Trading Operations · MT4Account overview