@orderly.network/hooks 2.0.7 → 2.1.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 +92 -52
- package/dist/index.d.ts +92 -52
- package/dist/index.js +470 -395
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +467 -395
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -11
package/dist/index.js
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
var useSWR = require('swr');
|
|
4
4
|
var net = require('@orderly.network/net');
|
|
5
5
|
var React = require('react');
|
|
6
|
+
var types = require('@orderly.network/types');
|
|
6
7
|
var useSWRMutation = require('swr/mutation');
|
|
7
8
|
var useConstant = require('use-constant');
|
|
8
9
|
var core = require('@orderly.network/core');
|
|
9
10
|
var utils = require('@orderly.network/utils');
|
|
10
|
-
var
|
|
11
|
+
var lodash = require('lodash');
|
|
11
12
|
var useSWRInfinite = require('swr/infinite');
|
|
13
|
+
var amplitude = require('@amplitude/analytics-browser');
|
|
12
14
|
var jsxRuntime = require('react/jsx-runtime');
|
|
13
15
|
var ramda = require('ramda');
|
|
14
16
|
var zustand = require('zustand');
|
|
@@ -20,7 +22,6 @@ var immer$1 = require('immer');
|
|
|
20
22
|
var defaultEvmAdapter = require('@orderly.network/default-evm-adapter');
|
|
21
23
|
var defaultSolanaAdapter = require('@orderly.network/default-solana-adapter');
|
|
22
24
|
var web3ProviderEthers = require('@orderly.network/web3-provider-ethers');
|
|
23
|
-
var amplitude = require('@amplitude/analytics-browser');
|
|
24
25
|
var qr = require('@akamfoad/qr');
|
|
25
26
|
|
|
26
27
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -48,8 +49,8 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
48
49
|
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
49
50
|
var useConstant__default = /*#__PURE__*/_interopDefault(useConstant);
|
|
50
51
|
var useSWRInfinite__default = /*#__PURE__*/_interopDefault(useSWRInfinite);
|
|
51
|
-
var useSWRSubscription__default = /*#__PURE__*/_interopDefault(useSWRSubscription);
|
|
52
52
|
var amplitude__namespace = /*#__PURE__*/_interopNamespace(amplitude);
|
|
53
|
+
var useSWRSubscription__default = /*#__PURE__*/_interopDefault(useSWRSubscription);
|
|
53
54
|
|
|
54
55
|
var __defProp = Object.defineProperty;
|
|
55
56
|
var __export = (target, all) => {
|
|
@@ -60,20 +61,18 @@ var __export = (target, all) => {
|
|
|
60
61
|
// src/version.ts
|
|
61
62
|
if (typeof window !== "undefined") {
|
|
62
63
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
63
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0
|
|
64
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.1.0";
|
|
64
65
|
}
|
|
65
|
-
var version_default = "2.0
|
|
66
|
+
var version_default = "2.1.0";
|
|
66
67
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
67
68
|
var OrderlyContext = React.createContext({
|
|
68
69
|
// configStore: new MemoryConfigStore(),
|
|
69
70
|
});
|
|
70
71
|
var OrderlyProvider = OrderlyContext.Provider;
|
|
71
|
-
|
|
72
|
-
// src/useConfig.ts
|
|
73
72
|
function useConfig(key, defaultValue) {
|
|
74
73
|
const { configStore } = React.useContext(OrderlyContext);
|
|
75
74
|
if (!configStore) {
|
|
76
|
-
throw new
|
|
75
|
+
throw new types.SDKError(
|
|
77
76
|
"useConfig must be used within OrderlyConfigProvider or OrderlyAppProvider"
|
|
78
77
|
);
|
|
79
78
|
}
|
|
@@ -85,13 +84,11 @@ function useConfig(key, defaultValue) {
|
|
|
85
84
|
}
|
|
86
85
|
return configStore;
|
|
87
86
|
}
|
|
88
|
-
|
|
89
|
-
// src/useQuery.ts
|
|
90
87
|
var useQuery = (query, options) => {
|
|
91
88
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
92
89
|
const { formatter, ...swrOptions } = options || {};
|
|
93
90
|
if (typeof apiBaseUrl === "undefined") {
|
|
94
|
-
throw new
|
|
91
|
+
throw new types.SDKError("please add OrderlyConfigProvider to your app");
|
|
95
92
|
}
|
|
96
93
|
return useSWR__default.default(
|
|
97
94
|
query,
|
|
@@ -105,7 +102,7 @@ var useLazyQuery = (query, options) => {
|
|
|
105
102
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
106
103
|
const { formatter, init: init2, ...swrOptions } = options || {};
|
|
107
104
|
if (typeof apiBaseUrl === "undefined") {
|
|
108
|
-
throw new
|
|
105
|
+
throw new types.SDKError("please add OrderlyConfigProvider to your app");
|
|
109
106
|
}
|
|
110
107
|
return useSWRMutation__default.default(
|
|
111
108
|
query,
|
|
@@ -127,9 +124,11 @@ var useLazyQuery = (query, options) => {
|
|
|
127
124
|
var useAccountInstance = () => {
|
|
128
125
|
const { configStore, keyStore, walletAdapters } = React.useContext(OrderlyContext);
|
|
129
126
|
if (!configStore)
|
|
130
|
-
throw new
|
|
127
|
+
throw new types.SDKError(
|
|
128
|
+
"configStore is not defined, please use OrderlyProvider"
|
|
129
|
+
);
|
|
131
130
|
if (!keyStore) {
|
|
132
|
-
throw new
|
|
131
|
+
throw new types.SDKError(
|
|
133
132
|
"keyStore is not defined, please use OrderlyProvider and provide keyStore"
|
|
134
133
|
);
|
|
135
134
|
}
|
|
@@ -250,6 +249,26 @@ var useEventEmitter = () => {
|
|
|
250
249
|
return ee;
|
|
251
250
|
});
|
|
252
251
|
};
|
|
252
|
+
|
|
253
|
+
// src/useTrack.ts
|
|
254
|
+
var useTrack = () => {
|
|
255
|
+
const ee = useEventEmitter();
|
|
256
|
+
const debouncedTrackFn = React.useCallback(
|
|
257
|
+
lodash.debounce((eventName, params) => {
|
|
258
|
+
ee.emit(eventName, params);
|
|
259
|
+
}, 500),
|
|
260
|
+
[]
|
|
261
|
+
);
|
|
262
|
+
const track2 = React.useCallback((eventName, params) => {
|
|
263
|
+
debouncedTrackFn(eventName, params);
|
|
264
|
+
}, [debouncedTrackFn]);
|
|
265
|
+
const setTrackUserId = React.useCallback((userId) => {
|
|
266
|
+
ee.emit(types.EnumTrackerKeys.trackIdentifyUserId, userId);
|
|
267
|
+
}, []);
|
|
268
|
+
return { track: track2, setTrackUserId };
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/useAccount.ts
|
|
253
272
|
var useAccount = () => {
|
|
254
273
|
const {
|
|
255
274
|
configStore,
|
|
@@ -259,21 +278,18 @@ var useAccount = () => {
|
|
|
259
278
|
// onSetChain,
|
|
260
279
|
} = React.useContext(OrderlyContext);
|
|
261
280
|
if (!configStore)
|
|
262
|
-
throw new
|
|
281
|
+
throw new types.SDKError(
|
|
282
|
+
"configStore is not defined, please use OrderlyProvider"
|
|
283
|
+
);
|
|
263
284
|
if (!keyStore) {
|
|
264
|
-
throw new
|
|
285
|
+
throw new types.SDKError(
|
|
265
286
|
"keyStore is not defined, please use OrderlyProvider and provide keyStore"
|
|
266
287
|
);
|
|
267
288
|
}
|
|
268
289
|
const account5 = useAccountInstance();
|
|
269
290
|
const [state, setState] = React.useState(account5.stateValue);
|
|
270
|
-
const
|
|
291
|
+
const { track: track2 } = useTrack();
|
|
271
292
|
const statusChangeHandler = (nextState) => {
|
|
272
|
-
if (types.AccountStatusEnum.Connected === nextState.status) {
|
|
273
|
-
ee.emit(types.EnumTrackerKeys.WALLET_CONNECT, {
|
|
274
|
-
...nextState
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
293
|
setState(() => nextState);
|
|
278
294
|
};
|
|
279
295
|
React.useEffect(() => {
|
|
@@ -284,9 +300,9 @@ var useAccount = () => {
|
|
|
284
300
|
}, []);
|
|
285
301
|
const createOrderlyKey = React.useCallback(
|
|
286
302
|
async (remember) => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
303
|
+
track2(types.EnumTrackerKeys.signinSuccess, {
|
|
304
|
+
network: account5.chainId,
|
|
305
|
+
wallet: state.connectWallet?.name
|
|
290
306
|
});
|
|
291
307
|
return account5.createOrderlyKey(remember ? 365 : 30);
|
|
292
308
|
},
|
|
@@ -511,6 +527,77 @@ var useNetworkInfo = (networkId) => {
|
|
|
511
527
|
};
|
|
512
528
|
};
|
|
513
529
|
};
|
|
530
|
+
var apiKeyMap = {
|
|
531
|
+
dev: "4d6b7db0fdd6e9de2b6a270414fd51e0",
|
|
532
|
+
qa: "96476b00bc2701360f9b480629ae5263",
|
|
533
|
+
staging: "dffc00e003479b86d410c448e00f2304",
|
|
534
|
+
prod: "3ab9ae56ed16cc57bc2ac97ffc1098c2"
|
|
535
|
+
};
|
|
536
|
+
var AmplitudeTracker = class {
|
|
537
|
+
constructor(env, sdkInfo) {
|
|
538
|
+
this._ee = core.SimpleDI.get("EE");
|
|
539
|
+
amplitude__namespace.init(apiKeyMap[env], { serverZone: "EU" });
|
|
540
|
+
this.setSdkInfo(sdkInfo);
|
|
541
|
+
this._bindEvents();
|
|
542
|
+
}
|
|
543
|
+
setUserId(userId) {
|
|
544
|
+
if (userId === this._userId) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
amplitude__namespace.setUserId(userId);
|
|
548
|
+
this._userId = userId;
|
|
549
|
+
}
|
|
550
|
+
setSdkInfo(sdkInfo) {
|
|
551
|
+
if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag)
|
|
552
|
+
return;
|
|
553
|
+
const identify2 = new amplitude__namespace.Identify();
|
|
554
|
+
Object.entries(sdkInfo).forEach(([key, value]) => {
|
|
555
|
+
identify2.set(key, value);
|
|
556
|
+
});
|
|
557
|
+
amplitude__namespace.identify(identify2);
|
|
558
|
+
this._sdkInfoTag = sdkInfo.address;
|
|
559
|
+
}
|
|
560
|
+
identify(identifyEvent) {
|
|
561
|
+
amplitude__namespace.identify(identifyEvent);
|
|
562
|
+
}
|
|
563
|
+
track(eventName, properties) {
|
|
564
|
+
amplitude__namespace.track(types.TrackerListenerKeyMap[eventName], properties);
|
|
565
|
+
}
|
|
566
|
+
_bindEvents() {
|
|
567
|
+
const listenKeys = Object.keys(types.TrackerListenerKeyMap);
|
|
568
|
+
listenKeys.forEach((key) => {
|
|
569
|
+
this._ee.addListener(key, (params = {}) => {
|
|
570
|
+
if (key === types.EnumTrackerKeys.trackIdentifyUserId) {
|
|
571
|
+
this.setUserId(params);
|
|
572
|
+
} else {
|
|
573
|
+
this.track(key, params);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
AmplitudeTracker.instanceName = "amplitudeTracker";
|
|
580
|
+
|
|
581
|
+
// src/useTrackInstance.ts
|
|
582
|
+
var useTrackingInstance = () => {
|
|
583
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
584
|
+
if (!configStore)
|
|
585
|
+
throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
586
|
+
const env = configStore.get("env");
|
|
587
|
+
const brokerId = configStore.get("brokerId");
|
|
588
|
+
const trackInstace = useConstant__default.default(() => {
|
|
589
|
+
let instance = core.SimpleDI.get("amplitudeTracker");
|
|
590
|
+
if (!instance) {
|
|
591
|
+
instance = new AmplitudeTracker(env, {
|
|
592
|
+
brokerId,
|
|
593
|
+
sdk_version: window?.__ORDERLY_VERSION__?.["@orderly.network/net"] ?? ""
|
|
594
|
+
});
|
|
595
|
+
core.SimpleDI.registerByName("instance", instance);
|
|
596
|
+
}
|
|
597
|
+
return instance;
|
|
598
|
+
});
|
|
599
|
+
return trackInstace;
|
|
600
|
+
};
|
|
514
601
|
var WS_NAME = "nativeWebsocketClient";
|
|
515
602
|
var useWS = () => {
|
|
516
603
|
const { configStore } = React.useContext(OrderlyContext);
|
|
@@ -794,7 +881,7 @@ var AlgoOrderMergeHandler = class _AlgoOrderMergeHandler extends BaseMergeHandle
|
|
|
794
881
|
(order) => order.parentAlgoOrderId === 0 && order.algoOrderId === order.rootAlgoOrderId
|
|
795
882
|
);
|
|
796
883
|
if (rootOrderIndex === -1) {
|
|
797
|
-
throw new
|
|
884
|
+
throw new types.SDKError("Root order not found");
|
|
798
885
|
}
|
|
799
886
|
const rootOrder_ = object2underscore(
|
|
800
887
|
orders[rootOrderIndex]
|
|
@@ -816,7 +903,7 @@ var AlgoOrderMergeHandler = class _AlgoOrderMergeHandler extends BaseMergeHandle
|
|
|
816
903
|
(order) => order.algoType !== types.AlgoOrderType.STOP_LOSS && order.algoType !== types.AlgoOrderType.TAKE_PROFIT
|
|
817
904
|
);
|
|
818
905
|
if (rootOrderIndex === -1) {
|
|
819
|
-
throw new
|
|
906
|
+
throw new types.SDKError("Root order not found");
|
|
820
907
|
}
|
|
821
908
|
const rootOrder = innerOrders.splice(
|
|
822
909
|
rootOrderIndex,
|
|
@@ -1886,7 +1973,7 @@ var useFutures = () => {
|
|
|
1886
1973
|
// src/orderly/useTickerStream.ts
|
|
1887
1974
|
var useTickerStream = (symbol) => {
|
|
1888
1975
|
if (!symbol) {
|
|
1889
|
-
throw new
|
|
1976
|
+
throw new types.SDKError("Symbol is required");
|
|
1890
1977
|
}
|
|
1891
1978
|
const { data: info } = useQuery(
|
|
1892
1979
|
`/v1/public/futures/${symbol}`,
|
|
@@ -2185,10 +2272,12 @@ var reduceOrderbook = (depth, level, padding, data) => {
|
|
|
2185
2272
|
var INIT_DATA = { asks: [], bids: [] };
|
|
2186
2273
|
var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
2187
2274
|
if (!symbol) {
|
|
2188
|
-
throw new types.SDKError("
|
|
2275
|
+
throw new types.SDKError("Symbol is required");
|
|
2189
2276
|
}
|
|
2190
2277
|
const level = options?.level ?? 10;
|
|
2191
2278
|
const padding = options?.padding ?? true;
|
|
2279
|
+
const symbolRef = React.useRef(symbol);
|
|
2280
|
+
symbolRef.current = symbol;
|
|
2192
2281
|
const [requestData, setRequestData] = React.useState(null);
|
|
2193
2282
|
const [data, setData] = React.useState(initial);
|
|
2194
2283
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
@@ -2231,13 +2320,17 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
2231
2320
|
formatter: (message) => message,
|
|
2232
2321
|
onMessage: (message) => {
|
|
2233
2322
|
const { data: wsData, ts } = message;
|
|
2234
|
-
const { asks, bids, prevTs } = wsData;
|
|
2323
|
+
const { symbol: symbol2, asks, bids, prevTs } = wsData;
|
|
2324
|
+
if (symbolRef.current !== symbol2) {
|
|
2325
|
+
orderBookUpdateSub?.();
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2235
2328
|
orderbook_service_default.updateOrderbook(
|
|
2236
|
-
|
|
2329
|
+
symbol2,
|
|
2237
2330
|
{ asks, bids, ts, prevTs },
|
|
2238
2331
|
() => needRequestFullOrderbook = true
|
|
2239
2332
|
);
|
|
2240
|
-
const data2 = orderbook_service_default.getRawOrderbook(
|
|
2333
|
+
const data2 = orderbook_service_default.getRawOrderbook(symbol2);
|
|
2241
2334
|
setData({ bids: data2.bids, asks: data2.asks });
|
|
2242
2335
|
}
|
|
2243
2336
|
}
|
|
@@ -2257,6 +2350,9 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
2257
2350
|
formatter: (message) => message,
|
|
2258
2351
|
onMessage: (message) => {
|
|
2259
2352
|
const { symbol: symbol2, asks, bids, ts } = message.data;
|
|
2353
|
+
if (symbolRef.current !== symbol2) {
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2260
2356
|
orderbook_service_default.setFullOrderbook(symbol2, { asks, bids, ts });
|
|
2261
2357
|
const data2 = orderbook_service_default.getRawOrderbook(symbol2);
|
|
2262
2358
|
setData({ bids: data2.bids, asks: data2.asks });
|
|
@@ -3026,7 +3122,7 @@ var useLeverage = () => {
|
|
|
3026
3122
|
};
|
|
3027
3123
|
var useFundingRate = (symbol) => {
|
|
3028
3124
|
if (!symbol) {
|
|
3029
|
-
throw new
|
|
3125
|
+
throw new types.SDKError("Symbol is required");
|
|
3030
3126
|
}
|
|
3031
3127
|
const [countDown, setCountDown] = React.useState("00:00:00");
|
|
3032
3128
|
const { data } = useQuery(
|
|
@@ -3390,10 +3486,10 @@ var useOrderStream = (params, options) => {
|
|
|
3390
3486
|
}, [orders?.length]);
|
|
3391
3487
|
const cancelAlgoOrdersByTypes = (types$1) => {
|
|
3392
3488
|
if (!types$1) {
|
|
3393
|
-
throw new types.SDKError("
|
|
3489
|
+
throw new types.SDKError("Types is required");
|
|
3394
3490
|
}
|
|
3395
3491
|
if (!Array.isArray(types$1)) {
|
|
3396
|
-
throw new types.SDKError("
|
|
3492
|
+
throw new types.SDKError("Types should be an array");
|
|
3397
3493
|
}
|
|
3398
3494
|
return Promise.all(
|
|
3399
3495
|
types$1.map((type) => {
|
|
@@ -3494,7 +3590,7 @@ var useOrderStream = (params, options) => {
|
|
|
3494
3590
|
const updateTPSLOrder = React.useCallback(
|
|
3495
3591
|
(orderId, childOrders) => {
|
|
3496
3592
|
if (!Array.isArray(childOrders)) {
|
|
3497
|
-
throw new types.SDKError("
|
|
3593
|
+
throw new types.SDKError("Children orders is required");
|
|
3498
3594
|
}
|
|
3499
3595
|
return doUpdateAlgoOrder({
|
|
3500
3596
|
order_id: orderId,
|
|
@@ -3540,7 +3636,7 @@ var useOrderStream = (params, options) => {
|
|
|
3540
3636
|
};
|
|
3541
3637
|
var useMarketTradeStream = (symbol, options = {}) => {
|
|
3542
3638
|
if (!symbol) {
|
|
3543
|
-
throw new
|
|
3639
|
+
throw new types.SDKError("Symbol is required");
|
|
3544
3640
|
}
|
|
3545
3641
|
const [trades, setTrades] = React.useState([]);
|
|
3546
3642
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
@@ -3769,7 +3865,13 @@ function useChains(networkId, options = {}) {
|
|
|
3769
3865
|
);
|
|
3770
3866
|
const { data: testTokenChainsRes } = useQuery(
|
|
3771
3867
|
"https://testnet-api.orderly.org/v1/public/token",
|
|
3772
|
-
{
|
|
3868
|
+
{
|
|
3869
|
+
...commonSwrOpts,
|
|
3870
|
+
fallbackData: types.TesntTokenFallback([
|
|
3871
|
+
types.ArbitrumSepoliaTokenInfo,
|
|
3872
|
+
types.SolanaDevnetTokenInfo
|
|
3873
|
+
])
|
|
3874
|
+
}
|
|
3773
3875
|
);
|
|
3774
3876
|
const brokerId = configStore.get("brokerId");
|
|
3775
3877
|
const needFetchFromAPI = options.forceAPI || !customChains;
|
|
@@ -3777,9 +3879,14 @@ function useChains(networkId, options = {}) {
|
|
|
3777
3879
|
needFetchFromAPI ? `https://api.orderly.org/v1/public/chain_info${brokerId !== "orderly" ? `?broker_id=${brokerId}` : ""}` : null,
|
|
3778
3880
|
{ ...commonSwrOpts }
|
|
3779
3881
|
);
|
|
3780
|
-
const { data: testChainInfos } = useQuery(
|
|
3882
|
+
const { data: testChainInfos, error: testChainInfoError } = useQuery(
|
|
3781
3883
|
needFetchFromAPI ? `https://testnet-api.orderly.org/v1/public/chain_info${brokerId !== "orderly" ? `?broker_id=${brokerId}` : ""}` : null,
|
|
3782
|
-
{
|
|
3884
|
+
{
|
|
3885
|
+
...commonSwrOpts,
|
|
3886
|
+
fallbackData: [types.ArbitrumSepoliaChainInfo, types.SolanaDevnetChainInfo],
|
|
3887
|
+
onError: (error) => {
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3783
3890
|
);
|
|
3784
3891
|
const chains = React.useMemo(() => {
|
|
3785
3892
|
const tokenChains = fillChainsInfo(
|
|
@@ -3956,6 +4063,23 @@ function filterByAllowedChains(chains, allowedChains) {
|
|
|
3956
4063
|
)
|
|
3957
4064
|
);
|
|
3958
4065
|
}
|
|
4066
|
+
function useStorageChain() {
|
|
4067
|
+
const [chain, setChain] = useLocalStorage(types.ChainKey, null);
|
|
4068
|
+
const setStorageChain = (chainId) => {
|
|
4069
|
+
let namespace = types.ChainNamespace.evm;
|
|
4070
|
+
if (types.SolanaChains.has(chainId)) {
|
|
4071
|
+
namespace = types.ChainNamespace.solana;
|
|
4072
|
+
}
|
|
4073
|
+
setChain({
|
|
4074
|
+
chainId,
|
|
4075
|
+
namespace
|
|
4076
|
+
});
|
|
4077
|
+
};
|
|
4078
|
+
return {
|
|
4079
|
+
storageChain: chain,
|
|
4080
|
+
setStorageChain
|
|
4081
|
+
};
|
|
4082
|
+
}
|
|
3959
4083
|
var useChain = (token) => {
|
|
3960
4084
|
const { data, isLoading } = useQuery("/v1/public/token");
|
|
3961
4085
|
const chains = React.useMemo(() => {
|
|
@@ -4031,6 +4155,7 @@ var useWithdraw = (options) => {
|
|
|
4031
4155
|
const networkId = useConfig("networkId");
|
|
4032
4156
|
const [_, { findByChainId }] = useChains(void 0);
|
|
4033
4157
|
const ee = useEventEmitter();
|
|
4158
|
+
const { track: track2 } = useTrack();
|
|
4034
4159
|
const { usdc } = useHoldingStream();
|
|
4035
4160
|
const maxAmount = React.useMemo(() => {
|
|
4036
4161
|
return freeCollateral;
|
|
@@ -4072,7 +4197,7 @@ var useWithdraw = (options) => {
|
|
|
4072
4197
|
(inputs) => {
|
|
4073
4198
|
return account5.assetsManager.withdraw(inputs).then((res) => {
|
|
4074
4199
|
if (res.success) {
|
|
4075
|
-
ee.emit(types.EnumTrackerKeys.
|
|
4200
|
+
ee.emit(types.EnumTrackerKeys.withdrawSuccess, {
|
|
4076
4201
|
wallet: state?.connectWallet?.name,
|
|
4077
4202
|
network: targetChain?.network_infos.name,
|
|
4078
4203
|
quantity: inputs.amount
|
|
@@ -4080,7 +4205,7 @@ var useWithdraw = (options) => {
|
|
|
4080
4205
|
}
|
|
4081
4206
|
return res;
|
|
4082
4207
|
}).catch((err) => {
|
|
4083
|
-
|
|
4208
|
+
track2(types.EnumTrackerKeys.withdrawFailed, {
|
|
4084
4209
|
wallet: state?.connectWallet?.name,
|
|
4085
4210
|
network: targetChain?.network_infos.name,
|
|
4086
4211
|
msg: JSON.stringify(err)
|
|
@@ -4104,7 +4229,7 @@ var useDeposit = (options) => {
|
|
|
4104
4229
|
const networkId = useConfig("networkId");
|
|
4105
4230
|
const [balanceRevalidating, setBalanceRevalidating] = React.useState(false);
|
|
4106
4231
|
const [allowanceRevalidating, setAllowanceRevalidating] = React.useState(false);
|
|
4107
|
-
|
|
4232
|
+
useEventEmitter();
|
|
4108
4233
|
const [_, { findByChainId }] = useChains(void 0);
|
|
4109
4234
|
const [quantity, setQuantity] = React.useState("");
|
|
4110
4235
|
const [depositFee, setDepositFee] = React.useState(0n);
|
|
@@ -4112,6 +4237,7 @@ var useDeposit = (options) => {
|
|
|
4112
4237
|
const [balance, setBalance] = React.useState("0");
|
|
4113
4238
|
const [allowance, setAllowance] = React.useState("0");
|
|
4114
4239
|
const { account: account5, state } = useAccount();
|
|
4240
|
+
const { track: track2 } = useTrack();
|
|
4115
4241
|
const prevAddress = React.useRef();
|
|
4116
4242
|
const getBalanceListener = React.useRef();
|
|
4117
4243
|
const targetChain = React.useMemo(() => {
|
|
@@ -4277,7 +4403,7 @@ var useDeposit = (options) => {
|
|
|
4277
4403
|
const approve = React.useCallback(
|
|
4278
4404
|
async (amount) => {
|
|
4279
4405
|
if (!options?.address) {
|
|
4280
|
-
throw new
|
|
4406
|
+
throw new types.SDKError("Address is required");
|
|
4281
4407
|
}
|
|
4282
4408
|
return account5.assetsManager.approve({
|
|
4283
4409
|
address: options.address,
|
|
@@ -4291,17 +4417,17 @@ var useDeposit = (options) => {
|
|
|
4291
4417
|
);
|
|
4292
4418
|
const deposit = React.useCallback(async () => {
|
|
4293
4419
|
if (!options?.address) {
|
|
4294
|
-
throw new
|
|
4420
|
+
throw new types.SDKError("Address is required");
|
|
4295
4421
|
}
|
|
4296
4422
|
const _allowance = await account5.assetsManager.getAllowance({
|
|
4297
4423
|
address: options?.address
|
|
4298
4424
|
});
|
|
4299
4425
|
setAllowance(() => _allowance);
|
|
4300
4426
|
if (new utils.Decimal(quantity).greaterThan(_allowance)) {
|
|
4301
|
-
throw new
|
|
4427
|
+
throw new types.SDKError("Insufficient allowance");
|
|
4302
4428
|
}
|
|
4303
4429
|
return account5.assetsManager.deposit(quantity, depositFee).then((res) => {
|
|
4304
|
-
|
|
4430
|
+
track2(types.EnumTrackerKeys.depositSuccess, {
|
|
4305
4431
|
wallet: state?.connectWallet?.name,
|
|
4306
4432
|
network: targetChain?.network_infos.name,
|
|
4307
4433
|
quantity
|
|
@@ -4310,7 +4436,7 @@ var useDeposit = (options) => {
|
|
|
4310
4436
|
setBalance((value) => new utils.Decimal(value).sub(quantity).toString());
|
|
4311
4437
|
return res;
|
|
4312
4438
|
}).catch((e) => {
|
|
4313
|
-
|
|
4439
|
+
track2(types.EnumTrackerKeys.depositFailed, {
|
|
4314
4440
|
wallet: state?.connectWallet?.name,
|
|
4315
4441
|
network: targetChain?.network_infos?.name,
|
|
4316
4442
|
msg: JSON.stringify(e)
|
|
@@ -4706,6 +4832,26 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
4706
4832
|
// }),
|
|
4707
4833
|
};
|
|
4708
4834
|
}
|
|
4835
|
+
function getMinNotional(props) {
|
|
4836
|
+
const { price, base_tick, qty, min_notional, base_dp, quote_dp, quote_tick } = props;
|
|
4837
|
+
if (price !== void 0 && qty !== void 0 && min_notional !== void 0) {
|
|
4838
|
+
try {
|
|
4839
|
+
const calcNotional = new utils.Decimal(price).mul(new utils.Decimal(qty)).toNumber();
|
|
4840
|
+
const notional = Number.parseFloat(`${min_notional}`);
|
|
4841
|
+
if (calcNotional < notional) {
|
|
4842
|
+
let minQty = new utils.Decimal(notional).div(price).toDecimalPlaces(base_dp, utils.Decimal.ROUND_DOWN).add(base_tick ?? 0);
|
|
4843
|
+
if (base_tick && base_tick > 0) {
|
|
4844
|
+
minQty = new utils.Decimal(
|
|
4845
|
+
getRoundedDownDivision(minQty.toNumber(), base_tick)
|
|
4846
|
+
);
|
|
4847
|
+
}
|
|
4848
|
+
const newMinNotional = minQty.mul(price).add(quote_tick ?? 0).toFixed(quote_dp);
|
|
4849
|
+
return newMinNotional;
|
|
4850
|
+
}
|
|
4851
|
+
} catch (e) {
|
|
4852
|
+
}
|
|
4853
|
+
}
|
|
4854
|
+
}
|
|
4709
4855
|
function checkNotional(props) {
|
|
4710
4856
|
const { price, base_tick, qty, min_notional, base_dp, quote_dp, quote_tick } = props;
|
|
4711
4857
|
if (price !== void 0 && qty !== void 0 && min_notional !== void 0) {
|
|
@@ -4736,6 +4882,47 @@ function getRoundedDownDivision(value, tick) {
|
|
|
4736
4882
|
return quotient.mul(decimalTick).toNumber();
|
|
4737
4883
|
}
|
|
4738
4884
|
|
|
4885
|
+
// src/services/orderCreator/orderValidation.ts
|
|
4886
|
+
var OrderValidation = class {
|
|
4887
|
+
static getLabel(key) {
|
|
4888
|
+
switch (key) {
|
|
4889
|
+
case "quantity":
|
|
4890
|
+
case "order_quantity":
|
|
4891
|
+
return "Quantity";
|
|
4892
|
+
case "order_price":
|
|
4893
|
+
return "Price";
|
|
4894
|
+
case "trigger_price":
|
|
4895
|
+
return "Trigger price";
|
|
4896
|
+
case "tp_trigger_price":
|
|
4897
|
+
return "TP price";
|
|
4898
|
+
case "sl_trigger_price":
|
|
4899
|
+
return "SL price";
|
|
4900
|
+
default:
|
|
4901
|
+
return key;
|
|
4902
|
+
}
|
|
4903
|
+
}
|
|
4904
|
+
static required(key) {
|
|
4905
|
+
return {
|
|
4906
|
+
type: "required",
|
|
4907
|
+
message: `${this.getLabel(key)} is required`
|
|
4908
|
+
};
|
|
4909
|
+
}
|
|
4910
|
+
static min(key, value) {
|
|
4911
|
+
return {
|
|
4912
|
+
type: "min",
|
|
4913
|
+
message: `${this.getLabel(key)} must be greater than ${value}`,
|
|
4914
|
+
value
|
|
4915
|
+
};
|
|
4916
|
+
}
|
|
4917
|
+
static max(key, value) {
|
|
4918
|
+
return {
|
|
4919
|
+
type: "max",
|
|
4920
|
+
message: `${this.getLabel(key)} must be less than ${value}`,
|
|
4921
|
+
value
|
|
4922
|
+
};
|
|
4923
|
+
}
|
|
4924
|
+
};
|
|
4925
|
+
|
|
4739
4926
|
// src/services/orderCreator/baseCreator.ts
|
|
4740
4927
|
var BaseOrderCreator = class {
|
|
4741
4928
|
baseOrder(data) {
|
|
@@ -4774,31 +4961,24 @@ var BaseOrderCreator = class {
|
|
|
4774
4961
|
}
|
|
4775
4962
|
}
|
|
4776
4963
|
if (!order_quantity) {
|
|
4777
|
-
errors.order_quantity =
|
|
4778
|
-
type: "required",
|
|
4779
|
-
message: "Quantity is required"
|
|
4780
|
-
};
|
|
4964
|
+
errors.order_quantity = OrderValidation.required("order_quantity");
|
|
4781
4965
|
} else {
|
|
4782
4966
|
const { base_min, quote_dp: quote_dp2, base_dp: base_dp2 } = configs.symbol;
|
|
4783
4967
|
const qty = new utils.Decimal(order_quantity);
|
|
4784
4968
|
if (qty.lt(base_min)) {
|
|
4785
|
-
errors.order_quantity =
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
)}`
|
|
4790
|
-
};
|
|
4969
|
+
errors.order_quantity = OrderValidation.min(
|
|
4970
|
+
"order_quantity",
|
|
4971
|
+
new utils.Decimal(base_min).todp(base_dp2).toString()
|
|
4972
|
+
);
|
|
4791
4973
|
} else if (qty.gt(maxQty)) {
|
|
4792
|
-
errors.order_quantity =
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
)}`
|
|
4797
|
-
};
|
|
4974
|
+
errors.order_quantity = OrderValidation.max(
|
|
4975
|
+
"order_quantity",
|
|
4976
|
+
new utils.Decimal(maxQty).todp(base_dp2).toString()
|
|
4977
|
+
);
|
|
4798
4978
|
}
|
|
4799
4979
|
}
|
|
4800
4980
|
const price = `${order_type}`.includes("MARKET") ? markPrice : order_price;
|
|
4801
|
-
const
|
|
4981
|
+
const minNotional = getMinNotional({
|
|
4802
4982
|
base_tick,
|
|
4803
4983
|
quote_tick,
|
|
4804
4984
|
price,
|
|
@@ -4807,10 +4987,11 @@ var BaseOrderCreator = class {
|
|
|
4807
4987
|
quote_dp,
|
|
4808
4988
|
base_dp
|
|
4809
4989
|
});
|
|
4810
|
-
if (
|
|
4990
|
+
if (minNotional !== void 0 && !reduce_only) {
|
|
4811
4991
|
errors.total = {
|
|
4812
4992
|
type: "min",
|
|
4813
|
-
message:
|
|
4993
|
+
message: `The order value should be greater or equal to ${minNotional} USDC`,
|
|
4994
|
+
value: minNotional
|
|
4814
4995
|
};
|
|
4815
4996
|
}
|
|
4816
4997
|
this.validateBracketOrder(values2, configs, errors);
|
|
@@ -4875,62 +5056,62 @@ var BaseOrderCreator = class {
|
|
|
4875
5056
|
if (hasTPPrice) {
|
|
4876
5057
|
const tpPrice = new utils.Decimal(tp_trigger_price);
|
|
4877
5058
|
if (tpPrice.gt(quote_max)) {
|
|
4878
|
-
errors.tp_trigger_price =
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
5059
|
+
errors.tp_trigger_price = OrderValidation.max(
|
|
5060
|
+
"tp_trigger_price",
|
|
5061
|
+
quote_max
|
|
5062
|
+
);
|
|
4882
5063
|
}
|
|
4883
5064
|
if (tpPrice.lt(quote_min)) {
|
|
4884
|
-
errors.tp_trigger_price =
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
5065
|
+
errors.tp_trigger_price = OrderValidation.min(
|
|
5066
|
+
"tp_trigger_price",
|
|
5067
|
+
quote_min
|
|
5068
|
+
);
|
|
4888
5069
|
}
|
|
4889
5070
|
if (side === types.OrderSide.BUY) {
|
|
4890
5071
|
if (tpPrice.lte(_orderPrice)) {
|
|
4891
|
-
errors.tp_trigger_price =
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
5072
|
+
errors.tp_trigger_price = OrderValidation.min(
|
|
5073
|
+
"tp_trigger_price",
|
|
5074
|
+
_orderPrice
|
|
5075
|
+
);
|
|
4895
5076
|
}
|
|
4896
5077
|
}
|
|
4897
5078
|
if (side === types.OrderSide.SELL) {
|
|
4898
5079
|
if (tpPrice.gte(_orderPrice)) {
|
|
4899
|
-
errors.tp_trigger_price =
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
5080
|
+
errors.tp_trigger_price = OrderValidation.max(
|
|
5081
|
+
"tp_trigger_price",
|
|
5082
|
+
_orderPrice
|
|
5083
|
+
);
|
|
4903
5084
|
}
|
|
4904
5085
|
}
|
|
4905
5086
|
}
|
|
4906
5087
|
if (hasSLPrice) {
|
|
4907
5088
|
const slPrice = new utils.Decimal(sl_trigger_price);
|
|
4908
5089
|
if (slPrice.gt(quote_max)) {
|
|
4909
|
-
errors.sl_trigger_price =
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
5090
|
+
errors.sl_trigger_price = OrderValidation.max(
|
|
5091
|
+
"sl_trigger_price",
|
|
5092
|
+
quote_max
|
|
5093
|
+
);
|
|
4913
5094
|
}
|
|
4914
5095
|
if (slPrice.lt(quote_min)) {
|
|
4915
|
-
errors.sl_trigger_price =
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
5096
|
+
errors.sl_trigger_price = OrderValidation.min(
|
|
5097
|
+
"sl_trigger_price",
|
|
5098
|
+
quote_min
|
|
5099
|
+
);
|
|
4919
5100
|
}
|
|
4920
5101
|
if (side === types.OrderSide.BUY) {
|
|
4921
5102
|
if (slPrice.gte(_orderPrice)) {
|
|
4922
|
-
errors.sl_trigger_price =
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
5103
|
+
errors.sl_trigger_price = OrderValidation.max(
|
|
5104
|
+
"sl_trigger_price",
|
|
5105
|
+
_orderPrice
|
|
5106
|
+
);
|
|
4926
5107
|
}
|
|
4927
5108
|
}
|
|
4928
5109
|
if (side === types.OrderSide.SELL) {
|
|
4929
5110
|
if (slPrice.lte(_orderPrice)) {
|
|
4930
|
-
errors.sl_trigger_price =
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
5111
|
+
errors.sl_trigger_price = OrderValidation.min(
|
|
5112
|
+
"sl_trigger_price",
|
|
5113
|
+
_orderPrice
|
|
5114
|
+
);
|
|
4934
5115
|
}
|
|
4935
5116
|
}
|
|
4936
5117
|
}
|
|
@@ -4985,10 +5166,7 @@ var LimitOrderCreator = class extends BaseOrderCreator {
|
|
|
4985
5166
|
return this.baseValidate(values2, config).then((errors) => {
|
|
4986
5167
|
const { order_price, side } = values2;
|
|
4987
5168
|
if (!order_price) {
|
|
4988
|
-
errors.order_price =
|
|
4989
|
-
type: "required",
|
|
4990
|
-
message: "Price is required"
|
|
4991
|
-
};
|
|
5169
|
+
errors.order_price = OrderValidation.required("order_price");
|
|
4992
5170
|
} else {
|
|
4993
5171
|
const price = new utils.Decimal(order_price);
|
|
4994
5172
|
const { symbol } = config;
|
|
@@ -5008,33 +5186,23 @@ var LimitOrderCreator = class extends BaseOrderCreator {
|
|
|
5008
5186
|
max: scopePriceNumber
|
|
5009
5187
|
};
|
|
5010
5188
|
if (price.gt(quote_max)) {
|
|
5011
|
-
errors.order_price =
|
|
5012
|
-
type: "max",
|
|
5013
|
-
message: `Price must be less than ${quote_max}`
|
|
5014
|
-
};
|
|
5189
|
+
errors.order_price = OrderValidation.max("order_price", quote_max);
|
|
5015
5190
|
} else {
|
|
5016
5191
|
if (price.gt(priceRange?.max)) {
|
|
5017
|
-
errors.order_price =
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
).todp(symbol.quote_dp)}`
|
|
5022
|
-
};
|
|
5192
|
+
errors.order_price = OrderValidation.max(
|
|
5193
|
+
"order_price",
|
|
5194
|
+
new utils.Decimal(priceRange.max).todp(symbol.quote_dp).toString()
|
|
5195
|
+
);
|
|
5023
5196
|
}
|
|
5024
5197
|
}
|
|
5025
5198
|
if (price.lt(quote_min)) {
|
|
5026
|
-
errors.order_price =
|
|
5027
|
-
type: "min",
|
|
5028
|
-
message: `Price must be greater than ${quote_min}`
|
|
5029
|
-
};
|
|
5199
|
+
errors.order_price = OrderValidation.min("order_price", quote_min);
|
|
5030
5200
|
} else {
|
|
5031
5201
|
if (price.lt(priceRange?.min)) {
|
|
5032
|
-
errors.order_price =
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
).todp(symbol.quote_dp)}`
|
|
5037
|
-
};
|
|
5202
|
+
errors.order_price = OrderValidation.min(
|
|
5203
|
+
"order_price",
|
|
5204
|
+
new utils.Decimal(priceRange.min).todp(symbol.quote_dp).toString()
|
|
5205
|
+
);
|
|
5038
5206
|
}
|
|
5039
5207
|
}
|
|
5040
5208
|
}
|
|
@@ -5081,27 +5249,15 @@ var StopLimitOrderCreator = class extends BaseOrderCreator {
|
|
|
5081
5249
|
const { symbol } = config;
|
|
5082
5250
|
const { price_range, price_scope, quote_max, quote_min } = symbol;
|
|
5083
5251
|
if (!trigger_price) {
|
|
5084
|
-
errors.trigger_price =
|
|
5085
|
-
type: "required",
|
|
5086
|
-
message: "Trigger price is required"
|
|
5087
|
-
};
|
|
5252
|
+
errors.trigger_price = OrderValidation.required("trigger_price");
|
|
5088
5253
|
}
|
|
5089
5254
|
if (!order_price) {
|
|
5090
|
-
errors.order_price =
|
|
5091
|
-
type: "required",
|
|
5092
|
-
message: "Price is required"
|
|
5093
|
-
};
|
|
5255
|
+
errors.order_price = OrderValidation.required("order_price");
|
|
5094
5256
|
}
|
|
5095
5257
|
if (trigger_price > quote_max) {
|
|
5096
|
-
errors.trigger_price =
|
|
5097
|
-
type: "max",
|
|
5098
|
-
message: `Trigger price must be less than ${quote_max}`
|
|
5099
|
-
};
|
|
5258
|
+
errors.trigger_price = OrderValidation.max("trigger_price", quote_max);
|
|
5100
5259
|
} else if (trigger_price < quote_min) {
|
|
5101
|
-
errors.trigger_price =
|
|
5102
|
-
type: "min",
|
|
5103
|
-
message: `Trigger price must be greater than ${quote_min}`
|
|
5104
|
-
};
|
|
5260
|
+
errors.trigger_price = OrderValidation.min("trigger_price", quote_min);
|
|
5105
5261
|
} else {
|
|
5106
5262
|
if (trigger_price && order_price) {
|
|
5107
5263
|
const price = new utils.Decimal(order_price);
|
|
@@ -5120,33 +5276,23 @@ var StopLimitOrderCreator = class extends BaseOrderCreator {
|
|
|
5120
5276
|
max: scropePriceNumbere
|
|
5121
5277
|
};
|
|
5122
5278
|
if (price.gt(quote_max)) {
|
|
5123
|
-
errors.order_price =
|
|
5124
|
-
type: "max",
|
|
5125
|
-
message: `Price must be less than ${quote_max}`
|
|
5126
|
-
};
|
|
5279
|
+
errors.order_price = OrderValidation.max("order_price", quote_max);
|
|
5127
5280
|
} else {
|
|
5128
5281
|
if (price.gt(priceRange?.max)) {
|
|
5129
|
-
errors.order_price =
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
).todp(symbol.quote_dp)}`
|
|
5134
|
-
};
|
|
5282
|
+
errors.order_price = OrderValidation.max(
|
|
5283
|
+
"order_price",
|
|
5284
|
+
new utils.Decimal(priceRange.max).todp(symbol.quote_dp).toString()
|
|
5285
|
+
);
|
|
5135
5286
|
}
|
|
5136
5287
|
}
|
|
5137
5288
|
if (price.lt(quote_min)) {
|
|
5138
|
-
errors.order_price =
|
|
5139
|
-
type: "min",
|
|
5140
|
-
message: `Price must be greater than ${quote_min}`
|
|
5141
|
-
};
|
|
5289
|
+
errors.order_price = OrderValidation.min("order_price", quote_min);
|
|
5142
5290
|
} else {
|
|
5143
5291
|
if (price.lt(priceRange?.min)) {
|
|
5144
|
-
errors.order_price =
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
).todp(symbol.quote_dp)}`
|
|
5149
|
-
};
|
|
5292
|
+
errors.order_price = OrderValidation.min(
|
|
5293
|
+
"order_price",
|
|
5294
|
+
new utils.Decimal(priceRange.min).todp(symbol.quote_dp).toString()
|
|
5295
|
+
);
|
|
5150
5296
|
}
|
|
5151
5297
|
}
|
|
5152
5298
|
}
|
|
@@ -5203,21 +5349,12 @@ var StopMarketOrderCreator = class extends BaseOrderCreator {
|
|
|
5203
5349
|
const { symbol } = config;
|
|
5204
5350
|
const { quote_max, quote_min } = symbol;
|
|
5205
5351
|
if (!trigger_price) {
|
|
5206
|
-
errors.trigger_price =
|
|
5207
|
-
type: "required",
|
|
5208
|
-
message: "Trigger price is required"
|
|
5209
|
-
};
|
|
5352
|
+
errors.trigger_price = OrderValidation.required("trigger_price");
|
|
5210
5353
|
}
|
|
5211
5354
|
if (trigger_price > quote_max) {
|
|
5212
|
-
errors.trigger_price =
|
|
5213
|
-
type: "max",
|
|
5214
|
-
message: `Trigger price must be less than ${quote_max}`
|
|
5215
|
-
};
|
|
5355
|
+
errors.trigger_price = OrderValidation.max("trigger_price", quote_max);
|
|
5216
5356
|
} else if (trigger_price < quote_min) {
|
|
5217
|
-
errors.trigger_price =
|
|
5218
|
-
type: "min",
|
|
5219
|
-
message: `Trigger price must be greater than ${quote_min}`
|
|
5220
|
-
};
|
|
5357
|
+
errors.trigger_price = OrderValidation.min("trigger_price", quote_min);
|
|
5221
5358
|
}
|
|
5222
5359
|
return errors;
|
|
5223
5360
|
});
|
|
@@ -5246,82 +5383,91 @@ var BaseAlgoOrderCreator = class {
|
|
|
5246
5383
|
const qty = Number(values2.quantity);
|
|
5247
5384
|
const maxQty = config.maxQty;
|
|
5248
5385
|
const orderType = values2.order_type;
|
|
5249
|
-
const {
|
|
5386
|
+
const {
|
|
5387
|
+
quote_max,
|
|
5388
|
+
quote_min,
|
|
5389
|
+
price_scope,
|
|
5390
|
+
quote_dp,
|
|
5391
|
+
base_min,
|
|
5392
|
+
min_notional
|
|
5393
|
+
} = config.symbol ?? {};
|
|
5250
5394
|
if (!isNaN(qty) && qty > maxQty) {
|
|
5251
|
-
result.quantity =
|
|
5252
|
-
message: `Quantity must be less than ${config.maxQty}`
|
|
5253
|
-
};
|
|
5395
|
+
result.quantity = OrderValidation.max("quantity", config.maxQty);
|
|
5254
5396
|
}
|
|
5255
5397
|
if (!isNaN(qty) && qty < base_min) {
|
|
5256
|
-
result.quantity =
|
|
5257
|
-
message: `Quantity must be greater than ${base_min}`
|
|
5258
|
-
};
|
|
5398
|
+
result.quantity = OrderValidation.min("quantity", base_min);
|
|
5259
5399
|
}
|
|
5260
5400
|
if (Number(tp_trigger_price) < 0) {
|
|
5261
|
-
result.tp_trigger_price =
|
|
5262
|
-
message: `TP Price must be greater than 0`
|
|
5263
|
-
};
|
|
5401
|
+
result.tp_trigger_price = OrderValidation.min("tp_trigger_price", 0);
|
|
5264
5402
|
}
|
|
5265
5403
|
if (Number(sl_trigger_price) < 0) {
|
|
5266
|
-
result.sl_trigger_price =
|
|
5267
|
-
message: `SL Price must be greater than 0`
|
|
5268
|
-
};
|
|
5404
|
+
result.sl_trigger_price = OrderValidation.min("sl_trigger_price", 0);
|
|
5269
5405
|
}
|
|
5270
5406
|
const mark_price = orderType === types.OrderType.MARKET || orderType == null ? config.markPrice : values2.order_price ? Number(values2.order_price) : void 0;
|
|
5271
5407
|
if (side === types.OrderSide.BUY && mark_price) {
|
|
5272
5408
|
const slTriggerPriceScope = new utils.Decimal(mark_price * (1 - price_scope)).toDecimalPlaces(quote_dp, utils.Decimal.ROUND_DOWN).toNumber();
|
|
5273
5409
|
if (!!sl_trigger_price && Number(sl_trigger_price) < slTriggerPriceScope) {
|
|
5274
|
-
result.sl_trigger_price =
|
|
5275
|
-
|
|
5276
|
-
|
|
5410
|
+
result.sl_trigger_price = OrderValidation.min(
|
|
5411
|
+
"sl_trigger_price",
|
|
5412
|
+
slTriggerPriceScope
|
|
5413
|
+
);
|
|
5277
5414
|
}
|
|
5278
5415
|
if (!!sl_trigger_price && Number(sl_trigger_price) > config.markPrice) {
|
|
5279
|
-
result.sl_trigger_price =
|
|
5280
|
-
|
|
5281
|
-
|
|
5416
|
+
result.sl_trigger_price = OrderValidation.max(
|
|
5417
|
+
"sl_trigger_price",
|
|
5418
|
+
config.markPrice
|
|
5419
|
+
);
|
|
5282
5420
|
}
|
|
5283
5421
|
if (!!tp_trigger_price && Number(tp_trigger_price) <= config.markPrice) {
|
|
5284
|
-
result.tp_trigger_price =
|
|
5285
|
-
|
|
5286
|
-
|
|
5422
|
+
result.tp_trigger_price = OrderValidation.min(
|
|
5423
|
+
"tp_trigger_price",
|
|
5424
|
+
config.markPrice
|
|
5425
|
+
);
|
|
5287
5426
|
}
|
|
5288
5427
|
if (!!tp_trigger_price && Number(tp_trigger_price) > quote_max) {
|
|
5289
|
-
result.tp_trigger_price =
|
|
5290
|
-
|
|
5291
|
-
|
|
5428
|
+
result.tp_trigger_price = OrderValidation.max(
|
|
5429
|
+
"tp_trigger_price",
|
|
5430
|
+
quote_max
|
|
5431
|
+
);
|
|
5292
5432
|
}
|
|
5293
5433
|
if (!!sl_trigger_price && Number(sl_trigger_price) < quote_min) {
|
|
5294
|
-
result.sl_trigger_price =
|
|
5295
|
-
|
|
5296
|
-
|
|
5434
|
+
result.sl_trigger_price = OrderValidation.min(
|
|
5435
|
+
"sl_trigger_price",
|
|
5436
|
+
quote_min
|
|
5437
|
+
);
|
|
5297
5438
|
}
|
|
5298
5439
|
}
|
|
5299
5440
|
if (side === types.OrderSide.SELL && mark_price) {
|
|
5300
5441
|
const slTriggerPriceScope = new utils.Decimal(mark_price * (1 + price_scope)).toDecimalPlaces(quote_dp, utils.Decimal.ROUND_DOWN).toNumber();
|
|
5301
5442
|
if (!!sl_trigger_price && Number(sl_trigger_price) > slTriggerPriceScope) {
|
|
5302
|
-
result.sl_trigger_price =
|
|
5303
|
-
|
|
5304
|
-
|
|
5443
|
+
result.sl_trigger_price = OrderValidation.max(
|
|
5444
|
+
"sl_trigger_price",
|
|
5445
|
+
slTriggerPriceScope
|
|
5446
|
+
);
|
|
5305
5447
|
}
|
|
5306
5448
|
if (!!sl_trigger_price && Number(sl_trigger_price) < config.markPrice) {
|
|
5307
|
-
result.sl_trigger_price =
|
|
5308
|
-
|
|
5309
|
-
|
|
5449
|
+
result.sl_trigger_price = OrderValidation.min(
|
|
5450
|
+
"sl_trigger_price",
|
|
5451
|
+
config.markPrice
|
|
5452
|
+
);
|
|
5310
5453
|
}
|
|
5311
5454
|
if (!!tp_trigger_price && Number(tp_trigger_price) >= config.markPrice) {
|
|
5312
|
-
result.tp_trigger_price =
|
|
5313
|
-
|
|
5314
|
-
|
|
5455
|
+
result.tp_trigger_price = OrderValidation.max(
|
|
5456
|
+
"tp_trigger_price",
|
|
5457
|
+
config.markPrice
|
|
5458
|
+
);
|
|
5315
5459
|
}
|
|
5316
5460
|
if (!!tp_trigger_price && Number(tp_trigger_price) > quote_max) {
|
|
5317
|
-
result.tp_trigger_price =
|
|
5318
|
-
|
|
5319
|
-
|
|
5461
|
+
result.tp_trigger_price = OrderValidation.max(
|
|
5462
|
+
"tp_trigger_price",
|
|
5463
|
+
quote_max
|
|
5464
|
+
);
|
|
5320
5465
|
}
|
|
5321
5466
|
if (!!sl_trigger_price && Number(sl_trigger_price) < quote_min) {
|
|
5322
|
-
result.sl_trigger_price =
|
|
5323
|
-
|
|
5324
|
-
|
|
5467
|
+
result.sl_trigger_price = OrderValidation.min(
|
|
5468
|
+
"sl_trigger_price",
|
|
5469
|
+
quote_min
|
|
5470
|
+
);
|
|
5325
5471
|
}
|
|
5326
5472
|
}
|
|
5327
5473
|
return Object.keys(result).length > 0 ? result : null;
|
|
@@ -5493,64 +5639,66 @@ async function bracketOrderValidator(values2, config) {
|
|
|
5493
5639
|
const { quote_max, quote_min, price_scope, quote_dp } = config.symbol ?? {};
|
|
5494
5640
|
const mark_price = type === types.OrderType.MARKET ? config.markPrice : values2.order_price ? Number(values2.order_price) : void 0;
|
|
5495
5641
|
if (!isNaN(qty) && qty > maxQty) {
|
|
5496
|
-
result.quantity =
|
|
5497
|
-
message: `Quantity must be less than ${config.maxQty}`
|
|
5498
|
-
};
|
|
5642
|
+
result.quantity = OrderValidation.max("quantity", config.maxQty);
|
|
5499
5643
|
}
|
|
5500
5644
|
if (Number(tp_trigger_price) < 0) {
|
|
5501
|
-
result.tp_trigger_price =
|
|
5502
|
-
message: `TP Price must be greater than 0`
|
|
5503
|
-
};
|
|
5645
|
+
result.tp_trigger_price = OrderValidation.min("tp_trigger_price", 0);
|
|
5504
5646
|
}
|
|
5505
5647
|
if (Number(sl_trigger_price) < 0) {
|
|
5506
|
-
result.sl_trigger_price =
|
|
5507
|
-
message: `SL Price must be greater than 0`
|
|
5508
|
-
};
|
|
5648
|
+
result.sl_trigger_price = OrderValidation.min("sl_trigger_price", 0);
|
|
5509
5649
|
}
|
|
5510
5650
|
if (side === types.OrderSide.BUY && mark_price) {
|
|
5511
5651
|
const slTriggerPriceScope = new utils.Decimal(mark_price * (1 - price_scope)).toDecimalPlaces(quote_dp, utils.Decimal.ROUND_DOWN).toNumber();
|
|
5512
5652
|
if (!!sl_trigger_price && Number(sl_trigger_price) < slTriggerPriceScope) {
|
|
5513
|
-
result.sl_trigger_price =
|
|
5514
|
-
|
|
5515
|
-
|
|
5653
|
+
result.sl_trigger_price = OrderValidation.min(
|
|
5654
|
+
"sl_trigger_price",
|
|
5655
|
+
slTriggerPriceScope
|
|
5656
|
+
);
|
|
5516
5657
|
}
|
|
5517
5658
|
if (!!tp_trigger_price && Number(tp_trigger_price) <= mark_price) {
|
|
5518
|
-
result.tp_trigger_price =
|
|
5519
|
-
|
|
5520
|
-
|
|
5659
|
+
result.tp_trigger_price = OrderValidation.min(
|
|
5660
|
+
"tp_trigger_price",
|
|
5661
|
+
mark_price
|
|
5662
|
+
);
|
|
5521
5663
|
}
|
|
5522
5664
|
if (!!tp_trigger_price && Number(tp_trigger_price) > quote_max) {
|
|
5523
|
-
result.tp_trigger_price =
|
|
5524
|
-
|
|
5525
|
-
|
|
5665
|
+
result.tp_trigger_price = OrderValidation.max(
|
|
5666
|
+
"tp_trigger_price",
|
|
5667
|
+
quote_max
|
|
5668
|
+
);
|
|
5526
5669
|
}
|
|
5527
5670
|
if (!!sl_trigger_price && Number(sl_trigger_price) < quote_min) {
|
|
5528
|
-
result.sl_trigger_price =
|
|
5529
|
-
|
|
5530
|
-
|
|
5671
|
+
result.sl_trigger_price = OrderValidation.min(
|
|
5672
|
+
"sl_trigger_price",
|
|
5673
|
+
quote_min
|
|
5674
|
+
);
|
|
5531
5675
|
}
|
|
5532
5676
|
}
|
|
5533
5677
|
if (side === types.OrderSide.SELL && mark_price) {
|
|
5534
5678
|
const slTriggerPriceScope = new utils.Decimal(mark_price * (1 + price_scope)).toDecimalPlaces(quote_dp, utils.Decimal.ROUND_DOWN).toNumber();
|
|
5535
5679
|
if (!!sl_trigger_price && Number(sl_trigger_price) > slTriggerPriceScope) {
|
|
5536
|
-
result.sl_trigger_price =
|
|
5537
|
-
|
|
5538
|
-
|
|
5680
|
+
result.sl_trigger_price = OrderValidation.max(
|
|
5681
|
+
"sl_trigger_price",
|
|
5682
|
+
slTriggerPriceScope
|
|
5683
|
+
);
|
|
5539
5684
|
}
|
|
5540
5685
|
if (!!tp_trigger_price && Number(tp_trigger_price) >= mark_price) {
|
|
5541
|
-
result.tp_trigger_price =
|
|
5542
|
-
|
|
5543
|
-
|
|
5686
|
+
result.tp_trigger_price = OrderValidation.max(
|
|
5687
|
+
"tp_trigger_price",
|
|
5688
|
+
mark_price
|
|
5689
|
+
);
|
|
5544
5690
|
}
|
|
5545
5691
|
if (!!tp_trigger_price && Number(tp_trigger_price) > quote_max) {
|
|
5546
|
-
result.tp_trigger_price =
|
|
5547
|
-
|
|
5548
|
-
|
|
5692
|
+
result.tp_trigger_price = OrderValidation.max(
|
|
5693
|
+
"tp_trigger_price",
|
|
5694
|
+
quote_max
|
|
5695
|
+
);
|
|
5549
5696
|
}
|
|
5550
5697
|
if (!!sl_trigger_price && Number(sl_trigger_price) < quote_min) {
|
|
5551
|
-
result.sl_trigger_price =
|
|
5552
|
-
|
|
5553
|
-
|
|
5698
|
+
result.sl_trigger_price = OrderValidation.min(
|
|
5699
|
+
"sl_trigger_price",
|
|
5700
|
+
quote_min
|
|
5701
|
+
);
|
|
5554
5702
|
}
|
|
5555
5703
|
}
|
|
5556
5704
|
return Object.keys(result).length > 0 ? result : null;
|
|
@@ -5619,7 +5767,7 @@ var BBOOrderCreator = class extends BaseOrderCreator {
|
|
|
5619
5767
|
let { order_quantity, order_price, reduce_only, level } = values2;
|
|
5620
5768
|
const { symbol } = configs;
|
|
5621
5769
|
const { min_notional, base_tick, quote_dp, quote_tick, base_dp } = symbol || {};
|
|
5622
|
-
const
|
|
5770
|
+
const minNotional = getMinNotional({
|
|
5623
5771
|
base_tick,
|
|
5624
5772
|
quote_tick,
|
|
5625
5773
|
price: order_price,
|
|
@@ -5628,10 +5776,11 @@ var BBOOrderCreator = class extends BaseOrderCreator {
|
|
|
5628
5776
|
quote_dp,
|
|
5629
5777
|
base_dp
|
|
5630
5778
|
});
|
|
5631
|
-
if (
|
|
5779
|
+
if (minNotional !== void 0 && !reduce_only) {
|
|
5632
5780
|
errors.total = {
|
|
5633
5781
|
type: "min",
|
|
5634
|
-
message:
|
|
5782
|
+
message: `The order value should be greater or equal to ${minNotional} USDC`,
|
|
5783
|
+
value: minNotional
|
|
5635
5784
|
};
|
|
5636
5785
|
}
|
|
5637
5786
|
return errors;
|
|
@@ -5922,12 +6071,12 @@ var useSymbolLeverage = (symbol) => {
|
|
|
5922
6071
|
return maxLeverage;
|
|
5923
6072
|
};
|
|
5924
6073
|
var AssetHistoryStatusEnum = /* @__PURE__ */ ((AssetHistoryStatusEnum2) => {
|
|
5925
|
-
AssetHistoryStatusEnum2["NEW"] = "
|
|
5926
|
-
AssetHistoryStatusEnum2["CONFIRM"] = "
|
|
5927
|
-
AssetHistoryStatusEnum2["PROCESSING"] = "
|
|
5928
|
-
AssetHistoryStatusEnum2["COMPLETED"] = "
|
|
5929
|
-
AssetHistoryStatusEnum2["
|
|
5930
|
-
AssetHistoryStatusEnum2["PENDING_REBALANCE"] = "
|
|
6074
|
+
AssetHistoryStatusEnum2["NEW"] = "NEW";
|
|
6075
|
+
AssetHistoryStatusEnum2["CONFIRM"] = "CONFIRM";
|
|
6076
|
+
AssetHistoryStatusEnum2["PROCESSING"] = "PROCESSING";
|
|
6077
|
+
AssetHistoryStatusEnum2["COMPLETED"] = "COMPLETED";
|
|
6078
|
+
AssetHistoryStatusEnum2["FAILED"] = "FAILED";
|
|
6079
|
+
AssetHistoryStatusEnum2["PENDING_REBALANCE"] = "PENDING_REBALANCE";
|
|
5931
6080
|
return AssetHistoryStatusEnum2;
|
|
5932
6081
|
})(AssetHistoryStatusEnum || {});
|
|
5933
6082
|
var useAssetsHistory = (options) => {
|
|
@@ -5978,7 +6127,7 @@ var useStatisticsDaily = (params, options) => {
|
|
|
5978
6127
|
const { startDate, endDate, page = 1 } = params;
|
|
5979
6128
|
const { ignoreAggregation = false } = options || {};
|
|
5980
6129
|
if (!startDate || !endDate) {
|
|
5981
|
-
throw new types.SDKError("
|
|
6130
|
+
throw new types.SDKError("Start date and end date are required");
|
|
5982
6131
|
}
|
|
5983
6132
|
const getPeriod = (startDate2, endDate2) => {
|
|
5984
6133
|
if (startDate2 === endDate2) {
|
|
@@ -6124,11 +6273,14 @@ function useMaintenanceStatus() {
|
|
|
6124
6273
|
const [startTime, setStartTime] = React.useState();
|
|
6125
6274
|
const [endTime, setEndTime] = React.useState();
|
|
6126
6275
|
const [brokerName, setBrokerName] = React.useState("Orderly network");
|
|
6127
|
-
const { data: systemInfo, mutate: mutate3 } = useQuery(
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6276
|
+
const { data: systemInfo, mutate: mutate3 } = useQuery(
|
|
6277
|
+
`/v1/public/system_info?source=maintenance`,
|
|
6278
|
+
{
|
|
6279
|
+
revalidateOnFocus: false,
|
|
6280
|
+
errorRetryCount: 2,
|
|
6281
|
+
errorRetryInterval: 200
|
|
6282
|
+
}
|
|
6283
|
+
);
|
|
6132
6284
|
const ws = useWS();
|
|
6133
6285
|
const config = useConfig();
|
|
6134
6286
|
React.useEffect(() => {
|
|
@@ -6567,7 +6719,7 @@ var ProxyConfigStore = class {
|
|
|
6567
6719
|
(this._proxyConfigStore ?? this._originConfigStore).set(key, value);
|
|
6568
6720
|
}
|
|
6569
6721
|
clear() {
|
|
6570
|
-
throw new
|
|
6722
|
+
throw new types.SDKError("Method not implemented.");
|
|
6571
6723
|
}
|
|
6572
6724
|
getFromOrigin(key) {
|
|
6573
6725
|
return this._originConfigStore.get(key);
|
|
@@ -6688,91 +6840,6 @@ var OrderlyConfigProvider = (props) => {
|
|
|
6688
6840
|
}
|
|
6689
6841
|
);
|
|
6690
6842
|
};
|
|
6691
|
-
var apiKeyMap = {
|
|
6692
|
-
dev: "4d6b7db0fdd6e9de2b6a270414fd51e0",
|
|
6693
|
-
qa: "96476b00bc2701360f9b480629ae5263",
|
|
6694
|
-
staging: "dffc00e003479b86d410c448e00f2304",
|
|
6695
|
-
prod: "3ab9ae56ed16cc57bc2ac97ffc1098c2"
|
|
6696
|
-
};
|
|
6697
|
-
var TrackerContext = React.createContext({});
|
|
6698
|
-
var OrderlyTrackerProvider = ({ children }) => {
|
|
6699
|
-
const listenKeys = Object.keys(types.TrackerListenerKeyMap);
|
|
6700
|
-
const ee = useEventEmitter();
|
|
6701
|
-
const env = useGetEnv();
|
|
6702
|
-
const walletConnectRef = React.useRef(false);
|
|
6703
|
-
const { account: account5, state } = useAccount();
|
|
6704
|
-
const networkId = useConfig("networkId");
|
|
6705
|
-
const brokerId = useConfig("brokerId");
|
|
6706
|
-
const getChainInfo = useNetworkInfo(networkId);
|
|
6707
|
-
const handleEvent = React.useCallback(
|
|
6708
|
-
(key, params) => {
|
|
6709
|
-
account5?.accountId && amplitude__namespace.setUserId(account5?.accountId);
|
|
6710
|
-
if (key === types.EnumTrackerKeys.WALLET_CONNECT) {
|
|
6711
|
-
if (walletConnectRef.current)
|
|
6712
|
-
return;
|
|
6713
|
-
const info = getChainInfo(
|
|
6714
|
-
params?.connectWallet?.chainId
|
|
6715
|
-
).info;
|
|
6716
|
-
const { address = "", connectWallet } = params;
|
|
6717
|
-
const identify2 = {
|
|
6718
|
-
address,
|
|
6719
|
-
broker_id: brokerId,
|
|
6720
|
-
sdk_version: window?.__ORDERLY_VERSION__?.["@orderly.network/net"] ?? ""
|
|
6721
|
-
};
|
|
6722
|
-
const identifyEvent = new amplitude__namespace.Identify();
|
|
6723
|
-
Object.keys(identify2).map((subKey) => {
|
|
6724
|
-
identifyEvent.set(subKey, identify2[subKey]);
|
|
6725
|
-
});
|
|
6726
|
-
amplitude__namespace.identify(identifyEvent);
|
|
6727
|
-
const eventProperties = {
|
|
6728
|
-
wallet: connectWallet?.name,
|
|
6729
|
-
network: info?.network_infos?.name
|
|
6730
|
-
};
|
|
6731
|
-
amplitude__namespace.track(types.TrackerListenerKeyMap[key], eventProperties);
|
|
6732
|
-
walletConnectRef.current = true;
|
|
6733
|
-
return;
|
|
6734
|
-
}
|
|
6735
|
-
if (key === types.EnumTrackerKeys.SIGNIN_SUCCESS) {
|
|
6736
|
-
const info = getChainInfo(
|
|
6737
|
-
params?.connectWallet?.chainId
|
|
6738
|
-
).info;
|
|
6739
|
-
amplitude__namespace.track(types.TrackerListenerKeyMap[key], {
|
|
6740
|
-
wallet: params?.connectWallet?.name,
|
|
6741
|
-
network: info?.network_infos?.name
|
|
6742
|
-
});
|
|
6743
|
-
return;
|
|
6744
|
-
}
|
|
6745
|
-
amplitude__namespace.track(types.TrackerListenerKeyMap[key], params);
|
|
6746
|
-
},
|
|
6747
|
-
[account5?.accountId, brokerId, state?.connectWallet?.name]
|
|
6748
|
-
);
|
|
6749
|
-
React.useEffect(() => {
|
|
6750
|
-
amplitude__namespace.init(apiKeyMap[env], { serverZone: "EU" });
|
|
6751
|
-
listenKeys.forEach((key) => {
|
|
6752
|
-
ee.on(key, (params = {}) => {
|
|
6753
|
-
setTimeout(() => {
|
|
6754
|
-
handleEvent(key, params);
|
|
6755
|
-
}, 2e3);
|
|
6756
|
-
});
|
|
6757
|
-
});
|
|
6758
|
-
return () => {
|
|
6759
|
-
listenKeys.forEach((key) => {
|
|
6760
|
-
ee.off(key);
|
|
6761
|
-
});
|
|
6762
|
-
};
|
|
6763
|
-
}, [env]);
|
|
6764
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6765
|
-
TrackerContext.Provider,
|
|
6766
|
-
{
|
|
6767
|
-
value: {
|
|
6768
|
-
track: (key, params) => {
|
|
6769
|
-
amplitude__namespace.track(key, params);
|
|
6770
|
-
}
|
|
6771
|
-
},
|
|
6772
|
-
children
|
|
6773
|
-
}
|
|
6774
|
-
);
|
|
6775
|
-
};
|
|
6776
6843
|
var WalletConnectorContext = React.createContext({});
|
|
6777
6844
|
var useWalletConnector = () => {
|
|
6778
6845
|
return React.useContext(WalletConnectorContext);
|
|
@@ -7019,13 +7086,13 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
7019
7086
|
if (typeof symbolOrOrder === "object") {
|
|
7020
7087
|
isNewVersion = true;
|
|
7021
7088
|
if (!symbolOrOrder.symbol) {
|
|
7022
|
-
throw new types.SDKError("
|
|
7089
|
+
throw new types.SDKError("Symbol is required");
|
|
7023
7090
|
}
|
|
7024
7091
|
if (!symbolOrOrder.side) {
|
|
7025
7092
|
throw new types.SDKError("Order side is required");
|
|
7026
7093
|
}
|
|
7027
7094
|
if (!symbolOrOrder.order_type) {
|
|
7028
|
-
throw new types.SDKError("
|
|
7095
|
+
throw new types.SDKError("Order type is required");
|
|
7029
7096
|
}
|
|
7030
7097
|
}
|
|
7031
7098
|
const prevOrderData = React.useRef(null);
|
|
@@ -7186,20 +7253,20 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
7186
7253
|
);
|
|
7187
7254
|
const createOrder = (values2) => {
|
|
7188
7255
|
if (!values2.symbol) {
|
|
7189
|
-
throw new types.SDKError("
|
|
7256
|
+
throw new types.SDKError("Symbol is error");
|
|
7190
7257
|
}
|
|
7191
7258
|
if (!values2.side) {
|
|
7192
|
-
throw new types.SDKError("side is error");
|
|
7259
|
+
throw new types.SDKError("Order side is error");
|
|
7193
7260
|
}
|
|
7194
7261
|
if (!values2 || typeof values2.order_type === "undefined") {
|
|
7195
|
-
throw new types.SDKError("
|
|
7262
|
+
throw new types.SDKError("Order type is error");
|
|
7196
7263
|
}
|
|
7197
7264
|
const orderCreator = OrderFactory.create(
|
|
7198
7265
|
// @ts-ignore
|
|
7199
7266
|
values2.order_type_ext ? values2.order_type_ext : values2.order_type
|
|
7200
7267
|
);
|
|
7201
7268
|
if (!orderCreator) {
|
|
7202
|
-
return Promise.reject(new types.SDKError("
|
|
7269
|
+
return Promise.reject(new types.SDKError("Order creator is null"));
|
|
7203
7270
|
}
|
|
7204
7271
|
return new Promise((resolve, reject) => {
|
|
7205
7272
|
return orderCreator.validate(values2, {
|
|
@@ -14087,9 +14154,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
14087
14154
|
};
|
|
14088
14155
|
var useOrderEntry2 = (symbol, options = {}) => {
|
|
14089
14156
|
if (!symbol) {
|
|
14090
|
-
throw new types.SDKError("
|
|
14157
|
+
throw new types.SDKError("Symbol is required");
|
|
14091
14158
|
}
|
|
14092
14159
|
const ee = useEventEmitter();
|
|
14160
|
+
const { track: track2 } = useTrack();
|
|
14093
14161
|
const [meta, setMeta] = React.useState({
|
|
14094
14162
|
dirty: {},
|
|
14095
14163
|
submitted: false,
|
|
@@ -14241,28 +14309,30 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
14241
14309
|
return validate(order, creator, prepareData());
|
|
14242
14310
|
}
|
|
14243
14311
|
const validateOrder = () => {
|
|
14244
|
-
return new Promise(
|
|
14245
|
-
|
|
14246
|
-
|
|
14247
|
-
|
|
14248
|
-
|
|
14249
|
-
|
|
14250
|
-
immer$1.produce((draft) => {
|
|
14251
|
-
draft.errors = errors;
|
|
14252
|
-
})
|
|
14253
|
-
);
|
|
14254
|
-
if (!meta.validated) {
|
|
14312
|
+
return new Promise(
|
|
14313
|
+
async (resolve, reject) => {
|
|
14314
|
+
const creator = getOrderCreator(formattedOrder);
|
|
14315
|
+
const errors = await validate(formattedOrder, creator, prepareData());
|
|
14316
|
+
const keys = Object.keys(errors);
|
|
14317
|
+
if (keys.length > 0) {
|
|
14255
14318
|
setMeta(
|
|
14256
14319
|
immer$1.produce((draft) => {
|
|
14257
|
-
draft.
|
|
14320
|
+
draft.errors = errors;
|
|
14258
14321
|
})
|
|
14259
14322
|
);
|
|
14323
|
+
if (!meta.validated) {
|
|
14324
|
+
setMeta(
|
|
14325
|
+
immer$1.produce((draft) => {
|
|
14326
|
+
draft.validated = true;
|
|
14327
|
+
})
|
|
14328
|
+
);
|
|
14329
|
+
}
|
|
14330
|
+
reject(errors);
|
|
14260
14331
|
}
|
|
14261
|
-
|
|
14332
|
+
const order = generateOrder(creator, prepareData());
|
|
14333
|
+
resolve(order);
|
|
14262
14334
|
}
|
|
14263
|
-
|
|
14264
|
-
resolve(order);
|
|
14265
|
-
});
|
|
14335
|
+
);
|
|
14266
14336
|
};
|
|
14267
14337
|
const { freeCollateral, totalCollateral } = useCollateral();
|
|
14268
14338
|
const estLiqPrice = React.useMemo(() => {
|
|
@@ -14329,12 +14399,12 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
14329
14399
|
draft.errors = errors;
|
|
14330
14400
|
})
|
|
14331
14401
|
);
|
|
14332
|
-
throw new
|
|
14402
|
+
throw new types.SDKError("Order validation failed");
|
|
14333
14403
|
}
|
|
14334
14404
|
const order = generateOrder(creator, prepareData());
|
|
14335
14405
|
const result = await doCreateOrder(order);
|
|
14336
14406
|
if (result.success) {
|
|
14337
|
-
|
|
14407
|
+
track2(types.EnumTrackerKeys.placeorderSuccess, {
|
|
14338
14408
|
side: order.side,
|
|
14339
14409
|
order_type: order.order_type,
|
|
14340
14410
|
tp_sl: hasTPSL(formattedOrder),
|
|
@@ -14462,7 +14532,7 @@ var useOrderStore2 = zustand.create()(
|
|
|
14462
14532
|
);
|
|
14463
14533
|
var useOrderEntity = (order, options) => {
|
|
14464
14534
|
if (!order.symbol) {
|
|
14465
|
-
throw new types.SDKError("
|
|
14535
|
+
throw new types.SDKError("Symbol is required");
|
|
14466
14536
|
}
|
|
14467
14537
|
const [errors, setErrors] = React.useState();
|
|
14468
14538
|
const maxQty = useMaxQty(order.symbol, order.side, order.reduce_only);
|
|
@@ -14477,27 +14547,29 @@ var useOrderEntity = (order, options) => {
|
|
|
14477
14547
|
}, [finalMaxQty, order.symbol, order]);
|
|
14478
14548
|
const symbolInfo = useSymbolsInfo();
|
|
14479
14549
|
const validate = () => {
|
|
14480
|
-
return new Promise(
|
|
14481
|
-
|
|
14482
|
-
|
|
14483
|
-
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
|
|
14550
|
+
return new Promise(
|
|
14551
|
+
async (resolve, reject) => {
|
|
14552
|
+
const creator = getOrderCreator(order);
|
|
14553
|
+
const _symbol = symbolInfo[order.symbol]();
|
|
14554
|
+
const errors2 = await creator?.validate(order, {
|
|
14555
|
+
symbol: _symbol,
|
|
14556
|
+
maxQty: finalMaxQty,
|
|
14557
|
+
markPrice
|
|
14558
|
+
});
|
|
14559
|
+
const keys = Object.keys(errors2);
|
|
14560
|
+
if (keys.length > 0) {
|
|
14561
|
+
setErrors(errors2);
|
|
14562
|
+
reject(errors2);
|
|
14563
|
+
} else {
|
|
14564
|
+
setErrors({});
|
|
14565
|
+
}
|
|
14566
|
+
const orderEntity = creator.create(order, {
|
|
14567
|
+
...prepareData(),
|
|
14568
|
+
symbol: _symbol
|
|
14569
|
+
});
|
|
14570
|
+
resolve(orderEntity);
|
|
14494
14571
|
}
|
|
14495
|
-
|
|
14496
|
-
...prepareData(),
|
|
14497
|
-
symbol: _symbol
|
|
14498
|
-
});
|
|
14499
|
-
resolve(orderEntity);
|
|
14500
|
-
});
|
|
14572
|
+
);
|
|
14501
14573
|
};
|
|
14502
14574
|
const autoCheck = useDebounce.useThrottledCallback(
|
|
14503
14575
|
() => {
|
|
@@ -14612,7 +14684,6 @@ exports.MarketsType = MarketsType;
|
|
|
14612
14684
|
exports.OrderlyConfigProvider = OrderlyConfigProvider;
|
|
14613
14685
|
exports.OrderlyContext = OrderlyContext;
|
|
14614
14686
|
exports.OrderlyProvider = OrderlyProvider;
|
|
14615
|
-
exports.OrderlyTrackerProvider = OrderlyTrackerProvider;
|
|
14616
14687
|
exports.StatusContext = StatusContext;
|
|
14617
14688
|
exports.StatusProvider = StatusProvider;
|
|
14618
14689
|
exports.TWType = TWType;
|
|
@@ -14620,6 +14691,7 @@ exports.WalletConnectorContext = WalletConnectorContext;
|
|
|
14620
14691
|
exports.WsNetworkStatus = WsNetworkStatus;
|
|
14621
14692
|
exports.checkNotional = checkNotional;
|
|
14622
14693
|
exports.cleanStringStyle = cleanStringStyle;
|
|
14694
|
+
exports.getMinNotional = getMinNotional;
|
|
14623
14695
|
exports.parseJSON = parseJSON;
|
|
14624
14696
|
exports.useAccount = useAccount;
|
|
14625
14697
|
exports.useAccountInfo = useAccountInfo2;
|
|
@@ -14693,12 +14765,15 @@ exports.useSessionStorage = useSessionStorage;
|
|
|
14693
14765
|
exports.useSettleSubscription = useSettleSubscription;
|
|
14694
14766
|
exports.useSimpleDI = useSimpleDI;
|
|
14695
14767
|
exports.useStatisticsDaily = useStatisticsDaily;
|
|
14768
|
+
exports.useStorageChain = useStorageChain;
|
|
14696
14769
|
exports.useStorageLedgerAddress = useStorageLedgerAddress;
|
|
14697
14770
|
exports.useSymbolLeverage = useSymbolLeverage;
|
|
14698
14771
|
exports.useSymbolPriceRange = useSymbolPriceRange;
|
|
14699
14772
|
exports.useSymbolsInfo = useSymbolsInfo;
|
|
14700
14773
|
exports.useTPSLOrder = useTPSLOrder;
|
|
14701
14774
|
exports.useTickerStream = useTickerStream;
|
|
14775
|
+
exports.useTrack = useTrack;
|
|
14776
|
+
exports.useTrackingInstance = useTrackingInstance;
|
|
14702
14777
|
exports.useWS = useWS;
|
|
14703
14778
|
exports.useWalletConnector = useWalletConnector;
|
|
14704
14779
|
exports.useWalletRewardsHistory = useWalletRewardsHistory;
|