get_l2_snapshot
Fetch the Level 2 order book snapshot for a specific cryptocurrency to view current bids and asks with prices and sizes.
Instructions
Fetch the Level 2 order book snapshot for a specific coin.
Parameters:
coin_name (str): The trading symbol (e.g., 'BTC', 'ETH').
ctx (Context): The MCP context object for accessing server state.
Returns:
str: A JSON string containing the Level 2 order book snapshot, including bids and asks with prices and sizes.
Returns a JSON string with an error message if the query fails.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coin_name | Yes |
Input Schema (JSON Schema)
{
"properties": {
"coin_name": {
"title": "Coin Name",
"type": "string"
}
},
"required": [
"coin_name"
],
"type": "object"
}
Implementation Reference
- main.py:172-189 (handler)The main handler function for the 'get_l2_snapshot' tool. It is decorated with @mcp.tool(), which serves as both the handler implementation and registration. The function fetches the L2 order book snapshot for the given coin using info.l2_snapshot and returns it as a JSON string, with error handling.@mcp.tool() async def get_l2_snapshot(coin_name: str, ctx: Context) -> str: """ Fetch the Level 2 order book snapshot for a specific coin. Parameters: coin_name (str): The trading symbol (e.g., 'BTC', 'ETH'). ctx (Context): The MCP context object for accessing server state. Returns: str: A JSON string containing the Level 2 order book snapshot, including bids and asks with prices and sizes. Returns a JSON string with an error message if the query fails. """ try: data = info.l2_snapshot(coin_name) return json.dumps(data) except Exception as e: return json.dumps({"error": f"Failed to fetch L2 snapshot: {str(e)}"})