TradingStrategyUniverseModel#

API documentation for tradeexecutor.strategy.trading_strategy_universe.TradingStrategyUniverseModel Python class in Trading Strategy framework.

class TradingStrategyUniverseModel[source]#

Bases: UniverseModel

A universe constructor that builds the trading universe data using Trading Strategy client.

On a live exeuction, trade universe is reconstructor for the every tick, by refreshing the trading data from the server.

__init__(client, timed_task_context_manager)[source]#
Parameters:

Methods

__init__(client, timed_task_context_manager)

check_data_age(ts, universe, ...)

Check if our data is up-to-date and we do not have issues with feeds.

construct_universe(ts, mode, options)

On each strategy tick, refresh/recreate the trading universe for the strategy.

create_from_dataset(dataset, chains, ...[, ...])

Create an trading universe from dataset with zero filtering for the data.

load_data(time_frame, mode[, ...])

Loads the server-side data using the client.

log_universe(universe)

Log the state of the current universe.]

preload_universe(universe_options[, ...])

Triggered before backtesting execution.

__init__(client, timed_task_context_manager)[source]#
Parameters:
log_universe(universe)[source]#

Log the state of the current universe.]

Parameters:

universe (Universe) –

load_data(time_frame, mode, backtest_stop_loss_time_frame=None)[source]#

Loads the server-side data using the client.

Parameters:
  • client – Client instance. Note that this cannot be stable across ticks, as e.g. API keys can change. Client is recreated for every tick.

  • mode (ExecutionMode) – Live trading or vacktesting

  • backtest_stop_loss_time_frame (Optional[TimeBucket]) – Load more granular data for backtesting stop loss

  • time_frame (TimeBucket) –

Returns:

None if not dataset for the strategy required

Return type:

Dataset

check_data_age(ts, universe, best_before_duration)[source]#

Check if our data is up-to-date and we do not have issues with feeds.

Ensure we do not try to execute live trades with stale data.

Raises:

DataTooOld – in the case data is too old to execute.

Returns:

The data timestamp

Parameters:
Return type:

datetime

static create_from_dataset(dataset, chains, reserve_assets, pairs_index=True)[source]#

Create an trading universe from dataset with zero filtering for the data.

Parameters:
abstract construct_universe(ts, mode, options)[source]#

On each strategy tick, refresh/recreate the trading universe for the strategy.

This is called in mainloop before the strategy tick. It needs to download any data updates since the last tick.

Parameters:
  • mode (ExecutionMode) – Are we live trading or backtesting.

  • universe_options – Override any parameters for universe data. Most useful for making stop loss data checks less frequent, speeding up the backtesting.

  • ts (datetime) –

  • options (UniverseOptions) –

Return type:

TradingStrategyUniverse