This commit is contained in:
Ichinga Samuel
2024-11-15 21:13:19 +01:00
parent 2a55f49f78
commit 2e7aa73aec
19 changed files with 1400 additions and 1415 deletions
+4 -3
View File
@@ -1,11 +1,11 @@
# Account
## Table of Contents
- [Account](#account.Account)
- [Account](#account.account)
- [refresh](#account.refresh)
<a id="account.Account"></a>
<a id="account.account"></a>
### Account
```python
class Account(_Base, AccountInfo)
@@ -13,11 +13,12 @@ class Account(_Base, AccountInfo)
A singleton class for managing a trading account. A subclass of _Base and AccountInfo. It supports asynchronous context
management protocol.
#### Attributes
#### Attributes:
| Name | Type | Description | Default |
|-------------|-------------------|------------------------------------------------------|---------|
| `connected` | `bool` | Status of connection to MetaTrader 5 Terminal | False |
<a id="account.refresh"></a>
### refresh
```python
+14 -6
View File
@@ -1,7 +1,7 @@
# Bot
## Table of Contents
- [Bot](#bot.Bot)
- [Bot](#bot.bot)
- [\_\_init\_\_](#bot.init)
- [initialize](#bot.initialize)
- [execute](#bot.execute)
@@ -13,14 +13,14 @@
- [add_strategy_all](#bot.add_strategy_all)
- [process_pool](#bot.run_bots)
<a id='bot.Bot'></a>
<a id='bot.bot'></a>
### Bot
```python
class Bot
```
"""The bot class. Create a bot instance to run strategies.
#### Attributes.
#### Attributes:
| Name | Type | Description | Default |
|--------------|--------------------|--------------------------------------------|--------------|
| `account` | `Account` | Account Object. | None |
@@ -30,12 +30,13 @@ class Bot
| `config` | `Config` | A Config instance | Config() |
<a id='bot.init'></a>
### \_\_init\_\_
### \__init\__
```python
def __init__()
```
Initializes the Bot class.
<a id='bot.initialize'></a>
### initialize
```python
@@ -52,7 +53,6 @@ Note: *initialize_sync* is a synchronous version of this method.
| `SystemExit` | If sign in was not successful |
<a id='bot.execute'></a>
### execute
```python
@@ -61,6 +61,7 @@ def execute()
Executes the bot. Use this method to run the bot in a synchronous manner.
This method is blocking and will not return until the bot is done running.
<a id='bot.start'></a>
### start
```python
@@ -68,13 +69,14 @@ async def start()
```
Initialize the bot and execute it. Similar to calling **execute** method but is asynchronous.
<a id='bot.add_coroutine'></a>
### add_coroutine
```python
def add_coroutine(self, coroutine: Coroutine, on_separate_thread=False, **kwargs)
```
Add a coroutine to the executor. By default, all coroutines added to the executor run on this same thread,
using _asyncio.gather_, but if _on_separate_thread_ is true then the coroutine is given it's own thread.
using `asyncio.gather`, but if `on_separate_thread` is true then the coroutine is given it's own thread.
#### Parameters:
| Name | Type | Description |
@@ -83,6 +85,7 @@ using _asyncio.gather_, but if _on_separate_thread_ is true then the coroutine i
| `on_separate_thread` | `bool` | Run coroutine on a separate thread in the executor |
| `kwargs` | `Any` | Keyword arguments to pass to the coroutine |
<a id='bot.add_function'></a>
### add_function
```python
@@ -95,6 +98,7 @@ Add a function to the executor.
| `function` | `Callable` | A function to run in the executor |
| `kwargs` | `Any` | Keyword arguments to pass to the function |
<a id='bot.add_strategy'></a>
### add_strategy
```python
@@ -107,23 +111,27 @@ Add a strategy to the list of strategies.
|------------|------------|-----------------------------------|
| `strategy` | `Strategy` | A Strategy instance to run on bot |
<a id='bot.add_strategies'></a>
### add_strategies
```python
def add_strategies(strategies: Iterable[Strategy])
```
Add multiple strategies at the same time
#### Parameters:
| Name | Type | Description |
|--------------|----------------------|-----------------------------------|
| `strategies` | `Iterable[Strategy]` | An iterable of Strategy instances |
<a id='bot.add_strategy_all'></a>
### add_strategy_all
```python
def add_strategy_all(*, strategy: Type[Strategy], params: dict | None = None, symbols: list[Symbol] = None, **kwargs)
```
Use this to run a single strategy on multiple symbols with the same parameters and keyword arguments.
#### Parameters:
| Name | Type | Description |
|------------|------------------|---------------------------------------------|
-66
View File
@@ -1,66 +0,0 @@
# Utils
Utils is a collection of utility functions that are used throughout the codebase. It is a collection of functions.
## Table of Contents
- [round_off](#round_off)
- [find_bearish_fractal](#find_bearish_fractal)
- [find_bullish_fractal](#find_bullish_fractal)
- [dict_to_string](#dict_to_string)
<a id="round_off"></a>
```python
def round_off(value: float, step: float, round_down: bool = True) -> float:
```
Rounds off a value to the nearest step. If round_down is True, it will round down, otherwise it will round up.
#### Parameters
| Name | Type | Description | Default |
|------------|-------|--------------------------------------------|---------|
| value | float | The value to round off. | |
| step | float | The step to round off to. | |
| round_down | bool | Whether to round down. If False, round up. | True |
#### Returns
| Type | Description |
|-------|------------------------|
| float | The rounded off value. |
```python
def find_bearish_fractal(candles: Candles) -> Candle | None:
```
Finds the most recent bearish fractal in the candles.
#### Parameters
| Name | Type | Description | Default |
|---------|---------|----------------------------------|---------|
| candles | Candles | The candles to search for. | |
#### Returns
| Type | Description |
|--------|----------------------------------|
| Candle | The most recent bearish fractal. |
```python
def find_bullish_fractal(candles: Candles) -> Candle | None:
```
Finds the most recent bullish fractal in the candles.
#### Parameters
| Name | Type | Description | Default |
|---------|---------|----------------------------------|---------|
| candles | Candles | The candles to search for. | |
#### Returns
| Type | Description |
|--------|----------------------------------|
| Candle | The most recent bullish fractal. |
<a id="dict_to_string"></a>
```python
def dict_to_string(data: dict, multi=True) -> str:
```
Converts a dictionary to a string. If multi is True, it will return a multi-line string.
#### Parameters
| Name | Type | Description | Default |
|-------|------|----------------------------------------|---------|
| data | dict | The dictionary to convert to a string. | |
| multi | bool | Whether to return a multi-line string. | True |
#### Returns
| Type | Description |
|------|-----------------------------|
| str | The dictionary as a string. |