Files
aiomql/docs/bot_builder.md
T

106 lines
2.9 KiB
Markdown
Raw Normal View History

2023-10-11 09:49:06 +01:00
## <a id="bot_builder"></a> Bot Builder
```python
class Bot()
```
The bot class. Create a bot instance to run your strategies.
2023-10-16 15:36:31 +01:00
### Attributes:
2023-10-11 09:49:06 +01:00
|Name|Type|Description|Default|
|---|---|---|---|
|**account**|**Account**|Account Object.|None|
|**executor**|**ThreadPoolExecutor**|The default thread executor.|None|
|**symbols**|**set[Symbols]**|A set of symbols for the trading session|set()|
### initialize
```python
async def initialize()
```
Prepares the bot by signing in to the trading account and initializing the symbols for the trading session.
2023-10-16 15:36:31 +01:00
#### Raises:
2023-10-11 09:49:06 +01:00
|Exception|Description|
|---|---|
|**SystemExit**|If sign in was not successful|
2023-10-16 15:36:31 +01:00
### execute
2023-10-11 09:49:06 +01:00
```python
def execute()
```
2023-10-16 15:36:31 +01:00
Execute the bot. This method calls start internally. To enable you run your bot outside of an async function.
### start
2023-10-11 09:49:06 +01:00
```python
async def start()
```
Starts the bot by calling the initialize method and running the strategies in the executor.
2023-10-16 15:36:31 +01:00
### add_coroutine
```python
def add_coroutine(coro: Coroutine, **kwargs)
```
#### Arguments:
|Name|Type|Description|
|---|---|---|
|**coro**|**Coroutine**|A coroutine to run in the executor|
2023-10-11 09:49:06 +01:00
2023-10-16 15:36:31 +01:00
### add_function
```python
def add_coroutine(func: Callable, **kwargs)
```
#### Arguments:
| Name | Type | Description |
|----------|--------------|-----------------------------------|
| **func** | **Callable** | A function to run in the executor |
### add_strategy
2023-10-11 09:49:06 +01:00
```python
def add_strategy(strategy: Strategy)
```
Add a strategy to the executor. An added strategy will only run if it's symbol was successfully initialized.
2023-10-16 15:36:31 +01:00
#### Arguments:
2023-10-11 09:49:06 +01:00
|Name|Type|Description|
|---|---|---|
|**strategy**|**Strategy**|A Strategy instance to run on bot|
2023-10-16 15:36:31 +01:00
### add_strategies
2023-10-11 09:49:06 +01:00
```python
def add_strategies(strategies: Iterable[Strategy])
```
Add multiple strategies at the same time
2023-10-16 15:36:31 +01:00
#### Arguments:
2023-10-11 09:49:06 +01:00
|Name|Type|Description|
|---|---|---|
|**strategies**|**Iterable[Strategy]**|An iterable of Strategy instances|
2023-10-16 15:36:31 +01:00
### add_strategy_all
2023-10-11 09:49:06 +01:00
```python
def add_strategy_all(*, strategy: Type[Strategy], params: dict | None = None)
```
Use this to run a single strategy on all available instruments in the market using the default parameters
i.e one set of parameters for all trading symbols
2023-10-16 15:36:31 +01:00
#### Arguments
2023-10-11 09:49:06 +01:00
|Name|Type|Description|
|---|---|---|
|**strategy**|**Type[Strategy]**|A Strategy class|
|**params**|**dict** or **None**|A dictionary of parameters for the strategy|
2023-10-16 15:36:31 +01:00
### init_symbols
2023-10-11 09:49:06 +01:00
```python
async def init_symbols()
```
Initialize the symbols for the current trading session. This method is called internally by the bot.
2023-10-16 15:36:31 +01:00
### init_symbol
2023-10-11 09:49:06 +01:00
```python
async def init_symbol(symbol: Symbol) -> Symbol
```
Initialize a symbol before the beginning of a trading session.
Removes it from the list of symbols if it was not successfully initialized or not available
for the account.
2023-10-16 15:36:31 +01:00
#### Arguments:
2023-10-11 09:49:06 +01:00
|Name|Type|Description|
|---|---|---|
|**symbol**|**Symbol**|A Symbol instance|
2023-10-16 15:36:31 +01:00
#### Returns:
2023-10-11 09:49:06 +01:00
|Type|Description|
|---|---|
|**Symbol**|A Symbol instance|