stats, standartized data provider

This commit is contained in:
Dobromir Popov
2025-07-28 08:35:08 +03:00
parent 6efaa27c33
commit 240d2b7877
3 changed files with 220 additions and 58 deletions

View File

@ -1076,7 +1076,7 @@ class CleanTradingDashboard:
return [html.I(className="fas fa-save me-1"), "Store All Models"]
def _get_current_price(self, symbol: str) -> Optional[float]:
"""Get current price for symbol - ENHANCED with better fallbacks"""
"""Get current price for symbol - ONLY using our data providers"""
try:
# Try WebSocket cache first
ws_symbol = symbol.replace('/', '')
@ -1099,6 +1099,16 @@ class CleanTradingDashboard:
except Exception as dp_error:
logger.debug(f"Data provider get_current_price failed: {dp_error}")
# Try data provider get_live_price_from_api method (our standardized method)
if hasattr(self.data_provider, 'get_live_price_from_api'):
try:
price = self.data_provider.get_live_price_from_api(symbol)
if price and price > 0:
self.current_prices[symbol] = price
return price
except Exception as live_error:
logger.debug(f"Data provider get_live_price_from_api failed: {live_error}")
# Fallback to dashboard current prices
if symbol in self.current_prices and self.current_prices[symbol] > 0:
return self.current_prices[symbol]
@ -1127,34 +1137,18 @@ class CleanTradingDashboard:
self.current_prices[symbol] = price
logger.debug(f"Got current price for {symbol} from orchestrator: ${price:.2f}")
return price
# Try orchestrator's live price method
if hasattr(self.orchestrator.data_provider, 'get_live_price_from_api'):
price = self.orchestrator.data_provider.get_live_price_from_api(symbol)
if price and price > 0:
self.current_prices[symbol] = price
logger.debug(f"Got current price for {symbol} from orchestrator live API: ${price:.2f}")
return price
except Exception as orch_error:
logger.debug(f"Failed to get price from orchestrator: {orch_error}")
# Try external API as last resort
try:
import requests
if symbol == 'ETH/USDT':
response = requests.get('https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT', timeout=2)
if response.status_code == 200:
data = response.json()
price = float(data['price'])
if price > 0:
self.current_prices[symbol] = price
logger.debug(f"Got current price for {symbol} from Binance API: ${price:.2f}")
return price
elif symbol == 'BTC/USDT':
response = requests.get('https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT', timeout=2)
if response.status_code == 200:
data = response.json()
price = float(data['price'])
if price > 0:
self.current_prices[symbol] = price
logger.debug(f"Got current price for {symbol} from Binance API: ${price:.2f}")
return price
except Exception as api_error:
logger.debug(f"External API failed: {api_error}")
logger.warning(f"Could not get current price for {symbol} from any source")
logger.warning(f"Could not get current price for {symbol} from any data provider source")
except Exception as e:
logger.error(f"Error getting current price for {symbol}: {e}")
@ -1163,12 +1157,7 @@ class CleanTradingDashboard:
if symbol in self.current_prices and self.current_prices[symbol] > 0:
return self.current_prices[symbol]
# Return a reasonable fallback based on current market conditions
if symbol == 'ETH/USDT':
return 3385.0 # Current market price fallback
elif symbol == 'BTC/USDT':
return 119500.0 # Current market price fallback
# Return None instead of hardcoded fallbacks - let the UI handle missing data
return None
def _create_price_chart(self, symbol: str) -> go.Figure: