Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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()
  • 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}")

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