Skip to content

Commit ad98ed2

Browse files
committed
docs: update fetchOrderBook outcome examples
1 parent 7ea51f3 commit ad98ed2

2 files changed

Lines changed: 44 additions & 22 deletions

File tree

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [2.43.14] - 2026-05-24
6+
7+
### Fixed
8+
9+
- **Docs**: Updated the `fetchOrderBook` API reference examples to show the recommended historical order book flow: fetch a market by slug, pass `market_id` / `marketId`, and select the side with `params.outcome: "yes"` or `"no"`.
10+
511
## [2.43.13] - 2026-05-24
612

713
### Fixed

docs/api-reference/fetch-order-book.mdx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ openapi: GET /api/{exchange}/fetchOrderBook
77

88
### Live order book
99

10-
Fetch the current L2 order book for an outcome:
10+
Fetch the current L2 order book for an outcome. If you already have an outcome token ID, pass it directly:
1111

1212
<CodeGroup>
1313
```python Python
@@ -36,40 +36,52 @@ curl "https://api.pmxt.dev/api/polymarket/fetchOrderBook?outcomeId=1049326100321
3636

3737
Get the order book at a specific point in time. Pass `since` as a Unix timestamp in milliseconds — returns the nearest snapshot at or before that time.
3838

39+
For binary markets, you can pass the market ID and choose the side with `params.outcome`. Use `"yes"` or `"no"` instead of copying the long outcome token ID:
40+
3941
<CodeGroup>
4042
```python Python
4143
import pmxt
42-
from datetime import datetime
4344

4445
poly = pmxt.Polymarket(pmxt_api_key="pmxt_...")
4546

46-
# 2028 Presidential Election — order book from last week
47+
market = poly.fetch_market(
48+
slug="will-spacex-starship-flight-test-12-launch-by-may-22-354-721"
49+
)
50+
4751
book = poly.fetch_order_book(
48-
"0xce9a5fa30fe74e323b4a8f15afbb0b7a41a537aa880779ddf7dee22223b2f34a",
49-
params={"since": int(datetime(2026, 5, 20, 12, 0).timestamp() * 1000)}
52+
market.market_id,
53+
params={"since": 1779487200000, "outcome": "yes"},
5054
)
51-
print(f"{book.dt}{len(book.bids)} bids, {len(book.asks)} asks")
55+
56+
print(f"{book.dt}: {len(book.bids)} bids, {len(book.asks)} asks")
57+
print(f" best bid: {max(b.price for b in book.bids):.3f}")
58+
print(f" best ask: {min(a.price for a in book.asks):.3f}")
5259
```
5360

5461
```javascript JavaScript
5562
import { Polymarket } from "pmxtjs";
5663

5764
const poly = new Polymarket({ pmxtApiKey: "pmxt_..." });
5865

59-
// 2028 Presidential Election — order book from last week
66+
const market = await poly.fetchMarket({
67+
slug: "will-spacex-starship-flight-test-12-launch-by-may-22-354-721",
68+
});
69+
6070
const book = await poly.fetchOrderBook(
61-
"0xce9a5fa30fe74e323b4a8f15afbb0b7a41a537aa880779ddf7dee22223b2f34a",
71+
market.marketId,
6272
undefined,
63-
{ since: new Date("2026-05-20T12:00:00Z").getTime() }
73+
{ since: 1779487200000, outcome: "yes" }
6474
);
65-
console.log(`${book.datetime}${book.bids.length} bids, ${book.asks.length} asks`);
75+
console.log(`${book.datetime}: ${book.bids.length} bids, ${book.asks.length} asks`);
76+
console.log(` best bid: ${Math.max(...book.bids.map((b) => b.price)).toFixed(3)}`);
77+
console.log(` best ask: ${Math.min(...book.asks.map((a) => a.price)).toFixed(3)}`);
6678
```
6779

6880
```bash curl
6981
curl -X POST "https://api.pmxt.dev/api/polymarket/fetchOrderBook" \
7082
-H "Authorization: Bearer $PMXT_API_KEY" \
7183
-H "Content-Type: application/json" \
72-
-d '{"args":["0xce9a5fa30fe74e323b4a8f15afbb0b7a41a537aa880779ddf7dee22223b2f34a", null, {"since": 1747742400000}]}'
84+
-d '{"args":["61b0ed20-7f42-41fd-af15-7b86153f6bb7", null, {"since": 1779487200000, "outcome": "yes"}]}'
7385
```
7486
</CodeGroup>
7587

@@ -82,17 +94,19 @@ Default 100 snapshots per request, max 1000.
8294
<CodeGroup>
8395
```python Python
8496
import pmxt
85-
import time
8697

8798
poly = pmxt.Polymarket(pmxt_api_key="pmxt_...")
8899

89-
# 2028 Presidential Election — every order book change over the last hour
90-
now = int(time.time() * 1000)
100+
market = poly.fetch_market(
101+
slug="will-spacex-starship-flight-test-12-launch-by-may-22-354-721"
102+
)
103+
91104
books = poly.fetch_order_book(
92-
"0xce9a5fa30fe74e323b4a8f15afbb0b7a41a537aa880779ddf7dee22223b2f34a",
105+
market.market_id,
93106
params={
94-
"since": now - 60 * 60 * 1000,
95-
"until": now,
107+
"since": 1779480000000,
108+
"until": 1779487200000,
109+
"outcome": "yes",
96110
}
97111
)
98112
print(f"{len(books)} snapshots")
@@ -105,12 +119,14 @@ import { Polymarket } from "pmxtjs";
105119

106120
const poly = new Polymarket({ pmxtApiKey: "pmxt_..." });
107121

108-
// 2028 Presidential Election — every order book change over the last hour
109-
const now = Date.now();
122+
const market = await poly.fetchMarket({
123+
slug: "will-spacex-starship-flight-test-12-launch-by-may-22-354-721",
124+
});
125+
110126
const books = await poly.fetchOrderBook(
111-
"0xce9a5fa30fe74e323b4a8f15afbb0b7a41a537aa880779ddf7dee22223b2f34a",
127+
market.marketId,
112128
undefined,
113-
{ since: now - 60 * 60 * 1000, until: now }
129+
{ since: 1779480000000, until: 1779487200000, outcome: "yes" }
114130
);
115131
console.log(`${books.length} snapshots`);
116132
books.slice(0, 3).forEach((ob) =>
@@ -122,7 +138,7 @@ books.slice(0, 3).forEach((ob) =>
122138
curl -X POST "https://api.pmxt.dev/api/polymarket/fetchOrderBook" \
123139
-H "Authorization: Bearer $PMXT_API_KEY" \
124140
-H "Content-Type: application/json" \
125-
-d '{"args":["0xce9a5fa30fe74e323b4a8f15afbb0b7a41a537aa880779ddf7dee22223b2f34a", null, {"since": 1779300000000, "until": 1779400000000}]}'
141+
-d '{"args":["61b0ed20-7f42-41fd-af15-7b86153f6bb7", null, {"since": 1779480000000, "until": 1779487200000, "outcome": "yes"}]}'
126142
```
127143
</CodeGroup>
128144

0 commit comments

Comments
 (0)