@liberfi.io/react-predict 0.3.61 → 0.3.62

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.mjs CHANGED
@@ -174,6 +174,23 @@ var PredictClient = class {
174
174
  const url = `${this.endpoint}/api/v1/positions${query}`;
175
175
  return await httpGet(url);
176
176
  }
177
+ /**
178
+ * Maps to `GET /api/v1/positions/value`.
179
+ *
180
+ * Single-source: `getPositionValue("addr", "polymarket")`.
181
+ * Multi-wallet: `getPositionValue({ kalshi_user: "SOLaddr", polymarket_user: "EVMaddr" })`.
182
+ * Legacy agg: `getPositionValue("addr")` (same address for all providers).
183
+ */
184
+ async getPositionValue(userOrWallets, source) {
185
+ let query;
186
+ if (typeof userOrWallets === "string") {
187
+ query = buildQuery({ source, user: userOrWallets });
188
+ } else {
189
+ query = buildQuery(userOrWallets);
190
+ }
191
+ const url = `${this.endpoint}/api/v1/positions/value${query}`;
192
+ return await httpGet(url);
193
+ }
177
194
  // -------------------------------------------------------------------------
178
195
  // Available shares (for sell flow)
179
196
  // -------------------------------------------------------------------------
@@ -1466,6 +1483,41 @@ function usePositionsMulti(params, queryOptions = {}) {
1466
1483
  ...queryOptions
1467
1484
  });
1468
1485
  }
1486
+ function positionValueQueryKey(user, source) {
1487
+ return ["predict", "position-value", source ?? "all", user];
1488
+ }
1489
+ function positionValueMultiQueryKey(wallets) {
1490
+ return [
1491
+ "predict",
1492
+ "position-value",
1493
+ "multi",
1494
+ wallets.kalshi_user ?? "",
1495
+ wallets.polymarket_user ?? ""
1496
+ ];
1497
+ }
1498
+ function usePositionValue(params, queryOptions = {}) {
1499
+ const client = usePredictClient();
1500
+ return useQuery({
1501
+ queryKey: positionValueQueryKey(params.user, params.source),
1502
+ queryFn: () => client.getPositionValue(params.user, params.source),
1503
+ enabled: Boolean(params.user),
1504
+ staleTime: 1e4,
1505
+ refetchInterval: 3e4,
1506
+ ...queryOptions
1507
+ });
1508
+ }
1509
+ function usePositionValueMulti(params, queryOptions = {}) {
1510
+ const client = usePredictClient();
1511
+ const hasAnyWallet = Boolean(params.kalshi_user || params.polymarket_user);
1512
+ return useQuery({
1513
+ queryKey: positionValueMultiQueryKey(params),
1514
+ queryFn: () => client.getPositionValue(params),
1515
+ enabled: hasAnyWallet,
1516
+ staleTime: 1e4,
1517
+ refetchInterval: 3e4,
1518
+ ...queryOptions
1519
+ });
1520
+ }
1469
1521
  function availableSharesQueryKey(params) {
1470
1522
  return [
1471
1523
  "predict",
@@ -1601,7 +1653,8 @@ var SLOW_AFTER_MS = 12e3;
1601
1653
  var QUERY_PREFIXES = [
1602
1654
  ["predict", "trades"],
1603
1655
  ["predict", "trades-by-wallet"],
1604
- ["predict", "available-shares"]
1656
+ ["predict", "available-shares"],
1657
+ ["predict", "position-value"]
1605
1658
  ];
1606
1659
  var OPEN_ORDER_STATUSES = /* @__PURE__ */ new Set(["live", "open", "submitted", "pending"]);
1607
1660
  function getPositionsWallets(input) {
@@ -1884,6 +1937,29 @@ function requestPositionsSnapshot(queryClient, predictClient, input) {
1884
1937
  return normalizePositionsData(data, input);
1885
1938
  });
1886
1939
  }
1940
+ function refreshPositionValueSnapshot(queryClient, predictClient, input) {
1941
+ const wallets = getPositionsWallets(input);
1942
+ const tasks = [];
1943
+ if (wallets) {
1944
+ tasks.push(
1945
+ predictClient.getPositionValue(wallets).then((data) => {
1946
+ queryClient.setQueryData(positionValueMultiQueryKey(wallets), data);
1947
+ })
1948
+ );
1949
+ }
1950
+ if (input.user) {
1951
+ tasks.push(
1952
+ predictClient.getPositionValue(input.user, input.source).then((data) => {
1953
+ queryClient.setQueryData(
1954
+ positionValueQueryKey(input.user, input.source),
1955
+ data
1956
+ );
1957
+ })
1958
+ );
1959
+ }
1960
+ if (tasks.length === 0) return Promise.resolve();
1961
+ return Promise.all(tasks).then(() => void 0);
1962
+ }
1887
1963
  function requestOrdersSnapshot(queryClient, predictClient, input) {
1888
1964
  if (!input.user) return Promise.resolve(void 0);
1889
1965
  const params = { source: input.source, wallet_address: input.user };
@@ -1974,7 +2050,11 @@ async function runFixedIntervalConfirmation({
1974
2050
  const pollField = (field, request) => {
1975
2051
  if (inFlight[field] || settled) return;
1976
2052
  inFlight[field] = true;
1977
- void request().then((value) => handleSnapshot(field, value)).catch(() => void 0).finally(() => {
2053
+ void request().then((value) => handleSnapshot(field, value)).then(() => {
2054
+ if (field === "positions") {
2055
+ void refreshPositionValueSnapshot(queryClient, predictClient, input);
2056
+ }
2057
+ }).catch(() => void 0).finally(() => {
1978
2058
  inFlight[field] = false;
1979
2059
  });
1980
2060
  };
@@ -3194,6 +3274,6 @@ function walkOrderbook({
3194
3274
  };
3195
3275
  }
3196
3276
 
3197
- 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, orderQueryKey, orderbookQueryKey, ordersMultiQueryKey, ordersQueryKey, pickBestAsk, pickBestBid, polymarketDepositAddressesQueryKey, polymarketSetupQueryKey, polymarketSupportedAssetsQueryKey, polymarketWithdrawStatusQueryKey, 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, usePositions, usePositionsMulti, usePredictClient, usePredictWsClient, usePriceHistory, usePricesSubscription, useRealtimeOrderbook, useRealtimePrices, useRealtimeTrades, useRebateConfig, useRedeemPosition, useRunPolymarketSetup, useSearchEvents, useSimilarEvents, useTickSize, useTradeResultConfirmation, useTrades, useTradesSubscription, useWithdrawBuildMutation, useWithdrawStatusQuery, useWithdrawSubmitMutation, walkOrderbook, withdrawStatusQueryKey };
3277
+ 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, 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 };
3198
3278
  //# sourceMappingURL=index.mjs.map
3199
3279
  //# sourceMappingURL=index.mjs.map