stop_live_algorithm
Stop a live trading algorithm by providing the project ID to halt execution and manage active strategies.
Instructions
Stop a live algorithm.
Args: project_id: ID of the project with the live algorithm to stop
Returns: Dictionary containing stop result
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes |
Implementation Reference
- The handler function for the 'stop_live_algorithm' tool. It authenticates with QuantConnect, prepares a request with the project ID, and sends a POST request to the 'live/update/stop' API endpoint to stop the live algorithm. Handles various response cases including success, errors, and exceptions.@mcp.tool() async def stop_live_algorithm(project_id: int) -> Dict[str, Any]: """ Stop a live algorithm. Args: project_id: ID of the project with the live algorithm to stop Returns: Dictionary containing stop result """ auth = get_auth_instance() if auth is None: return { "status": "error", "error": "QuantConnect authentication not configured. Use configure_auth() first.", } try: # Prepare request data request_data = {"projectId": project_id} # Make API request response = await auth.make_authenticated_request( endpoint="live/update/stop", method="POST", json=request_data ) # Parse response if response.status_code == 200: data = response.json() if data.get("success", False): return { "status": "success", "project_id": project_id, "message": f"Successfully stopped live algorithm for project {project_id}", } else: # API returned success=false errors = data.get("errors", ["Unknown error"]) return { "status": "error", "error": "Live algorithm stop failed", "details": errors, "project_id": project_id, } elif response.status_code == 401: return { "status": "error", "error": "Authentication failed. Check your credentials and ensure they haven't expired.", } else: return { "status": "error", "error": f"API request failed with status {response.status_code}", "response_text": ( response.text[:500] if hasattr(response, "text") else "No response text" ), } except Exception as e: return { "status": "error", "error": f"Failed to stop live algorithm: {str(e)}", "project_id": project_id, }
- quantconnect_mcp/main.py:51-51 (registration)Calls register_live_tools(mcp) to register all live trading tools, including 'stop_live_algorithm', with the MCP server instance.register_live_tools(mcp)