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.1.tar.gz
(1.9 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.1.tar.gz.
File metadata
- Download URL: polytrader-0.1.1.tar.gz
- Upload date:
- Size: 1.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
246a537198ee124d2c31b94f6dc16e7cd7b9f5b2ab4477540919e510934e11d2
|
|
| MD5 |
0b7d40f35257bb7ecf058c58fae0525f
|
|
| BLAKE2b-256 |
338576658dacb2658b7d22f34c9b5e1e4614f286136b93df53f5cd4f923b45cc
|
File details
Details for the file polytrader-0.1.1-py3-none-any.whl.
File metadata
- Download URL: polytrader-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90d2efba43e746daaf842b1e3bd5bb947f3a8eada49d282f6c1092a530713ade
|
|
| MD5 |
1b1e30cc95ae0fdd00eed5e6490ce998
|
|
| BLAKE2b-256 |
7bb67d8fd10e74eb44767862bf71e57d051e03a95642d6e8cef9af4dd645b9db
|