@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 CHANGED
@@ -905,4 +905,71 @@ interface CreatePolymarketOrderVariables {
905
905
  */
906
906
  declare function useCreatePolymarketOrder(mutationOptions?: Omit<UseMutationOptions<PredictOrder, Error, CreatePolymarketOrderVariables>, "mutationFn">): _tanstack_react_query.UseMutationResult<PredictOrder, Error, CreatePolymarketOrderVariables, unknown>;
907
907
 
908
- export { AvailableSharesResponse, BalanceResponse, CancelOrderResult, type CancelOrderVariables, Candlestick, ChartRange, type ChartRangeType, CreateOrderInput, type CreatePolymarketOrderVariables, DFlowKYCStatus, DFlowQuoteRequest, DFlowQuoteResponse, DFlowSubmitRequest, DFlowSubmitResponse, EventSortField, EventStats, EventStatus, FeeRateResponse, ListCandlesticksParams, ListEventsParams, ListMarketTradesParams, ListOrdersMultiParams, ListOrdersParams, ListTradesMultiParams, ListTradesParams, type MarketHistoryPoint, type MarketHistorySeries, MatchGroup, MatchGroupPage, MatchMarketPage, MatchMarketParams, MatchesParams, Orderbook, PolymarketContext, type PolymarketContextValue, type PolymarketCredentials, PolymarketDepositAddresses, type PolymarketDepositResult, type PolymarketDepositVariables, PolymarketProvider, type PolymarketProviderProps, PolymarketRedeemResponse, type PolymarketSigner, PolymarketWithdrawRequest, PolymarketWithdrawResponse, PositionsResponse, PredictClient, PredictContext, type PredictContextValue, PredictEvent, PredictMarket, PredictOrder, PredictOrdersResponse, PredictPage, PredictProvider, type PredictProviderProps, PredictTrade, PredictWsClient, PriceHistoryRange, PriceHistoryResponse, ProviderSource, type RedeemPositionVariables, SimilarEventsParams, TickSizeResponse, type UseAvailableSharesOptions, type UseAvailableSharesParams, type UseBalanceParams, type UseCancelOrderOptions, type UseCandlesticksParams, type UseEventParams, type UseInfiniteMatchMarketsParams, type UseInfiniteMatchesParams, type UseInfiniteOrdersOptions, type UseInfiniteOrdersParams, type UseInfiniteTradesMultiParams, type UseInfiniteTradesParams, type UseMarketHistoryResult, type UseMarketParams, type UseMarketTradesParams, type UseOrderParams, type UseOrderbookParams, type UseOrderbookSubscriptionParams, type UseOrderbookSubscriptionResult, type UseOrdersMultiOptions, type UseOrdersOptions, type UsePositionsMultiParams, type UsePositionsParams, type UsePredictWsClientResult, type UsePriceHistoryParams, type UsePricesSubscriptionParams, type UsePricesSubscriptionResult, type UseRealtimeOrderbookParams, type UseRealtimePricesParams, type UseRealtimeTradesParams, type UseRealtimeTradesResult, type UseSearchEventsParams, type UseSimilarEventsParams, type UseTradesSubscriptionParams, type UseTradesSubscriptionResult, type UseWithdrawStatusQueryParams, WithdrawBuildRequest, WithdrawBuildResponse, WithdrawStatusResponse, WithdrawSubmitRequest, WithdrawSubmitResponse, WsConnectionStatus, WsDataMessage, WsOrderbookEvent, WsPriceEvent, WsTradeEvent, availableSharesQueryKey, balanceQueryKey, candlesticksQueryKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventStatsQueryKey, eventsQueryKey, feeRateQueryKey, fetchEvents, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketTradesQueryKey, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, 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, withdrawStatusQueryKey };
908
+ /**
909
+ * Orderbook-aware pricing utilities for prediction-market orders.
910
+ *
911
+ * Polymarket's binary markets store the orderbook for the YES side only.
912
+ * NO levels are derived by inversion: a NO ask at price p maps to a YES
913
+ * bid at (1 - p) and vice versa. The helpers below normalize that flip so
914
+ * callers can reason about a single outcome at a time.
915
+ *
916
+ * Market-style orders (FOK on Polymarket) require a price that actually
917
+ * crosses every level we intend to fill into; a price quoted at top-of-book
918
+ * is only valid when the requested size fits within the first level.
919
+ * `walkOrderbook` walks the depth chart for the chosen outcome and side,
920
+ * accumulating size until the requested shares are covered, returning the
921
+ * worst price hit (the price the FOK order must use) and a slippage
922
+ * verdict relative to the top-of-book.
923
+ */
924
+
925
+ type WalkSide = "buy" | "sell";
926
+ type WalkOutcome = "yes" | "no";
927
+ type WalkStatus = "ok" | "insufficient_liquidity" | "exceeds_slippage" | "no_orderbook";
928
+ interface WalkResult {
929
+ status: WalkStatus;
930
+ /** Top-of-book price after outcome inversion (best ask for buy, best bid for sell). */
931
+ bestPrice: number | null;
932
+ /** Worst price walked into; equals `bestPrice` when one level fully covers the request. */
933
+ worstPrice: number | null;
934
+ /** Volume-weighted average price across all levels actually consumed. */
935
+ vwap: number | null;
936
+ /** Total share size available on the relevant side, after outcome inversion. */
937
+ totalAvailable: number;
938
+ /** Share size that was actually filled while walking (≤ totalAvailable). */
939
+ filled: number;
940
+ /** Absolute price impact between worst and best, expressed in basis points. */
941
+ priceImpactBps: number;
942
+ }
943
+ /**
944
+ * Best ask for the chosen outcome (price you pay to buy a share).
945
+ * Returns `null` when the orderbook is empty on the relevant side.
946
+ */
947
+ declare function pickBestAsk(orderbook: Orderbook | null | undefined, outcome: WalkOutcome): number | null;
948
+ /**
949
+ * Best bid for the chosen outcome (price you receive when selling a share).
950
+ * Returns `null` when the orderbook is empty on the relevant side.
951
+ */
952
+ declare function pickBestBid(orderbook: Orderbook | null | undefined, outcome: WalkOutcome): number | null;
953
+ interface WalkOrderbookParams {
954
+ orderbook: Orderbook | null | undefined;
955
+ outcome: WalkOutcome;
956
+ side: WalkSide;
957
+ /** How many shares the caller wants to fill. */
958
+ sharesNeeded: number;
959
+ /**
960
+ * Maximum tolerated slippage between the best-of-book price and the
961
+ * worst price hit while walking, expressed in basis points (100 = 1%).
962
+ * When `0` or omitted, no slippage check is performed.
963
+ */
964
+ slippageBps?: number;
965
+ }
966
+ /**
967
+ * Walk the orderbook depth on the chosen side until `sharesNeeded` is
968
+ * covered. Returns the worst price hit (which becomes the limit price for
969
+ * a Polymarket FOK order so every consumed level matches), the volume-
970
+ * weighted average, and a status describing whether the walk succeeded,
971
+ * ran out of liquidity, or breached the slippage tolerance.
972
+ */
973
+ declare function walkOrderbook({ orderbook, outcome, side, sharesNeeded, slippageBps, }: WalkOrderbookParams): WalkResult;
974
+
975
+ export { AvailableSharesResponse, BalanceResponse, CancelOrderResult, type CancelOrderVariables, Candlestick, ChartRange, type ChartRangeType, CreateOrderInput, type CreatePolymarketOrderVariables, DFlowKYCStatus, DFlowQuoteRequest, DFlowQuoteResponse, DFlowSubmitRequest, DFlowSubmitResponse, EventSortField, EventStats, EventStatus, FeeRateResponse, ListCandlesticksParams, ListEventsParams, ListMarketTradesParams, ListOrdersMultiParams, ListOrdersParams, ListTradesMultiParams, ListTradesParams, type MarketHistoryPoint, type MarketHistorySeries, MatchGroup, MatchGroupPage, MatchMarketPage, MatchMarketParams, MatchesParams, Orderbook, PolymarketContext, type PolymarketContextValue, type PolymarketCredentials, PolymarketDepositAddresses, type PolymarketDepositResult, type PolymarketDepositVariables, PolymarketProvider, type PolymarketProviderProps, PolymarketRedeemResponse, type PolymarketSigner, PolymarketWithdrawRequest, PolymarketWithdrawResponse, PositionsResponse, PredictClient, PredictContext, type PredictContextValue, PredictEvent, PredictMarket, PredictOrder, PredictOrdersResponse, PredictPage, PredictProvider, type PredictProviderProps, PredictTrade, PredictWsClient, PriceHistoryRange, PriceHistoryResponse, ProviderSource, type RedeemPositionVariables, SimilarEventsParams, TickSizeResponse, type UseAvailableSharesOptions, type UseAvailableSharesParams, type UseBalanceParams, type UseCancelOrderOptions, type UseCandlesticksParams, type UseEventParams, type UseInfiniteMatchMarketsParams, type UseInfiniteMatchesParams, type UseInfiniteOrdersOptions, type UseInfiniteOrdersParams, type UseInfiniteTradesMultiParams, type UseInfiniteTradesParams, type UseMarketHistoryResult, type UseMarketParams, type UseMarketTradesParams, type UseOrderParams, type UseOrderbookParams, type UseOrderbookSubscriptionParams, type UseOrderbookSubscriptionResult, type UseOrdersMultiOptions, type UseOrdersOptions, type UsePositionsMultiParams, type UsePositionsParams, type UsePredictWsClientResult, type UsePriceHistoryParams, type UsePricesSubscriptionParams, type UsePricesSubscriptionResult, type UseRealtimeOrderbookParams, type UseRealtimePricesParams, type UseRealtimeTradesParams, type UseRealtimeTradesResult, type UseSearchEventsParams, type UseSimilarEventsParams, type UseTradesSubscriptionParams, type UseTradesSubscriptionResult, type UseWithdrawStatusQueryParams, type WalkOrderbookParams, type WalkOutcome, type WalkResult, type WalkSide, type WalkStatus, WithdrawBuildRequest, WithdrawBuildResponse, WithdrawStatusResponse, WithdrawSubmitRequest, WithdrawSubmitResponse, WsConnectionStatus, WsDataMessage, WsOrderbookEvent, WsPriceEvent, WsTradeEvent, availableSharesQueryKey, balanceQueryKey, candlesticksQueryKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventStatsQueryKey, eventsQueryKey, feeRateQueryKey, fetchEvents, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketTradesQueryKey, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, 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 };
package/dist/index.d.ts CHANGED
@@ -905,4 +905,71 @@ interface CreatePolymarketOrderVariables {
905
905
  */
906
906
  declare function useCreatePolymarketOrder(mutationOptions?: Omit<UseMutationOptions<PredictOrder, Error, CreatePolymarketOrderVariables>, "mutationFn">): _tanstack_react_query.UseMutationResult<PredictOrder, Error, CreatePolymarketOrderVariables, unknown>;
907
907
 
908
- export { AvailableSharesResponse, BalanceResponse, CancelOrderResult, type CancelOrderVariables, Candlestick, ChartRange, type ChartRangeType, CreateOrderInput, type CreatePolymarketOrderVariables, DFlowKYCStatus, DFlowQuoteRequest, DFlowQuoteResponse, DFlowSubmitRequest, DFlowSubmitResponse, EventSortField, EventStats, EventStatus, FeeRateResponse, ListCandlesticksParams, ListEventsParams, ListMarketTradesParams, ListOrdersMultiParams, ListOrdersParams, ListTradesMultiParams, ListTradesParams, type MarketHistoryPoint, type MarketHistorySeries, MatchGroup, MatchGroupPage, MatchMarketPage, MatchMarketParams, MatchesParams, Orderbook, PolymarketContext, type PolymarketContextValue, type PolymarketCredentials, PolymarketDepositAddresses, type PolymarketDepositResult, type PolymarketDepositVariables, PolymarketProvider, type PolymarketProviderProps, PolymarketRedeemResponse, type PolymarketSigner, PolymarketWithdrawRequest, PolymarketWithdrawResponse, PositionsResponse, PredictClient, PredictContext, type PredictContextValue, PredictEvent, PredictMarket, PredictOrder, PredictOrdersResponse, PredictPage, PredictProvider, type PredictProviderProps, PredictTrade, PredictWsClient, PriceHistoryRange, PriceHistoryResponse, ProviderSource, type RedeemPositionVariables, SimilarEventsParams, TickSizeResponse, type UseAvailableSharesOptions, type UseAvailableSharesParams, type UseBalanceParams, type UseCancelOrderOptions, type UseCandlesticksParams, type UseEventParams, type UseInfiniteMatchMarketsParams, type UseInfiniteMatchesParams, type UseInfiniteOrdersOptions, type UseInfiniteOrdersParams, type UseInfiniteTradesMultiParams, type UseInfiniteTradesParams, type UseMarketHistoryResult, type UseMarketParams, type UseMarketTradesParams, type UseOrderParams, type UseOrderbookParams, type UseOrderbookSubscriptionParams, type UseOrderbookSubscriptionResult, type UseOrdersMultiOptions, type UseOrdersOptions, type UsePositionsMultiParams, type UsePositionsParams, type UsePredictWsClientResult, type UsePriceHistoryParams, type UsePricesSubscriptionParams, type UsePricesSubscriptionResult, type UseRealtimeOrderbookParams, type UseRealtimePricesParams, type UseRealtimeTradesParams, type UseRealtimeTradesResult, type UseSearchEventsParams, type UseSimilarEventsParams, type UseTradesSubscriptionParams, type UseTradesSubscriptionResult, type UseWithdrawStatusQueryParams, WithdrawBuildRequest, WithdrawBuildResponse, WithdrawStatusResponse, WithdrawSubmitRequest, WithdrawSubmitResponse, WsConnectionStatus, WsDataMessage, WsOrderbookEvent, WsPriceEvent, WsTradeEvent, availableSharesQueryKey, balanceQueryKey, candlesticksQueryKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventStatsQueryKey, eventsQueryKey, feeRateQueryKey, fetchEvents, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketTradesQueryKey, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, 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, withdrawStatusQueryKey };
908
+ /**
909
+ * Orderbook-aware pricing utilities for prediction-market orders.
910
+ *
911
+ * Polymarket's binary markets store the orderbook for the YES side only.
912
+ * NO levels are derived by inversion: a NO ask at price p maps to a YES
913
+ * bid at (1 - p) and vice versa. The helpers below normalize that flip so
914
+ * callers can reason about a single outcome at a time.
915
+ *
916
+ * Market-style orders (FOK on Polymarket) require a price that actually
917
+ * crosses every level we intend to fill into; a price quoted at top-of-book
918
+ * is only valid when the requested size fits within the first level.
919
+ * `walkOrderbook` walks the depth chart for the chosen outcome and side,
920
+ * accumulating size until the requested shares are covered, returning the
921
+ * worst price hit (the price the FOK order must use) and a slippage
922
+ * verdict relative to the top-of-book.
923
+ */
924
+
925
+ type WalkSide = "buy" | "sell";
926
+ type WalkOutcome = "yes" | "no";
927
+ type WalkStatus = "ok" | "insufficient_liquidity" | "exceeds_slippage" | "no_orderbook";
928
+ interface WalkResult {
929
+ status: WalkStatus;
930
+ /** Top-of-book price after outcome inversion (best ask for buy, best bid for sell). */
931
+ bestPrice: number | null;
932
+ /** Worst price walked into; equals `bestPrice` when one level fully covers the request. */
933
+ worstPrice: number | null;
934
+ /** Volume-weighted average price across all levels actually consumed. */
935
+ vwap: number | null;
936
+ /** Total share size available on the relevant side, after outcome inversion. */
937
+ totalAvailable: number;
938
+ /** Share size that was actually filled while walking (≤ totalAvailable). */
939
+ filled: number;
940
+ /** Absolute price impact between worst and best, expressed in basis points. */
941
+ priceImpactBps: number;
942
+ }
943
+ /**
944
+ * Best ask for the chosen outcome (price you pay to buy a share).
945
+ * Returns `null` when the orderbook is empty on the relevant side.
946
+ */
947
+ declare function pickBestAsk(orderbook: Orderbook | null | undefined, outcome: WalkOutcome): number | null;
948
+ /**
949
+ * Best bid for the chosen outcome (price you receive when selling a share).
950
+ * Returns `null` when the orderbook is empty on the relevant side.
951
+ */
952
+ declare function pickBestBid(orderbook: Orderbook | null | undefined, outcome: WalkOutcome): number | null;
953
+ interface WalkOrderbookParams {
954
+ orderbook: Orderbook | null | undefined;
955
+ outcome: WalkOutcome;
956
+ side: WalkSide;
957
+ /** How many shares the caller wants to fill. */
958
+ sharesNeeded: number;
959
+ /**
960
+ * Maximum tolerated slippage between the best-of-book price and the
961
+ * worst price hit while walking, expressed in basis points (100 = 1%).
962
+ * When `0` or omitted, no slippage check is performed.
963
+ */
964
+ slippageBps?: number;
965
+ }
966
+ /**
967
+ * Walk the orderbook depth on the chosen side until `sharesNeeded` is
968
+ * covered. Returns the worst price hit (which becomes the limit price for
969
+ * a Polymarket FOK order so every consumed level matches), the volume-
970
+ * weighted average, and a status describing whether the walk succeeded,
971
+ * ran out of liquidity, or breached the slippage tolerance.
972
+ */
973
+ declare function walkOrderbook({ orderbook, outcome, side, sharesNeeded, slippageBps, }: WalkOrderbookParams): WalkResult;
974
+
975
+ export { AvailableSharesResponse, BalanceResponse, CancelOrderResult, type CancelOrderVariables, Candlestick, ChartRange, type ChartRangeType, CreateOrderInput, type CreatePolymarketOrderVariables, DFlowKYCStatus, DFlowQuoteRequest, DFlowQuoteResponse, DFlowSubmitRequest, DFlowSubmitResponse, EventSortField, EventStats, EventStatus, FeeRateResponse, ListCandlesticksParams, ListEventsParams, ListMarketTradesParams, ListOrdersMultiParams, ListOrdersParams, ListTradesMultiParams, ListTradesParams, type MarketHistoryPoint, type MarketHistorySeries, MatchGroup, MatchGroupPage, MatchMarketPage, MatchMarketParams, MatchesParams, Orderbook, PolymarketContext, type PolymarketContextValue, type PolymarketCredentials, PolymarketDepositAddresses, type PolymarketDepositResult, type PolymarketDepositVariables, PolymarketProvider, type PolymarketProviderProps, PolymarketRedeemResponse, type PolymarketSigner, PolymarketWithdrawRequest, PolymarketWithdrawResponse, PositionsResponse, PredictClient, PredictContext, type PredictContextValue, PredictEvent, PredictMarket, PredictOrder, PredictOrdersResponse, PredictPage, PredictProvider, type PredictProviderProps, PredictTrade, PredictWsClient, PriceHistoryRange, PriceHistoryResponse, ProviderSource, type RedeemPositionVariables, SimilarEventsParams, TickSizeResponse, type UseAvailableSharesOptions, type UseAvailableSharesParams, type UseBalanceParams, type UseCancelOrderOptions, type UseCandlesticksParams, type UseEventParams, type UseInfiniteMatchMarketsParams, type UseInfiniteMatchesParams, type UseInfiniteOrdersOptions, type UseInfiniteOrdersParams, type UseInfiniteTradesMultiParams, type UseInfiniteTradesParams, type UseMarketHistoryResult, type UseMarketParams, type UseMarketTradesParams, type UseOrderParams, type UseOrderbookParams, type UseOrderbookSubscriptionParams, type UseOrderbookSubscriptionResult, type UseOrdersMultiOptions, type UseOrdersOptions, type UsePositionsMultiParams, type UsePositionsParams, type UsePredictWsClientResult, type UsePriceHistoryParams, type UsePricesSubscriptionParams, type UsePricesSubscriptionResult, type UseRealtimeOrderbookParams, type UseRealtimePricesParams, type UseRealtimeTradesParams, type UseRealtimeTradesResult, type UseSearchEventsParams, type UseSimilarEventsParams, type UseTradesSubscriptionParams, type UseTradesSubscriptionResult, type UseWithdrawStatusQueryParams, type WalkOrderbookParams, type WalkOutcome, type WalkResult, type WalkSide, type WalkStatus, WithdrawBuildRequest, WithdrawBuildResponse, WithdrawStatusResponse, WithdrawSubmitRequest, WithdrawSubmitResponse, WsConnectionStatus, WsDataMessage, WsOrderbookEvent, WsPriceEvent, WsTradeEvent, availableSharesQueryKey, balanceQueryKey, candlesticksQueryKey, dflowKYCQueryKey, dflowQuoteQueryKey, eventStatsQueryKey, eventsQueryKey, feeRateQueryKey, fetchEvents, infiniteOrdersQueryKey, infiniteTradesMultiQueryKey, infiniteTradesQueryKey, marketTradesQueryKey, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, positionsMultiQueryKey, positionsQueryKey, priceHistoryQueryKey, 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 };
package/dist/index.js CHANGED
@@ -2287,6 +2287,109 @@ async function pollTxConfirmed(fetchStatus, txHash) {
2287
2287
  );
2288
2288
  }
2289
2289
 
2290
+ // src/utils/orderbook-pricing.ts
2291
+ function getWalkLevels(orderbook, outcome, side) {
2292
+ if (!orderbook) return [];
2293
+ const isNo = outcome === "no";
2294
+ const useAsks = side === "buy" && !isNo || side === "sell" && isNo;
2295
+ const raw = useAsks ? orderbook.asks : orderbook.bids;
2296
+ if (!raw || raw.length === 0) return [];
2297
+ const mapped = raw.map((lvl) => ({
2298
+ price: isNo ? 1 - lvl.price : lvl.price,
2299
+ size: lvl.size
2300
+ }));
2301
+ if (side === "buy") {
2302
+ return [...mapped].sort((a, b) => a.price - b.price);
2303
+ }
2304
+ return [...mapped].sort((a, b) => b.price - a.price);
2305
+ }
2306
+ function pickBestAsk(orderbook, outcome) {
2307
+ const levels = getWalkLevels(orderbook, outcome, "buy");
2308
+ return levels[0]?.price ?? null;
2309
+ }
2310
+ function pickBestBid(orderbook, outcome) {
2311
+ const levels = getWalkLevels(orderbook, outcome, "sell");
2312
+ return levels[0]?.price ?? null;
2313
+ }
2314
+ function walkOrderbook({
2315
+ orderbook,
2316
+ outcome,
2317
+ side,
2318
+ sharesNeeded,
2319
+ slippageBps
2320
+ }) {
2321
+ const levels = getWalkLevels(orderbook, outcome, side);
2322
+ const totalAvailable = levels.reduce((sum, lvl) => sum + lvl.size, 0);
2323
+ if (levels.length === 0) {
2324
+ return {
2325
+ status: "no_orderbook",
2326
+ bestPrice: null,
2327
+ worstPrice: null,
2328
+ vwap: null,
2329
+ totalAvailable: 0,
2330
+ filled: 0,
2331
+ priceImpactBps: 0
2332
+ };
2333
+ }
2334
+ const bestPrice = levels[0].price;
2335
+ if (!Number.isFinite(sharesNeeded) || sharesNeeded <= 0) {
2336
+ return {
2337
+ status: "ok",
2338
+ bestPrice,
2339
+ worstPrice: bestPrice,
2340
+ vwap: bestPrice,
2341
+ totalAvailable,
2342
+ filled: 0,
2343
+ priceImpactBps: 0
2344
+ };
2345
+ }
2346
+ let remaining = sharesNeeded;
2347
+ let filled = 0;
2348
+ let notional = 0;
2349
+ let worstPrice = bestPrice;
2350
+ for (const lvl of levels) {
2351
+ if (remaining <= 0) break;
2352
+ const take = Math.min(remaining, lvl.size);
2353
+ notional += take * lvl.price;
2354
+ filled += take;
2355
+ worstPrice = lvl.price;
2356
+ remaining -= take;
2357
+ }
2358
+ const vwap = filled > 0 ? notional / filled : bestPrice;
2359
+ const priceImpactBps = bestPrice > 0 ? Math.round(Math.abs(worstPrice - bestPrice) / bestPrice * 1e4) : 0;
2360
+ if (remaining > 0) {
2361
+ return {
2362
+ status: "insufficient_liquidity",
2363
+ bestPrice,
2364
+ worstPrice,
2365
+ vwap,
2366
+ totalAvailable,
2367
+ filled,
2368
+ priceImpactBps
2369
+ };
2370
+ }
2371
+ if (slippageBps != null && slippageBps > 0 && priceImpactBps > slippageBps) {
2372
+ return {
2373
+ status: "exceeds_slippage",
2374
+ bestPrice,
2375
+ worstPrice,
2376
+ vwap,
2377
+ totalAvailable,
2378
+ filled,
2379
+ priceImpactBps
2380
+ };
2381
+ }
2382
+ return {
2383
+ status: "ok",
2384
+ bestPrice,
2385
+ worstPrice,
2386
+ vwap,
2387
+ totalAvailable,
2388
+ filled,
2389
+ priceImpactBps
2390
+ };
2391
+ }
2392
+
2290
2393
  exports.CLOB_AUTH_DOMAIN = CLOB_AUTH_DOMAIN;
2291
2394
  exports.CLOB_AUTH_TYPES = CLOB_AUTH_TYPES;
2292
2395
  exports.CTF_EXCHANGE_ADDRESS = CTF_EXCHANGE_ADDRESS;
@@ -2342,6 +2445,8 @@ exports.orderQueryKey = orderQueryKey;
2342
2445
  exports.orderbookQueryKey = orderbookQueryKey;
2343
2446
  exports.ordersMultiQueryKey = ordersMultiQueryKey;
2344
2447
  exports.ordersQueryKey = ordersQueryKey;
2448
+ exports.pickBestAsk = pickBestAsk;
2449
+ exports.pickBestBid = pickBestBid;
2345
2450
  exports.polymarketDepositAddressesQueryKey = polymarketDepositAddressesQueryKey;
2346
2451
  exports.polymarketSetupQueryKey = polymarketSetupQueryKey;
2347
2452
  exports.positionsMultiQueryKey = positionsMultiQueryKey;
@@ -2403,6 +2508,7 @@ exports.useTradesSubscription = useTradesSubscription;
2403
2508
  exports.useWithdrawBuildMutation = useWithdrawBuildMutation;
2404
2509
  exports.useWithdrawStatusQuery = useWithdrawStatusQuery;
2405
2510
  exports.useWithdrawSubmitMutation = useWithdrawSubmitMutation;
2511
+ exports.walkOrderbook = walkOrderbook;
2406
2512
  exports.withdrawStatusQueryKey = withdrawStatusQueryKey;
2407
2513
  //# sourceMappingURL=index.js.map
2408
2514
  //# sourceMappingURL=index.js.map