@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,54 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useHoldingStream", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useHoldingStream;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _usePrivateQuery = require("../usePrivateQuery");
|
|
12
|
+
const _react = require("react");
|
|
13
|
+
const _useWS = require("../useWS");
|
|
14
|
+
const _subscription = /*#__PURE__*/ _interop_require_default(require("swr/subscription"));
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const useHoldingStream = ()=>{
|
|
21
|
+
const ws = (0, _useWS.useWS)();
|
|
22
|
+
const { data, isLoading, mutate } = (0, _usePrivateQuery.usePrivateQuery)("/v1/client/holding", {
|
|
23
|
+
formatter: (data)=>{
|
|
15
24
|
return data.holding;
|
|
16
|
-
}
|
|
25
|
+
}
|
|
17
26
|
});
|
|
18
|
-
const usdc = (0,
|
|
19
|
-
const usdc = data?.find((item)
|
|
27
|
+
const usdc = (0, _react.useMemo)(()=>{
|
|
28
|
+
const usdc = data?.find((item)=>item.token === "USDC");
|
|
20
29
|
return usdc;
|
|
21
|
-
}, [
|
|
22
|
-
|
|
30
|
+
}, [
|
|
31
|
+
data
|
|
32
|
+
]);
|
|
33
|
+
(0, _subscription.default)("holding", (_, { next })=>{
|
|
23
34
|
const unsubscribe = ws.privateSubscribe({
|
|
24
35
|
id: "balance",
|
|
25
36
|
event: "subscribe",
|
|
26
37
|
topic: "balance",
|
|
27
|
-
ts: Date.now()
|
|
38
|
+
ts: Date.now()
|
|
28
39
|
}, {
|
|
29
|
-
onMessage: (data)
|
|
40
|
+
onMessage: (data)=>{
|
|
30
41
|
const holding = data?.balances ?? {};
|
|
31
42
|
if (holding) {
|
|
32
|
-
mutate((prevData)
|
|
33
|
-
return prevData?.map((item)
|
|
43
|
+
mutate((prevData)=>{
|
|
44
|
+
return prevData?.map((item)=>{
|
|
34
45
|
const token = holding[item.token];
|
|
35
46
|
return {
|
|
36
47
|
...item,
|
|
37
48
|
frozen: token.frozen,
|
|
38
|
-
holding: token.holding
|
|
49
|
+
holding: token.holding
|
|
39
50
|
};
|
|
40
51
|
});
|
|
41
52
|
});
|
|
42
53
|
next(holding);
|
|
43
54
|
}
|
|
44
|
-
}
|
|
55
|
+
}
|
|
45
56
|
});
|
|
46
|
-
return ()
|
|
57
|
+
return ()=>unsubscribe();
|
|
47
58
|
});
|
|
48
59
|
return {
|
|
49
60
|
data,
|
|
50
61
|
usdc,
|
|
51
|
-
isLoading
|
|
62
|
+
isLoading
|
|
52
63
|
};
|
|
53
64
|
};
|
|
54
|
-
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=useHoldingStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orderly/useHoldingStream.ts"],"sourcesContent":["import { API } from \"@orderly.network/types\";\nimport { usePrivateQuery } from \"../usePrivateQuery\";\nimport { useMemo } from \"react\";\nimport { useWS } from \"../useWS\";\nimport useSWRSubscription from \"swr/subscription\";\n\nexport const useHoldingStream = () => {\n const ws = useWS();\n\n const { data, isLoading, mutate } = usePrivateQuery<API.Holding[]>(\n \"/v1/client/holding\",\n {\n formatter: (data) => {\n return data.holding;\n },\n }\n );\n\n const usdc = useMemo(() => {\n const usdc = data?.find((item) => item.token === \"USDC\");\n return usdc;\n }, [data]);\n\n useSWRSubscription(\"holding\", (_, { next }) => {\n const unsubscribe = ws.privateSubscribe(\n {\n id: \"balance\",\n event: \"subscribe\",\n topic: \"balance\",\n ts: Date.now(),\n },\n {\n onMessage: (data: any) => {\n const holding = data?.balances ?? ({} as Record<string, any>);\n\n if (holding) {\n mutate((prevData) => {\n return prevData?.map((item) => {\n const token = holding[item.token];\n return {\n ...item,\n frozen: token.frozen,\n holding: token.holding,\n };\n });\n });\n\n next(holding);\n }\n },\n }\n );\n\n return () => unsubscribe();\n });\n\n return {\n data,\n usdc,\n isLoading,\n };\n};\n"],"names":["useHoldingStream","ws","useWS","data","isLoading","mutate","usePrivateQuery","formatter","holding","usdc","useMemo","find","item","token","useSWRSubscription","_","next","unsubscribe","privateSubscribe","id","event","topic","ts","Date","now","onMessage","balances","prevData","map","frozen"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAMaA;;;eAAAA;;;iCALmB;uBACR;uBACF;qEACS;;;;;;AAExB,MAAMA,mBAAmB;IAC9B,MAAMC,KAAKC,IAAAA,YAAK;IAEhB,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,MAAM,EAAE,GAAGC,IAAAA,gCAAe,EACjD,sBACA;QACEC,WAAW,CAACJ;YACV,OAAOA,KAAKK,OAAO;QACrB;IACF;IAGF,MAAMC,OAAOC,IAAAA,cAAO,EAAC;QACnB,MAAMD,OAAON,MAAMQ,KAAK,CAACC,OAASA,KAAKC,KAAK,KAAK;QACjD,OAAOJ;IACT,GAAG;QAACN;KAAK;IAETW,IAAAA,qBAAkB,EAAC,WAAW,CAACC,GAAG,EAAEC,IAAI,EAAE;QACxC,MAAMC,cAAchB,GAAGiB,gBAAgB,CACrC;YACEC,IAAI;YACJC,OAAO;YACPC,OAAO;YACPC,IAAIC,KAAKC,GAAG;QACd,GACA;YACEC,WAAW,CAACtB;gBACV,MAAMK,UAAUL,MAAMuB,YAAa,CAAC;gBAEpC,IAAIlB,SAAS;oBACXH,OAAO,CAACsB;wBACN,OAAOA,UAAUC,IAAI,CAAChB;4BACpB,MAAMC,QAAQL,OAAO,CAACI,KAAKC,KAAK,CAAC;4BACjC,OAAO;gCACL,GAAGD,IAAI;gCACPiB,QAAQhB,MAAMgB,MAAM;gCACpBrB,SAASK,MAAML,OAAO;4BACxB;wBACF;oBACF;oBAEAQ,KAAKR;gBACP;YACF;QACF;QAGF,OAAO,IAAMS;IACf;IAEA,OAAO;QACLd;QACAM;QACAL;IACF;AACF"}
|
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useIndexPrice", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useIndexPrice;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _useWS = require("../useWS");
|
|
12
|
+
const _subscription = /*#__PURE__*/ _interop_require_default(require("swr/subscription"));
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const useIndexPrice = (symbol)=>{
|
|
10
19
|
// WARNING: force change perp to spot, because there is no perp now
|
|
11
20
|
symbol = symbol.replace("PERP", "SPOT");
|
|
12
|
-
const ws = (0,
|
|
13
|
-
return (0,
|
|
21
|
+
const ws = (0, _useWS.useWS)();
|
|
22
|
+
return (0, _subscription.default)(`${symbol}@indexprice`, (key, { next })=>{
|
|
14
23
|
const unsubscribe = ws.subscribe(`${symbol}@indexprice`, {
|
|
15
|
-
onMessage: (message)
|
|
24
|
+
onMessage: (message)=>{
|
|
16
25
|
next(null, message.price);
|
|
17
|
-
}
|
|
26
|
+
}
|
|
18
27
|
});
|
|
19
|
-
return ()
|
|
28
|
+
return ()=>{
|
|
20
29
|
unsubscribe?.();
|
|
21
30
|
};
|
|
22
31
|
});
|
|
23
32
|
};
|
|
24
|
-
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=useIndexPrice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orderly/useIndexPrice.ts"],"sourcesContent":["import { useWS } from \"../useWS\";\nimport useSWRSubscription from \"swr/subscription\";\n\nexport const useIndexPrice = (symbol: string) => {\n // WARNING: force change perp to spot, because there is no perp now\n symbol = symbol.replace(\"PERP\", \"SPOT\");\n const ws = useWS();\n return useSWRSubscription(`${symbol}@indexprice`, (key, { next }) => {\n const unsubscribe = ws.subscribe(`${symbol}@indexprice`, {\n onMessage: (message: any) => {\n next(null, message.price);\n },\n });\n\n return () => {\n unsubscribe?.();\n };\n });\n};\n"],"names":["useIndexPrice","symbol","replace","ws","useWS","useSWRSubscription","key","next","unsubscribe","subscribe","onMessage","message","price"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAGaA;;;eAAAA;;;uBAHS;qEACS;;;;;;AAExB,MAAMA,gBAAgB,CAACC;IAC5B,mEAAmE;IACnEA,SAASA,OAAOC,OAAO,CAAC,QAAQ;IAChC,MAAMC,KAAKC,IAAAA,YAAK;IAChB,OAAOC,IAAAA,qBAAkB,EAAC,CAAC,EAAEJ,OAAO,WAAW,CAAC,EAAE,CAACK,KAAK,EAAEC,IAAI,EAAE;QAC9D,MAAMC,cAAcL,GAAGM,SAAS,CAAC,CAAC,EAAER,OAAO,WAAW,CAAC,EAAE;YACvDS,WAAW,CAACC;gBACVJ,KAAK,MAAMI,QAAQC,KAAK;YAC1B;QACF;QAEA,OAAO;YACLJ;QACF;IACF;AACF"}
|
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useLeverage", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useLeverage;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const _useMutation = require("../useMutation");
|
|
13
|
+
const _usePrivateQuery = require("../usePrivateQuery");
|
|
14
|
+
const _ramda = require("ramda");
|
|
15
|
+
const _useQuery = require("../useQuery");
|
|
16
|
+
const useLeverage = ()=>{
|
|
17
|
+
const { data, mutate } = (0, _usePrivateQuery.usePrivateQuery)("/v1/client/info");
|
|
18
|
+
const [update, { isMutating }] = (0, _useMutation.useMutation)("/v1/client/leverage");
|
|
19
|
+
const { data: config } = (0, _useQuery.useQuery)("/v1/public/config");
|
|
20
|
+
const updateLeverage = (0, _react.useCallback)((data)=>{
|
|
21
|
+
return update(data).then((res)=>{
|
|
15
22
|
if (res.success) {
|
|
16
23
|
return mutate();
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
24
|
+
} else {
|
|
19
25
|
throw new Error(res.message);
|
|
20
26
|
}
|
|
21
|
-
|
|
27
|
+
// return res
|
|
22
28
|
});
|
|
23
29
|
}, []);
|
|
24
30
|
return [
|
|
25
|
-
(0,
|
|
31
|
+
(0, _ramda.prop)("max_leverage", data),
|
|
26
32
|
{
|
|
27
33
|
update: updateLeverage,
|
|
28
34
|
isMutating,
|
|
29
35
|
// config: [1, 2, 3, 4, 5, 10, 15, 20],
|
|
30
|
-
config: config
|
|
31
|
-
|
|
32
|
-
?.split(",")
|
|
33
|
-
.map((item) => parseInt(item))
|
|
34
|
-
: [],
|
|
35
|
-
},
|
|
36
|
+
config: config ? config?.available_futures_leverage?.split(",").map((item)=>parseInt(item)) : []
|
|
37
|
+
}
|
|
36
38
|
];
|
|
37
39
|
};
|
|
38
|
-
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=useLeverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orderly/useLeverage.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useMutation } from \"../useMutation\";\nimport { usePrivateQuery } from \"../usePrivateQuery\";\nimport { prop } from \"ramda\";\nimport { useQuery } from \"../useQuery\";\n\nexport const useLeverage = (): any => {\n const { data, mutate } = usePrivateQuery(\"/v1/client/info\");\n const [update, { isMutating }] = useMutation(\"/v1/client/leverage\");\n\n const { data: config } = useQuery(\"/v1/public/config\");\n\n const updateLeverage = useCallback((data: { leverage: number }) => {\n return update(data).then((res: any) => {\n if (res.success) {\n return mutate();\n } else {\n throw new Error(res.message);\n }\n // return res\n });\n }, []);\n\n return [\n prop(\"max_leverage\", data as any),\n {\n update: updateLeverage,\n isMutating,\n // config: [1, 2, 3, 4, 5, 10, 15, 20],\n config: config\n ? (config as any)?.available_futures_leverage\n ?.split(\",\")\n .map((item: string) => parseInt(item))\n : [],\n },\n ];\n};\n"],"names":["useLeverage","data","mutate","usePrivateQuery","update","isMutating","useMutation","config","useQuery","updateLeverage","useCallback","then","res","success","Error","message","prop","available_futures_leverage","split","map","item","parseInt"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAMaA;;;eAAAA;;;uBANe;6BACA;iCACI;uBACX;0BACI;AAElB,MAAMA,cAAc;IACzB,MAAM,EAAEC,IAAI,EAAEC,MAAM,EAAE,GAAGC,IAAAA,gCAAe,EAAC;IACzC,MAAM,CAACC,QAAQ,EAAEC,UAAU,EAAE,CAAC,GAAGC,IAAAA,wBAAW,EAAC;IAE7C,MAAM,EAAEL,MAAMM,MAAM,EAAE,GAAGC,IAAAA,kBAAQ,EAAC;IAElC,MAAMC,iBAAiBC,IAAAA,kBAAW,EAAC,CAACT;QAClC,OAAOG,OAAOH,MAAMU,IAAI,CAAC,CAACC;YACxB,IAAIA,IAAIC,OAAO,EAAE;gBACf,OAAOX;YACT,OAAO;gBACL,MAAM,IAAIY,MAAMF,IAAIG,OAAO;YAC7B;QACA,aAAa;QACf;IACF,GAAG,EAAE;IAEL,OAAO;QACLC,IAAAA,WAAI,EAAC,gBAAgBf;QACrB;YACEG,QAAQK;YACRJ;YACA,uCAAuC;YACvCE,QAAQA,SACHA,QAAgBU,4BACbC,MAAM,KACPC,IAAI,CAACC,OAAiBC,SAASD,SAClC,EAAE;QACR;KACD;AACH"}
|
|
@@ -1,45 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useMarginRatio", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useMarginRatio;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const _perp = require("@orderly.network/perp");
|
|
13
|
+
const _usePositionStream = require("./usePositionStream");
|
|
14
|
+
const _useMarkPricesStream = require("./useMarkPricesStream");
|
|
15
|
+
const _useCollateral = require("./useCollateral");
|
|
16
|
+
const _utils = require("@orderly.network/utils");
|
|
17
|
+
const useMarginRatio = ()=>{
|
|
18
|
+
const [{ rows, aggregated }] = (0, _usePositionStream.usePositionStream)();
|
|
19
|
+
const { data: markPrices } = (0, _useMarkPricesStream.useMarkPricesStream)();
|
|
20
|
+
const { totalCollateral } = (0, _useCollateral.useCollateral)();
|
|
21
|
+
const marginRatio = (0, _react.useMemo)(()=>{
|
|
15
22
|
if (!rows || !markPrices || !totalCollateral || rows.length === 0) {
|
|
16
23
|
return 0;
|
|
17
24
|
}
|
|
18
|
-
const ratio =
|
|
25
|
+
const ratio = _perp.account.totalMarginRatio({
|
|
19
26
|
totalCollateral: totalCollateral,
|
|
20
27
|
markPrices: markPrices,
|
|
21
|
-
positions: rows ?? []
|
|
28
|
+
positions: rows ?? []
|
|
22
29
|
});
|
|
23
30
|
return ratio;
|
|
24
|
-
}, [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
}, [
|
|
32
|
+
rows,
|
|
33
|
+
markPrices,
|
|
34
|
+
totalCollateral
|
|
35
|
+
]);
|
|
36
|
+
const currentLeverage = (0, _react.useMemo)(()=>{
|
|
37
|
+
return _perp.account.currentLeverage(marginRatio);
|
|
38
|
+
}, [
|
|
39
|
+
marginRatio
|
|
40
|
+
]);
|
|
28
41
|
// MMR
|
|
29
|
-
const mmr = (0,
|
|
30
|
-
if (!rows || rows.length <= 0)
|
|
31
|
-
|
|
32
|
-
let positionsMM = utils_1.zero;
|
|
42
|
+
const mmr = (0, _react.useMemo)(()=>{
|
|
43
|
+
if (!rows || rows.length <= 0) return null;
|
|
44
|
+
let positionsMM = _utils.zero;
|
|
33
45
|
// const positionsNotional = positions.totalNotional(rows);
|
|
34
|
-
for
|
|
46
|
+
for(let index = 0; index < rows.length; index++){
|
|
35
47
|
const item = rows[index];
|
|
36
48
|
positionsMM = positionsMM.add(item.mm);
|
|
37
49
|
}
|
|
38
|
-
return
|
|
50
|
+
return _perp.account.MMR({
|
|
39
51
|
positionsMMR: positionsMM.toNumber(),
|
|
40
|
-
positionsNotional: aggregated.notional
|
|
52
|
+
positionsNotional: aggregated.notional
|
|
41
53
|
});
|
|
42
|
-
}, [
|
|
43
|
-
|
|
54
|
+
}, [
|
|
55
|
+
rows,
|
|
56
|
+
aggregated
|
|
57
|
+
]);
|
|
58
|
+
return {
|
|
59
|
+
marginRatio,
|
|
60
|
+
currentLeverage,
|
|
61
|
+
mmr
|
|
62
|
+
};
|
|
44
63
|
};
|
|
45
|
-
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=useMarginRatio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orderly/useMarginRatio.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { account, positions } from \"@orderly.network/perp\";\nimport { usePositionStream } from \"./usePositionStream\";\nimport { useMarkPricesStream } from \"./useMarkPricesStream\";\nimport { useCollateral } from \"./useCollateral\";\nimport { zero } from \"@orderly.network/utils\";\n\nexport type MarginRatioReturn = {\n // Margin Ratio\n marginRatio: number;\n // Current Leverage\n currentLeverage: number;\n // account margin ratio, if user has no position, return null\n mmr: number | null;\n};\n\nexport const useMarginRatio = (): MarginRatioReturn => {\n const [{ rows, aggregated }] = usePositionStream();\n const { data: markPrices } = useMarkPricesStream();\n\n const { totalCollateral } = useCollateral();\n const marginRatio = useMemo(() => {\n if (!rows || !markPrices || !totalCollateral || rows.length === 0) {\n return 0;\n }\n\n const ratio = account.totalMarginRatio({\n totalCollateral: totalCollateral,\n markPrices: markPrices,\n positions: rows ?? [],\n });\n return ratio;\n }, [rows, markPrices, totalCollateral]);\n\n const currentLeverage = useMemo(() => {\n return account.currentLeverage(marginRatio);\n }, [marginRatio]);\n\n // MMR\n const mmr = useMemo<number | null>(() => {\n if (!rows || rows.length <= 0) return null;\n let positionsMM = zero;\n // const positionsNotional = positions.totalNotional(rows);\n\n for (let index = 0; index < rows.length; index++) {\n const item = rows[index];\n positionsMM = positionsMM.add(item.mm);\n }\n\n return account.MMR({\n positionsMMR: positionsMM.toNumber(),\n positionsNotional: aggregated.notional,\n });\n }, [rows, aggregated]);\n\n return { marginRatio, currentLeverage, mmr };\n};\n"],"names":["useMarginRatio","rows","aggregated","usePositionStream","data","markPrices","useMarkPricesStream","totalCollateral","useCollateral","marginRatio","useMemo","length","ratio","account","totalMarginRatio","positions","currentLeverage","mmr","positionsMM","zero","index","item","add","mm","MMR","positionsMMR","toNumber","positionsNotional","notional"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAgBaA;;;eAAAA;;;uBAhBW;sBACW;mCACD;qCACE;+BACN;uBACT;AAWd,MAAMA,iBAAiB;IAC5B,MAAM,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAE,CAAC,GAAGC,IAAAA,oCAAiB;IAChD,MAAM,EAAEC,MAAMC,UAAU,EAAE,GAAGC,IAAAA,wCAAmB;IAEhD,MAAM,EAAEC,eAAe,EAAE,GAAGC,IAAAA,4BAAa;IACzC,MAAMC,cAAcC,IAAAA,cAAO,EAAC;QAC1B,IAAI,CAACT,QAAQ,CAACI,cAAc,CAACE,mBAAmBN,KAAKU,MAAM,KAAK,GAAG;YACjE,OAAO;QACT;QAEA,MAAMC,QAAQC,aAAO,CAACC,gBAAgB,CAAC;YACrCP,iBAAiBA;YACjBF,YAAYA;YACZU,WAAWd,QAAQ,EAAE;QACvB;QACA,OAAOW;IACT,GAAG;QAACX;QAAMI;QAAYE;KAAgB;IAEtC,MAAMS,kBAAkBN,IAAAA,cAAO,EAAC;QAC9B,OAAOG,aAAO,CAACG,eAAe,CAACP;IACjC,GAAG;QAACA;KAAY;IAEhB,MAAM;IACN,MAAMQ,MAAMP,IAAAA,cAAO,EAAgB;QACjC,IAAI,CAACT,QAAQA,KAAKU,MAAM,IAAI,GAAG,OAAO;QACtC,IAAIO,cAAcC,WAAI;QACtB,2DAA2D;QAE3D,IAAK,IAAIC,QAAQ,GAAGA,QAAQnB,KAAKU,MAAM,EAAES,QAAS;YAChD,MAAMC,OAAOpB,IAAI,CAACmB,MAAM;YACxBF,cAAcA,YAAYI,GAAG,CAACD,KAAKE,EAAE;QACvC;QAEA,OAAOV,aAAO,CAACW,GAAG,CAAC;YACjBC,cAAcP,YAAYQ,QAAQ;YAClCC,mBAAmBzB,WAAW0B,QAAQ;QACxC;IACF,GAAG;QAAC3B;QAAMC;KAAW;IAErB,OAAO;QAAEO;QAAaO;QAAiBC;IAAI;AAC7C"}
|
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useMarkPrice", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useMarkPrice;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const _useWS = require("../useWS");
|
|
13
|
+
const useMarkPrice = (symbol)=>{
|
|
14
|
+
const ws = (0, _useWS.useWS)();
|
|
15
|
+
const [price, setPrice] = (0, _react.useState)(0);
|
|
16
|
+
(0, _react.useEffect)(()=>{
|
|
11
17
|
const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
|
|
12
|
-
onMessage: (message)
|
|
18
|
+
onMessage: (message)=>{
|
|
13
19
|
setPrice(message.price);
|
|
14
|
-
}
|
|
20
|
+
}
|
|
15
21
|
});
|
|
16
|
-
return ()
|
|
22
|
+
return ()=>{
|
|
17
23
|
unsubscribe?.();
|
|
18
24
|
};
|
|
19
|
-
}, [
|
|
25
|
+
}, [
|
|
26
|
+
symbol
|
|
27
|
+
]);
|
|
20
28
|
// return useSWRSubscription(`${symbol}@markprice`, (key, { next }) => {
|
|
21
29
|
// const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
|
|
22
30
|
// onMessage: (message: any) => {
|
|
@@ -28,6 +36,9 @@ const useMarkPrice = (symbol) => {
|
|
|
28
36
|
// unsubscribe?.();
|
|
29
37
|
// };
|
|
30
38
|
// });
|
|
31
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
data: price
|
|
41
|
+
};
|
|
32
42
|
};
|
|
33
|
-
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=useMarkPrice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orderly/useMarkPrice.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport { useWS } from \"../useWS\";\n// import useSWRSubscription from \"swr/subscription\";\n\nexport const useMarkPrice = (symbol: string) => {\n const ws = useWS();\n const [price, setPrice] = useState(0);\n\n useEffect(() => {\n const unsubscribe = ws.subscribe(`${symbol}@markprice`, {\n onMessage: (message: any) => {\n setPrice(message.price);\n },\n });\n\n return () => {\n unsubscribe?.();\n };\n }, [symbol]);\n\n // return useSWRSubscription(`${symbol}@markprice`, (key, { next }) => {\n // const unsubscribe = ws.subscribe(`${symbol}@markprice`, {\n // onMessage: (message: any) => {\n // next(null, message.price);\n // },\n // });\n\n // return () => {\n // // console.log(\"_____________________ unsubscribe _________ \", symbol);\n // unsubscribe?.();\n // };\n // });\n\n return { data: price };\n};\n"],"names":["useMarkPrice","symbol","ws","useWS","price","setPrice","useState","useEffect","unsubscribe","subscribe","onMessage","message","data"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAIaA;;;eAAAA;;;uBAJuB;uBACd;AAGf,MAAMA,eAAe,CAACC;IAC3B,MAAMC,KAAKC,IAAAA,YAAK;IAChB,MAAM,CAACC,OAAOC,SAAS,GAAGC,IAAAA,eAAQ,EAAC;IAEnCC,IAAAA,gBAAS,EAAC;QACR,MAAMC,cAAcN,GAAGO,SAAS,CAAC,CAAC,EAAER,OAAO,UAAU,CAAC,EAAE;YACtDS,WAAW,CAACC;gBACVN,SAASM,QAAQP,KAAK;YACxB;QACF;QAEA,OAAO;YACLI;QACF;IACF,GAAG;QAACP;KAAO;IAEX,wEAAwE;IACxE,8DAA8D;IAC9D,qCAAqC;IACrC,mCAAmC;IACnC,SAAS;IACT,QAAQ;IAER,mBAAmB;IACnB,8EAA8E;IAC9E,uBAAuB;IACvB,OAAO;IACP,MAAM;IAEN,OAAO;QAAEW,MAAMR;IAAM;AACvB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useMarkPricesStream: () => import("swr/subscription").SWRSubscriptionResponse<
|
|
1
|
+
export declare const useMarkPricesStream: () => import("swr/subscription").SWRSubscriptionResponse<Record<string, number>, any>;
|
|
2
2
|
//# sourceMappingURL=useMarkPricesStream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMarkPricesStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useMarkPricesStream.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"useMarkPricesStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useMarkPricesStream.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,uFAkC/B,CAAC"}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useMarkPricesStream", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useMarkPricesStream;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _subscription = /*#__PURE__*/ _interop_require_default(require("swr/subscription"));
|
|
12
|
+
const _useWS = require("../useWS");
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const useMarkPricesStream = ()=>{
|
|
19
|
+
const ws = (0, _useWS.useWS)();
|
|
20
|
+
return (0, _subscription.default)("markPrices", (key, { next })=>{
|
|
21
|
+
const unsubscribe = ws.subscribe(// { event: "subscribe", topic: "markprices" },
|
|
14
22
|
"markprices", {
|
|
15
|
-
onMessage: (message)
|
|
23
|
+
onMessage: (message)=>{
|
|
16
24
|
const data = Object.create(null);
|
|
17
|
-
for
|
|
25
|
+
for(let index = 0; index < message.length; index++){
|
|
18
26
|
const element = message[index];
|
|
19
27
|
data[element.symbol] = element.price;
|
|
20
28
|
}
|
|
@@ -23,11 +31,12 @@ const useMarkPricesStream = () => {
|
|
|
23
31
|
// onUnsubscribe: () => {
|
|
24
32
|
// return "markprices";
|
|
25
33
|
// },
|
|
26
|
-
onError: (error)
|
|
34
|
+
onError: (error)=>{}
|
|
27
35
|
});
|
|
28
|
-
return ()
|
|
36
|
+
return ()=>{
|
|
29
37
|
unsubscribe?.();
|
|
30
38
|
};
|
|
31
39
|
});
|
|
32
40
|
};
|
|
33
|
-
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=useMarkPricesStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orderly/useMarkPricesStream.ts"],"sourcesContent":["import useSWRSubscription, { SWRSubscriptionOptions } from \"swr/subscription\";\nimport { useWS } from \"../useWS\";\n\nexport const useMarkPricesStream = () => {\n const ws = useWS();\n return useSWRSubscription<Record<string, number>>(\n \"markPrices\",\n (\n key: string,\n { next }: SWRSubscriptionOptions<Record<string, number>, any>\n ) => {\n const unsubscribe = ws.subscribe(\n // { event: \"subscribe\", topic: \"markprices\" },\n \"markprices\",\n {\n onMessage: (message: any) => {\n const data: Record<string, number> = Object.create(null);\n\n for (let index = 0; index < message.length; index++) {\n const element = message[index];\n data[element.symbol] = element.price;\n }\n\n next(null, data);\n },\n // onUnsubscribe: () => {\n // return \"markprices\";\n // },\n onError: (error: any) => {},\n }\n );\n\n return () => {\n unsubscribe?.();\n };\n }\n );\n};\n"],"names":["useMarkPricesStream","ws","useWS","useSWRSubscription","key","next","unsubscribe","subscribe","onMessage","message","data","Object","create","index","length","element","symbol","price","onError","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAGaA;;;eAAAA;;;qEAH8C;uBACrC;;;;;;AAEf,MAAMA,sBAAsB;IACjC,MAAMC,KAAKC,IAAAA,YAAK;IAChB,OAAOC,IAAAA,qBAAkB,EACvB,cACA,CACEC,KACA,EAAEC,IAAI,EAAuD;QAE7D,MAAMC,cAAcL,GAAGM,SAAS,CAC9B,+CAA+C;QAC/C,cACA;YACEC,WAAW,CAACC;gBACV,MAAMC,OAA+BC,OAAOC,MAAM,CAAC;gBAEnD,IAAK,IAAIC,QAAQ,GAAGA,QAAQJ,QAAQK,MAAM,EAAED,QAAS;oBACnD,MAAME,UAAUN,OAAO,CAACI,MAAM;oBAC9BH,IAAI,CAACK,QAAQC,MAAM,CAAC,GAAGD,QAAQE,KAAK;gBACtC;gBAEAZ,KAAK,MAAMK;YACb;YACA,yBAAyB;YACzB,yBAAyB;YACzB,KAAK;YACLQ,SAAS,CAACC,SAAgB;QAC5B;QAGF,OAAO;YACLb;QACF;IACF;AAEJ"}
|
|
@@ -1,55 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useMarketTradeStream", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useMarketTradeStream;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _useWS = require("../useWS");
|
|
12
|
+
const _react = require("react");
|
|
13
|
+
const useMarketTradeStream = (symbol, options = {})=>{
|
|
7
14
|
if (!symbol) {
|
|
8
15
|
throw new Error("useTradeStream: symbol is required");
|
|
9
16
|
}
|
|
10
|
-
const [trades, setTrades] = (0,
|
|
11
|
-
const [isLoading, setIsLoading] = (0,
|
|
17
|
+
const [trades, setTrades] = (0, _react.useState)([]);
|
|
18
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
12
19
|
const { limit = 50 } = options;
|
|
13
|
-
const ws = (0,
|
|
14
|
-
(0,
|
|
20
|
+
const ws = (0, _useWS.useWS)();
|
|
21
|
+
(0, _react.useEffect)(()=>{
|
|
15
22
|
setIsLoading(true);
|
|
16
|
-
setTrades(()
|
|
23
|
+
setTrades(()=>[]);
|
|
17
24
|
ws.onceSubscribe({
|
|
18
25
|
id: `${symbol}@trade`,
|
|
19
26
|
event: "request",
|
|
20
27
|
params: {
|
|
21
28
|
type: "trade",
|
|
22
29
|
symbol: symbol,
|
|
23
|
-
limit
|
|
24
|
-
}
|
|
30
|
+
limit
|
|
31
|
+
}
|
|
25
32
|
}, {
|
|
26
|
-
onMessage: (data)
|
|
33
|
+
onMessage: (data)=>{
|
|
27
34
|
setIsLoading(false);
|
|
28
|
-
setTrades(()
|
|
29
|
-
}
|
|
35
|
+
setTrades(()=>data);
|
|
36
|
+
}
|
|
30
37
|
});
|
|
31
|
-
}, [
|
|
32
|
-
|
|
38
|
+
}, [
|
|
39
|
+
symbol
|
|
40
|
+
]);
|
|
41
|
+
(0, _react.useEffect)(()=>{
|
|
33
42
|
const unsubscript = ws.subscribe({
|
|
34
43
|
id: `${symbol}@trade`,
|
|
35
44
|
event: "subscribe",
|
|
36
45
|
topic: `${symbol}@trade`,
|
|
37
|
-
ts: Date.now()
|
|
46
|
+
ts: Date.now()
|
|
38
47
|
}, {
|
|
39
|
-
onMessage: (data)
|
|
40
|
-
setTrades((prev)
|
|
41
|
-
const arr = [
|
|
48
|
+
onMessage: (data)=>{
|
|
49
|
+
setTrades((prev)=>{
|
|
50
|
+
const arr = [
|
|
51
|
+
{
|
|
52
|
+
...data,
|
|
53
|
+
ts: Date.now()
|
|
54
|
+
},
|
|
55
|
+
...prev
|
|
56
|
+
];
|
|
42
57
|
if (arr.length > limit) {
|
|
43
58
|
arr.pop();
|
|
44
59
|
}
|
|
45
60
|
return arr;
|
|
46
61
|
});
|
|
47
|
-
}
|
|
62
|
+
}
|
|
48
63
|
});
|
|
49
|
-
return ()
|
|
64
|
+
return ()=>{
|
|
50
65
|
unsubscript?.();
|
|
51
66
|
};
|
|
52
|
-
}, [
|
|
53
|
-
|
|
67
|
+
}, [
|
|
68
|
+
symbol
|
|
69
|
+
]);
|
|
70
|
+
return {
|
|
71
|
+
data: trades,
|
|
72
|
+
isLoading
|
|
73
|
+
};
|
|
54
74
|
};
|
|
55
|
-
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=useMarketTradeStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orderly/useMarketTradeStream.ts"],"sourcesContent":["import { API } from \"@orderly.network/types\";\nimport { useWS } from \"../useWS\";\nimport { useEffect, useState } from \"react\";\n\nexport interface MarketTradeStreamOptions {\n limit?: number;\n}\n\nexport const useMarketTradeStream = (\n symbol: string,\n options: MarketTradeStreamOptions = {}\n) => {\n if (!symbol) {\n throw new Error(\"useTradeStream: symbol is required\");\n }\n\n const [trades, setTrades] = useState<API.Trade[]>([]);\n const [isLoading, setIsLoading] = useState<boolean>(false);\n\n const { limit = 50 } = options;\n\n const ws = useWS();\n\n useEffect(() => {\n setIsLoading(true);\n setTrades(() => []);\n ws.onceSubscribe(\n {\n id: `${symbol}@trade`,\n event: \"request\",\n params: {\n type: \"trade\",\n symbol: symbol,\n limit,\n },\n },\n {\n onMessage: (data: any) => {\n setIsLoading(false);\n setTrades(() => data);\n },\n }\n );\n }, [symbol]);\n\n useEffect(() => {\n const unsubscript = ws.subscribe(\n {\n id: `${symbol}@trade`,\n event: \"subscribe\",\n topic: `${symbol}@trade`,\n ts: Date.now(),\n },\n {\n onMessage: (data: any) => {\n setTrades((prev) => {\n const arr = [{ ...data, ts: Date.now() }, ...prev];\n if (arr.length > limit) {\n arr.pop();\n }\n return arr;\n });\n },\n }\n );\n\n return () => {\n unsubscript?.();\n };\n }, [symbol]);\n\n return { data: trades, isLoading };\n};\n"],"names":["useMarketTradeStream","symbol","options","Error","trades","setTrades","useState","isLoading","setIsLoading","limit","ws","useWS","useEffect","onceSubscribe","id","event","params","type","onMessage","data","unsubscript","subscribe","topic","ts","Date","now","prev","arr","length","pop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAQaA;;;eAAAA;;;uBAPS;uBACc;AAM7B,MAAMA,uBAAuB,CAClCC,QACAC,UAAoC,CAAC,CAAC;IAEtC,IAAI,CAACD,QAAQ;QACX,MAAM,IAAIE,MAAM;IAClB;IAEA,MAAM,CAACC,QAAQC,UAAU,GAAGC,IAAAA,eAAQ,EAAc,EAAE;IACpD,MAAM,CAACC,WAAWC,aAAa,GAAGF,IAAAA,eAAQ,EAAU;IAEpD,MAAM,EAAEG,QAAQ,EAAE,EAAE,GAAGP;IAEvB,MAAMQ,KAAKC,IAAAA,YAAK;IAEhBC,IAAAA,gBAAS,EAAC;QACRJ,aAAa;QACbH,UAAU,IAAM,EAAE;QAClBK,GAAGG,aAAa,CACd;YACEC,IAAI,CAAC,EAAEb,OAAO,MAAM,CAAC;YACrBc,OAAO;YACPC,QAAQ;gBACNC,MAAM;gBACNhB,QAAQA;gBACRQ;YACF;QACF,GACA;YACES,WAAW,CAACC;gBACVX,aAAa;gBACbH,UAAU,IAAMc;YAClB;QACF;IAEJ,GAAG;QAAClB;KAAO;IAEXW,IAAAA,gBAAS,EAAC;QACR,MAAMQ,cAAcV,GAAGW,SAAS,CAC9B;YACEP,IAAI,CAAC,EAAEb,OAAO,MAAM,CAAC;YACrBc,OAAO;YACPO,OAAO,CAAC,EAAErB,OAAO,MAAM,CAAC;YACxBsB,IAAIC,KAAKC,GAAG;QACd,GACA;YACEP,WAAW,CAACC;gBACVd,UAAU,CAACqB;oBACT,MAAMC,MAAM;wBAAC;4BAAE,GAAGR,IAAI;4BAAEI,IAAIC,KAAKC,GAAG;wBAAG;2BAAMC;qBAAK;oBAClD,IAAIC,IAAIC,MAAM,GAAGnB,OAAO;wBACtBkB,IAAIE,GAAG;oBACT;oBACA,OAAOF;gBACT;YACF;QACF;QAGF,OAAO;YACLP;QACF;IACF,GAAG;QAACnB;KAAO;IAEX,OAAO;QAAEkB,MAAMf;QAAQG;IAAU;AACnC"}
|