new__training
This commit is contained in:
@ -500,9 +500,38 @@ class DataProvider:
|
||||
return pd.DataFrame()
|
||||
|
||||
def get_current_price(self, symbol: str) -> Optional[float]:
|
||||
"""Get current price for a symbol"""
|
||||
with self.data_lock:
|
||||
return self.current_prices.get(symbol)
|
||||
"""Get current price for a symbol from latest candle"""
|
||||
try:
|
||||
# Try to get from 1s candle first (most recent)
|
||||
for tf in ['1s', '1m', '5m', '1h']:
|
||||
df = self.get_latest_candles(symbol, tf, limit=1)
|
||||
if df is not None and not df.empty:
|
||||
return float(df.iloc[-1]['close'])
|
||||
|
||||
# Fallback to any available data
|
||||
key = f"{symbol}_{self.timeframes[0]}"
|
||||
if key in self.historical_data and not self.historical_data[key].empty:
|
||||
return float(self.historical_data[key].iloc[-1]['close'])
|
||||
|
||||
logger.warning(f"No price data available for {symbol}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting current price for {symbol}: {e}")
|
||||
return None
|
||||
|
||||
def get_price_at_index(self, symbol: str, index: int, timeframe: str = '1m') -> Optional[float]:
|
||||
"""Get price at specific index for backtesting"""
|
||||
try:
|
||||
key = f"{symbol}_{timeframe}"
|
||||
if key in self.historical_data:
|
||||
df = self.historical_data[key]
|
||||
if 0 <= index < len(df):
|
||||
return float(df.iloc[index]['close'])
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting price at index {index}: {e}")
|
||||
return None
|
||||
|
||||
def get_feature_matrix(self, symbol: str, timeframes: List[str] = None,
|
||||
window_size: int = 20) -> Optional[np.ndarray]:
|
||||
|
Reference in New Issue
Block a user