SymbolParams (RECOMMENDED)¶
One symbol's contract spec โ point, digits, volume step/limits, tick value/size, stops level.
API Information:
- Low-level API:
MT4Account.SymbolParams(ctx, symbol)(defined inmt4/MT4Account.go) - Built on:
SymbolParamsMany(mt4_term_api.AccountHelper) โ it requests the one symbol and returns the first info. - Payload:
SymbolParamsManyInfo
๐ฌ Just the essentials¶
- What it is. The trading rules for a symbol โ everything you need to normalize volume/price and size risk.
- Why you need it. Avoid invalid-volume (131) / invalid-stops (130) rejections.
- When to use. Before sizing a lot, rounding a price, or setting SL/TP.
๐ฏ Purpose¶
- Read
PointandDigitsfor pip math and price rounding - Read
VolumeMin/VolumeMax/VolumeStepfor lot normalization - Read
TradeTickValue/TradeTickSizefor risk sizing - Read
TradeStopsLevelfor minimum SL/TP distance
Method Signature¶
func (a *MT4Account) SymbolParams(ctx context.Context, symbol string) (*pb.SymbolParamsManyInfo, error)
How it works: it calls SymbolParamsMany with a single-element list and returns GetSymbolInfos()[0].
Payload message (excerpt):
message SymbolParamsManyInfo {
string symbol_name = ...;
int32 digits = ...;
double point = ...;
double volume_min = ...; double volume_max = ...; double volume_step = ...;
double trade_tick_value = ...; double trade_tick_size = ...;
int32 trade_stops_level = ...;
double trade_contract_size = ...;
string currency_base = ...; string currency_profit = ...;
double bid = ...; double ask = ...;
bool spread_float = ...;
}
๐ฝ Input¶
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context |
yes | Cancellation / timeout. |
symbol |
string |
yes | Instrument, e.g. "EURUSD". |
โฌ๏ธ Output โ *pb.SymbolParamsManyInfo¶
| Field | Proto Type | Go getter | Description |
|---|---|---|---|
symbol_name |
string | GetSymbolName() string |
Symbol |
digits |
int32 | GetDigits() int32 |
Price decimal places |
point |
double | GetPoint() float64 |
Point size |
volume_min / volume_max |
double | GetVolumeMin() / GetVolumeMax() |
Lot limits |
volume_step |
double | GetVolumeStep() float64 |
Lot increment |
trade_tick_value |
double | GetTradeTickValue() float64 |
Money value of one tick per lot |
trade_tick_size |
double | GetTradeTickSize() float64 |
Price size of one tick |
trade_stops_level |
int32 | GetTradeStopsLevel() int32 |
Min SL/TP distance (points) |
trade_contract_size |
double | GetTradeContractSize() float64 |
Contract size |
currency_base / currency_profit |
string | GetCurrencyBase() / GetCurrencyProfit() |
Currencies |
bid / ask |
double | GetBid() / GetAsk() |
Last known prices |
spread_float |
bool | GetSpreadFloat() bool |
Floating vs fixed spread |
On failure the call returns a non-nil
error(text"API error (code=โฆ): โฆ") โ see the Return Codes Reference.
๐งฉ Notes & Tips¶
- Pip size =
GetPoint()ร 10 on 3/5-digit symbols, elseGetPoint(). - Normalize volume to
GetVolumeStep()and clamp to[VolumeMin, VolumeMax]โ or the broker rejects it (131). - Pip value per lot โ
GetTradeTickValue() ร (pip / GetTradeTickSize())โ the basis of risk sizing. - Respect
GetTradeStopsLevel()when placing SL/TP (130 otherwise). - The high-level
MT4Sugarwraps all of this.
๐ Usage Examples¶
1) Print the trading rules¶
func rules(ctx context.Context, acc *mt4.MT4Account, symbol string) error {
p, err := acc.SymbolParams(ctx, symbol)
if err != nil { return err }
fmt.Printf("%s digits=%d point=%.5f vol[%.2f..%.2f step %.2f] stopsLvl=%d\n",
p.GetSymbolName(), p.GetDigits(), p.GetPoint(),
p.GetVolumeMin(), p.GetVolumeMax(), p.GetVolumeStep(), p.GetTradeStopsLevel())
return nil
}
2) Normalize a lot to the step and limits¶
func normalizeLot(ctx context.Context, acc *mt4.MT4Account, symbol string, lot float64) (float64, error) {
p, err := acc.SymbolParams(ctx, symbol)
if err != nil { return 0, err }
step := p.GetVolumeStep()
if step <= 0 { step = 0.01 }
v := math.Round(lot/step) * step
if v < p.GetVolumeMin() { v = p.GetVolumeMin() }
if p.GetVolumeMax() > 0 && v > p.GetVolumeMax() { v = p.GetVolumeMax() }
return v, nil
}
3) Pip value per lot (for risk sizing)¶
func pipValuePerLot(ctx context.Context, acc *mt4.MT4Account, symbol string) (float64, error) {
p, err := acc.SymbolParams(ctx, symbol)
if err != nil { return 0, err }
pip := p.GetPoint()
if p.GetDigits() == 3 || p.GetDigits() == 5 { pip *= 10 }
if p.GetTradeTickSize() > 0 {
return p.GetTradeTickValue() * (pip / p.GetTradeTickSize()), nil
}
return p.GetTradeTickValue(), nil
}
โ ๏ธ Pitfalls¶
- Don't hardcode digits/step. They vary per symbol and broker โ always read them.
- Zero step guard. Treat a
0GetVolumeStep()as0.01to avoid divide-by-zero. - Stops level is in points, not pips โ convert when comparing to a pip distance.
๐งช Testing Suggestions¶
- Happy path (demo).
GetPoint() > 0,GetVolumeStep() > 0,GetDigits()in {2,3,5}. - Normalize.
normalizeLotrounds0.137 โ 0.14on a0.01step and clamps belowVolumeMin. - Pip value.
pipValuePerLotis positive and finite for a liquid FX symbol.