Skip to main content

Python trading client for Polymarket

Project description

PolyTrader

A Python trading client for Polymarket — the world's largest prediction market.

Features

  • Order management — create limit (GTC/GTD) and market (FOK/FAK) orders, cancel single or all orders
  • Real-time WebSocket — market data (order book, price changes, trades, best bid/ask) and user events (order updates, trade confirmations)
  • Typed models — all API and WebSocket data parsed into Python dataclasses with proper types (Decimal prices, enum statuses)
  • Position & balance tracking — query positions, USDC balance, and conditional token balances
  • On-chain operations — approve tokens and collateral for trading, with optional builder/relayer support

Installation

pip install polytrader

Quick Start

from decimal import Decimal
from polytrader import PolyTrader, OrderSide, Coin, Timeframe

trader = PolyTrader(
    private_key="0x...",
    funder="0x...",
    signature_type=0,
)

# Get current Up/Down market
market = await trader.get_current_updown_market(Coin.BTC, Timeframe.M5)

# Place a limit order
result = trader.create_order(
    token_id=market.up_token_id,
    side=OrderSide.BUY,
    price=Decimal("0.50"),
    size=Decimal("10"),
)

# Get open orders
orders = trader.get_orders()

# Cancel all orders
trader.cancel_all_orders()

WebSocket

# Market data (public)
await trader.market_ws.connect()
await trader.market_ws.subscribe([market.up_token_id], callback)
await trader.market_ws.run()

# User events (authenticated)
await trader.user_ws.connect()
await trader.user_ws.subscribe([market.condition_id], callback)
await trader.user_ws.run()

Requirements

  • Python >= 3.11

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polytrader-0.1.2.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polytrader-0.1.2-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file polytrader-0.1.2.tar.gz.

File metadata

  • Download URL: polytrader-0.1.2.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for polytrader-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7c2473ce44cf1ada27bbe14264102f69174265b29498251db705f7b39a72a1f6
MD5 bdd9e253df3e82146a64a7dadd120b22
BLAKE2b-256 7deb2724f19ca7715085ba022c0fca3edf9c3e178351651c08d325cb2aab524e

See more details on using hashes here.

File details

Details for the file polytrader-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: polytrader-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for polytrader-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0f395941fe0878f024d2ad4a88174569cea67cbcaf9d706907c8d5da06596e13
MD5 0d80010c71d5607ef3a8df0763b87a01
BLAKE2b-256 1305411832cd5036b66ebeb5ad8f392224aacfb74ae1d40266e391de54e1b472

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page