MCPcopy Index your code
hub / github.com/ashercn97/predmarket

github.com/ashercn97/predmarket @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
52 symbols 200 edges 17 files 19 documented · 37%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

A Unified SDK for Prediction Markets

Check out The Odds Company for similar projects

predmarket is an asyncio-native Python-based library that communicates directly with prediction markets (Kalshi and Polymarket).

Both Kalshi and Polymarket provide public-facing APIs with high rate limits. predmarket aims to unify these two APIs into one install, one format, and one library to learn. The goal to be abstract enough to be intuitive, but not lose any power of the individual APIs.

Currently, Websocket support is under development. A working implementation of Polymarket's CLOB WS API is available, while Kalshi's is still being developed.

Install

uv add predmarket or pip install predmarket

Basic Usage

REST

from predmarket import KalshiRest, PolymarketRest
from httpx import AsyncClient

async def main()
    async with AsyncClient() as client:

        # Initialize fetchers. Each with exact same public-facing API.
        kalshi = KalshiRest(client)
        polymarket = PolymarketRest(client)

        # Fetch available Questions (e.g. "When will Elon Musk get to Mars?", known as events in native API)
        kalshi_questions = await kalshi.fetch_questions()
        polymarket_questions = await polymarket.fetch_questions(limit=10, asc=True) # Polymarket-specific query params

        # Fetch available Contracts  (e.g. "Will Elon Musk get to Mars before 2026?", these are individual "solutions" for a given question , Markets in native APIs)
        kalshi_contracts = await kalshi.fetch_contracts()
        polymarket_contracts = await polymarket.fetch_contracts() # Polymarket-specific query params

WS

from predmarket import PolymarktWS # Kalshi is NOT currently supported, but will be very solutions

async def main():
    async with PolymarketWS.connect() as socket:
        polymarket = PolymarketWS(socket)
        for row in polymarket.stream(["AB.....XYZ"]): # Example of fetching real markets later in docs
            print(row) # Row is a pydantic model. Autocomplete!


More Information

predmarket is under rapid development. Expect breaking changes unless indiciated otherwise.

Core symbols most depended-on inside this repo

_safe_get
called by 10
src/predmarket/model/rest/exchange.py
_coerce
called by 10
src/predmarket/model/rest/price.py
from_kalshi
called by 5
src/predmarket/model/rest/price.py
from_polymarket
called by 5
src/predmarket/model/rest/price.py
clean_params
called by 4
src/predmarket/model/rest/__init__.py
parse
called by 2
src/predmarket/model/ws/normalize.py
main
called by 1
main.py
_normalize_outcomes
called by 1
src/predmarket/model/rest/contract.py

Shape

Method 31
Class 18
Function 3

Languages

Python100%

Modules by API surface

src/predmarket/model/ws/normalize.py12 symbols
src/predmarket/model/rest/exchange.py8 symbols
src/predmarket/polymarket/rest.py6 symbols
src/predmarket/kalshi/rest.py6 symbols
src/predmarket/polymarket/ws.py4 symbols
src/predmarket/model/rest/price.py4 symbols
src/predmarket/model/rest/contract.py4 symbols
src/predmarket/model/rest/question.py3 symbols
src/predmarket/model/rest/response.py2 symbols
src/predmarket/model/ws/exchange.py1 symbols
src/predmarket/model/rest/__init__.py1 symbols
main.py1 symbols

For agents

$ claude mcp add predmarket \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact