@liberfi.io/react-predict 0.3.67 → 0.3.69
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.
- package/dist/index.d.mts +40 -3
- package/dist/index.d.ts +40 -3
- package/dist/index.js +439 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +412 -112
- package/dist/index.mjs.map +1 -1
- package/dist/{server-B6SSpkMN.d.mts → server-CCZfNoWO.d.mts} +244 -1
- package/dist/{server-B6SSpkMN.d.ts → server-CCZfNoWO.d.ts} +244 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +204 -0
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +175 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +11 -4
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { httpGet, httpPost, httpDelete } from '@liberfi.io/utils';
|
|
2
2
|
import { createContext, useMemo, useState, useRef, useCallback, useContext, useEffect } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
|
-
import { useQuery, useInfiniteQuery, useQueries, useMutation
|
|
4
|
+
import { useQuery, useInfiniteQuery, useQueryClient, useQueries, useMutation } from '@tanstack/react-query';
|
|
5
5
|
import { OrderBuilder, SignatureTypeV2, Side, OrderType, orderToJsonV2, ClobClient } from '@polymarket/clob-client-v2';
|
|
6
6
|
|
|
7
7
|
// src/client/client.ts
|
|
@@ -82,6 +82,67 @@ var PredictClient = class {
|
|
|
82
82
|
const url = `${this.endpoint}/api/v1/events/${encodeURIComponent(slug)}/similar${query}`;
|
|
83
83
|
return await httpGet(url);
|
|
84
84
|
}
|
|
85
|
+
// -------------------------------------------------------------------------
|
|
86
|
+
// Sports / esports
|
|
87
|
+
// -------------------------------------------------------------------------
|
|
88
|
+
/** Maps to `GET /api/v1/sports/taxonomy`. */
|
|
89
|
+
async getSportsTaxonomy(params) {
|
|
90
|
+
const query = buildQuery(params ?? {});
|
|
91
|
+
const url = `${this.endpoint}/api/v1/sports/taxonomy${query}`;
|
|
92
|
+
return await httpGet(url, this.requestOptions());
|
|
93
|
+
}
|
|
94
|
+
/** Maps to `GET /api/v1/sports/matches`. */
|
|
95
|
+
async getSportsMatches(params) {
|
|
96
|
+
const query = buildQuery(params ?? {});
|
|
97
|
+
const url = `${this.endpoint}/api/v1/sports/matches${query}`;
|
|
98
|
+
return await httpGet(url, this.requestOptions());
|
|
99
|
+
}
|
|
100
|
+
/** Maps to `GET /api/v1/sports/props`. */
|
|
101
|
+
async getSportsProps(params) {
|
|
102
|
+
const query = buildQuery(params ?? {});
|
|
103
|
+
const url = `${this.endpoint}/api/v1/sports/props${query}`;
|
|
104
|
+
return await httpGet(url, this.requestOptions());
|
|
105
|
+
}
|
|
106
|
+
/** Maps to `GET /api/v1/esports/taxonomy`. */
|
|
107
|
+
async getEsportsTaxonomy(params) {
|
|
108
|
+
const query = buildQuery(params ?? {});
|
|
109
|
+
const url = `${this.endpoint}/api/v1/esports/taxonomy${query}`;
|
|
110
|
+
return await httpGet(url, this.requestOptions());
|
|
111
|
+
}
|
|
112
|
+
/** Maps to `GET /api/v1/esports/matches`. */
|
|
113
|
+
async getEsportsMatches(params) {
|
|
114
|
+
const query = buildQuery(params ?? {});
|
|
115
|
+
const url = `${this.endpoint}/api/v1/esports/matches${query}`;
|
|
116
|
+
return await httpGet(url, this.requestOptions());
|
|
117
|
+
}
|
|
118
|
+
/** Maps to `GET /api/v1/esports/props`. */
|
|
119
|
+
async getEsportsProps(params) {
|
|
120
|
+
const query = buildQuery(params ?? {});
|
|
121
|
+
const url = `${this.endpoint}/api/v1/esports/props${query}`;
|
|
122
|
+
return await httpGet(url, this.requestOptions());
|
|
123
|
+
}
|
|
124
|
+
/** Maps to `GET /api/v1/sports/routing/:slug`. */
|
|
125
|
+
async getSportsRouting(slug, params) {
|
|
126
|
+
const query = buildQuery(params ?? {});
|
|
127
|
+
const url = `${this.endpoint}/api/v1/sports/routing/${encodeURIComponent(slug)}${query}`;
|
|
128
|
+
return await httpGet(url, this.requestOptions());
|
|
129
|
+
}
|
|
130
|
+
/** Maps to `GET /api/v1/sports/matches/:match_group_slug`. */
|
|
131
|
+
async getSportsMatchDetail(section, matchGroupSlug, params) {
|
|
132
|
+
const query = buildQuery(params ?? {});
|
|
133
|
+
const url = `${this.endpoint}/api/v1/${encodeURIComponent(section)}/matches/${encodeURIComponent(matchGroupSlug)}${query}`;
|
|
134
|
+
return await httpGet(url, this.requestOptions());
|
|
135
|
+
}
|
|
136
|
+
/** Convenience wrapper for `GET /api/v1/esports/matches/:match_group_slug`. */
|
|
137
|
+
async getEsportsMatchDetail(matchGroupSlug, params) {
|
|
138
|
+
return this.getSportsMatchDetail("esports", matchGroupSlug, params);
|
|
139
|
+
}
|
|
140
|
+
/** Maps to `GET /api/v1/search`. */
|
|
141
|
+
async search(params) {
|
|
142
|
+
const query = buildQuery(params ?? {});
|
|
143
|
+
const url = `${this.endpoint}/api/v1/search${query}`;
|
|
144
|
+
return await httpGet(url, this.requestOptions());
|
|
145
|
+
}
|
|
85
146
|
/**
|
|
86
147
|
* List comments for a prediction event.
|
|
87
148
|
*
|
|
@@ -1220,6 +1281,355 @@ function useEvent(params, queryOptions = {}) {
|
|
|
1220
1281
|
...queryOptions
|
|
1221
1282
|
});
|
|
1222
1283
|
}
|
|
1284
|
+
|
|
1285
|
+
// src/hooks/predict/search.params.ts
|
|
1286
|
+
function predictSearchQueryKey(params) {
|
|
1287
|
+
return ["predict", "search-documents", params];
|
|
1288
|
+
}
|
|
1289
|
+
function resolvePredictSearchParams(params = {}) {
|
|
1290
|
+
const q = params.q ?? "";
|
|
1291
|
+
return {
|
|
1292
|
+
...params,
|
|
1293
|
+
q,
|
|
1294
|
+
sort_by: params.sort_by ?? (q ? "relevance" : "volume"),
|
|
1295
|
+
sort_asc: params.sort_asc ?? (q ? void 0 : false)
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
async function fetchPredictSearch(client, params) {
|
|
1299
|
+
return client.search(resolvePredictSearchParams(params));
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// src/hooks/predict/usePredictSearch.ts
|
|
1303
|
+
function usePredictSearch(params = {}, queryOptions) {
|
|
1304
|
+
const client = usePredictClient();
|
|
1305
|
+
const resolved = resolvePredictSearchParams(params);
|
|
1306
|
+
return useQuery({
|
|
1307
|
+
queryKey: predictSearchQueryKey(resolved),
|
|
1308
|
+
queryFn: () => fetchPredictSearch(client, resolved),
|
|
1309
|
+
enabled: queryOptions?.enabled ?? true
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
function useInfinitePredictSearch(params = {}, queryOptions) {
|
|
1313
|
+
const client = usePredictClient();
|
|
1314
|
+
const resolved = resolvePredictSearchParams(params);
|
|
1315
|
+
return useInfiniteQuery({
|
|
1316
|
+
queryKey: predictSearchQueryKey(resolved),
|
|
1317
|
+
queryFn: ({ pageParam }) => fetchPredictSearch(client, {
|
|
1318
|
+
...resolved,
|
|
1319
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1320
|
+
}),
|
|
1321
|
+
initialPageParam: void 0,
|
|
1322
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1323
|
+
enabled: queryOptions?.enabled ?? true
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// src/hooks/predict/sports.params.ts
|
|
1328
|
+
function sportsTaxonomyQueryKey(params) {
|
|
1329
|
+
return ["predict", "sports", "taxonomy", params];
|
|
1330
|
+
}
|
|
1331
|
+
function sportsMatchesQueryKey(params) {
|
|
1332
|
+
return ["predict", "sports", "matches", params];
|
|
1333
|
+
}
|
|
1334
|
+
function sportsPropsQueryKey(params) {
|
|
1335
|
+
return ["predict", "sports", "props", params];
|
|
1336
|
+
}
|
|
1337
|
+
function resolveSportsTaxonomyParams(params = {}) {
|
|
1338
|
+
return { ...params, section: "sports" };
|
|
1339
|
+
}
|
|
1340
|
+
function resolveSportsMatchesParams(params = {}) {
|
|
1341
|
+
return params;
|
|
1342
|
+
}
|
|
1343
|
+
function resolveSportsPropsParams(params = {}) {
|
|
1344
|
+
return params;
|
|
1345
|
+
}
|
|
1346
|
+
async function fetchSportsTaxonomy(client, params) {
|
|
1347
|
+
return client.getSportsTaxonomy(resolveSportsTaxonomyParams(params));
|
|
1348
|
+
}
|
|
1349
|
+
async function fetchSportsMatches(client, params) {
|
|
1350
|
+
return client.getSportsMatches(resolveSportsMatchesParams(params));
|
|
1351
|
+
}
|
|
1352
|
+
async function fetchSportsProps(client, params) {
|
|
1353
|
+
return client.getSportsProps(resolveSportsPropsParams(params));
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// src/hooks/predict/useSportsTaxonomy.ts
|
|
1357
|
+
function useSportsTaxonomy(params = {}, queryOptions = {}) {
|
|
1358
|
+
const client = usePredictClient();
|
|
1359
|
+
const resolved = resolveSportsTaxonomyParams(params);
|
|
1360
|
+
return useQuery({
|
|
1361
|
+
queryKey: sportsTaxonomyQueryKey(resolved),
|
|
1362
|
+
queryFn: () => fetchSportsTaxonomy(client, resolved),
|
|
1363
|
+
...queryOptions
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
function useSportsMatches(params = {}, queryOptions) {
|
|
1367
|
+
const client = usePredictClient();
|
|
1368
|
+
const resolved = resolveSportsMatchesParams(params);
|
|
1369
|
+
return useInfiniteQuery({
|
|
1370
|
+
queryKey: sportsMatchesQueryKey(resolved),
|
|
1371
|
+
queryFn: ({ pageParam }) => fetchSportsMatches(client, {
|
|
1372
|
+
...resolved,
|
|
1373
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1374
|
+
}),
|
|
1375
|
+
initialPageParam: void 0,
|
|
1376
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1377
|
+
enabled: queryOptions?.enabled ?? true
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
function useSportsProps(params = {}, queryOptions) {
|
|
1381
|
+
const client = usePredictClient();
|
|
1382
|
+
const resolved = resolveSportsPropsParams(params);
|
|
1383
|
+
return useInfiniteQuery({
|
|
1384
|
+
queryKey: sportsPropsQueryKey(resolved),
|
|
1385
|
+
queryFn: ({ pageParam }) => fetchSportsProps(client, {
|
|
1386
|
+
...resolved,
|
|
1387
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1388
|
+
}),
|
|
1389
|
+
initialPageParam: void 0,
|
|
1390
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1391
|
+
enabled: queryOptions?.enabled ?? true
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
// src/hooks/predict/esports.params.ts
|
|
1396
|
+
function esportsTaxonomyQueryKey(params) {
|
|
1397
|
+
return ["predict", "esports", "taxonomy", params];
|
|
1398
|
+
}
|
|
1399
|
+
function esportsMatchesQueryKey(params) {
|
|
1400
|
+
return ["predict", "esports", "matches", params];
|
|
1401
|
+
}
|
|
1402
|
+
function esportsPropsQueryKey(params) {
|
|
1403
|
+
return ["predict", "esports", "props", params];
|
|
1404
|
+
}
|
|
1405
|
+
function resolveEsportsTaxonomyParams(params = {}) {
|
|
1406
|
+
return params;
|
|
1407
|
+
}
|
|
1408
|
+
function resolveEsportsMatchesParams(params = {}) {
|
|
1409
|
+
return params;
|
|
1410
|
+
}
|
|
1411
|
+
function resolveEsportsPropsParams(params = {}) {
|
|
1412
|
+
return params;
|
|
1413
|
+
}
|
|
1414
|
+
async function fetchEsportsTaxonomy(client, params) {
|
|
1415
|
+
return client.getEsportsTaxonomy(resolveEsportsTaxonomyParams(params));
|
|
1416
|
+
}
|
|
1417
|
+
async function fetchEsportsMatches(client, params) {
|
|
1418
|
+
return client.getEsportsMatches(resolveEsportsMatchesParams(params));
|
|
1419
|
+
}
|
|
1420
|
+
async function fetchEsportsProps(client, params) {
|
|
1421
|
+
return client.getEsportsProps(resolveEsportsPropsParams(params));
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
// src/hooks/predict/useEsportsTaxonomy.ts
|
|
1425
|
+
function useEsportsTaxonomy(params = {}, queryOptions = {}) {
|
|
1426
|
+
const client = usePredictClient();
|
|
1427
|
+
const resolved = resolveEsportsTaxonomyParams(params);
|
|
1428
|
+
return useQuery({
|
|
1429
|
+
queryKey: esportsTaxonomyQueryKey(resolved),
|
|
1430
|
+
queryFn: () => fetchEsportsTaxonomy(client, resolved),
|
|
1431
|
+
...queryOptions
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
function useEsportsMatches(params = {}, queryOptions) {
|
|
1435
|
+
const client = usePredictClient();
|
|
1436
|
+
const resolved = resolveEsportsMatchesParams(params);
|
|
1437
|
+
return useInfiniteQuery({
|
|
1438
|
+
queryKey: esportsMatchesQueryKey(resolved),
|
|
1439
|
+
queryFn: ({ pageParam }) => fetchEsportsMatches(client, {
|
|
1440
|
+
...resolved,
|
|
1441
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1442
|
+
}),
|
|
1443
|
+
initialPageParam: void 0,
|
|
1444
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1445
|
+
enabled: queryOptions?.enabled ?? true
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
function useEsportsProps(params = {}, queryOptions) {
|
|
1449
|
+
const client = usePredictClient();
|
|
1450
|
+
const resolved = resolveEsportsPropsParams(params);
|
|
1451
|
+
return useInfiniteQuery({
|
|
1452
|
+
queryKey: esportsPropsQueryKey(resolved),
|
|
1453
|
+
queryFn: ({ pageParam }) => fetchEsportsProps(client, {
|
|
1454
|
+
...resolved,
|
|
1455
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1456
|
+
}),
|
|
1457
|
+
initialPageParam: void 0,
|
|
1458
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1459
|
+
enabled: queryOptions?.enabled ?? true
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// src/hooks/predict/sports-routing.params.ts
|
|
1464
|
+
function sportsRoutingQueryKey(slug, params) {
|
|
1465
|
+
return ["predict", "sports", "routing", slug, params];
|
|
1466
|
+
}
|
|
1467
|
+
function resolveSportsRoutingParams(params = {}) {
|
|
1468
|
+
return params;
|
|
1469
|
+
}
|
|
1470
|
+
async function fetchSportsRouting(client, slug, params) {
|
|
1471
|
+
return client.getSportsRouting(slug, resolveSportsRoutingParams(params));
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// src/hooks/predict/useSportsRouting.ts
|
|
1475
|
+
function useSportsRouting(slug, params = {}, queryOptions = {}) {
|
|
1476
|
+
const client = usePredictClient();
|
|
1477
|
+
const resolved = resolveSportsRoutingParams(params);
|
|
1478
|
+
return useQuery({
|
|
1479
|
+
queryKey: sportsRoutingQueryKey(slug, resolved),
|
|
1480
|
+
queryFn: () => fetchSportsRouting(client, slug, resolved),
|
|
1481
|
+
enabled: Boolean(slug),
|
|
1482
|
+
...queryOptions
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
// src/hooks/predict/sports-match-detail.params.ts
|
|
1487
|
+
function sportsMatchDetailQueryKey(section, matchGroupSlug, params) {
|
|
1488
|
+
return ["predict", section, "match-detail", matchGroupSlug, params];
|
|
1489
|
+
}
|
|
1490
|
+
function resolveSportsMatchDetailParams(params = {}) {
|
|
1491
|
+
return params;
|
|
1492
|
+
}
|
|
1493
|
+
async function fetchSportsMatchDetail(client, section, matchGroupSlug, params) {
|
|
1494
|
+
return client.getSportsMatchDetail(
|
|
1495
|
+
section,
|
|
1496
|
+
matchGroupSlug,
|
|
1497
|
+
resolveSportsMatchDetailParams(params)
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// src/hooks/predict/useSportsMatchDetail.ts
|
|
1502
|
+
function useSportsMatchDetail(section, matchGroupSlug, params = {}, queryOptions = {}) {
|
|
1503
|
+
const client = usePredictClient();
|
|
1504
|
+
const resolved = resolveSportsMatchDetailParams(params);
|
|
1505
|
+
return useQuery({
|
|
1506
|
+
queryKey: sportsMatchDetailQueryKey(section, matchGroupSlug, resolved),
|
|
1507
|
+
queryFn: () => fetchSportsMatchDetail(client, section, matchGroupSlug, resolved),
|
|
1508
|
+
enabled: Boolean(section && matchGroupSlug),
|
|
1509
|
+
...queryOptions
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
function orderbookQueryKey(slug, source, outcome = "yes") {
|
|
1513
|
+
return ["predict", "orderbook", slug, source, outcome];
|
|
1514
|
+
}
|
|
1515
|
+
function useOrderbook(params, queryOptions = {}) {
|
|
1516
|
+
const client = usePredictClient();
|
|
1517
|
+
const outcome = params.outcome ?? "yes";
|
|
1518
|
+
return useQuery({
|
|
1519
|
+
queryKey: orderbookQueryKey(params.slug, params.source, outcome),
|
|
1520
|
+
queryFn: () => client.getOrderbook(params.slug, params.source, outcome),
|
|
1521
|
+
enabled: Boolean(params.slug),
|
|
1522
|
+
refetchInterval: 3e4,
|
|
1523
|
+
...queryOptions
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
function useOrderbookSubscription({
|
|
1527
|
+
wsClient,
|
|
1528
|
+
slug,
|
|
1529
|
+
enabled = true,
|
|
1530
|
+
outcome,
|
|
1531
|
+
onUpdate
|
|
1532
|
+
}) {
|
|
1533
|
+
const [orderbook, setOrderbook] = useState(null);
|
|
1534
|
+
const [isSubscribed, setIsSubscribed] = useState(false);
|
|
1535
|
+
const onUpdateRef = useRef(onUpdate);
|
|
1536
|
+
onUpdateRef.current = onUpdate;
|
|
1537
|
+
const handleUpdate = useCallback(
|
|
1538
|
+
(msg) => {
|
|
1539
|
+
if (msg.data.market_slug === slug) {
|
|
1540
|
+
if (!outcome || msg.data.outcome === outcome) {
|
|
1541
|
+
setOrderbook(msg.data);
|
|
1542
|
+
}
|
|
1543
|
+
onUpdateRef.current?.(msg);
|
|
1544
|
+
}
|
|
1545
|
+
},
|
|
1546
|
+
[slug, outcome]
|
|
1547
|
+
);
|
|
1548
|
+
useEffect(() => {
|
|
1549
|
+
if (!wsClient || !enabled || !slug) {
|
|
1550
|
+
setIsSubscribed(false);
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
setOrderbook(null);
|
|
1554
|
+
const unsub = wsClient.subscribeOrderbook([slug], handleUpdate);
|
|
1555
|
+
setIsSubscribed(true);
|
|
1556
|
+
return () => {
|
|
1557
|
+
unsub();
|
|
1558
|
+
setIsSubscribed(false);
|
|
1559
|
+
};
|
|
1560
|
+
}, [wsClient, enabled, slug, handleUpdate]);
|
|
1561
|
+
return { orderbook, isSubscribed };
|
|
1562
|
+
}
|
|
1563
|
+
function usePredictWsClient() {
|
|
1564
|
+
const context = useContext(PredictContext);
|
|
1565
|
+
if (!context) {
|
|
1566
|
+
throw new Error("usePredictWsClient must be used within a PredictProvider");
|
|
1567
|
+
}
|
|
1568
|
+
const { wsClient } = context;
|
|
1569
|
+
const [wsStatus, setWsStatus] = useState(
|
|
1570
|
+
wsClient?.getStatus() ?? "disconnected"
|
|
1571
|
+
);
|
|
1572
|
+
useEffect(() => {
|
|
1573
|
+
if (!wsClient) {
|
|
1574
|
+
setWsStatus("disconnected");
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
setWsStatus(wsClient.getStatus());
|
|
1578
|
+
return wsClient.onStatusChange(setWsStatus);
|
|
1579
|
+
}, [wsClient]);
|
|
1580
|
+
return {
|
|
1581
|
+
wsClient,
|
|
1582
|
+
wsStatus,
|
|
1583
|
+
isWsConnected: wsStatus === "connected"
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
// src/hooks/predict/useRealtimeOrderbook.ts
|
|
1588
|
+
var REST_POLL_INTERVAL = 5e3;
|
|
1589
|
+
function useRealtimeOrderbook(params, queryOptions = {}) {
|
|
1590
|
+
const { wsClient } = usePredictWsClient();
|
|
1591
|
+
const queryClient = useQueryClient();
|
|
1592
|
+
const outcome = params.outcome ?? "yes";
|
|
1593
|
+
const handleUpdate = useCallback(
|
|
1594
|
+
(msg) => {
|
|
1595
|
+
if (msg.data.market_slug !== params.slug) return;
|
|
1596
|
+
if (msg.data.outcome !== "yes" && msg.data.outcome !== "no") return;
|
|
1597
|
+
const ob = {
|
|
1598
|
+
market_id: msg.data.market_slug,
|
|
1599
|
+
outcome: msg.data.outcome,
|
|
1600
|
+
bids: msg.data.bids,
|
|
1601
|
+
asks: msg.data.asks,
|
|
1602
|
+
spread: msg.data.spread
|
|
1603
|
+
};
|
|
1604
|
+
queryClient.setQueryData(
|
|
1605
|
+
orderbookQueryKey(params.slug, params.source, msg.data.outcome),
|
|
1606
|
+
ob
|
|
1607
|
+
);
|
|
1608
|
+
},
|
|
1609
|
+
[params.slug, params.source, queryClient]
|
|
1610
|
+
);
|
|
1611
|
+
const subParams = {
|
|
1612
|
+
wsClient,
|
|
1613
|
+
slug: params.slug,
|
|
1614
|
+
enabled: Boolean(params.slug),
|
|
1615
|
+
outcome,
|
|
1616
|
+
onUpdate: handleUpdate
|
|
1617
|
+
};
|
|
1618
|
+
const { isSubscribed } = useOrderbookSubscription(subParams);
|
|
1619
|
+
return useOrderbook(params, {
|
|
1620
|
+
refetchInterval: isSubscribed ? false : REST_POLL_INTERVAL,
|
|
1621
|
+
...queryOptions
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// src/hooks/predict/useSportsOrderbook.ts
|
|
1626
|
+
function useSportsOrderbook(key) {
|
|
1627
|
+
return useRealtimeOrderbook({
|
|
1628
|
+
slug: key.market_slug,
|
|
1629
|
+
source: key.source,
|
|
1630
|
+
outcome: key.outcome
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1223
1633
|
function useInfiniteEvents(params, queryOptions = {}) {
|
|
1224
1634
|
const client = usePredictClient();
|
|
1225
1635
|
return useInfiniteQuery({
|
|
@@ -1475,20 +1885,6 @@ function useMarketHistory(markets, range = ChartRange.ALL, options = {}) {
|
|
|
1475
1885
|
}, [marketParams, queries]);
|
|
1476
1886
|
return { series, isLoading };
|
|
1477
1887
|
}
|
|
1478
|
-
function orderbookQueryKey(slug, source, outcome = "yes") {
|
|
1479
|
-
return ["predict", "orderbook", slug, source, outcome];
|
|
1480
|
-
}
|
|
1481
|
-
function useOrderbook(params, queryOptions = {}) {
|
|
1482
|
-
const client = usePredictClient();
|
|
1483
|
-
const outcome = params.outcome ?? "yes";
|
|
1484
|
-
return useQuery({
|
|
1485
|
-
queryKey: orderbookQueryKey(params.slug, params.source, outcome),
|
|
1486
|
-
queryFn: () => client.getOrderbook(params.slug, params.source, outcome),
|
|
1487
|
-
enabled: Boolean(params.slug),
|
|
1488
|
-
refetchInterval: 3e4,
|
|
1489
|
-
...queryOptions
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
1888
|
function marketTradesQueryKey(slug, params) {
|
|
1493
1889
|
return ["predict", "market-trades", slug, params];
|
|
1494
1890
|
}
|
|
@@ -2682,29 +3078,6 @@ function useRebateConfig(queryOptions = {}) {
|
|
|
2682
3078
|
...queryOptions
|
|
2683
3079
|
});
|
|
2684
3080
|
}
|
|
2685
|
-
function usePredictWsClient() {
|
|
2686
|
-
const context = useContext(PredictContext);
|
|
2687
|
-
if (!context) {
|
|
2688
|
-
throw new Error("usePredictWsClient must be used within a PredictProvider");
|
|
2689
|
-
}
|
|
2690
|
-
const { wsClient } = context;
|
|
2691
|
-
const [wsStatus, setWsStatus] = useState(
|
|
2692
|
-
wsClient?.getStatus() ?? "disconnected"
|
|
2693
|
-
);
|
|
2694
|
-
useEffect(() => {
|
|
2695
|
-
if (!wsClient) {
|
|
2696
|
-
setWsStatus("disconnected");
|
|
2697
|
-
return;
|
|
2698
|
-
}
|
|
2699
|
-
setWsStatus(wsClient.getStatus());
|
|
2700
|
-
return wsClient.onStatusChange(setWsStatus);
|
|
2701
|
-
}, [wsClient]);
|
|
2702
|
-
return {
|
|
2703
|
-
wsClient,
|
|
2704
|
-
wsStatus,
|
|
2705
|
-
isWsConnected: wsStatus === "connected"
|
|
2706
|
-
};
|
|
2707
|
-
}
|
|
2708
3081
|
function usePricesSubscription({
|
|
2709
3082
|
wsClient,
|
|
2710
3083
|
slugs,
|
|
@@ -2740,43 +3113,6 @@ function usePricesSubscription({
|
|
|
2740
3113
|
}, [wsClient, enabled, slugsKey, handleUpdate]);
|
|
2741
3114
|
return { prices, isSubscribed };
|
|
2742
3115
|
}
|
|
2743
|
-
function useOrderbookSubscription({
|
|
2744
|
-
wsClient,
|
|
2745
|
-
slug,
|
|
2746
|
-
enabled = true,
|
|
2747
|
-
outcome,
|
|
2748
|
-
onUpdate
|
|
2749
|
-
}) {
|
|
2750
|
-
const [orderbook, setOrderbook] = useState(null);
|
|
2751
|
-
const [isSubscribed, setIsSubscribed] = useState(false);
|
|
2752
|
-
const onUpdateRef = useRef(onUpdate);
|
|
2753
|
-
onUpdateRef.current = onUpdate;
|
|
2754
|
-
const handleUpdate = useCallback(
|
|
2755
|
-
(msg) => {
|
|
2756
|
-
if (msg.data.market_slug === slug) {
|
|
2757
|
-
if (!outcome || msg.data.outcome === outcome) {
|
|
2758
|
-
setOrderbook(msg.data);
|
|
2759
|
-
}
|
|
2760
|
-
onUpdateRef.current?.(msg);
|
|
2761
|
-
}
|
|
2762
|
-
},
|
|
2763
|
-
[slug, outcome]
|
|
2764
|
-
);
|
|
2765
|
-
useEffect(() => {
|
|
2766
|
-
if (!wsClient || !enabled || !slug) {
|
|
2767
|
-
setIsSubscribed(false);
|
|
2768
|
-
return;
|
|
2769
|
-
}
|
|
2770
|
-
setOrderbook(null);
|
|
2771
|
-
const unsub = wsClient.subscribeOrderbook([slug], handleUpdate);
|
|
2772
|
-
setIsSubscribed(true);
|
|
2773
|
-
return () => {
|
|
2774
|
-
unsub();
|
|
2775
|
-
setIsSubscribed(false);
|
|
2776
|
-
};
|
|
2777
|
-
}, [wsClient, enabled, slug, handleUpdate]);
|
|
2778
|
-
return { orderbook, isSubscribed };
|
|
2779
|
-
}
|
|
2780
3116
|
var DEFAULT_MAX_HISTORY = 100;
|
|
2781
3117
|
function useTradesSubscription({
|
|
2782
3118
|
wsClient,
|
|
@@ -2821,42 +3157,6 @@ function useTradesSubscription({
|
|
|
2821
3157
|
}, [wsClient, enabled, slug, handleUpdate]);
|
|
2822
3158
|
return { trades, isSubscribed, clearHistory };
|
|
2823
3159
|
}
|
|
2824
|
-
var REST_POLL_INTERVAL = 5e3;
|
|
2825
|
-
function useRealtimeOrderbook(params, queryOptions = {}) {
|
|
2826
|
-
const { wsClient } = usePredictWsClient();
|
|
2827
|
-
const queryClient = useQueryClient();
|
|
2828
|
-
const outcome = params.outcome ?? "yes";
|
|
2829
|
-
const handleUpdate = useCallback(
|
|
2830
|
-
(msg) => {
|
|
2831
|
-
if (msg.data.market_slug !== params.slug) return;
|
|
2832
|
-
if (msg.data.outcome !== "yes" && msg.data.outcome !== "no") return;
|
|
2833
|
-
const ob = {
|
|
2834
|
-
market_id: msg.data.market_slug,
|
|
2835
|
-
outcome: msg.data.outcome,
|
|
2836
|
-
bids: msg.data.bids,
|
|
2837
|
-
asks: msg.data.asks,
|
|
2838
|
-
spread: msg.data.spread
|
|
2839
|
-
};
|
|
2840
|
-
queryClient.setQueryData(
|
|
2841
|
-
orderbookQueryKey(params.slug, params.source, msg.data.outcome),
|
|
2842
|
-
ob
|
|
2843
|
-
);
|
|
2844
|
-
},
|
|
2845
|
-
[params.slug, params.source, queryClient]
|
|
2846
|
-
);
|
|
2847
|
-
const subParams = {
|
|
2848
|
-
wsClient,
|
|
2849
|
-
slug: params.slug,
|
|
2850
|
-
enabled: Boolean(params.slug),
|
|
2851
|
-
outcome,
|
|
2852
|
-
onUpdate: handleUpdate
|
|
2853
|
-
};
|
|
2854
|
-
const { isSubscribed } = useOrderbookSubscription(subParams);
|
|
2855
|
-
return useOrderbook(params, {
|
|
2856
|
-
refetchInterval: isSubscribed ? false : REST_POLL_INTERVAL,
|
|
2857
|
-
...queryOptions
|
|
2858
|
-
});
|
|
2859
|
-
}
|
|
2860
3160
|
|
|
2861
3161
|
// src/hooks/predict/useRealtimePrices.ts
|
|
2862
3162
|
function useRealtimePrices({
|
|
@@ -3374,6 +3674,6 @@ function walkOrderbook({
|
|
|
3374
3674
|
};
|
|
3375
3675
|
}
|
|
3376
3676
|
|
|
3377
|
-
export { CLOB_AUTH_DOMAIN, CLOB_AUTH_TYPES, CTF_EXCHANGE_ADDRESS, CTF_ORDER_TYPES, ChartRange, NEG_RISK_CTF_EXCHANGE_ADDRESS, ORDER_TYPE, POLYGON_CHAIN_ID, PolymarketContext, PolymarketProvider, PredictClient, PredictContext, PredictProvider, PredictWsClient, SIDE, USDC_ADDRESS, availableSharesQueryKey, balanceQueryKey, buildClobAuthMessage, buildClobPayload, buildCtfExchangeDomain, buildOrderMessage, buildPolymarketL2Headers, buildSignedOrder, buildSignedV2OrderPayload, candlesticksQueryKey, createPredictClient, createPredictWsClient, derivePolymarketApiKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventQueryKey, eventStatsQueryKey, eventsQueryKey, feeRateQueryKey, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, getPolymarketSharesPrecision, hmacSha256Base64, infiniteCommentsQueryKey, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, normalizePolymarketTickSize, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, polymarketSupportedAssetsQueryKey, polymarketWithdrawStatusQueryKey, positionValueMultiQueryKey, positionValueQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, rebateConfigQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, tickSizeQueryKey, tradesQueryKey, updatePolymarketBalanceAllowance, useAvailableShares, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useDeployPolymarketDepositWallet, useEvent, useEventStats, useEvents, useFeeRate, useInfiniteComments, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfiniteTrades, useInfiniteTradesMulti, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, useOrdersMulti, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketSupportedAssets, usePolymarketWithdraw, usePolymarketWithdrawPrepareMutation, usePolymarketWithdrawQuoteMutation, usePolymarketWithdrawRelayBuildMutation, usePolymarketWithdrawRelaySubmitMutation, usePolymarketWithdrawStatusQuery, usePositionValue, usePositionValueMulti, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRebateConfig, useRedeemPosition, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTradeResultConfirmation, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, walkOrderbook, withdrawStatusQueryKey };
|
|
3677
|
+
export { CLOB_AUTH_DOMAIN, CLOB_AUTH_TYPES, CTF_EXCHANGE_ADDRESS, CTF_ORDER_TYPES, ChartRange, NEG_RISK_CTF_EXCHANGE_ADDRESS, ORDER_TYPE, POLYGON_CHAIN_ID, PolymarketContext, PolymarketProvider, PredictClient, PredictContext, PredictProvider, PredictWsClient, SIDE, USDC_ADDRESS, availableSharesQueryKey, balanceQueryKey, buildClobAuthMessage, buildClobPayload, buildCtfExchangeDomain, buildOrderMessage, buildPolymarketL2Headers, buildSignedOrder, buildSignedV2OrderPayload, candlesticksQueryKey, createPredictClient, createPredictWsClient, derivePolymarketApiKey, dflowKYCQueryKey, dflowQuoteQueryKey, esportsMatchesQueryKey, esportsPropsQueryKey, esportsTaxonomyQueryKey, eventQueryKey, eventStatsQueryKey, eventsQueryKey, feeRateQueryKey, fetchEsportsMatches, fetchEsportsProps, fetchEsportsTaxonomy, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, fetchPredictSearch, fetchSportsMatchDetail, fetchSportsMatches, fetchSportsProps, fetchSportsRouting, fetchSportsTaxonomy, getPolymarketSharesPrecision, hmacSha256Base64, infiniteCommentsQueryKey, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, normalizePolymarketTickSize, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, polymarketSupportedAssetsQueryKey, polymarketWithdrawStatusQueryKey, positionValueMultiQueryKey, positionValueQueryKey, positionsMultiQueryKey, positionsQueryKey, predictSearchQueryKey, priceHistoryQueryKey, rebateConfigQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, sportsMatchDetailQueryKey, sportsMatchesQueryKey, sportsPropsQueryKey, sportsRoutingQueryKey, sportsTaxonomyQueryKey, tickSizeQueryKey, tradesQueryKey, updatePolymarketBalanceAllowance, useAvailableShares, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useDeployPolymarketDepositWallet, useEsportsMatches, useEsportsProps, useEsportsTaxonomy, useEvent, useEventStats, useEvents, useFeeRate, useInfiniteComments, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfinitePredictSearch, useInfiniteTrades, useInfiniteTradesMulti, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, useOrdersMulti, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketSupportedAssets, usePolymarketWithdraw, usePolymarketWithdrawPrepareMutation, usePolymarketWithdrawQuoteMutation, usePolymarketWithdrawRelayBuildMutation, usePolymarketWithdrawRelaySubmitMutation, usePolymarketWithdrawStatusQuery, usePositionValue, usePositionValueMulti, usePositions, usePositionsMulti, usePredictClient, usePredictSearch, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRebateConfig, useRedeemPosition, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useSportsMatchDetail, useSportsMatches, useSportsOrderbook, useSportsProps, useSportsRouting, useSportsTaxonomy, useTickSize, useTradeResultConfirmation, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, walkOrderbook, withdrawStatusQueryKey };
|
|
3378
3678
|
//# sourceMappingURL=index.mjs.map
|
|
3379
3679
|
//# sourceMappingURL=index.mjs.map
|