@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.d.mts
CHANGED
|
@@ -36,7 +36,7 @@ declare global {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
declare const _default: "2.8.
|
|
39
|
+
declare const _default: "2.8.6-alpha.0";
|
|
40
40
|
|
|
41
41
|
declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
|
|
42
42
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
@@ -1442,6 +1442,10 @@ type OrderValidationItem = {
|
|
|
1442
1442
|
type: "priceErrorMin" | "priceErrorMax";
|
|
1443
1443
|
message: string;
|
|
1444
1444
|
value?: never;
|
|
1445
|
+
} | {
|
|
1446
|
+
type: number;
|
|
1447
|
+
message: string;
|
|
1448
|
+
value?: never;
|
|
1445
1449
|
};
|
|
1446
1450
|
type OrderValidationResult = {
|
|
1447
1451
|
[P in keyof OrderlyOrder]?: OrderValidationItem;
|
|
@@ -1513,7 +1517,7 @@ ComputedAlgoOrder, {
|
|
|
1513
1517
|
/**
|
|
1514
1518
|
*
|
|
1515
1519
|
*/
|
|
1516
|
-
validate: () => Promise<AlgoOrderEntity<AlgoOrderRootType.POSITIONAL_TP_SL | AlgoOrderRootType.TP_SL>>;
|
|
1520
|
+
validate: (otherErrors?: ValidateError) => Promise<AlgoOrderEntity<AlgoOrderRootType.POSITIONAL_TP_SL | AlgoOrderRootType.TP_SL>>;
|
|
1517
1521
|
metaState: {
|
|
1518
1522
|
dirty: { [K in keyof OrderlyOrder]?: boolean; };
|
|
1519
1523
|
submitted: boolean;
|
|
@@ -2637,7 +2641,7 @@ type OrderEntryReturn = {
|
|
|
2637
2641
|
* Function to validate the order.
|
|
2638
2642
|
* @returns {Promise<OrderValidationResult | null>} The validation result.
|
|
2639
2643
|
*/
|
|
2640
|
-
validate: () => Promise<OrderValidationResult | null>;
|
|
2644
|
+
validate: (otherErrors?: OrderValidationResult) => Promise<OrderValidationResult | null>;
|
|
2641
2645
|
};
|
|
2642
2646
|
freeCollateral: number;
|
|
2643
2647
|
/**
|
|
@@ -2847,4 +2851,19 @@ declare const usePositionClose: (options: PositionCloseOptions) => {
|
|
|
2847
2851
|
declare const useMarketList: () => API.MarketInfoExt[];
|
|
2848
2852
|
declare const useMarketMap: () => Record<string, API.MarketInfoExt> | null;
|
|
2849
2853
|
|
|
2850
|
-
|
|
2854
|
+
type TpslPriceParams = {
|
|
2855
|
+
warning_threshold?: number;
|
|
2856
|
+
slPrice?: string;
|
|
2857
|
+
liqPrice: number | null;
|
|
2858
|
+
side?: OrderSide;
|
|
2859
|
+
};
|
|
2860
|
+
declare const useTpslPriceChecker: (params: TpslPriceParams) => OrderValidationResult | null;
|
|
2861
|
+
|
|
2862
|
+
declare const ERROR_MSG_CODES: {
|
|
2863
|
+
SL_PRICE_WARNING: number;
|
|
2864
|
+
SL_PRICE_ERROR: number;
|
|
2865
|
+
};
|
|
2866
|
+
|
|
2867
|
+
declare const useEstLiqPriceBySymbol: (symbol: string) => number | undefined;
|
|
2868
|
+
|
|
2869
|
+
export { type APIKeyItem, type AccountRewardsHistory, type AccountRewardsHistoryRow, type Brokers, type Chain, type ChainFilter, type Chains, type CheckReferralCodeReturns, type CollateralOutputs, type ComputedAlgoOrder, type ConfigProviderProps, type ConnectedChain, type CurrentEpochEstimate, DefaultLayoutConfig, DistributionId, type DrawOptions, ENVType, ERROR_MSG_CODES, type EpochInfoItem, type EpochInfoType, EpochStatus, type ExclusiveConfigProviderProps, ExtendedConfigStore, type Favorite, type FavoriteTab, type FilteredChains, type FundingRates, MaintenanceStatus, type MarginRatioReturn, type MarketsItem, MarketsStorageKey, type MarketsStore, MarketsType, type NewListing, ORDERLY_ORDERBOOK_DEPTH_KEY, type OrderBookItem, type OrderEntryReturn, type OrderMetadata, type OrderMetadataConfig, type OrderParams, type OrderValidationItem, type OrderValidationResult, type OrderbookData, type OrderbookOptions, type OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, type PosterLayoutConfig, type PriceMode, type Recent, RefferalAPI, type RestrictedInfoOptions, type RestrictedInfoReturns, type RwaSymbolResult, type RwaSymbolsInfo, ScopeType, type StatusInfo, StatusProvider, type SymbolsInfo, TWType, type UseChainsOptions, type UseChainsReturnObject, type UseOrderEntryMetaState, WalletConnectorContext, type WalletConnectorContextState, type WalletRewards, type WalletRewardsHistoryReturns, type WalletRewardsItem, type WalletState, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, getMinNotional, getPriceKey, indexedDBManager, initializeAppDatabase, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, persistIndexedDB, resetTimestampOffsetState, timestampWaitingMiddleware, useAccount, 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, useOrderEntry, useOrderEntry$1 as useOrderEntry_deprecated, useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, type useQueryOptions, 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, index as utils, _default as version };
|
package/dist/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ declare global {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
declare const _default: "2.8.
|
|
39
|
+
declare const _default: "2.8.6-alpha.0";
|
|
40
40
|
|
|
41
41
|
declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
|
|
42
42
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
@@ -1442,6 +1442,10 @@ type OrderValidationItem = {
|
|
|
1442
1442
|
type: "priceErrorMin" | "priceErrorMax";
|
|
1443
1443
|
message: string;
|
|
1444
1444
|
value?: never;
|
|
1445
|
+
} | {
|
|
1446
|
+
type: number;
|
|
1447
|
+
message: string;
|
|
1448
|
+
value?: never;
|
|
1445
1449
|
};
|
|
1446
1450
|
type OrderValidationResult = {
|
|
1447
1451
|
[P in keyof OrderlyOrder]?: OrderValidationItem;
|
|
@@ -1513,7 +1517,7 @@ ComputedAlgoOrder, {
|
|
|
1513
1517
|
/**
|
|
1514
1518
|
*
|
|
1515
1519
|
*/
|
|
1516
|
-
validate: () => Promise<AlgoOrderEntity<AlgoOrderRootType.POSITIONAL_TP_SL | AlgoOrderRootType.TP_SL>>;
|
|
1520
|
+
validate: (otherErrors?: ValidateError) => Promise<AlgoOrderEntity<AlgoOrderRootType.POSITIONAL_TP_SL | AlgoOrderRootType.TP_SL>>;
|
|
1517
1521
|
metaState: {
|
|
1518
1522
|
dirty: { [K in keyof OrderlyOrder]?: boolean; };
|
|
1519
1523
|
submitted: boolean;
|
|
@@ -2637,7 +2641,7 @@ type OrderEntryReturn = {
|
|
|
2637
2641
|
* Function to validate the order.
|
|
2638
2642
|
* @returns {Promise<OrderValidationResult | null>} The validation result.
|
|
2639
2643
|
*/
|
|
2640
|
-
validate: () => Promise<OrderValidationResult | null>;
|
|
2644
|
+
validate: (otherErrors?: OrderValidationResult) => Promise<OrderValidationResult | null>;
|
|
2641
2645
|
};
|
|
2642
2646
|
freeCollateral: number;
|
|
2643
2647
|
/**
|
|
@@ -2847,4 +2851,19 @@ declare const usePositionClose: (options: PositionCloseOptions) => {
|
|
|
2847
2851
|
declare const useMarketList: () => API.MarketInfoExt[];
|
|
2848
2852
|
declare const useMarketMap: () => Record<string, API.MarketInfoExt> | null;
|
|
2849
2853
|
|
|
2850
|
-
|
|
2854
|
+
type TpslPriceParams = {
|
|
2855
|
+
warning_threshold?: number;
|
|
2856
|
+
slPrice?: string;
|
|
2857
|
+
liqPrice: number | null;
|
|
2858
|
+
side?: OrderSide;
|
|
2859
|
+
};
|
|
2860
|
+
declare const useTpslPriceChecker: (params: TpslPriceParams) => OrderValidationResult | null;
|
|
2861
|
+
|
|
2862
|
+
declare const ERROR_MSG_CODES: {
|
|
2863
|
+
SL_PRICE_WARNING: number;
|
|
2864
|
+
SL_PRICE_ERROR: number;
|
|
2865
|
+
};
|
|
2866
|
+
|
|
2867
|
+
declare const useEstLiqPriceBySymbol: (symbol: string) => number | undefined;
|
|
2868
|
+
|
|
2869
|
+
export { type APIKeyItem, type AccountRewardsHistory, type AccountRewardsHistoryRow, type Brokers, type Chain, type ChainFilter, type Chains, type CheckReferralCodeReturns, type CollateralOutputs, type ComputedAlgoOrder, type ConfigProviderProps, type ConnectedChain, type CurrentEpochEstimate, DefaultLayoutConfig, DistributionId, type DrawOptions, ENVType, ERROR_MSG_CODES, type EpochInfoItem, type EpochInfoType, EpochStatus, type ExclusiveConfigProviderProps, ExtendedConfigStore, type Favorite, type FavoriteTab, type FilteredChains, type FundingRates, MaintenanceStatus, type MarginRatioReturn, type MarketsItem, MarketsStorageKey, type MarketsStore, MarketsType, type NewListing, ORDERLY_ORDERBOOK_DEPTH_KEY, type OrderBookItem, type OrderEntryReturn, type OrderMetadata, type OrderMetadataConfig, type OrderParams, type OrderValidationItem, type OrderValidationResult, type OrderbookData, type OrderbookOptions, type OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, type PosterLayoutConfig, type PriceMode, type Recent, RefferalAPI, type RestrictedInfoOptions, type RestrictedInfoReturns, type RwaSymbolResult, type RwaSymbolsInfo, ScopeType, type StatusInfo, StatusProvider, type SymbolsInfo, TWType, type UseChainsOptions, type UseChainsReturnObject, type UseOrderEntryMetaState, WalletConnectorContext, type WalletConnectorContextState, type WalletRewards, type WalletRewardsHistoryReturns, type WalletRewardsItem, type WalletState, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, getMinNotional, getPriceKey, indexedDBManager, initializeAppDatabase, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, persistIndexedDB, resetTimestampOffsetState, timestampWaitingMiddleware, useAccount, 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, useOrderEntry, useOrderEntry$1 as useOrderEntry_deprecated, useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, type useQueryOptions, 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, index as utils, _default as version };
|
package/dist/index.js
CHANGED
|
@@ -64,9 +64,9 @@ var __export = (target, all) => {
|
|
|
64
64
|
// src/version.ts
|
|
65
65
|
if (typeof window !== "undefined") {
|
|
66
66
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
67
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.
|
|
67
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.6-alpha.0";
|
|
68
68
|
}
|
|
69
|
-
var version_default = "2.8.
|
|
69
|
+
var version_default = "2.8.6-alpha.0";
|
|
70
70
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
71
71
|
var noCacheConfig = {
|
|
72
72
|
dedupingInterval: 0,
|
|
@@ -762,8 +762,8 @@ var useCommission = (options) => {
|
|
|
762
762
|
}];
|
|
763
763
|
};
|
|
764
764
|
function compareDate(d1, d2) {
|
|
765
|
-
const
|
|
766
|
-
return
|
|
765
|
+
const isEqual2 = d1 && d2 && d1.getDay() === d2.getDay() && d1.getMonth() === d2.getMonth() && d1.getFullYear() === d2.getFullYear();
|
|
766
|
+
return isEqual2;
|
|
767
767
|
}
|
|
768
768
|
|
|
769
769
|
// src/referral/format.ts
|
|
@@ -6981,6 +6981,7 @@ var useDeposit = (options) => {
|
|
|
6981
6981
|
const [balance, setBalance] = React2.useState("0");
|
|
6982
6982
|
const [allowance, setAllowance] = React2.useState("0");
|
|
6983
6983
|
const balanceRef = React2.useRef("");
|
|
6984
|
+
const currentAddressRef = React2.useRef();
|
|
6984
6985
|
const { account: account9, state } = useAccount();
|
|
6985
6986
|
const { track: track2 } = useTrack();
|
|
6986
6987
|
const prevAddress = React2.useRef();
|
|
@@ -7319,6 +7320,7 @@ var useDeposit = (options) => {
|
|
|
7319
7320
|
if (balanceRef.current === "") {
|
|
7320
7321
|
setBalanceRevalidating(true);
|
|
7321
7322
|
}
|
|
7323
|
+
currentAddressRef.current = options.address;
|
|
7322
7324
|
getBalanceListener.current = setTimeout(async () => {
|
|
7323
7325
|
try {
|
|
7324
7326
|
const balance2 = await fetchBalanceHandler(
|
|
@@ -7329,9 +7331,11 @@ var useDeposit = (options) => {
|
|
|
7329
7331
|
balanceRef.current = balance2;
|
|
7330
7332
|
loopGetBalance();
|
|
7331
7333
|
} catch (err) {
|
|
7334
|
+
if (currentAddressRef.current !== options.address)
|
|
7335
|
+
return;
|
|
7332
7336
|
loopGetBalance(1e3);
|
|
7333
7337
|
} finally {
|
|
7334
|
-
if (balanceRef.current !== "") {
|
|
7338
|
+
if (balanceRef.current !== "" && currentAddressRef.current === options.address) {
|
|
7335
7339
|
setBalanceRevalidating(false);
|
|
7336
7340
|
}
|
|
7337
7341
|
}
|
|
@@ -7373,6 +7377,10 @@ var useDeposit = (options) => {
|
|
|
7373
7377
|
if (!options.address) {
|
|
7374
7378
|
return;
|
|
7375
7379
|
}
|
|
7380
|
+
currentAddressRef.current = options.address;
|
|
7381
|
+
setBalance("0");
|
|
7382
|
+
balanceRef.current = "";
|
|
7383
|
+
setBalanceRevalidating(false);
|
|
7376
7384
|
loopGetBalance(0);
|
|
7377
7385
|
return () => {
|
|
7378
7386
|
if (getBalanceListener.current) {
|
|
@@ -7404,8 +7412,8 @@ var useDeposit = (options) => {
|
|
|
7404
7412
|
};
|
|
7405
7413
|
};
|
|
7406
7414
|
function ignoreBalanceError(options) {
|
|
7407
|
-
const {
|
|
7408
|
-
return chainNamespace === types.ChainNamespace.solana &&
|
|
7415
|
+
const { chainNamespace, err } = options;
|
|
7416
|
+
return chainNamespace === types.ChainNamespace.solana && err?.name === "TokenAccountNotFoundError";
|
|
7409
7417
|
}
|
|
7410
7418
|
|
|
7411
7419
|
// src/orderly/useConvert.ts
|
|
@@ -10422,13 +10430,19 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
10422
10430
|
);
|
|
10423
10431
|
});
|
|
10424
10432
|
};
|
|
10425
|
-
const validate = () => {
|
|
10433
|
+
const validate = (otherErrors) => {
|
|
10426
10434
|
const orderCreator = getOrderCreator2();
|
|
10427
10435
|
return new Promise((resolve, reject) => {
|
|
10428
10436
|
return orderCreator.validate(
|
|
10429
10437
|
order,
|
|
10430
10438
|
valueConfig
|
|
10431
10439
|
).then((errors2) => {
|
|
10440
|
+
if (otherErrors) {
|
|
10441
|
+
errors2 = {
|
|
10442
|
+
...errors2,
|
|
10443
|
+
...otherErrors
|
|
10444
|
+
};
|
|
10445
|
+
}
|
|
10432
10446
|
if (errors2) {
|
|
10433
10447
|
const keys = Object.keys(errors2);
|
|
10434
10448
|
if (keys.length > 0) {
|
|
@@ -17862,11 +17876,12 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
17862
17876
|
const [doCreateOrder, { isMutating }] = useMutation(
|
|
17863
17877
|
getCreateOrderUrl(formattedOrder)
|
|
17864
17878
|
);
|
|
17865
|
-
const
|
|
17879
|
+
const maxQtyValue = useMaxQty(
|
|
17866
17880
|
symbol,
|
|
17867
17881
|
formattedOrder.side,
|
|
17868
17882
|
formattedOrder.reduce_only
|
|
17869
17883
|
);
|
|
17884
|
+
const maxQty = options.maxQty ?? maxQtyValue;
|
|
17870
17885
|
const updateOrderPrice = () => {
|
|
17871
17886
|
const order_type = formattedOrder.order_type;
|
|
17872
17887
|
const order_type_ext = formattedOrder.order_type_ext ?? lastOrderTypeExt.current;
|
|
@@ -18045,11 +18060,17 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18045
18060
|
const creator = getOrderCreator(order);
|
|
18046
18061
|
return validate(order, creator, prepareData());
|
|
18047
18062
|
}
|
|
18048
|
-
const validateOrder = () => {
|
|
18063
|
+
const validateOrder = (otherErrors) => {
|
|
18049
18064
|
return new Promise(
|
|
18050
18065
|
async (resolve, reject) => {
|
|
18051
18066
|
const creator = getOrderCreator(formattedOrder);
|
|
18052
|
-
|
|
18067
|
+
let errors = await validate(formattedOrder, creator, prepareData());
|
|
18068
|
+
if (otherErrors) {
|
|
18069
|
+
errors = {
|
|
18070
|
+
...errors,
|
|
18071
|
+
...otherErrors
|
|
18072
|
+
};
|
|
18073
|
+
}
|
|
18053
18074
|
const keys = Object.keys(errors);
|
|
18054
18075
|
if (keys.length > 0) {
|
|
18055
18076
|
setMeta(
|
|
@@ -18077,10 +18098,6 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18077
18098
|
if (!markPrice2 || !accountInfo || !symbolInfo) {
|
|
18078
18099
|
return null;
|
|
18079
18100
|
}
|
|
18080
|
-
const orderQuantity = Number(formattedOrder.order_quantity);
|
|
18081
|
-
if (orderQuantity === 0 || orderQuantity > maxQty) {
|
|
18082
|
-
return null;
|
|
18083
|
-
}
|
|
18084
18101
|
const estLiqPrice2 = calcEstLiqPrice(formattedOrder, askAndBid.current[0], {
|
|
18085
18102
|
markPrice: markPrice2,
|
|
18086
18103
|
totalCollateral,
|
|
@@ -18545,6 +18562,81 @@ var usePositionClose = (options) => {
|
|
|
18545
18562
|
};
|
|
18546
18563
|
};
|
|
18547
18564
|
|
|
18565
|
+
// src/next/tpsl/errorMsgCodes.ts
|
|
18566
|
+
var ERROR_MSG_CODES = {
|
|
18567
|
+
SL_PRICE_WARNING: 10001,
|
|
18568
|
+
// sl price warning
|
|
18569
|
+
SL_PRICE_ERROR: 10002
|
|
18570
|
+
// sl price error
|
|
18571
|
+
};
|
|
18572
|
+
|
|
18573
|
+
// src/next/tpsl/useTpslPriceChecker.ts
|
|
18574
|
+
var isEqual = (a, b) => {
|
|
18575
|
+
if (a === b)
|
|
18576
|
+
return true;
|
|
18577
|
+
if (a === null || b === null)
|
|
18578
|
+
return false;
|
|
18579
|
+
const aItem = a.sl_trigger_price;
|
|
18580
|
+
const bItem = b.sl_trigger_price;
|
|
18581
|
+
if (aItem === bItem)
|
|
18582
|
+
return true;
|
|
18583
|
+
if (aItem === void 0 || bItem === void 0)
|
|
18584
|
+
return false;
|
|
18585
|
+
return aItem.type === bItem.type && aItem.message === bItem.message;
|
|
18586
|
+
};
|
|
18587
|
+
var useTpslPriceChecker = (params) => {
|
|
18588
|
+
const { warning_threshold = 0.01, slPrice, liqPrice, side } = params;
|
|
18589
|
+
const prevResultRef = React2.useRef(null);
|
|
18590
|
+
const currentResult = React2.useMemo(() => {
|
|
18591
|
+
if (slPrice === void 0 || liqPrice === void 0 || side === void 0 || liqPrice === null) {
|
|
18592
|
+
return null;
|
|
18593
|
+
}
|
|
18594
|
+
let slPriceDecimal;
|
|
18595
|
+
let liqPriceDecimal;
|
|
18596
|
+
try {
|
|
18597
|
+
slPriceDecimal = new utils.Decimal(slPrice);
|
|
18598
|
+
liqPriceDecimal = new utils.Decimal(liqPrice);
|
|
18599
|
+
} catch (e) {
|
|
18600
|
+
return null;
|
|
18601
|
+
}
|
|
18602
|
+
const slPriceNum = slPriceDecimal.toNumber();
|
|
18603
|
+
const liqPriceNum = liqPriceDecimal.toNumber();
|
|
18604
|
+
if (Number.isNaN(slPriceNum) || Number.isNaN(liqPriceNum) || !Number.isFinite(slPriceNum) || !Number.isFinite(liqPriceNum) || liqPriceDecimal.isZero() || slPriceDecimal.isZero()) {
|
|
18605
|
+
return null;
|
|
18606
|
+
}
|
|
18607
|
+
const distance_ratio = side === types.OrderSide.BUY ? slPriceDecimal.minus(liqPriceDecimal).div(liqPriceDecimal) : liqPriceDecimal.minus(slPriceDecimal).div(liqPriceDecimal);
|
|
18608
|
+
if (distance_ratio.gt(warning_threshold)) {
|
|
18609
|
+
return null;
|
|
18610
|
+
}
|
|
18611
|
+
if (distance_ratio.gt(0) && distance_ratio.lte(warning_threshold)) {
|
|
18612
|
+
return {
|
|
18613
|
+
sl_trigger_price: {
|
|
18614
|
+
type: ERROR_MSG_CODES.SL_PRICE_WARNING,
|
|
18615
|
+
message: "Stop losses set near the liq. price may not trigger. Note: the liq. price can change with position notional."
|
|
18616
|
+
}
|
|
18617
|
+
};
|
|
18618
|
+
}
|
|
18619
|
+
return {
|
|
18620
|
+
sl_trigger_price: {
|
|
18621
|
+
type: ERROR_MSG_CODES.SL_PRICE_ERROR,
|
|
18622
|
+
message: "Stop loss crosses the liq. price. Please adjust your SL."
|
|
18623
|
+
}
|
|
18624
|
+
};
|
|
18625
|
+
}, [slPrice, liqPrice, side, warning_threshold]);
|
|
18626
|
+
if (isEqual(prevResultRef.current, currentResult)) {
|
|
18627
|
+
return prevResultRef.current;
|
|
18628
|
+
}
|
|
18629
|
+
prevResultRef.current = currentResult;
|
|
18630
|
+
return currentResult;
|
|
18631
|
+
};
|
|
18632
|
+
var useEstLiqPriceBySymbol = (symbol) => {
|
|
18633
|
+
const [data] = usePositionStream(symbol);
|
|
18634
|
+
const position = data?.rows?.find((row) => row.symbol === symbol);
|
|
18635
|
+
return React2.useMemo(() => {
|
|
18636
|
+
return position?.est_liq_price ?? void 0;
|
|
18637
|
+
}, [position]);
|
|
18638
|
+
};
|
|
18639
|
+
|
|
18548
18640
|
exports.swr = useSWR__namespace;
|
|
18549
18641
|
Object.defineProperty(exports, "unstable_serialize", {
|
|
18550
18642
|
enumerable: true,
|
|
@@ -18565,6 +18657,7 @@ Object.defineProperty(exports, "useConstant", {
|
|
|
18565
18657
|
exports.DefaultLayoutConfig = DefaultLayoutConfig;
|
|
18566
18658
|
exports.DistributionId = DistributionId;
|
|
18567
18659
|
exports.ENVType = ENVType2;
|
|
18660
|
+
exports.ERROR_MSG_CODES = ERROR_MSG_CODES;
|
|
18568
18661
|
exports.EpochStatus = EpochStatus;
|
|
18569
18662
|
exports.ExtendedConfigStore = ExtendedConfigStore;
|
|
18570
18663
|
exports.MaintenanceStatus = MaintenanceStatus;
|
|
@@ -18622,6 +18715,7 @@ exports.useDeposit = useDeposit;
|
|
|
18622
18715
|
exports.useDistribution = useDistribution;
|
|
18623
18716
|
exports.useDistributionHistory = useDistributionHistory;
|
|
18624
18717
|
exports.useEpochInfo = useEpochInfo;
|
|
18718
|
+
exports.useEstLiqPriceBySymbol = useEstLiqPriceBySymbol;
|
|
18625
18719
|
exports.useEventEmitter = useEventEmitter;
|
|
18626
18720
|
exports.useFeeState = useFeeState;
|
|
18627
18721
|
exports.useFundingDetails = useFundingDetails;
|
|
@@ -18719,6 +18813,7 @@ exports.useTestnetChainsStore = useTestnetChainsStore;
|
|
|
18719
18813
|
exports.useTickerStream = useTickerStream;
|
|
18720
18814
|
exports.useTokenInfo = useTokenInfo;
|
|
18721
18815
|
exports.useTokensInfo = useTokensInfo;
|
|
18816
|
+
exports.useTpslPriceChecker = useTpslPriceChecker;
|
|
18722
18817
|
exports.useTrack = useTrack;
|
|
18723
18818
|
exports.useTrackingInstance = useTrackingInstance;
|
|
18724
18819
|
exports.useTradingRewardsStatus = useTradingRewardsStatus;
|