@orderly.network/hooks 2.8.10 → 2.8.11-alpha.1
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 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +128 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -152
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -13
package/dist/index.js
CHANGED
|
@@ -64,9 +64,9 @@ var __export = (target, all) => {
|
|
|
64
64
|
// src/version.ts
|
|
65
65
|
if (typeof window !== "undefined") {
|
|
66
66
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
67
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.
|
|
67
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.11-alpha.1";
|
|
68
68
|
}
|
|
69
|
-
var version_default = "2.8.
|
|
69
|
+
var version_default = "2.8.11-alpha.1";
|
|
70
70
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
71
71
|
var noCacheConfig = {
|
|
72
72
|
dedupingInterval: 0,
|
|
@@ -510,8 +510,7 @@ var usePrivateInfiniteQuery = (getKey, options) => {
|
|
|
510
510
|
const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
|
|
511
511
|
const result = useSWRInfinite__default.default(
|
|
512
512
|
(pageIndex, previousPageData) => {
|
|
513
|
-
if (!getKey)
|
|
514
|
-
return null;
|
|
513
|
+
if (!getKey) return null;
|
|
515
514
|
const queryKey = getKey(pageIndex, previousPageData);
|
|
516
515
|
if (queryKey && (state.status >= types.AccountStatusEnum.EnableTrading || state.status === types.AccountStatusEnum.EnableTradingWithoutConnected)) {
|
|
517
516
|
return [queryKey, state.accountId];
|
|
@@ -556,8 +555,8 @@ var useUpdatedRef = (val) => {
|
|
|
556
555
|
return latestRef;
|
|
557
556
|
};
|
|
558
557
|
var useMemoizedFn = (fn) => {
|
|
559
|
-
const safeFn = typeof fn === "function" ? fn : () => {
|
|
560
|
-
};
|
|
558
|
+
const safeFn = typeof fn === "function" ? fn : (() => {
|
|
559
|
+
});
|
|
561
560
|
const fnRef = React2.useRef(safeFn);
|
|
562
561
|
fnRef.current = React2.useMemo(() => safeFn, [safeFn]);
|
|
563
562
|
const wrapperRef = React2.useRef(null);
|
|
@@ -1138,8 +1137,7 @@ var findPositionTPSLFromOrders = (orders, symbol) => {
|
|
|
1138
1137
|
};
|
|
1139
1138
|
function offsetToPrice(inputs) {
|
|
1140
1139
|
const { qty, offset, entryPrice, orderType, orderSide } = inputs;
|
|
1141
|
-
if (!offset)
|
|
1142
|
-
return;
|
|
1140
|
+
if (!offset) return;
|
|
1143
1141
|
if (orderSide === types.OrderSide.BUY) {
|
|
1144
1142
|
if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
|
|
1145
1143
|
return new utils.Decimal(entryPrice).add(new utils.Decimal(offset)).toNumber();
|
|
@@ -1176,8 +1174,7 @@ function priceToOffset(inputs, options = {}) {
|
|
|
1176
1174
|
}
|
|
1177
1175
|
function offsetPercentageToPrice(inputs) {
|
|
1178
1176
|
const { qty, percentage, entryPrice, orderType, orderSide } = inputs;
|
|
1179
|
-
if (!percentage)
|
|
1180
|
-
return;
|
|
1177
|
+
if (!percentage) return;
|
|
1181
1178
|
if (orderSide === types.OrderSide.BUY) {
|
|
1182
1179
|
if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
|
|
1183
1180
|
return new utils.Decimal(1).add(new utils.Decimal(percentage)).mul(new utils.Decimal(entryPrice)).toNumber();
|
|
@@ -1200,16 +1197,14 @@ function priceToOffsetPercentage(inputs) {
|
|
|
1200
1197
|
orderPrice: entryPrice
|
|
1201
1198
|
});
|
|
1202
1199
|
if (orderSide === types.OrderSide.BUY) {
|
|
1203
|
-
if (entryPrice === 0)
|
|
1204
|
-
return 0;
|
|
1200
|
+
if (entryPrice === 0) return 0;
|
|
1205
1201
|
if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
|
|
1206
1202
|
return new utils.Decimal(price).div(new utils.Decimal(entryPrice)).minus(1).abs().mul(direction).toDecimalPlaces(4, utils.Decimal.ROUND_DOWN).toNumber();
|
|
1207
1203
|
}
|
|
1208
1204
|
return new utils.Decimal(1).minus(new utils.Decimal(price).div(new utils.Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, utils.Decimal.ROUND_DOWN).toNumber();
|
|
1209
1205
|
}
|
|
1210
1206
|
if (orderSide === types.OrderSide.SELL) {
|
|
1211
|
-
if (entryPrice === 0)
|
|
1212
|
-
return 0;
|
|
1207
|
+
if (entryPrice === 0) return 0;
|
|
1213
1208
|
if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
|
|
1214
1209
|
return new utils.Decimal(1).minus(new utils.Decimal(price).div(new utils.Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, utils.Decimal.ROUND_DOWN).toNumber();
|
|
1215
1210
|
}
|
|
@@ -1221,8 +1216,7 @@ function pnlToPrice(inputs) {
|
|
|
1221
1216
|
if (!pnl) {
|
|
1222
1217
|
return;
|
|
1223
1218
|
}
|
|
1224
|
-
if (qty === 0)
|
|
1225
|
-
return;
|
|
1219
|
+
if (qty === 0) return;
|
|
1226
1220
|
if (orderSide === types.OrderSide.BUY) {
|
|
1227
1221
|
if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
|
|
1228
1222
|
return new utils.Decimal(entryPrice).plus(new utils.Decimal(pnl).div(new utils.Decimal(qty))).toNumber();
|
|
@@ -1304,8 +1298,7 @@ function priceToROI(inputs) {
|
|
|
1304
1298
|
function calcTPSL_ROI(inputs) {
|
|
1305
1299
|
const qtyNum = Number(inputs.qty);
|
|
1306
1300
|
const priceNum = Number(inputs.price);
|
|
1307
|
-
if (qtyNum === 0 || priceNum === 0)
|
|
1308
|
-
return "0";
|
|
1301
|
+
if (qtyNum === 0 || priceNum === 0) return "0";
|
|
1309
1302
|
return new utils.Decimal(inputs.pnl).div(new utils.Decimal(qtyNum).abs().mul(new utils.Decimal(priceNum))).toString();
|
|
1310
1303
|
}
|
|
1311
1304
|
function checkTPSLOrderTypeIsMarket(key, values) {
|
|
@@ -1354,6 +1347,31 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
1354
1347
|
}
|
|
1355
1348
|
break;
|
|
1356
1349
|
}
|
|
1350
|
+
// case "tp_enable":
|
|
1351
|
+
// case "sl_enable": {
|
|
1352
|
+
// return {
|
|
1353
|
+
// [`${keyPrefix}enable`]: inputs.value,
|
|
1354
|
+
// [`${keyPrefix}order_type`]: OrderType.MARKET,
|
|
1355
|
+
// [`${keyPrefix}trigger_price`]: "",
|
|
1356
|
+
// [`${keyPrefix}order_price`]: "",
|
|
1357
|
+
// [`${keyPrefix}offset`]: "",
|
|
1358
|
+
// [`${keyPrefix}offset_percentage`]: "",
|
|
1359
|
+
// [`${keyPrefix}pnl`]: "",
|
|
1360
|
+
// [`${keyPrefix}ROI`]: "",
|
|
1361
|
+
// };
|
|
1362
|
+
// }
|
|
1363
|
+
// case 'tp_pnl':{
|
|
1364
|
+
// if (inputs.values.tp_order_type !== OrderType.MARKET) {
|
|
1365
|
+
// pnl = inputs.value;
|
|
1366
|
+
// trigger_price = pnlToPrice({
|
|
1367
|
+
// qty,
|
|
1368
|
+
// pnl: Number(inputs.value),
|
|
1369
|
+
// entryPrice,
|
|
1370
|
+
// orderSide: inputs.orderSide,
|
|
1371
|
+
// orderType,
|
|
1372
|
+
// })
|
|
1373
|
+
// }
|
|
1374
|
+
// }
|
|
1357
1375
|
case "tp_pnl":
|
|
1358
1376
|
case "sl_pnl": {
|
|
1359
1377
|
pnl = inputs.value;
|
|
@@ -1702,6 +1720,8 @@ var getCalculateHandler = (fieldName) => {
|
|
|
1702
1720
|
case "total": {
|
|
1703
1721
|
return totalInputHandle;
|
|
1704
1722
|
}
|
|
1723
|
+
// case "tp_enable":
|
|
1724
|
+
// case "sl_enable":
|
|
1705
1725
|
case "tp_pnl":
|
|
1706
1726
|
case "sl_pnl":
|
|
1707
1727
|
case "tp_trigger_price":
|
|
@@ -1720,17 +1740,14 @@ var getCalculateHandler = (fieldName) => {
|
|
|
1720
1740
|
}
|
|
1721
1741
|
};
|
|
1722
1742
|
function formatNumber(qty, dp) {
|
|
1723
|
-
if (typeof qty === "undefined")
|
|
1724
|
-
|
|
1725
|
-
if (typeof dp === "undefined")
|
|
1726
|
-
return `${qty}`;
|
|
1743
|
+
if (typeof qty === "undefined") return qty;
|
|
1744
|
+
if (typeof dp === "undefined") return `${qty}`;
|
|
1727
1745
|
const _qty = `${qty}`.replace(/,/g, "");
|
|
1728
1746
|
try {
|
|
1729
1747
|
const _dp = new utils.Decimal(dp);
|
|
1730
1748
|
const _qtyDecimal = new utils.Decimal(_qty);
|
|
1731
1749
|
if (_dp.lessThan(1)) {
|
|
1732
|
-
if (`${_qty}`.endsWith("."))
|
|
1733
|
-
return `${_qty}`;
|
|
1750
|
+
if (`${_qty}`.endsWith(".")) return `${_qty}`;
|
|
1734
1751
|
const numStr = dp.toString();
|
|
1735
1752
|
const decimalIndex = numStr.indexOf(".");
|
|
1736
1753
|
const digitsAfterDecimal = decimalIndex === -1 ? 0 : numStr.length - decimalIndex - 1;
|
|
@@ -2754,21 +2771,18 @@ var usePreLoadData = () => {
|
|
|
2754
2771
|
});
|
|
2755
2772
|
}, []);
|
|
2756
2773
|
React2.useEffect(() => {
|
|
2757
|
-
if (!urlPrefix)
|
|
2758
|
-
return;
|
|
2774
|
+
if (!urlPrefix) return;
|
|
2759
2775
|
fetchTestTokens(urlPrefix);
|
|
2760
2776
|
fetchTestChains(urlPrefix, {
|
|
2761
2777
|
brokerId: configStore.get("brokerId")
|
|
2762
2778
|
});
|
|
2763
2779
|
}, [urlPrefix]);
|
|
2764
2780
|
React2.useEffect(() => {
|
|
2765
|
-
if (!mainTokenInfo || !testTokenInfo)
|
|
2766
|
-
return;
|
|
2781
|
+
if (!mainTokenInfo || !testTokenInfo) return;
|
|
2767
2782
|
setTokensInfo(env === "prod" ? mainTokenInfo : testTokenInfo);
|
|
2768
2783
|
}, [mainTokenInfo, testTokenInfo]);
|
|
2769
2784
|
React2.useEffect(() => {
|
|
2770
|
-
if (swapSupportInfo || !enableSwapDeposit)
|
|
2771
|
-
return;
|
|
2785
|
+
if (swapSupportInfo || !enableSwapDeposit) return;
|
|
2772
2786
|
fetchSwapSupport();
|
|
2773
2787
|
}, [swapSupportInfo, enableSwapDeposit]);
|
|
2774
2788
|
const { data: systemInfo } = useSWR__namespace.default(
|
|
@@ -2786,8 +2800,7 @@ var usePreLoadData = () => {
|
|
|
2786
2800
|
}
|
|
2787
2801
|
);
|
|
2788
2802
|
React2.useEffect(() => {
|
|
2789
|
-
if (timestampOffsetInitialized)
|
|
2790
|
-
return;
|
|
2803
|
+
if (timestampOffsetInitialized) return;
|
|
2791
2804
|
if (typeof systemInfo !== "undefined") {
|
|
2792
2805
|
const serverTimestamp = systemInfo.timestamp;
|
|
2793
2806
|
const localTimestamp = Date.now();
|
|
@@ -3063,8 +3076,7 @@ var AmplitudeTracker = class {
|
|
|
3063
3076
|
this._userId = userId;
|
|
3064
3077
|
}
|
|
3065
3078
|
setSdkInfo(sdkInfo) {
|
|
3066
|
-
if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag)
|
|
3067
|
-
return;
|
|
3079
|
+
if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag) return;
|
|
3068
3080
|
this.identify(sdkInfo);
|
|
3069
3081
|
this._sdkInfoTag = sdkInfo.address;
|
|
3070
3082
|
}
|
|
@@ -3192,6 +3204,10 @@ var DEFAULT_TICK_SIZES = {
|
|
|
3192
3204
|
var DEFAULT_SYMBOL_DEPTHS = {
|
|
3193
3205
|
PERP_ETH_USDC: [0.01, 0.1, 0.5, 1, 10]
|
|
3194
3206
|
};
|
|
3207
|
+
var DEFAULT_SYMBOL_DISPLAY_NAMES = {
|
|
3208
|
+
PERP_XAU_USDC: "XAU (Gold) ",
|
|
3209
|
+
PERP_XAG_USDC: "XAG (Silver)"
|
|
3210
|
+
};
|
|
3195
3211
|
var ProxyConfigStore = class {
|
|
3196
3212
|
constructor(_originConfigStore) {
|
|
3197
3213
|
this._originConfigStore = _originConfigStore;
|
|
@@ -3272,10 +3288,8 @@ var useMarketsStream = () => {
|
|
|
3272
3288
|
};
|
|
3273
3289
|
});
|
|
3274
3290
|
const value = React2.useMemo(() => {
|
|
3275
|
-
if (!futures)
|
|
3276
|
-
|
|
3277
|
-
if (!tickers)
|
|
3278
|
-
return futures;
|
|
3291
|
+
if (!futures) return null;
|
|
3292
|
+
if (!tickers) return futures;
|
|
3279
3293
|
return futures.map((item) => {
|
|
3280
3294
|
const ticker = tickers.find(
|
|
3281
3295
|
(t) => t.symbol === item.symbol
|
|
@@ -3318,8 +3332,7 @@ function createGetter(data, depth = 2) {
|
|
|
3318
3332
|
}
|
|
3319
3333
|
if (depth === 1) {
|
|
3320
3334
|
return (defaultValue) => {
|
|
3321
|
-
if (!target)
|
|
3322
|
-
return defaultValue;
|
|
3335
|
+
if (!target) return defaultValue;
|
|
3323
3336
|
return getValue(target[property], defaultValue);
|
|
3324
3337
|
};
|
|
3325
3338
|
}
|
|
@@ -3660,6 +3673,7 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
|
|
|
3660
3673
|
...item,
|
|
3661
3674
|
quote_dp: info("quote_dp"),
|
|
3662
3675
|
created_time: info("created_time"),
|
|
3676
|
+
displayName: info("displayName"),
|
|
3663
3677
|
leverage: getLeverage(info("base_imr")),
|
|
3664
3678
|
openInterest: getOpenInterest(item.open_interest, item.index_price),
|
|
3665
3679
|
"8h_funding": get8hFunding(item.est_funding_rate, info("funding_period")),
|
|
@@ -3873,8 +3887,7 @@ var useWSObserver = (calculatorService) => {
|
|
|
3873
3887
|
});
|
|
3874
3888
|
const indexPriceSubscription = ws.subscribe("indexprices", {
|
|
3875
3889
|
onMessage: (message) => {
|
|
3876
|
-
if (!Array.isArray(message))
|
|
3877
|
-
return;
|
|
3890
|
+
if (!Array.isArray(message)) return;
|
|
3878
3891
|
const prices = /* @__PURE__ */ Object.create(null);
|
|
3879
3892
|
for (let index = 0; index < message.length; index++) {
|
|
3880
3893
|
const element = message[index];
|
|
@@ -4111,10 +4124,8 @@ var useTickerStream = (symbol) => {
|
|
|
4111
4124
|
const { data: openInterest } = useOpenInterest(symbol);
|
|
4112
4125
|
const marketMap = useMarketMap();
|
|
4113
4126
|
const value = React2.useMemo(() => {
|
|
4114
|
-
if (!info)
|
|
4115
|
-
|
|
4116
|
-
if (!ticker || ticker.symbol !== symbol)
|
|
4117
|
-
return info;
|
|
4127
|
+
if (!info) return null;
|
|
4128
|
+
if (!ticker || ticker.symbol !== symbol) return info;
|
|
4118
4129
|
const config = {
|
|
4119
4130
|
...info,
|
|
4120
4131
|
mark_price: markPrice,
|
|
@@ -5130,8 +5141,7 @@ var CalculatorService = class {
|
|
|
5130
5141
|
if (!ctx.isReady && options?.skipPending) {
|
|
5131
5142
|
return;
|
|
5132
5143
|
}
|
|
5133
|
-
if (options?.skipWhenOnPause && !this.windowIsVisible)
|
|
5134
|
-
return;
|
|
5144
|
+
if (options?.skipWhenOnPause && !this.windowIsVisible) return;
|
|
5135
5145
|
this.calcQueue.push({ scope, data, options });
|
|
5136
5146
|
await this.handleCalcQueue(ctx);
|
|
5137
5147
|
this.ctx = ctx;
|
|
@@ -5332,8 +5342,7 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5332
5342
|
return data;
|
|
5333
5343
|
}
|
|
5334
5344
|
update(data, scope) {
|
|
5335
|
-
if (!data || !Array.isArray(data.rows))
|
|
5336
|
-
return;
|
|
5345
|
+
if (!data || !Array.isArray(data.rows)) return;
|
|
5337
5346
|
usePositionStore.getState().actions.setPositions(this.symbol, data);
|
|
5338
5347
|
if (Array.isArray(data.rows) && useApiStatusStore.getState().apis.positions.loading) {
|
|
5339
5348
|
useApiStatusStore.getState().actions.updateApiLoading("positions", false);
|
|
@@ -5372,8 +5381,7 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5372
5381
|
return this.format(positions3, ctx);
|
|
5373
5382
|
}
|
|
5374
5383
|
calcByPosition(positions3, ctx) {
|
|
5375
|
-
if (positions3.rows.length === 0)
|
|
5376
|
-
return positions3;
|
|
5384
|
+
if (positions3.rows.length === 0) return positions3;
|
|
5377
5385
|
return this.format(positions3, ctx);
|
|
5378
5386
|
}
|
|
5379
5387
|
format(data, ctx) {
|
|
@@ -5586,8 +5594,7 @@ var IndexPriceCalculator = class extends BaseCalculator {
|
|
|
5586
5594
|
return data;
|
|
5587
5595
|
}
|
|
5588
5596
|
update(data) {
|
|
5589
|
-
if (!data)
|
|
5590
|
-
return;
|
|
5597
|
+
if (!data) return;
|
|
5591
5598
|
useIndexPriceStore.getState().actions.updateIndexPrice(data);
|
|
5592
5599
|
}
|
|
5593
5600
|
static getValue() {
|
|
@@ -5981,8 +5988,7 @@ var useOrderStream = (params, options) => {
|
|
|
5981
5988
|
registerKeyHandler?.(key.replace("orders", "algoOrders"), algoOrderKeyFn);
|
|
5982
5989
|
}
|
|
5983
5990
|
return () => {
|
|
5984
|
-
if (!options?.stopOnUnmount)
|
|
5985
|
-
return;
|
|
5991
|
+
if (!options?.stopOnUnmount) return;
|
|
5986
5992
|
unregisterKeyHandler(key);
|
|
5987
5993
|
if (algoOrderKeyFn) {
|
|
5988
5994
|
unregisterKeyHandler(key.replace("orders", "algoOrders"));
|
|
@@ -6548,8 +6554,7 @@ var useSubAccountDataObserver = (accountId) => {
|
|
|
6548
6554
|
tokensInfo
|
|
6549
6555
|
]);
|
|
6550
6556
|
React2.useEffect(() => {
|
|
6551
|
-
if (!positionsInfo)
|
|
6552
|
-
return;
|
|
6557
|
+
if (!positionsInfo) return;
|
|
6553
6558
|
if (positionsInfo.rows?.length === 0) {
|
|
6554
6559
|
setPositions(positionsInfo);
|
|
6555
6560
|
return;
|
|
@@ -6581,8 +6586,7 @@ var useSubAccountDataObserver = (accountId) => {
|
|
|
6581
6586
|
}
|
|
6582
6587
|
}, [holdingRes]);
|
|
6583
6588
|
React2.useEffect(() => {
|
|
6584
|
-
if (!accountId)
|
|
6585
|
-
return;
|
|
6589
|
+
if (!accountId) return;
|
|
6586
6590
|
const unsubscribe = ws.privateSubscribe(
|
|
6587
6591
|
{
|
|
6588
6592
|
id: "balance",
|
|
@@ -6607,8 +6611,7 @@ var useSubAccountDataObserver = (accountId) => {
|
|
|
6607
6611
|
return () => unsubscribe?.();
|
|
6608
6612
|
}, [accountId]);
|
|
6609
6613
|
React2.useEffect(() => {
|
|
6610
|
-
if (!accountId)
|
|
6611
|
-
return;
|
|
6614
|
+
if (!accountId) return;
|
|
6612
6615
|
const key = ["/v1/positions", accountId];
|
|
6613
6616
|
const unsubscribe = ws.privateSubscribe("position", {
|
|
6614
6617
|
onMessage: (data) => {
|
|
@@ -7092,8 +7095,7 @@ var useLeverageBySymbol = (symbol) => {
|
|
|
7092
7095
|
}
|
|
7093
7096
|
);
|
|
7094
7097
|
React2.useEffect(() => {
|
|
7095
|
-
if (!state.accountId || !symbol)
|
|
7096
|
-
return;
|
|
7098
|
+
if (!state.accountId || !symbol) return;
|
|
7097
7099
|
const unsubscribe = ws.privateSubscribe("account", {
|
|
7098
7100
|
onMessage: (data2) => {
|
|
7099
7101
|
const res = data2?.accountDetail?.symbolLeverage || {};
|
|
@@ -7122,8 +7124,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
7122
7124
|
const { data: markPrices } = useMarkPricesStream();
|
|
7123
7125
|
const symbolLeverage = useLeverageBySymbol(symbol);
|
|
7124
7126
|
const maxQty = React2.useMemo(() => {
|
|
7125
|
-
if (!symbol)
|
|
7126
|
-
return 0;
|
|
7127
|
+
if (!symbol) return 0;
|
|
7127
7128
|
const positionQty = perp.account.getQtyFromPositions(
|
|
7128
7129
|
positions3 === null ? [] : positions3,
|
|
7129
7130
|
symbol
|
|
@@ -7226,7 +7227,20 @@ var useMarginRatio = () => {
|
|
|
7226
7227
|
positionsNotional: notional
|
|
7227
7228
|
});
|
|
7228
7229
|
}, [rows, notional]);
|
|
7229
|
-
|
|
7230
|
+
const maintenanceMargin = React2.useMemo(() => {
|
|
7231
|
+
if (!rows || rows.length <= 0 || notional == null) {
|
|
7232
|
+
return null;
|
|
7233
|
+
}
|
|
7234
|
+
let maintenanceMargin2 = utils.zero;
|
|
7235
|
+
for (let index = 0; index < rows.length; index++) {
|
|
7236
|
+
const item = rows[index];
|
|
7237
|
+
if (item.mm !== null) {
|
|
7238
|
+
maintenanceMargin2 = maintenanceMargin2.add(item.mm);
|
|
7239
|
+
}
|
|
7240
|
+
}
|
|
7241
|
+
return maintenanceMargin2.toNumber();
|
|
7242
|
+
}, [rows, notional]);
|
|
7243
|
+
return { marginRatio, currentLeverage, mmr, maintenanceMargin };
|
|
7230
7244
|
};
|
|
7231
7245
|
var TestNetWhiteList = [
|
|
7232
7246
|
types.ARBITRUM_TESTNET_CHAINID,
|
|
@@ -7488,8 +7502,7 @@ function formatChains({
|
|
|
7488
7502
|
token_infos: [...tokenInfos, ...swapTokens]
|
|
7489
7503
|
};
|
|
7490
7504
|
if (typeof filter === "function") {
|
|
7491
|
-
if (!filter(_chain))
|
|
7492
|
-
continue;
|
|
7505
|
+
if (!filter(_chain)) continue;
|
|
7493
7506
|
}
|
|
7494
7507
|
chains.push(_chain);
|
|
7495
7508
|
}
|
|
@@ -7840,12 +7853,9 @@ var useDeposit = (options) => {
|
|
|
7840
7853
|
const getAllowance = async (inputs) => {
|
|
7841
7854
|
const { address, vaultAddress: vaultAddress2, decimals } = inputs;
|
|
7842
7855
|
const key = `${address}-${vaultAddress2}`;
|
|
7843
|
-
if (prevAddress.current === key)
|
|
7844
|
-
|
|
7845
|
-
if (
|
|
7846
|
-
return;
|
|
7847
|
-
if (types.isNativeTokenChecker(address))
|
|
7848
|
-
return;
|
|
7856
|
+
if (prevAddress.current === key) return;
|
|
7857
|
+
if (!address || !vaultAddress2) return;
|
|
7858
|
+
if (types.isNativeTokenChecker(address)) return;
|
|
7849
7859
|
prevAddress.current = key;
|
|
7850
7860
|
const allowance2 = await account9.assetsManager.getAllowance({
|
|
7851
7861
|
address,
|
|
@@ -7857,10 +7867,8 @@ var useDeposit = (options) => {
|
|
|
7857
7867
|
};
|
|
7858
7868
|
const getAllowanceByDefaultAddress = async (inputs) => {
|
|
7859
7869
|
const { address, decimals } = inputs;
|
|
7860
|
-
if (prevAddress.current === address)
|
|
7861
|
-
|
|
7862
|
-
if (!address || types.isNativeTokenChecker(address))
|
|
7863
|
-
return;
|
|
7870
|
+
if (prevAddress.current === address) return;
|
|
7871
|
+
if (!address || types.isNativeTokenChecker(address)) return;
|
|
7864
7872
|
prevAddress.current = address;
|
|
7865
7873
|
const allowance2 = await account9.assetsManager.getAllowance({
|
|
7866
7874
|
address,
|
|
@@ -7903,8 +7911,7 @@ var useDeposit = (options) => {
|
|
|
7903
7911
|
100
|
|
7904
7912
|
);
|
|
7905
7913
|
React2.useEffect(() => {
|
|
7906
|
-
if (state.status < types.AccountStatusEnum.Connected)
|
|
7907
|
-
return;
|
|
7914
|
+
if (state.status < types.AccountStatusEnum.Connected) return;
|
|
7908
7915
|
setBalanceRevalidating(true);
|
|
7909
7916
|
queryBalance(options.address, options.decimals);
|
|
7910
7917
|
if (account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana) {
|
|
@@ -8108,8 +8115,7 @@ var useDeposit = (options) => {
|
|
|
8108
8115
|
balanceRef.current = balance2;
|
|
8109
8116
|
loopGetBalance();
|
|
8110
8117
|
} catch (err) {
|
|
8111
|
-
if (currentAddressRef.current !== options.address)
|
|
8112
|
-
return;
|
|
8118
|
+
if (currentAddressRef.current !== options.address) return;
|
|
8113
8119
|
loopGetBalance(1e3);
|
|
8114
8120
|
} finally {
|
|
8115
8121
|
if (balanceRef.current !== "" && currentAddressRef.current === options.address) {
|
|
@@ -8317,8 +8323,7 @@ var useWalletTopic = (options) => {
|
|
|
8317
8323
|
const ws = useWS();
|
|
8318
8324
|
const { state } = useAccount();
|
|
8319
8325
|
React2.useEffect(() => {
|
|
8320
|
-
if (!state.accountId)
|
|
8321
|
-
return;
|
|
8326
|
+
if (!state.accountId) return;
|
|
8322
8327
|
const unsubscribe = ws.privateSubscribe(
|
|
8323
8328
|
{
|
|
8324
8329
|
id: "wallet",
|
|
@@ -8339,8 +8344,7 @@ var useBalanceTopic = (options) => {
|
|
|
8339
8344
|
const ws = useWS();
|
|
8340
8345
|
const { state } = useAccount();
|
|
8341
8346
|
React2.useEffect(() => {
|
|
8342
|
-
if (!state.accountId)
|
|
8343
|
-
return;
|
|
8347
|
+
if (!state.accountId) return;
|
|
8344
8348
|
const unsubscribe = ws.privateSubscribe(
|
|
8345
8349
|
{
|
|
8346
8350
|
id: "balance",
|
|
@@ -8440,8 +8444,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
8440
8444
|
}
|
|
8441
8445
|
);
|
|
8442
8446
|
React2.useEffect(() => {
|
|
8443
|
-
if (!account9.accountId)
|
|
8444
|
-
return;
|
|
8447
|
+
if (!account9.accountId) return;
|
|
8445
8448
|
const unsubscribe = ws.privateSubscribe(
|
|
8446
8449
|
{
|
|
8447
8450
|
id: "balance",
|
|
@@ -8537,10 +8540,8 @@ var usePrivateDataObserver = (options) => {
|
|
|
8537
8540
|
return () => unsubscribe?.();
|
|
8538
8541
|
}, [state.accountId, subOrder]);
|
|
8539
8542
|
React2.useEffect(() => {
|
|
8540
|
-
if (!state.accountId)
|
|
8541
|
-
|
|
8542
|
-
if (subOrder !== true)
|
|
8543
|
-
return;
|
|
8543
|
+
if (!state.accountId) return;
|
|
8544
|
+
if (subOrder !== true) return;
|
|
8544
8545
|
const unsubscribe = ws.privateSubscribe("algoexecutionreport", {
|
|
8545
8546
|
onMessage: (data) => {
|
|
8546
8547
|
updateOrders(data, true);
|
|
@@ -8549,8 +8550,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
8549
8550
|
return () => unsubscribe?.();
|
|
8550
8551
|
}, [state.accountId, subOrder]);
|
|
8551
8552
|
React2.useEffect(() => {
|
|
8552
|
-
if (!state.accountId)
|
|
8553
|
-
return;
|
|
8553
|
+
if (!state.accountId) return;
|
|
8554
8554
|
const key = ["/v1/positions", state.accountId];
|
|
8555
8555
|
const unsubscribe = ws.privateSubscribe("account", {
|
|
8556
8556
|
onMessage: (data) => {
|
|
@@ -8912,8 +8912,7 @@ var BaseOrderCreator = class {
|
|
|
8912
8912
|
}
|
|
8913
8913
|
orders.push(orderItem);
|
|
8914
8914
|
}
|
|
8915
|
-
if (!orders.length)
|
|
8916
|
-
return null;
|
|
8915
|
+
if (!orders.length) return null;
|
|
8917
8916
|
return {
|
|
8918
8917
|
symbol: data.symbol,
|
|
8919
8918
|
algo_type: algoType,
|
|
@@ -8923,8 +8922,7 @@ var BaseOrderCreator = class {
|
|
|
8923
8922
|
validateBracketOrder(values, config, errors) {
|
|
8924
8923
|
const { tp_trigger_price, sl_trigger_price, side, order_price } = values;
|
|
8925
8924
|
const { markPrice } = config;
|
|
8926
|
-
if (!tp_trigger_price && !sl_trigger_price)
|
|
8927
|
-
return errors;
|
|
8925
|
+
if (!tp_trigger_price && !sl_trigger_price) return errors;
|
|
8928
8926
|
const hasTPPrice = !!tp_trigger_price;
|
|
8929
8927
|
const hasSLPrice = !!sl_trigger_price;
|
|
8930
8928
|
const { symbol } = config;
|
|
@@ -10423,6 +10421,7 @@ var OrderFactory = class {
|
|
|
10423
10421
|
return new ScaledOrderCreator();
|
|
10424
10422
|
case types.OrderType.TRAILING_STOP:
|
|
10425
10423
|
return new TrailingStopOrderCreator();
|
|
10424
|
+
// algo order
|
|
10426
10425
|
case types.AlgoOrderRootType.TP_SL:
|
|
10427
10426
|
return new TPSLOrderCreator();
|
|
10428
10427
|
case types.AlgoOrderRootType.POSITIONAL_TP_SL:
|
|
@@ -10505,11 +10504,9 @@ var getPriceAndQty = (order, symbolInfo, askAndBid) => {
|
|
|
10505
10504
|
var calcEstLiqPrice = (order, askAndBid, inputs) => {
|
|
10506
10505
|
const { symbolInfo } = inputs;
|
|
10507
10506
|
const result = getPriceAndQty(order, symbolInfo, askAndBid);
|
|
10508
|
-
if (!result)
|
|
10509
|
-
return null;
|
|
10507
|
+
if (!result) return null;
|
|
10510
10508
|
const { price, quantity } = result;
|
|
10511
|
-
if (!price || !quantity)
|
|
10512
|
-
return null;
|
|
10509
|
+
if (!price || !quantity) return null;
|
|
10513
10510
|
const {
|
|
10514
10511
|
symbol,
|
|
10515
10512
|
imr_factor,
|
|
@@ -10537,18 +10534,15 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
|
|
|
10537
10534
|
symbol
|
|
10538
10535
|
}
|
|
10539
10536
|
});
|
|
10540
|
-
if (liqPrice <= 0)
|
|
10541
|
-
return null;
|
|
10537
|
+
if (liqPrice <= 0) return null;
|
|
10542
10538
|
return liqPrice;
|
|
10543
10539
|
};
|
|
10544
10540
|
var calcEstLeverage = (order, askAndBid, inputs) => {
|
|
10545
10541
|
const { totalCollateral, positions: positions3, symbol, symbolInfo } = inputs;
|
|
10546
10542
|
const result = getPriceAndQty(order, symbolInfo, askAndBid);
|
|
10547
|
-
if (!result)
|
|
10548
|
-
return null;
|
|
10543
|
+
if (!result) return null;
|
|
10549
10544
|
const { price, quantity } = result;
|
|
10550
|
-
if (!price || !quantity)
|
|
10551
|
-
return null;
|
|
10545
|
+
if (!price || !quantity) return null;
|
|
10552
10546
|
return perp.order.estLeverage({
|
|
10553
10547
|
totalCollateral,
|
|
10554
10548
|
positions: positions3,
|
|
@@ -10613,8 +10607,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
10613
10607
|
});
|
|
10614
10608
|
const { orderMetadata } = useOrderlyContext();
|
|
10615
10609
|
React2.useEffect(() => {
|
|
10616
|
-
if (!isEditing || !options?.defaultOrder)
|
|
10617
|
-
return;
|
|
10610
|
+
if (!isEditing || !options?.defaultOrder) return;
|
|
10618
10611
|
const trigger_prices = findTPSLFromOrder(options.defaultOrder);
|
|
10619
10612
|
const order2 = {};
|
|
10620
10613
|
if (trigger_prices.tp_trigger_price) {
|
|
@@ -10772,8 +10765,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
10772
10765
|
};
|
|
10773
10766
|
const compare = () => {
|
|
10774
10767
|
const quantityNum = Number(order.quantity);
|
|
10775
|
-
if (isNaN(quantityNum))
|
|
10776
|
-
return false;
|
|
10768
|
+
if (isNaN(quantityNum)) return false;
|
|
10777
10769
|
return quantityNum === Math.abs(Number(position.position_qty));
|
|
10778
10770
|
};
|
|
10779
10771
|
const getOrderCreator2 = () => {
|
|
@@ -11324,14 +11316,16 @@ var usePublicDataObserver = () => {
|
|
|
11324
11316
|
const arr = item.symbol.split("_");
|
|
11325
11317
|
const base_dp = utils.getPrecisionByNumber(item.base_tick);
|
|
11326
11318
|
const quote_dp = utils.getPrecisionByNumber(item.quote_tick);
|
|
11327
|
-
|
|
11319
|
+
const symbol = item.symbol;
|
|
11320
|
+
obj[symbol] = {
|
|
11328
11321
|
...item,
|
|
11329
11322
|
base_dp,
|
|
11330
11323
|
quote_dp,
|
|
11331
11324
|
base: arr[1],
|
|
11332
11325
|
quote: arr[2],
|
|
11333
11326
|
type: arr[0],
|
|
11334
|
-
name: `${arr[1]}-${arr[0]}
|
|
11327
|
+
name: `${arr[1]}-${arr[0]}`,
|
|
11328
|
+
displayName: DEFAULT_SYMBOL_DISPLAY_NAMES[symbol]
|
|
11335
11329
|
};
|
|
11336
11330
|
}
|
|
11337
11331
|
setSymbolsInfo(obj);
|
|
@@ -11625,8 +11619,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11625
11619
|
);
|
|
11626
11620
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
11627
11621
|
const diffOrderEntry = (prev, current) => {
|
|
11628
|
-
if (!prev)
|
|
11629
|
-
return null;
|
|
11622
|
+
if (!prev) return null;
|
|
11630
11623
|
let key, value, preValue;
|
|
11631
11624
|
const keys = Object.keys(current);
|
|
11632
11625
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -11642,14 +11635,12 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11642
11635
|
break;
|
|
11643
11636
|
}
|
|
11644
11637
|
}
|
|
11645
|
-
if (!key)
|
|
11646
|
-
return null;
|
|
11638
|
+
if (!key) return null;
|
|
11647
11639
|
return { key, value, preValue };
|
|
11648
11640
|
};
|
|
11649
11641
|
const maxQty = useMaxQty(symbol, sideValue, isReduceOnly);
|
|
11650
11642
|
const parseString2Number = (order, key, dp) => {
|
|
11651
|
-
if (typeof order[key] !== "string")
|
|
11652
|
-
return;
|
|
11643
|
+
if (typeof order[key] !== "string") return;
|
|
11653
11644
|
if (order[key] && order[key].startsWith(".")) {
|
|
11654
11645
|
order[key] = `0${order[key]}`;
|
|
11655
11646
|
}
|
|
@@ -11853,8 +11844,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11853
11844
|
return values;
|
|
11854
11845
|
}, [parsedData, markPrice]);
|
|
11855
11846
|
React2.useEffect(() => {
|
|
11856
|
-
if (!markPrice || symbolInfo.isNil)
|
|
11857
|
-
return;
|
|
11847
|
+
if (!markPrice || symbolInfo.isNil) return;
|
|
11858
11848
|
validator(formattedOrder)?.then((err) => {
|
|
11859
11849
|
setErrors(err);
|
|
11860
11850
|
}).catch((err) => {
|
|
@@ -11928,14 +11918,11 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11928
11918
|
return { price, quantity };
|
|
11929
11919
|
};
|
|
11930
11920
|
const estLiqPrice = React2.useMemo(() => {
|
|
11931
|
-
if (!accountInfo || !parsedData || !markPrice)
|
|
11932
|
-
return null;
|
|
11921
|
+
if (!accountInfo || !parsedData || !markPrice) return null;
|
|
11933
11922
|
const result = getPriceAndQty2(formattedOrder);
|
|
11934
|
-
if (result === null)
|
|
11935
|
-
return null;
|
|
11923
|
+
if (result === null) return null;
|
|
11936
11924
|
const { price, quantity } = result;
|
|
11937
|
-
if (!price || !quantity)
|
|
11938
|
-
return null;
|
|
11925
|
+
if (!price || !quantity) return null;
|
|
11939
11926
|
const orderFee = perp.order.orderFee({
|
|
11940
11927
|
qty: quantity,
|
|
11941
11928
|
price,
|
|
@@ -11955,8 +11942,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11955
11942
|
symbol: parsedData.symbol
|
|
11956
11943
|
}
|
|
11957
11944
|
});
|
|
11958
|
-
if (liqPrice <= 0)
|
|
11959
|
-
return null;
|
|
11945
|
+
if (liqPrice <= 0) return null;
|
|
11960
11946
|
return liqPrice;
|
|
11961
11947
|
}, [
|
|
11962
11948
|
markPrice,
|
|
@@ -11970,11 +11956,9 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11970
11956
|
accountInfo
|
|
11971
11957
|
]);
|
|
11972
11958
|
const estLeverage = React2.useMemo(() => {
|
|
11973
|
-
if (!accountInfo || !parsedData)
|
|
11974
|
-
return null;
|
|
11959
|
+
if (!accountInfo || !parsedData) return null;
|
|
11975
11960
|
const result = getPriceAndQty2(formattedOrder);
|
|
11976
|
-
if (result === null || !result.price || !result.quantity)
|
|
11977
|
-
return null;
|
|
11961
|
+
if (result === null || !result.price || !result.quantity) return null;
|
|
11978
11962
|
const leverage = perp.order.estLeverage({
|
|
11979
11963
|
totalCollateral,
|
|
11980
11964
|
positions: positions3 === null ? [] : positions3,
|
|
@@ -12491,8 +12475,7 @@ var PosterPainter = class {
|
|
|
12491
12475
|
requestAnimationFrame(() => this._draw.bind(this)(options));
|
|
12492
12476
|
}
|
|
12493
12477
|
async _draw(options) {
|
|
12494
|
-
if (this.ctx === null)
|
|
12495
|
-
return;
|
|
12478
|
+
if (this.ctx === null) return;
|
|
12496
12479
|
await new BackgroundPaint(this.ctx, this).draw(options);
|
|
12497
12480
|
await new DataPaint(this.ctx, this).draw(options);
|
|
12498
12481
|
}
|
|
@@ -12598,8 +12581,7 @@ var usePoster = (data, options) => {
|
|
|
12598
12581
|
[target]
|
|
12599
12582
|
);
|
|
12600
12583
|
const ref = (ref2) => {
|
|
12601
|
-
if (!ref2)
|
|
12602
|
-
return;
|
|
12584
|
+
if (!ref2) return;
|
|
12603
12585
|
if (ref2.tagName.toUpperCase() !== "CANVAS") {
|
|
12604
12586
|
setError(new types.SDKError("The ref must be a canvas element"));
|
|
12605
12587
|
return;
|
|
@@ -17839,8 +17821,7 @@ var useApiKeyManager = (queryParams) => {
|
|
|
17839
17821
|
];
|
|
17840
17822
|
};
|
|
17841
17823
|
function getQueryParamsFromObject(obj) {
|
|
17842
|
-
if (typeof obj === "undefined")
|
|
17843
|
-
return "";
|
|
17824
|
+
if (typeof obj === "undefined") return "";
|
|
17844
17825
|
const queryParams = new URLSearchParams();
|
|
17845
17826
|
for (const [key, value] of Object.entries(obj)) {
|
|
17846
17827
|
if (value !== void 0) {
|
|
@@ -18069,8 +18050,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18069
18050
|
};
|
|
18070
18051
|
const onMarkPriceUpdated = React2.useCallback(
|
|
18071
18052
|
(markPrice, baseOn = []) => {
|
|
18072
|
-
if (!options.symbolInfo)
|
|
18073
|
-
return;
|
|
18053
|
+
if (!options.symbolInfo) return;
|
|
18074
18054
|
let newValues = { ...orderEntity };
|
|
18075
18055
|
if (baseOn.length === 0) {
|
|
18076
18056
|
newValues = calculate2(
|
|
@@ -18881,16 +18861,12 @@ var ERROR_MSG_CODES = {
|
|
|
18881
18861
|
|
|
18882
18862
|
// src/next/tpsl/useTpslPriceChecker.ts
|
|
18883
18863
|
var isEqual = (a, b) => {
|
|
18884
|
-
if (a === b)
|
|
18885
|
-
|
|
18886
|
-
if (a === null || b === null)
|
|
18887
|
-
return false;
|
|
18864
|
+
if (a === b) return true;
|
|
18865
|
+
if (a === null || b === null) return false;
|
|
18888
18866
|
const aItem = a.sl_trigger_price;
|
|
18889
18867
|
const bItem = b.sl_trigger_price;
|
|
18890
|
-
if (aItem === bItem)
|
|
18891
|
-
|
|
18892
|
-
if (aItem === void 0 || bItem === void 0)
|
|
18893
|
-
return false;
|
|
18868
|
+
if (aItem === bItem) return true;
|
|
18869
|
+
if (aItem === void 0 || bItem === void 0) return false;
|
|
18894
18870
|
return aItem.type === bItem.type && aItem.message === bItem.message;
|
|
18895
18871
|
};
|
|
18896
18872
|
var useTpslPriceChecker = (params) => {
|
|
@@ -19146,5 +19122,5 @@ Object.keys(useDebounce).forEach(function (k) {
|
|
|
19146
19122
|
get: function () { return useDebounce[k]; }
|
|
19147
19123
|
});
|
|
19148
19124
|
});
|
|
19149
|
-
//# sourceMappingURL=
|
|
19125
|
+
//# sourceMappingURL=index.js.map
|
|
19150
19126
|
//# sourceMappingURL=index.js.map
|