Browse Source

Update Hyperliquid API configuration and documentation - Refined the configuration to replace HYPERLIQUID_PRIVATE_KEY with HYPERLIQUID_WALLET_ADDRESS and clarified the usage of HYPERLIQUID_SECRET_KEY. Enhanced README, setup instructions, and logging to improve user understanding and ensure compatibility with CCXT implementation.

Carles Sentis 4 days ago
parent
commit
d071987233
5 changed files with 42 additions and 35 deletions
  1. 2 2
      README.md
  2. 7 5
      config/env.example
  3. 13 9
      docs/setup.md
  4. 10 16
      src/config.py
  5. 10 3
      src/hyperliquid_client.py

+ 2 - 2
README.md

@@ -179,8 +179,8 @@ Following [CCXT standards](https://github.com/ccxt/ccxt) for exchange compatibil
 
 ```env
 # Hyperliquid API (CCXT Style)
-HYPERLIQUID_PRIVATE_KEY=your_wallet_address_here     # ← Your wallet address (0x...)
-HYPERLIQUID_SECRET_KEY=your_api_generator_key_here   # ← Use API Generator Key from app.hyperliquid.xyz/API
+HYPERLIQUID_SECRET_KEY=your_api_secret_key_here      # ← Secret Key from API generator
+HYPERLIQUID_WALLET_ADDRESS=your_api_wallet_address_here  # ← API Wallet Address from generator
 HYPERLIQUID_TESTNET=true
 
 # Telegram Bot

+ 7 - 5
config/env.example

@@ -1,12 +1,14 @@
 # ========================================
 # Hyperliquid API Configuration (CCXT Style)
 # ========================================
-# Your wallet address (required - this goes to CCXT as 'secret')
-HYPERLIQUID_PRIVATE_KEY=your_wallet_address_here
+# Your Hyperliquid API Generator Secret Key (from https://app.hyperliquid.xyz/API)
+# This is the SECRET KEY generated by the API panel - NOT your main wallet's private key!
+HYPERLIQUID_SECRET_KEY=your_api_secret_key_here
 
-# Your Hyperliquid API Generator Key (from https://app.hyperliquid.xyz/API)
-# This goes to CCXT as 'apiKey' - NEVER use your wallet's private key directly!
-HYPERLIQUID_SECRET_KEY=your_api_generator_key_here
+# Your API Wallet Address (from https://app.hyperliquid.xyz/API)
+# This is the NEW wallet address created by the API generator - NOT your main MetaMask address!
+# It will be different from your main wallet address (0x...)
+HYPERLIQUID_WALLET_ADDRESS=your_api_wallet_address_here
 
 # Network selection: true for testnet (safe), false for mainnet (real money!)
 HYPERLIQUID_TESTNET=true

+ 13 - 9
docs/setup.md

@@ -44,8 +44,8 @@ nano .env  # Or use your preferred editor
 **Required settings:**
 ```env
 # Use API Generator Key from https://app.hyperliquid.xyz/API (NOT your wallet private key)
-HYPERLIQUID_PRIVATE_KEY=your_wallet_address_here
 HYPERLIQUID_SECRET_KEY=your_api_generator_key_here
+HYPERLIQUID_WALLET_ADDRESS=your_wallet_address_here
 HYPERLIQUID_TESTNET=true
 
 # From steps above
@@ -65,17 +65,21 @@ python trading_bot.py
 
 ### API Keys (Recommended - SECURE)
 1. Go to [Hyperliquid API Panel](https://app.hyperliquid.xyz/API)
-2. Generate a dedicated API key for trading
-3. **NEVER use your wallet's private key directly**
-4. Copy your wallet address (0x...) from your wallet interface
-5. Set HYPERLIQUID_PRIVATE_KEY to your wallet address
-6. Set HYPERLIQUID_SECRET_KEY to your API generator key
+2. Click "Generate API Key" or similar
+3. **This creates TWO things**:
+   - **API Wallet Address**: A NEW wallet address (0x...) different from your main wallet
+   - **Secret Key**: The secret key for this API wallet
+4. **NEVER use your main wallet's private key directly**
+5. Set HYPERLIQUID_SECRET_KEY to the **Secret Key** from the API generator
+6. Set HYPERLIQUID_WALLET_ADDRESS to the **API Wallet Address** from the API generator
+
+**Important**: The API wallet address is DIFFERENT from your main MetaMask/wallet address!
 
 ### Testnet (Recommended First)
 1. Go to [Hyperliquid Testnet](https://app.hyperliquid-testnet.xyz/)
-2. Connect/create wallet
-3. Note your wallet address from the wallet interface
-4. Generate API key from API panel
+2. Connect your main wallet
+3. Go to API panel and generate API credentials
+4. Use the API wallet address and secret key (not your main wallet credentials)
 5. Use testnet settings in your `.env` file
 
 ### Mainnet (Real Money)

+ 10 - 16
src/config.py

@@ -12,8 +12,8 @@ class Config:
     """Configuration class for the Hyperliquid trading bot."""
     
     # Hyperliquid API Configuration
-    HYPERLIQUID_PRIVATE_KEY: Optional[str] = os.getenv('HYPERLIQUID_PRIVATE_KEY')  # Wallet address
     HYPERLIQUID_SECRET_KEY: Optional[str] = os.getenv('HYPERLIQUID_SECRET_KEY')    # API generator key
+    HYPERLIQUID_WALLET_ADDRESS: Optional[str] = os.getenv('HYPERLIQUID_WALLET_ADDRESS')  # Wallet address
     HYPERLIQUID_TESTNET: bool = os.getenv('HYPERLIQUID_TESTNET', 'true').lower() == 'true'
     
     # Trading Bot Configuration
@@ -46,22 +46,14 @@ class Config:
         is_valid = True
         
         # Validate Hyperliquid settings
-        if not cls.HYPERLIQUID_PRIVATE_KEY:
-            logger.error("❌ HYPERLIQUID_PRIVATE_KEY (wallet address) is required")
+        if not cls.HYPERLIQUID_WALLET_ADDRESS:
+            logger.error("❌ HYPERLIQUID_WALLET_ADDRESS is required")
             is_valid = False
         
         if not cls.HYPERLIQUID_SECRET_KEY:
             logger.error("❌ HYPERLIQUID_SECRET_KEY (API generator key) is required")
             is_valid = False
         
-        # Validate wallet address or private key format
-        if not cls.HYPERLIQUID_PRIVATE_KEY and cls.HYPERLIQUID_SECRET_KEY:
-            # Check if private key looks like an address
-            if not cls.HYPERLIQUID_PRIVATE_KEY.startswith('0x') and len(cls.HYPERLIQUID_PRIVATE_KEY) < 40:
-                logger.warning("⚠️ HYPERLIQUID_WALLET_ADDRESS not set - will attempt to use private key as address")
-            elif len(cls.HYPERLIQUID_PRIVATE_KEY) < 64:
-                logger.warning("⚠️ HYPERLIQUID_WALLET_ADDRESS not set and private key appears short - consider setting explicit wallet address")
-        
         # Validate Telegram settings (if enabled)
         if cls.TELEGRAM_ENABLED:
             if not cls.TELEGRAM_BOT_TOKEN:
@@ -110,12 +102,14 @@ class Config:
         # Add authentication if available
         # Hyperliquid CCXT implementation expects:
         # - apiKey: API generator key (SECRET_KEY)  
-        # - secret: wallet address (PRIVATE_KEY)
+        # - walletAddress: wallet address (WALLET_ADDRESS)
+        # - secret: (optional, set to wallet address for compatibility)
         if cls.HYPERLIQUID_SECRET_KEY:
             config['apiKey'] = cls.HYPERLIQUID_SECRET_KEY  # API generator key
             
-        if cls.HYPERLIQUID_PRIVATE_KEY:
-            config['secret'] = cls.HYPERLIQUID_PRIVATE_KEY  # Wallet address
+        if cls.HYPERLIQUID_WALLET_ADDRESS:
+            config['walletAddress'] = cls.HYPERLIQUID_WALLET_ADDRESS  # Wallet address
+            config['secret'] = cls.HYPERLIQUID_WALLET_ADDRESS  # Also set as secret for backward compatibility
             
         return config
     
@@ -124,8 +118,8 @@ class Config:
         """Print current configuration (hiding sensitive data)."""
         logger.info("🔧 Configuration:")
         logger.info(f"  📡 Hyperliquid Testnet: {cls.HYPERLIQUID_TESTNET}")
-        logger.info(f"  🔑 Private Key: {'✅ Set' if cls.HYPERLIQUID_PRIVATE_KEY else '❌ Missing'}")
-        logger.info(f"  🔐 Secret Key: {'✅ Set' if cls.HYPERLIQUID_SECRET_KEY else '⚠️ Missing (may be optional)'}")
+        logger.info(f"  🏠 Wallet Address: {'✅ Set' if cls.HYPERLIQUID_WALLET_ADDRESS else '❌ Missing'}")
+        logger.info(f"  🔑 API Generator Key: {'✅ Set' if cls.HYPERLIQUID_SECRET_KEY else '❌ Missing'}")
         logger.info(f"  📱 Telegram: {'✅ Enabled' if cls.TELEGRAM_ENABLED else '❌ Disabled'}")
         logger.info(f"  🔍 Log Level: {cls.LOG_LEVEL}")
         logger.info(f"  💾 Log to File: {cls.LOG_TO_FILE}")

+ 10 - 3
src/hyperliquid_client.py

@@ -32,12 +32,15 @@ class HyperliquidClient:
             self.config['sandbox'] = use_testnet
         
         # Ensure proper CCXT format
-        # Hyperliquid CCXT expects: apiKey=API_generator_key, secret=wallet_address
+        # Hyperliquid CCXT expects: apiKey=API_generator_key, walletAddress=wallet_address
         if not self.config.get('apiKey') and Config.HYPERLIQUID_SECRET_KEY:
             self.config['apiKey'] = Config.HYPERLIQUID_SECRET_KEY  # API generator key
             
-        if not self.config.get('secret') and Config.HYPERLIQUID_PRIVATE_KEY:
-            self.config['secret'] = Config.HYPERLIQUID_PRIVATE_KEY  # Wallet address
+        if not self.config.get('walletAddress') and Config.HYPERLIQUID_WALLET_ADDRESS:
+            self.config['walletAddress'] = Config.HYPERLIQUID_WALLET_ADDRESS  # Wallet address
+            
+        if not self.config.get('secret') and Config.HYPERLIQUID_WALLET_ADDRESS:
+            self.config['secret'] = Config.HYPERLIQUID_WALLET_ADDRESS  # Wallet address as secret too
         
         # Initialize clients
         self.sync_client = None
@@ -82,6 +85,8 @@ class HyperliquidClient:
         safe_config = self.config.copy()
         if 'apiKey' in safe_config and safe_config['apiKey']:
             safe_config['apiKey'] = f"{safe_config['apiKey'][:8]}..."
+        if 'walletAddress' in safe_config and safe_config['walletAddress']:
+            safe_config['walletAddress'] = f"{safe_config['walletAddress'][:8]}..."
         if 'secret' in safe_config and safe_config['secret']:
             safe_config['secret'] = f"{safe_config['secret'][:8]}..."
         return safe_config
@@ -91,6 +96,8 @@ class HyperliquidClient:
         safe_config = config.copy()
         if 'apiKey' in safe_config and safe_config['apiKey']:
             safe_config['apiKey'] = f"{safe_config['apiKey'][:8]}..."
+        if 'walletAddress' in safe_config and safe_config['walletAddress']:
+            safe_config['walletAddress'] = f"{safe_config['walletAddress'][:8]}..."
         if 'secret' in safe_config and safe_config['secret']:
             safe_config['secret'] = f"{safe_config['secret'][:8]}..."
         return safe_config