This commit is contained in:
Ichinga Samuel
2026-02-27 04:11:38 +01:00
parent cb2c700752
commit eed7e80c0d
15 changed files with 430 additions and 78 deletions
+31 -9
View File
@@ -7,7 +7,7 @@
The `Order` class creates and manages trade orders for the MetaTrader 5 terminal. It handles
margin calculations, profit projections, order validation, modification, and cancellation.
Inherits from [`_Base`](../core/base.md).
Inherits from [`_Base`](../core/base.md) and `TradeRequest`.
## Classes
@@ -30,32 +30,54 @@ Inherits from [`_Base`](../core/base.md).
| `type_filling` | `OrderFilling` | Filling policy |
| `type_time` | `OrderTime` | Time-in-force policy |
#### Initialisation
| Method | Description |
|--------|-------------|
| `__init__(**kwargs)` | Requires `symbol`. Defaults: `action=TradeAction.DEAL`, `type_time=OrderTime.DAY`, `type_filling=OrderFilling.FOK` |
#### `request` *(property)*
Returns the trade request as a dict, filtering out `None` values.
Returns the trade request as a dict, filtering to keys valid for `TradeRequest`.
#### Validation
| Method | Returns | Description |
|--------|---------|-------------|
| `check()` | `OrderCheckResult` | Validates the order, raises `OrderError` on failure |
| `check(**kwargs)` | `OrderCheckResult` | Validates the order; raises `OrderError` on failure |
#### Execution
| Method | Returns | Description |
|--------|---------|-------------|
| `send()` | `OrderSendResult` | Sends the order; retries on requote/timeout |
| `send()` | `OrderSendResult` | Sends the order via `send_order()` |
| `send_order(request, connection_retries=0)` | `OrderSendResult` | Class method. Sends a trade request; retries up to 3 times on connection loss (retcode 10031). Raises `OrderError` on failure |
#### Calculations
| Method | Returns | Description |
|--------|---------|-------------|
| `calc_margin()` | `float \| None` | Required margin for the order |
| `calc_profit(close_price)` | `float \| None` | Projected profit at a given close price |
| `calc_profit()` | `float \| None` | Projected profit at `tp` (take profit) price |
| `calc_loss()` | `float \| None` | Projected loss at `sl` (stop loss) price |
| `profit_to_price(profit, order_type, volume, symbol, price_open)` | `float` | Class method. Reverse-calculates the close price needed to achieve a target profit |
#### Modification
| Method | Description |
|--------|-------------|
| `modify(**kwargs)` | Modifies a pending order's parameters |
| `cancel()` | Cancels a pending order |
| Method | Returns | Description |
|--------|---------|-------------|
| `modify(**kwargs)` | — | Updates the order's attributes |
| `cancel_order(order, symbol="")` | `OrderSendResult` | Class method. Cancels a pending order by ticket; raises `OrderError` on failure |
#### Pending & Historical Orders
| Method | Returns | Description |
|--------|---------|-------------|
| `orders_total()` | `int` | Class method. Total number of active pending orders |
| `get_pending_order(ticket)` | `TradeOrder \| None` | Class method. Gets a single pending order by ticket |
| `get_pending_orders(ticket, symbol, group)` | `tuple[TradeOrder, ...]` | Class method. Gets pending orders filtered by ticket, symbol, or group |
| `get_history_order_by_ticket(ticket)` | `TradeOrder \| None` | Class method. Gets a historical order by ticket |
## Synchronous API
Available in `aiomql.lib.sync.order`. All async methods become synchronous with the same signatures.
+55 -12
View File
@@ -7,7 +7,7 @@
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.
Inherits from [`_Base`](../core/base.md).
Inherits from [`_Base`](../core/base.md) and `SymbolInfo`.
## Classes
@@ -19,33 +19,76 @@ Inherits from [`_Base`](../core/base.md).
|-----------|------|-------------|
| `name` | `str` | Symbol name (e.g. `"EURUSD"`) |
| `select` | `bool` | Whether the symbol is selected in Market Watch |
| `tick` | `Tick` | Current price tick for the instrument |
| `account` | `Account` | Trading account instance |
| `initialized` | `bool` | Whether the symbol has been successfully initialized |
All `SymbolInfo` fields are available as instance attributes after initialisation.
#### Initialisation
| Method | Description |
|--------|-------------|
| `init()` | Fetches symbol info from the terminal and sets all attributes |
| 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 |
#### Market Data
| Method | Returns | Description |
|--------|---------|-------------|
| `info_tick()` | `Tick` | Current tick for the symbol |
| `copy_rates_from(timeframe, date_from, count)` | `Candles` | Historical bars from a date |
| `copy_rates_from_pos(timeframe, start_pos, count)` | `Candles` | Historical bars from a position |
| `copy_rates_range(timeframe, date_from, date_to)` | `Candles` | Historical bars in a range |
| `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 |
| `copy_ticks_from(date_from, count, flags)` | `Ticks` | Historical ticks from a date |
| `copy_ticks_range(date_from, date_to, flags)` | `Ticks` | Historical ticks in a range |
| `copy_ticks_range(date_from, date_to, flags)` | `Ticks` | Historical ticks in a date range |
#### Helpers
#### Properties
| Property | Returns | Description |
|----------|---------|-------------|
| `pip` | `float` | The pip size for the symbol |
| `spread` | `float` | Current bid-ask spread |
| `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 |
## Synchronous API
Available in `aiomql.lib.sync.symbol`.
Available in `aiomql.lib.sync.symbol`. All async methods become synchronous with the same signatures.