|
6 | 6 |
|
7 | 7 | from investing_algorithm_framework.domain import OperationalException, \ |
8 | 8 | Position, PositionSize, TimeUnit, StrategyProfile, Trade, \ |
9 | | - DataSource, OrderSide, StopLossRule, TakeProfitRule, Order, \ |
| 9 | + DataSource, DataType, OrderSide, StopLossRule, TakeProfitRule, Order, \ |
10 | 10 | INDEX_DATETIME |
11 | 11 | from .context import Context |
12 | 12 |
|
@@ -156,6 +156,32 @@ def __init__( |
156 | 156 | f"Interval not set for strategy instance {self.strategy_id}" |
157 | 157 | ) |
158 | 158 |
|
| 159 | + # Check if scheduling interval is faster than the smallest |
| 160 | + # OHLCV data source timeframe |
| 161 | + ohlcv_timeframes = [ |
| 162 | + ds.time_frame.amount_of_minutes |
| 163 | + for ds in self.data_sources |
| 164 | + if ds.time_frame is not None |
| 165 | + and DataType.OHLCV.equals(ds.data_type) |
| 166 | + ] |
| 167 | + |
| 168 | + if ohlcv_timeframes: |
| 169 | + scheduling_interval = \ |
| 170 | + self.time_unit.amount_of_minutes * self.interval |
| 171 | + smallest_timeframe = min(ohlcv_timeframes) |
| 172 | + |
| 173 | + if scheduling_interval < smallest_timeframe: |
| 174 | + raise OperationalException( |
| 175 | + f"Strategy '{self.strategy_id}' scheduling interval " |
| 176 | + f"({self.interval} {self.time_unit.value.lower()}" |
| 177 | + f"{'s' if self.interval > 1 else ''}" |
| 178 | + f" = {scheduling_interval} min) is faster than " |
| 179 | + f"the smallest OHLCV data source timeframe " |
| 180 | + f"({smallest_timeframe} min). The strategy would " |
| 181 | + f"run without new data. Increase the scheduling " |
| 182 | + f"interval or use a smaller data timeframe." |
| 183 | + ) |
| 184 | + |
159 | 185 | # Initialize stop_losses as a new list per instance |
160 | 186 | if stop_losses is not None: |
161 | 187 | self.stop_losses = list(stop_losses) |
|
0 commit comments