@liberfi.io/react-predict 0.2.7 → 0.2.8
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 +68 -1
- package/dist/index.d.ts +68 -1
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -2285,6 +2285,109 @@ async function pollTxConfirmed(fetchStatus, txHash) {
|
|
|
2285
2285
|
);
|
|
2286
2286
|
}
|
|
2287
2287
|
|
|
2288
|
-
|
|
2288
|
+
// src/utils/orderbook-pricing.ts
|
|
2289
|
+
function getWalkLevels(orderbook, outcome, side) {
|
|
2290
|
+
if (!orderbook) return [];
|
|
2291
|
+
const isNo = outcome === "no";
|
|
2292
|
+
const useAsks = side === "buy" && !isNo || side === "sell" && isNo;
|
|
2293
|
+
const raw = useAsks ? orderbook.asks : orderbook.bids;
|
|
2294
|
+
if (!raw || raw.length === 0) return [];
|
|
2295
|
+
const mapped = raw.map((lvl) => ({
|
|
2296
|
+
price: isNo ? 1 - lvl.price : lvl.price,
|
|
2297
|
+
size: lvl.size
|
|
2298
|
+
}));
|
|
2299
|
+
if (side === "buy") {
|
|
2300
|
+
return [...mapped].sort((a, b) => a.price - b.price);
|
|
2301
|
+
}
|
|
2302
|
+
return [...mapped].sort((a, b) => b.price - a.price);
|
|
2303
|
+
}
|
|
2304
|
+
function pickBestAsk(orderbook, outcome) {
|
|
2305
|
+
const levels = getWalkLevels(orderbook, outcome, "buy");
|
|
2306
|
+
return levels[0]?.price ?? null;
|
|
2307
|
+
}
|
|
2308
|
+
function pickBestBid(orderbook, outcome) {
|
|
2309
|
+
const levels = getWalkLevels(orderbook, outcome, "sell");
|
|
2310
|
+
return levels[0]?.price ?? null;
|
|
2311
|
+
}
|
|
2312
|
+
function walkOrderbook({
|
|
2313
|
+
orderbook,
|
|
2314
|
+
outcome,
|
|
2315
|
+
side,
|
|
2316
|
+
sharesNeeded,
|
|
2317
|
+
slippageBps
|
|
2318
|
+
}) {
|
|
2319
|
+
const levels = getWalkLevels(orderbook, outcome, side);
|
|
2320
|
+
const totalAvailable = levels.reduce((sum, lvl) => sum + lvl.size, 0);
|
|
2321
|
+
if (levels.length === 0) {
|
|
2322
|
+
return {
|
|
2323
|
+
status: "no_orderbook",
|
|
2324
|
+
bestPrice: null,
|
|
2325
|
+
worstPrice: null,
|
|
2326
|
+
vwap: null,
|
|
2327
|
+
totalAvailable: 0,
|
|
2328
|
+
filled: 0,
|
|
2329
|
+
priceImpactBps: 0
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
const bestPrice = levels[0].price;
|
|
2333
|
+
if (!Number.isFinite(sharesNeeded) || sharesNeeded <= 0) {
|
|
2334
|
+
return {
|
|
2335
|
+
status: "ok",
|
|
2336
|
+
bestPrice,
|
|
2337
|
+
worstPrice: bestPrice,
|
|
2338
|
+
vwap: bestPrice,
|
|
2339
|
+
totalAvailable,
|
|
2340
|
+
filled: 0,
|
|
2341
|
+
priceImpactBps: 0
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2344
|
+
let remaining = sharesNeeded;
|
|
2345
|
+
let filled = 0;
|
|
2346
|
+
let notional = 0;
|
|
2347
|
+
let worstPrice = bestPrice;
|
|
2348
|
+
for (const lvl of levels) {
|
|
2349
|
+
if (remaining <= 0) break;
|
|
2350
|
+
const take = Math.min(remaining, lvl.size);
|
|
2351
|
+
notional += take * lvl.price;
|
|
2352
|
+
filled += take;
|
|
2353
|
+
worstPrice = lvl.price;
|
|
2354
|
+
remaining -= take;
|
|
2355
|
+
}
|
|
2356
|
+
const vwap = filled > 0 ? notional / filled : bestPrice;
|
|
2357
|
+
const priceImpactBps = bestPrice > 0 ? Math.round(Math.abs(worstPrice - bestPrice) / bestPrice * 1e4) : 0;
|
|
2358
|
+
if (remaining > 0) {
|
|
2359
|
+
return {
|
|
2360
|
+
status: "insufficient_liquidity",
|
|
2361
|
+
bestPrice,
|
|
2362
|
+
worstPrice,
|
|
2363
|
+
vwap,
|
|
2364
|
+
totalAvailable,
|
|
2365
|
+
filled,
|
|
2366
|
+
priceImpactBps
|
|
2367
|
+
};
|
|
2368
|
+
}
|
|
2369
|
+
if (slippageBps != null && slippageBps > 0 && priceImpactBps > slippageBps) {
|
|
2370
|
+
return {
|
|
2371
|
+
status: "exceeds_slippage",
|
|
2372
|
+
bestPrice,
|
|
2373
|
+
worstPrice,
|
|
2374
|
+
vwap,
|
|
2375
|
+
totalAvailable,
|
|
2376
|
+
filled,
|
|
2377
|
+
priceImpactBps
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
return {
|
|
2381
|
+
status: "ok",
|
|
2382
|
+
bestPrice,
|
|
2383
|
+
worstPrice,
|
|
2384
|
+
vwap,
|
|
2385
|
+
totalAvailable,
|
|
2386
|
+
filled,
|
|
2387
|
+
priceImpactBps
|
|
2388
|
+
};
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
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, feeRateQueryKey, fetchEvent, fetchEvents, fetchEventsPage, fetchMarket, fetchMatchMarketsPage, fetchMatchesPage, getPolymarketSharesPrecision, hmacSha256Base64, infiniteEventsQueryKey, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketQueryKey, marketTradesQueryKey, matchMarketsQueryKey, matchQueryKey, matchesQueryKey, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, resolveEventsParams, resolveTagSlug, similarEventsQueryKey, tickSizeQueryKey, tradesQueryKey, useAvailableShares, useBalance, useCancelOrder, useCandlesticks, useCreatePolymarketOrder, useDFlowKYC, useDFlowQuote, useDFlowSubmit, useEvent, useEventStats, useEvents, useFeeRate, useInfiniteEvents, useInfiniteMatchMarkets, useInfiniteMatches, useInfiniteOrders, useInfiniteTrades, useInfiniteTradesMulti, useMarket, useMarketHistory, useMarketTrades, useMatch, useOrder, useOrderbook, useOrderbookSubscription, useOrders, useOrdersMulti, usePolymarket, usePolymarketDeposit, usePolymarketDepositAddresses, usePolymarketSetup, usePolymarketWithdraw, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRedeemPosition, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, walkOrderbook, withdrawStatusQueryKey };
|
|
2289
2392
|
//# sourceMappingURL=index.mjs.map
|
|
2290
2393
|
//# sourceMappingURL=index.mjs.map
|