place_trigger_order
Execute stop-loss or take-profit orders on Hyperliquid DEX by setting trigger prices for automated position management and risk control.
Instructions
Place a trigger order (stop-loss or take-profit) on Hyperliquid
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| assetIndex | Yes | Asset index for the coin (0 for BTC, 1 for ETH, etc.) | |
| clientOrderId | No | Client order ID (optional) | |
| isBuy | Yes | True for buy order, false for sell order | |
| isMarket | Yes | Whether to execute as market order when triggered | |
| reduceOnly | No | Whether this is a reduce-only order (optional, default false) | |
| size | Yes | Order size as string | |
| triggerPrice | Yes | Trigger price as string | |
| triggerType | Yes | Trigger type |
Implementation Reference
- Tool schema definition for place_trigger_order, including input parameters like assetIndex, isBuy, size, triggerPrice, etc.place_trigger_order_tool = Tool( name="place_trigger_order", description="Place a trigger order (stop-loss or take-profit) on Hyperliquid", inputSchema={ "type": "object", "properties": { "assetIndex": { "type": "number", "description": "Asset index for the coin (0 for BTC, 1 for ETH, etc.)", }, "isBuy": { "type": "boolean", "description": "True for buy order, false for sell order", }, "size": { "type": "string", "description": "Order size as string", }, "triggerPrice": { "type": "string", "description": "Trigger price as string", }, "isMarket": { "type": "boolean", "description": "Whether to execute as market order when triggered", }, "triggerType": { "type": "string", "description": "Trigger type", "enum": ["tp", "sl"], }, "reduceOnly": { "type": "boolean", "description": "Whether this is a reduce-only order (optional, default false)", }, "clientOrderId": { "type": "string", "description": "Client order ID (optional)", }, }, "required": ["assetIndex", "isBuy", "size", "triggerPrice", "isMarket", "triggerType"], }, )
- The main handler function that processes the place_trigger_order tool call, constructs the OrderRequest with trigger type, and calls the HyperliquidClient to place the order.async def handle_place_trigger_order(client: HyperliquidClient, args: Dict[str, Any]) -> Dict[str, Any]: """Handle place trigger order request.""" asset_index = args["assetIndex"] is_buy = args["isBuy"] size = args["size"] trigger_price = args["triggerPrice"] is_market = args["isMarket"] trigger_type = args["triggerType"] reduce_only = args.get("reduceOnly", False) client_order_id = args.get("clientOrderId") order = OrderRequest( a=asset_index, b=is_buy, p="0", # Not used for trigger orders s=size, r=reduce_only, t={ "trigger": TriggerOrderType( triggerPx=trigger_price, isMarket=is_market, tpsl=trigger_type, ) }, ) if client_order_id: order.c = client_order_id action = PlaceOrderAction(orders=[order]) result = await client.place_order(action) if not result.success: raise ValueError(f"Failed to place trigger order: {result.error}") return { "content": [ TextContent( type="text", text=f"Trigger order placed successfully!\n\n{json.dumps(result.data, indent=2)}", ) ] }
- hyperliquid_mcp_server/main.py:68-85 (registration)Registration of the place_trigger_order_tool in the MCP server's list_tools handler.async def list_tools() -> list: """List all available tools.""" return [ # Market data tools get_all_mids_tool, get_l2_book_tool, get_candle_snapshot_tool, # Account info tools get_open_orders_tool, get_user_fills_tool, get_user_fills_by_time_tool, get_portfolio_tool, # Trading tools place_order_tool, place_trigger_order_tool, cancel_order_tool, cancel_all_orders_tool, ]
- hyperliquid_mcp_server/main.py:89-129 (registration)Dispatch/registration of the handle_place_trigger_order in the MCP call_tool handler for the name 'place_trigger_order'.async def call_tool(name: str, arguments: dict[str, Any] | None) -> list[TextContent]: """Handle tool calls.""" args = arguments or {} try: if name == "get_all_mids": result = await handle_get_all_mids(client, args) elif name == "get_l2_book": result = await handle_get_l2_book(client, args) elif name == "get_candle_snapshot": result = await handle_get_candle_snapshot(client, args) elif name == "get_open_orders": result = await handle_get_open_orders(client, args) elif name == "get_user_fills": result = await handle_get_user_fills(client, args) elif name == "get_user_fills_by_time": result = await handle_get_user_fills_by_time(client, args) elif name == "get_portfolio": result = await handle_get_portfolio(client, args) elif name == "place_order": result = await handle_place_order(client, args) elif name == "place_trigger_order": result = await handle_place_trigger_order(client, args) elif name == "cancel_order": result = await handle_cancel_order(client, args) elif name == "cancel_all_orders": result = await handle_cancel_all_orders(client, args) else: raise ValueError(f"Unknown tool: {name}") return result["content"] except Exception as error: error_message = str(error) return [ TextContent( type="text", text=f"Error: {error_message}", ) ]
- hyperliquid_mcp_server/mcp_http_server.py:44-56 (registration)Registration of the handler in the TOOL_HANDLERS dict for the HTTP MCP server.TOOL_HANDLERS = { "get_all_mids": handle_get_all_mids, "get_l2_book": handle_get_l2_book, "get_candle_snapshot": handle_get_candle_snapshot, "get_open_orders": handle_get_open_orders, "get_user_fills": handle_get_user_fills, "get_user_fills_by_time": handle_get_user_fills_by_time, "get_portfolio": handle_get_portfolio, "place_order": handle_place_order, "place_trigger_order": handle_place_trigger_order, "cancel_order": handle_cancel_order, "cancel_all_orders": handle_cancel_all_orders, }