Optional numeric return head (predicts percent change for 1s,1m,1h,1d)
This commit is contained in:
@@ -215,7 +215,7 @@ class TimeframeInferenceCoordinator:
|
||||
await asyncio.sleep(1.0) # Wait longer on error
|
||||
|
||||
async def _hourly_inference_scheduler(self):
|
||||
"""Scheduler for hourly multi-timeframe inference"""
|
||||
"""Scheduler for hourly multi-timeframe inference and timeframe-boundary triggers"""
|
||||
logger.info("Starting hourly inference scheduler")
|
||||
|
||||
while self.running:
|
||||
@@ -231,6 +231,17 @@ class TimeframeInferenceCoordinator:
|
||||
next_hour = current_time.replace(minute=0, second=0, microsecond=0) + timedelta(hours=1)
|
||||
self.next_hourly_inference[symbol] = next_hour
|
||||
self.last_hourly_inference[symbol] = current_time
|
||||
|
||||
# Trigger at each new timeframe boundary: 1m, 1h, 1d
|
||||
if current_time.second == 0:
|
||||
# New minute
|
||||
await self._execute_boundary_inference(symbol, current_time, TimeFrame.MINUTES_1)
|
||||
if current_time.minute == 0 and current_time.second == 0:
|
||||
# New hour
|
||||
await self._execute_boundary_inference(symbol, current_time, TimeFrame.HOURS_1)
|
||||
if current_time.hour == 0 and current_time.minute == 0 and current_time.second == 0:
|
||||
# New day
|
||||
await self._execute_boundary_inference(symbol, current_time, TimeFrame.DAYS_1)
|
||||
|
||||
# Sleep for 30 seconds between checks
|
||||
await asyncio.sleep(30)
|
||||
@@ -238,6 +249,21 @@ class TimeframeInferenceCoordinator:
|
||||
except Exception as e:
|
||||
logger.error(f"Error in hourly inference scheduler: {e}")
|
||||
await asyncio.sleep(60) # Wait longer on error
|
||||
|
||||
async def _execute_boundary_inference(self, symbol: str, timestamp: datetime, timeframe: TimeFrame):
|
||||
"""Execute an inference exactly at timeframe boundary"""
|
||||
try:
|
||||
context = InferenceContext(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
timestamp=timestamp,
|
||||
target_timeframe=timeframe,
|
||||
is_hourly_inference=False,
|
||||
inference_type="boundary"
|
||||
)
|
||||
await self._execute_inference(context)
|
||||
except Exception as e:
|
||||
logger.debug(f"Boundary inference error for {symbol} {timeframe.value}: {e}")
|
||||
|
||||
async def _execute_hourly_inference(self, symbol: str, timestamp: datetime):
|
||||
"""
|
||||
@@ -327,6 +353,7 @@ class TimeframeInferenceCoordinator:
|
||||
try:
|
||||
# Update price cache if data provider available
|
||||
if self.data_provider:
|
||||
# DataProvider.get_current_price is synchronous; do not await
|
||||
await self._update_price_cache()
|
||||
|
||||
# Evaluate predictions and get training data
|
||||
@@ -352,7 +379,7 @@ class TimeframeInferenceCoordinator:
|
||||
for symbol in self.symbols:
|
||||
# Get current price from data provider
|
||||
if hasattr(self.data_provider, 'get_current_price'):
|
||||
current_price = await self.data_provider.get_current_price(symbol)
|
||||
current_price = self.data_provider.get_current_price(symbol)
|
||||
if current_price:
|
||||
self.reward_calculator.update_price(symbol, current_price)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user