TradingStrategyUniverseModel#
tradeexecutor.strategy.trading_strategy_universe.TradingStrategyUniverseModel class.
- 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
client (Client) –
timed_task_context_manager (AbstractContextManager) –
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, live)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
()Triggered before backtesting execution.
- __init__(client, timed_task_context_manager)[source]#
- Parameters
client (Client) –
timed_task_context_manager (AbstractContextManager) –
- 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
- 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.
- Parameters
ts (datetime) –
universe (TradingStrategyUniverse) –
best_before_duration (timedelta) –
- 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
dataset (Dataset) –
reserve_assets (List[AssetIdentifier]) –