@liberfi.io/react-predict 0.3.60 → 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.d.mts +32 -3
- package/dist/index.d.ts +32 -3
- package/dist/index.js +93 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{server-h41hs9SR.d.mts → server-BW_QhQos.d.mts} +44 -1
- package/dist/{server-h41hs9SR.d.ts → server-BW_QhQos.d.ts} +44 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +17 -0
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +17 -0
- package/dist/server.mjs.map +1 -1
- package/package.json +3 -3
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) {
|
|
@@ -1771,7 +1824,8 @@ function getOpenOrderCount(snapshot) {
|
|
|
1771
1824
|
function hasBothAccountFields(snapshot) {
|
|
1772
1825
|
return snapshot.balance !== void 0 && snapshot.positions !== void 0;
|
|
1773
1826
|
}
|
|
1774
|
-
function isTradeResultConfirmed(
|
|
1827
|
+
function isTradeResultConfirmed(input, baseline, current) {
|
|
1828
|
+
const expectation = input.expectation;
|
|
1775
1829
|
const ordersChanged = didFieldChange("orders", baseline, current);
|
|
1776
1830
|
const baselineOpenOrders = getOpenOrderCount(baseline);
|
|
1777
1831
|
const currentOpenOrders = getOpenOrderCount(current);
|
|
@@ -1801,6 +1855,9 @@ function isTradeResultConfirmed(expectation, baseline, current) {
|
|
|
1801
1855
|
case "sell-market":
|
|
1802
1856
|
return balanceIncreased && positionsDecreased;
|
|
1803
1857
|
case "redeem":
|
|
1858
|
+
if (input.expectedPayout !== void 0 && input.expectedPayout <= 0) {
|
|
1859
|
+
return positionsChanged;
|
|
1860
|
+
}
|
|
1804
1861
|
return balanceChanged && positionsChanged;
|
|
1805
1862
|
case "cancel-order":
|
|
1806
1863
|
return false;
|
|
@@ -1880,6 +1937,29 @@ function requestPositionsSnapshot(queryClient, predictClient, input) {
|
|
|
1880
1937
|
return normalizePositionsData(data, input);
|
|
1881
1938
|
});
|
|
1882
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
|
+
}
|
|
1883
1963
|
function requestOrdersSnapshot(queryClient, predictClient, input) {
|
|
1884
1964
|
if (!input.user) return Promise.resolve(void 0);
|
|
1885
1965
|
const params = { source: input.source, wallet_address: input.user };
|
|
@@ -1955,7 +2035,7 @@ async function runFixedIntervalConfirmation({
|
|
|
1955
2035
|
if (value === void 0 || settled) return;
|
|
1956
2036
|
if (baseline[field] === void 0) {
|
|
1957
2037
|
current[field] = value;
|
|
1958
|
-
if (field === "orders" && isLimitExpectation(input.expectation) && isTradeResultConfirmed(input
|
|
2038
|
+
if (field === "orders" && isLimitExpectation(input.expectation) && isTradeResultConfirmed(input, baseline, current)) {
|
|
1959
2039
|
finishConfirmed();
|
|
1960
2040
|
return;
|
|
1961
2041
|
}
|
|
@@ -1963,14 +2043,18 @@ async function runFixedIntervalConfirmation({
|
|
|
1963
2043
|
return;
|
|
1964
2044
|
}
|
|
1965
2045
|
current[field] = value;
|
|
1966
|
-
if (isTradeResultConfirmed(input
|
|
2046
|
+
if (isTradeResultConfirmed(input, baseline, current)) {
|
|
1967
2047
|
finishConfirmed();
|
|
1968
2048
|
}
|
|
1969
2049
|
};
|
|
1970
2050
|
const pollField = (field, request) => {
|
|
1971
2051
|
if (inFlight[field] || settled) return;
|
|
1972
2052
|
inFlight[field] = true;
|
|
1973
|
-
void request().then((value) => handleSnapshot(field, value)).
|
|
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(() => {
|
|
1974
2058
|
inFlight[field] = false;
|
|
1975
2059
|
});
|
|
1976
2060
|
};
|
|
@@ -3190,6 +3274,6 @@ function walkOrderbook({
|
|
|
3190
3274
|
};
|
|
3191
3275
|
}
|
|
3192
3276
|
|
|
3193
|
-
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 };
|
|
3194
3278
|
//# sourceMappingURL=index.mjs.map
|
|
3195
3279
|
//# sourceMappingURL=index.mjs.map
|