SymbolInfoSessionTrade HOW
Example from file: examples/demos/lowlevel/01_general_operations.goΒΆ
The
SymbolInfoSessionTrade()method is used to retrieve trading session times β periods when trading operations are allowed for a symbol.Unlike
SymbolInfoSessionQuote()(which shows when quotes are available), this method shows when trading is allowed β that is, when the server accepts orders and executes trades.
π§© Code exampleΒΆ
tradeSessionReq := &pb.SymbolInfoSessionTradeRequest{
Symbol: cfg.TestSymbol,
DayOfWeek: pb.DayOfWeek_MONDAY,
SessionIndex: 0,
}
tradeSessionData, err := account.SymbolInfoSessionTrade(ctx, tradeSessionReq)
if err != nil {
helpers.PrintShortError(err, "SymbolInfoSessionTrade failed")
} else {
fmt.Printf(" Monday trade session #0:\n")
if tradeSessionData.From != nil {
fromTime := tradeSessionData.From.AsTime()
fromSeconds := fromTime.Hour()*3600 + fromTime.Minute()*60 + fromTime.Second()
fmt.Printf(" From (seconds from day start): %d\n", fromSeconds)
}
if tradeSessionData.To != nil {
toTime := tradeSessionData.To.AsTime()
toSeconds := toTime.Hour()*3600 + toTime.Minute()*60 + toTime.Second()
fmt.Printf(" To (seconds from day start): %d\n", toSeconds)
}
}
π’ Detailed Code ExplanationΒΆ
tradeSessionReq := &pb.SymbolInfoSessionTradeRequest{
Symbol: cfg.TestSymbol,
DayOfWeek: pb.DayOfWeek_MONDAY,
SessionIndex: 0,
}
A request is created with parameters:
Symbolβ trading instrument (e.g.,EURUSD);DayOfWeekβ day of the week for which the schedule is needed;SessionIndexβ sequential session number for that day.
A request is sent to the MetaTrader server via gRPC. The response returns a structure with From and To fields β trading session start and end.
if tradeSessionData.From != nil {
fromTime := tradeSessionData.From.AsTime()
fromSeconds := fromTime.Hour()*3600 + fromTime.Minute()*60 + fromTime.Second()
fmt.Printf(" From (seconds from day start): %d\n", fromSeconds)
}
Converts From to time.Time format and calculates the number of seconds from the start of the day.
if tradeSessionData.To != nil {
toTime := tradeSessionData.To.AsTime()
toSeconds := toTime.Hour()*3600 + toTime.Minute()*60 + toTime.Second()
fmt.Printf(" To (seconds from day start): %d\n", toSeconds)
}
Same for the session end.
π What is SessionIndexΒΆ
The SessionIndex parameter is not related to the day of the week, it indicates the session number within the selected day.
For example, if a symbol has several trading intervals during the day:
| DayOfWeek | SessionIndex | From | To |
|---|---|---|---|
| MONDAY | 0 | 09:00 | 12:00 |
| MONDAY | 1 | 13:00 | 17:00 |
| TUESDAY | 0 | 09:00 | 17:00 |
That is:
DayOfWeekβ day of the week;SessionIndexβ sequential session number on that day.
If an instrument has only one trading session per day (e.g., Forex 24 hours), then SessionIndex = 0.
π¦ What the Server ReturnsΒΆ
message SymbolInfoSessionTradeData {
google.protobuf.Timestamp From = 1; // Trading session start time
google.protobuf.Timestamp To = 2; // Trading session end time
}
π‘ Example OutputΒΆ
π This means trading is available all day β from 00:00:00 to 23:59:59.
βΉοΈ Why Values Can Be ZeroΒΆ
If you see the output:
this is normal behavior, not a code error.
Reasons:
- 24/5 trading β the broker doesn't set separate intervals.
- Broker hasn't filled in the schedule β often found on demo servers.
- Gateway doesn't transmit these fields β API returns empty Timestamp.
- Day or index contains no data β there's no session on that day with that index.
β
In such cases, 0 is interpreted as "all day open for trading".
π§ What It's Used ForΒΆ
The SymbolInfoSessionTrade() method is used:
- to check trading hours before opening orders;
- to avoid trading outside sessions;
- for visualizing market operation (charts, calendars);
- in backtests and simulations to account for trading schedules.
π¬ In Simple TermsΒΆ
SymbolInfoSessionTrade()shows what hours and days trading is allowed for a symbol. If it returns zeros β it means trading is available all day or the broker hasn't specified a schedule.