mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-15 21:08:06 +00:00
v4
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
<a id="backtester"></a>
|
||||
|
||||
# backtester
|
||||
|
||||
<a id="backtester.BackTester"></a>
|
||||
|
||||
## BackTester Objects
|
||||
|
||||
```python
|
||||
class BackTester()
|
||||
```
|
||||
|
||||
The bot class. Create a bot instance to run your strategies.
|
||||
|
||||
**Attributes**:
|
||||
|
||||
- `executor` - The default thread executor.
|
||||
- `config` _Config_ - Config instance
|
||||
- `mt` _MetaBackTester_ - MetaTrader instance
|
||||
|
||||
<a id="backtester.BackTester.initialize_sync"></a>
|
||||
|
||||
#### initialize\_sync
|
||||
|
||||
```python
|
||||
def initialize_sync()
|
||||
```
|
||||
|
||||
Prepares the bot by signing in to the trading account and initializing the symbols for the trading session.
|
||||
Starts the global task queue.
|
||||
|
||||
**Raises**:
|
||||
|
||||
SystemExit if sign in was not successful
|
||||
|
||||
<a id="backtester.BackTester.initialize"></a>
|
||||
|
||||
#### initialize
|
||||
|
||||
```python
|
||||
async def initialize()
|
||||
```
|
||||
|
||||
Prepares the bot by signing in to the trading account and initializing the symbols for the trading session.
|
||||
Starts the global task queue.
|
||||
|
||||
**Raises**:
|
||||
|
||||
SystemExit if sign in was not successful
|
||||
|
||||
<a id="backtester.BackTester.add_coroutine"></a>
|
||||
|
||||
#### add\_coroutine
|
||||
|
||||
```python
|
||||
def add_coroutine(*,
|
||||
coroutine: Callable[..., ...] | Coroutine,
|
||||
on_separate_thread=False,
|
||||
**kwargs)
|
||||
```
|
||||
|
||||
Add a coroutine to the executor.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `coroutine` _Coroutine_ - A coroutine to be executed
|
||||
- `on_separate_thread` _bool_ - Run the coroutine
|
||||
- `**kwargs` _dict_ - keyword arguments for the coroutine
|
||||
|
||||
|
||||
<a id="backtester.BackTester.execute"></a>
|
||||
|
||||
#### execute
|
||||
|
||||
```python
|
||||
def execute()
|
||||
```
|
||||
|
||||
Execute the bot.
|
||||
|
||||
<a id="backtester.BackTester.start"></a>
|
||||
|
||||
#### start
|
||||
|
||||
```python
|
||||
async def start()
|
||||
```
|
||||
|
||||
Initialize the bot and execute it. Similar to calling `execute` method but is a coroutine.
|
||||
|
||||
<a id="backtester.BackTester.add_strategy"></a>
|
||||
|
||||
#### add\_strategy
|
||||
|
||||
```python
|
||||
def add_strategy(*, strategy: Strategy)
|
||||
```
|
||||
|
||||
Add a strategy to the list of strategies.
|
||||
An added strategy will only run if it's symbol was successfully initialized and it is added to the executor.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `strategy` _Strategy_ - A Strategy instance to run on bot
|
||||
|
||||
|
||||
**Notes**:
|
||||
|
||||
Make sure the symbol has been added to the market
|
||||
|
||||
<a id="backtester.BackTester.add_strategies"></a>
|
||||
|
||||
#### add\_strategies
|
||||
|
||||
```python
|
||||
def add_strategies(*, strategies: Iterable[Strategy])
|
||||
```
|
||||
|
||||
Add multiple strategies at the same time
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `strategies` - A list of strategies
|
||||
|
||||
<a id="backtester.BackTester.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.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `strategy` _Strategy_ - Strategy class
|
||||
- `params` _dict_ - A dictionary of parameters for the strategy
|
||||
- `symbols` _list_ - A list of symbols to run the strategy on
|
||||
- `**kwargs` - Additional keyword arguments for the strategy
|
||||
|
||||
<a id="backtester.BackTester.init_strategy"></a>
|
||||
|
||||
#### init\_strategy
|
||||
|
||||
```python
|
||||
async def init_strategy(*, strategy: Strategy) -> bool
|
||||
```
|
||||
|
||||
Initialize a single strategy. This method is called internally by the bot.
|
||||
|
||||
<a id="backtester.BackTester.init_strategy_sync"></a>
|
||||
|
||||
#### init\_strategy\_sync
|
||||
|
||||
```python
|
||||
def init_strategy_sync(*, strategy: Strategy) -> bool
|
||||
```
|
||||
|
||||
Initialize a single strategy. This method is called internally by the bot.
|
||||
|
||||
<a id="backtester.BackTester.init_strategies"></a>
|
||||
|
||||
#### init\_strategies
|
||||
|
||||
```python
|
||||
async def init_strategies()
|
||||
```
|
||||
|
||||
Initialize the symbols for the current trading session. This method is called internally by the bot.
|
||||
|
||||
<a id="backtester.BackTester.init_strategies_sync"></a>
|
||||
|
||||
#### init\_strategies\_sync
|
||||
|
||||
```python
|
||||
def init_strategies_sync()
|
||||
```
|
||||
|
||||
Initialize the symbols for the current trading session. This method is called internally by the bot.
|
||||
|
||||
+11
-3
@@ -3,8 +3,9 @@ The base class for creating strategies.
|
||||
|
||||
## Table of Contents
|
||||
- [Strategy](#strategy.strategy)
|
||||
- [\_\_init\_\_](#strategy.__init__)
|
||||
- [\__init\__](#strategy.__init__)
|
||||
- [sleep](#strategy.sleep)
|
||||
- [delay](#strategy.delay)
|
||||
- [live_sleep](#strategy.live_sleep)
|
||||
- [backtest_sleep](#strategy.backtest_sleep)
|
||||
- [run_strategy](#strategy.run_strategy)
|
||||
@@ -54,8 +55,7 @@ Initiate the parameters dict and add name and symbol fields. Use class name as s
|
||||
<a id="strategy.sleep"></a>
|
||||
### sleep
|
||||
```python
|
||||
@staticmethod
|
||||
async def sleep(secs: float)
|
||||
async def sleep(*, secs: float)
|
||||
```
|
||||
Sleep for the needed amount of seconds in between requests to the terminal.
|
||||
computes the accurate amount of time needed to sleep ensuring that the next request is made at the start of
|
||||
@@ -68,6 +68,14 @@ This method calls the `live_sleep` method during live trading or `backtest_sleep
|
||||
| `secs` | `float` | The time in seconds. Usually the timeframe you are trading on. | None |
|
||||
|
||||
|
||||
<a id="strategy.delay"></a>
|
||||
### delay
|
||||
```python
|
||||
async def delay(*, secs: float)
|
||||
```
|
||||
Sleep for the needed amount of seconds specified in the parameter.
|
||||
|
||||
|
||||
<a id="strategy.live_sleep"></a>
|
||||
### live_sleep
|
||||
```python
|
||||
|
||||
Reference in New Issue
Block a user