Procházet zdrojové kódy

Refactor Hyperliquid API to use wallet address instead of private key - Updated the trading bot and Hyperliquid client to replace references to HYPERLIQUID_PRIVATE_KEY with HYPERLIQUID_WALLET_ADDRESS, ensuring consistency across the codebase and improving error handling for wallet address configuration. Enhanced logging for deposit and withdrawal checks in the Telegram bot.

Carles Sentis před 5 dny
rodič
revize
8480c1e58a
3 změnil soubory, kde provedl 23 přidání a 24 odebrání
  1. 18 19
      src/hyperliquid_client.py
  2. 3 3
      src/telegram_bot.py
  3. 2 2
      trading_bot.py

+ 18 - 19
src/hyperliquid_client.py

@@ -108,8 +108,8 @@ class HyperliquidClient:
             # Try to fetch balance to test authentication
             # Use the same logic as get_balance for consistency
             params = {}
-            if Config.HYPERLIQUID_PRIVATE_KEY:
-                wallet_address = Config.HYPERLIQUID_PRIVATE_KEY
+            if Config.HYPERLIQUID_WALLET_ADDRESS:
+                wallet_address = Config.HYPERLIQUID_WALLET_ADDRESS
                 params['user'] = f"0x{wallet_address}" if not wallet_address.startswith('0x') else wallet_address
             
             balance = self.sync_client.fetch_balance(params=params)
@@ -129,18 +129,17 @@ class HyperliquidClient:
             # The user parameter should be the wallet address derived from private key
             params = {}
             
-            # If we have a private key, derive the wallet address
-            if Config.HYPERLIQUID_PRIVATE_KEY:
-                # Extract the wallet address from the private key
+            # If we have a wallet address, use it as the user parameter
+            if Config.HYPERLIQUID_WALLET_ADDRESS:
+                # Extract the wallet address
                 # For CCXT Hyperliquid, the user parameter should be the wallet address
-                wallet_address = Config.HYPERLIQUID_PRIVATE_KEY
+                wallet_address = Config.HYPERLIQUID_WALLET_ADDRESS
                 if wallet_address.startswith('0x'):
                     # Use the address as the user parameter
                     params['user'] = wallet_address
                 else:
-                    # If it's just the private key, we might need to derive the address
-                    # For now, try using the private key directly
-                    params['user'] = f"0x{wallet_address}" if not wallet_address.startswith('0x') else wallet_address
+                    # Add 0x prefix if missing
+                    params['user'] = f"0x{wallet_address}"
             
             logger.debug(f"🔍 Fetching balance with params: {params}")
             balance = self.sync_client.fetch_balance(params=params)
@@ -162,10 +161,10 @@ class HyperliquidClient:
             approaches = [
                 # Approach 1: No params (original)
                 {},
-                # Approach 2: Private key as user
-                {'user': Config.HYPERLIQUID_PRIVATE_KEY},
-                # Approach 3: Private key with 0x prefix
-                {'user': f"0x{Config.HYPERLIQUID_PRIVATE_KEY}" if not Config.HYPERLIQUID_PRIVATE_KEY.startswith('0x') else Config.HYPERLIQUID_PRIVATE_KEY},
+                # Approach 2: Wallet address as user
+                {'user': Config.HYPERLIQUID_WALLET_ADDRESS},
+                # Approach 3: Wallet address with 0x prefix
+                {'user': f"0x{Config.HYPERLIQUID_WALLET_ADDRESS}" if Config.HYPERLIQUID_WALLET_ADDRESS and not Config.HYPERLIQUID_WALLET_ADDRESS.startswith('0x') else Config.HYPERLIQUID_WALLET_ADDRESS},
                 # Approach 4: Empty user
                 {'user': ''},
             ]
@@ -196,8 +195,8 @@ class HyperliquidClient:
             
             # Add user parameter for Hyperliquid CCXT compatibility
             params = {}
-            if Config.HYPERLIQUID_PRIVATE_KEY:
-                wallet_address = Config.HYPERLIQUID_PRIVATE_KEY
+            if Config.HYPERLIQUID_WALLET_ADDRESS:
+                wallet_address = Config.HYPERLIQUID_WALLET_ADDRESS
                 params['user'] = f"0x{wallet_address}" if not wallet_address.startswith('0x') else wallet_address
             
             logger.debug(f"🔍 Fetching positions with params: {params}")
@@ -295,8 +294,8 @@ class HyperliquidClient:
             
             # Add user parameter for Hyperliquid CCXT compatibility
             params = {}
-            if Config.HYPERLIQUID_PRIVATE_KEY:
-                wallet_address = Config.HYPERLIQUID_PRIVATE_KEY
+            if Config.HYPERLIQUID_WALLET_ADDRESS:
+                wallet_address = Config.HYPERLIQUID_WALLET_ADDRESS
                 params['user'] = f"0x{wallet_address}" if not wallet_address.startswith('0x') else wallet_address
             
             logger.debug(f"🔍 Fetching open orders with params: {params}")
@@ -449,8 +448,8 @@ class HyperliquidClient:
             
             # Add user parameter for Hyperliquid CCXT compatibility
             params = {}
-            if Config.HYPERLIQUID_PRIVATE_KEY:
-                wallet_address = Config.HYPERLIQUID_PRIVATE_KEY
+            if Config.HYPERLIQUID_WALLET_ADDRESS:
+                wallet_address = Config.HYPERLIQUID_WALLET_ADDRESS
                 params['user'] = f"0x{wallet_address}" if not wallet_address.startswith('0x') else wallet_address
                 
             # Fetch recent trades/fills for the account

+ 3 - 3
src/telegram_bot.py

@@ -2466,11 +2466,11 @@ This will place a limit {exit_side} order at ${profit_price:,.2f} to capture pro
             
             # Set up user parameter for Hyperliquid API calls
             params = {}
-            if Config.HYPERLIQUID_PRIVATE_KEY:
-                wallet_address = Config.HYPERLIQUID_PRIVATE_KEY
+            if Config.HYPERLIQUID_WALLET_ADDRESS:
+                wallet_address = Config.HYPERLIQUID_WALLET_ADDRESS
                 params['user'] = f"0x{wallet_address}" if not wallet_address.startswith('0x') else wallet_address
             else:
-                logger.warning("⚠️ No private key configured for deposit/withdrawal checking")
+                logger.warning("⚠️ No wallet address configured for deposit/withdrawal checking")
                 self.last_deposit_withdrawal_check = current_time
                 return
             

+ 2 - 2
trading_bot.py

@@ -91,8 +91,8 @@ class BotManager:
         
         missing_config = []
         
-        if not hasattr(Config, 'HYPERLIQUID_PRIVATE_KEY') or not Config.HYPERLIQUID_PRIVATE_KEY:
-            missing_config.append("HYPERLIQUID_PRIVATE_KEY")
+        if not hasattr(Config, 'HYPERLIQUID_WALLET_ADDRESS') or not Config.HYPERLIQUID_WALLET_ADDRESS:
+            missing_config.append("HYPERLIQUID_WALLET_ADDRESS")
         
         if not hasattr(Config, 'TELEGRAM_BOT_TOKEN') or not Config.TELEGRAM_BOT_TOKEN:
             missing_config.append("TELEGRAM_BOT_TOKEN")