trading_agent.risk.exchange_hours
¶
Decides whether an exchange is open for new orders at a given moment.
With trading_window = "exchange_hours", each exchange's own regular session applies: NSE and BSE equities and derivatives 09:15 to 15:30, currency derivatives 09:00 to 17:00, and MCX 09:00 to 23:30, or 23:55 while the United States is not on daylight saving time, because MCX's evening follows US trading hours. A fixed "HH:MM-HH:MM" window applies the same hours to every exchange. Weekends are closed. With a market calendar, exchange holidays are closed too, a commodity holiday that closes only the morning or evening session narrows the hours, and a special session such as Muhurat trading opens the exchange for its own hours, even on a weekend or holiday.
Typical usage example:
hours = ExchangeHours() is_open, reason = hours.is_open('nse', 'nse_equities', moment, 'exchange_hours')
ExchangeHours
¶
The trading sessions of the Indian exchanges.
Creates the checker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calendar
|
MarketCalendar | None
|
The exchanges' holidays and special sessions, or None to know weekends only. |
None
|
Source code in src/trading_agent/risk/exchange_hours.py
is_open
¶
Says whether new orders are allowed for an instrument at a moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exchange
|
str
|
The exchange, such as nse, bse or mcx. |
required |
segment
|
str
|
UBI's segment, used to tell currency derivatives apart. |
required |
moment
|
datetime
|
The moment, with a time zone. |
required |
trading_window
|
str
|
"exchange_hours", or "HH:MM-HH:MM" in India time. |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Whether it is open, and the session that applies, for messages. |