Skip to main content
Glama

read_backtest_orders

Retrieve order execution data from a completed backtest to analyze trading strategy performance and validate order logic.

Instructions

Read orders from a backtest.

Args: project_id: ID of the project containing the backtest backtest_id: ID of the backtest to read orders from start: Starting index of orders to fetch (default: 0) end: Last index of orders to fetch (default: 100, max range: 100)

Returns: Dictionary containing orders data and total count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
backtest_idYes
startNo
endNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'read_backtest_orders' tool. It validates input parameters, authenticates with QuantConnect, makes an API request to fetch orders from a backtest with pagination, and handles various error cases.
    @mcp.tool()
    async def read_backtest_orders(
        project_id: int, backtest_id: str, start: int = 0, end: int = 100
    ) -> Dict[str, Any]:
        """
        Read orders from a backtest.
    
        Args:
            project_id: ID of the project containing the backtest
            backtest_id: ID of the backtest to read orders from
            start: Starting index of orders to fetch (default: 0)
            end: Last index of orders to fetch (default: 100, max range: 100)
    
        Returns:
            Dictionary containing orders data and total count
        """
        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,
                "backtestId": backtest_id,
                "start": start,
                "end": end,
            }
    
            # Make API request
            response = await auth.make_authenticated_request(
                endpoint="backtests/orders/read", method="POST", json=request_data
            )
    
            # Parse response
            if response.status_code == 200:
                data = response.json()
    
                # Note: This API doesn't appear to have a "success" field based on the spec
                orders = data.get("orders", {})
                length = data.get("length", 0)
    
                return {
                    "status": "success",
                    "project_id": project_id,
                    "backtest_id": backtest_id,
                    "start": start,
                    "end": end,
                    "orders": orders,
                    "length": length,
                    "message": f"Successfully retrieved {length} orders from backtest {backtest_id} (range: {start}-{end})",
                }
    
            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 backtest orders: {str(e)}",
                "project_id": project_id,
                "backtest_id": backtest_id,
                "start": start,
                "end": end,
            }
  • Calls register_backtest_tools(mcp) which registers the read_backtest_orders tool among other backtest tools.
    register_backtest_tools(mcp)
  • Calls register_backtest_tools(mcp) which registers the read_backtest_orders tool.
    register_backtest_tools(mcp)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the tool reads orders, implying a read-only operation, but doesn't specify permissions needed, rate limits, pagination behavior beyond the default range, or error conditions. This leaves significant gaps for an agent to understand how to use it safely and effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by clear sections for arguments and returns. Every sentence adds value without redundancy, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no annotations, but with an output schema), the description is reasonably complete. It covers the purpose and parameters well, and the output schema handles return values, so the description doesn't need to explain returns. However, it lacks behavioral details like error handling or usage context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It clearly explains all four parameters: 'project_id' and 'backtest_id' as IDs for context, and 'start' and 'end' for pagination with defaults and a max range. This adds meaningful context beyond the basic schema, though it could benefit from examples or format details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'read' and the resource 'orders from a backtest', making the purpose specific and understandable. However, it doesn't explicitly distinguish this tool from sibling tools like 'read_backtest' or 'read_live_orders', which would require mentioning it's specifically for historical/backtest orders versus live ones.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'read_backtest' (for general backtest data) or 'read_live_orders' (for real-time orders). It also lacks information about prerequisites, such as whether the backtest must be completed or accessible.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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