@orderly.network/hooks 2.8.13-rc.0 → 2.8.13
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 +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +139 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -28
- 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.13
|
|
41
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.13";
|
|
42
42
|
}
|
|
43
|
-
var version_default = "2.8.13
|
|
43
|
+
var version_default = "2.8.13";
|
|
44
44
|
var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
|
|
45
45
|
var noCacheConfig = {
|
|
46
46
|
dedupingInterval: 0,
|
|
@@ -7075,12 +7075,18 @@ var useLeverageBySymbol = (symbol) => {
|
|
|
7075
7075
|
const res = data2?.accountDetail?.symbolLeverage || {};
|
|
7076
7076
|
if (res.symbol === symbol) {
|
|
7077
7077
|
const key = [`/v1/client/leverage?symbol=${symbol}`, state.accountId];
|
|
7078
|
-
mutate(
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7078
|
+
mutate(
|
|
7079
|
+
key,
|
|
7080
|
+
(prevData) => {
|
|
7081
|
+
return {
|
|
7082
|
+
...prevData,
|
|
7083
|
+
leverage: res.leverage
|
|
7084
|
+
};
|
|
7085
|
+
},
|
|
7086
|
+
{
|
|
7087
|
+
revalidate: false
|
|
7088
|
+
}
|
|
7089
|
+
);
|
|
7084
7090
|
}
|
|
7085
7091
|
}
|
|
7086
7092
|
});
|
|
@@ -18356,6 +18362,13 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18356
18362
|
);
|
|
18357
18363
|
};
|
|
18358
18364
|
const { freeCollateral, totalCollateral } = useCollateral();
|
|
18365
|
+
const currentPosition = useMemo(() => {
|
|
18366
|
+
const rows = positions3 ?? [];
|
|
18367
|
+
const p = Array.isArray(rows) ? rows.find(
|
|
18368
|
+
(r) => r.symbol === symbol
|
|
18369
|
+
) : null;
|
|
18370
|
+
return p?.position_qty ?? 0;
|
|
18371
|
+
}, [positions3, symbol]);
|
|
18359
18372
|
const estLiqPrice = useMemo(() => {
|
|
18360
18373
|
const markPrice2 = actions.getMarkPriceBySymbol(symbol);
|
|
18361
18374
|
if (!markPrice2 || !accountInfo || !symbolInfo) {
|
|
@@ -18380,6 +18393,12 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18380
18393
|
maxQty,
|
|
18381
18394
|
symbolInfo
|
|
18382
18395
|
]);
|
|
18396
|
+
const estLiqPriceDistance = useMemo(() => {
|
|
18397
|
+
if (!estLiqPrice) {
|
|
18398
|
+
return null;
|
|
18399
|
+
}
|
|
18400
|
+
return new Decimal(estLiqPrice).minus(markPrice).abs().div(markPrice).toNumber();
|
|
18401
|
+
}, [estLiqPrice, markPrice]);
|
|
18383
18402
|
const estLeverage = useMemo(() => {
|
|
18384
18403
|
if (!symbolInfo) {
|
|
18385
18404
|
return null;
|
|
@@ -18496,6 +18515,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18496
18515
|
formattedOrder,
|
|
18497
18516
|
maxQty,
|
|
18498
18517
|
estLiqPrice,
|
|
18518
|
+
estLiqPriceDistance,
|
|
18519
|
+
currentPosition,
|
|
18499
18520
|
estLeverage,
|
|
18500
18521
|
estSlippage,
|
|
18501
18522
|
helper: {
|
|
@@ -18843,9 +18864,85 @@ var isEqual = (a, b) => {
|
|
|
18843
18864
|
if (aItem === void 0 || bItem === void 0) return false;
|
|
18844
18865
|
return aItem.type === bItem.type && aItem.message === bItem.message;
|
|
18845
18866
|
};
|
|
18867
|
+
function calculateDistanceRatio(slPriceDecimal, liqPriceDecimal, side) {
|
|
18868
|
+
return side === OrderSide.BUY ? slPriceDecimal.minus(liqPriceDecimal).div(liqPriceDecimal) : liqPriceDecimal.minus(slPriceDecimal).div(liqPriceDecimal);
|
|
18869
|
+
}
|
|
18870
|
+
function checkDistanceAndReturnResult(distance_ratio, warning_threshold) {
|
|
18871
|
+
if (distance_ratio.gt(warning_threshold)) {
|
|
18872
|
+
return null;
|
|
18873
|
+
}
|
|
18874
|
+
if (distance_ratio.gt(0) && distance_ratio.lte(warning_threshold)) {
|
|
18875
|
+
return {
|
|
18876
|
+
sl_trigger_price: {
|
|
18877
|
+
type: ERROR_MSG_CODES.SL_PRICE_WARNING,
|
|
18878
|
+
message: "Stop losses set near the liq. price may not trigger. Note: the liq. price can change with position notional."
|
|
18879
|
+
}
|
|
18880
|
+
};
|
|
18881
|
+
}
|
|
18882
|
+
return {
|
|
18883
|
+
sl_trigger_price: {
|
|
18884
|
+
type: ERROR_MSG_CODES.SL_PRICE_ERROR,
|
|
18885
|
+
message: "Stop loss crosses the liq. price. Please adjust your SL."
|
|
18886
|
+
}
|
|
18887
|
+
};
|
|
18888
|
+
}
|
|
18846
18889
|
var useTpslPriceChecker = (params) => {
|
|
18847
|
-
const {
|
|
18890
|
+
const {
|
|
18891
|
+
warning_threshold = 0.01,
|
|
18892
|
+
slPrice,
|
|
18893
|
+
liqPrice,
|
|
18894
|
+
side,
|
|
18895
|
+
currentPosition,
|
|
18896
|
+
orderQuantity
|
|
18897
|
+
} = params;
|
|
18848
18898
|
const prevResultRef = useRef(null);
|
|
18899
|
+
function validateSlPriceBasic(slPriceDecimal, liqPriceDecimal) {
|
|
18900
|
+
if (!side) return null;
|
|
18901
|
+
const distance_ratio = calculateDistanceRatio(
|
|
18902
|
+
slPriceDecimal,
|
|
18903
|
+
liqPriceDecimal,
|
|
18904
|
+
side
|
|
18905
|
+
);
|
|
18906
|
+
return checkDistanceAndReturnResult(distance_ratio, warning_threshold);
|
|
18907
|
+
}
|
|
18908
|
+
function validateSlPriceWithPosition(slPriceDecimal, liqPriceDecimal, currentPosition2, orderQuantity2) {
|
|
18909
|
+
if (!side) return null;
|
|
18910
|
+
const canComputeIsReducing = currentPosition2 !== void 0 && orderQuantity2 !== void 0 && orderQuantity2 > 0;
|
|
18911
|
+
if (!canComputeIsReducing) {
|
|
18912
|
+
return null;
|
|
18913
|
+
}
|
|
18914
|
+
const orderQty = side === OrderSide.SELL ? -(orderQuantity2 || 0) : orderQuantity2 || 0;
|
|
18915
|
+
const cur = currentPosition2 ?? 0;
|
|
18916
|
+
const net = new Decimal(cur).plus(orderQty).toNumber();
|
|
18917
|
+
const is_reducing = new Decimal(Math.abs(net)).lt(Math.abs(cur));
|
|
18918
|
+
const posSide = currentPosition2 > 0 ? OrderSide.BUY : OrderSide.SELL;
|
|
18919
|
+
const isSameSide = posSide === side;
|
|
18920
|
+
if (is_reducing && isSameSide) {
|
|
18921
|
+
return null;
|
|
18922
|
+
}
|
|
18923
|
+
if (net > 0 && slPriceDecimal.lte(liqPriceDecimal)) {
|
|
18924
|
+
return {
|
|
18925
|
+
sl_trigger_price: {
|
|
18926
|
+
type: ERROR_MSG_CODES.SL_PRICE_ERROR,
|
|
18927
|
+
message: "Stop loss crosses the liq. price. Please adjust your SL."
|
|
18928
|
+
}
|
|
18929
|
+
};
|
|
18930
|
+
}
|
|
18931
|
+
if (net < 0 && slPriceDecimal.gte(liqPriceDecimal)) {
|
|
18932
|
+
return {
|
|
18933
|
+
sl_trigger_price: {
|
|
18934
|
+
type: ERROR_MSG_CODES.SL_PRICE_ERROR,
|
|
18935
|
+
message: "Stop loss crosses the liq. price. Please adjust your SL."
|
|
18936
|
+
}
|
|
18937
|
+
};
|
|
18938
|
+
}
|
|
18939
|
+
const distance_ratio = calculateDistanceRatio(
|
|
18940
|
+
slPriceDecimal,
|
|
18941
|
+
liqPriceDecimal,
|
|
18942
|
+
side
|
|
18943
|
+
);
|
|
18944
|
+
return checkDistanceAndReturnResult(distance_ratio, warning_threshold);
|
|
18945
|
+
}
|
|
18849
18946
|
const currentResult = useMemo(() => {
|
|
18850
18947
|
if (slPrice === void 0 || liqPrice === void 0 || side === void 0 || liqPrice === null) {
|
|
18851
18948
|
return null;
|
|
@@ -18863,25 +18960,23 @@ var useTpslPriceChecker = (params) => {
|
|
|
18863
18960
|
if (Number.isNaN(slPriceNum) || Number.isNaN(liqPriceNum) || !Number.isFinite(slPriceNum) || !Number.isFinite(liqPriceNum) || liqPriceDecimal.isZero() || slPriceDecimal.isZero()) {
|
|
18864
18961
|
return null;
|
|
18865
18962
|
}
|
|
18866
|
-
|
|
18867
|
-
|
|
18868
|
-
|
|
18869
|
-
|
|
18870
|
-
|
|
18871
|
-
|
|
18872
|
-
|
|
18873
|
-
type: ERROR_MSG_CODES.SL_PRICE_WARNING,
|
|
18874
|
-
message: "Stop losses set near the liq. price may not trigger. Note: the liq. price can change with position notional."
|
|
18875
|
-
}
|
|
18876
|
-
};
|
|
18963
|
+
if (currentPosition !== void 0 && orderQuantity !== void 0 && orderQuantity > 0) {
|
|
18964
|
+
return validateSlPriceWithPosition(
|
|
18965
|
+
slPriceDecimal,
|
|
18966
|
+
liqPriceDecimal,
|
|
18967
|
+
currentPosition,
|
|
18968
|
+
orderQuantity
|
|
18969
|
+
);
|
|
18877
18970
|
}
|
|
18878
|
-
return
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
|
|
18882
|
-
|
|
18883
|
-
|
|
18884
|
-
|
|
18971
|
+
return validateSlPriceBasic(slPriceDecimal, liqPriceDecimal);
|
|
18972
|
+
}, [
|
|
18973
|
+
slPrice,
|
|
18974
|
+
liqPrice,
|
|
18975
|
+
side,
|
|
18976
|
+
warning_threshold,
|
|
18977
|
+
currentPosition,
|
|
18978
|
+
orderQuantity
|
|
18979
|
+
]);
|
|
18885
18980
|
if (isEqual(prevResultRef.current, currentResult)) {
|
|
18886
18981
|
return prevResultRef.current;
|
|
18887
18982
|
}
|
|
@@ -18895,7 +18990,23 @@ var useEstLiqPriceBySymbol = (symbol) => {
|
|
|
18895
18990
|
return position?.est_liq_price ?? void 0;
|
|
18896
18991
|
}, [position]);
|
|
18897
18992
|
};
|
|
18993
|
+
var useGetEstLiqPrice = (props) => {
|
|
18994
|
+
const { estLiqPrice, symbol, side } = props;
|
|
18995
|
+
const { data: markPrice } = useMarkPrice(symbol);
|
|
18996
|
+
return useMemo(() => {
|
|
18997
|
+
if (!estLiqPrice || !markPrice) {
|
|
18998
|
+
return null;
|
|
18999
|
+
}
|
|
19000
|
+
if (side === OrderSide.BUY && estLiqPrice > markPrice) {
|
|
19001
|
+
return null;
|
|
19002
|
+
}
|
|
19003
|
+
if (side === OrderSide.SELL && estLiqPrice < markPrice) {
|
|
19004
|
+
return null;
|
|
19005
|
+
}
|
|
19006
|
+
return estLiqPrice;
|
|
19007
|
+
}, [estLiqPrice, markPrice, side]);
|
|
19008
|
+
};
|
|
18898
19009
|
|
|
18899
|
-
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, useSubAccountAlgoOrderStream, 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 };
|
|
19010
|
+
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, useGetEstLiqPrice, 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, useSubAccountAlgoOrderStream, 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 };
|
|
18900
19011
|
//# sourceMappingURL=index.mjs.map
|
|
18901
19012
|
//# sourceMappingURL=index.mjs.map
|