Skip to content

Symbols

The list of instruments the server exposes โ€” names and indices.

API Information:

  • Low-level API: MT4Account.Symbols(ctx) (defined in mt4/MT4Account.go)
  • gRPC service: mt4_term_api.MarketInfo
  • RPC: Symbols(SymbolsRequest) โ†’ SymbolsReply
  • Payload: SymbolsData โ†’ GetSymbolNameInfos() โ†’ SymbolNameInfo

๐Ÿ’ฌ Just the essentials

  • What it is. The catalog of tradable symbol names (with their indices).
  • Why you need it. Discover/validate symbol names before quoting or trading.
  • When to use. Startup discovery, building pickers, validating config.

๐ŸŽฏ Purpose

  • Enumerate all available symbols
  • Validate a configured symbol exists
  • Build a symbol picker / autocomplete

Method Signature

func (a *MT4Account) Symbols(ctx context.Context) (*pb.SymbolsData, error)

Request message:

message SymbolsRequest {}   // no arguments

Payload message:

message SymbolsData { repeated SymbolNameInfo symbol_name_infos = 1; }

message SymbolNameInfo {
  string symbol_name = 1;
  int32  symbol_index = 2;
}

๐Ÿ”ฝ Input

Parameter Type Required Description
ctx context.Context yes Cancellation / timeout. The call takes no other arguments.

โฌ†๏ธ Output โ€” *pb.SymbolsData

GetSymbolNameInfos() returns []*pb.SymbolNameInfo:

Field Proto Type Go getter Description
symbol_name string GetSymbolName() string Symbol, e.g. "EURUSD"
symbol_index int32 GetSymbolIndex() int32 Server-side index

On failure the call returns a non-nil error (text "API error (code=โ€ฆ): โ€ฆ") โ€” see the Return Codes Reference.


๐Ÿงฉ Notes & Tips

  • Names, not prices. For prices use Quote / QuoteMany; for contract specs use SymbolParams.
  • Add to Market Watch before trading a discovered symbol with SymbolSelect.
  • Large lists โ€” brokers may expose hundreds of symbols.

๐Ÿ”— Usage Examples

1) Count and print the first few

func listSymbols(ctx context.Context, acc *mt4.MT4Account) error {
    d, err := acc.Symbols(ctx)
    if err != nil { return err }
    all := d.GetSymbolNameInfos()
    fmt.Printf("%d symbols\n", len(all))
    for i, s := range all {
        if i >= 10 { break }
        fmt.Println(" -", s.GetSymbolName())
    }
    return nil
}

2) Validate a configured symbol exists

func symbolExists(ctx context.Context, acc *mt4.MT4Account, want string) (bool, error) {
    d, err := acc.Symbols(ctx)
    if err != nil { return false, err }
    for _, s := range d.GetSymbolNameInfos() {
        if s.GetSymbolName() == want { return true, nil }
    }
    return false, nil
}

3) Filter by prefix (e.g. all USD crosses)

func withPrefix(ctx context.Context, acc *mt4.MT4Account, prefix string) ([]string, error) {
    d, err := acc.Symbols(ctx)
    if err != nil { return nil, err }
    var out []string
    for _, s := range d.GetSymbolNameInfos() {
        if strings.HasPrefix(s.GetSymbolName(), prefix) {
            out = append(out, s.GetSymbolName())
        }
    }
    return out, nil
}

โš ๏ธ Pitfalls

  • Suffixes vary. Brokers may use EURUSD, EURUSD.m, EURUSDpro, etc. โ€” validate rather than assume.
  • Not all are tradable at all times (sessions/holidays).

๐Ÿงช Testing Suggestions

  • Happy path (demo). len(GetSymbolNameInfos()) > 0; your base symbol is present.
  • Validate. symbolExists returns true for a known symbol, false for a bogus one.
  • Prefix. Filtering by a common prefix returns a non-empty subset.

๐Ÿ“š See also