Browse Source

Refine market order placement in HyperliquidClient for slippage protection

- Updated the market order placement logic to explicitly pass the slippage price as an argument, enhancing clarity and ensuring compliance with Hyperliquid's requirements.
- Improved logging to include slippage price details, providing better visibility into order parameters during execution.
Carles Sentis 2 days ago
parent
commit
9ec067f147
2 changed files with 5 additions and 5 deletions
  1. 4 4
      src/clients/hyperliquid_client.py
  2. 1 1
      trading_bot.py

+ 4 - 4
src/clients/hyperliquid_client.py

@@ -335,12 +335,12 @@ class HyperliquidClient:
                 order_params['marginMode'] = Config.HYPERLIQUID_MARGIN_MODE.lower()
             
             # Hyperliquid requires a price for market orders for slippage protection.
-            order_params['price'] = slippage_price
+            # This must be passed as the 'price' argument, not within 'params'.
 
-            logger.info(f"Placing market order: {side} {amount} {symbol} with params {order_params}")
+            logger.info(f"Placing market order: {side} {amount} {symbol} with slippage price {slippage_price} and params {order_params}")
             
-            # Use create_market_order for market orders
-            order = self.sync_client.create_market_order(symbol, side, amount, params=order_params)
+            # Use create_market_order for market orders, passing the slippage price explicitly.
+            order = self.sync_client.create_market_order(symbol, side, amount, price=slippage_price, params=order_params)
             
             logger.info(f"✅ Market order placed successfully: {order}")
             return order, None

+ 1 - 1
trading_bot.py

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