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), user events (order updates, trade confirmations), and Binance streams (aggTrade, kline, depth)
- 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()
Binance WebSocket
from polytrader import BinanceAggTrade, BinanceKline
# Subscribe to Binance streams
await trader.binance_ws.connect()
await trader.binance_ws.subscribe_agg_trade("BTCUSDT", on_trade)
await trader.binance_ws.subscribe_kline("BTCUSDT", "1m", on_kline)
await trader.binance_ws.subscribe_depth("BTCUSDT", on_depth)
await trader.binance_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.3.tar.gz
(2.0 MB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polytrader-0.1.3.tar.gz.
File metadata
- Download URL: polytrader-0.1.3.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
721ba72bff691134cbf2053206194fd2dd15a485dce9d61ce4d0eb59f007e70e
|
|
| MD5 |
9a32d7ebcbd9338c3318300649b5815f
|
|
| BLAKE2b-256 |
82cde8214ec57e8e0d5311b34a0e4080fcb94af3eb30323150ae0488010b6461
|
File details
Details for the file polytrader-0.1.3-py3-none-any.whl.
File metadata
- Download URL: polytrader-0.1.3-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7762ce0e25e2278cce7ca6d3af4c79b61e2849900d4671cc8c679329d5be8de7
|
|
| MD5 |
5f2810cb0319199fdb8467359b10f691
|
|
| BLAKE2b-256 |
c5ca7065c983a4fdaea42e914205f9f3e587ba60364fe962851d343e60748864
|