ExecutionContext#
API documentation for tradeexecutor.strategy.execution_context.ExecutionContext Python class in Trading Strategy framework.
- class ExecutionContext[source]#
Bases:
object
Information about the strategy execution environment.
This is passed to create_trading_universe and couple of other functions and they can determine and take action based the mode of strategy execution. For example, we may load pair and candle data differently in live trading.
Example how to create for backtests:
from tradeexecutor.strategy.execution_context import ExecutionContext, ExecutionMode execution_context = ExecutionContext( mode=ExecutionMode.backtesting, )
See also
unit_test_execution_context
notebook_execution_context
- __init__(mode, timed_task_context_manager=<function timed_task>, engine_version=None, parameters=None, grid_search=False)#
- Parameters:
mode (ExecutionMode) –
timed_task_context_manager (Callable) –
parameters (Optional[StrategyParameters]) –
grid_search (bool) –
- Return type:
None
Methods
__init__
(mode[, timed_task_context_manager, ...])is_version_greater_or_equal_than
(major, ...)Check that we are runing engine as the minimum required version.
timed_task_context_manager
(**context_info)A simple context manger to measure the duration of different tasks.
Attributes
What TS engine the strategy is using.
Is this backtest run part of a grid search group
Are we doing live trading.
Strategy parameters
unit_test
What is the current mode of the execution.
- mode: ExecutionMode#
What is the current mode of the execution.
- timed_task_context_manager(**context_info)#
Python context manager for timed tasks.
Functions can use this context manager to add them to the tracing. Used for profiling the strategy code run-time performance.
Set default to
tradeexecutor.utils.timer.timed_task()
. which logs task duration using logging.INFO level.- Parameters:
task_name (str) –
- Return type:
AbstractContextManager[None]
- parameters: tradeexecutor.strategy.parameters.StrategyParameters | None = None#
Strategy parameters
For backtesting/grid search cycle.
v0.4 only
- is_version_greater_or_equal_than(major, minor, patch)[source]#
Check that we are runing engine as the minimum required version.
- property live_trading: bool#
Are we doing live trading.
This is a bit trickier, as live trading itself can have different phases with different execution modes.
- Returns:
- True if we doing live trading or paper trading.
False if we are operating on backtesting data.
- __init__(mode, timed_task_context_manager=<function timed_task>, engine_version=None, parameters=None, grid_search=False)#
- Parameters:
mode (ExecutionMode) –
timed_task_context_manager (Callable) –
parameters (Optional[StrategyParameters]) –
grid_search (bool) –
- Return type:
None