2026-02-21 07:43:33 +01:00
|
|
|
# sessions
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
`aiomql.lib.sessions` — Trading session time windows.
|
2024-02-12 21:09:28 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
## Overview
|
2024-02-12 21:09:28 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
Provides `Session` (a single trading window) and `Sessions` (a collection of windows)
|
|
|
|
|
for restricting trading to specific hours of the day. Sessions can automatically trigger
|
|
|
|
|
actions at their boundaries — e.g. closing all positions when a session ends.
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
## Classes
|
2024-02-12 21:09:28 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
### `Session`
|
2024-02-12 21:09:28 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
> Defines a single trading time window.
|
2024-02-12 21:09:28 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
| Attribute | Type | Description |
|
|
|
|
|
|-----------|------|-------------|
|
|
|
|
|
| `name` | `str` | Session name |
|
|
|
|
|
| `start` | `time` | Session start time |
|
|
|
|
|
| `end` | `time` | Session end time |
|
|
|
|
|
| `on_start` | `Callable \| None` | Hook called when the session opens |
|
|
|
|
|
| `on_end` | `Callable \| None` | Hook called when the session closes |
|
|
|
|
|
| `close_all` | `bool` | If `True`, close all positions on session end |
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
#### Properties
|
2023-10-16 15:36:31 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
| Property | Returns | Description |
|
|
|
|
|
|----------|---------|-------------|
|
|
|
|
|
| `duration` | `timedelta` | Length of the session |
|
|
|
|
|
| `in_session` | `bool` | `True` if current time is within the window |
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
---
|
2024-02-12 21:09:28 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
### `Sessions`
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
> Manages multiple `Session` objects.
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
| Attribute | Type | Description |
|
|
|
|
|
|-----------|------|-------------|
|
|
|
|
|
| `sessions` | `list[Session]` | Registered sessions |
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
#### Methods
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
| Method | Description |
|
|
|
|
|
|--------|-------------|
|
|
|
|
|
| `add(session)` | Adds a session |
|
|
|
|
|
| `find(name)` | Finds a session by name |
|
|
|
|
|
| `check()` | Checks which sessions are active and triggers hooks |
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
## Synchronous API
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
Available in `aiomql.lib.sync.sessions`.
|