2026-02-21 07:43:33 +01:00
|
|
|
# strategy
|
2024-02-12 21:09:28 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
`aiomql.lib.strategy` — Strategy base class.
|
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
|
|
|
The `Strategy` class is the abstract base for all trading strategies. Subclasses implement
|
|
|
|
|
`trade()` to define entry/exit logic. The strategy lifecycle is managed by the
|
|
|
|
|
[`Bot`](bot.md) / [`Executor`](executor.md).
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
Inherits from [`_Base`](../core/base.md).
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
## Classes
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
### `Strategy`
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
> Abstract base class for trading strategies.
|
2023-10-16 15:36:31 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
| Attribute | Type | Description |
|
|
|
|
|
|-----------|------|-------------|
|
|
|
|
|
| `name` | `str` | Strategy name (defaults to class name) |
|
|
|
|
|
| `symbol` | `Symbol` | The trading instrument |
|
|
|
|
|
| `sessions` | `Sessions \| None` | Optional session restrictions |
|
|
|
|
|
| `params` | `dict` | Strategy parameters |
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
#### Lifecycle
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
| Method | Description |
|
|
|
|
|
|--------|-------------|
|
|
|
|
|
| `__init__(symbol, params, sessions, …)` | Initialises the strategy with a symbol and parameters |
|
|
|
|
|
| `init()` | Async setup hook (called once before trading begins) |
|
|
|
|
|
| `run()` | Main loop — calls `trade()` repeatedly |
|
|
|
|
|
| `sleep(secs)` | Suspends the strategy for a duration |
|
2023-10-11 09:49:06 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
#### Trading Logic
|
2024-11-10 12:25:50 +01:00
|
|
|
|
2026-02-21 07:43:33 +01:00
|
|
|
| Method | Description |
|
|
|
|
|
|--------|-------------|
|
|
|
|
|
| `trade()` | **Abstract** — implement entry/exit logic here |
|