mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-15 12:58:06 +00:00
v3.19
This commit is contained in:
+109
-102
@@ -1,33 +1,45 @@
|
||||
## <a id="sessions"></a> Sessions and Session
|
||||
# Session and Sessions
|
||||
Sessions allow you to run a strategy at specific times of the day.
|
||||
|
||||
Sessions allow you to run code at specific times of the day.
|
||||
## Table of Contents
|
||||
- [Session](#session)
|
||||
- [\_\_init\_\_](#session.__init__)
|
||||
- [begin](#session.begin)
|
||||
- [close](#session.close)
|
||||
- [action](#session.action)
|
||||
- [Sessions](#sessions)
|
||||
- [\_\_init\_\_](#sessions.__init__)
|
||||
- [find](#sessions.find)
|
||||
- [find_next](#sessions.find_next)
|
||||
- [check](#sessions.check)
|
||||
- [delta](#delta)
|
||||
- [until](#until)
|
||||
|
||||
|
||||
<a id="session"></a>
|
||||
## Session
|
||||
```python
|
||||
class Session()
|
||||
class Session
|
||||
```
|
||||
A session is a time period between two datetime.time objects specified in utc.
|
||||
A session is a time period between two `datetime.time` objects specified in utc.
|
||||
#### Attributes
|
||||
| Name | Type | Description | Default |
|
||||
|----------------|-------------------------------------------------------------------|------------------------------------------------------------------------|---------|
|
||||
| `start` | `datetime.time` | The start time of the session. | None |
|
||||
| `end` | `datetime.time` | The end time of the session. | None |
|
||||
| `on_start` | `Literal['close_all', 'close_win', 'close_loss', 'custom_start']` | The action to take when the session starts. Default is None. | None |
|
||||
| `on_end` | `Literal['close_all', 'close_win', 'close_loss', 'custom_end']` | The action to take when the session ends. Default is None. | None |
|
||||
| `custom_start` | `Callable` | A custom function to call when the session starts. Default is None. | None |
|
||||
| `custom_end` | `Callable` | A custom function to call when the session ends. Default is None. | None |
|
||||
| `name` | `str` | The name of the session. Default is a combination of start and finish. | |
|
||||
|
||||
### Attributes:
|
||||
|Name| Type | Description | Default |
|
||||
|---|----------------|------------------------------------------------------------------------|----|
|
||||
|**start**| **datetime.time** | The start time of the session. | None |
|
||||
|**end**| **datetime.time** | The end time of the session. | None |
|
||||
|**on_start**| **Literal['close_all', 'close_win', 'close_loss', 'custom_start']** | The action to take when the session starts. Default is None. | None |
|
||||
|**on_end**| **Literal['close_all', 'close_win', 'close_loss', 'custom_end']** | The action to take when the session ends. Default is None. | None |
|
||||
|**custom_start**| **Callable** | A custom function to call when the session starts. Default is None. | None |
|
||||
|**custom_end**| **Callable** | A custom function to call when the session ends. Default is None. | None |
|
||||
|**name**| **str** | The name of the session. Default is a combination of start and finish. | |
|
||||
|
||||
### Methods:
|
||||
|Name|Description|
|
||||
|---|---|
|
||||
|**begin**|Call the action specified in on_start or custom_start.|
|
||||
|**close**|Call the action specified in on_end or custom_end.|
|
||||
|**action**|Used by begin and close to call the action specified.|
|
||||
|**until**|Get the seconds until the session starts from the current time.|
|
||||
#### Notes:
|
||||
The `[close_all, close_win, close_loss]` will affect or open positions in the account irrespective of whether they were
|
||||
opened during the session or not or even by a strategy using the session. This is because the session is not aware of the
|
||||
positions opened by the strategy. This will be handled in a future release.
|
||||
|
||||
<a id="session.__init__"></a>
|
||||
### \_\_init\_\_
|
||||
|
||||
```python
|
||||
def __init__(*,
|
||||
start: int | time,
|
||||
@@ -40,131 +52,126 @@ def __init__(*,
|
||||
custom_end: Callable = None)
|
||||
```
|
||||
Create a session.
|
||||
#### Arguments:
|
||||
|Name| Type | Description | Default |
|
||||
|---|-------------------------|--------------|-------------------|
|
||||
|**start**| **int** \| **datetime.time** | The start time of the session in UTC. | None |
|
||||
|**end**| **int** \| **datetime.time** | The end time of the session in UTC. | None |
|
||||
|**on_start**| **Literal['close_all', 'close_win', 'close_loss', 'custom_start']** | The action to take when the session starts. Default is None. | None |
|
||||
|**on_end**| **Literal['close_all', 'close_win', 'close_loss', 'custom_end']** | The action to take when the session ends. Default is None. | None |
|
||||
|**custom_start**| **Callable** | A custom function to call when the session starts. Default is None. | None |
|
||||
|**custom_end**| **Callable** | A custom function to call when the session ends. Default is None. | None |
|
||||
|**name**| **str** | The name of the session. Default is None. | None |
|
||||
#### Arguments
|
||||
| Name | Type | Description | Default |
|
||||
|----------------|-------------------------------------------------------------------|---------------------------------------------------------------------|---------|
|
||||
| `start` | `int` \| `datetime.time` | The start time of the session in UTC. | None |
|
||||
| `end` | `int` \| `datetime.time` | The end time of the session in UTC. | None |
|
||||
| `on_start` | `Literal['close_all', 'close_win', 'close_loss', 'custom_start']` | The action to take when the session starts. Default is None. | None |
|
||||
| `on_end` | `Literal['close_all', 'close_win', 'close_loss', 'custom_end']` | The action to take when the session ends. Default is None. | None |
|
||||
| `custom_start` | `Callable` | A custom function to call when the session starts. Default is None. | None |
|
||||
| `custom_end` | `Callable` | A custom function to call when the session ends. Default is None. | None |
|
||||
| `name` | `str` | The name of the session. Default is None. | None |
|
||||
|
||||
<a id="session.begin"></a>
|
||||
### begin
|
||||
```python
|
||||
async def begin()
|
||||
```
|
||||
Call the action specified in on_start or custom_start.
|
||||
|
||||
<a id="session.close"></a>
|
||||
### close
|
||||
```python
|
||||
async def close()
|
||||
```
|
||||
Call the action specified in on_end or custom_end.
|
||||
|
||||
### action
|
||||
```python
|
||||
async def action(action)
|
||||
async def action(action): pass
|
||||
```
|
||||
Used by begin and close to call the action specified.
|
||||
|
||||
#### Arguments:
|
||||
|Name| Type | Description | Default |
|
||||
|---|-------------------------|--------------|-------------------|
|
||||
|**action**| **Literal['close_all', 'close_win', 'close_loss', 'custom_start', 'custom_end']** | The action to take. | None |
|
||||
|
||||
### delta
|
||||
```python
|
||||
@staticmethod
|
||||
def delta(obj: time)
|
||||
```
|
||||
Get the timedelta of a datetime.time object.
|
||||
|
||||
#### Arguments:
|
||||
|Name| Type | Description | Default |
|
||||
|---|-------------------------|--------------|-------------------|
|
||||
|**obj**| **datetime.time** | A datetime.time object. | None |
|
||||
|
||||
#### Returns:
|
||||
|Type|Description|
|
||||
|---|---|
|
||||
|**timedelta**|A timedelta object.|
|
||||
|
||||
### until
|
||||
```python
|
||||
def until()
|
||||
```
|
||||
Get the seconds until the session starts from the current time.
|
||||
#### Returns:
|
||||
|Type|Description|
|
||||
|---|---|
|
||||
|**int**|The seconds until the session starts.|
|
||||
#### Arguments
|
||||
| Name | Type | Description | Default |
|
||||
|----------|---------------------------------------------------------------------------------|---------------------|---------|
|
||||
| `action` | `Literal['close_all', 'close_win', 'close_loss', 'custom_start', 'custom_end']` | The action to take. | None |
|
||||
|
||||
|
||||
<a id="sessions"></a>
|
||||
## Sessions
|
||||
|
||||
```python
|
||||
class Sessions()
|
||||
```
|
||||
Sessions allow you to run code at specific times of the day. It is a collection of Session objects.
|
||||
Sessions are sorted by start time. The sessions object is an asynchronous context manager.
|
||||
### Attributes:
|
||||
|Name|Type|Description|Default|
|
||||
|---|---|---|---|
|
||||
|**sessions**|**list[Session]**|A list of Session objects.|[]|
|
||||
|**current_session**|**Session**|The current session.|None|
|
||||
|
||||
### Methods:
|
||||
|Name|Description|
|
||||
|---|---|
|
||||
|**add**|Add a Session object to the sessions list.|
|
||||
|**remove**|Remove a Session object from the sessions list.|
|
||||
|**find**|Find a session that contains a datetime.time object.|
|
||||
|**find_next**|Find the next session that contains a datetime.time object.|
|
||||
|**check**|Check if the current session has started and if not, wait until it starts.|
|
||||
| Name | Type | Description | Default |
|
||||
|-------------------|-----------------|----------------------------|---------|
|
||||
| `sessions` | `list[Session]` | A list of Session objects. | [] |
|
||||
| `current_session` | `Session` | The current session. | None |
|
||||
|
||||
<a id="sessions.__init__"></a>
|
||||
#### \_\_init\_\_
|
||||
```python
|
||||
def __init__(*sessions)
|
||||
```
|
||||
Create a Sessions object.
|
||||
#### Arguments:
|
||||
|Name| Type | Description | Default |
|
||||
|---|--------------------|-----------------------------|-------------------|
|
||||
|**sessions**| **tuple[Session]** | A tuple of Session objects. | None |
|
||||
#### Arguments
|
||||
| Name | Type | Description | Default |
|
||||
|------------|------------------|-----------------------------|---------|
|
||||
| `sessions` | `tuple[Session]` | A tuple of Session objects. | None |
|
||||
|
||||
<a id="sessions.find"></a>
|
||||
### find
|
||||
```python
|
||||
def find(obj: time) -> Session | None
|
||||
```
|
||||
Find a session that contains a datetime.time object.
|
||||
#### Arguments:
|
||||
|Name| Type | Description | Default |
|
||||
|---|-------------------------|--------------|-------------------|
|
||||
|**obj**| **datetime.time** | A datetime.time object. | None |
|
||||
#### Arguments
|
||||
| Name | Type | Description | Default |
|
||||
|-------|-----------------|-------------------------|---------|
|
||||
| `obj` | `datetime.time` | A datetime.time object. | None |
|
||||
|
||||
#### Returns:
|
||||
|Type|Description|
|
||||
|---|---|
|
||||
|**Session**|A Session object or None if not found.|
|
||||
#### Returns
|
||||
| Type | Description |
|
||||
|-----------|----------------------------------------|
|
||||
| `Session` | A Session object or None if not found. |
|
||||
|
||||
<a id="sessions.find_next"></a>
|
||||
### find\_next
|
||||
```python
|
||||
def find_next(obj: time) -> Session
|
||||
```
|
||||
Find the next session that contains a datetime.time object.
|
||||
#### Arguments:
|
||||
|Name| Type | Description | Default |
|
||||
|---|-------------------------|--------------|-------------------|
|
||||
|**obj**| **datetime.time** | A datetime.time object. | None |
|
||||
#### Returns:
|
||||
|Type|Description|
|
||||
|---|---|
|
||||
|**Session**|A Session object.|
|
||||
|
||||
|
||||
#### Arguments
|
||||
| Name | Type | Description | Default |
|
||||
|-------|-----------------|-------------------------|---------|
|
||||
| `obj` | `datetime.time` | A datetime.time object. | |
|
||||
#### Returns
|
||||
| Type | Description |
|
||||
|-----------|-------------------|
|
||||
| `Session` | A Session object. |
|
||||
<a id="sessions.check"></a>
|
||||
### check
|
||||
```python
|
||||
async def check()
|
||||
async def check(): pass
|
||||
```
|
||||
Check if the current session has started and if not, wait until it starts.
|
||||
|
||||
<a id="delta"></a>
|
||||
### delta
|
||||
```python
|
||||
def delta(obj: time) -> timedelta: pass
|
||||
```
|
||||
Get the timedelta of a datetime.time object.
|
||||
#### Arguments:
|
||||
| Name | Type | Description | Default |
|
||||
|-------|-----------------|-------------------------|---------|
|
||||
| `obj` | `datetime.time` | A datetime.time object. | None |
|
||||
#### Returns
|
||||
| Type | Description |
|
||||
|-------------|---------------------|
|
||||
| `timedelta` | A timedelta object. |
|
||||
|
||||
<a id="until"></a>
|
||||
### until
|
||||
```python
|
||||
def until()
|
||||
```
|
||||
Get the seconds until the session starts from the current time.
|
||||
#### Returns:
|
||||
| Type | Description |
|
||||
|-------|---------------------------------------|
|
||||
| `int` | The seconds until the session starts. |
|
||||
|
||||
Reference in New Issue
Block a user