You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/integrations/polymarket.md
+49-36Lines changed: 49 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ separately depending on the use case.
58
58
59
59
:::note
60
60
Most users will define a configuration for a live trading node (as below),
61
-
and won't need to necessarily work with these lowerlevel components directly.
61
+
and won't need to work with these lower-level components directly.
62
62
:::
63
63
64
64
## USDC.e (PoS)
@@ -99,7 +99,7 @@ Ensure your wallet is funded with **USDC.e**, otherwise you will encounter the "
99
99
### Setting allowances for Polymarket contracts
100
100
101
101
Before you can start trading, you need to ensure that your wallet has allowances set for Polymarket's smart contracts.
102
-
You can do this by running the provided script located at `/adapters/polymarket/scripts/set_allowances.py`.
102
+
You can do this by running the provided script located at `nautilus_trader/adapters/polymarket/scripts/set_allowances.py`.
103
103
104
104
This script is adapted from a [gist](https://gist.github.com/poly-rodr/44313920481de58d5a3f6d1f8226bd5e) created by @poly-rodr.
105
105
@@ -114,7 +114,7 @@ Polymarket CLOB Exchange to interact with your funds.
114
114
Before running the script, ensure the following prerequisites are met:
115
115
116
116
- Install the web3 Python package: `uv pip install "web3==7.12.1"`.
117
-
- Have a **Polygon**-compatible wallet funded with some MATIC (used for gas fees).
117
+
- Have a **Polygon**-compatible wallet funded with some POL (used for gas fees).
118
118
- Set the following environment variables in your shell:
119
119
-`POLYGON_PRIVATE_KEY`: Your private key for the **Polygon**-compatible wallet.
120
120
-`POLYGON_PUBLIC_KEY`: Your public key for the **Polygon**-compatible wallet.
@@ -150,7 +150,7 @@ The script performs the following actions:
150
150
- Connects to the Polygon network via an RPC URL (<https://polygon-rpc.com/>).
151
151
- Signs and sends a transaction to approve the maximum USDC allowance for Polymarket contracts.
152
152
- Sets approval for the CTF contract to manage Conditional Tokens on your behalf.
153
-
- Repeats the approval process for specific addresses like the Polymarket CLOB Exchange and Neg Risk Adapter.
153
+
- Repeats the approval process for specific addresses like the Polymarket CLOB Exchange and Neg Risk adapter.
154
154
155
155
This allows Polymarket to interact with your funds when executing trades and ensures smooth integration with the CLOB Exchange.
156
156
@@ -186,7 +186,7 @@ When setting up NautilusTrader to work with Polymarket, it’s crucial to proper
186
186
**Key parameters**:
187
187
188
188
-`private_key`: The private key for your wallet used to sign orders. The interpretation depends on your `signature_type` configuration. If not explicitly provided in the configuration, it will automatically source the `POLYMARKET_PK` environment variable.
189
-
-`funder`: The **USDC.e** wallet address used for funding trades. If not provided, will source the `POLYMARKET_FUNDER` environment variable.
189
+
-`funder`: The **USDC.e**funding wallet address used for funding trades. If not provided, will source the `POLYMARKET_FUNDER` environment variable.
190
190
- API credentials: You will need to provide the following API credentials to interact with the Polymarket CLOB:
191
191
-`api_key`: If not provided, will source the `POLYMARKET_API_KEY` environment variable.
192
192
-`api_secret`: If not provided, will source the `POLYMARKET_API_SECRET` environment variable.
@@ -271,11 +271,11 @@ FAK (Fill and Kill) is Polymarket's terminology for Immediate or Cancel (IOC) se
| Query order history | ✓ | Limited historical data. |
303
+
| Order status updates | ✓ | Real-time order state changes. |
304
+
| Trade history | ✓ | Execution and fill reports. |
305
305
306
306
### Contingent orders
307
307
@@ -356,13 +356,28 @@ Once a trade is initially matched, subsequent trade status updates will be recei
356
356
NautilusTrader records the initial trade details in the `info` field of the `OrderFilled` event,
357
357
with additional trade events stored in the cache as JSON under a custom key to retain this information.
358
358
359
+
## Fees
360
+
361
+
Polymarket charges **zero fees** on most markets. The exception is **15-minute crypto markets**:
362
+
363
+
| Trade Type | Fee Deducted In | Rate Range |
364
+
|------------|-----------------|-------------|
365
+
| Buy | Tokens | 0.2% - 1.6% |
366
+
| Sell | USDC | 0.8% - 3.7% |
367
+
368
+
Fees are rounded to 4 decimal places (0.0001 USDC minimum). Market makers receive daily rebates from collected taker fees.
369
+
370
+
:::note
371
+
For the latest rates, see Polymarket's [Fees](https://docs.polymarket.com/polymarket-learn/trading/fees) and [Maker Rebates](https://docs.polymarket.com/polymarket-learn/trading/maker-rebates-program) documentation.
372
+
:::
373
+
359
374
## Reconciliation
360
375
361
376
The Polymarket API returns either all **active** (open) orders or specific orders when queried by the
362
377
Polymarket order ID (`venue_order_id`). The execution reconciliation procedure for Polymarket is as follows:
363
378
364
379
- Generate order reports for all instruments with active (open) orders, as reported by Polymarket.
365
-
- Generate position reports from contract balances reported by Polymarket, *for instruments available in the cache*.
380
+
- Generate position reports from contract balances reported by Polymarket, for instruments available in the cache.
366
381
- Compare these reports with Nautilus execution state.
367
382
- Generate missing orders to bring Nautilus execution state in line with positions reported by Polymarket.
368
383
@@ -402,19 +417,19 @@ When you attempt to subscribe to 501 or more instruments on a single WebSocket c
402
417
- You will **not** receive the initial order book snapshot for each instrument.
403
418
- You will only receive subsequent order book updates.
404
419
405
-
To handle this limitation, NautilusTrader automatically manages WebSocket connections:
420
+
NautilusTrader automatically manages WebSocket connections to handle this limitation:
406
421
407
-
- When the subscription count exceeds 500 instruments, the adapter **automatically creates additional WebSocket connections**.
422
+
- When the subscription count exceeds 500 instruments, the adapter automatically creates additional WebSocket connections.
408
423
- Each connection maintains up to 500 instrument subscriptions.
409
-
- This protection ensures you receive complete order book data (including initial snapshots) for all subscribed instruments.
424
+
- This ensures you receive complete order book data (including initial snapshots) for all subscribed instruments.
410
425
411
426
:::tip
412
427
If you need to subscribe to a large number of instruments (e.g., 5000+), the adapter will automatically distribute these subscriptions across multiple WebSocket connections, with each connection handling up to 500 instruments.
413
428
:::
414
429
415
430
## Limitations and considerations
416
431
417
-
The following limitations and considerations are currently known:
432
+
The following limitations are currently known:
418
433
419
434
- Order signing via the Polymarket Python client is slow, taking around one second.
420
435
- Post-only orders are not supported.
@@ -502,15 +517,13 @@ All data loader methods are **asynchronous** and must be called with `await`.
502
517
503
518
```python
504
519
import asyncio
505
-
from datetime importUTC, datetime, timedelta
506
520
507
521
from nautilus_trader.adapters.polymarket import PolymarketDataLoader
508
522
from nautilus_trader.adapters.polymarket import parse_polymarket_instrument
509
-
from nautilus_trader.core.datetime import millis_to_nanos
510
523
511
524
asyncdefload_market_data():
512
525
# Discovery methods are static - no instance needed
0 commit comments