pmls 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pmls-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,312 @@
1
+ Metadata-Version: 2.4
2
+ Name: pmls
3
+ Version: 0.1.0
4
+ Summary: Polymarket CLI utilities
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: requests<3.0.0,>=2.31.0
8
+ Requires-Dist: python-dotenv<2.0.0,>=1.0.0
9
+ Requires-Dist: py-clob-client
10
+
11
+ # pmls — Polymarket CLI
12
+
13
+ A Python CLI for reading and trading on [Polymarket](https://polymarket.com) prediction markets via the CLOB and GAMMA APIs.
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ python3 -m venv .venv && source .venv/bin/activate
21
+ pip install -r requirements-dev.txt
22
+ pip install -e .
23
+ ```
24
+
25
+ Requires Python ≥ 3.11.
26
+
27
+ ---
28
+
29
+ ## Environment Variables
30
+
31
+ Create a `.env` file in the working directory (loaded automatically via `python-dotenv`).
32
+
33
+ | Variable | Required for | Description |
34
+ |---|---|---|
35
+ | `PMLS_CLOB_PRIVATE_KEY` | Trading | EOA private key for signing orders |
36
+ | `PMLS_CLOB_API_KEY` | Trading | Polymarket CLOB API key |
37
+ | `PMLS_CLOB_API_SECRET` | Trading | Polymarket CLOB API secret |
38
+ | `PMLS_CLOB_API_PASSPHRASE` | Trading | Polymarket CLOB API passphrase |
39
+ | `FUNDER_ADDR` | Trading | Funder wallet address (proxy wallet on Polygon) |
40
+ | `POLY_ADDR` | `pos`, `pnl` | Your Polygon wallet address for position lookups |
41
+
42
+ Trading commands (`marketo`, `limito`, `orders`, `cancel`) require all five CLOB vars. Read-only commands (`pos`, `pnl`) only require `POLY_ADDR`.
43
+
44
+ ---
45
+
46
+ ## Key Concepts
47
+
48
+ - **Event slug**: identifier for a top-level event (e.g. `super-bowl-2025`). One event contains multiple markets.
49
+ - **Market slug**: identifier for a single binary market (e.g. `chiefs-win-super-bowl-2025`).
50
+ - **Token ID**: large integer string identifying one side (outcome) of a binary market. Each binary market has exactly two token IDs (e.g. Yes and No).
51
+ - **Outcome**: human-readable label for one side of a market, e.g. `"Yes"` or `"No"` (case-insensitive in CLI).
52
+ - **Price convention**: all `--price` arguments are in **cents (0–100)**. The CLOB API uses 0–1 internally; the CLI converts automatically.
53
+
54
+ ---
55
+
56
+ ## Commands
57
+
58
+ ### `get-markets <event-slug>`
59
+
60
+ Resolve an event slug to its constituent market slugs.
61
+
62
+ ```bash
63
+ pmls get-markets <event-slug>
64
+ ```
65
+
66
+ **Output** — one market slug per line on stdout:
67
+ ```
68
+ chiefs-win-super-bowl-2025
69
+ eagles-win-super-bowl-2025
70
+ ```
71
+
72
+ ---
73
+
74
+ ### `orderbook <market-slug>`
75
+
76
+ Fetch and display the L2 orderbook for all outcomes of a market.
77
+
78
+ ```bash
79
+ pmls orderbook <market-slug> [--depth N] [--once|-o]
80
+ ```
81
+
82
+ | Argument | Default | Description |
83
+ |---|---|---|
84
+ | `market-slug` | required | Market slug to fetch |
85
+ | `--depth N` | `3` | Price levels per side (1–10) |
86
+ | `--once` / `-o` | off | Fetch once and exit; omit for continuous 0.5 s polling |
87
+
88
+ **Output format** — repeated per outcome:
89
+ ```
90
+ Outcome: Yes (Token: <token-id>)
91
+ Timestamp: 2025-01-01 12:00:00:000000
92
+ Asks
93
+ | PRICE| SIZE|
94
+ | 63.0| 100.0|
95
+ | 62.5| 200.0|
96
+
97
+ Bids
98
+ | PRICE| SIZE|
99
+ | 61.0| 150.0|
100
+ | 60.5| 80.0|
101
+ ```
102
+
103
+ Asks are sorted ascending (best ask last, i.e. closest to mid at the bottom). Bids are sorted descending (best bid first).
104
+
105
+ ---
106
+
107
+ ### `marketo`
108
+
109
+ Place a **market order** (Fill-or-Kill) filled immediately at the best available price.
110
+
111
+ ```bash
112
+ pmls marketo --bet <amount> --side <BUY|SELL> \
113
+ (--token-id <id> | --slug <slug> --outcome <name>) \
114
+ [--price <cap-cents>]
115
+ ```
116
+
117
+ | Argument | Required | Description |
118
+ |---|---|---|
119
+ | `--bet` | Yes | USDC to spend (BUY), or number of shares to sell (SELL). Pass `-1` with `--side SELL` to sell the entire position. |
120
+ | `--side` | No (default `BUY`) | `BUY` or `SELL` |
121
+ | `--token-id` | One group required | Token ID to trade directly |
122
+ | `--slug` + `--outcome` | One group required | Market slug and outcome name; resolved to a token ID via GAMMA API |
123
+ | `--price` | No | Max buy price cap in cents (0–100). BUY only; order is rejected if best ask exceeds this. |
124
+
125
+ **Output on success:**
126
+ ```
127
+ Note: Marketable orders in sport market are delayed by 3 seconds.
128
+ BUY order <order-id> submitted.
129
+ ```
130
+
131
+ **Output on failure:** Polymarket server error message to stderr, exit code 1.
132
+
133
+ ---
134
+
135
+ ### `limito`
136
+
137
+ Place a **GTC limit order** at an explicit price.
138
+
139
+ ```bash
140
+ pmls limito --bet <amount> --price <cents> --side <BUY|SELL> \
141
+ (--token-id <id> | --slug <slug> --outcome <name>)
142
+ ```
143
+
144
+ | Argument | Required | Description |
145
+ |---|---|---|
146
+ | `--bet` | Yes | USDC to spend (BUY), or number of shares to sell (SELL). Pass `-1` with `--side SELL` to sell the entire position. |
147
+ | `--price` | Yes | Limit price in cents (0–100) |
148
+ | `--side` | No (default `BUY`) | `BUY` or `SELL` |
149
+ | `--token-id` | One group required | Token ID to trade directly |
150
+ | `--slug` + `--outcome` | One group required | Market slug and outcome name |
151
+
152
+ **Output on success:**
153
+ ```
154
+ BUY order <order-id> submitted.
155
+ ```
156
+
157
+ ---
158
+
159
+ ### `orders`
160
+
161
+ List all open (resting) orders.
162
+
163
+ ```bash
164
+ pmls orders
165
+ ```
166
+
167
+ **Output format** — one order per line:
168
+ ```
169
+ <outcome> <side> <size>@$<price>, token ID: <token-id>
170
+ ```
171
+
172
+ Example:
173
+ ```
174
+ Yes BUY 100@$0.62, token ID: 10667...
175
+ ```
176
+
177
+ ---
178
+
179
+ ### `cancel`
180
+
181
+ Cancel open orders.
182
+
183
+ ```bash
184
+ pmls cancel --all
185
+ pmls cancel --id <order-id>[,<order-id>,...]
186
+ ```
187
+
188
+ | Argument | Description |
189
+ |---|---|
190
+ | `--all` / `-a` | Cancel every open order |
191
+ | `--id` | Comma-separated list of order IDs to cancel |
192
+
193
+ **Output on success:**
194
+ ```
195
+ Canceled 2 order(s): <id1>, <id2>
196
+ ```
197
+
198
+ Per-order failures are printed to stderr:
199
+ ```
200
+ Not canceled <id>: <reason>
201
+ ```
202
+
203
+ ---
204
+
205
+ ### `trade`
206
+
207
+ List trade history.
208
+
209
+ ```bash
210
+ pmls trade [--token-id <id>] [--before <unix-ts>] [--after <unix-ts>] [--market <market-id>] [-q <keyword>]
211
+ ```
212
+
213
+ | Argument | Description |
214
+ |---|---|
215
+ | `--token-id` | Filter to a specific token ID |
216
+ | `--before` | Unix timestamp upper bound |
217
+ | `--after` | Unix timestamp lower bound |
218
+ | `--market` | Filter by market ID |
219
+ | `-q <keyword>` | Keyword filter matched against outcome name or market description (case-insensitive). Slow path: does a GAMMA lookup per trade. |
220
+
221
+ **Output format** — one trade per line:
222
+ ```
223
+ <outcome> <side> <size>@<price>. Total: $<total> (<market-id>)
224
+ ```
225
+
226
+ Example:
227
+ ```
228
+ Yes BUY 50.0@0.6. Total: $30.0 (0x1234...)
229
+ ```
230
+
231
+ ---
232
+
233
+ ### `pos`
234
+
235
+ Show open positions for a wallet address.
236
+
237
+ ```bash
238
+ pmls pos [--user <address>]
239
+ ```
240
+
241
+ | Argument | Default | Description |
242
+ |---|---|---|
243
+ | `--user` | `$POLY_ADDR` | Polygon wallet address |
244
+
245
+ **Output format** — one position per line:
246
+ ```
247
+ <market-title> <outcome>: size=<shares> avg=<avg-price> curPrice=<current-price> value=<current-value-usd> pnl=<unrealized-pnl-usd> token_id=<token-id>
248
+ ```
249
+
250
+ ---
251
+
252
+ ### `pnl`
253
+
254
+ Show P&L summary across all open positions with a totals row.
255
+
256
+ ```bash
257
+ pmls pnl [--user <address>]
258
+ ```
259
+
260
+ | Argument | Default | Description |
261
+ |---|---|---|
262
+ | `--user` | `$POLY_ADDR` | Polygon wallet address |
263
+
264
+ **Output format:**
265
+ ```
266
+ <title> <outcome>: <size> shares @ <avg-price> | cur <cur-price> | cost $<cost> | value $<value> | unPnL +<unrealized> (<pct>%) | realPnL $<realized>
267
+ ------------------------------------------------------------
268
+ TOTAL <N> position(s) | cost $<total-cost> | value $<total-value> | unPnL $<total-unrealized> | realPnL $<total-realized> | net +<net>
269
+ ```
270
+
271
+ ---
272
+
273
+ ## Exit Codes
274
+
275
+ | Code | Meaning |
276
+ |---|---|
277
+ | `0` | Success |
278
+ | `1` | Error (message on stderr) |
279
+
280
+ ---
281
+
282
+ ## Module Map
283
+
284
+ ```
285
+ pmls/
286
+ cli.py — Argument parsing and command dispatch (entry point: pmls.cli:main)
287
+ models.py — Dataclasses: Position, TradeHistory, OpenOrder, PostOrderResult,
288
+ CancelOrderResponse, DisplayOutcome
289
+ credentials.py — Loads .env, builds authenticated ClobClient (L2 builder auth)
290
+ constants.py — API hosts, chain ID (137 = Polygon), env var name constants
291
+ display.py — Orderbook table formatter
292
+ api/
293
+ gamma_client.py — GAMMA API: event/market metadata, slug→token ID resolution
294
+ orderbook_client.py — Fetches L2 orderbook snapshots via py-clob-client
295
+ positions.py — Fetches open positions from data-api.polymarket.com
296
+ get_order.py — Lists open orders via ClobClient.get_orders()
297
+ trade_hist.py — Fetches trade history via ClobClient.get_trades()
298
+ trading/
299
+ limit_order.py — run_limito(): creates and posts a GTC limit order
300
+ market_order.py — run_marketo(): creates and posts a FOK market order
301
+ cancel.py — cancel_all_orders() / cancel_by_order_ids()
302
+ ```
303
+
304
+ ---
305
+
306
+ ## External APIs
307
+
308
+ | API | Base URL | Auth | Used for |
309
+ |---|---|---|---|
310
+ | GAMMA | `https://gamma-api.polymarket.com` | None | Event/market metadata, slug→token ID resolution |
311
+ | CLOB | `https://clob.polymarket.com` | L2 builder key | Orderbook, order placement, trade history |
312
+ | Data API | `https://data-api.polymarket.com` | None | Open positions |
pmls-0.1.0/README.md ADDED
@@ -0,0 +1,302 @@
1
+ # pmls — Polymarket CLI
2
+
3
+ A Python CLI for reading and trading on [Polymarket](https://polymarket.com) prediction markets via the CLOB and GAMMA APIs.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ python3 -m venv .venv && source .venv/bin/activate
11
+ pip install -r requirements-dev.txt
12
+ pip install -e .
13
+ ```
14
+
15
+ Requires Python ≥ 3.11.
16
+
17
+ ---
18
+
19
+ ## Environment Variables
20
+
21
+ Create a `.env` file in the working directory (loaded automatically via `python-dotenv`).
22
+
23
+ | Variable | Required for | Description |
24
+ |---|---|---|
25
+ | `PMLS_CLOB_PRIVATE_KEY` | Trading | EOA private key for signing orders |
26
+ | `PMLS_CLOB_API_KEY` | Trading | Polymarket CLOB API key |
27
+ | `PMLS_CLOB_API_SECRET` | Trading | Polymarket CLOB API secret |
28
+ | `PMLS_CLOB_API_PASSPHRASE` | Trading | Polymarket CLOB API passphrase |
29
+ | `FUNDER_ADDR` | Trading | Funder wallet address (proxy wallet on Polygon) |
30
+ | `POLY_ADDR` | `pos`, `pnl` | Your Polygon wallet address for position lookups |
31
+
32
+ Trading commands (`marketo`, `limito`, `orders`, `cancel`) require all five CLOB vars. Read-only commands (`pos`, `pnl`) only require `POLY_ADDR`.
33
+
34
+ ---
35
+
36
+ ## Key Concepts
37
+
38
+ - **Event slug**: identifier for a top-level event (e.g. `super-bowl-2025`). One event contains multiple markets.
39
+ - **Market slug**: identifier for a single binary market (e.g. `chiefs-win-super-bowl-2025`).
40
+ - **Token ID**: large integer string identifying one side (outcome) of a binary market. Each binary market has exactly two token IDs (e.g. Yes and No).
41
+ - **Outcome**: human-readable label for one side of a market, e.g. `"Yes"` or `"No"` (case-insensitive in CLI).
42
+ - **Price convention**: all `--price` arguments are in **cents (0–100)**. The CLOB API uses 0–1 internally; the CLI converts automatically.
43
+
44
+ ---
45
+
46
+ ## Commands
47
+
48
+ ### `get-markets <event-slug>`
49
+
50
+ Resolve an event slug to its constituent market slugs.
51
+
52
+ ```bash
53
+ pmls get-markets <event-slug>
54
+ ```
55
+
56
+ **Output** — one market slug per line on stdout:
57
+ ```
58
+ chiefs-win-super-bowl-2025
59
+ eagles-win-super-bowl-2025
60
+ ```
61
+
62
+ ---
63
+
64
+ ### `orderbook <market-slug>`
65
+
66
+ Fetch and display the L2 orderbook for all outcomes of a market.
67
+
68
+ ```bash
69
+ pmls orderbook <market-slug> [--depth N] [--once|-o]
70
+ ```
71
+
72
+ | Argument | Default | Description |
73
+ |---|---|---|
74
+ | `market-slug` | required | Market slug to fetch |
75
+ | `--depth N` | `3` | Price levels per side (1–10) |
76
+ | `--once` / `-o` | off | Fetch once and exit; omit for continuous 0.5 s polling |
77
+
78
+ **Output format** — repeated per outcome:
79
+ ```
80
+ Outcome: Yes (Token: <token-id>)
81
+ Timestamp: 2025-01-01 12:00:00:000000
82
+ Asks
83
+ | PRICE| SIZE|
84
+ | 63.0| 100.0|
85
+ | 62.5| 200.0|
86
+
87
+ Bids
88
+ | PRICE| SIZE|
89
+ | 61.0| 150.0|
90
+ | 60.5| 80.0|
91
+ ```
92
+
93
+ Asks are sorted ascending (best ask last, i.e. closest to mid at the bottom). Bids are sorted descending (best bid first).
94
+
95
+ ---
96
+
97
+ ### `marketo`
98
+
99
+ Place a **market order** (Fill-or-Kill) filled immediately at the best available price.
100
+
101
+ ```bash
102
+ pmls marketo --bet <amount> --side <BUY|SELL> \
103
+ (--token-id <id> | --slug <slug> --outcome <name>) \
104
+ [--price <cap-cents>]
105
+ ```
106
+
107
+ | Argument | Required | Description |
108
+ |---|---|---|
109
+ | `--bet` | Yes | USDC to spend (BUY), or number of shares to sell (SELL). Pass `-1` with `--side SELL` to sell the entire position. |
110
+ | `--side` | No (default `BUY`) | `BUY` or `SELL` |
111
+ | `--token-id` | One group required | Token ID to trade directly |
112
+ | `--slug` + `--outcome` | One group required | Market slug and outcome name; resolved to a token ID via GAMMA API |
113
+ | `--price` | No | Max buy price cap in cents (0–100). BUY only; order is rejected if best ask exceeds this. |
114
+
115
+ **Output on success:**
116
+ ```
117
+ Note: Marketable orders in sport market are delayed by 3 seconds.
118
+ BUY order <order-id> submitted.
119
+ ```
120
+
121
+ **Output on failure:** Polymarket server error message to stderr, exit code 1.
122
+
123
+ ---
124
+
125
+ ### `limito`
126
+
127
+ Place a **GTC limit order** at an explicit price.
128
+
129
+ ```bash
130
+ pmls limito --bet <amount> --price <cents> --side <BUY|SELL> \
131
+ (--token-id <id> | --slug <slug> --outcome <name>)
132
+ ```
133
+
134
+ | Argument | Required | Description |
135
+ |---|---|---|
136
+ | `--bet` | Yes | USDC to spend (BUY), or number of shares to sell (SELL). Pass `-1` with `--side SELL` to sell the entire position. |
137
+ | `--price` | Yes | Limit price in cents (0–100) |
138
+ | `--side` | No (default `BUY`) | `BUY` or `SELL` |
139
+ | `--token-id` | One group required | Token ID to trade directly |
140
+ | `--slug` + `--outcome` | One group required | Market slug and outcome name |
141
+
142
+ **Output on success:**
143
+ ```
144
+ BUY order <order-id> submitted.
145
+ ```
146
+
147
+ ---
148
+
149
+ ### `orders`
150
+
151
+ List all open (resting) orders.
152
+
153
+ ```bash
154
+ pmls orders
155
+ ```
156
+
157
+ **Output format** — one order per line:
158
+ ```
159
+ <outcome> <side> <size>@$<price>, token ID: <token-id>
160
+ ```
161
+
162
+ Example:
163
+ ```
164
+ Yes BUY 100@$0.62, token ID: 10667...
165
+ ```
166
+
167
+ ---
168
+
169
+ ### `cancel`
170
+
171
+ Cancel open orders.
172
+
173
+ ```bash
174
+ pmls cancel --all
175
+ pmls cancel --id <order-id>[,<order-id>,...]
176
+ ```
177
+
178
+ | Argument | Description |
179
+ |---|---|
180
+ | `--all` / `-a` | Cancel every open order |
181
+ | `--id` | Comma-separated list of order IDs to cancel |
182
+
183
+ **Output on success:**
184
+ ```
185
+ Canceled 2 order(s): <id1>, <id2>
186
+ ```
187
+
188
+ Per-order failures are printed to stderr:
189
+ ```
190
+ Not canceled <id>: <reason>
191
+ ```
192
+
193
+ ---
194
+
195
+ ### `trade`
196
+
197
+ List trade history.
198
+
199
+ ```bash
200
+ pmls trade [--token-id <id>] [--before <unix-ts>] [--after <unix-ts>] [--market <market-id>] [-q <keyword>]
201
+ ```
202
+
203
+ | Argument | Description |
204
+ |---|---|
205
+ | `--token-id` | Filter to a specific token ID |
206
+ | `--before` | Unix timestamp upper bound |
207
+ | `--after` | Unix timestamp lower bound |
208
+ | `--market` | Filter by market ID |
209
+ | `-q <keyword>` | Keyword filter matched against outcome name or market description (case-insensitive). Slow path: does a GAMMA lookup per trade. |
210
+
211
+ **Output format** — one trade per line:
212
+ ```
213
+ <outcome> <side> <size>@<price>. Total: $<total> (<market-id>)
214
+ ```
215
+
216
+ Example:
217
+ ```
218
+ Yes BUY 50.0@0.6. Total: $30.0 (0x1234...)
219
+ ```
220
+
221
+ ---
222
+
223
+ ### `pos`
224
+
225
+ Show open positions for a wallet address.
226
+
227
+ ```bash
228
+ pmls pos [--user <address>]
229
+ ```
230
+
231
+ | Argument | Default | Description |
232
+ |---|---|---|
233
+ | `--user` | `$POLY_ADDR` | Polygon wallet address |
234
+
235
+ **Output format** — one position per line:
236
+ ```
237
+ <market-title> <outcome>: size=<shares> avg=<avg-price> curPrice=<current-price> value=<current-value-usd> pnl=<unrealized-pnl-usd> token_id=<token-id>
238
+ ```
239
+
240
+ ---
241
+
242
+ ### `pnl`
243
+
244
+ Show P&L summary across all open positions with a totals row.
245
+
246
+ ```bash
247
+ pmls pnl [--user <address>]
248
+ ```
249
+
250
+ | Argument | Default | Description |
251
+ |---|---|---|
252
+ | `--user` | `$POLY_ADDR` | Polygon wallet address |
253
+
254
+ **Output format:**
255
+ ```
256
+ <title> <outcome>: <size> shares @ <avg-price> | cur <cur-price> | cost $<cost> | value $<value> | unPnL +<unrealized> (<pct>%) | realPnL $<realized>
257
+ ------------------------------------------------------------
258
+ TOTAL <N> position(s) | cost $<total-cost> | value $<total-value> | unPnL $<total-unrealized> | realPnL $<total-realized> | net +<net>
259
+ ```
260
+
261
+ ---
262
+
263
+ ## Exit Codes
264
+
265
+ | Code | Meaning |
266
+ |---|---|
267
+ | `0` | Success |
268
+ | `1` | Error (message on stderr) |
269
+
270
+ ---
271
+
272
+ ## Module Map
273
+
274
+ ```
275
+ pmls/
276
+ cli.py — Argument parsing and command dispatch (entry point: pmls.cli:main)
277
+ models.py — Dataclasses: Position, TradeHistory, OpenOrder, PostOrderResult,
278
+ CancelOrderResponse, DisplayOutcome
279
+ credentials.py — Loads .env, builds authenticated ClobClient (L2 builder auth)
280
+ constants.py — API hosts, chain ID (137 = Polygon), env var name constants
281
+ display.py — Orderbook table formatter
282
+ api/
283
+ gamma_client.py — GAMMA API: event/market metadata, slug→token ID resolution
284
+ orderbook_client.py — Fetches L2 orderbook snapshots via py-clob-client
285
+ positions.py — Fetches open positions from data-api.polymarket.com
286
+ get_order.py — Lists open orders via ClobClient.get_orders()
287
+ trade_hist.py — Fetches trade history via ClobClient.get_trades()
288
+ trading/
289
+ limit_order.py — run_limito(): creates and posts a GTC limit order
290
+ market_order.py — run_marketo(): creates and posts a FOK market order
291
+ cancel.py — cancel_all_orders() / cancel_by_order_ids()
292
+ ```
293
+
294
+ ---
295
+
296
+ ## External APIs
297
+
298
+ | API | Base URL | Auth | Used for |
299
+ |---|---|---|---|
300
+ | GAMMA | `https://gamma-api.polymarket.com` | None | Event/market metadata, slug→token ID resolution |
301
+ | CLOB | `https://clob.polymarket.com` | L2 builder key | Orderbook, order placement, trade history |
302
+ | Data API | `https://data-api.polymarket.com` | None | Open positions |
@@ -0,0 +1,5 @@
1
+ """pmls package."""
2
+
3
+ __all__ = ["__version__"]
4
+
5
+ __version__ = "0.1.0"
File without changes