浏览代码

Enhance market data retrieval in HyperliquidClient by including 24h OHLCV data for accurate high/low values in the ticker. Update MarketCommands to calculate the spread using ticker bid and ask prices for improved clarity in order book information.

Carles Sentis 4 天之前
父节点
当前提交
f25c81c0df
共有 3 个文件被更改,包括 16 次插入5 次删除
  1. 10 1
      src/clients/hyperliquid_client.py
  2. 5 3
      src/commands/info/market.py
  3. 1 1
      trading_bot.py

+ 10 - 1
src/clients/hyperliquid_client.py

@@ -256,7 +256,7 @@ class HyperliquidClient:
             return None
             return None
     
     
     def get_market_data(self, symbol: str) -> Optional[Dict[str, Any]]:
     def get_market_data(self, symbol: str) -> Optional[Dict[str, Any]]:
-        """Get market data for a symbol."""
+        """Get market data for a symbol, including OHLCV for high/low."""
         try:
         try:
             if not self.sync_client:
             if not self.sync_client:
                 logger.error("❌ Client not initialized")
                 logger.error("❌ Client not initialized")
@@ -265,6 +265,15 @@ class HyperliquidClient:
             ticker = self.sync_client.fetch_ticker(symbol)
             ticker = self.sync_client.fetch_ticker(symbol)
             orderbook = self.sync_client.fetch_order_book(symbol)
             orderbook = self.sync_client.fetch_order_book(symbol)
             
             
+            # Fetch last 24h OHLCV data to get accurate high/low
+            ohlcv = self.sync_client.fetch_ohlcv(symbol, '1d', limit=1)
+            
+            if ohlcv:
+                # CCXT OHLCV format: [timestamp, open, high, low, close, volume]
+                last_day_candle = ohlcv[0]
+                ticker['high'] = last_day_candle[2]
+                ticker['low'] = last_day_candle[3]
+
             market_data = {
             market_data = {
                 'ticker': ticker,
                 'ticker': ticker,
                 'orderbook': orderbook,
                 'orderbook': orderbook,

+ 5 - 3
src/commands/info/market.py

@@ -73,10 +73,12 @@ class MarketCommands(InfoCommandsBase):
             
             
             # Add order book information if available
             # Add order book information if available
             if orderbook:
             if orderbook:
-                spread = orderbook.get('ask', 0) - orderbook.get('bid', 0)
+                bid = ticker.get('bid', 0)
+                ask = ticker.get('ask', 0)
+                spread = ask - bid if ask and bid else 0
                 message += f"\n📚 <b>Order Book:</b>\n"
                 message += f"\n📚 <b>Order Book:</b>\n"
-                message += f"Bid: {self.formatter.format_price_with_symbol(orderbook.get('bid', 0))}\n"
-                message += f"Ask: {self.formatter.format_price_with_symbol(orderbook.get('ask', 0))}\n"
+                message += f"Bid: {self.formatter.format_price_with_symbol(bid)}\n"
+                message += f"Ask: {self.formatter.format_price_with_symbol(ask)}\n"
                 message += f"Spread: {self.formatter.format_price_with_symbol(spread)}\n"
                 message += f"Spread: {self.formatter.format_price_with_symbol(spread)}\n"
             
             
             await self._reply(update, message.strip())
             await self._reply(update, message.strip())

+ 1 - 1
trading_bot.py

@@ -14,7 +14,7 @@ from datetime import datetime
 from pathlib import Path
 from pathlib import Path
 
 
 # Bot version
 # Bot version
-BOT_VERSION = "2.4.225"
+BOT_VERSION = "2.4.226"
 
 
 # Add src directory to Python path
 # Add src directory to Python path
 sys.path.insert(0, str(Path(__file__).parent / "src"))
 sys.path.insert(0, str(Path(__file__).parent / "src"))