Files

172 lines
5.3 KiB
Markdown
Raw Permalink Normal View History

2024-02-12 21:09:28 +01:00
# Order
## Table of contents
2024-11-10 12:25:50 +01:00
- [Order](#order.order)
- [\_\_init\_\_](#order.__init__)
- [orders_total](#order.orders_total)
- [get_order](#order.get_pending_order)
- [get_orders](#order.get_pending_orders)
- [check](#order.check)
- [send](#order.send)
- [calc_margin](#order.calc_margin)
- [calc_profit](#order.calc_profit)
- [calc_loss](#order.calc_loss)
- [request](#order.request)
2024-11-30 23:10:31 +01:00
- [modify](#order.modify)
2024-11-10 12:25:50 +01:00
<a id="order.order"></a>
2024-02-12 21:09:28 +01:00
### Order
2023-10-11 09:49:06 +01:00
```python
2024-11-10 12:25:50 +01:00
class Order(_Base, TradeRequest)
2023-10-11 09:49:06 +01:00
```
2024-02-12 21:09:28 +01:00
Trade order related functions and attributes. Subclass of TradeRequest.
2023-10-11 09:49:06 +01:00
2024-11-10 12:25:50 +01:00
<a id="order.__init__"></a>
2023-10-16 15:36:31 +01:00
### \_\_init\_\_
2023-10-11 09:49:06 +01:00
```python
def __init__(**kwargs)
```
Initialize the order object with keyword arguments, symbol must be provided.
Provides default values for action, type_time and type_filling if not provided.
2024-02-12 21:09:28 +01:00
#### Arguments
| Name | Type | Description | Default |
|----------------|---------------------|----------------------------------------|------------------|
| `action` | `TradeAction` | Trade action | TradeAction.DEAL |
| `type_time` | `OrderTime` | Order time | OrderTime.DAY |
| `type_filling` | `OrderFilling` | Order filling | OrderFilling.FOK |
2024-11-10 12:25:50 +01:00
<a id="order.orders_total"></a>
2023-10-11 09:49:06 +01:00
```python
async def orders_total()
```
2024-11-10 12:25:50 +01:00
Get the total number of active pending orders.
2024-02-12 21:09:28 +01:00
#### Returns
| Type | Description |
|-------|-------------------------------|
| `int` | total number of active orders |
2024-11-10 12:25:50 +01:00
<a id="order.get_pending_order"></a>
### get_pending order
2024-05-05 00:08:57 +01:00
```python
2024-11-10 12:25:50 +01:00
async def get_pending_order(self, ticket: int) -> TradeOrder
2024-05-05 00:08:57 +01:00
```
2024-11-10 12:25:50 +01:00
Get an active pending trade order by ticket.
2024-05-05 00:08:57 +01:00
2024-11-10 12:25:50 +01:00
<a id="order.get_pending_orders"></a>
### get_pending_orders
2023-10-11 09:49:06 +01:00
```python
2024-11-10 12:25:50 +01:00
async def get_pending_orders(self, *, ticket: int = 0, symbol: str = '', group: str = '') -> tuple[TradeOrder, ...]:
2023-10-11 09:49:06 +01:00
```
2024-02-12 21:09:28 +01:00
Get active trade orders. If ticket is provided, it will return the order with the specified ticket.
If symbol is provided, it will return all orders for the specified symbol.
If group is provided, it will return all orders for the specified group.
2024-11-10 12:25:50 +01:00
#### Parameters:
2024-02-12 21:09:28 +01:00
| Name | Type | Description | Default |
|----------|--------|--------------------------------------|---------|
| `ticket` | `int` | Order ticket | 0 |
| `symbol` | `str` | Symbol name | '' |
| `group` | `str` | Group name | '' |
2024-11-10 12:25:50 +01:00
#### Returns:
| Type | Description |
|--------------------------|------------------------------------------------------|
| `tuple[TradeOrder, ...]` | A Tuple of active trade orders as TradeOrder objects |
2024-02-12 21:09:28 +01:00
2024-11-10 12:25:50 +01:00
<a id="order.check"></a>
2023-10-16 15:36:31 +01:00
### check
2023-10-11 09:49:06 +01:00
```python
2024-11-10 12:25:50 +01:00
async def check(**kwargs) -> OrderCheckResult
2023-10-11 09:49:06 +01:00
```
2024-11-10 12:25:50 +01:00
#### Parameters:
| Type | Description |
|--------|----------------------------------------------|
| kwargs | Update the request dict with extra arguments |
Check if an order is okay.
#### Returns:
2024-02-12 21:09:28 +01:00
| Type | Description |
|--------------------|----------------------------|
| `OrderCheckResult` | An OrderCheckResult object |
2024-11-10 12:25:50 +01:00
2023-10-16 15:36:31 +01:00
#### Raises:
2024-02-12 21:09:28 +01:00
| Exception | Description |
|--------------|-------------------|
| `OrderError` | If not successful |
2023-10-11 09:49:06 +01:00
2024-11-10 12:25:50 +01:00
<a id="order.send"></a>
2024-02-12 21:09:28 +01:00
### send
2023-10-11 09:49:06 +01:00
```python
async def send() -> OrderSendResult
```
Send a request to perform a trading operation from the terminal to the trade server.
2024-11-10 12:25:50 +01:00
#### Returns:
2024-02-12 21:09:28 +01:00
| Type | Description |
|-------------------|---------------------------|
| `OrderSendResult` | An OrderSendResult object |
2024-11-10 12:25:50 +01:00
2023-10-16 15:36:31 +01:00
#### Raises:
2024-02-12 21:09:28 +01:00
| Exception | Description |
|--------------|-------------------|
| `OrderError` | If not successful |
2023-10-11 09:49:06 +01:00
2024-11-10 12:25:50 +01:00
<a id="order.calc_margin"></a>
### calc_margin:
2023-10-11 09:49:06 +01:00
```python
async def calc_margin() -> float
```
Return the required margin in the account currency to perform a specified trading operation.
2024-11-10 12:25:50 +01:00
#### Returns:
2024-02-12 21:09:28 +01:00
| Type | Description |
|---------|-----------------------------------|
| `float` | Returns float value if successful |
2024-11-10 12:25:50 +01:00
<a id="order.calc_profit"></a>
2023-10-16 15:36:31 +01:00
### calc_profit
2023-10-11 09:49:06 +01:00
```python
async def calc_profit() -> float
```
Return profit in the account currency for a specified trading operation.
2024-11-10 12:25:50 +01:00
#### Returns:
| Type | Description |
|---------|-----------------------------------|
| `float` | Returns float value if successful |
| `None` | If not successful |
<a id="order.calc_loss"></a>
### calc_profit
```python
async def calc_loss() -> float
```
Return loss in the account currency for a specified trading operation.
2024-02-12 21:09:28 +01:00
#### Returns
| Type | Description |
|---------|-----------------------------------|
| `float` | Returns float value if successful |
2024-08-20 06:22:51 +01:00
| `None` | If not successful |
2024-11-10 12:25:50 +01:00
<a id="order.request"></a>
### request
```python
@property
async def request() -> dict
```
Return the trade request object as a dict
#### Returns
| Type | Description |
|--------|----------------------------------|
| `dict` | Returns the trade request object |
2024-11-30 23:10:31 +01:00
<a id="order.modify"></a>
### modify
```python
def modify(**kwargs)
```
Modify the order object with keyword arguments.