@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.js
CHANGED
|
@@ -84,6 +84,67 @@ var PredictClient = class {
|
|
|
84
84
|
const url = `${this.endpoint}/api/v1/events/${encodeURIComponent(slug)}/similar${query}`;
|
|
85
85
|
return await utils.httpGet(url);
|
|
86
86
|
}
|
|
87
|
+
// -------------------------------------------------------------------------
|
|
88
|
+
// Sports / esports
|
|
89
|
+
// -------------------------------------------------------------------------
|
|
90
|
+
/** Maps to `GET /api/v1/sports/taxonomy`. */
|
|
91
|
+
async getSportsTaxonomy(params) {
|
|
92
|
+
const query = buildQuery(params ?? {});
|
|
93
|
+
const url = `${this.endpoint}/api/v1/sports/taxonomy${query}`;
|
|
94
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
95
|
+
}
|
|
96
|
+
/** Maps to `GET /api/v1/sports/matches`. */
|
|
97
|
+
async getSportsMatches(params) {
|
|
98
|
+
const query = buildQuery(params ?? {});
|
|
99
|
+
const url = `${this.endpoint}/api/v1/sports/matches${query}`;
|
|
100
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
101
|
+
}
|
|
102
|
+
/** Maps to `GET /api/v1/sports/props`. */
|
|
103
|
+
async getSportsProps(params) {
|
|
104
|
+
const query = buildQuery(params ?? {});
|
|
105
|
+
const url = `${this.endpoint}/api/v1/sports/props${query}`;
|
|
106
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
107
|
+
}
|
|
108
|
+
/** Maps to `GET /api/v1/esports/taxonomy`. */
|
|
109
|
+
async getEsportsTaxonomy(params) {
|
|
110
|
+
const query = buildQuery(params ?? {});
|
|
111
|
+
const url = `${this.endpoint}/api/v1/esports/taxonomy${query}`;
|
|
112
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
113
|
+
}
|
|
114
|
+
/** Maps to `GET /api/v1/esports/matches`. */
|
|
115
|
+
async getEsportsMatches(params) {
|
|
116
|
+
const query = buildQuery(params ?? {});
|
|
117
|
+
const url = `${this.endpoint}/api/v1/esports/matches${query}`;
|
|
118
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
119
|
+
}
|
|
120
|
+
/** Maps to `GET /api/v1/esports/props`. */
|
|
121
|
+
async getEsportsProps(params) {
|
|
122
|
+
const query = buildQuery(params ?? {});
|
|
123
|
+
const url = `${this.endpoint}/api/v1/esports/props${query}`;
|
|
124
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
125
|
+
}
|
|
126
|
+
/** Maps to `GET /api/v1/sports/routing/:slug`. */
|
|
127
|
+
async getSportsRouting(slug, params) {
|
|
128
|
+
const query = buildQuery(params ?? {});
|
|
129
|
+
const url = `${this.endpoint}/api/v1/sports/routing/${encodeURIComponent(slug)}${query}`;
|
|
130
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
131
|
+
}
|
|
132
|
+
/** Maps to `GET /api/v1/sports/matches/:match_group_slug`. */
|
|
133
|
+
async getSportsMatchDetail(section, matchGroupSlug, params) {
|
|
134
|
+
const query = buildQuery(params ?? {});
|
|
135
|
+
const url = `${this.endpoint}/api/v1/${encodeURIComponent(section)}/matches/${encodeURIComponent(matchGroupSlug)}${query}`;
|
|
136
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
137
|
+
}
|
|
138
|
+
/** Convenience wrapper for `GET /api/v1/esports/matches/:match_group_slug`. */
|
|
139
|
+
async getEsportsMatchDetail(matchGroupSlug, params) {
|
|
140
|
+
return this.getSportsMatchDetail("esports", matchGroupSlug, params);
|
|
141
|
+
}
|
|
142
|
+
/** Maps to `GET /api/v1/search`. */
|
|
143
|
+
async search(params) {
|
|
144
|
+
const query = buildQuery(params ?? {});
|
|
145
|
+
const url = `${this.endpoint}/api/v1/search${query}`;
|
|
146
|
+
return await utils.httpGet(url, this.requestOptions());
|
|
147
|
+
}
|
|
87
148
|
/**
|
|
88
149
|
* List comments for a prediction event.
|
|
89
150
|
*
|
|
@@ -1222,6 +1283,355 @@ function useEvent(params, queryOptions = {}) {
|
|
|
1222
1283
|
...queryOptions
|
|
1223
1284
|
});
|
|
1224
1285
|
}
|
|
1286
|
+
|
|
1287
|
+
// src/hooks/predict/search.params.ts
|
|
1288
|
+
function predictSearchQueryKey(params) {
|
|
1289
|
+
return ["predict", "search-documents", params];
|
|
1290
|
+
}
|
|
1291
|
+
function resolvePredictSearchParams(params = {}) {
|
|
1292
|
+
const q = params.q ?? "";
|
|
1293
|
+
return {
|
|
1294
|
+
...params,
|
|
1295
|
+
q,
|
|
1296
|
+
sort_by: params.sort_by ?? (q ? "relevance" : "volume"),
|
|
1297
|
+
sort_asc: params.sort_asc ?? (q ? void 0 : false)
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
async function fetchPredictSearch(client, params) {
|
|
1301
|
+
return client.search(resolvePredictSearchParams(params));
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
// src/hooks/predict/usePredictSearch.ts
|
|
1305
|
+
function usePredictSearch(params = {}, queryOptions) {
|
|
1306
|
+
const client = usePredictClient();
|
|
1307
|
+
const resolved = resolvePredictSearchParams(params);
|
|
1308
|
+
return reactQuery.useQuery({
|
|
1309
|
+
queryKey: predictSearchQueryKey(resolved),
|
|
1310
|
+
queryFn: () => fetchPredictSearch(client, resolved),
|
|
1311
|
+
enabled: queryOptions?.enabled ?? true
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
function useInfinitePredictSearch(params = {}, queryOptions) {
|
|
1315
|
+
const client = usePredictClient();
|
|
1316
|
+
const resolved = resolvePredictSearchParams(params);
|
|
1317
|
+
return reactQuery.useInfiniteQuery({
|
|
1318
|
+
queryKey: predictSearchQueryKey(resolved),
|
|
1319
|
+
queryFn: ({ pageParam }) => fetchPredictSearch(client, {
|
|
1320
|
+
...resolved,
|
|
1321
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1322
|
+
}),
|
|
1323
|
+
initialPageParam: void 0,
|
|
1324
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1325
|
+
enabled: queryOptions?.enabled ?? true
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
// src/hooks/predict/sports.params.ts
|
|
1330
|
+
function sportsTaxonomyQueryKey(params) {
|
|
1331
|
+
return ["predict", "sports", "taxonomy", params];
|
|
1332
|
+
}
|
|
1333
|
+
function sportsMatchesQueryKey(params) {
|
|
1334
|
+
return ["predict", "sports", "matches", params];
|
|
1335
|
+
}
|
|
1336
|
+
function sportsPropsQueryKey(params) {
|
|
1337
|
+
return ["predict", "sports", "props", params];
|
|
1338
|
+
}
|
|
1339
|
+
function resolveSportsTaxonomyParams(params = {}) {
|
|
1340
|
+
return { ...params, section: "sports" };
|
|
1341
|
+
}
|
|
1342
|
+
function resolveSportsMatchesParams(params = {}) {
|
|
1343
|
+
return params;
|
|
1344
|
+
}
|
|
1345
|
+
function resolveSportsPropsParams(params = {}) {
|
|
1346
|
+
return params;
|
|
1347
|
+
}
|
|
1348
|
+
async function fetchSportsTaxonomy(client, params) {
|
|
1349
|
+
return client.getSportsTaxonomy(resolveSportsTaxonomyParams(params));
|
|
1350
|
+
}
|
|
1351
|
+
async function fetchSportsMatches(client, params) {
|
|
1352
|
+
return client.getSportsMatches(resolveSportsMatchesParams(params));
|
|
1353
|
+
}
|
|
1354
|
+
async function fetchSportsProps(client, params) {
|
|
1355
|
+
return client.getSportsProps(resolveSportsPropsParams(params));
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
// src/hooks/predict/useSportsTaxonomy.ts
|
|
1359
|
+
function useSportsTaxonomy(params = {}, queryOptions = {}) {
|
|
1360
|
+
const client = usePredictClient();
|
|
1361
|
+
const resolved = resolveSportsTaxonomyParams(params);
|
|
1362
|
+
return reactQuery.useQuery({
|
|
1363
|
+
queryKey: sportsTaxonomyQueryKey(resolved),
|
|
1364
|
+
queryFn: () => fetchSportsTaxonomy(client, resolved),
|
|
1365
|
+
...queryOptions
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
function useSportsMatches(params = {}, queryOptions) {
|
|
1369
|
+
const client = usePredictClient();
|
|
1370
|
+
const resolved = resolveSportsMatchesParams(params);
|
|
1371
|
+
return reactQuery.useInfiniteQuery({
|
|
1372
|
+
queryKey: sportsMatchesQueryKey(resolved),
|
|
1373
|
+
queryFn: ({ pageParam }) => fetchSportsMatches(client, {
|
|
1374
|
+
...resolved,
|
|
1375
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1376
|
+
}),
|
|
1377
|
+
initialPageParam: void 0,
|
|
1378
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1379
|
+
enabled: queryOptions?.enabled ?? true
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
function useSportsProps(params = {}, queryOptions) {
|
|
1383
|
+
const client = usePredictClient();
|
|
1384
|
+
const resolved = resolveSportsPropsParams(params);
|
|
1385
|
+
return reactQuery.useInfiniteQuery({
|
|
1386
|
+
queryKey: sportsPropsQueryKey(resolved),
|
|
1387
|
+
queryFn: ({ pageParam }) => fetchSportsProps(client, {
|
|
1388
|
+
...resolved,
|
|
1389
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1390
|
+
}),
|
|
1391
|
+
initialPageParam: void 0,
|
|
1392
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1393
|
+
enabled: queryOptions?.enabled ?? true
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// src/hooks/predict/esports.params.ts
|
|
1398
|
+
function esportsTaxonomyQueryKey(params) {
|
|
1399
|
+
return ["predict", "esports", "taxonomy", params];
|
|
1400
|
+
}
|
|
1401
|
+
function esportsMatchesQueryKey(params) {
|
|
1402
|
+
return ["predict", "esports", "matches", params];
|
|
1403
|
+
}
|
|
1404
|
+
function esportsPropsQueryKey(params) {
|
|
1405
|
+
return ["predict", "esports", "props", params];
|
|
1406
|
+
}
|
|
1407
|
+
function resolveEsportsTaxonomyParams(params = {}) {
|
|
1408
|
+
return params;
|
|
1409
|
+
}
|
|
1410
|
+
function resolveEsportsMatchesParams(params = {}) {
|
|
1411
|
+
return params;
|
|
1412
|
+
}
|
|
1413
|
+
function resolveEsportsPropsParams(params = {}) {
|
|
1414
|
+
return params;
|
|
1415
|
+
}
|
|
1416
|
+
async function fetchEsportsTaxonomy(client, params) {
|
|
1417
|
+
return client.getEsportsTaxonomy(resolveEsportsTaxonomyParams(params));
|
|
1418
|
+
}
|
|
1419
|
+
async function fetchEsportsMatches(client, params) {
|
|
1420
|
+
return client.getEsportsMatches(resolveEsportsMatchesParams(params));
|
|
1421
|
+
}
|
|
1422
|
+
async function fetchEsportsProps(client, params) {
|
|
1423
|
+
return client.getEsportsProps(resolveEsportsPropsParams(params));
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
// src/hooks/predict/useEsportsTaxonomy.ts
|
|
1427
|
+
function useEsportsTaxonomy(params = {}, queryOptions = {}) {
|
|
1428
|
+
const client = usePredictClient();
|
|
1429
|
+
const resolved = resolveEsportsTaxonomyParams(params);
|
|
1430
|
+
return reactQuery.useQuery({
|
|
1431
|
+
queryKey: esportsTaxonomyQueryKey(resolved),
|
|
1432
|
+
queryFn: () => fetchEsportsTaxonomy(client, resolved),
|
|
1433
|
+
...queryOptions
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
function useEsportsMatches(params = {}, queryOptions) {
|
|
1437
|
+
const client = usePredictClient();
|
|
1438
|
+
const resolved = resolveEsportsMatchesParams(params);
|
|
1439
|
+
return reactQuery.useInfiniteQuery({
|
|
1440
|
+
queryKey: esportsMatchesQueryKey(resolved),
|
|
1441
|
+
queryFn: ({ pageParam }) => fetchEsportsMatches(client, {
|
|
1442
|
+
...resolved,
|
|
1443
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1444
|
+
}),
|
|
1445
|
+
initialPageParam: void 0,
|
|
1446
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1447
|
+
enabled: queryOptions?.enabled ?? true
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
function useEsportsProps(params = {}, queryOptions) {
|
|
1451
|
+
const client = usePredictClient();
|
|
1452
|
+
const resolved = resolveEsportsPropsParams(params);
|
|
1453
|
+
return reactQuery.useInfiniteQuery({
|
|
1454
|
+
queryKey: esportsPropsQueryKey(resolved),
|
|
1455
|
+
queryFn: ({ pageParam }) => fetchEsportsProps(client, {
|
|
1456
|
+
...resolved,
|
|
1457
|
+
...pageParam !== void 0 ? { cursor: pageParam } : {}
|
|
1458
|
+
}),
|
|
1459
|
+
initialPageParam: void 0,
|
|
1460
|
+
getNextPageParam: (lastPage) => lastPage.has_more && lastPage.next_cursor ? lastPage.next_cursor : void 0,
|
|
1461
|
+
enabled: queryOptions?.enabled ?? true
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/hooks/predict/sports-routing.params.ts
|
|
1466
|
+
function sportsRoutingQueryKey(slug, params) {
|
|
1467
|
+
return ["predict", "sports", "routing", slug, params];
|
|
1468
|
+
}
|
|
1469
|
+
function resolveSportsRoutingParams(params = {}) {
|
|
1470
|
+
return params;
|
|
1471
|
+
}
|
|
1472
|
+
async function fetchSportsRouting(client, slug, params) {
|
|
1473
|
+
return client.getSportsRouting(slug, resolveSportsRoutingParams(params));
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// src/hooks/predict/useSportsRouting.ts
|
|
1477
|
+
function useSportsRouting(slug, params = {}, queryOptions = {}) {
|
|
1478
|
+
const client = usePredictClient();
|
|
1479
|
+
const resolved = resolveSportsRoutingParams(params);
|
|
1480
|
+
return reactQuery.useQuery({
|
|
1481
|
+
queryKey: sportsRoutingQueryKey(slug, resolved),
|
|
1482
|
+
queryFn: () => fetchSportsRouting(client, slug, resolved),
|
|
1483
|
+
enabled: Boolean(slug),
|
|
1484
|
+
...queryOptions
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
// src/hooks/predict/sports-match-detail.params.ts
|
|
1489
|
+
function sportsMatchDetailQueryKey(section, matchGroupSlug, params) {
|
|
1490
|
+
return ["predict", section, "match-detail", matchGroupSlug, params];
|
|
1491
|
+
}
|
|
1492
|
+
function resolveSportsMatchDetailParams(params = {}) {
|
|
1493
|
+
return params;
|
|
1494
|
+
}
|
|
1495
|
+
async function fetchSportsMatchDetail(client, section, matchGroupSlug, params) {
|
|
1496
|
+
return client.getSportsMatchDetail(
|
|
1497
|
+
section,
|
|
1498
|
+
matchGroupSlug,
|
|
1499
|
+
resolveSportsMatchDetailParams(params)
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
// src/hooks/predict/useSportsMatchDetail.ts
|
|
1504
|
+
function useSportsMatchDetail(section, matchGroupSlug, params = {}, queryOptions = {}) {
|
|
1505
|
+
const client = usePredictClient();
|
|
1506
|
+
const resolved = resolveSportsMatchDetailParams(params);
|
|
1507
|
+
return reactQuery.useQuery({
|
|
1508
|
+
queryKey: sportsMatchDetailQueryKey(section, matchGroupSlug, resolved),
|
|
1509
|
+
queryFn: () => fetchSportsMatchDetail(client, section, matchGroupSlug, resolved),
|
|
1510
|
+
enabled: Boolean(section && matchGroupSlug),
|
|
1511
|
+
...queryOptions
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
function orderbookQueryKey(slug, source, outcome = "yes") {
|
|
1515
|
+
return ["predict", "orderbook", slug, source, outcome];
|
|
1516
|
+
}
|
|
1517
|
+
function useOrderbook(params, queryOptions = {}) {
|
|
1518
|
+
const client = usePredictClient();
|
|
1519
|
+
const outcome = params.outcome ?? "yes";
|
|
1520
|
+
return reactQuery.useQuery({
|
|
1521
|
+
queryKey: orderbookQueryKey(params.slug, params.source, outcome),
|
|
1522
|
+
queryFn: () => client.getOrderbook(params.slug, params.source, outcome),
|
|
1523
|
+
enabled: Boolean(params.slug),
|
|
1524
|
+
refetchInterval: 3e4,
|
|
1525
|
+
...queryOptions
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
function useOrderbookSubscription({
|
|
1529
|
+
wsClient,
|
|
1530
|
+
slug,
|
|
1531
|
+
enabled = true,
|
|
1532
|
+
outcome,
|
|
1533
|
+
onUpdate
|
|
1534
|
+
}) {
|
|
1535
|
+
const [orderbook, setOrderbook] = react.useState(null);
|
|
1536
|
+
const [isSubscribed, setIsSubscribed] = react.useState(false);
|
|
1537
|
+
const onUpdateRef = react.useRef(onUpdate);
|
|
1538
|
+
onUpdateRef.current = onUpdate;
|
|
1539
|
+
const handleUpdate = react.useCallback(
|
|
1540
|
+
(msg) => {
|
|
1541
|
+
if (msg.data.market_slug === slug) {
|
|
1542
|
+
if (!outcome || msg.data.outcome === outcome) {
|
|
1543
|
+
setOrderbook(msg.data);
|
|
1544
|
+
}
|
|
1545
|
+
onUpdateRef.current?.(msg);
|
|
1546
|
+
}
|
|
1547
|
+
},
|
|
1548
|
+
[slug, outcome]
|
|
1549
|
+
);
|
|
1550
|
+
react.useEffect(() => {
|
|
1551
|
+
if (!wsClient || !enabled || !slug) {
|
|
1552
|
+
setIsSubscribed(false);
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
setOrderbook(null);
|
|
1556
|
+
const unsub = wsClient.subscribeOrderbook([slug], handleUpdate);
|
|
1557
|
+
setIsSubscribed(true);
|
|
1558
|
+
return () => {
|
|
1559
|
+
unsub();
|
|
1560
|
+
setIsSubscribed(false);
|
|
1561
|
+
};
|
|
1562
|
+
}, [wsClient, enabled, slug, handleUpdate]);
|
|
1563
|
+
return { orderbook, isSubscribed };
|
|
1564
|
+
}
|
|
1565
|
+
function usePredictWsClient() {
|
|
1566
|
+
const context = react.useContext(PredictContext);
|
|
1567
|
+
if (!context) {
|
|
1568
|
+
throw new Error("usePredictWsClient must be used within a PredictProvider");
|
|
1569
|
+
}
|
|
1570
|
+
const { wsClient } = context;
|
|
1571
|
+
const [wsStatus, setWsStatus] = react.useState(
|
|
1572
|
+
wsClient?.getStatus() ?? "disconnected"
|
|
1573
|
+
);
|
|
1574
|
+
react.useEffect(() => {
|
|
1575
|
+
if (!wsClient) {
|
|
1576
|
+
setWsStatus("disconnected");
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
setWsStatus(wsClient.getStatus());
|
|
1580
|
+
return wsClient.onStatusChange(setWsStatus);
|
|
1581
|
+
}, [wsClient]);
|
|
1582
|
+
return {
|
|
1583
|
+
wsClient,
|
|
1584
|
+
wsStatus,
|
|
1585
|
+
isWsConnected: wsStatus === "connected"
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// src/hooks/predict/useRealtimeOrderbook.ts
|
|
1590
|
+
var REST_POLL_INTERVAL = 5e3;
|
|
1591
|
+
function useRealtimeOrderbook(params, queryOptions = {}) {
|
|
1592
|
+
const { wsClient } = usePredictWsClient();
|
|
1593
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1594
|
+
const outcome = params.outcome ?? "yes";
|
|
1595
|
+
const handleUpdate = react.useCallback(
|
|
1596
|
+
(msg) => {
|
|
1597
|
+
if (msg.data.market_slug !== params.slug) return;
|
|
1598
|
+
if (msg.data.outcome !== "yes" && msg.data.outcome !== "no") return;
|
|
1599
|
+
const ob = {
|
|
1600
|
+
market_id: msg.data.market_slug,
|
|
1601
|
+
outcome: msg.data.outcome,
|
|
1602
|
+
bids: msg.data.bids,
|
|
1603
|
+
asks: msg.data.asks,
|
|
1604
|
+
spread: msg.data.spread
|
|
1605
|
+
};
|
|
1606
|
+
queryClient.setQueryData(
|
|
1607
|
+
orderbookQueryKey(params.slug, params.source, msg.data.outcome),
|
|
1608
|
+
ob
|
|
1609
|
+
);
|
|
1610
|
+
},
|
|
1611
|
+
[params.slug, params.source, queryClient]
|
|
1612
|
+
);
|
|
1613
|
+
const subParams = {
|
|
1614
|
+
wsClient,
|
|
1615
|
+
slug: params.slug,
|
|
1616
|
+
enabled: Boolean(params.slug),
|
|
1617
|
+
outcome,
|
|
1618
|
+
onUpdate: handleUpdate
|
|
1619
|
+
};
|
|
1620
|
+
const { isSubscribed } = useOrderbookSubscription(subParams);
|
|
1621
|
+
return useOrderbook(params, {
|
|
1622
|
+
refetchInterval: isSubscribed ? false : REST_POLL_INTERVAL,
|
|
1623
|
+
...queryOptions
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
// src/hooks/predict/useSportsOrderbook.ts
|
|
1628
|
+
function useSportsOrderbook(key) {
|
|
1629
|
+
return useRealtimeOrderbook({
|
|
1630
|
+
slug: key.market_slug,
|
|
1631
|
+
source: key.source,
|
|
1632
|
+
outcome: key.outcome
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1225
1635
|
function useInfiniteEvents(params, queryOptions = {}) {
|
|
1226
1636
|
const client = usePredictClient();
|
|
1227
1637
|
return reactQuery.useInfiniteQuery({
|
|
@@ -1477,20 +1887,6 @@ function useMarketHistory(markets, range = ChartRange.ALL, options = {}) {
|
|
|
1477
1887
|
}, [marketParams, queries]);
|
|
1478
1888
|
return { series, isLoading };
|
|
1479
1889
|
}
|
|
1480
|
-
function orderbookQueryKey(slug, source, outcome = "yes") {
|
|
1481
|
-
return ["predict", "orderbook", slug, source, outcome];
|
|
1482
|
-
}
|
|
1483
|
-
function useOrderbook(params, queryOptions = {}) {
|
|
1484
|
-
const client = usePredictClient();
|
|
1485
|
-
const outcome = params.outcome ?? "yes";
|
|
1486
|
-
return reactQuery.useQuery({
|
|
1487
|
-
queryKey: orderbookQueryKey(params.slug, params.source, outcome),
|
|
1488
|
-
queryFn: () => client.getOrderbook(params.slug, params.source, outcome),
|
|
1489
|
-
enabled: Boolean(params.slug),
|
|
1490
|
-
refetchInterval: 3e4,
|
|
1491
|
-
...queryOptions
|
|
1492
|
-
});
|
|
1493
|
-
}
|
|
1494
1890
|
function marketTradesQueryKey(slug, params) {
|
|
1495
1891
|
return ["predict", "market-trades", slug, params];
|
|
1496
1892
|
}
|
|
@@ -2684,29 +3080,6 @@ function useRebateConfig(queryOptions = {}) {
|
|
|
2684
3080
|
...queryOptions
|
|
2685
3081
|
});
|
|
2686
3082
|
}
|
|
2687
|
-
function usePredictWsClient() {
|
|
2688
|
-
const context = react.useContext(PredictContext);
|
|
2689
|
-
if (!context) {
|
|
2690
|
-
throw new Error("usePredictWsClient must be used within a PredictProvider");
|
|
2691
|
-
}
|
|
2692
|
-
const { wsClient } = context;
|
|
2693
|
-
const [wsStatus, setWsStatus] = react.useState(
|
|
2694
|
-
wsClient?.getStatus() ?? "disconnected"
|
|
2695
|
-
);
|
|
2696
|
-
react.useEffect(() => {
|
|
2697
|
-
if (!wsClient) {
|
|
2698
|
-
setWsStatus("disconnected");
|
|
2699
|
-
return;
|
|
2700
|
-
}
|
|
2701
|
-
setWsStatus(wsClient.getStatus());
|
|
2702
|
-
return wsClient.onStatusChange(setWsStatus);
|
|
2703
|
-
}, [wsClient]);
|
|
2704
|
-
return {
|
|
2705
|
-
wsClient,
|
|
2706
|
-
wsStatus,
|
|
2707
|
-
isWsConnected: wsStatus === "connected"
|
|
2708
|
-
};
|
|
2709
|
-
}
|
|
2710
3083
|
function usePricesSubscription({
|
|
2711
3084
|
wsClient,
|
|
2712
3085
|
slugs,
|
|
@@ -2742,43 +3115,6 @@ function usePricesSubscription({
|
|
|
2742
3115
|
}, [wsClient, enabled, slugsKey, handleUpdate]);
|
|
2743
3116
|
return { prices, isSubscribed };
|
|
2744
3117
|
}
|
|
2745
|
-
function useOrderbookSubscription({
|
|
2746
|
-
wsClient,
|
|
2747
|
-
slug,
|
|
2748
|
-
enabled = true,
|
|
2749
|
-
outcome,
|
|
2750
|
-
onUpdate
|
|
2751
|
-
}) {
|
|
2752
|
-
const [orderbook, setOrderbook] = react.useState(null);
|
|
2753
|
-
const [isSubscribed, setIsSubscribed] = react.useState(false);
|
|
2754
|
-
const onUpdateRef = react.useRef(onUpdate);
|
|
2755
|
-
onUpdateRef.current = onUpdate;
|
|
2756
|
-
const handleUpdate = react.useCallback(
|
|
2757
|
-
(msg) => {
|
|
2758
|
-
if (msg.data.market_slug === slug) {
|
|
2759
|
-
if (!outcome || msg.data.outcome === outcome) {
|
|
2760
|
-
setOrderbook(msg.data);
|
|
2761
|
-
}
|
|
2762
|
-
onUpdateRef.current?.(msg);
|
|
2763
|
-
}
|
|
2764
|
-
},
|
|
2765
|
-
[slug, outcome]
|
|
2766
|
-
);
|
|
2767
|
-
react.useEffect(() => {
|
|
2768
|
-
if (!wsClient || !enabled || !slug) {
|
|
2769
|
-
setIsSubscribed(false);
|
|
2770
|
-
return;
|
|
2771
|
-
}
|
|
2772
|
-
setOrderbook(null);
|
|
2773
|
-
const unsub = wsClient.subscribeOrderbook([slug], handleUpdate);
|
|
2774
|
-
setIsSubscribed(true);
|
|
2775
|
-
return () => {
|
|
2776
|
-
unsub();
|
|
2777
|
-
setIsSubscribed(false);
|
|
2778
|
-
};
|
|
2779
|
-
}, [wsClient, enabled, slug, handleUpdate]);
|
|
2780
|
-
return { orderbook, isSubscribed };
|
|
2781
|
-
}
|
|
2782
3118
|
var DEFAULT_MAX_HISTORY = 100;
|
|
2783
3119
|
function useTradesSubscription({
|
|
2784
3120
|
wsClient,
|
|
@@ -2823,42 +3159,6 @@ function useTradesSubscription({
|
|
|
2823
3159
|
}, [wsClient, enabled, slug, handleUpdate]);
|
|
2824
3160
|
return { trades, isSubscribed, clearHistory };
|
|
2825
3161
|
}
|
|
2826
|
-
var REST_POLL_INTERVAL = 5e3;
|
|
2827
|
-
function useRealtimeOrderbook(params, queryOptions = {}) {
|
|
2828
|
-
const { wsClient } = usePredictWsClient();
|
|
2829
|
-
const queryClient = reactQuery.useQueryClient();
|
|
2830
|
-
const outcome = params.outcome ?? "yes";
|
|
2831
|
-
const handleUpdate = react.useCallback(
|
|
2832
|
-
(msg) => {
|
|
2833
|
-
if (msg.data.market_slug !== params.slug) return;
|
|
2834
|
-
if (msg.data.outcome !== "yes" && msg.data.outcome !== "no") return;
|
|
2835
|
-
const ob = {
|
|
2836
|
-
market_id: msg.data.market_slug,
|
|
2837
|
-
outcome: msg.data.outcome,
|
|
2838
|
-
bids: msg.data.bids,
|
|
2839
|
-
asks: msg.data.asks,
|
|
2840
|
-
spread: msg.data.spread
|
|
2841
|
-
};
|
|
2842
|
-
queryClient.setQueryData(
|
|
2843
|
-
orderbookQueryKey(params.slug, params.source, msg.data.outcome),
|
|
2844
|
-
ob
|
|
2845
|
-
);
|
|
2846
|
-
},
|
|
2847
|
-
[params.slug, params.source, queryClient]
|
|
2848
|
-
);
|
|
2849
|
-
const subParams = {
|
|
2850
|
-
wsClient,
|
|
2851
|
-
slug: params.slug,
|
|
2852
|
-
enabled: Boolean(params.slug),
|
|
2853
|
-
outcome,
|
|
2854
|
-
onUpdate: handleUpdate
|
|
2855
|
-
};
|
|
2856
|
-
const { isSubscribed } = useOrderbookSubscription(subParams);
|
|
2857
|
-
return useOrderbook(params, {
|
|
2858
|
-
refetchInterval: isSubscribed ? false : REST_POLL_INTERVAL,
|
|
2859
|
-
...queryOptions
|
|
2860
|
-
});
|
|
2861
|
-
}
|
|
2862
3162
|
|
|
2863
3163
|
// src/hooks/predict/useRealtimePrices.ts
|
|
2864
3164
|
function useRealtimePrices({
|
|
@@ -3407,16 +3707,28 @@ exports.createPredictWsClient = createPredictWsClient;
|
|
|
3407
3707
|
exports.derivePolymarketApiKey = derivePolymarketApiKey;
|
|
3408
3708
|
exports.dflowKYCQueryKey = dflowKYCQueryKey;
|
|
3409
3709
|
exports.dflowQuoteQueryKey = dflowQuoteQueryKey;
|
|
3710
|
+
exports.esportsMatchesQueryKey = esportsMatchesQueryKey;
|
|
3711
|
+
exports.esportsPropsQueryKey = esportsPropsQueryKey;
|
|
3712
|
+
exports.esportsTaxonomyQueryKey = esportsTaxonomyQueryKey;
|
|
3410
3713
|
exports.eventQueryKey = eventQueryKey;
|
|
3411
3714
|
exports.eventStatsQueryKey = eventStatsQueryKey;
|
|
3412
3715
|
exports.eventsQueryKey = eventsQueryKey;
|
|
3413
3716
|
exports.feeRateQueryKey = feeRateQueryKey;
|
|
3717
|
+
exports.fetchEsportsMatches = fetchEsportsMatches;
|
|
3718
|
+
exports.fetchEsportsProps = fetchEsportsProps;
|
|
3719
|
+
exports.fetchEsportsTaxonomy = fetchEsportsTaxonomy;
|
|
3414
3720
|
exports.fetchEvent = fetchEvent;
|
|
3415
3721
|
exports.fetchEvents = fetchEvents;
|
|
3416
3722
|
exports.fetchEventsPage = fetchEventsPage;
|
|
3417
3723
|
exports.fetchMarket = fetchMarket;
|
|
3418
3724
|
exports.fetchMatchMarketsPage = fetchMatchMarketsPage;
|
|
3419
3725
|
exports.fetchMatchesPage = fetchMatchesPage;
|
|
3726
|
+
exports.fetchPredictSearch = fetchPredictSearch;
|
|
3727
|
+
exports.fetchSportsMatchDetail = fetchSportsMatchDetail;
|
|
3728
|
+
exports.fetchSportsMatches = fetchSportsMatches;
|
|
3729
|
+
exports.fetchSportsProps = fetchSportsProps;
|
|
3730
|
+
exports.fetchSportsRouting = fetchSportsRouting;
|
|
3731
|
+
exports.fetchSportsTaxonomy = fetchSportsTaxonomy;
|
|
3420
3732
|
exports.getPolymarketSharesPrecision = getPolymarketSharesPrecision;
|
|
3421
3733
|
exports.hmacSha256Base64 = hmacSha256Base64;
|
|
3422
3734
|
exports.infiniteCommentsQueryKey = infiniteCommentsQueryKey;
|
|
@@ -3444,11 +3756,17 @@ exports.positionValueMultiQueryKey = positionValueMultiQueryKey;
|
|
|
3444
3756
|
exports.positionValueQueryKey = positionValueQueryKey;
|
|
3445
3757
|
exports.positionsMultiQueryKey = positionsMultiQueryKey;
|
|
3446
3758
|
exports.positionsQueryKey = positionsQueryKey;
|
|
3759
|
+
exports.predictSearchQueryKey = predictSearchQueryKey;
|
|
3447
3760
|
exports.priceHistoryQueryKey = priceHistoryQueryKey;
|
|
3448
3761
|
exports.rebateConfigQueryKey = rebateConfigQueryKey;
|
|
3449
3762
|
exports.resolveEventsParams = resolveEventsParams;
|
|
3450
3763
|
exports.resolveTagSlug = resolveTagSlug;
|
|
3451
3764
|
exports.similarEventsQueryKey = similarEventsQueryKey;
|
|
3765
|
+
exports.sportsMatchDetailQueryKey = sportsMatchDetailQueryKey;
|
|
3766
|
+
exports.sportsMatchesQueryKey = sportsMatchesQueryKey;
|
|
3767
|
+
exports.sportsPropsQueryKey = sportsPropsQueryKey;
|
|
3768
|
+
exports.sportsRoutingQueryKey = sportsRoutingQueryKey;
|
|
3769
|
+
exports.sportsTaxonomyQueryKey = sportsTaxonomyQueryKey;
|
|
3452
3770
|
exports.tickSizeQueryKey = tickSizeQueryKey;
|
|
3453
3771
|
exports.tradesQueryKey = tradesQueryKey;
|
|
3454
3772
|
exports.updatePolymarketBalanceAllowance = updatePolymarketBalanceAllowance;
|
|
@@ -3461,6 +3779,9 @@ exports.useDFlowKYC = useDFlowKYC;
|
|
|
3461
3779
|
exports.useDFlowQuote = useDFlowQuote;
|
|
3462
3780
|
exports.useDFlowSubmit = useDFlowSubmit;
|
|
3463
3781
|
exports.useDeployPolymarketDepositWallet = useDeployPolymarketDepositWallet;
|
|
3782
|
+
exports.useEsportsMatches = useEsportsMatches;
|
|
3783
|
+
exports.useEsportsProps = useEsportsProps;
|
|
3784
|
+
exports.useEsportsTaxonomy = useEsportsTaxonomy;
|
|
3464
3785
|
exports.useEvent = useEvent;
|
|
3465
3786
|
exports.useEventStats = useEventStats;
|
|
3466
3787
|
exports.useEvents = useEvents;
|
|
@@ -3470,6 +3791,7 @@ exports.useInfiniteEvents = useInfiniteEvents;
|
|
|
3470
3791
|
exports.useInfiniteMatchMarkets = useInfiniteMatchMarkets;
|
|
3471
3792
|
exports.useInfiniteMatches = useInfiniteMatches;
|
|
3472
3793
|
exports.useInfiniteOrders = useInfiniteOrders;
|
|
3794
|
+
exports.useInfinitePredictSearch = useInfinitePredictSearch;
|
|
3473
3795
|
exports.useInfiniteTrades = useInfiniteTrades;
|
|
3474
3796
|
exports.useInfiniteTradesMulti = useInfiniteTradesMulti;
|
|
3475
3797
|
exports.useMarket = useMarket;
|
|
@@ -3497,6 +3819,7 @@ exports.usePositionValueMulti = usePositionValueMulti;
|
|
|
3497
3819
|
exports.usePositions = usePositions;
|
|
3498
3820
|
exports.usePositionsMulti = usePositionsMulti;
|
|
3499
3821
|
exports.usePredictClient = usePredictClient;
|
|
3822
|
+
exports.usePredictSearch = usePredictSearch;
|
|
3500
3823
|
exports.usePredictWsClient = usePredictWsClient;
|
|
3501
3824
|
exports.usePriceHistory = usePriceHistory;
|
|
3502
3825
|
exports.usePricesSubscription = usePricesSubscription;
|
|
@@ -3508,6 +3831,12 @@ exports.useRedeemPosition = useRedeemPosition;
|
|
|
3508
3831
|
exports.useRunPolymarketSetup = useRunPolymarketSetup;
|
|
3509
3832
|
exports.useSearchEvents = useSearchEvents;
|
|
3510
3833
|
exports.useSimilarEvents = useSimilarEvents;
|
|
3834
|
+
exports.useSportsMatchDetail = useSportsMatchDetail;
|
|
3835
|
+
exports.useSportsMatches = useSportsMatches;
|
|
3836
|
+
exports.useSportsOrderbook = useSportsOrderbook;
|
|
3837
|
+
exports.useSportsProps = useSportsProps;
|
|
3838
|
+
exports.useSportsRouting = useSportsRouting;
|
|
3839
|
+
exports.useSportsTaxonomy = useSportsTaxonomy;
|
|
3511
3840
|
exports.useTickSize = useTickSize;
|
|
3512
3841
|
exports.useTradeResultConfirmation = useTradeResultConfirmation;
|
|
3513
3842
|
exports.useTrades = useTrades;
|