@orderly.network/hooks 1.2.0 → 1.3.2
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/esm/configProvider.d.ts +7 -1
- package/esm/configProvider.d.ts.map +1 -1
- package/esm/configProvider.js +44 -18
- package/esm/configProvider.js.map +1 -0
- package/esm/dataProvider.js +24 -19
- package/esm/dataProvider.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -1
- package/esm/index.js.map +1 -0
- package/esm/middleware/signatureMiddleware.js +9 -8
- package/esm/middleware/signatureMiddleware.js.map +1 -0
- package/esm/orderly/orderbook.service.js +39 -28
- package/esm/orderly/orderbook.service.js.map +1 -0
- package/esm/orderly/orderlyHooks.d.ts +3 -0
- package/esm/orderly/orderlyHooks.d.ts.map +1 -1
- package/esm/orderly/orderlyHooks.js +2 -0
- package/esm/orderly/orderlyHooks.js.map +1 -0
- package/esm/orderly/useAccountInfo.js +3 -1
- package/esm/orderly/useAccountInfo.js.map +1 -0
- package/esm/orderly/useChain.js +16 -9
- package/esm/orderly/useChain.js.map +1 -0
- package/esm/orderly/useChains.d.ts +11 -12
- package/esm/orderly/useChains.d.ts.map +1 -1
- package/esm/orderly/useChains.js +68 -46
- package/esm/orderly/useChains.js.map +1 -0
- package/esm/orderly/useCollateral.d.ts +3 -4
- package/esm/orderly/useCollateral.d.ts.map +1 -1
- package/esm/orderly/useCollateral.js +53 -20
- package/esm/orderly/useCollateral.js.map +1 -0
- package/esm/orderly/useDeposit.js +123 -125
- package/esm/orderly/useDeposit.js.map +1 -0
- package/esm/orderly/useFundingRate.js +14 -13
- package/esm/orderly/useFundingRate.js.map +1 -0
- package/esm/orderly/useFundingRates.js +6 -4
- package/esm/orderly/useFundingRates.js.map +1 -0
- package/esm/orderly/useHoldingStream.js +19 -15
- package/esm/orderly/useHoldingStream.js.map +1 -0
- package/esm/orderly/useIndexPrice.js +7 -5
- package/esm/orderly/useIndexPrice.js.map +1 -0
- package/esm/orderly/useLeverage.js +9 -12
- package/esm/orderly/useLeverage.js.map +1 -0
- package/esm/orderly/useMarginRatio.js +27 -13
- package/esm/orderly/useMarginRatio.js.map +1 -0
- package/esm/orderly/useMarkPrice.js +13 -7
- package/esm/orderly/useMarkPrice.js.map +1 -0
- package/esm/orderly/useMarkPricesStream.d.ts +1 -1
- package/esm/orderly/useMarkPricesStream.d.ts.map +1 -1
- package/esm/orderly/useMarkPricesStream.js +9 -8
- package/esm/orderly/useMarkPricesStream.js.map +1 -0
- package/esm/orderly/useMarketTradeStream.js +33 -18
- package/esm/orderly/useMarketTradeStream.js.map +1 -0
- package/esm/orderly/useMarkets.js +144 -81
- package/esm/orderly/useMarkets.js.map +1 -0
- package/esm/orderly/useMarketsStream.js +23 -28
- package/esm/orderly/useMarketsStream.js.map +1 -0
- package/esm/orderly/useMaxQty.d.ts +6 -0
- package/esm/orderly/useMaxQty.d.ts.map +1 -1
- package/esm/orderly/useMaxQty.js +26 -18
- package/esm/orderly/useMaxQty.js.map +1 -0
- package/esm/orderly/useOpenInterest.js +7 -5
- package/esm/orderly/useOpenInterest.js.map +1 -0
- package/esm/orderly/useOrderEntry.js +182 -160
- package/esm/orderly/useOrderEntry.js.map +1 -0
- package/esm/orderly/useOrderStream.js +85 -66
- package/esm/orderly/useOrderStream.js.map +1 -0
- package/esm/orderly/useOrderbookStream.d.ts +2 -3
- package/esm/orderly/useOrderbookStream.d.ts.map +1 -1
- package/esm/orderly/useOrderbookStream.js +173 -103
- package/esm/orderly/useOrderbookStream.js.map +1 -0
- package/esm/orderly/usePositionStream.js +82 -62
- package/esm/orderly/usePositionStream.js.map +1 -0
- package/esm/orderly/usePrivateDataObserver.js +55 -48
- package/esm/orderly/usePrivateDataObserver.js.map +1 -0
- package/esm/orderly/useSettleSubscription.js +8 -6
- package/esm/orderly/useSettleSubscription.js.map +1 -0
- package/esm/orderly/useSymbolPriceRange.js +14 -8
- package/esm/orderly/useSymbolPriceRange.js.map +1 -0
- package/esm/orderly/useSymbolsInfo.js +7 -5
- package/esm/orderly/useSymbolsInfo.js.map +1 -0
- package/esm/orderly/useTickerStream.d.ts +5 -1
- package/esm/orderly/useTickerStream.d.ts.map +1 -1
- package/esm/orderly/useTickerStream.js +26 -29
- package/esm/orderly/useTickerStream.js.map +1 -0
- package/esm/orderly/useWalletSubscription.js +8 -6
- package/esm/orderly/useWalletSubscription.js.map +1 -0
- package/esm/orderly/useWithdraw.js +19 -11
- package/esm/orderly/useWithdraw.js.map +1 -0
- package/esm/orderlyContext.d.ts +8 -1
- package/esm/orderlyContext.d.ts.map +1 -1
- package/esm/orderlyContext.js +2 -1
- package/esm/orderlyContext.js.map +1 -0
- package/esm/services/dataCenter.js +10 -8
- package/esm/services/dataCenter.js.map +1 -0
- package/esm/services/painter/backgroundPaint.js +11 -14
- package/esm/services/painter/backgroundPaint.js.map +1 -0
- package/esm/services/painter/basePaint.js +5 -1
- package/esm/services/painter/basePaint.js.map +1 -0
- package/esm/services/painter/dataPaint.js +53 -50
- package/esm/services/painter/dataPaint.js.map +1 -0
- package/esm/services/painter/layout.config.js +15 -13
- package/esm/services/painter/layout.config.js.map +1 -0
- package/esm/services/painter/painter.js +14 -13
- package/esm/services/painter/painter.js.map +1 -0
- package/esm/services/painter/resource.js +6 -4
- package/esm/services/painter/resource.js.map +1 -0
- package/esm/statusProvider.js +10 -3
- package/esm/statusProvider.js.map +1 -0
- package/esm/unuse/apiPrefixMiddleware.js +18 -16
- package/esm/unuse/apiPrefixMiddleware.js.map +1 -0
- package/esm/unuse/fn.js +3 -1
- package/esm/unuse/fn.js.map +1 -0
- package/esm/unuse/useBalance.js +6 -4
- package/esm/unuse/useBalance.js.map +1 -0
- package/esm/unuse/useFetures.js +26 -18
- package/esm/unuse/useFetures.js.map +1 -0
- package/esm/unuse/useRunOnce.js +10 -7
- package/esm/unuse/useRunOnce.js.map +1 -0
- package/esm/unuse/useSyncEnd.js +5 -4
- package/esm/unuse/useSyncEnd.js.map +1 -0
- package/esm/unuse/useTokenInfo.js +7 -5
- package/esm/unuse/useTokenInfo.js.map +1 -0
- package/esm/unuse/useUnsettlementPnL.js +7 -3
- package/esm/unuse/useUnsettlementPnL.js.map +1 -0
- package/esm/useAccount.js +18 -21
- package/esm/useAccount.js.map +1 -0
- package/esm/useAccountInstance.js +6 -7
- package/esm/useAccountInstance.js.map +1 -0
- package/esm/useBoolean.js +14 -5
- package/esm/useBoolean.js.map +1 -0
- package/esm/useConfig.js +3 -1
- package/esm/useConfig.js.map +1 -0
- package/esm/useEventEmitter.js +4 -2
- package/esm/useEventEmitter.js.map +1 -0
- package/esm/useLazyQuery.js +6 -7
- package/esm/useLazyQuery.js.map +1 -0
- package/esm/useLocalStorage.js +30 -20
- package/esm/useLocalStorage.js.map +1 -0
- package/esm/useMediaQuery.js +11 -9
- package/esm/useMediaQuery.js.map +1 -0
- package/esm/useMutation.js +26 -37
- package/esm/useMutation.js.map +1 -0
- package/esm/useObserve.js +4 -4
- package/esm/useObserve.js.map +1 -0
- package/esm/useParamsCheck.js +8 -10
- package/esm/useParamsCheck.js.map +1 -0
- package/esm/usePoster.js +56 -45
- package/esm/usePoster.js.map +1 -0
- package/esm/usePreloadData.js +9 -5
- package/esm/usePreloadData.js.map +1 -0
- package/esm/usePrivateInfiniteQuery.js +15 -9
- package/esm/usePrivateInfiniteQuery.js.map +1 -0
- package/esm/usePrivateQuery.js +15 -8
- package/esm/usePrivateQuery.js.map +1 -0
- package/esm/useQuery.js +6 -5
- package/esm/useQuery.js.map +1 -0
- package/esm/useSessionStorage.js +28 -19
- package/esm/useSessionStorage.js.map +1 -0
- package/esm/useWS.js +15 -13
- package/esm/useWS.js.map +1 -0
- package/esm/useWsStatus.js +12 -12
- package/esm/useWsStatus.js.map +1 -0
- package/esm/utils/createGetter.js +8 -8
- package/esm/utils/createGetter.js.map +1 -0
- package/esm/utils/createOrder.d.ts +1 -0
- package/esm/utils/createOrder.d.ts.map +1 -1
- package/esm/utils/createOrder.js +59 -43
- package/esm/utils/createOrder.js.map +1 -0
- package/esm/utils/dev.js +6 -4
- package/esm/utils/dev.js.map +1 -0
- package/esm/utils/fetcher.js +3 -1
- package/esm/utils/fetcher.js.map +1 -0
- package/esm/utils/json.js +3 -2
- package/esm/utils/json.js.map +1 -0
- package/esm/utils/orderEntryHelper.js +92 -63
- package/esm/utils/orderEntryHelper.js.map +1 -0
- package/esm/utils/parseHolding.js +10 -6
- package/esm/utils/parseHolding.js.map +1 -0
- package/esm/utils/swr.js +114 -104
- package/esm/utils/swr.js.map +1 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +4 -3
- package/esm/version.js.map +1 -0
- package/esm/walletConnectorContext.js +4 -2
- package/esm/walletConnectorContext.js.map +1 -0
- package/lib/configProvider.d.ts +7 -1
- package/lib/configProvider.d.ts.map +1 -1
- package/lib/configProvider.js +108 -56
- package/lib/configProvider.js.map +1 -0
- package/lib/dataProvider.js +50 -29
- package/lib/dataProvider.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +191 -88
- package/lib/index.js.map +1 -0
- package/lib/middleware/signatureMiddleware.js +22 -15
- package/lib/middleware/signatureMiddleware.js.map +1 -0
- package/lib/orderly/orderbook.service.js +59 -33
- package/lib/orderly/orderbook.service.js.map +1 -0
- package/lib/orderly/orderlyHooks.d.ts +3 -0
- package/lib/orderly/orderlyHooks.d.ts.map +1 -1
- package/lib/orderly/orderlyHooks.js +124 -57
- package/lib/orderly/orderlyHooks.js.map +1 -0
- package/lib/orderly/useAccountInfo.js +14 -6
- package/lib/orderly/useAccountInfo.js.map +1 -0
- package/lib/orderly/useChain.js +30 -17
- package/lib/orderly/useChain.js.map +1 -0
- package/lib/orderly/useChains.d.ts +11 -12
- package/lib/orderly/useChains.d.ts.map +1 -1
- package/lib/orderly/useChains.js +100 -59
- package/lib/orderly/useChains.js.map +1 -0
- package/lib/orderly/useCollateral.d.ts +3 -4
- package/lib/orderly/useCollateral.d.ts.map +1 -1
- package/lib/orderly/useCollateral.js +81 -42
- package/lib/orderly/useCollateral.js.map +1 -0
- package/lib/orderly/useDeposit.js +154 -150
- package/lib/orderly/useDeposit.js.map +1 -0
- package/lib/orderly/useFundingRate.js +29 -22
- package/lib/orderly/useFundingRate.js.map +1 -0
- package/lib/orderly/useFundingRates.js +19 -11
- package/lib/orderly/useFundingRates.js.map +1 -0
- package/lib/orderly/useHoldingStream.js +39 -27
- package/lib/orderly/useHoldingStream.js.map +1 -0
- package/lib/orderly/useIndexPrice.js +24 -14
- package/lib/orderly/useIndexPrice.js.map +1 -0
- package/lib/orderly/useLeverage.js +27 -24
- package/lib/orderly/useLeverage.js.map +1 -0
- package/lib/orderly/useMarginRatio.js +49 -29
- package/lib/orderly/useMarginRatio.js.map +1 -0
- package/lib/orderly/useMarkPrice.js +26 -15
- package/lib/orderly/useMarkPrice.js.map +1 -0
- package/lib/orderly/useMarkPricesStream.d.ts +1 -1
- package/lib/orderly/useMarkPricesStream.d.ts.map +1 -1
- package/lib/orderly/useMarkPricesStream.js +26 -17
- package/lib/orderly/useMarkPricesStream.js.map +1 -0
- package/lib/orderly/useMarketTradeStream.js +47 -26
- package/lib/orderly/useMarketTradeStream.js.map +1 -0
- package/lib/orderly/useMarkets.js +172 -95
- package/lib/orderly/useMarkets.js.map +1 -0
- package/lib/orderly/useMarketsStream.js +44 -41
- package/lib/orderly/useMarketsStream.js.map +1 -0
- package/lib/orderly/useMaxQty.d.ts +6 -0
- package/lib/orderly/useMaxQty.d.ts.map +1 -1
- package/lib/orderly/useMaxQty.js +52 -43
- package/lib/orderly/useMaxQty.js.map +1 -0
- package/lib/orderly/useOpenInterest.js +24 -14
- package/lib/orderly/useOpenInterest.js.map +1 -0
- package/lib/orderly/useOrderEntry.js +238 -210
- package/lib/orderly/useOrderEntry.js.map +1 -0
- package/lib/orderly/useOrderStream.js +111 -84
- package/lib/orderly/useOrderStream.js.map +1 -0
- package/lib/orderly/useOrderbookStream.d.ts +2 -3
- package/lib/orderly/useOrderbookStream.d.ts.map +1 -1
- package/lib/orderly/useOrderbookStream.js +227 -148
- package/lib/orderly/useOrderbookStream.js.map +1 -0
- package/lib/orderly/usePositionStream.js +134 -100
- package/lib/orderly/usePositionStream.js.map +1 -0
- package/lib/orderly/usePrivateDataObserver.js +76 -63
- package/lib/orderly/usePrivateDataObserver.js.map +1 -0
- package/lib/orderly/useSettleSubscription.js +25 -15
- package/lib/orderly/useSettleSubscription.js.map +1 -0
- package/lib/orderly/useSymbolPriceRange.js +29 -23
- package/lib/orderly/useSymbolPriceRange.js.map +1 -0
- package/lib/orderly/useSymbolsInfo.js +23 -15
- package/lib/orderly/useSymbolsInfo.js.map +1 -0
- package/lib/orderly/useTickerStream.d.ts +5 -1
- package/lib/orderly/useTickerStream.d.ts.map +1 -1
- package/lib/orderly/useTickerStream.js +51 -48
- package/lib/orderly/useTickerStream.js.map +1 -0
- package/lib/orderly/useWalletSubscription.js +25 -15
- package/lib/orderly/useWalletSubscription.js.map +1 -0
- package/lib/orderly/useWithdraw.js +36 -22
- package/lib/orderly/useWithdraw.js.map +1 -0
- package/lib/orderlyContext.d.ts +8 -1
- package/lib/orderlyContext.d.ts.map +1 -1
- package/lib/orderlyContext.js +22 -6
- package/lib/orderlyContext.js.map +1 -0
- package/lib/services/dataCenter.js +15 -11
- package/lib/services/dataCenter.js.map +1 -0
- package/lib/services/painter/backgroundPaint.js +21 -18
- package/lib/services/painter/backgroundPaint.js.map +1 -0
- package/lib/services/painter/basePaint.js +14 -4
- package/lib/services/painter/basePaint.js.map +1 -0
- package/lib/services/painter/dataPaint.js +67 -58
- package/lib/services/painter/dataPaint.js.map +1 -0
- package/lib/services/painter/layout.config.js +25 -16
- package/lib/services/painter/layout.config.js.map +1 -0
- package/lib/services/painter/painter.js +27 -20
- package/lib/services/painter/painter.js.map +1 -0
- package/lib/services/painter/resource.js +15 -7
- package/lib/services/painter/resource.js.map +1 -0
- package/lib/statusProvider.js +31 -10
- package/lib/statusProvider.js.map +1 -0
- package/lib/unuse/apiPrefixMiddleware.js +30 -22
- package/lib/unuse/apiPrefixMiddleware.js.map +1 -0
- package/lib/unuse/fn.js +14 -5
- package/lib/unuse/fn.js.map +1 -0
- package/lib/unuse/useBalance.js +23 -13
- package/lib/unuse/useBalance.js.map +1 -0
- package/lib/unuse/useFetures.js +41 -28
- package/lib/unuse/useFetures.js.map +1 -0
- package/lib/unuse/useRunOnce.js +61 -11
- package/lib/unuse/useRunOnce.js.map +1 -0
- package/lib/unuse/useSyncEnd.js +17 -10
- package/lib/unuse/useSyncEnd.js.map +1 -0
- package/lib/unuse/useTokenInfo.js +20 -12
- package/lib/unuse/useTokenInfo.js.map +1 -0
- package/lib/unuse/useUnsettlementPnL.js +21 -11
- package/lib/unuse/useUnsettlementPnL.js.map +1 -0
- package/lib/useAccount.js +32 -29
- package/lib/useAccount.js.map +1 -0
- package/lib/useAccountInstance.js +27 -20
- package/lib/useAccountInstance.js.map +1 -0
- package/lib/useBoolean.js +25 -10
- package/lib/useBoolean.js.map +1 -0
- package/lib/useConfig.js +15 -7
- package/lib/useConfig.js.map +1 -0
- package/lib/useEventEmitter.js +23 -13
- package/lib/useEventEmitter.js.map +1 -0
- package/lib/useLazyQuery.js +25 -23
- package/lib/useLazyQuery.js.map +1 -0
- package/lib/useLocalStorage.js +44 -28
- package/lib/useLocalStorage.js.map +1 -0
- package/lib/useMediaQuery.js +22 -14
- package/lib/useMediaQuery.js.map +1 -0
- package/lib/useMutation.js +47 -52
- package/lib/useMutation.js.map +1 -0
- package/lib/useObserve.js +22 -8
- package/lib/useObserve.js.map +1 -0
- package/lib/useParamsCheck.js +18 -14
- package/lib/useParamsCheck.js.map +1 -0
- package/lib/usePoster.js +80 -74
- package/lib/usePoster.js.map +1 -0
- package/lib/usePreloadData.js +21 -11
- package/lib/usePreloadData.js.map +1 -0
- package/lib/usePrivateInfiniteQuery.js +36 -22
- package/lib/usePrivateInfiniteQuery.js.map +1 -0
- package/lib/usePrivateQuery.js +35 -25
- package/lib/usePrivateQuery.js.map +1 -0
- package/lib/useQuery.js +24 -20
- package/lib/useQuery.js.map +1 -0
- package/lib/useSessionStorage.js +41 -26
- package/lib/useSessionStorage.js.map +1 -0
- package/lib/useWS.js +42 -32
- package/lib/useWS.js.map +1 -0
- package/lib/useWsStatus.js +34 -20
- package/lib/useWsStatus.js.map +1 -0
- package/lib/utils/createGetter.js +19 -14
- package/lib/utils/createGetter.js.map +1 -0
- package/lib/utils/createOrder.d.ts +1 -0
- package/lib/utils/createOrder.d.ts.map +1 -1
- package/lib/utils/createOrder.js +133 -82
- package/lib/utils/createOrder.js.map +1 -0
- package/lib/utils/dev.js +13 -9
- package/lib/utils/dev.js.map +1 -0
- package/lib/utils/fetcher.js +13 -5
- package/lib/utils/fetcher.js.map +1 -0
- package/lib/utils/json.js +12 -5
- package/lib/utils/json.js.map +1 -0
- package/lib/utils/orderEntryHelper.js +125 -82
- package/lib/utils/orderEntryHelper.js.map +1 -0
- package/lib/utils/parseHolding.js +19 -9
- package/lib/utils/parseHolding.js.map +1 -0
- package/lib/utils/swr.js +134 -111
- package/lib/utils/swr.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +13 -4
- package/lib/version.js.map +1 -0
- package/lib/walletConnectorContext.js +23 -7
- package/lib/walletConnectorContext.js.map +1 -0
- package/package.json +17 -9
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { OrderSide, OrderType, SDKError
|
|
2
|
+
import { OrderSide, OrderType, SDKError } from "@orderly.network/types";
|
|
3
3
|
import { useSymbolsInfo } from "./useSymbolsInfo";
|
|
4
4
|
import { Decimal, getPrecisionByNumber } from "@orderly.network/utils";
|
|
5
5
|
import { useMutation } from "../useMutation";
|
|
6
6
|
import { compose, head, includes, omit, pick } from "ramda";
|
|
7
|
-
import { baseInputHandle, getCalculateHandler, orderEntityFormatHandle
|
|
7
|
+
import { baseInputHandle, getCalculateHandler, orderEntityFormatHandle } from "../utils/orderEntryHelper";
|
|
8
8
|
import { useCollateral } from "./useCollateral";
|
|
9
9
|
import { useMaxQty } from "./useMaxQty";
|
|
10
10
|
import { OrderFactory, availableOrderTypes } from "../utils/createOrder";
|
|
@@ -37,25 +37,29 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
37
37
|
const fieldDirty = useRef({});
|
|
38
38
|
const submitted = useRef(false);
|
|
39
39
|
const askAndBid = useRef([]); // 0: ask0, 1: bid0
|
|
40
|
-
const onOrderbookUpdate = useDebouncedCallback((data)
|
|
40
|
+
const onOrderbookUpdate = useDebouncedCallback((data)=>{
|
|
41
41
|
askAndBid.current = data;
|
|
42
42
|
}, 200);
|
|
43
43
|
const { freeCollateral, totalCollateral, positions, accountInfo } = useCollateral();
|
|
44
44
|
const symbolInfo = useSymbolsInfo();
|
|
45
45
|
// const tokenInfo = useTokenInfo();
|
|
46
|
-
const symbol = useMemo(()
|
|
46
|
+
const symbol = useMemo(()=>{
|
|
47
47
|
if (typeof symbolOrOrder === "string") {
|
|
48
48
|
return symbolOrOrder;
|
|
49
49
|
}
|
|
50
50
|
return symbolOrOrder.symbol;
|
|
51
|
-
}, [
|
|
52
|
-
|
|
51
|
+
}, [
|
|
52
|
+
symbolOrOrder
|
|
53
|
+
]);
|
|
54
|
+
const optionsValue = useMemo(()=>{
|
|
53
55
|
if (typeof sideOrOptions === "object") {
|
|
54
56
|
return sideOrOptions;
|
|
55
57
|
}
|
|
56
58
|
return options;
|
|
57
|
-
}, [
|
|
58
|
-
|
|
59
|
+
}, [
|
|
60
|
+
sideOrOptions
|
|
61
|
+
]);
|
|
62
|
+
const isReduceOnly = useMemo(()=>{
|
|
59
63
|
if (typeof reduceOnly === "boolean") {
|
|
60
64
|
return reduceOnly;
|
|
61
65
|
}
|
|
@@ -63,35 +67,46 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
63
67
|
return !!symbolOrOrder.reduce_only;
|
|
64
68
|
}
|
|
65
69
|
return false;
|
|
66
|
-
}, [
|
|
67
|
-
|
|
70
|
+
}, [
|
|
71
|
+
symbolOrOrder,
|
|
72
|
+
reduceOnly
|
|
73
|
+
]);
|
|
74
|
+
const sideValue = useMemo(()=>{
|
|
68
75
|
if (typeof symbolOrOrder === "object") {
|
|
69
76
|
return symbolOrOrder.side;
|
|
70
77
|
}
|
|
71
78
|
// if (typeof sideOrOptions === "string") {
|
|
72
79
|
return sideOrOptions;
|
|
73
|
-
|
|
74
|
-
}, [
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
// }
|
|
81
|
+
}, [
|
|
82
|
+
symbolOrOrder,
|
|
83
|
+
sideOrOptions
|
|
84
|
+
]);
|
|
85
|
+
const baseDP = useMemo(()=>getPrecisionByNumber(symbolInfo[symbol]("base_tick", 0)), [
|
|
86
|
+
symbolInfo
|
|
87
|
+
]);
|
|
88
|
+
const quoteDP = useMemo(()=>{
|
|
77
89
|
return getPrecisionByNumber(symbolInfo[symbol]("quote_tick", 0));
|
|
78
|
-
}, [
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
}, [
|
|
91
|
+
symbolInfo
|
|
92
|
+
]);
|
|
93
|
+
const baseIMR = useMemo(()=>symbolInfo[symbol]("base_imr", 0), [
|
|
94
|
+
symbolInfo
|
|
95
|
+
]);
|
|
96
|
+
const baseMMR = useMemo(()=>symbolInfo[symbol]("base_mmr", 0), [
|
|
97
|
+
symbolInfo
|
|
98
|
+
]);
|
|
81
99
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
82
100
|
// const markPrice = 1;
|
|
83
|
-
const diffOrderEntry = (prev, current)
|
|
84
|
-
if (!prev)
|
|
85
|
-
return null;
|
|
101
|
+
const diffOrderEntry = (prev, current)=>{
|
|
102
|
+
if (!prev) return null;
|
|
86
103
|
let key, value, preValue;
|
|
87
104
|
const keys = Object.keys(current);
|
|
88
|
-
for
|
|
105
|
+
for(let i = 0; i < keys.length; i++){
|
|
89
106
|
const k = keys[i];
|
|
90
107
|
let preveValue = prev[k];
|
|
91
108
|
let currentValue = current[k];
|
|
92
|
-
if (typeof preveValue === "undefined" &&
|
|
93
|
-
typeof currentValue === "undefined")
|
|
94
|
-
continue;
|
|
109
|
+
if (typeof preveValue === "undefined" && typeof currentValue === "undefined") continue;
|
|
95
110
|
// if (k === "order_quantity") {
|
|
96
111
|
// preveValue = Number(preveValue);
|
|
97
112
|
// currentValue = Number(currentValue);
|
|
@@ -103,14 +118,16 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
103
118
|
break;
|
|
104
119
|
}
|
|
105
120
|
}
|
|
106
|
-
if (!key)
|
|
107
|
-
|
|
108
|
-
|
|
121
|
+
if (!key) return null;
|
|
122
|
+
return {
|
|
123
|
+
key,
|
|
124
|
+
value,
|
|
125
|
+
preValue
|
|
126
|
+
};
|
|
109
127
|
};
|
|
110
128
|
const maxQty = useMaxQty(symbol, sideValue, isReduceOnly);
|
|
111
|
-
const parseString2Number = (order, key)
|
|
112
|
-
if (typeof order[key] !== "string")
|
|
113
|
-
return;
|
|
129
|
+
const parseString2Number = (order, key, dp)=>{
|
|
130
|
+
if (typeof order[key] !== "string") return;
|
|
114
131
|
// fix: delete the comma then remove the forward one of the string
|
|
115
132
|
// first find the difference between current value and previous value
|
|
116
133
|
if (order[key] && order[key].startsWith(".")) {
|
|
@@ -118,9 +135,18 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
118
135
|
}
|
|
119
136
|
// order[`${key}_origin`] = order[key];
|
|
120
137
|
order[key] = order[key].replace(/,/g, "");
|
|
138
|
+
// format input by decimal precision
|
|
139
|
+
if (dp && order[key].length > 0) {
|
|
140
|
+
const hasPoint = `${order[key]}`.includes(".");
|
|
141
|
+
const endOfPoint = `${order[key]}`.endsWith(".");
|
|
142
|
+
const decimalPart = `${order[key]}`.split(".");
|
|
143
|
+
if (hasPoint && !endOfPoint) {
|
|
144
|
+
order[key] = `${decimalPart[0]}.${decimalPart[1].slice(0, quoteDP)}`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
121
147
|
};
|
|
122
148
|
// just for performance optimization
|
|
123
|
-
const needParse = useMemo(()
|
|
149
|
+
const needParse = useMemo(()=>{
|
|
124
150
|
if (typeof symbolOrOrder === "string") {
|
|
125
151
|
return null;
|
|
126
152
|
}
|
|
@@ -134,32 +160,30 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
134
160
|
"symbol",
|
|
135
161
|
"total",
|
|
136
162
|
"reduce_only",
|
|
137
|
-
"trigger_price"
|
|
138
|
-
])(
|
|
139
|
-
//@ts-ignore
|
|
163
|
+
"trigger_price"
|
|
164
|
+
])(//@ts-ignore
|
|
140
165
|
symbolOrOrder);
|
|
141
|
-
}, [
|
|
142
|
-
|
|
166
|
+
}, [
|
|
167
|
+
symbolOrOrder
|
|
168
|
+
]);
|
|
169
|
+
const parsedData = useMemo(()=>{
|
|
143
170
|
if (typeof symbolOrOrder === "string") {
|
|
144
171
|
return null;
|
|
145
172
|
}
|
|
146
173
|
// clean comma
|
|
147
174
|
if (typeof symbolOrOrder.order_quantity === "string") {
|
|
148
175
|
parseString2Number(symbolOrOrder, "order_quantity");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
symbolOrOrder.order_quantity = new Decimal(symbolOrOrder.order_quantity)
|
|
152
|
-
.toDecimalPlaces(baseDP)
|
|
153
|
-
.toString();
|
|
176
|
+
} else if (typeof symbolOrOrder.order_quantity === "number") {
|
|
177
|
+
symbolOrOrder.order_quantity = new Decimal(symbolOrOrder.order_quantity).toDecimalPlaces(baseDP).toString();
|
|
154
178
|
}
|
|
155
179
|
if (typeof symbolOrOrder.order_price === "string") {
|
|
156
|
-
parseString2Number(symbolOrOrder, "order_price");
|
|
180
|
+
parseString2Number(symbolOrOrder, "order_price", quoteDP);
|
|
157
181
|
}
|
|
158
182
|
if (typeof symbolOrOrder.total === "string") {
|
|
159
|
-
parseString2Number(symbolOrOrder, "total");
|
|
183
|
+
parseString2Number(symbolOrOrder, "total", quoteDP);
|
|
160
184
|
}
|
|
161
185
|
if (typeof symbolOrOrder.trigger_price === "string") {
|
|
162
|
-
parseString2Number(symbolOrOrder, "trigger_price");
|
|
186
|
+
parseString2Number(symbolOrOrder, "trigger_price", quoteDP);
|
|
163
187
|
}
|
|
164
188
|
// if (typeof symbolOrOrder.trigger_price === "string") {
|
|
165
189
|
// symbolOrOrder.trigger_price = symbolOrOrder.trigger_price.replace(
|
|
@@ -179,72 +203,67 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
179
203
|
needParse?.reduce_only,
|
|
180
204
|
needParse?.side,
|
|
181
205
|
needParse?.visible_quantity,
|
|
206
|
+
quoteDP,
|
|
207
|
+
baseDP
|
|
182
208
|
]);
|
|
183
|
-
const isStopOrder = parsedData?.order_type === OrderType.STOP_LIMIT ||
|
|
184
|
-
parsedData?.order_type === OrderType.STOP_MARKET;
|
|
209
|
+
const isStopOrder = parsedData?.order_type === OrderType.STOP_LIMIT || parsedData?.order_type === OrderType.STOP_MARKET;
|
|
185
210
|
const [doCreateOrder, { isMutating }] = useMutation(isStopOrder ? "/v1/algo/order" : "/v1/order");
|
|
186
211
|
// const maxQty = 3;
|
|
187
|
-
const createOrder = (values)
|
|
212
|
+
const createOrder = (values)=>{
|
|
188
213
|
if (!values.symbol) {
|
|
189
214
|
throw new SDKError("symbol is error");
|
|
190
215
|
}
|
|
191
216
|
if (!values.side) {
|
|
192
217
|
throw new SDKError("side is error");
|
|
193
218
|
}
|
|
194
|
-
if (!values ||
|
|
195
|
-
typeof values.order_type === "undefined" ||
|
|
196
|
-
!includes(values.order_type, availableOrderTypes)) {
|
|
219
|
+
if (!values || typeof values.order_type === "undefined" || !includes(values.order_type, availableOrderTypes)) {
|
|
197
220
|
throw new SDKError("order_type is error");
|
|
198
221
|
}
|
|
199
222
|
const orderCreator = OrderFactory.create(values.order_type_ext ? values.order_type_ext : values.order_type);
|
|
200
223
|
if (!orderCreator) {
|
|
201
224
|
return Promise.reject(new SDKError("orderCreator is null"));
|
|
202
225
|
}
|
|
203
|
-
return new Promise((resolve, reject)
|
|
204
|
-
return orderCreator
|
|
205
|
-
.validate(values, {
|
|
226
|
+
return new Promise((resolve, reject)=>{
|
|
227
|
+
return orderCreator.validate(values, {
|
|
206
228
|
symbol: symbolInfo[symbol](),
|
|
207
229
|
// token: tokenInfo[symbol](),
|
|
208
230
|
maxQty,
|
|
209
|
-
markPrice: markPrice
|
|
210
|
-
})
|
|
211
|
-
.then((errors) => {
|
|
231
|
+
markPrice: markPrice
|
|
232
|
+
}).then((errors)=>{
|
|
212
233
|
submitted.current = true;
|
|
213
|
-
if (errors.order_price ||
|
|
214
|
-
errors.order_quantity ||
|
|
215
|
-
errors.trigger_price) {
|
|
234
|
+
if (errors.order_price || errors.order_quantity || errors.trigger_price || errors.total) {
|
|
216
235
|
setErrors(errors);
|
|
217
236
|
reject(errors.order_price?.message || errors.order_quantity?.message);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
237
|
+
// throw new SDKError(
|
|
238
|
+
// errors.order_price?.message ||
|
|
239
|
+
// errors.order_quantity?.message ||
|
|
240
|
+
// "order validation error"
|
|
241
|
+
// );
|
|
242
|
+
} else {
|
|
225
243
|
const data = orderCreator.create(values, {
|
|
226
244
|
symbol: symbolInfo[symbol](),
|
|
227
245
|
maxQty,
|
|
228
|
-
markPrice: markPrice
|
|
246
|
+
markPrice: markPrice
|
|
229
247
|
});
|
|
230
248
|
// console.log("------------------", values, data);
|
|
231
|
-
return doCreateOrder(omit([
|
|
249
|
+
return doCreateOrder(omit([
|
|
250
|
+
"order_type_ext"
|
|
251
|
+
], {
|
|
232
252
|
// ...values,
|
|
233
253
|
// ...omit(["order_price"], values),
|
|
234
|
-
...data
|
|
235
|
-
})).then((res)
|
|
254
|
+
...data
|
|
255
|
+
})).then((res)=>{
|
|
236
256
|
// resolve(res);
|
|
237
257
|
if (res.success) {
|
|
238
258
|
// TODO: remove when the WS service is fixed
|
|
239
259
|
if (Array.isArray(res.data.rows)) {
|
|
240
260
|
ee.emit("algoOrder:cache", {
|
|
241
261
|
...res.data.rows[0],
|
|
242
|
-
trigger_price: data.trigger_price
|
|
262
|
+
trigger_price: data.trigger_price
|
|
243
263
|
});
|
|
244
264
|
}
|
|
245
265
|
resolve(res.data);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
266
|
+
} else {
|
|
248
267
|
reject(res);
|
|
249
268
|
}
|
|
250
269
|
}, reject);
|
|
@@ -253,41 +272,53 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
253
272
|
});
|
|
254
273
|
};
|
|
255
274
|
/**
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const onSubmit = (values) => {
|
|
275
|
+
* submit form,validate values
|
|
276
|
+
* @param values
|
|
277
|
+
* @returns
|
|
278
|
+
*/ const onSubmit = (values)=>{
|
|
261
279
|
if (typeof reduceOnly === "boolean" && reduceOnly && !values.reduce_only) {
|
|
262
280
|
return Promise.reject(new SDKError("The reduceOny parameter of hook does not match your order data"));
|
|
263
281
|
}
|
|
264
282
|
return createOrder({
|
|
265
283
|
...values,
|
|
266
|
-
symbol
|
|
284
|
+
symbol
|
|
267
285
|
});
|
|
268
286
|
};
|
|
269
|
-
const submit = useCallback(()
|
|
287
|
+
const submit = useCallback(()=>{
|
|
270
288
|
if (!parsedData) {
|
|
271
289
|
throw new SDKError("Function is not supported, please use onSubmit()");
|
|
272
290
|
}
|
|
273
291
|
return createOrder(parsedData);
|
|
274
|
-
}, [
|
|
275
|
-
|
|
292
|
+
}, [
|
|
293
|
+
parsedData
|
|
294
|
+
]);
|
|
295
|
+
const calculate = useCallback((values, field, value)=>{
|
|
276
296
|
const fieldHandler = getCalculateHandler(field);
|
|
277
|
-
const newValues = compose(head, orderEntityFormatHandle(baseDP, quoteDP), fieldHandler, baseInputHandle)([
|
|
297
|
+
const newValues = compose(head, orderEntityFormatHandle(baseDP, quoteDP), fieldHandler, baseInputHandle)([
|
|
298
|
+
values,
|
|
299
|
+
field,
|
|
300
|
+
value,
|
|
301
|
+
markPrice,
|
|
302
|
+
{
|
|
303
|
+
baseDP,
|
|
304
|
+
quoteDP
|
|
305
|
+
}
|
|
306
|
+
]);
|
|
278
307
|
return newValues;
|
|
279
|
-
}, [
|
|
308
|
+
}, [
|
|
309
|
+
markPrice
|
|
310
|
+
]);
|
|
280
311
|
// const estLiqPrice = useMemo(() => {}, []);
|
|
281
|
-
const validator = (values)
|
|
312
|
+
const validator = (values)=>{
|
|
282
313
|
const creator = OrderFactory.create(values.order_type);
|
|
283
314
|
return creator?.validate(values, {
|
|
284
315
|
symbol: symbolInfo[symbol](),
|
|
285
316
|
// token: tokenInfo[symbol](),
|
|
286
317
|
maxQty,
|
|
287
|
-
markPrice: markPrice
|
|
318
|
+
markPrice: markPrice
|
|
288
319
|
});
|
|
289
320
|
};
|
|
290
|
-
const formattedOrder = useMemo(()
|
|
321
|
+
const formattedOrder = useMemo(()=>{
|
|
291
322
|
if (!parsedData) {
|
|
292
323
|
return notSupportData.current;
|
|
293
324
|
}
|
|
@@ -300,7 +331,7 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
300
331
|
prevOrderData.current = parsedData;
|
|
301
332
|
orderDataCache.current = {
|
|
302
333
|
...parsedData,
|
|
303
|
-
total: ""
|
|
334
|
+
total: ""
|
|
304
335
|
};
|
|
305
336
|
return orderDataCache.current;
|
|
306
337
|
}
|
|
@@ -324,47 +355,50 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
324
355
|
prevOrderData.current = parsedData;
|
|
325
356
|
orderDataCache.current = values;
|
|
326
357
|
return values;
|
|
327
|
-
}, [
|
|
358
|
+
}, [
|
|
359
|
+
parsedData,
|
|
360
|
+
markPrice
|
|
361
|
+
]);
|
|
328
362
|
/// validator order info
|
|
329
|
-
useEffect(()
|
|
330
|
-
if (!markPrice || symbolInfo.isNil)
|
|
331
|
-
return;
|
|
363
|
+
useEffect(()=>{
|
|
364
|
+
if (!markPrice || symbolInfo.isNil) return;
|
|
332
365
|
// validate order data;
|
|
333
|
-
validator(formattedOrder)
|
|
334
|
-
?.then((err) => {
|
|
366
|
+
validator(formattedOrder)?.then((err)=>{
|
|
335
367
|
setErrors(err);
|
|
336
|
-
})
|
|
337
|
-
.catch((err) => { });
|
|
368
|
+
}).catch((err)=>{});
|
|
338
369
|
}, [
|
|
339
370
|
formattedOrder.broker_id,
|
|
340
371
|
formattedOrder.order_quantity,
|
|
341
372
|
formattedOrder.total,
|
|
342
373
|
formattedOrder.trigger_price,
|
|
343
374
|
formattedOrder.order_type,
|
|
344
|
-
markPrice
|
|
375
|
+
markPrice
|
|
345
376
|
]);
|
|
346
377
|
//====== update orderbook ask0/bid0 ======
|
|
347
|
-
useEffect(()
|
|
378
|
+
useEffect(()=>{
|
|
348
379
|
if (isNewVersion) {
|
|
349
380
|
if (!optionsValue?.watchOrderbook) {
|
|
350
381
|
throw new SDKError("In order to calculate the estimated liquidation price, the `options.watchOrderbook` parameter must be set to true.");
|
|
351
382
|
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
383
|
+
} else {
|
|
354
384
|
if (!optionsValue?.watchOrderbook) {
|
|
355
385
|
return;
|
|
356
386
|
}
|
|
357
387
|
}
|
|
358
388
|
ee.on("orderbook:update", onOrderbookUpdate);
|
|
359
|
-
return ()
|
|
389
|
+
return ()=>{
|
|
360
390
|
ee.off("orderbook:update", onOrderbookUpdate);
|
|
361
391
|
};
|
|
362
|
-
}, [
|
|
363
|
-
|
|
392
|
+
}, [
|
|
393
|
+
optionsValue?.watchOrderbook
|
|
394
|
+
]);
|
|
395
|
+
useEffect(()=>{
|
|
364
396
|
askAndBid.current = [];
|
|
365
|
-
}, [
|
|
397
|
+
}, [
|
|
398
|
+
parsedData?.symbol
|
|
399
|
+
]);
|
|
366
400
|
//====== end ======
|
|
367
|
-
const getPriceAndQty = (symbolOrOrder)
|
|
401
|
+
const getPriceAndQty = (symbolOrOrder)=>{
|
|
368
402
|
let quantity = Number(symbolOrOrder.order_quantity);
|
|
369
403
|
const orderPrice = Number(symbolOrOrder.order_price);
|
|
370
404
|
if (isNaN(quantity) || quantity <= 0) {
|
|
@@ -373,48 +407,38 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
373
407
|
if (!!options?.watchOrderbook && askAndBid.current.length === 0) {
|
|
374
408
|
throw new SDKError("Please check if you are using the `useOrderbookStream` hook or if the orderBook has data.");
|
|
375
409
|
}
|
|
376
|
-
if ((symbolOrOrder.order_type === OrderType.LIMIT ||
|
|
377
|
-
symbolOrOrder.order_type === OrderType.STOP_LIMIT) &&
|
|
378
|
-
isNaN(orderPrice))
|
|
379
|
-
return null;
|
|
410
|
+
if ((symbolOrOrder.order_type === OrderType.LIMIT || symbolOrOrder.order_type === OrderType.STOP_LIMIT) && isNaN(orderPrice)) return null;
|
|
380
411
|
/**
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (symbolOrOrder.order_type === OrderType.MARKET ||
|
|
395
|
-
symbolOrOrder.order_type === OrderType.STOP_MARKET) {
|
|
412
|
+
* price
|
|
413
|
+
* if order_type = market order,
|
|
414
|
+
order side = long, then order_price_i = ask0
|
|
415
|
+
order side = short, then order_price_i = bid0
|
|
416
|
+
if order_type = limit order
|
|
417
|
+
order side = long
|
|
418
|
+
limit_price >= ask0, then order_price_i = ask0
|
|
419
|
+
limit_price < ask0, then order_price_i = limit_price
|
|
420
|
+
order side = short
|
|
421
|
+
limit_price <= bid0, then order_price_i = bid0
|
|
422
|
+
limit_price > ask0, then order_price_i = ask0
|
|
423
|
+
*/ let price;
|
|
424
|
+
if (symbolOrOrder.order_type === OrderType.MARKET || symbolOrOrder.order_type === OrderType.STOP_MARKET) {
|
|
396
425
|
if (symbolOrOrder.side === OrderSide.BUY) {
|
|
397
426
|
price = askAndBid.current[0];
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
427
|
+
} else {
|
|
400
428
|
price = askAndBid.current[1];
|
|
401
429
|
}
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
430
|
+
} else {
|
|
404
431
|
// LIMIT order
|
|
405
432
|
if (symbolOrOrder.side === OrderSide.BUY) {
|
|
406
433
|
if (orderPrice >= askAndBid.current[0]) {
|
|
407
434
|
price = askAndBid.current[0];
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
435
|
+
} else {
|
|
410
436
|
price = orderPrice;
|
|
411
437
|
}
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
438
|
+
} else {
|
|
414
439
|
if (orderPrice <= askAndBid.current[1]) {
|
|
415
440
|
price = askAndBid.current[1];
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
441
|
+
} else {
|
|
418
442
|
price = orderPrice;
|
|
419
443
|
}
|
|
420
444
|
}
|
|
@@ -422,21 +446,21 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
422
446
|
if (symbolOrOrder.side === OrderSide.SELL) {
|
|
423
447
|
quantity = -quantity;
|
|
424
448
|
}
|
|
425
|
-
return {
|
|
449
|
+
return {
|
|
450
|
+
price,
|
|
451
|
+
quantity
|
|
452
|
+
};
|
|
426
453
|
};
|
|
427
|
-
const estLiqPrice = useMemo(()
|
|
428
|
-
if (!accountInfo || !parsedData || !markPrice)
|
|
429
|
-
return null;
|
|
454
|
+
const estLiqPrice = useMemo(()=>{
|
|
455
|
+
if (!accountInfo || !parsedData || !markPrice) return null;
|
|
430
456
|
const result = getPriceAndQty(formattedOrder);
|
|
431
|
-
if (result === null)
|
|
432
|
-
return null;
|
|
457
|
+
if (result === null) return null;
|
|
433
458
|
const { price, quantity } = result;
|
|
434
|
-
if (!price || !quantity)
|
|
435
|
-
return null;
|
|
459
|
+
if (!price || !quantity) return null;
|
|
436
460
|
const orderFee = orderUtils.orderFee({
|
|
437
461
|
qty: quantity,
|
|
438
462
|
price,
|
|
439
|
-
futuresTakeFeeRate: Number(accountInfo["futures_taker_fee_rate"]) / 10000
|
|
463
|
+
futuresTakeFeeRate: Number(accountInfo["futures_taker_fee_rate"]) / 10000
|
|
440
464
|
});
|
|
441
465
|
const liqPrice = orderUtils.estLiqPrice({
|
|
442
466
|
markPrice,
|
|
@@ -449,12 +473,11 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
449
473
|
newOrder: {
|
|
450
474
|
qty: quantity,
|
|
451
475
|
price,
|
|
452
|
-
symbol: parsedData.symbol
|
|
453
|
-
}
|
|
476
|
+
symbol: parsedData.symbol
|
|
477
|
+
}
|
|
454
478
|
});
|
|
455
479
|
// console.log("********", liqPrice, markPrice, totalCollateral, result);
|
|
456
|
-
if (liqPrice <= 0)
|
|
457
|
-
return null;
|
|
480
|
+
if (liqPrice <= 0) return null;
|
|
458
481
|
return liqPrice;
|
|
459
482
|
}, [
|
|
460
483
|
markPrice,
|
|
@@ -465,22 +488,20 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
465
488
|
formattedOrder?.order_quantity,
|
|
466
489
|
formattedOrder?.total,
|
|
467
490
|
formattedOrder?.trigger_price,
|
|
468
|
-
accountInfo
|
|
491
|
+
accountInfo
|
|
469
492
|
]);
|
|
470
|
-
const estLeverage = useMemo(()
|
|
471
|
-
if (!accountInfo || !parsedData)
|
|
472
|
-
return null;
|
|
493
|
+
const estLeverage = useMemo(()=>{
|
|
494
|
+
if (!accountInfo || !parsedData) return null;
|
|
473
495
|
const result = getPriceAndQty(formattedOrder);
|
|
474
|
-
if (result === null || !result.price || !result.quantity)
|
|
475
|
-
return null;
|
|
496
|
+
if (result === null || !result.price || !result.quantity) return null;
|
|
476
497
|
const leverage = orderUtils.estLeverage({
|
|
477
498
|
totalCollateral,
|
|
478
499
|
positions,
|
|
479
500
|
newOrder: {
|
|
480
501
|
symbol: parsedData.symbol,
|
|
481
502
|
qty: result.quantity,
|
|
482
|
-
price: result.price
|
|
483
|
-
}
|
|
503
|
+
price: result.price
|
|
504
|
+
}
|
|
484
505
|
});
|
|
485
506
|
return leverage;
|
|
486
507
|
}, [
|
|
@@ -491,7 +512,7 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
491
512
|
formattedOrder?.order_price,
|
|
492
513
|
formattedOrder?.order_quantity,
|
|
493
514
|
formattedOrder?.total,
|
|
494
|
-
formattedOrder?.trigger_price
|
|
515
|
+
formattedOrder?.trigger_price
|
|
495
516
|
]);
|
|
496
517
|
return {
|
|
497
518
|
maxQty,
|
|
@@ -506,14 +527,15 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
506
527
|
estLeverage,
|
|
507
528
|
helper: {
|
|
508
529
|
calculate,
|
|
509
|
-
validator
|
|
510
|
-
// clearErrors,
|
|
530
|
+
validator
|
|
511
531
|
},
|
|
512
532
|
metaState: {
|
|
513
533
|
dirty: fieldDirty.current,
|
|
514
534
|
submitted: submitted.current,
|
|
515
|
-
errors
|
|
535
|
+
errors
|
|
516
536
|
},
|
|
517
|
-
symbolConfig: symbolInfo[symbol]()
|
|
537
|
+
symbolConfig: symbolInfo[symbol]()
|
|
518
538
|
};
|
|
519
539
|
}
|
|
540
|
+
|
|
541
|
+
//# sourceMappingURL=useOrderEntry.js.map
|