mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-17 05:48:07 +00:00
v4.0.17 no-backtest
This commit is contained in:
+30
-83
@@ -1,94 +1,41 @@
|
||||
# Executor
|
||||
# executor
|
||||
|
||||
## Table of Contents
|
||||
- [Executor](#executor.Executor)
|
||||
- [__init__](#executor.__init__)
|
||||
- [add_function](#executor.add_function)
|
||||
- [add_coroutine](#executor.add_coroutine)
|
||||
- [run_function](#executor.run_function)
|
||||
- [execute](#executor.execute)
|
||||
`aiomql.lib.executor` — Strategy and task executor.
|
||||
|
||||
<a id='executor.Executor'></a>
|
||||
### Executor
|
||||
```python
|
||||
class Executor
|
||||
```
|
||||
Executor class for running multiple strategies on multiple symbols concurrently.
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|--------------------|----------------------|------------------------------------------------|---------|
|
||||
| `executor` | `ThreadPoolExecutor` | The default thread executor. | None |
|
||||
| `strategy_runners` | `list[Strategy]` | List of strategies. | [] |
|
||||
| `coroutines` | `dict` | Dictionary of coroutines and keyword arguments | {} |
|
||||
| `functions` | `dict` | Dictionary of functions and keyword arguments | {} |
|
||||
## Overview
|
||||
|
||||
<a id="executor.__init__"></a>
|
||||
#### \_\_init\_\_
|
||||
```python
|
||||
def __init__(self):
|
||||
```
|
||||
Initialize the executor class.
|
||||
The `Executor` manages the lifecycle of trading strategies and background tasks. It collects
|
||||
functions, coroutines, and `Strategy` instances, then runs them via a `TaskQueue`.
|
||||
|
||||
<a id="executor.add_coroutine"></a>
|
||||
### add_coroutine
|
||||
```python
|
||||
def add_coroutine(self,*,coroutine: Callable | Coroutine,kwargs: dict = None,on_separate_thread=False):
|
||||
```
|
||||
Submit a coroutine to the executor. The coroutines are run in parallel using *asyncio.gather* except when the
|
||||
on_spate_thread flag is set to True. In that case, the coroutine is run in a separate thread.
|
||||
## Classes
|
||||
|
||||
#### Arguments:
|
||||
| Name | Type | Description |
|
||||
|----------------------|------------|-------------------------------------------------|
|
||||
| `coroutine` | `Callable` | The coroutine |
|
||||
| `kwargs` | `Dict` | The keyword arguments to pass to the coroutine. |
|
||||
| `on_separate_thread` | `bool` | If True run the coroutine on a separate thread |
|
||||
### `Executor`
|
||||
|
||||
<a id="executor.add_function"></a>
|
||||
### add_function
|
||||
```python
|
||||
def add_function(self, *, function: Callable, kwargs: dict = None)
|
||||
```
|
||||
Submit a function to the executor. Each functions runs on a separate thread.
|
||||
> Executes strategies and tasks using a `TaskQueue`.
|
||||
|
||||
#### Arguments:
|
||||
| Name | Type | Description |
|
||||
|------------|------------|--------------------------------------------|
|
||||
| `function` | `Callable` | The function to run in the executor |
|
||||
| `kwargs` | `Dict` | Keyword arguments to pass to the function. |
|
||||
| Attribute | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `config` | `Config` | Global configuration |
|
||||
| `task_queue` | `TaskQueue` | The underlying task queue |
|
||||
|
||||
<a id="executor.run_function"></a>
|
||||
### run_function
|
||||
```python
|
||||
@staticmethod
|
||||
def run_function(function: Callable, kwargs: dict)
|
||||
```
|
||||
Wrap the input coroutine function with 'asyncio.run' so that it can be executed in a threadpool executor.
|
||||
#### Arguments:
|
||||
| Name | Type | Description |
|
||||
|------------|------------|--------------------------------------------|
|
||||
| `function` | `Callable` | Run a function in the executor |
|
||||
| `kwargs` | `Dict` | Keyword arguments to pass to the function. |
|
||||
#### Adding Tasks
|
||||
|
||||
<a id="executor.exit"></a>
|
||||
### exit
|
||||
```python
|
||||
async def exit()
|
||||
```
|
||||
Shutdowns the executor. Due to the nature of threadpool executors, shutdown is not usually an immediate process.
|
||||
This exit function is added as a coroutine function to the bot or backtester during initialization.
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `add_function(func, *args, **kwargs)` | Registers a regular callable |
|
||||
| `add_coroutine(coro, *args, **kwargs)` | Registers an async coroutine |
|
||||
| `add_strategy(strategy)` | Registers a `Strategy` instance |
|
||||
|
||||
<a id="executor.execute"></a>
|
||||
### execute
|
||||
```python
|
||||
def execute(workers: int = 5)
|
||||
```
|
||||
Run the strategies with a threadpool executor.
|
||||
#### Arguments:
|
||||
| Name | Type | Description |
|
||||
|-----------|-------|-----------------------------------------------------------|
|
||||
| `workers` | `int` | Number of workers to use in executor pool. Defaults to 5. |
|
||||
#### Execution
|
||||
|
||||
#### Notes:
|
||||
No matter the number specified, the number of workers will always be greater than equal to the minimum number of
|
||||
workers required to run all functions, coroutines and strategies added to the executor.
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `execute()` | Starts all registered tasks and strategies via the queue |
|
||||
| `run_coroutine_task(coro, *args, **kwargs)` | Runs a single coroutine task |
|
||||
|
||||
#### Shutdown
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `sigint_handle(sig, frame)` | Handles SIGINT for graceful shutdown |
|
||||
| `exit()` | Sets the shutdown flag and stops the queue |
|
||||
|
||||
Reference in New Issue
Block a user