Files

95 lines
3.7 KiB
Markdown
Raw Permalink Normal View History

2026-02-21 07:43:33 +01:00
# symbol
2023-10-11 09:49:06 +01:00
2026-02-21 07:43:33 +01:00
`aiomql.lib.symbol` — Trading instrument interface.
2024-11-10 12:25:50 +01:00
2026-02-21 07:43:33 +01:00
## Overview
2024-11-10 12:25:50 +01:00
2026-02-21 07:43:33 +01:00
The `Symbol` class represents a financial instrument (forex pair, stock, etc.) and provides
methods for querying market data, selecting symbols, and retrieving rates and ticks.
2024-11-10 12:25:50 +01:00
2026-02-27 04:11:38 +01:00
Inherits from [`_Base`](../core/base.md) and `SymbolInfo`.
2024-02-12 21:09:28 +01:00
2026-02-21 07:43:33 +01:00
## Classes
2023-10-11 09:49:06 +01:00
2026-02-21 07:43:33 +01:00
### `Symbol`
2024-11-10 12:25:50 +01:00
2026-02-21 07:43:33 +01:00
> Interface for a MetaTrader 5 trading instrument.
2024-11-10 12:25:50 +01:00
2026-02-21 07:43:33 +01:00
| Attribute | Type | Description |
|-----------|------|-------------|
| `name` | `str` | Symbol name (e.g. `"EURUSD"`) |
| `select` | `bool` | Whether the symbol is selected in Market Watch |
2026-02-27 04:11:38 +01:00
| `tick` | `Tick` | Current price tick for the instrument |
| `account` | `Account` | Trading account instance |
| `initialized` | `bool` | Whether the symbol has been successfully initialized |
2024-02-12 21:09:28 +01:00
2026-02-21 07:43:33 +01:00
All `SymbolInfo` fields are available as instance attributes after initialisation.
2024-11-10 12:25:50 +01:00
2026-02-21 07:43:33 +01:00
#### Initialisation
2024-11-10 12:25:50 +01:00
2026-02-27 04:11:38 +01:00
| Method | Returns | Description |
|--------|---------|-------------|
| `__init__(**kwargs)` | — | Requires `name` keyword argument |
| `initialize()` | `bool` | Async. Fetches symbol info, tick, and selects the symbol |
| `initialize_sync()` | `bool` | Synchronous version of `initialize()` |
#### Symbol Info
| Method | Returns | Description |
|--------|---------|-------------|
| `info()` | `SymbolInfo \| None` | Fetches and updates all symbol properties |
| `info_tick(name="")` | `Tick \| None` | Gets the current price tick |
| `symbol_select(enable=True)` | `bool` | Selects or removes the symbol from Market Watch |
#### Market Depth
| Method | Returns | Description |
|--------|---------|-------------|
| `book_add()` | `bool` | Subscribes to Market Depth events |
| `book_get()` | `tuple[BookInfo, ...]` | Returns Market Depth entries |
| `book_release()` | `bool` | Cancels Market Depth subscription |
#### Volume Helpers
| Method | Returns | Description |
|--------|---------|-------------|
| `check_volume(volume)` | `tuple[bool, float]` | Checks if volume is within min/max limits |
| `round_off_volume(volume, round_down=False)` | `float` | Rounds volume to nearest volume step |
| `compute_volume(*args, **kwargs)` | `float` | Returns `volume_min` (override in subclasses) |
#### Currency Conversion
| Method | Returns | Description |
|--------|---------|-------------|
| `amount_in_quote_currency(amount)` | `float` | Converts amount to the symbol's quote currency |
| `convert_currency(amount, from_currency, to_currency)` | `float \| None` | Converts between two currencies via tick data |
2024-11-10 12:25:50 +01:00
2026-02-21 07:43:33 +01:00
#### Market Data
2024-02-12 21:09:28 +01:00
2026-02-21 07:43:33 +01:00
| Method | Returns | Description |
|--------|---------|-------------|
| `copy_rates_from(timeframe, date_from, count)` | `Candles` | Historical bars from a date |
2026-02-27 04:11:38 +01:00
| `copy_rates_from_pos(timeframe, count, start_position)` | `Candles` | Historical bars from a position |
| `copy_rates_range(timeframe, date_from, date_to)` | `Candles` | Historical bars in a date range |
2026-02-21 07:43:33 +01:00
| `copy_ticks_from(date_from, count, flags)` | `Ticks` | Historical ticks from a date |
2026-02-27 04:11:38 +01:00
| `copy_ticks_range(date_from, date_to, flags)` | `Ticks` | Historical ticks in a date range |
2024-11-10 12:25:50 +01:00
2026-02-27 04:11:38 +01:00
#### Properties
2024-11-10 12:25:50 +01:00
2026-02-21 07:43:33 +01:00
| Property | Returns | Description |
|----------|---------|-------------|
2026-02-27 04:11:38 +01:00
| `pip` | `float` | Pip size (`point * 10`) |
#### Overridable Methods
These methods raise `NotImplementedError` in the base `Symbol` and are meant to be implemented by subclasses such as [`ForexSymbol`](../contrib/symbols/forex_symbol.md).
| Method | Returns | Description |
|--------|---------|-------------|
| `compute_volume_sl(amount, price, sl, round_down)` | `float` | Compute volume from stop-loss distance |
| `compute_volume_points(amount, points, round_down)` | `float` | Compute volume from point distance |
2024-11-10 12:25:50 +01:00
2026-02-21 07:43:33 +01:00
## Synchronous API
2024-02-12 21:09:28 +01:00
2026-02-27 04:11:38 +01:00
Available in `aiomql.lib.sync.symbol`. All async methods become synchronous with the same signatures.