@orderly.network/hooks 2.12.4-alpha.0 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -10
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import useSWR5__default, { mutate } from 'swr';
|
|
|
4
4
|
import * as useSWR5 from 'swr';
|
|
5
5
|
export { useSWR5 as swr };
|
|
6
6
|
export { unstable_serialize, default as useSWR, useSWRConfig } from 'swr';
|
|
7
|
+
import { usePluginScope } from '@orderly.network/plugin-core';
|
|
7
8
|
import { TesnetTokenFallback, ArbitrumSepoliaTokenInfo, SolanaDevnetTokenInfo, MarginMode, OrderType, OrderSide, SDKError, TrackerEventName, AccountStatusEnum, AlgoOrderType, AlgoOrderRootType, OrderStatus, ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo, EMPTY_LIST, EMPTY_OBJECT, isNativeTokenChecker, nativeTokenAddress, ChainKey, chainsInfoMap, ARBITRUM_TESTNET_CHAINID, ARBITRUM_MAINNET_CHAINID, ChainNamespace, MaxUint256, DEPOSIT_FEE_RATE, ETHEREUM_MAINNET_CHAINID, LedgerWalletKey, SOLANA_TESTNET_CHAINID, MONAD_TESTNET_CHAINID, ABSTRACT_TESTNET_CHAINID, BSC_TESTNET_CHAINID, SolanaChains, PositionType, DistributionType, TriggerPriceType } from '@orderly.network/types';
|
|
8
9
|
import { zero, windowGuard, getTimestamp, getGlobalObject, Decimal, timeConvertString, isTestnet, getPrecisionByNumber, getBBOType, camelCaseToUnderscoreCase, commify, todpIfNeed, getTPSLDirection } from '@orderly.network/utils';
|
|
9
10
|
import useSWRMutation from 'swr/mutation';
|
|
@@ -49,9 +50,9 @@ function useMarketCategoriesConfig() {
|
|
|
49
50
|
// src/version.ts
|
|
50
51
|
if (typeof window !== "undefined") {
|
|
51
52
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
52
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "
|
|
53
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-alpha.0";
|
|
53
54
|
}
|
|
54
|
-
var version_default = "
|
|
55
|
+
var version_default = "3.0.0-alpha.0";
|
|
55
56
|
var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
|
|
56
57
|
var noCacheConfig = {
|
|
57
58
|
dedupingInterval: 0,
|
|
@@ -84,19 +85,26 @@ function useConfig(key, defaultValue) {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
// src/useQuery.ts
|
|
88
|
+
var PLUGIN_ID_HEADER = "X-Orderly-Plugin-Id";
|
|
87
89
|
var useQuery = (query, options) => {
|
|
88
90
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
91
|
+
const pluginScope = usePluginScope();
|
|
89
92
|
const { formatter, ...swrOptions } = options || {};
|
|
90
93
|
if (typeof apiBaseUrl === "undefined") {
|
|
91
94
|
throw new SDKError("please add OrderlyConfigProvider to your app");
|
|
92
95
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
const fetcherFn = useCallback(
|
|
97
|
+
(url, init2) => {
|
|
98
|
+
const fullUrl = url.startsWith("http") ? url : `${apiBaseUrl}${url}`;
|
|
99
|
+
const headers = new Headers(init2?.headers);
|
|
100
|
+
if (pluginScope?.pluginId) {
|
|
101
|
+
headers.set(PLUGIN_ID_HEADER, pluginScope.pluginId);
|
|
102
|
+
}
|
|
103
|
+
return fetcher(fullUrl, { ...init2, headers }, { formatter });
|
|
104
|
+
},
|
|
105
|
+
[apiBaseUrl, pluginScope?.pluginId, formatter]
|
|
99
106
|
);
|
|
107
|
+
return useSWR5__default(query, fetcherFn, swrOptions);
|
|
100
108
|
};
|
|
101
109
|
var timestampOffsetPromise = null;
|
|
102
110
|
var timestampOffsetReady = false;
|
|
@@ -19021,12 +19029,37 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
19021
19029
|
);
|
|
19022
19030
|
const bestAskBid = askAndBid.current?.[0] || [];
|
|
19023
19031
|
const referencePriceFromOrder = bestAskBid.length >= 2 && formattedOrder.order_type && formattedOrder.side ? getOrderReferencePriceFromOrder(formattedOrder, bestAskBid) : null;
|
|
19024
|
-
const
|
|
19032
|
+
const maxBuyQtyValue = useMaxQty(symbol, OrderSide.BUY, {
|
|
19025
19033
|
reduceOnly: formattedOrder.reduce_only,
|
|
19026
19034
|
marginMode: effectiveMarginMode,
|
|
19027
19035
|
currentOrderReferencePrice: referencePriceFromOrder && referencePriceFromOrder > 0 ? referencePriceFromOrder : void 0
|
|
19028
19036
|
});
|
|
19037
|
+
const maxSellQtyValue = useMaxQty(symbol, OrderSide.SELL, {
|
|
19038
|
+
reduceOnly: formattedOrder.reduce_only,
|
|
19039
|
+
marginMode: effectiveMarginMode,
|
|
19040
|
+
currentOrderReferencePrice: referencePriceFromOrder && referencePriceFromOrder > 0 ? referencePriceFromOrder : void 0
|
|
19041
|
+
});
|
|
19042
|
+
const maxQtyValue = formattedOrder.side === OrderSide.BUY ? maxBuyQtyValue : maxSellQtyValue;
|
|
19029
19043
|
const maxQty = options.maxQty ?? maxQtyValue;
|
|
19044
|
+
const maxQtys = useMemo(
|
|
19045
|
+
() => ({
|
|
19046
|
+
maxBuy: formattedOrder.side === OrderSide.BUY ? (
|
|
19047
|
+
// @ts-ignore
|
|
19048
|
+
options.maxQty ?? maxBuyQtyValue
|
|
19049
|
+
) : maxBuyQtyValue,
|
|
19050
|
+
maxSell: formattedOrder.side === OrderSide.SELL ? (
|
|
19051
|
+
// @ts-ignore
|
|
19052
|
+
options.maxQty ?? maxSellQtyValue
|
|
19053
|
+
) : maxSellQtyValue
|
|
19054
|
+
}),
|
|
19055
|
+
[
|
|
19056
|
+
formattedOrder.side,
|
|
19057
|
+
maxBuyQtyValue,
|
|
19058
|
+
maxSellQtyValue,
|
|
19059
|
+
// @ts-ignore
|
|
19060
|
+
options.maxQty
|
|
19061
|
+
]
|
|
19062
|
+
);
|
|
19030
19063
|
const updateOrderPrice = () => {
|
|
19031
19064
|
const order_type = formattedOrder.order_type;
|
|
19032
19065
|
const order_type_ext = formattedOrder.order_type_ext ?? lastOrderTypeExt.current;
|
|
@@ -19416,6 +19449,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
19416
19449
|
resetMetaState,
|
|
19417
19450
|
formattedOrder,
|
|
19418
19451
|
maxQty,
|
|
19452
|
+
maxQtys,
|
|
19419
19453
|
estLiqPrice,
|
|
19420
19454
|
estLiqPriceDistance,
|
|
19421
19455
|
currentPosition,
|