@liberfi.io/react-predict 0.1.49 → 0.1.51
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 +48 -4
- package/dist/index.d.ts +48 -4
- package/dist/index.js +118 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -19
- package/dist/index.mjs.map +1 -1
- package/dist/{server-rYuNULuJ.d.mts → server-eKqIns8z.d.mts} +49 -2
- package/dist/{server-rYuNULuJ.d.ts → server-eKqIns8z.d.ts} +49 -2
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +46 -14
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +46 -14
- package/dist/server.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -132,6 +132,28 @@ var PredictClient = class {
|
|
|
132
132
|
return await httpGet(url);
|
|
133
133
|
}
|
|
134
134
|
// -------------------------------------------------------------------------
|
|
135
|
+
// Available shares (for sell flow)
|
|
136
|
+
// -------------------------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Get the number of shares available for selling, accounting for active orders.
|
|
139
|
+
*
|
|
140
|
+
* Maps to `GET /api/v1/available-shares?source=...&user=...&market=...&side=...`.
|
|
141
|
+
*
|
|
142
|
+
* @param source - Provider source.
|
|
143
|
+
* @param user - Wallet address.
|
|
144
|
+
* @param market - Market slug.
|
|
145
|
+
* @param side - Position side ("yes" or "no").
|
|
146
|
+
* @param headers - Optional extra headers (e.g. Polymarket POLY_* HMAC headers).
|
|
147
|
+
*/
|
|
148
|
+
async getAvailableShares(source, user, market, side, headers) {
|
|
149
|
+
const query = buildQuery({ source, user, market, side });
|
|
150
|
+
const url = `${this.endpoint}/api/v1/available-shares${query}`;
|
|
151
|
+
return await httpGet(
|
|
152
|
+
url,
|
|
153
|
+
headers ? { headers } : void 0
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
// -------------------------------------------------------------------------
|
|
135
157
|
// Balance
|
|
136
158
|
// -------------------------------------------------------------------------
|
|
137
159
|
/**
|
|
@@ -164,6 +186,22 @@ var PredictClient = class {
|
|
|
164
186
|
headers ? { headers } : void 0
|
|
165
187
|
);
|
|
166
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Multi-wallet order listing with enriched market/event context.
|
|
191
|
+
*
|
|
192
|
+
* Maps to `GET /api/v1/orders?kalshi_user=...&polymarket_user=...`.
|
|
193
|
+
*
|
|
194
|
+
* @param params - Per-provider wallet addresses.
|
|
195
|
+
* @param headers - Optional extra headers (e.g. Polymarket POLY_* HMAC headers).
|
|
196
|
+
*/
|
|
197
|
+
async listOrdersMulti(params, headers) {
|
|
198
|
+
const query = buildQuery(params);
|
|
199
|
+
const url = `${this.endpoint}/api/v1/orders${query}`;
|
|
200
|
+
return await httpGet(
|
|
201
|
+
url,
|
|
202
|
+
headers ? { headers } : void 0
|
|
203
|
+
);
|
|
204
|
+
}
|
|
167
205
|
/**
|
|
168
206
|
* Maps to `GET /api/v1/orders/:id?source=...`.
|
|
169
207
|
*
|
|
@@ -1223,6 +1261,7 @@ function usePositions(params, queryOptions = {}) {
|
|
|
1223
1261
|
queryFn: () => client.getPositions(params.user, params.source),
|
|
1224
1262
|
enabled: Boolean(params.user),
|
|
1225
1263
|
staleTime: 1e4,
|
|
1264
|
+
refetchInterval: 3e4,
|
|
1226
1265
|
...queryOptions
|
|
1227
1266
|
});
|
|
1228
1267
|
}
|
|
@@ -1234,6 +1273,37 @@ function usePositionsMulti(params, queryOptions = {}) {
|
|
|
1234
1273
|
queryFn: () => client.getPositions(params),
|
|
1235
1274
|
enabled: hasAnyWallet,
|
|
1236
1275
|
staleTime: 1e4,
|
|
1276
|
+
refetchInterval: 3e4,
|
|
1277
|
+
...queryOptions
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
function availableSharesQueryKey(params) {
|
|
1281
|
+
return [
|
|
1282
|
+
"predict",
|
|
1283
|
+
"available-shares",
|
|
1284
|
+
params.source,
|
|
1285
|
+
params.user,
|
|
1286
|
+
params.market,
|
|
1287
|
+
params.side
|
|
1288
|
+
];
|
|
1289
|
+
}
|
|
1290
|
+
function useAvailableShares(params, options, queryOptions = {}) {
|
|
1291
|
+
const client = usePredictClient();
|
|
1292
|
+
return useQuery({
|
|
1293
|
+
queryKey: availableSharesQueryKey(params),
|
|
1294
|
+
queryFn: async () => {
|
|
1295
|
+
const headers = await options?.getHeaders?.();
|
|
1296
|
+
return client.getAvailableShares(
|
|
1297
|
+
params.source,
|
|
1298
|
+
params.user,
|
|
1299
|
+
params.market,
|
|
1300
|
+
params.side,
|
|
1301
|
+
headers
|
|
1302
|
+
);
|
|
1303
|
+
},
|
|
1304
|
+
enabled: Boolean(params.user && params.market && params.side),
|
|
1305
|
+
staleTime: 5e3,
|
|
1306
|
+
refetchInterval: 1e4,
|
|
1237
1307
|
...queryOptions
|
|
1238
1308
|
});
|
|
1239
1309
|
}
|
|
@@ -1281,6 +1351,30 @@ function useInfiniteOrders(params, options) {
|
|
|
1281
1351
|
enabled: Boolean(params.wallet_address)
|
|
1282
1352
|
});
|
|
1283
1353
|
}
|
|
1354
|
+
function ordersMultiQueryKey(params) {
|
|
1355
|
+
return [
|
|
1356
|
+
"predict",
|
|
1357
|
+
"orders",
|
|
1358
|
+
"multi",
|
|
1359
|
+
params.kalshi_user ?? "",
|
|
1360
|
+
params.polymarket_user ?? ""
|
|
1361
|
+
];
|
|
1362
|
+
}
|
|
1363
|
+
function useOrdersMulti(params, options, queryOptions = {}) {
|
|
1364
|
+
const client = usePredictClient();
|
|
1365
|
+
const hasAnyWallet = Boolean(params.kalshi_user || params.polymarket_user);
|
|
1366
|
+
return useQuery({
|
|
1367
|
+
queryKey: [...ordersMultiQueryKey(params), ...options?.keyExtra ?? []],
|
|
1368
|
+
queryFn: async () => {
|
|
1369
|
+
const headers = await options?.getHeaders?.();
|
|
1370
|
+
return client.listOrdersMulti(params, headers);
|
|
1371
|
+
},
|
|
1372
|
+
enabled: hasAnyWallet,
|
|
1373
|
+
staleTime: 1e4,
|
|
1374
|
+
refetchInterval: 3e4,
|
|
1375
|
+
...queryOptions
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1284
1378
|
function orderQueryKey(id, source) {
|
|
1285
1379
|
return ["predict", "order", id, source];
|
|
1286
1380
|
}
|
|
@@ -1294,15 +1388,23 @@ function useOrder(params, queryOptions = {}) {
|
|
|
1294
1388
|
...queryOptions
|
|
1295
1389
|
});
|
|
1296
1390
|
}
|
|
1297
|
-
function useCancelOrder(mutationOptions = {}) {
|
|
1391
|
+
function useCancelOrder(options, mutationOptions = {}) {
|
|
1298
1392
|
const client = usePredictClient();
|
|
1299
1393
|
const queryClient = useQueryClient();
|
|
1394
|
+
const { onSuccess, onError, ...restMutationOptions } = mutationOptions;
|
|
1300
1395
|
return useMutation({
|
|
1301
|
-
mutationFn: (vars) =>
|
|
1302
|
-
|
|
1396
|
+
mutationFn: async (vars) => {
|
|
1397
|
+
const headers = await options?.getHeaders?.(vars);
|
|
1398
|
+
return client.cancelOrder(vars.id, vars.source, headers);
|
|
1399
|
+
},
|
|
1400
|
+
onSuccess: (...args) => {
|
|
1303
1401
|
queryClient.invalidateQueries({ queryKey: ["predict", "orders"] });
|
|
1402
|
+
onSuccess?.(...args);
|
|
1304
1403
|
},
|
|
1305
|
-
...
|
|
1404
|
+
onError: (...args) => {
|
|
1405
|
+
onError?.(...args);
|
|
1406
|
+
},
|
|
1407
|
+
...restMutationOptions
|
|
1306
1408
|
});
|
|
1307
1409
|
}
|
|
1308
1410
|
|
|
@@ -1881,17 +1983,13 @@ var DEFAULT_ROUNDING = { size: 2, price: 2, amount: 4 };
|
|
|
1881
1983
|
function decimalPlaces(n, d) {
|
|
1882
1984
|
return parseFloat(n.toFixed(d));
|
|
1883
1985
|
}
|
|
1986
|
+
function floorDecimalPlaces(n, d) {
|
|
1987
|
+
const factor = 10 ** d;
|
|
1988
|
+
return Math.floor(n * factor) / factor;
|
|
1989
|
+
}
|
|
1884
1990
|
function toMicroUsdc(amount) {
|
|
1885
1991
|
return BigInt(Math.round(amount * 1e6));
|
|
1886
1992
|
}
|
|
1887
|
-
function ceilMicro(raw, maxDecimals) {
|
|
1888
|
-
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1889
|
-
return (raw + factor - 1n) / factor * factor;
|
|
1890
|
-
}
|
|
1891
|
-
function floorMicro(raw, maxDecimals) {
|
|
1892
|
-
const factor = BigInt(10 ** (6 - maxDecimals));
|
|
1893
|
-
return raw / factor * factor;
|
|
1894
|
-
}
|
|
1895
1993
|
function normalizeTokenId(tokenId) {
|
|
1896
1994
|
if (tokenId.startsWith("0x") || tokenId.startsWith("0X")) {
|
|
1897
1995
|
return BigInt(tokenId).toString(10);
|
|
@@ -1902,14 +2000,12 @@ function buildOrderMessage(input) {
|
|
|
1902
2000
|
const side = input.side === "BUY" ? SIDE.BUY : SIDE.SELL;
|
|
1903
2001
|
const rc = ROUNDING_CONFIG[input.tickSize] ?? DEFAULT_ROUNDING;
|
|
1904
2002
|
const rawPrice = decimalPlaces(input.price, rc.price);
|
|
1905
|
-
const rawSize = decimalPlaces(input.size, rc.size);
|
|
1906
|
-
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
2003
|
+
const rawSize = side === SIDE.SELL ? floorDecimalPlaces(input.size, rc.size) : decimalPlaces(input.size, rc.size);
|
|
1907
2004
|
const sizeInMicro = toMicroUsdc(rawSize);
|
|
2005
|
+
const rawAmount = decimalPlaces(rawSize * rawPrice, rc.amount);
|
|
1908
2006
|
const amountInMicro = toMicroUsdc(rawAmount);
|
|
1909
|
-
const
|
|
1910
|
-
const
|
|
1911
|
-
const makerAmount = side === SIDE.BUY ? usdcMicro.toString() : sharesMicro.toString();
|
|
1912
|
-
const takerAmount = side === SIDE.BUY ? sharesMicro.toString() : usdcMicro.toString();
|
|
2007
|
+
const makerAmount = side === SIDE.BUY ? amountInMicro.toString() : sizeInMicro.toString();
|
|
2008
|
+
const takerAmount = side === SIDE.BUY ? sizeInMicro.toString() : amountInMicro.toString();
|
|
1913
2009
|
const maker = input.funderAddress ?? input.signerAddress;
|
|
1914
2010
|
return {
|
|
1915
2011
|
salt: Math.floor(Math.random() * 1e15).toString(),
|
|
@@ -2040,6 +2136,6 @@ async function pollTxConfirmed(fetchStatus, txHash) {
|
|
|
2040
2136
|
);
|
|
2041
2137
|
}
|
|
2042
2138
|
|
|
2043
|
-
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, balanceQueryKey, buildClobAuthMessage, buildClobPayload, buildCtfExchangeDomain, buildOrderMessage, buildPolymarketL2Headers, buildSignedOrder, candlesticksQueryKey, createPredictClient, createPredictWsClient, derivePolymarketApiKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventQueryKey, eventStatsQueryKey, eventsQueryKey, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, hmacSha256Base64, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, orderQueryKey, orderbookQueryKey, ordersQueryKey, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, tickSizeQueryKey, tradesQueryKey, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useEvent, useEventStats, useEvents, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfiniteTrades, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketWithdraw, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, withdrawStatusQueryKey };
|
|
2139
|
+
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, candlesticksQueryKey, createPredictClient, createPredictWsClient, derivePolymarketApiKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventQueryKey, eventStatsQueryKey, eventsQueryKey, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, hmacSha256Base64, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, tickSizeQueryKey, tradesQueryKey, useAvailableShares, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useEvent, useEventStats, useEvents, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfiniteTrades, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, useOrdersMulti, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketWithdraw, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, withdrawStatusQueryKey };
|
|
2044
2140
|
//# sourceMappingURL=index.mjs.map
|
|
2045
2141
|
//# sourceMappingURL=index.mjs.map
|