3.8 KiB
backtester
BackTester Objects
class BackTester()
The bot class. Create a bot instance to run your strategies.
Attributes:
executor- The default thread executor.configConfig - Config instancemtMetaBackTester - MetaTrader instance
initialize_sync
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
initialize
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
add_coroutine
def add_coroutine(*,
coroutine: Callable[..., ...] | Coroutine,
on_separate_thread=False,
**kwargs)
Add a coroutine to the executor.
Arguments:
coroutineCoroutine - A coroutine to be executedon_separate_threadbool - Run the coroutine**kwargsdict - keyword arguments for the coroutine
execute
def execute()
Execute the bot.
start
async def start()
Initialize the bot and execute it. Similar to calling execute method but is a coroutine.
add_strategy
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:
strategyStrategy - A Strategy instance to run on bot
Notes:
Make sure the symbol has been added to the market
add_strategies
def add_strategies(*, strategies: Iterable[Strategy])
Add multiple strategies at the same time
Arguments:
strategies- A list of strategies
add_strategy_all
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:
strategyStrategy - Strategy classparamsdict - A dictionary of parameters for the strategysymbolslist - A list of symbols to run the strategy on**kwargs- Additional keyword arguments for the strategy
init_strategy
async def init_strategy(*, strategy: Strategy) -> bool
Initialize a single strategy. This method is called internally by the bot.
init_strategy_sync
def init_strategy_sync(*, strategy: Strategy) -> bool
Initialize a single strategy. This method is called internally by the bot.
init_strategies
async def init_strategies()
Initialize the symbols for the current trading session. This method is called internally by the bot.
init_strategies_sync
def init_strategies_sync()
Initialize the symbols for the current trading session. This method is called internally by the bot.