Skip to main content
Glama
berlinbra

PolyMarket MCP Server

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
NameRequiredDescriptionDefault
market_idYesMarket ID or slug
timeframeNoTime period for historical data7d

Implementation Reference

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

Other Tools

Related Tools

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/berlinbra/polymarket-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server