Skip to main content
Glama

read_live_insights

Retrieve real-time trading insights from active algorithms to monitor performance and analyze strategy execution.

Instructions

Read insights from a live algorithm.

Args: project_id: Project ID of the live algorithm start: Starting index of insights to fetch (default: 0) end: Last index of insights to fetch (default: 100, max range: 100)

Returns: Dictionary containing live algorithm insights data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
startNo
endNo

Implementation Reference

  • The core handler function for the 'read_live_insights' MCP tool. It validates input parameters (project_id, start, end indices), authenticates with QuantConnect, sends a POST request to the '/live/read/insights' API endpoint, and returns the insights data or error details. The function is decorated with @mcp.tool() for automatic registration.
    @mcp.tool()
    async def read_live_insights(
        project_id: int, start: int = 0, end: int = 100
    ) -> Dict[str, Any]:
        """
        Read insights from a live algorithm.
    
        Args:
            project_id: Project ID of the live algorithm
            start: Starting index of insights to fetch (default: 0)
            end: Last index of insights to fetch (default: 100, max range: 100)
    
        Returns:
            Dictionary containing live algorithm insights data
        """
        auth = get_auth_instance()
        if auth is None:
            return {
                "status": "error",
                "error": "QuantConnect authentication not configured. Use configure_auth() first.",
            }
    
        # Validate range
        if end - start > 100:
            return {
                "status": "error",
                "error": "Range too large: end - start must be less than or equal to 100",
            }
    
        if start < 0 or end < 0:
            return {
                "status": "error",
                "error": "Start and end indices must be non-negative",
            }
    
        if start >= end:
            return {
                "status": "error",
                "error": "Start index must be less than end index",
            }
    
        try:
            # Prepare request data
            request_data = {
                "projectId": project_id,
                "start": start,
                "end": end,
            }
    
            # Make API request
            response = await auth.make_authenticated_request(
                endpoint="live/read/insights", method="POST", json=request_data
            )
    
            # Parse response
            if response.status_code == 200:
                data = response.json()
    
                if data.get("success", False):
                    insights = data.get("insights", [])
                    length = data.get("length", 0)
    
                    return {
                        "status": "success",
                        "project_id": project_id,
                        "start": start,
                        "end": end,
                        "insights": insights,
                        "length": length,
                        "message": f"Successfully retrieved {length} insights from live algorithm {project_id} (range: {start}-{end})",
                    }
                else:
                    # API returned success=false
                    errors = data.get("errors", ["Unknown error"])
                    return {
                        "status": "error",
                        "error": "Failed to read live algorithm insights",
                        "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 read live algorithm insights: {str(e)}",
                "project_id": project_id,
                "start": start,
                "end": end,
            }
  • Call to register_live_tools(mcp) which registers all live trading tools, including 'read_live_insights', onto the FastMCP server instance.
    register_live_tools(mcp)
    register_optimization_tools(mcp)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/taylorwilsdon/quantconnect-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server