Metadata-Version: 2.4
Name: polytrader
Version: 0.1.2
Summary: Python trading client for Polymarket
Project-URL: Homepage, https://github.com/omidroshani/polytrader
Author: Omid Roshani
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11
Requires-Dist: eth-abi>=5.0.0
Requires-Dist: eth-account>=0.13.0
Requires-Dist: eth-utils>=5.0.0
Requires-Dist: httpx>=0.28.1
Requires-Dist: py-builder-relayer-client>=0.0.1
Requires-Dist: py-clob-client>=0.34.6
Requires-Dist: python-dotenv>=1.2.2
Requires-Dist: websockets>=16.0
Description-Content-Type: text/markdown

# PolyTrader

A Python trading client for [Polymarket](https://polymarket.com) — 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

```bash
pip install polytrader
```

## Quick Start

```python
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

```python
# 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
