@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
|
@@ -2,25 +2,25 @@ import { isNil } from "ramda";
|
|
|
2
2
|
// export function createGetter<T extends Record<string, any>, K extends keyof T>(
|
|
3
3
|
export function createGetter(data, depth = 2) {
|
|
4
4
|
return new Proxy(data || {}, {
|
|
5
|
-
get(target, property, receiver) {
|
|
5
|
+
get (target, property, receiver) {
|
|
6
6
|
if (property === "isNil") {
|
|
7
7
|
return isNil(data);
|
|
8
8
|
}
|
|
9
9
|
if (depth === 1) {
|
|
10
|
-
return (defaultValue)
|
|
11
|
-
if (!target)
|
|
12
|
-
return defaultValue;
|
|
10
|
+
return (defaultValue)=>{
|
|
11
|
+
if (!target) return defaultValue;
|
|
13
12
|
return target[property] ?? defaultValue;
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
|
-
return (key, defaultValue)
|
|
15
|
+
return (key, defaultValue)=>{
|
|
17
16
|
if (key) {
|
|
18
17
|
return target[property]?.[key] ?? defaultValue;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
18
|
+
} else {
|
|
21
19
|
return target[property];
|
|
22
20
|
}
|
|
23
21
|
};
|
|
24
|
-
}
|
|
22
|
+
}
|
|
25
23
|
});
|
|
26
24
|
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=createGetter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/createGetter.ts"],"sourcesContent":["import { API } from \"@orderly.network/types\";\nimport { isNil } from \"ramda\";\n\ntype objectDepth = 1 | 2;\ntype propertyType<D, K, F> = D extends 1 ? K : F;\n\n// {\n// // [P in K]: (key: P, defaultValue?: T[P]) => T[K][P];\n// [P in K]: (key: P, defaultValue?: T[P]) => T[K][P];\n// }\n\n// type KeyOf<T> = keyof T;\ntype ValueOf<T> = T[keyof T];\n\n// export function createGetter<T extends Record<string, any>, K extends keyof T>(\nexport function createGetter<\n T extends any,\n K extends string = string,\n Key = keyof T\n>(\n data: Record<string, T> | null | undefined,\n depth: objectDepth = 2\n): (typeof depth extends 1\n ? { [P in K]: (defaultValue?: any) => any }\n : { [P in K]: (key?: Key, defaultValue?: ValueOf<T>) => any }) & {\n isNil: boolean;\n} {\n return new Proxy(data || {}, {\n get(\n target: any,\n property: propertyType<typeof depth, keyof T, any>,\n receiver\n ): any {\n if (property === \"isNil\") {\n return isNil(data);\n }\n if (depth === 1) {\n return (defaultValue: any) => {\n if (!target) return defaultValue;\n return target[property] ?? defaultValue;\n };\n }\n return (key?: Key, defaultValue?: any) => {\n if (key) {\n return (target as any)[property]?.[key] ?? defaultValue;\n } else {\n return target[property];\n }\n };\n },\n });\n}\n"],"names":["isNil","createGetter","data","depth","Proxy","get","target","property","receiver","defaultValue","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,KAAK,QAAQ,QAAQ;AAa9B,kFAAkF;AAClF,OAAO,SAASC,aAKdC,IAA0C,EAC1CC,QAAqB,CAAC;IAMtB,OAAO,IAAIC,MAAMF,QAAQ,CAAC,GAAG;QAC3BG,KACEC,MAAW,EACXC,QAAkD,EAClDC,QAAQ;YAER,IAAID,aAAa,SAAS;gBACxB,OAAOP,MAAME;YACf;YACA,IAAIC,UAAU,GAAG;gBACf,OAAO,CAACM;oBACN,IAAI,CAACH,QAAQ,OAAOG;oBACpB,OAAOH,MAAM,CAACC,SAAS,IAAIE;gBAC7B;YACF;YACA,OAAO,CAACC,KAAWD;gBACjB,IAAIC,KAAK;oBACP,OAAO,AAACJ,MAAc,CAACC,SAAS,EAAE,CAACG,IAAI,IAAID;gBAC7C,OAAO;oBACL,OAAOH,MAAM,CAACC,SAAS;gBACzB;YACF;QACF;IACF;AACF"}
|
|
@@ -22,6 +22,7 @@ export declare abstract class BaseOrderCreator implements OrderCreator {
|
|
|
22
22
|
baseValidate(values: OrderFormEntity, configs: ValuesDepConfig): Promise<VerifyResult>;
|
|
23
23
|
fixOrderQuantity(order: Partial<OrderEntity>, config: ValuesDepConfig): OrderEntity;
|
|
24
24
|
}
|
|
25
|
+
export declare function checkNotional(price?: string | number, qty?: string | number, minNotional?: number): string | undefined;
|
|
25
26
|
export declare class LimitOrderCreator extends BaseOrderCreator {
|
|
26
27
|
create(values: OrderEntity, config: ValuesDepConfig): OrderEntity;
|
|
27
28
|
validate(values: OrderFormEntity, config: ValuesDepConfig): Promise<VerifyResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOrder.d.ts","sourceRoot":"","sources":["../../src/utils/createOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;A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6,11 @@ export class BaseOrderCreator {
|
|
|
6
6
|
baseOrder(data) {
|
|
7
7
|
const order = {
|
|
8
8
|
symbol: data.symbol,
|
|
9
|
-
order_type: data.order_type === OrderType.LIMIT
|
|
10
|
-
? !!data.order_type_ext
|
|
11
|
-
? data.order_type_ext
|
|
12
|
-
: data.order_type
|
|
13
|
-
: data.order_type,
|
|
9
|
+
order_type: data.order_type === OrderType.LIMIT ? !!data.order_type_ext ? data.order_type_ext : data.order_type : data.order_type,
|
|
14
10
|
side: data.side,
|
|
15
11
|
reduce_only: data.reduce_only,
|
|
16
12
|
order_quantity: data.order_quantity,
|
|
17
|
-
total: data.total
|
|
13
|
+
total: data.total
|
|
18
14
|
};
|
|
19
15
|
if (data.visible_quantity === 0) {
|
|
20
16
|
order.visible_quantity = data.visible_quantity;
|
|
@@ -23,8 +19,10 @@ export class BaseOrderCreator {
|
|
|
23
19
|
}
|
|
24
20
|
baseValidate(values, configs) {
|
|
25
21
|
const errors = {};
|
|
26
|
-
const { maxQty } = configs;
|
|
27
|
-
|
|
22
|
+
const { maxQty, symbol } = configs;
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
let { order_quantity, total, order_price, reduce_only } = values;
|
|
25
|
+
const { min_notional } = symbol;
|
|
28
26
|
if (!order_quantity) {
|
|
29
27
|
// calculate order_quantity from total
|
|
30
28
|
if (total && order_price) {
|
|
@@ -37,24 +35,22 @@ export class BaseOrderCreator {
|
|
|
37
35
|
if (!order_quantity) {
|
|
38
36
|
errors.order_quantity = {
|
|
39
37
|
type: "required",
|
|
40
|
-
message: "quantity is required"
|
|
38
|
+
message: "quantity is required"
|
|
41
39
|
};
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
40
|
+
} else {
|
|
44
41
|
// need to use MaxQty+base_max, base_min to compare
|
|
45
42
|
const { base_min, quote_dp, base_dp } = configs.symbol;
|
|
46
43
|
const qty = new Decimal(order_quantity);
|
|
47
44
|
if (qty.lt(base_min)) {
|
|
48
45
|
errors.order_quantity = {
|
|
49
46
|
type: "min",
|
|
50
|
-
message: `quantity must be greater than ${new Decimal(base_min).todp(base_dp)}
|
|
47
|
+
message: `quantity must be greater than ${new Decimal(base_min).todp(base_dp)}`
|
|
51
48
|
};
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
else if (qty.gt(maxQty)) {
|
|
49
|
+
// errors.order_quantity = `quantity must be greater than ${base_min}`;
|
|
50
|
+
} else if (qty.gt(maxQty)) {
|
|
55
51
|
errors.order_quantity = {
|
|
56
52
|
type: "max",
|
|
57
|
-
message: `quantity must be less than ${new Decimal(maxQty).todp(base_dp)}
|
|
53
|
+
message: `quantity must be less than ${new Decimal(maxQty).todp(base_dp)}`
|
|
58
54
|
};
|
|
59
55
|
}
|
|
60
56
|
}
|
|
@@ -64,16 +60,22 @@ export class BaseOrderCreator {
|
|
|
64
60
|
if (totalNumber.lt(quote_min)) {
|
|
65
61
|
errors.total = {
|
|
66
62
|
type: "min",
|
|
67
|
-
message: `Quantity must be at least ${new Decimal(quote_min).todp(quote_dp)}
|
|
63
|
+
message: `Quantity must be at least ${new Decimal(quote_min).todp(quote_dp)}`
|
|
68
64
|
};
|
|
69
|
-
}
|
|
70
|
-
else if (totalNumber.gt(quote_max)) {
|
|
65
|
+
} else if (totalNumber.gt(quote_max)) {
|
|
71
66
|
errors.total = {
|
|
72
67
|
type: "max",
|
|
73
|
-
message: `Quantity should be less or equal than ${new Decimal(quote_max).todp(quote_dp)}
|
|
68
|
+
message: `Quantity should be less or equal than ${new Decimal(quote_max).todp(quote_dp)}`
|
|
74
69
|
};
|
|
75
70
|
}
|
|
76
71
|
}
|
|
72
|
+
const notionalHintStr = checkNotional(order_price, order_quantity, min_notional);
|
|
73
|
+
if (notionalHintStr !== undefined && reduce_only !== true) {
|
|
74
|
+
errors.total = {
|
|
75
|
+
type: "min",
|
|
76
|
+
message: notionalHintStr
|
|
77
|
+
};
|
|
78
|
+
}
|
|
77
79
|
return Promise.resolve(errors);
|
|
78
80
|
}
|
|
79
81
|
fixOrderQuantity(order, config) {
|
|
@@ -88,11 +90,24 @@ export class BaseOrderCreator {
|
|
|
88
90
|
return order;
|
|
89
91
|
}
|
|
90
92
|
}
|
|
93
|
+
export function checkNotional(price, qty, minNotional) {
|
|
94
|
+
if (price !== undefined && qty !== undefined && minNotional !== undefined) {
|
|
95
|
+
try {
|
|
96
|
+
const calcNotional = new Decimal(price).mul(new Decimal(qty)).toNumber();
|
|
97
|
+
const notional = Number.parseFloat(`${minNotional}`);
|
|
98
|
+
const str = calcNotional < notional ? `The order value should be greater or equal to ${minNotional} USDC` : undefined;
|
|
99
|
+
return str;
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
91
106
|
export class LimitOrderCreator extends BaseOrderCreator {
|
|
92
107
|
create(values, config) {
|
|
93
108
|
const order = {
|
|
94
109
|
...this.baseOrder(values),
|
|
95
|
-
order_price: values.order_price
|
|
110
|
+
order_price: values.order_price
|
|
96
111
|
};
|
|
97
112
|
this.fixOrderQuantity(order, config);
|
|
98
113
|
delete order['total'];
|
|
@@ -105,17 +120,16 @@ export class LimitOrderCreator extends BaseOrderCreator {
|
|
|
105
120
|
return order;
|
|
106
121
|
}
|
|
107
122
|
validate(values, config) {
|
|
108
|
-
return this.baseValidate(values, config).then((errors)
|
|
123
|
+
return this.baseValidate(values, config).then((errors)=>{
|
|
109
124
|
// const errors = this.baseValidate(values, config);
|
|
110
125
|
// @ts-ignore
|
|
111
126
|
const { order_price, side } = values;
|
|
112
127
|
if (!order_price) {
|
|
113
128
|
errors.order_price = {
|
|
114
129
|
type: "required",
|
|
115
|
-
message: "price is required"
|
|
130
|
+
message: "price is required"
|
|
116
131
|
};
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
132
|
+
} else {
|
|
119
133
|
const price = new Decimal(order_price);
|
|
120
134
|
const { symbol } = config;
|
|
121
135
|
const { price_range, price_scope } = symbol;
|
|
@@ -124,7 +138,7 @@ export class LimitOrderCreator extends BaseOrderCreator {
|
|
|
124
138
|
const scropePriceNumbere = scropePrice(config.markPrice, price_scope, side);
|
|
125
139
|
const priceRange = side === "BUY" ? {
|
|
126
140
|
min: scropePriceNumbere,
|
|
127
|
-
max: maxPriceNumber
|
|
141
|
+
max: maxPriceNumber
|
|
128
142
|
} : {
|
|
129
143
|
min: minPriceNumber,
|
|
130
144
|
max: scropePriceNumbere
|
|
@@ -134,13 +148,13 @@ export class LimitOrderCreator extends BaseOrderCreator {
|
|
|
134
148
|
if (price.gt(priceRange?.max)) {
|
|
135
149
|
errors.order_price = {
|
|
136
150
|
type: "max",
|
|
137
|
-
message: `Price must be less than ${new Decimal(priceRange.max).todp(symbol.quote_dp)}
|
|
151
|
+
message: `Price must be less than ${new Decimal(priceRange.max).todp(symbol.quote_dp)}`
|
|
138
152
|
};
|
|
139
153
|
}
|
|
140
154
|
if (price.lt(priceRange?.min)) {
|
|
141
155
|
errors.order_price = {
|
|
142
156
|
type: "min",
|
|
143
|
-
message: `Price must be greater than ${new Decimal(priceRange.min).todp(symbol.quote_dp)}
|
|
157
|
+
message: `Price must be greater than ${new Decimal(priceRange.min).todp(symbol.quote_dp)}`
|
|
144
158
|
};
|
|
145
159
|
}
|
|
146
160
|
}
|
|
@@ -156,7 +170,7 @@ export class MarketOrderCreator extends BaseOrderCreator {
|
|
|
156
170
|
delete data['trigger_price'];
|
|
157
171
|
delete data['isStopOrder'];
|
|
158
172
|
return {
|
|
159
|
-
...data
|
|
173
|
+
...data
|
|
160
174
|
};
|
|
161
175
|
}
|
|
162
176
|
validate(values, configs) {
|
|
@@ -179,7 +193,7 @@ export class StopLimitOrderCreator extends LimitOrderCreator {
|
|
|
179
193
|
type: "LIMIT",
|
|
180
194
|
quantity: values["order_quantity"],
|
|
181
195
|
price: values["order_price"],
|
|
182
|
-
trigger_price_type: "MARK_PRICE"
|
|
196
|
+
trigger_price_type: "MARK_PRICE"
|
|
183
197
|
};
|
|
184
198
|
this.fixOrderQuantity(order, config);
|
|
185
199
|
delete order["order_quantity"];
|
|
@@ -199,20 +213,20 @@ export class StopLimitOrderCreator extends LimitOrderCreator {
|
|
|
199
213
|
return order;
|
|
200
214
|
}
|
|
201
215
|
validate(values, config) {
|
|
202
|
-
return this.baseValidate(values, config).then((errors)
|
|
216
|
+
return this.baseValidate(values, config).then((errors)=>{
|
|
203
217
|
// const errors = this.baseValidate(values, config);
|
|
204
218
|
// @ts-ignore
|
|
205
219
|
const { order_price, trigger_price, side } = values;
|
|
206
220
|
if (!order_price) {
|
|
207
221
|
errors.order_price = {
|
|
208
222
|
type: "required",
|
|
209
|
-
message: "price is required"
|
|
223
|
+
message: "price is required"
|
|
210
224
|
};
|
|
211
225
|
}
|
|
212
226
|
if (!trigger_price) {
|
|
213
227
|
errors.trigger_price = {
|
|
214
228
|
type: "required",
|
|
215
|
-
message: "Trigger price is required"
|
|
229
|
+
message: "Trigger price is required"
|
|
216
230
|
};
|
|
217
231
|
}
|
|
218
232
|
if (trigger_price && order_price) {
|
|
@@ -224,7 +238,7 @@ export class StopLimitOrderCreator extends LimitOrderCreator {
|
|
|
224
238
|
const scropePriceNumbere = scropePrice(trigger_price, price_scope, side);
|
|
225
239
|
const priceRange = side === "BUY" ? {
|
|
226
240
|
min: scropePriceNumbere,
|
|
227
|
-
max: maxPriceNumber
|
|
241
|
+
max: maxPriceNumber
|
|
228
242
|
} : {
|
|
229
243
|
min: minPriceNumber,
|
|
230
244
|
max: scropePriceNumbere
|
|
@@ -234,13 +248,13 @@ export class StopLimitOrderCreator extends LimitOrderCreator {
|
|
|
234
248
|
if (price.gt(priceRange?.max)) {
|
|
235
249
|
errors.order_price = {
|
|
236
250
|
type: "max",
|
|
237
|
-
message: `Price must be less than ${new Decimal(priceRange.max).todp(symbol.quote_dp)}
|
|
251
|
+
message: `Price must be less than ${new Decimal(priceRange.max).todp(symbol.quote_dp)}`
|
|
238
252
|
};
|
|
239
253
|
}
|
|
240
254
|
if (price.lt(priceRange?.min)) {
|
|
241
255
|
errors.order_price = {
|
|
242
256
|
type: "min",
|
|
243
|
-
message: `Price must be greater than ${new Decimal(priceRange.min).todp(symbol.quote_dp)}
|
|
257
|
+
message: `Price must be greater than ${new Decimal(priceRange.min).todp(symbol.quote_dp)}`
|
|
244
258
|
};
|
|
245
259
|
}
|
|
246
260
|
}
|
|
@@ -258,7 +272,7 @@ export class StopMarketOrderCreator extends LimitOrderCreator {
|
|
|
258
272
|
type: "MARKET",
|
|
259
273
|
quantity: values["order_quantity"],
|
|
260
274
|
// price: values["order_price"],
|
|
261
|
-
trigger_price_type: "MARK_PRICE"
|
|
275
|
+
trigger_price_type: "MARK_PRICE"
|
|
262
276
|
};
|
|
263
277
|
delete result["order_quantity"];
|
|
264
278
|
delete result["order_price"];
|
|
@@ -267,18 +281,18 @@ export class StopMarketOrderCreator extends LimitOrderCreator {
|
|
|
267
281
|
// @ts-ignore
|
|
268
282
|
delete result["isStopOrder"];
|
|
269
283
|
delete result['total'];
|
|
270
|
-
|
|
284
|
+
;
|
|
271
285
|
return result;
|
|
272
286
|
}
|
|
273
287
|
validate(values, config) {
|
|
274
|
-
return this.baseValidate(values, config).then((errors)
|
|
288
|
+
return this.baseValidate(values, config).then((errors)=>{
|
|
275
289
|
// const errors = this.baseValidate(values, config);
|
|
276
290
|
// @ts-ignore
|
|
277
291
|
const { order_price, trigger_price, side } = values;
|
|
278
292
|
if (!trigger_price) {
|
|
279
293
|
errors.trigger_price = {
|
|
280
294
|
type: "required",
|
|
281
|
-
message: "Trigger price is required"
|
|
295
|
+
message: "Trigger price is required"
|
|
282
296
|
};
|
|
283
297
|
}
|
|
284
298
|
return errors;
|
|
@@ -290,7 +304,7 @@ export class GeneralOrderCreator extends BaseOrderCreator {
|
|
|
290
304
|
return {
|
|
291
305
|
...this.baseOrder(data),
|
|
292
306
|
order_price: data.order_price,
|
|
293
|
-
order_quantity: data.order_quantity
|
|
307
|
+
order_quantity: data.order_quantity
|
|
294
308
|
};
|
|
295
309
|
}
|
|
296
310
|
validate(values, configs) {
|
|
@@ -304,11 +318,11 @@ export const availableOrderTypes = [
|
|
|
304
318
|
OrderType.FOK,
|
|
305
319
|
OrderType.POST_ONLY,
|
|
306
320
|
OrderType.STOP_LIMIT,
|
|
307
|
-
OrderType.STOP_MARKET
|
|
321
|
+
OrderType.STOP_MARKET
|
|
308
322
|
];
|
|
309
323
|
export class OrderFactory {
|
|
310
324
|
static create(type) {
|
|
311
|
-
switch
|
|
325
|
+
switch(type){
|
|
312
326
|
case OrderType.LIMIT:
|
|
313
327
|
return new LimitOrderCreator();
|
|
314
328
|
case OrderType.MARKET:
|
|
@@ -332,3 +346,5 @@ export class OrderFactory {
|
|
|
332
346
|
}
|
|
333
347
|
}
|
|
334
348
|
}
|
|
349
|
+
|
|
350
|
+
//# sourceMappingURL=createOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/createOrder.ts"],"sourcesContent":["import { OrderType, type API, OrderEntity } from \"@orderly.network/types\";\nimport { Decimal } from \"@orderly.network/utils\";\nimport { order } from \"@orderly.network/perp\";\nimport { OrderSide } from \"@orderly.network/types\";\n\nexport type VerifyResult = {\n [P in keyof OrderEntity]?: { type: string; message: string };\n};\nexport type OrderFormEntity = Pick<\n OrderEntity,\n \"order_price\" | \"order_quantity\" | \"total\"\n>;\n\ntype ValuesDepConfig = {\n // token: API.TokenInfo;\n symbol: API.SymbolExt;\n maxQty: number;\n markPrice: number;\n};\n\nexport interface OrderCreator {\n create: (values: OrderEntity, configs: ValuesDepConfig) => OrderEntity;\n validate: (\n values: OrderFormEntity,\n configs: ValuesDepConfig\n ) => Promise<VerifyResult>;\n}\n\nconst { maxPrice, minPrice, scropePrice } = order;\n\nexport abstract class BaseOrderCreator implements OrderCreator {\n abstract create(values: OrderEntity, config: ValuesDepConfig): OrderEntity;\n abstract validate(\n values: OrderFormEntity,\n config: ValuesDepConfig\n ): Promise<VerifyResult>;\n\n baseOrder(data: OrderEntity): OrderEntity {\n const order: Partial<OrderEntity> = {\n symbol: data.symbol,\n order_type:\n data.order_type === OrderType.LIMIT\n ? !!data.order_type_ext\n ? data.order_type_ext\n : data.order_type\n : data.order_type,\n side: data.side,\n reduce_only: data.reduce_only,\n order_quantity: data.order_quantity,\n total: data.total,\n };\n\n if (data.visible_quantity === 0) {\n order.visible_quantity = data.visible_quantity;\n }\n\n return order as OrderEntity;\n }\n\n baseValidate(\n values: OrderFormEntity,\n configs: ValuesDepConfig\n ): Promise<VerifyResult> {\n const errors: {\n [P in keyof OrderEntity]?: { type: string; message: string };\n } = {};\n\n const { maxQty, symbol } = configs;\n\n // @ts-ignore\n let { order_quantity, total, order_price, reduce_only } = values;\n const { min_notional } = symbol;\n\n if (!order_quantity) {\n // calculate order_quantity from total\n if (total && order_price) {\n const { quote_dp } = configs.symbol;\n const totalNumber = new Decimal(total);\n const qty = totalNumber.dividedBy(order_price).toFixed(quote_dp);\n order_quantity = qty;\n }\n }\n\n if (!order_quantity) {\n errors.order_quantity = {\n type: \"required\",\n message: \"quantity is required\",\n };\n } else {\n // need to use MaxQty+base_max, base_min to compare\n const { base_min, quote_dp, base_dp } = configs.symbol;\n const qty = new Decimal(order_quantity);\n if (qty.lt(base_min)) {\n errors.order_quantity = {\n type: \"min\",\n message: `quantity must be greater than ${new Decimal(base_min).todp(\n base_dp\n )}`,\n };\n // errors.order_quantity = `quantity must be greater than ${base_min}`;\n } else if (qty.gt(maxQty)) {\n errors.order_quantity = {\n type: \"max\",\n message: `quantity must be less than ${new Decimal(maxQty).todp(\n base_dp\n )}`,\n };\n }\n }\n\n if (!!total) {\n const { quote_max, quote_min, quote_dp } = configs.symbol;\n const totalNumber = new Decimal(total);\n if (totalNumber.lt(quote_min)) {\n errors.total = {\n type: \"min\",\n message: `Quantity must be at least ${new Decimal(quote_min).todp(\n quote_dp\n )}`,\n };\n } else if (totalNumber.gt(quote_max)) {\n errors.total = {\n type: \"max\",\n message: `Quantity should be less or equal than ${new Decimal(\n quote_max\n ).todp(quote_dp)}`,\n };\n }\n }\n\n const notionalHintStr = checkNotional(order_price, order_quantity, min_notional);\n \n if (notionalHintStr !== undefined && reduce_only !== true) {\n errors.total = {\n type: \"min\",\n message: notionalHintStr,\n }\n }\n\n return Promise.resolve(errors);\n }\n\n fixOrderQuantity(\n order: Partial<OrderEntity>,\n config: ValuesDepConfig\n ): OrderEntity {\n // if order_quantity is not set but total is set, calculate order_quantity from total\n if (!order.order_quantity && order.total && order.order_price) {\n const { base_dp } = config.symbol;\n const totalNumber = new Decimal(order.total);\n const qty = totalNumber.div(order.order_price).toDecimalPlaces(base_dp);\n order.order_quantity = qty.toNumber();\n\n delete order.total;\n }\n\n return order as OrderEntity;\n }\n}\n\nexport function checkNotional(price?: string | number, qty?: string | number, minNotional?: number): string | undefined {\n\n \n \n if (price !== undefined && qty !== undefined && minNotional !== undefined) {\n \n try {\n const calcNotional = new Decimal(price).mul(new Decimal(qty)).toNumber();\n const notional = Number.parseFloat(`${minNotional}`);\n \n const str = calcNotional < notional ? `The order value should be greater or equal to ${minNotional} USDC` : undefined;\n return str;\n } catch (e) {\n return undefined;\n }\n }\n\n return undefined;\n}\n\nexport class LimitOrderCreator extends BaseOrderCreator {\n create(values: OrderEntity, config: ValuesDepConfig): OrderEntity {\n const order = {\n ...this.baseOrder(values),\n order_price: values.order_price,\n };\n\n this.fixOrderQuantity(order, config);\n\n delete order['total'];\n delete order['trigger_price'];\n delete order['isStopOrder'];\n\n const { quote_dp } = config.symbol;\n if (values.order_price) {\n order[\"order_price\"] = new Decimal(Number.parseFloat(values.order_price.toString())).toFixed(quote_dp, Decimal.ROUND_DOWN);\n }\n\n return order;\n }\n validate(\n values: OrderFormEntity,\n config: ValuesDepConfig\n ): Promise<VerifyResult> {\n return this.baseValidate(values, config).then((errors) => {\n // const errors = this.baseValidate(values, config);\n // @ts-ignore\n const { order_price, side } = values;\n\n if (!order_price) {\n errors.order_price = {\n type: \"required\",\n message: \"price is required\",\n };\n } else {\n const price = new Decimal(order_price);\n const { symbol } = config;\n const { price_range, price_scope } = symbol;\n const maxPriceNumber = maxPrice(config.markPrice, price_range);\n const minPriceNumber = minPrice(config.markPrice, price_range);\n const scropePriceNumbere = scropePrice(\n config.markPrice,\n price_scope,\n side\n );\n\n const priceRange = side === \"BUY\" ? {\n min: scropePriceNumbere,\n max: maxPriceNumber,\n } : {\n min: minPriceNumber,\n max: scropePriceNumbere\n };\n\n /// if side is 'buy', only check max price,\n /// if side is 'sell', only check min price,\n if (price.gt(priceRange?.max)) {\n errors.order_price = {\n type: \"max\",\n message: `Price must be less than ${new Decimal(\n priceRange.max\n ).todp(symbol.quote_dp)}`,\n };\n }\n if (price.lt(priceRange?.min)) {\n errors.order_price = {\n type: \"min\",\n message: `Price must be greater than ${new Decimal(\n priceRange.min\n ).todp(symbol.quote_dp)}`,\n };\n }\n\n }\n\n return errors;\n });\n }\n}\n\nexport class MarketOrderCreator extends BaseOrderCreator {\n create(values: OrderEntity): OrderEntity {\n const data = this.baseOrder(values);\n\n delete data[\"order_price\"];\n delete data['total'];\n delete data['trigger_price'];\n delete data['isStopOrder'];\n\n return {\n ...data,\n };\n }\n validate(\n values: OrderFormEntity,\n configs: ValuesDepConfig\n ): Promise<VerifyResult> {\n return this.baseValidate(values, configs);\n }\n}\n\nexport class PostOnlyOrderCreator extends LimitOrderCreator { }\n\nexport class FOKOrderCreator extends LimitOrderCreator { }\nexport class IOCOrderCreator extends LimitOrderCreator { }\n\nexport class StopLimitOrderCreator extends LimitOrderCreator {\n create(values: OrderEntity, config: ValuesDepConfig): OrderEntity {\n const order = {\n ...this.baseOrder(values),\n order_price: values.order_price,\n trigger_price: values.trigger_price,\n algo_type: \"STOP\",\n type: \"LIMIT\",\n quantity: values[\"order_quantity\"],\n price: values[\"order_price\"],\n trigger_price_type: \"MARK_PRICE\",\n };\n this.fixOrderQuantity(order, config);\n delete order[\"order_quantity\"];\n delete order[\"order_price\"];\n // @ts-ignore\n delete order[\"order_type\"];\n // @ts-ignore\n delete order[\"isStopOrder\"];\n delete order['total'];\n\n const { quote_dp } = config.symbol;\n if (values.order_price) {\n order[\"order_price\"] = new Decimal(Number.parseFloat(values.order_price.toString())).toFixed(quote_dp, Decimal.ROUND_DOWN);\n }\n \n if (values.trigger_price) {\n order[\"trigger_price\"] = new Decimal(Number.parseFloat(values.trigger_price.toString())).toFixed(quote_dp, Decimal.ROUND_DOWN);\n }\n\n return order;\n }\n validate(\n values: OrderFormEntity,\n config: ValuesDepConfig\n ): Promise<VerifyResult> {\n return this.baseValidate(values, config).then((errors) => {\n // const errors = this.baseValidate(values, config);\n // @ts-ignore\n const { order_price, trigger_price, side } = values;\n\n if (!order_price) {\n errors.order_price = {\n type: \"required\",\n message: \"price is required\",\n };\n }\n \n if (!trigger_price) {\n errors.trigger_price = {\n type: \"required\",\n message: \"Trigger price is required\",\n };\n } \n \n if (trigger_price && order_price) {\n const price = new Decimal(order_price);\n const { symbol } = config;\n const { price_range, price_scope } = symbol;\n const maxPriceNumber = maxPrice(trigger_price, price_range);\n const minPriceNumber = minPrice(trigger_price, price_range);\n const scropePriceNumbere = scropePrice(\n trigger_price,\n price_scope,\n side\n );\n\n const priceRange = side === \"BUY\" ? {\n min: scropePriceNumbere,\n max: maxPriceNumber,\n } : {\n min: minPriceNumber,\n max: scropePriceNumbere\n };\n\n /// if side is 'buy', only check max price,\n /// if side is 'sell', only check min price,\n if (price.gt(priceRange?.max)) {\n errors.order_price = {\n type: \"max\",\n message: `Price must be less than ${new Decimal(\n priceRange.max\n ).todp(symbol.quote_dp)}`,\n };\n }\n if (price.lt(priceRange?.min)) {\n errors.order_price = {\n type: \"min\",\n message: `Price must be greater than ${new Decimal(\n priceRange.min\n ).todp(symbol.quote_dp)}`,\n };\n }\n }\n\n return errors;\n });\n }\n}\nexport class StopMarketOrderCreator extends LimitOrderCreator {\n create(values: OrderEntity, _: ValuesDepConfig): OrderEntity {\n const result = {\n ...this.baseOrder(values),\n // order_price: values.order_price,\n trigger_price: values.trigger_price,\n algo_type: \"STOP\",\n type: \"MARKET\",\n quantity: values[\"order_quantity\"],\n // price: values[\"order_price\"],\n trigger_price_type: \"MARK_PRICE\",\n };\n delete result[\"order_quantity\"];\n delete result[\"order_price\"];\n // @ts-ignore\n delete result[\"order_type\"];\n // @ts-ignore\n delete result[\"isStopOrder\"];\n delete result['total'];\n\n console.log(\"result is\", result);\n return result;\n }\n validate(\n values: OrderFormEntity,\n config: ValuesDepConfig\n ): Promise<VerifyResult> {\n return this.baseValidate(values, config).then((errors) => {\n // const errors = this.baseValidate(values, config);\n // @ts-ignore\n const { order_price, trigger_price, side } = values;\n\n if (!trigger_price) {\n errors.trigger_price = {\n type: \"required\",\n message: \"Trigger price is required\",\n };\n }\n\n return errors;\n });\n }\n}\n\nexport class GeneralOrderCreator extends BaseOrderCreator {\n create(data: OrderEntity): OrderEntity {\n return {\n ...this.baseOrder(data),\n order_price: data.order_price,\n order_quantity: data.order_quantity,\n };\n }\n validate(\n values: OrderFormEntity,\n configs: ValuesDepConfig\n ): Promise<VerifyResult> {\n return super.baseValidate(values, configs);\n }\n}\n\nexport const availableOrderTypes = [\n OrderType.LIMIT,\n OrderType.MARKET,\n OrderType.IOC,\n OrderType.FOK,\n OrderType.POST_ONLY,\n OrderType.STOP_LIMIT,\n OrderType.STOP_MARKET,\n];\n\nexport class OrderFactory {\n static create(type: OrderType): OrderCreator | null {\n switch (type) {\n case OrderType.LIMIT:\n return new LimitOrderCreator();\n case OrderType.MARKET:\n return new MarketOrderCreator();\n // case OrderType.ASK:\n // return new AskOrderCreator();\n // case OrderType.BID:\n // return new BidOrderCreator();\n case OrderType.IOC:\n return new IOCOrderCreator();\n case OrderType.FOK:\n return new FOKOrderCreator();\n case OrderType.POST_ONLY:\n return new PostOnlyOrderCreator();\n\n case OrderType.STOP_LIMIT:\n return new StopLimitOrderCreator();\n case OrderType.STOP_MARKET:\n return new StopMarketOrderCreator();\n\n default:\n return new GeneralOrderCreator();\n }\n }\n}\n"],"names":["OrderType","Decimal","order","maxPrice","minPrice","scropePrice","BaseOrderCreator","baseOrder","data","symbol","order_type","LIMIT","order_type_ext","side","reduce_only","order_quantity","total","visible_quantity","baseValidate","values","configs","errors","maxQty","order_price","min_notional","quote_dp","totalNumber","qty","dividedBy","toFixed","type","message","base_min","base_dp","lt","todp","gt","quote_max","quote_min","notionalHintStr","checkNotional","undefined","Promise","resolve","fixOrderQuantity","config","div","toDecimalPlaces","toNumber","price","minNotional","calcNotional","mul","notional","Number","parseFloat","str","e","LimitOrderCreator","create","toString","ROUND_DOWN","validate","then","price_range","price_scope","maxPriceNumber","markPrice","minPriceNumber","scropePriceNumbere","priceRange","min","max","MarketOrderCreator","PostOnlyOrderCreator","FOKOrderCreator","IOCOrderCreator","StopLimitOrderCreator","trigger_price","algo_type","quantity","trigger_price_type","StopMarketOrderCreator","_","result","GeneralOrderCreator","availableOrderTypes","MARKET","IOC","FOK","POST_ONLY","STOP_LIMIT","STOP_MARKET","OrderFactory"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,SAAS,QAA+B,yBAAyB;AAC1E,SAASC,OAAO,QAAQ,yBAAyB;AACjD,SAASC,KAAK,QAAQ,wBAAwB;AA0B9C,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,WAAW,EAAE,GAAGH;AA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AiB,EAAe;QACrC,OAAO;YACL,GAAG,IAAI,CAACD,SAAS,CAACC,KAAK;YACvBe,aAAaf,KAAKe,WAAW;YAC7BR,gBAAgBP,KAAKO,cAAc;QACrC;IACF;IACA+C,SACE3C,MAAuB,EACvBC,OAAwB,EACD;QACvB,OAAO,KAAK,CAACF,aAAaC,QAAQC;IACpC;AACF;AAEA,OAAO,MAAMkE,sBAAsB;IACjCtF,UAAUW,KAAK;IACfX,UAAUuF,MAAM;IAChBvF,UAAUwF,GAAG;IACbxF,UAAUyF,GAAG;IACbzF,UAAU0F,SAAS;IACnB1F,UAAU2F,UAAU;IACpB3F,UAAU4F,WAAW;CACtB,CAAC;AAEF,OAAO,MAAMC;IACX,OAAOlC,OAAO7B,IAAe,EAAuB;QAClD,OAAQA;YACN,KAAK9B,UAAUW,KAAK;gBAClB,OAAO,IAAI+C;YACb,KAAK1D,UAAUuF,MAAM;gBACnB,OAAO,IAAId;YACb,wBAAwB;YACxB,oCAAoC;YACpC,wBAAwB;YACxB,oCAAoC;YACpC,KAAKzE,UAAUwF,GAAG;gBAChB,OAAO,IAAIZ;YACb,KAAK5E,UAAUyF,GAAG;gBAChB,OAAO,IAAId;YACb,KAAK3E,UAAU0F,SAAS;gBACtB,OAAO,IAAIhB;YAEb,KAAK1E,UAAU2F,UAAU;gBACvB,OAAO,IAAId;YACb,KAAK7E,UAAU4F,WAAW;gBACxB,OAAO,IAAIV;YAEb;gBACE,OAAO,IAAIG;QACf;IACF;AACF"}
|
package/esm/utils/dev.js
CHANGED
|
@@ -4,10 +4,10 @@ const __ORDERLY__DEBUGER_TAG = "__ORDERLY__DEBUGER";
|
|
|
4
4
|
function debugPrint(msg, tag) {
|
|
5
5
|
tag = `${__ORDERLY__DEBUGER_TAG}:${tag} `;
|
|
6
6
|
if (!getGlobalObject().__ORDERLY__DEBUGER) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
;
|
|
8
|
+
// console.info(
|
|
9
|
+
// "You can add `DebugPrinter` component to see the data in your UI"
|
|
10
|
+
// );
|
|
11
11
|
}
|
|
12
12
|
let ee = SimpleDI.get("EE");
|
|
13
13
|
if (ee && msg) {
|
|
@@ -17,3 +17,5 @@ function debugPrint(msg, tag) {
|
|
|
17
17
|
if (typeof window !== "undefined") {
|
|
18
18
|
window.debugPrint = debugPrint;
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/dev.ts"],"sourcesContent":["import { EventEmitter, SimpleDI } from \"@orderly.network/core\";\nimport { getGlobalObject } from \"@orderly.network/utils\";\n\nconst __ORDERLY__DEBUGER_TAG = \"__ORDERLY__DEBUGER\";\n\nfunction debugPrint(msg: any): void;\nfunction debugPrint(msg: any, tag?: string) {\n tag = `${__ORDERLY__DEBUGER_TAG}:${tag} `;\n if (!(getGlobalObject() as any).__ORDERLY__DEBUGER) {\n console.log(\"${tag}${msg}\");\n // console.info(\n // \"You can add `DebugPrinter` component to see the data in your UI\"\n // );\n }\n\n let ee = SimpleDI.get<EventEmitter>(\"EE\");\n\n if (ee && msg) {\n ee.emit(\"print:data\", msg);\n }\n}\n\nif (typeof window !== \"undefined\") {\n (window as any).debugPrint = debugPrint;\n}\n"],"names":["SimpleDI","getGlobalObject","__ORDERLY__DEBUGER_TAG","debugPrint","msg","tag","__ORDERLY__DEBUGER","ee","get","emit","window"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAAuBA,QAAQ,QAAQ,wBAAwB;AAC/D,SAASC,eAAe,QAAQ,yBAAyB;AAEzD,MAAMC,yBAAyB;AAG/B,SAASC,WAAWC,GAAQ,EAAEC,GAAY;IACxCA,MAAM,CAAC,EAAEH,uBAAuB,CAAC,EAAEG,IAAI,CAAC,CAAC;IACzC,IAAI,CAAC,AAACJ,kBAA0BK,kBAAkB,EAAE;;IAElD,gBAAgB;IAChB,sEAAsE;IACtE,KAAK;IACP;IAEA,IAAIC,KAAKP,SAASQ,GAAG,CAAe;IAEpC,IAAID,MAAMH,KAAK;QACbG,GAAGE,IAAI,CAAC,cAAcL;IACxB;AACF;AAEA,IAAI,OAAOM,WAAW,aAAa;IAChCA,OAAeP,UAAU,GAAGA;AAC/B"}
|
package/esm/utils/fetcher.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { get } from "@orderly.network/net";
|
|
2
|
-
export const fetcher = (url, init = {}, queryOptions)
|
|
2
|
+
export const fetcher = (url, init = {}, queryOptions)=>get(url, init, queryOptions?.formatter);
|
|
3
|
+
|
|
4
|
+
//# sourceMappingURL=fetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/fetcher.ts"],"sourcesContent":["import { get } from \"@orderly.network/net\";\nimport { type SWRConfiguration } from \"swr\";\n\nexport const fetcher = (\n url: string,\n init: RequestInit = {},\n queryOptions: useQueryOptions<any>\n) => get(url, init, queryOptions?.formatter);\n\nexport type useQueryOptions<T> = SWRConfiguration & {\n formatter?: (data: any) => T;\n};\n"],"names":["get","fetcher","url","init","queryOptions","formatter"],"rangeMappings":";","mappings":"AAAA,SAASA,GAAG,QAAQ,uBAAuB;AAG3C,OAAO,MAAMC,UAAU,CACrBC,KACAC,OAAoB,CAAC,CAAC,EACtBC,eACGJ,IAAIE,KAAKC,MAAMC,cAAcC,WAAW"}
|
package/esm/utils/json.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/json.ts"],"sourcesContent":["export function parseJSON<T>(value: string | null): T | undefined {\n try {\n return value === \"undefined\" ? undefined : JSON.parse(value ?? \"\");\n } catch {\n return undefined;\n }\n}\n"],"names":["parseJSON","value","undefined","JSON","parse"],"rangeMappings":";;;;;;","mappings":"AAAA,OAAO,SAASA,UAAaC,KAAoB;IAC/C,IAAI;QACF,OAAOA,UAAU,cAAcC,YAAYC,KAAKC,KAAK,CAACH,SAAS;IACjE,EAAE,OAAM;QACN,OAAOC;IACT;AACF"}
|