Symbols¶
The list of instruments the server exposes โ names and indices.
API Information:
- Low-level API:
MT4Account.Symbols(ctx)(defined inmt4/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 useSymbolParams. - 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.
symbolExistsreturns true for a known symbol, false for a bogus one. - Prefix. Filtering by a common prefix returns a non-empty subset.
๐ See also¶
- SymbolSelect ยท SymbolParamsMany ยท Quote
- Back to: 3. Symbols & Quotes โ Overview ยท MT4Account โ Overview