Skip to main content
Glama

list_backtests

Retrieve all backtests for a specific project to analyze historical strategy performance and review testing results.

Instructions

List all backtests for a project.

Args: project_id: ID of the project to list backtests from

Returns: Dictionary containing list of backtests

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes

Implementation Reference

  • The core handler function for the 'list_backtests' tool. It authenticates with QuantConnect, makes a POST request to the 'backtests/list' endpoint, parses the response, and returns a structured dictionary with the list of backtests or error information.
    @mcp.tool()
    async def list_backtests(project_id: int) -> Dict[str, Any]:
        """
        List all backtests for a project.
    
        Args:
            project_id: ID of the project to list backtests from
    
        Returns:
            Dictionary containing list of backtests
        """
        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="backtests/list", method="POST", json=request_data
            )
    
            # Parse response
            if response.status_code == 200:
                data = response.json()
    
                if data.get("success", False):
                    backtests = data.get("backtests", [])
                    
                    return {
                        "status": "success",
                        "project_id": project_id,
                        "backtests": backtests,
                        "total_backtests": len(backtests),
                        "message": f"Successfully retrieved {len(backtests)} backtests from project {project_id}",
                    }
                else:
                    # API returned success=false
                    errors = data.get("errors", ["Unknown error"])
                    return {
                        "status": "error",
                        "error": "Failed to list backtests",
                        "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 list backtests: {str(e)}",
                "project_id": project_id,
            }
  • Registers the backtest tools module, including 'list_backtests', by calling the register_backtest_tools function with the MCP instance.
    register_backtest_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