fetch_balance
Retrieve current cryptocurrency trading account balance from the Freqtrade bot to monitor available funds and track portfolio value.
Instructions
Fetch the account balance.
Parameters: ctx (Context): MCP context object for logging and client access.
Returns: str: Stringified JSON response with account balance, or None if failed.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- __main__.py:104-116 (handler)Handler function for the 'fetch_balance' MCP tool. Retrieves the Freqtrade REST client from the context and calls client.balance() to fetch account balance, returning the result as a stringified JSON response.
@mcp.tool() def fetch_balance(ctx: Context) -> str: """ Fetch the account balance. Parameters: ctx (Context): MCP context object for logging and client access. Returns: str: Stringified JSON response with account balance, or None if failed. """ client: FtRestClient = ctx.request_context.lifespan_context["client"] return str(client.balance()) - __main__.py:104-104 (registration)Registration decorator that registers the fetch_balance function as an MCP tool with the FastMCP server instance 'mcp'.
@mcp.tool() - __main__.py:37-43 (helper)Helper utility function that provides version compatibility for the Freqtrade client by attempting to call methods from a list of possible method names, supporting multiple freqtrade-client library 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}")