@orderly.network/hooks 2.8.5 → 2.8.6-alpha.0
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 +23 -4
- package/dist/index.d.ts +23 -4
- package/dist/index.js +110 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -38,9 +38,9 @@ var __export = (target, all) => {
|
|
|
38
38
|
// src/version.ts
|
|
39
39
|
if (typeof window !== "undefined") {
|
|
40
40
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
41
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.
|
|
41
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.6-alpha.0";
|
|
42
42
|
}
|
|
43
|
-
var version_default = "2.8.
|
|
43
|
+
var version_default = "2.8.6-alpha.0";
|
|
44
44
|
var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
|
|
45
45
|
var noCacheConfig = {
|
|
46
46
|
dedupingInterval: 0,
|
|
@@ -736,8 +736,8 @@ var useCommission = (options) => {
|
|
|
736
736
|
}];
|
|
737
737
|
};
|
|
738
738
|
function compareDate(d1, d2) {
|
|
739
|
-
const
|
|
740
|
-
return
|
|
739
|
+
const isEqual2 = d1 && d2 && d1.getDay() === d2.getDay() && d1.getMonth() === d2.getMonth() && d1.getFullYear() === d2.getFullYear();
|
|
740
|
+
return isEqual2;
|
|
741
741
|
}
|
|
742
742
|
|
|
743
743
|
// src/referral/format.ts
|
|
@@ -6955,6 +6955,7 @@ var useDeposit = (options) => {
|
|
|
6955
6955
|
const [balance, setBalance] = useState("0");
|
|
6956
6956
|
const [allowance, setAllowance] = useState("0");
|
|
6957
6957
|
const balanceRef = useRef("");
|
|
6958
|
+
const currentAddressRef = useRef();
|
|
6958
6959
|
const { account: account9, state } = useAccount();
|
|
6959
6960
|
const { track: track2 } = useTrack();
|
|
6960
6961
|
const prevAddress = useRef();
|
|
@@ -7293,6 +7294,7 @@ var useDeposit = (options) => {
|
|
|
7293
7294
|
if (balanceRef.current === "") {
|
|
7294
7295
|
setBalanceRevalidating(true);
|
|
7295
7296
|
}
|
|
7297
|
+
currentAddressRef.current = options.address;
|
|
7296
7298
|
getBalanceListener.current = setTimeout(async () => {
|
|
7297
7299
|
try {
|
|
7298
7300
|
const balance2 = await fetchBalanceHandler(
|
|
@@ -7303,9 +7305,11 @@ var useDeposit = (options) => {
|
|
|
7303
7305
|
balanceRef.current = balance2;
|
|
7304
7306
|
loopGetBalance();
|
|
7305
7307
|
} catch (err) {
|
|
7308
|
+
if (currentAddressRef.current !== options.address)
|
|
7309
|
+
return;
|
|
7306
7310
|
loopGetBalance(1e3);
|
|
7307
7311
|
} finally {
|
|
7308
|
-
if (balanceRef.current !== "") {
|
|
7312
|
+
if (balanceRef.current !== "" && currentAddressRef.current === options.address) {
|
|
7309
7313
|
setBalanceRevalidating(false);
|
|
7310
7314
|
}
|
|
7311
7315
|
}
|
|
@@ -7347,6 +7351,10 @@ var useDeposit = (options) => {
|
|
|
7347
7351
|
if (!options.address) {
|
|
7348
7352
|
return;
|
|
7349
7353
|
}
|
|
7354
|
+
currentAddressRef.current = options.address;
|
|
7355
|
+
setBalance("0");
|
|
7356
|
+
balanceRef.current = "";
|
|
7357
|
+
setBalanceRevalidating(false);
|
|
7350
7358
|
loopGetBalance(0);
|
|
7351
7359
|
return () => {
|
|
7352
7360
|
if (getBalanceListener.current) {
|
|
@@ -7378,8 +7386,8 @@ var useDeposit = (options) => {
|
|
|
7378
7386
|
};
|
|
7379
7387
|
};
|
|
7380
7388
|
function ignoreBalanceError(options) {
|
|
7381
|
-
const {
|
|
7382
|
-
return chainNamespace === ChainNamespace.solana &&
|
|
7389
|
+
const { chainNamespace, err } = options;
|
|
7390
|
+
return chainNamespace === ChainNamespace.solana && err?.name === "TokenAccountNotFoundError";
|
|
7383
7391
|
}
|
|
7384
7392
|
|
|
7385
7393
|
// src/orderly/useConvert.ts
|
|
@@ -10396,13 +10404,19 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
10396
10404
|
);
|
|
10397
10405
|
});
|
|
10398
10406
|
};
|
|
10399
|
-
const validate = () => {
|
|
10407
|
+
const validate = (otherErrors) => {
|
|
10400
10408
|
const orderCreator = getOrderCreator2();
|
|
10401
10409
|
return new Promise((resolve, reject) => {
|
|
10402
10410
|
return orderCreator.validate(
|
|
10403
10411
|
order,
|
|
10404
10412
|
valueConfig
|
|
10405
10413
|
).then((errors2) => {
|
|
10414
|
+
if (otherErrors) {
|
|
10415
|
+
errors2 = {
|
|
10416
|
+
...errors2,
|
|
10417
|
+
...otherErrors
|
|
10418
|
+
};
|
|
10419
|
+
}
|
|
10406
10420
|
if (errors2) {
|
|
10407
10421
|
const keys = Object.keys(errors2);
|
|
10408
10422
|
if (keys.length > 0) {
|
|
@@ -17836,11 +17850,12 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
17836
17850
|
const [doCreateOrder, { isMutating }] = useMutation(
|
|
17837
17851
|
getCreateOrderUrl(formattedOrder)
|
|
17838
17852
|
);
|
|
17839
|
-
const
|
|
17853
|
+
const maxQtyValue = useMaxQty(
|
|
17840
17854
|
symbol,
|
|
17841
17855
|
formattedOrder.side,
|
|
17842
17856
|
formattedOrder.reduce_only
|
|
17843
17857
|
);
|
|
17858
|
+
const maxQty = options.maxQty ?? maxQtyValue;
|
|
17844
17859
|
const updateOrderPrice = () => {
|
|
17845
17860
|
const order_type = formattedOrder.order_type;
|
|
17846
17861
|
const order_type_ext = formattedOrder.order_type_ext ?? lastOrderTypeExt.current;
|
|
@@ -18019,11 +18034,17 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18019
18034
|
const creator = getOrderCreator(order);
|
|
18020
18035
|
return validate(order, creator, prepareData());
|
|
18021
18036
|
}
|
|
18022
|
-
const validateOrder = () => {
|
|
18037
|
+
const validateOrder = (otherErrors) => {
|
|
18023
18038
|
return new Promise(
|
|
18024
18039
|
async (resolve, reject) => {
|
|
18025
18040
|
const creator = getOrderCreator(formattedOrder);
|
|
18026
|
-
|
|
18041
|
+
let errors = await validate(formattedOrder, creator, prepareData());
|
|
18042
|
+
if (otherErrors) {
|
|
18043
|
+
errors = {
|
|
18044
|
+
...errors,
|
|
18045
|
+
...otherErrors
|
|
18046
|
+
};
|
|
18047
|
+
}
|
|
18027
18048
|
const keys = Object.keys(errors);
|
|
18028
18049
|
if (keys.length > 0) {
|
|
18029
18050
|
setMeta(
|
|
@@ -18051,10 +18072,6 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18051
18072
|
if (!markPrice2 || !accountInfo || !symbolInfo) {
|
|
18052
18073
|
return null;
|
|
18053
18074
|
}
|
|
18054
|
-
const orderQuantity = Number(formattedOrder.order_quantity);
|
|
18055
|
-
if (orderQuantity === 0 || orderQuantity > maxQty) {
|
|
18056
|
-
return null;
|
|
18057
|
-
}
|
|
18058
18075
|
const estLiqPrice2 = calcEstLiqPrice(formattedOrder, askAndBid.current[0], {
|
|
18059
18076
|
markPrice: markPrice2,
|
|
18060
18077
|
totalCollateral,
|
|
@@ -18519,6 +18536,81 @@ var usePositionClose = (options) => {
|
|
|
18519
18536
|
};
|
|
18520
18537
|
};
|
|
18521
18538
|
|
|
18522
|
-
|
|
18539
|
+
// src/next/tpsl/errorMsgCodes.ts
|
|
18540
|
+
var ERROR_MSG_CODES = {
|
|
18541
|
+
SL_PRICE_WARNING: 10001,
|
|
18542
|
+
// sl price warning
|
|
18543
|
+
SL_PRICE_ERROR: 10002
|
|
18544
|
+
// sl price error
|
|
18545
|
+
};
|
|
18546
|
+
|
|
18547
|
+
// src/next/tpsl/useTpslPriceChecker.ts
|
|
18548
|
+
var isEqual = (a, b) => {
|
|
18549
|
+
if (a === b)
|
|
18550
|
+
return true;
|
|
18551
|
+
if (a === null || b === null)
|
|
18552
|
+
return false;
|
|
18553
|
+
const aItem = a.sl_trigger_price;
|
|
18554
|
+
const bItem = b.sl_trigger_price;
|
|
18555
|
+
if (aItem === bItem)
|
|
18556
|
+
return true;
|
|
18557
|
+
if (aItem === void 0 || bItem === void 0)
|
|
18558
|
+
return false;
|
|
18559
|
+
return aItem.type === bItem.type && aItem.message === bItem.message;
|
|
18560
|
+
};
|
|
18561
|
+
var useTpslPriceChecker = (params) => {
|
|
18562
|
+
const { warning_threshold = 0.01, slPrice, liqPrice, side } = params;
|
|
18563
|
+
const prevResultRef = useRef(null);
|
|
18564
|
+
const currentResult = useMemo(() => {
|
|
18565
|
+
if (slPrice === void 0 || liqPrice === void 0 || side === void 0 || liqPrice === null) {
|
|
18566
|
+
return null;
|
|
18567
|
+
}
|
|
18568
|
+
let slPriceDecimal;
|
|
18569
|
+
let liqPriceDecimal;
|
|
18570
|
+
try {
|
|
18571
|
+
slPriceDecimal = new Decimal(slPrice);
|
|
18572
|
+
liqPriceDecimal = new Decimal(liqPrice);
|
|
18573
|
+
} catch (e) {
|
|
18574
|
+
return null;
|
|
18575
|
+
}
|
|
18576
|
+
const slPriceNum = slPriceDecimal.toNumber();
|
|
18577
|
+
const liqPriceNum = liqPriceDecimal.toNumber();
|
|
18578
|
+
if (Number.isNaN(slPriceNum) || Number.isNaN(liqPriceNum) || !Number.isFinite(slPriceNum) || !Number.isFinite(liqPriceNum) || liqPriceDecimal.isZero() || slPriceDecimal.isZero()) {
|
|
18579
|
+
return null;
|
|
18580
|
+
}
|
|
18581
|
+
const distance_ratio = side === OrderSide.BUY ? slPriceDecimal.minus(liqPriceDecimal).div(liqPriceDecimal) : liqPriceDecimal.minus(slPriceDecimal).div(liqPriceDecimal);
|
|
18582
|
+
if (distance_ratio.gt(warning_threshold)) {
|
|
18583
|
+
return null;
|
|
18584
|
+
}
|
|
18585
|
+
if (distance_ratio.gt(0) && distance_ratio.lte(warning_threshold)) {
|
|
18586
|
+
return {
|
|
18587
|
+
sl_trigger_price: {
|
|
18588
|
+
type: ERROR_MSG_CODES.SL_PRICE_WARNING,
|
|
18589
|
+
message: "Stop losses set near the liq. price may not trigger. Note: the liq. price can change with position notional."
|
|
18590
|
+
}
|
|
18591
|
+
};
|
|
18592
|
+
}
|
|
18593
|
+
return {
|
|
18594
|
+
sl_trigger_price: {
|
|
18595
|
+
type: ERROR_MSG_CODES.SL_PRICE_ERROR,
|
|
18596
|
+
message: "Stop loss crosses the liq. price. Please adjust your SL."
|
|
18597
|
+
}
|
|
18598
|
+
};
|
|
18599
|
+
}, [slPrice, liqPrice, side, warning_threshold]);
|
|
18600
|
+
if (isEqual(prevResultRef.current, currentResult)) {
|
|
18601
|
+
return prevResultRef.current;
|
|
18602
|
+
}
|
|
18603
|
+
prevResultRef.current = currentResult;
|
|
18604
|
+
return currentResult;
|
|
18605
|
+
};
|
|
18606
|
+
var useEstLiqPriceBySymbol = (symbol) => {
|
|
18607
|
+
const [data] = usePositionStream(symbol);
|
|
18608
|
+
const position = data?.rows?.find((row) => row.symbol === symbol);
|
|
18609
|
+
return useMemo(() => {
|
|
18610
|
+
return position?.est_liq_price ?? void 0;
|
|
18611
|
+
}, [position]);
|
|
18612
|
+
};
|
|
18613
|
+
|
|
18614
|
+
export { DefaultLayoutConfig, DistributionId, ENVType2 as ENVType, ERROR_MSG_CODES, EpochStatus, ExtendedConfigStore, MaintenanceStatus, MarketsStorageKey, MarketsType, ORDERLY_ORDERBOOK_DEPTH_KEY, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, StatusProvider, TWType, WalletConnectorContext, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, getMinNotional, getPriceKey, indexedDBManager, initializeAppDatabase, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, persistIndexedDB, resetTimestampOffsetState, timestampWaitingMiddleware, useAccount, useAccountInfo2 as useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAppStore, useAssetsHistory, useAudioPlayer, useBalanceSubscription, useBalanceTopic, useBoolean, useChain, useChainInfo, useChains, useCheckReferralCode, useCollateral, useCommission, useComputedLTV, useConfig, useConvert, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEstLiqPriceBySymbol, useEventEmitter, useFeeState, useFundingDetails, useFundingFeeHistory, useFundingRate, useFundingRateBySymbol, useFundingRateHistory, useFundingRates, useFundingRatesStore, useGetClaimed, useGetEnv, useGetReferralCode, useGetRwaSymbolCloseTimeInterval, useGetRwaSymbolInfo, useGetRwaSymbolOpenStatus, useGetRwaSymbolOpenTimeInterval, useHoldingStream, useIndexPrice, useIndexPricesStream, useInfiniteQuery, useInitRwaSymbolsRuntime, useInternalTransfer, useKeyStore, useLazyQuery, useLeverage, useLeverageBySymbol, useLocalStorage, useMainTokenStore, useMainnetChainsStore, useMaintenanceStatus, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketList, useMarketMap, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxLeverage, useMaxQty, useMaxWithdrawal, useMediaQuery, useMemoizedFn, useMutation, useNetworkInfo, useOdosQuote, useOrderEntity, useOrderEntry2 as useOrderEntry, useOrderEntry as useOrderEntry_deprecated, useOrderStore2 as useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedInfo, useRwaSymbolsInfo, useRwaSymbolsInfoStore, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useStorageChain, useStorageLedgerAddress, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useSubAccountMutation, useSubAccountQuery, useSubAccountWS, useSwapSupportStore, useSymbolInfo, useSymbolLeverage, useSymbolPriceRange, useSymbolsInfo, useSymbolsInfoStore, useTPSLOrder, useTestTokenStore, useTestnetChainsStore, useTickerStream, useTokenInfo, useTokensInfo, useTpslPriceChecker, useTrack, useTrackingInstance, useTradingRewardsStatus, useTransfer, useTransferHistory, useUpdatedRef, useVaultsHistory, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWalletTopic, useWithdraw, useWsStatus, utils_exports as utils, version_default as version };
|
|
18523
18615
|
//# sourceMappingURL=out.js.map
|
|
18524
18616
|
//# sourceMappingURL=index.mjs.map
|