PandasTraderRunner#
API documentation for tradeexecutor.strategy.pandas_trader.runner.PandasTraderRunner Python class in Trading Strategy framework.
- class PandasTraderRunner[source]#
Bases:
StrategyRunner
A trading executor for Pandas math based algorithm.
- __init__(*args, decide_trades, max_data_age=None, **kwargs)[source]#
- Parameters:
engine_version –
Strategy execution version.
Changes function arguments based on this. See StrategyModuleInformation.trading_strategy_engine_version.
decide_trades (tradeexecutor.strategy.strategy_module.DecideTradesProtocol | tradeexecutor.strategy.strategy_module.DecideTradesProtocol2) –
Methods
__init__
(*args, decide_trades[, max_data_age])- param engine_version:
check_accounts
(universe, state[, ...])Perform extra accounting checks on live trading startup.
check_balances_post_execution
(universe, state)Check that on-chain balances matches our internal accounting after executing trades.
check_position_triggers
(clock, state, ...)Check stop loss/take profit for positions.
collect_post_execution_data
(...)Collect post execution data for all trades.
get_image_and_dark_image
(figure, width, height)Renders the figure as a PNG image and a dark theme PNG image.
get_large_images
(large_figure)Gets the png image of the figure and the dark theme png image.
get_small_images
(small_figure)Gets the png image of the figure and the dark theme png image.
is_progress_report_needed
()Do we log the strategy steps to logger?
on_clock
(clock, strategy_universe, ...)Run one strategy tick.
on_data_signal
()pretick_check
(ts, universe)Check the data looks more or less sane.
refresh_visualisations
(state, universe)Update the visualisations in the run state.
repair_state
(state)Repair unclean state issues.
report_after_execution
(clock, universe, ...)report_after_sync_and_revaluation
(clock, ...)report_before_execution
(clock, universe, ...)Strategy admin helpers to understand a live running strategy.
revalue_state
(ts, state, valuation_model)Revalue portfolio based on the latest prices.
setup_routing
(universe)Setups routing state for this cycle.
sync_portfolio
(...[, end_block])Adjust portfolio balances based on the external events.
tick
(strategy_cycle_timestamp, universe, ...)Execute the core functions of a strategy.
Update the strategy thinking image data with small, small dark theme, large, and large dark theme images.
- __init__(*args, decide_trades, max_data_age=None, **kwargs)[source]#
- Parameters:
engine_version –
Strategy execution version.
Changes function arguments based on this. See StrategyModuleInformation.trading_strategy_engine_version.
decide_trades (tradeexecutor.strategy.strategy_module.DecideTradesProtocol | tradeexecutor.strategy.strategy_module.DecideTradesProtocol2) –
- on_clock(clock, strategy_universe, pricing_model, state, debug_details)[source]#
Run one strategy tick.
- Parameters:
clock (datetime) –
strategy_universe (TradingStrategyUniverse) –
pricing_model (PricingModel) –
state (State) –
debug_details (dict) –
- Return type:
- pretick_check(ts, universe)[source]#
Check the data looks more or less sane.
- Parameters:
ts (datetime) –
universe (TradingStrategyUniverse) –
- refresh_visualisations(state, universe)[source]#
Update the visualisations in the run state.
This will update RunState.visualisations for the current strategy.
In-process memory charts are served by webhook
In-process memory charts are posted to Discord, etc.
This is called on the startup, so that we have immediately good visualisation to show over the webhook when the web server boots up
This is called after each strategy thinking cycle is complete.
The function is overridden by the child class for actual strategy runner specific implementation.
- Parameters:
state (State) –
universe (TradingStrategyUniverse) –
- update_strategy_thinking_image_data(small_figure, large_figure)[source]#
Update the strategy thinking image data with small, small dark theme, large, and large dark theme images.
- Parameters:
small_image – 512 x 512 image
large_image – 1920 x 1920 image
- get_small_images(small_figure)[source]#
Gets the png image of the figure and the dark theme png image. Images are 512 x 512.
- get_large_images(large_figure)[source]#
Gets the png image of the figure and the dark theme png image. Images are 1024 x 1024.
- get_image_and_dark_image(figure, width, height, format='svg')[source]#
Renders the figure as a PNG image and a dark theme PNG image.
- report_strategy_thinking(strategy_cycle_timestamp, cycle, universe, state, trades, debug_details)[source]#
Strategy admin helpers to understand a live running strategy.
Post latest variables
Draw the single pair strategy visualisation.
To manually test the visualisation see: manual-visualisation-test.py.
- Parameters:
strategy_cycle_timestamp (datetime) – real time lock
cycle (int) – Cycle number
universe (TradingStrategyUniverse) – Currnet trading universe
trades (List[TradeExecution]) – Trades executed on this cycle
state (State) – Current execution state
debug_details (dict) – Dict of random debug stuff