StrategyModuleInformation#
API documentation for tradeexecutor.strategy.strategy_module.StrategyModuleInformation Python class in Trading Strategy framework.
- class StrategyModuleInformation[source]#
Bases:
object
Describe elements that we need to have in a strategy module.
The class variables are the same name as found in the Python strategy module. They can be uppercase or lowercase - all strategy module variables are exported as lowercase.
- __init__(path, source_code, trading_strategy_engine_version, trading_strategy_type, trading_strategy_cycle, decide_trades, create_trading_universe, create_indicators, trade_routing=None, chain_id=None, reserve_currency=None, backtest_start=None, backtest_end=None, initial_cash=None, name=None, short_description=None, long_description=None, icon=None, tags=None, sort_priority=0, parameters=None, management_fee=None, trading_strategy_protocol_fee=None, strategy_developer_fee=None)#
- Parameters:
path (Path) –
trading_strategy_engine_version (str) –
trading_strategy_type (StrategyType) –
trading_strategy_cycle (CycleDuration) –
decide_trades (tradeexecutor.strategy.strategy_module.DecideTradesProtocol | tradeexecutor.strategy.strategy_module.DecideTradesProtocol2) –
create_trading_universe (CreateTradingUniverseProtocol) –
create_indicators (tradeexecutor.strategy.pandas_trader.indicator.CreateIndicatorsProtocolV1 | tradeexecutor.strategy.pandas_trader.indicator.CreateIndicatorsProtocolV2) –
trade_routing (Optional[TradeRouting]) –
reserve_currency (Optional[ReserveCurrency]) –
tags (Optional[Set[StrategyTag]]) –
sort_priority (int) –
parameters (Optional[Union[Type, StrategyParameters]]) –
- Return type:
None
Methods
__init__
(path, source_code, ...[, ...])Get the primary chain id for this strategy module.
Get the required history timespan we need to load for each live trading cycle.
get_max_price_impact
()get_universe_options
([mode])What backtest range or live trading history period this strategy defaults to.
is_version_greater_or_equal_than
(major, ...)Check strategy module for its version compatibility.
unpack_strategy_parameters
(strategy_parameters)Load strategy module parameters from StrategyParameters class.
validate
()Check that the user inputted variable names look good.
Validate that the module is backtest runnable.
Attributes
Only needed for backtests
Only needed for backtests
Blockchain id on which this strategy operates
Strategy icon
Only needed for backtests
Strategy long description
Fees for the strategy.
Strategy name
StrategyParameters class.
What currency we use for the strategy.
Strategy short description
The display priority for this strategy.
strategy_developer_fee
Any tags on the strategy.
Routing hinting.
trading_strategy_protocol_fee
Path to the module
The source code of the strategy
The engine version this strategy requires.
Enable different strategy scripts.
trading_strategy_cycle
decide_trades
If execution_context.live_trading is true then this function is called for every execution cycle.
A function to prepare strategy indicators
- source_code: Optional[str]#
The source code of the strategy
Can be set None for strategies that are not public.
- trading_strategy_engine_version: str#
The engine version this strategy requires.
Function signatures and results may be changed depending on for engine version the strategy is for.
See
SUPPORTED_TRADING_STRATEGY_ENGINE_VERSIONS
.
- trading_strategy_type: StrategyType#
Enable different strategy scripts.
If not set default to
StrategyType.managed_positions
.
- create_trading_universe: CreateTradingUniverseProtocol#
If execution_context.live_trading is true then this function is called for every execution cycle. If we are backtesting, then this function is called only once at the start of backtesting and the decide_trades need to deal with new and deprecated trading pairs.
- create_indicators: tradeexecutor.strategy.pandas_trader.indicator.CreateIndicatorsProtocolV1 | tradeexecutor.strategy.pandas_trader.indicator.CreateIndicatorsProtocolV2#
A function to prepare strategy indicators
create_indicators() was added in engiver version 0.5
- trade_routing: Optional[TradeRouting] = None#
Routing hinting.
Legacy option: most strategies can set this in
create_trading_universe()
. Default toTradeRouting.default
.
- chain_id: Optional[ChainId] = None#
Blockchain id on which this strategy operates
Valid for single chain strategies only
Legacy. DO NOT USE. Use
get_default_chain_id()
instead.
- reserve_currency: Optional[ReserveCurrency] = None#
What currency we use for the strategy.
Can be left out in new versions and is set in
create_trading_universe()
- name: Optional[str] = None#
Strategy name
Note that this must be also separately configured in the frontend user interface, as name is used before the strategy metadata is loaded.
- long_description: Optional[str] = None#
Strategy long description
Two paragraph description, may contain HTML.
- tags: Optional[Set[StrategyTag]] = None#
Any tags on the strategy.
Set for
tags
attribute of a strategy module.
- sort_priority: int = 0#
The display priority for this strategy.
Higher = the strategy apppears in the frontend first.
- parameters: Optional[Union[Type, StrategyParameters]] = None#
StrategyParameters class.
trading_strategy_engine_version > “0.5”
Converted to StrategyParameters attributed dict after loading.
See
StrategyParameters
.
- is_version_greater_or_equal_than(major, minor, patch)[source]#
Check strategy module for its version compatibility.
- unpack_strategy_parameters(strategy_parameters)[source]#
Load strategy module parameters from StrategyParameters class.
trading_strategy_engive > “0.5”
- Parameters:
strategy_parameters (StrategyParameters) –
- validate()[source]#
Check that the user inputted variable names look good.
- Raises:
StrategyModuleNotValid – If we could not load/parse strategy module for some reason
- get_universe_options(mode=None)[source]#
What backtest range or live trading history period this strategy defaults to.
- Parameters:
mode (tradeexecutor.strategy.execution_context.ExecutionMode | None) –
- Return type:
- get_live_trading_history_period()[source]#
Get the required history timespan we need to load for each live trading cycle.
See
tradeexecutor.strategy.parameters.StrategyParameters.required_history_period
.- Returns:
None if not defined.
Legacy strategy modules do not define this.
- Return type:
datetime.timedelta | None
- __init__(path, source_code, trading_strategy_engine_version, trading_strategy_type, trading_strategy_cycle, decide_trades, create_trading_universe, create_indicators, trade_routing=None, chain_id=None, reserve_currency=None, backtest_start=None, backtest_end=None, initial_cash=None, name=None, short_description=None, long_description=None, icon=None, tags=None, sort_priority=0, parameters=None, management_fee=None, trading_strategy_protocol_fee=None, strategy_developer_fee=None)#
- Parameters:
path (Path) –
trading_strategy_engine_version (str) –
trading_strategy_type (StrategyType) –
trading_strategy_cycle (CycleDuration) –
decide_trades (tradeexecutor.strategy.strategy_module.DecideTradesProtocol | tradeexecutor.strategy.strategy_module.DecideTradesProtocol2) –
create_trading_universe (CreateTradingUniverseProtocol) –
create_indicators (tradeexecutor.strategy.pandas_trader.indicator.CreateIndicatorsProtocolV1 | tradeexecutor.strategy.pandas_trader.indicator.CreateIndicatorsProtocolV2) –
trade_routing (Optional[TradeRouting]) –
reserve_currency (Optional[ReserveCurrency]) –
tags (Optional[Set[StrategyTag]]) –
sort_priority (int) –
parameters (Optional[Union[Type, StrategyParameters]]) –
- Return type:
None