Skip to content

Commit fedfe37

Browse files
committed
feat(python): refactor SDK to use direct arguments and bump to v2.0.0
- Refactored fetch_markets, fetch_events, and create_order to accept direct arguments instead of parameter objects. - Removed MarketFilterParams, EventFetchParams, and CreateOrderParams classes. - Updated documentation (README, API_REFERENCE, QUICKREF, MIGRATION) and examples. - Incremented version to 2.0.0 to match TypeScript SDK ergonomics.
1 parent 9275be7 commit fedfe37

File tree

9 files changed

+116
-162
lines changed

9 files changed

+116
-162
lines changed

MIGRATION.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ If you're upgrading from v1.x to v2.0.0, use this checklist to ensure your code
99
- [ ] **Replace `event.searchMarkets(query)`** with `exchange.filterMarkets(event.markets, query)`
1010
- [ ] **Replace all `outcome.id`** with `outcome.outcomeId`
1111
- [ ] **Replace all `market.id`** with `market.marketId`
12-
- [ ] **Python: Replace `HistoryFilterParams`** with direct kwargs in `fetch_ohlcv()` and `fetch_trades()`
12+
- [ ] **Python: Remove all parameter wrapper classes** (`HistoryFilterParams`, `MarketFilterParams`, `EventFetchParams`, `CreateOrderParams`)
13+
- [ ] **Python: Update `create_order()` calls** to use direct arguments instead of `CreateOrderParams`
14+
- [ ] **Python: Update `fetch_markets()` and `fetch_events()` calls** to remove `params=` argument
1315
- [ ] **Verify all examples** use the new unified API (`fetchMarkets`, `fetchEvents`)
1416
- [ ] **Update error handling** to use new error classes (if relying on error types)
1517

@@ -19,7 +21,7 @@ If you already migrated to the unified API in v1.7.0, you only need to:
1921

2022
- [ ] **Replace `event.searchMarkets(query)`** with `exchange.filterMarkets(event.markets, query)`
2123
- [ ] **Replace `.id`** with `.outcomeId` / `.marketId`
22-
- [ ] **Python only: Replace `HistoryFilterParams`** with kwargs
24+
- [ ] **Python only: Remove all parameter wrapper classes** and use direct kwargs/arguments
2325

2426
### Quick Migration Example
2527

@@ -43,12 +45,14 @@ events = poly.fetch_events(query='Fed Chair')
4345
market = events[0].search_markets('Kevin Warsh')[0] # Removed
4446
outcome_id = market.yes.id # Removed
4547
candles = poly.fetch_ohlcv(outcome_id, pmxt.HistoryFilterParams(resolution='1h', limit=100)) # Removed
48+
order = poly.create_order(pmxt.CreateOrderParams(market_id='...', outcome_id='...', side='buy', type='limit', amount=10, price=0.5)) # Removed
4649

4750
# v2.0.0 Code
4851
events = poly.fetch_events(query='Fed Chair')
4952
market = poly.filter_markets(events[0].markets, 'Kevin Warsh')[0] #
5053
outcome_id = market.yes.outcome_id #
5154
candles = poly.fetch_ohlcv(outcome_id, resolution='1h', limit=100) #
55+
order = poly.create_order(market_id='...', outcome_id='...', side='buy', type='limit', amount=10, price=0.5) #
5256
```
5357

5458
### Testing Your Migration

sdks/python/API_REFERENCE.md

Lines changed: 36 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,20 @@ Fetch Markets
6161
**Signature:**
6262

6363
```python
64-
def fetch_markets(query: Optional[str] = None, params: Optional[MarketFilterParams] = None, **kwargs) -> List[UnifiedMarket]:
64+
def fetch_markets(query: Optional[str] = None, **kwargs) -> List[UnifiedMarket]:
6565
```
6666

6767
**Parameters:**
6868

69-
- `params` (MarketFilterParams) - **Optional**: Filter parameters
69+
- `query` (str) - **Optional**: Search keyword
70+
- `**kwargs` - **Optional**: Additional parameters (limit, offset, sort, search_in)
7071

7172
**Returns:** `List[UnifiedMarket]` - List of unified markets
7273

7374
**Example:**
7475

7576
```python
76-
markets = poly.fetch_markets(pmxt.MarketFilterParams(
77-
limit=20,
78-
sort='volume' # 'volume' | 'liquidity' | 'newest'
79-
))
77+
markets = poly.fetch_markets(query="Trump", limit=20, sort='volume')
8078
```
8179

8280

@@ -201,19 +199,20 @@ Fetch Events
201199
**Signature:**
202200

203201
```python
204-
def fetch_events(query: Optional[str] = None, params: Optional[EventFetchParams] = None, **kwargs) -> List[UnifiedEvent]:
202+
def fetch_events(query: Optional[str] = None, **kwargs) -> List[UnifiedEvent]:
205203
```
206204

207205
**Parameters:**
208206

209-
- `params` (EventFetchParams) - **Optional**: Filter parameters
207+
- `query` (str) - **Optional**: Search keyword
208+
- `**kwargs` - **Optional**: Additional parameters (limit, offset, search_in)
210209

211210
**Returns:** `List[UnifiedEvent]` - List of unified events
212211

213212
**Example:**
214213

215214
```python
216-
# No example available
215+
events = poly.fetch_events(query="Election", limit=10)
217216
```
218217

219218

@@ -362,38 +361,52 @@ Create Order
362361
**Signature:**
363362

364363
```python
365-
def create_order(params: Optional[CreateOrderParams] = None) -> Order:
364+
def create_order(
365+
market_id: str,
366+
outcome_id: str,
367+
side: Literal["buy", "sell"],
368+
type: Literal["market", "limit"],
369+
amount: float,
370+
price: Optional[float] = None,
371+
fee: Optional[int] = None
372+
) -> Order:
366373
```
367374

368375
**Parameters:**
369376

370-
- `params` (CreateOrderParams) - **Optional**: Filter parameters
377+
- `market_id` (str): Market ID
378+
- `outcome_id` (str): Outcome ID
379+
- `side` (Literal["buy", "sell"]): Order side
380+
- `type` (Literal["market", "limit"]): Order type
381+
- `amount` (float): Number of contracts
382+
- `price` (float) - **Optional**: Limit price (required for limit orders, 0.0-1.0)
383+
- `fee` (int) - **Optional**: Fee rate (e.g., 1000 for 0.1%)
371384

372385
**Returns:** `Order` - Order created
373386

374387
**Example:**
375388

376389
```python
377390
# Limit Order Example
378-
order = poly.create_order(pmxt.CreateOrderParams(
391+
order = poly.create_order(
379392
market_id='663583',
380393
outcome_id='109918492287...',
381394
side='buy',
382395
type='limit',
383396
amount=10, # Number of contracts
384397
price=0.55 # Required for limit orders (0.0-1.0)
385-
))
398+
)
386399

387400
print(f'Order {order.id}: {order.status}')
388401

389402
# Market Order Example
390-
order = kalshi.create_order(pmxt.CreateOrderParams(
403+
order = kalshi.create_order(
391404
market_id='FED-25JAN',
392405
outcome_id='FED-25JAN-YES',
393406
side='sell',
394407
type='market',
395408
amount=5 # Price not needed for market orders
396-
))
409+
)
397410
```
398411

399412

@@ -619,10 +632,11 @@ def search_markets() -> Any:
619632
**Example:**
620633

621634
```python
622-
results = kalshi.search_markets('Fed rates', pmxt.MarketFilterParams(
635+
results = kalshi.fetch_markets(
636+
query='Fed rates',
623637
limit=10,
624638
search_in='title' # 'title' (default) | 'description' | 'both'
625-
))
639+
)
626640
```
627641

628642

@@ -771,19 +785,19 @@ if balances:
771785
print(f'Available: ${balance.available}')
772786

773787
# 2. Search for a market
774-
markets = exchange.search_markets('Trump')
788+
markets = exchange.fetch_markets(query='Trump')
775789
market = markets[0]
776790
outcome = market.outcomes[0]
777791

778792
# 3. Place a limit order
779-
order = exchange.create_order(pmxt.CreateOrderParams(
780-
market_id=market.id,
781-
outcome_id=outcome.id,
793+
order = exchange.create_order(
794+
market_id=market.market_id,
795+
outcome_id=outcome.outcome_id,
782796
side='buy',
783797
type='limit',
784798
amount=10,
785799
price=0.50
786-
))
800+
)
787801

788802
print(f'Order placed: {order.id}')
789803

@@ -1008,62 +1022,3 @@ signature_type: Any # Signature type (0=EOA, 1=Poly Proxy, 2=Gnosis Safe, or nam
10081022
```
10091023

10101024
---
1011-
1012-
## Filter Parameters
1013-
1014-
### `BaseRequest`
1015-
1016-
Base request structure with optional credentials
1017-
1018-
```python
1019-
@dataclass
1020-
class BaseRequest:
1021-
credentials: ExchangeCredentials #
1022-
```
1023-
1024-
---
1025-
### `MarketFilterParams`
1026-
1027-
1028-
1029-
```python
1030-
@dataclass
1031-
class MarketFilterParams:
1032-
limit: int #
1033-
offset: int #
1034-
sort: str #
1035-
search_in: str #
1036-
```
1037-
1038-
---
1039-
### `EventFetchParams`
1040-
1041-
1042-
1043-
```python
1044-
@dataclass
1045-
class EventFetchParams:
1046-
query: str #
1047-
limit: int #
1048-
offset: int #
1049-
search_in: str #
1050-
```
1051-
1052-
---
1053-
### `CreateOrderParams`
1054-
1055-
1056-
1057-
```python
1058-
@dataclass
1059-
class CreateOrderParams:
1060-
market_id: str #
1061-
outcome_id: str #
1062-
side: str #
1063-
type: str #
1064-
amount: float #
1065-
price: float #
1066-
fee: float #
1067-
```
1068-
1069-
---

sdks/python/QUICKREF.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
import pmxt
1313
1414
poly = pmxt.Polymarket()
15-
markets = poly.search_markets("Trump")
15+
markets = poly.fetch_markets(query="Trump")
1616
1717
outcome = markets[0].outcomes[0]
1818
candles = poly.fetch_ohlcv(
1919
outcome.outcome_id,
20-
pmxt.HistoryFilterParams(resolution="1d", limit=30)
20+
resolution="1d",
21+
limit=30
2122
)
2223
2324
Authentication:
@@ -33,17 +34,16 @@
3334
)
3435
3536
Market Data Methods:
36-
fetch_markets(params?) # Get active markets
37-
search_markets(query, params?) # Search by keyword
38-
get_markets_by_slug(slug) # Get by URL slug/ticker
39-
fetch_ohlcv(outcome_id, params) # Historical candles
37+
fetch_markets(query?, **kwargs) # Get active markets
38+
fetch_events(query?, **kwargs) # Get events
39+
fetch_ohlcv(outcome_id, **kwargs) # Historical candles
4040
fetch_order_book(outcome_id) # Current order book
41-
fetch_trades(outcome_id, params) # Trade history
41+
fetch_trades(outcome_id, **kwargs) # Trade history
4242
watch_order_book(outcome_id) # WebSocket order book updates
43-
watch_trades(outcome_id) # WebSocket trade updates
43+
watch_trades(outcome_id) # WebSocket trade updates
4444
4545
Trading Methods (require auth):
46-
create_order(params) # Place order
46+
create_order(...) # Place order (direct args)
4747
cancel_order(order_id) # Cancel order
4848
fetch_order(order_id) # Get order details
4949
fetch_open_orders(market_id?) # Get open orders
@@ -60,29 +60,29 @@
6060
6161
Example - Complete Workflow:
6262
import pmxt
63-
63+
6464
# Initialize
6565
poly = pmxt.Polymarket(private_key=os.getenv("POLYMARKET_PRIVATE_KEY"))
66-
66+
6767
# Search
68-
markets = poly.search_markets("Trump")
68+
markets = poly.fetch_markets(query="Trump")
6969
market = markets[0]
7070
outcome = market.outcomes[0]
71-
71+
7272
# Check balance
7373
balance = poly.fetch_balance()[0]
7474
print(f"Available: ${balance.available}")
75-
75+
7676
# Place order
77-
order = poly.create_order(pmxt.CreateOrderParams(
77+
order = poly.create_order(
7878
market_id=market.market_id,
7979
outcome_id=outcome.outcome_id,
8080
side="buy",
8181
type="limit",
8282
amount=10,
8383
price=0.50
84-
))
85-
84+
)
85+
8686
# Check positions
8787
positions = poly.fetch_positions()
8888
for pos in positions:

sdks/python/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ balances = poly.fetch_balance()
8888
print(f"Available: ${balances[0].available}")
8989

9090
# Place order
91-
order = poly.create_order(pmxt.CreateOrderParams(
91+
order = poly.create_order(
9292
market_id="663583",
9393
outcome_id="10991849...",
9494
side="buy",
9595
type="limit",
9696
amount=10,
9797
price=0.55
98-
))
98+
)
9999
```
100100

101101
### Kalshi

sdks/python/examples/trading/place_limit_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
def main():
55
client = pmxt.Polymarket(private_key=os.getenv("POLYMARKET_PRIVATE_KEY"))
6-
7-
order = client.create_order(pmxt.CreateOrderParams(
6+
7+
order = client.create_order(
88
market_id='663583',
99
outcome_id='10991849228756847439673778874175365458450913336396982752046655649803657501964',
1010
side='buy',
1111
type='limit',
1212
amount=10,
1313
price=0.10
14-
))
14+
)
1515
print(order)
1616

1717
if __name__ == "__main__":

sdks/python/examples/trading/place_market_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
def main():
55
client = pmxt.Polymarket(private_key=os.getenv("POLYMARKET_PRIVATE_KEY"))
6-
7-
order = client.create_order(pmxt.CreateOrderParams(
6+
7+
order = client.create_order(
88
market_id='663583',
99
outcome_id='10991849228756847439673778874175365458450913336396982752046655649803657501964',
1010
side='buy',
1111
type='market',
1212
amount=10
13-
))
13+
)
1414
print(order)
1515

1616
if __name__ == "__main__":

0 commit comments

Comments
 (0)