✅ Symbol Info Session Trade¶
Request: get trading session window (time interval when trading is allowed) for a symbol on a given day of week and session index.
Source files:
MetaRpcMT5/mt5_account.py
— methodsymbol_info_session_trade(...)
MetaRpcMT5/mt5_term_api_market_info_pb2.py
—SymbolInfoSessionTrade*
messages (SymbolInfoSessionTradeRequest
,SymbolInfoSessionTradeReply
,SymbolInfoSessionTradeData
) and enumDayOfWeek
MetaRpcMT5/mt5_term_api_market_info_pb2_grpc.py
— service stubMarketInfoStub
RPC¶
- Service:
mt5_term_api.MarketInfo
- Method:
SymbolInfoSessionTrade(SymbolInfoSessionTradeRequest) → SymbolInfoSessionTradeReply
- Low-level client:
MarketInfoStub.SymbolInfoSessionTrade(request, metadata, timeout)
- SDK wrapper:
MT5Account.symbol_info_session_trade(symbol, day_of_week, session_index, deadline=None, cancellation_event=None)
🔗 Code Example¶
# Get trading session window for Monday, session #0
from MetaRpcMT5 import mt5_term_api_market_info_pb2 as mi_pb2
sess = await acct.symbol_info_session_trade(
"EURUSD",
mi_pb2.DayOfWeek.MONDAY,
0,
)
print(sess.from.seconds, sess.to.seconds) # UTC seconds
Method Signature¶
async def symbol_info_session_trade(
self,
symbol: str,
day_of_week: market_info_pb2.DayOfWeek,
session_index: int,
deadline: datetime | None = None,
cancellation_event: asyncio.Event | None = None,
) -> market_info_pb2.SymbolInfoSessionTradeData
💬 Plain English¶
- What it is. Returns the time window when trading is permitted for the symbol on a specific weekday.
- Why you care. Strategies and UIs can block order placement outside trading hours, even if quotes exist.
-
Mind the traps.
-
session_index
is zero‑based (0, 1, 2, …). Some brokers split a day into multiple sessions with breaks. - Timestamps are
google.protobuf.Timestamp
(UTC). Convert before display. - If the session is absent, the window may be empty (both ends zero/equal). Handle gracefully.
🔽 Input¶
Parameter | Type | Description | |
---|---|---|---|
symbol |
str (required) |
Symbol name. | |
day_of_week |
DayOfWeek (required) |
Weekday selector (enum below). | |
session_index |
uint32 (required) |
Zero‑based session index within the selected weekday. | |
deadline |
datetime \| None |
Absolute per‑call deadline → converted to timeout. | |
cancellation_event |
asyncio.Event \| None |
Cooperative cancel for the retry wrapper. |
Request message:
SymbolInfoSessionTradeRequest { symbol: string, day_of_week: DayOfWeek, session_index: uint32 }
⬆️ Output¶
Payload: SymbolInfoSessionTradeData
¶
Field | Proto Type | Description |
---|---|---|
from |
google.protobuf.Timestamp |
Trading start (UTC). |
to |
google.protobuf.Timestamp |
Trading end (UTC). |
Wire reply:
SymbolInfoSessionTradeReply { data: SymbolInfoSessionTradeData, error: Error? }
SDK returnsreply.data
.
Enum: DayOfWeek
¶
Number | Value |
---|---|
0 | SUNDAY |
1 | MONDAY |
2 | TUESDAY |
3 | WEDNESDAY |
4 | THURSDAY |
5 | FRIDAY |
6 | SATURDAY |
🎯 Purpose¶
- Enforce trading hours in order tickets and automation.
- Build weekly calendars showing when orders are allowed.
- Validate broker configs (unexpected closures/breaks).
🧩 Notes & Tips¶
- Quote sessions may differ from trade sessions. Use
SymbolInfoSessionQuote
to compare. - To enumerate all sessions for a day, increase
session_index
until the returned window is empty.
See also: symbol_info_session_quote.md, symbol_select.md, symbol_is_synchronized.md
Usage Examples¶
1) Print all Friday trading sessions¶
# English-only comments per project style
from MetaRpcMT5 import mt5_term_api_market_info_pb2 as mi_pb2
s = "XAUUSD"
for i in range(10):
w = await acct.symbol_info_session_trade(s, mi_pb2.DayOfWeek.FRIDAY, i)
if (not getattr(w, "from") or not getattr(w, "to") or w.from.seconds == 0 and w.to.seconds == 0):
break
print(i, w.from.seconds, w.to.seconds)
2) Convert to local time for UI¶
from datetime import datetime, timezone
w = await acct.symbol_info_session_trade("EURUSD", mi_pb2.DayOfWeek.MONDAY, 0)
start = datetime.fromtimestamp(w.from.seconds, tz=timezone.utc)
end = datetime.fromtimestamp(w.to.seconds, tz=timezone.utc)
print(start.isoformat(), "→", end.isoformat())
3) Guard order placement by current time¶
from datetime import datetime, timezone
w = await acct.symbol_info_session_trade("BTCUSD", mi_pb2.DayOfWeek.SUNDAY, 0)
now_utc = datetime.now(timezone.utc).timestamp()
inside = (w.from.seconds <= now_utc <= w.to.seconds)
if not inside:
raise RuntimeError("Trading session is closed right now")