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
| Name | Required | Description | Default |
|---|---|---|---|
| filename | No |
Implementation Reference
- __main__.py:377-382 (handler)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)) - __main__.py:46-47 (helper)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) - __main__.py:37-43 (helper)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}") - __main__.py:1-9 (schema)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