StrategyInput#
API documentation for tradeexecutor.strategy.pandas_trader.strategy_input.StrategyInput Python class in Trading Strategy framework.
- class StrategyInput[source]#
Bases:
object
Inputs for a trading decision.
The data structure used to make trade decisions. Captures all values that need to go to a single trade, under different live and backtesting circumstances.
Inputs for decide_trades function
Enabled when trading_strategy_engine_version = “0.5” or higher
- __init__(cycle, timestamp, state, strategy_universe, parameters, indicators, pricing_model, execution_context, other_data, web3=None)#
- Parameters:
cycle (int) –
timestamp (Timestamp) –
state (State) –
strategy_universe (TradingStrategyUniverse) –
parameters (StrategyParameters) –
indicators (StrategyInputIndicators) –
pricing_model (PricingModel) –
execution_context (ExecutionContext) –
other_data (dict) –
web3 (web3.main.Web3 | None) –
- Return type:
None
Methods
__init__
(cycle, timestamp, state, ...[, web3])Get the default trading pair for this stragegy.
Create a position manager instance to open/close trading positions in this decision cycle.
Should we render any visualisation or not.
Attributes
Web3 connection to the blockchain.
Strategy cycle number
Timestamp of this strategy cycle
The current state of a strategy
The source trading universe for this strategy run
Parameters used for this backtest or live run
All indicators that are precalculated with create_indicators()
Asset pricing model.
Information about whether this is live or backtest run.
Diagnostics and debug data
- timestamp: Timestamp#
Timestamp of this strategy cycle
Timestamp can/should only access earlier data and cannot peek into the future
Always in UTC, no timezone
- state: State#
The current state of a strategy
You can peek for open/closed positions
Use
get_position_manager()
to access
- strategy_universe: TradingStrategyUniverse#
The source trading universe for this strategy run
- parameters: StrategyParameters#
Parameters used for this backtest or live run
- indicators: StrategyInputIndicators#
All indicators that are precalculated with create_indicators()
Indicators calculated in create_indicators function
Cached in backtesting for fast reader
In livee trading recalculated for every cycle
- pricing_model: PricingModel#
Asset pricing model.
Used to determine the position size and value of trades
Backtesting uses historical pricing whereas live trading will read any data directly on-chain
Access using
get_position_manager()
- execution_context: ExecutionContext#
Information about whether this is live or backtest run.
- other_data: dict#
Diagnostics and debug data
Undefined format
Mostly used in internal testing and logging
Is mutated in-place, but don’t rely on this to work for live strategies
- web3: web3.main.Web3 | None = None#
Web3 connection to the blockchain.
For live trading only, to be used in real-time decision making based on onchain-data.
- get_position_manager()[source]#
Create a position manager instance to open/close trading positions in this decision cycle.
- Return type:
- get_default_pair()[source]#
Get the default trading pair for this stragegy.
Works only for single pair strateiges
- Raises:
InvalidForMultipairStrategy – If called for a multi pair strategy
- Return type:
- is_visualisation_enabled()[source]#
Should we render any visualisation or not.
Use this function inside decide_trades() to figure out if state.visualisation should be filled in
Disabled for grid seach to optimise grid search speed, as the visualisation results would be likely be discarded
Example:
def decide_trades(input: StrategyInput): # ... # # Visualisations # if input.is_visualisation_enabled(): visualisation = state.visualisation # Helper class to visualise strategy output visualisation.plot_indicator( timestamp, f"ETH", PlotKind.technical_indicator_detached, current_price[eth_pair], colour="blue", ) # Draw BTC + ETH RSI between its trigger zones for this pair of we got a valid value for RSI for this pair # BTC RSI daily if pd.notna(current_rsi_values[btc_pair]): visualisation.plot_indicator( timestamp, f"RSI", PlotKind.technical_indicator_detached, current_rsi_values[btc_pair], colour="orange", )
- Return type:
- __init__(cycle, timestamp, state, strategy_universe, parameters, indicators, pricing_model, execution_context, other_data, web3=None)#
- Parameters:
cycle (int) –
timestamp (Timestamp) –
state (State) –
strategy_universe (TradingStrategyUniverse) –
parameters (StrategyParameters) –
indicators (StrategyInputIndicators) –
pricing_model (PricingModel) –
execution_context (ExecutionContext) –
other_data (dict) –
web3 (web3.main.Web3 | None) –
- Return type:
None