get-market-history
Retrieve historical price and volume data for a specified market using a Market ID or slug. Choose timeframes like 1d, 7d, 30d, or all to analyze market trends and performance over time.
Instructions
Get historical price and volume data for a market
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| market_id | Yes | Market ID or slug | |
| timeframe | No | Time period for historical data | 7d |
Implementation Reference
- src/polymarket_mcp/server.py:293-303 (handler)The core handler logic for the 'get-market-history' tool within the @server.call_tool() function. It extracts market_id and timeframe from arguments, fetches market data using ClobClient.get_market(), formats it using format_market_history, and returns the result as text content.elif name == "get-market-history": market_id = arguments.get("market_id") timeframe = arguments.get("timeframe", "7d") if not market_id: return [types.TextContent(type="text", text="Missing market_id parameter")] # Note: Adjust this based on actual CLOB client capabilities market_data = client.get_market(market_id) formatted_history = format_market_history(market_data) return [types.TextContent(type="text", text=formatted_history)]
- src/polymarket_mcp/server.py:102-117 (schema)JSON Schema defining the input parameters for the 'get-market-history' tool: market_id (required string) and timeframe (optional enum with default '7d').inputSchema={ "type": "object", "properties": { "market_id": { "type": "string", "description": "Market ID or slug", }, "timeframe": { "type": "string", "description": "Time period for historical data", "enum": ["1d", "7d", "30d", "all"], "default": "7d" } }, "required": ["market_id"], },
- src/polymarket_mcp/server.py:99-118 (registration)Registration of the 'get-market-history' tool in the @server.list_tools() function, including name, description, and input schema.types.Tool( name="get-market-history", description="Get historical price and volume data for a market", inputSchema={ "type": "object", "properties": { "market_id": { "type": "string", "description": "Market ID or slug", }, "timeframe": { "type": "string", "description": "Time period for historical data", "enum": ["1d", "7d", "30d", "all"], "default": "7d" } }, "required": ["market_id"], }, )
- src/polymarket_mcp/server.py:203-224 (helper)Helper function to format the raw market history data into a readable string, extracting recent history points and handling errors.def format_market_history(history_data: dict) -> str: """Format market history data into a concise string.""" try: if not history_data or not isinstance(history_data, dict): return "No historical data available" formatted_history = [ f"Historical Data for {history_data.get('title', 'Unknown Market')}\n" ] # Format historical data points # Note: Adjust this based on actual CLOB client response structure for point in history_data.get('history', [])[-5:]: formatted_history.append( f"Time: {point.get('timestamp', 'N/A')}\n" f"Price: {point.get('price', 'N/A')}\n" "---\n" ) return "\n".join(formatted_history) except Exception as e: return f"Error formatting historical data: {str(e)}"