SymbolInfoSessionQuote HOW
Example from file: examples/demos/lowlevel/01_general_operations.goΒΆ
The
SymbolInfoSessionQuote()method is used to retrieve quote session times β periods when the broker provides quotes for a symbol throughout the week.Each trading instrument in MetaTrader can have one or more such time windows, for example: morning and evening sessions, or a 24/5 round-the-clock mode.
π§© Code exampleΒΆ
quoteSessionReq := &pb.SymbolInfoSessionQuoteRequest{
Symbol: cfg.TestSymbol,
DayOfWeek: pb.DayOfWeek_MONDAY,
SessionIndex: 0,
}
quoteSessionData, err := account.SymbolInfoSessionQuote(ctx, quoteSessionReq)
if err != nil {
helpers.PrintShortError(err, "SymbolInfoSessionQuote failed")
} else {
fmt.Printf(" Monday quote session #0:\n")
if quoteSessionData.From != nil {
fromTime := quoteSessionData.From.AsTime()
fromSeconds := fromTime.Hour()*3600 + fromTime.Minute()*60 + fromTime.Second()
fmt.Printf(" From (seconds from day start): %d\n", fromSeconds)
}
if quoteSessionData.To != nil {
toTime := quoteSessionData.To.AsTime()
toSeconds := toTime.Hour()*3600 + toTime.Minute()*60 + toTime.Second()
fmt.Printf(" To (seconds from day start): %d\n", toSeconds)
}
}
π’ Detailed Code ExplanationΒΆ
quoteSessionReq := &pb.SymbolInfoSessionQuoteRequest{
Symbol: cfg.TestSymbol,
DayOfWeek: pb.DayOfWeek_MONDAY,
SessionIndex: 0,
}
A request is created with parameters:
Symbolβ trading instrument name (e.g.,EURUSD);DayOfWeekβ day of the week for which the session is requested (MONDAY,TUESDAY, etc.);SessionIndexβ session index for that day (if there are multiple, e.g., morning and evening).
A call is made to the MetaTrader server via gRPC. The response contains a structure with From and To fields β session start and end times.
if quoteSessionData.From != nil {
fromTime := quoteSessionData.From.AsTime()
fromSeconds := fromTime.Hour()*3600 + fromTime.Minute()*60 + fromTime.Second()
fmt.Printf(" From (seconds from day start): %d\n", fromSeconds)
}
If the From field is filled, it's converted to time.Time, then translated to seconds from the start of the day.
if quoteSessionData.To != nil {
toTime := quoteSessionData.To.AsTime()
toSeconds := toTime.Hour()*3600 + toTime.Minute()*60 + toTime.Second()
fmt.Printf(" To (seconds from day start): %d\n", toSeconds)
}
Similarly, the session end time is calculated.
π¦ What the Server ReturnsΒΆ
message SymbolInfoSessionQuoteData {
google.protobuf.Timestamp From = 1; // Quote session start time
google.protobuf.Timestamp To = 2; // Quote session end time
}
π‘ Example OutputΒΆ
π This means quotes are available all day β from 00:00:00 to 23:59:59.
βΉοΈ Why Values Can Be ZeroΒΆ
If the terminal displays:
this is not a code error, but one of the standard MetaTrader API behaviors.
Reasons:
- Instrument trades 24/5 non-stop β the server doesn't set separate intervals.
- Broker hasn't configured sessions β demo servers often return zeros.
- Gateway doesn't support these fields β API returns empty
Timestamp. - Invalid
SessionIndexorDayOfWeekβ there may be no sessions on that day.
β
In these cases, 0 is interpreted as "active all day".
π§ What It's Used ForΒΆ
The SymbolInfoSessionQuote() method is used:
- to determine active market hours for an instrument;
- for restricting trading outside working hours;
- when building analytical panels and trading calendars;
- in demo examples where it's important to show how to get quote schedules via API.
π¬ In Simple TermsΒΆ
SymbolInfoSessionQuote()shows what hours the symbol receives quotes. Even if it returns 0, it means quotes are available all day (24/5).