Skip to main content
Glama

fetch_backtest_history

Retrieve historical backtest results from Freqtrade cryptocurrency trading bot to analyze past trading strategy performance and identify patterns.

Instructions

Get backtest result history; optionally filter by filename.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameNo

Implementation Reference

  • Main handler function for the 'fetch_backtest_history' MCP tool. Decorated with @mcp.tool() to register it as an MCP tool. Takes a Context and optional filename parameter, retrieves the Freqtrade REST client from context, and calls the backtest/history endpoint with optional filename filtering.
    @mcp.tool()
    def fetch_backtest_history(ctx: Context, filename: str = "") -> str:
        """Get backtest result history; optionally filter by filename."""
        client: FtRestClient = ctx.request_context.lifespan_context["client"]
        params = {"filename": filename} if filename else None
        return str(_client_get(client, "backtest/history", params=params))
  • Helper function that wraps _call_client_method to make GET requests to the Freqtrade REST client. Used by fetch_backtest_history to call the 'backtest/history' endpoint.
    def _client_get(client: FtRestClient, path: str, params: Dict[str, Any] | None = None):
        return _call_client_method(client, ["_get"], path, params=params)
  • Core helper utility that calls client methods with version compatibility support. Iterates through method names to find the first matching callable method on the client, supporting multiple freqtrade-client versions.
    def _call_client_method(client: FtRestClient, method_names: List[str], *args, **kwargs):
        """Call first matching client method to support multiple freqtrade-client versions."""
        for method_name in method_names:
            method = getattr(client, method_name, None)
            if callable(method):
                return method(*args, **kwargs)
        raise AttributeError(f"No supported method found in {method_names}")
  • Import statements defining the type system for the tool. Imports Context from mcp.server.fastmcp (used for MCP context), and FtRestClient from freqtrade_client (the REST client type used in the handler).
    # freqtrade_mcp.py
    import logging
    import os
    from typing import List, AsyncIterator, Dict, Any
    from contextlib import asynccontextmanager
    from mcp.server.fastmcp import FastMCP, Context
    
    # Import Freqtrade REST client
    from freqtrade_client.ft_rest_client import FtRestClient

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/worlddebugger/freqtrade-mcp'

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