@orderly.network/hooks 2.8.10 → 2.8.11-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +119 -150
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -150
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -13
package/dist/index.mjs
CHANGED
|
@@ -38,9 +38,9 @@ var __export = (target, all) => {
|
|
|
38
38
|
// src/version.ts
|
|
39
39
|
if (typeof window !== "undefined") {
|
|
40
40
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
41
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.
|
|
41
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.11-alpha.0";
|
|
42
42
|
}
|
|
43
|
-
var version_default = "2.8.
|
|
43
|
+
var version_default = "2.8.11-alpha.0";
|
|
44
44
|
var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
|
|
45
45
|
var noCacheConfig = {
|
|
46
46
|
dedupingInterval: 0,
|
|
@@ -484,8 +484,7 @@ var usePrivateInfiniteQuery = (getKey, options) => {
|
|
|
484
484
|
const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
|
|
485
485
|
const result = useSWRInfinite(
|
|
486
486
|
(pageIndex, previousPageData) => {
|
|
487
|
-
if (!getKey)
|
|
488
|
-
return null;
|
|
487
|
+
if (!getKey) return null;
|
|
489
488
|
const queryKey = getKey(pageIndex, previousPageData);
|
|
490
489
|
if (queryKey && (state.status >= AccountStatusEnum.EnableTrading || state.status === AccountStatusEnum.EnableTradingWithoutConnected)) {
|
|
491
490
|
return [queryKey, state.accountId];
|
|
@@ -530,8 +529,8 @@ var useUpdatedRef = (val) => {
|
|
|
530
529
|
return latestRef;
|
|
531
530
|
};
|
|
532
531
|
var useMemoizedFn = (fn) => {
|
|
533
|
-
const safeFn = typeof fn === "function" ? fn : () => {
|
|
534
|
-
};
|
|
532
|
+
const safeFn = typeof fn === "function" ? fn : (() => {
|
|
533
|
+
});
|
|
535
534
|
const fnRef = useRef(safeFn);
|
|
536
535
|
fnRef.current = useMemo(() => safeFn, [safeFn]);
|
|
537
536
|
const wrapperRef = useRef(null);
|
|
@@ -1112,8 +1111,7 @@ var findPositionTPSLFromOrders = (orders, symbol) => {
|
|
|
1112
1111
|
};
|
|
1113
1112
|
function offsetToPrice(inputs) {
|
|
1114
1113
|
const { qty, offset, entryPrice, orderType, orderSide } = inputs;
|
|
1115
|
-
if (!offset)
|
|
1116
|
-
return;
|
|
1114
|
+
if (!offset) return;
|
|
1117
1115
|
if (orderSide === OrderSide.BUY) {
|
|
1118
1116
|
if (orderType === AlgoOrderType.TAKE_PROFIT) {
|
|
1119
1117
|
return new Decimal(entryPrice).add(new Decimal(offset)).toNumber();
|
|
@@ -1150,8 +1148,7 @@ function priceToOffset(inputs, options = {}) {
|
|
|
1150
1148
|
}
|
|
1151
1149
|
function offsetPercentageToPrice(inputs) {
|
|
1152
1150
|
const { qty, percentage, entryPrice, orderType, orderSide } = inputs;
|
|
1153
|
-
if (!percentage)
|
|
1154
|
-
return;
|
|
1151
|
+
if (!percentage) return;
|
|
1155
1152
|
if (orderSide === OrderSide.BUY) {
|
|
1156
1153
|
if (orderType === AlgoOrderType.TAKE_PROFIT) {
|
|
1157
1154
|
return new Decimal(1).add(new Decimal(percentage)).mul(new Decimal(entryPrice)).toNumber();
|
|
@@ -1174,16 +1171,14 @@ function priceToOffsetPercentage(inputs) {
|
|
|
1174
1171
|
orderPrice: entryPrice
|
|
1175
1172
|
});
|
|
1176
1173
|
if (orderSide === OrderSide.BUY) {
|
|
1177
|
-
if (entryPrice === 0)
|
|
1178
|
-
return 0;
|
|
1174
|
+
if (entryPrice === 0) return 0;
|
|
1179
1175
|
if (orderType === AlgoOrderType.TAKE_PROFIT) {
|
|
1180
1176
|
return new Decimal(price).div(new Decimal(entryPrice)).minus(1).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1181
1177
|
}
|
|
1182
1178
|
return new Decimal(1).minus(new Decimal(price).div(new Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1183
1179
|
}
|
|
1184
1180
|
if (orderSide === OrderSide.SELL) {
|
|
1185
|
-
if (entryPrice === 0)
|
|
1186
|
-
return 0;
|
|
1181
|
+
if (entryPrice === 0) return 0;
|
|
1187
1182
|
if (orderType === AlgoOrderType.TAKE_PROFIT) {
|
|
1188
1183
|
return new Decimal(1).minus(new Decimal(price).div(new Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1189
1184
|
}
|
|
@@ -1195,8 +1190,7 @@ function pnlToPrice(inputs) {
|
|
|
1195
1190
|
if (!pnl) {
|
|
1196
1191
|
return;
|
|
1197
1192
|
}
|
|
1198
|
-
if (qty === 0)
|
|
1199
|
-
return;
|
|
1193
|
+
if (qty === 0) return;
|
|
1200
1194
|
if (orderSide === OrderSide.BUY) {
|
|
1201
1195
|
if (orderType === AlgoOrderType.TAKE_PROFIT) {
|
|
1202
1196
|
return new Decimal(entryPrice).plus(new Decimal(pnl).div(new Decimal(qty))).toNumber();
|
|
@@ -1278,8 +1272,7 @@ function priceToROI(inputs) {
|
|
|
1278
1272
|
function calcTPSL_ROI(inputs) {
|
|
1279
1273
|
const qtyNum = Number(inputs.qty);
|
|
1280
1274
|
const priceNum = Number(inputs.price);
|
|
1281
|
-
if (qtyNum === 0 || priceNum === 0)
|
|
1282
|
-
return "0";
|
|
1275
|
+
if (qtyNum === 0 || priceNum === 0) return "0";
|
|
1283
1276
|
return new Decimal(inputs.pnl).div(new Decimal(qtyNum).abs().mul(new Decimal(priceNum))).toString();
|
|
1284
1277
|
}
|
|
1285
1278
|
function checkTPSLOrderTypeIsMarket(key, values) {
|
|
@@ -1328,6 +1321,31 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
1328
1321
|
}
|
|
1329
1322
|
break;
|
|
1330
1323
|
}
|
|
1324
|
+
// case "tp_enable":
|
|
1325
|
+
// case "sl_enable": {
|
|
1326
|
+
// return {
|
|
1327
|
+
// [`${keyPrefix}enable`]: inputs.value,
|
|
1328
|
+
// [`${keyPrefix}order_type`]: OrderType.MARKET,
|
|
1329
|
+
// [`${keyPrefix}trigger_price`]: "",
|
|
1330
|
+
// [`${keyPrefix}order_price`]: "",
|
|
1331
|
+
// [`${keyPrefix}offset`]: "",
|
|
1332
|
+
// [`${keyPrefix}offset_percentage`]: "",
|
|
1333
|
+
// [`${keyPrefix}pnl`]: "",
|
|
1334
|
+
// [`${keyPrefix}ROI`]: "",
|
|
1335
|
+
// };
|
|
1336
|
+
// }
|
|
1337
|
+
// case 'tp_pnl':{
|
|
1338
|
+
// if (inputs.values.tp_order_type !== OrderType.MARKET) {
|
|
1339
|
+
// pnl = inputs.value;
|
|
1340
|
+
// trigger_price = pnlToPrice({
|
|
1341
|
+
// qty,
|
|
1342
|
+
// pnl: Number(inputs.value),
|
|
1343
|
+
// entryPrice,
|
|
1344
|
+
// orderSide: inputs.orderSide,
|
|
1345
|
+
// orderType,
|
|
1346
|
+
// })
|
|
1347
|
+
// }
|
|
1348
|
+
// }
|
|
1331
1349
|
case "tp_pnl":
|
|
1332
1350
|
case "sl_pnl": {
|
|
1333
1351
|
pnl = inputs.value;
|
|
@@ -1676,6 +1694,8 @@ var getCalculateHandler = (fieldName) => {
|
|
|
1676
1694
|
case "total": {
|
|
1677
1695
|
return totalInputHandle;
|
|
1678
1696
|
}
|
|
1697
|
+
// case "tp_enable":
|
|
1698
|
+
// case "sl_enable":
|
|
1679
1699
|
case "tp_pnl":
|
|
1680
1700
|
case "sl_pnl":
|
|
1681
1701
|
case "tp_trigger_price":
|
|
@@ -1694,17 +1714,14 @@ var getCalculateHandler = (fieldName) => {
|
|
|
1694
1714
|
}
|
|
1695
1715
|
};
|
|
1696
1716
|
function formatNumber(qty, dp) {
|
|
1697
|
-
if (typeof qty === "undefined")
|
|
1698
|
-
|
|
1699
|
-
if (typeof dp === "undefined")
|
|
1700
|
-
return `${qty}`;
|
|
1717
|
+
if (typeof qty === "undefined") return qty;
|
|
1718
|
+
if (typeof dp === "undefined") return `${qty}`;
|
|
1701
1719
|
const _qty = `${qty}`.replace(/,/g, "");
|
|
1702
1720
|
try {
|
|
1703
1721
|
const _dp = new Decimal(dp);
|
|
1704
1722
|
const _qtyDecimal = new Decimal(_qty);
|
|
1705
1723
|
if (_dp.lessThan(1)) {
|
|
1706
|
-
if (`${_qty}`.endsWith("."))
|
|
1707
|
-
return `${_qty}`;
|
|
1724
|
+
if (`${_qty}`.endsWith(".")) return `${_qty}`;
|
|
1708
1725
|
const numStr = dp.toString();
|
|
1709
1726
|
const decimalIndex = numStr.indexOf(".");
|
|
1710
1727
|
const digitsAfterDecimal = decimalIndex === -1 ? 0 : numStr.length - decimalIndex - 1;
|
|
@@ -2728,21 +2745,18 @@ var usePreLoadData = () => {
|
|
|
2728
2745
|
});
|
|
2729
2746
|
}, []);
|
|
2730
2747
|
useEffect(() => {
|
|
2731
|
-
if (!urlPrefix)
|
|
2732
|
-
return;
|
|
2748
|
+
if (!urlPrefix) return;
|
|
2733
2749
|
fetchTestTokens(urlPrefix);
|
|
2734
2750
|
fetchTestChains(urlPrefix, {
|
|
2735
2751
|
brokerId: configStore.get("brokerId")
|
|
2736
2752
|
});
|
|
2737
2753
|
}, [urlPrefix]);
|
|
2738
2754
|
useEffect(() => {
|
|
2739
|
-
if (!mainTokenInfo || !testTokenInfo)
|
|
2740
|
-
return;
|
|
2755
|
+
if (!mainTokenInfo || !testTokenInfo) return;
|
|
2741
2756
|
setTokensInfo(env === "prod" ? mainTokenInfo : testTokenInfo);
|
|
2742
2757
|
}, [mainTokenInfo, testTokenInfo]);
|
|
2743
2758
|
useEffect(() => {
|
|
2744
|
-
if (swapSupportInfo || !enableSwapDeposit)
|
|
2745
|
-
return;
|
|
2759
|
+
if (swapSupportInfo || !enableSwapDeposit) return;
|
|
2746
2760
|
fetchSwapSupport();
|
|
2747
2761
|
}, [swapSupportInfo, enableSwapDeposit]);
|
|
2748
2762
|
const { data: systemInfo } = useSWR__default(
|
|
@@ -2760,8 +2774,7 @@ var usePreLoadData = () => {
|
|
|
2760
2774
|
}
|
|
2761
2775
|
);
|
|
2762
2776
|
useEffect(() => {
|
|
2763
|
-
if (timestampOffsetInitialized)
|
|
2764
|
-
return;
|
|
2777
|
+
if (timestampOffsetInitialized) return;
|
|
2765
2778
|
if (typeof systemInfo !== "undefined") {
|
|
2766
2779
|
const serverTimestamp = systemInfo.timestamp;
|
|
2767
2780
|
const localTimestamp = Date.now();
|
|
@@ -3037,8 +3050,7 @@ var AmplitudeTracker = class {
|
|
|
3037
3050
|
this._userId = userId;
|
|
3038
3051
|
}
|
|
3039
3052
|
setSdkInfo(sdkInfo) {
|
|
3040
|
-
if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag)
|
|
3041
|
-
return;
|
|
3053
|
+
if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag) return;
|
|
3042
3054
|
this.identify(sdkInfo);
|
|
3043
3055
|
this._sdkInfoTag = sdkInfo.address;
|
|
3044
3056
|
}
|
|
@@ -3246,10 +3258,8 @@ var useMarketsStream = () => {
|
|
|
3246
3258
|
};
|
|
3247
3259
|
});
|
|
3248
3260
|
const value = useMemo(() => {
|
|
3249
|
-
if (!futures)
|
|
3250
|
-
|
|
3251
|
-
if (!tickers)
|
|
3252
|
-
return futures;
|
|
3261
|
+
if (!futures) return null;
|
|
3262
|
+
if (!tickers) return futures;
|
|
3253
3263
|
return futures.map((item) => {
|
|
3254
3264
|
const ticker = tickers.find(
|
|
3255
3265
|
(t) => t.symbol === item.symbol
|
|
@@ -3292,8 +3302,7 @@ function createGetter(data, depth = 2) {
|
|
|
3292
3302
|
}
|
|
3293
3303
|
if (depth === 1) {
|
|
3294
3304
|
return (defaultValue) => {
|
|
3295
|
-
if (!target)
|
|
3296
|
-
return defaultValue;
|
|
3305
|
+
if (!target) return defaultValue;
|
|
3297
3306
|
return getValue(target[property], defaultValue);
|
|
3298
3307
|
};
|
|
3299
3308
|
}
|
|
@@ -3847,8 +3856,7 @@ var useWSObserver = (calculatorService) => {
|
|
|
3847
3856
|
});
|
|
3848
3857
|
const indexPriceSubscription = ws.subscribe("indexprices", {
|
|
3849
3858
|
onMessage: (message) => {
|
|
3850
|
-
if (!Array.isArray(message))
|
|
3851
|
-
return;
|
|
3859
|
+
if (!Array.isArray(message)) return;
|
|
3852
3860
|
const prices = /* @__PURE__ */ Object.create(null);
|
|
3853
3861
|
for (let index = 0; index < message.length; index++) {
|
|
3854
3862
|
const element = message[index];
|
|
@@ -4085,10 +4093,8 @@ var useTickerStream = (symbol) => {
|
|
|
4085
4093
|
const { data: openInterest } = useOpenInterest(symbol);
|
|
4086
4094
|
const marketMap = useMarketMap();
|
|
4087
4095
|
const value = useMemo(() => {
|
|
4088
|
-
if (!info)
|
|
4089
|
-
|
|
4090
|
-
if (!ticker || ticker.symbol !== symbol)
|
|
4091
|
-
return info;
|
|
4096
|
+
if (!info) return null;
|
|
4097
|
+
if (!ticker || ticker.symbol !== symbol) return info;
|
|
4092
4098
|
const config = {
|
|
4093
4099
|
...info,
|
|
4094
4100
|
mark_price: markPrice,
|
|
@@ -5104,8 +5110,7 @@ var CalculatorService = class {
|
|
|
5104
5110
|
if (!ctx.isReady && options?.skipPending) {
|
|
5105
5111
|
return;
|
|
5106
5112
|
}
|
|
5107
|
-
if (options?.skipWhenOnPause && !this.windowIsVisible)
|
|
5108
|
-
return;
|
|
5113
|
+
if (options?.skipWhenOnPause && !this.windowIsVisible) return;
|
|
5109
5114
|
this.calcQueue.push({ scope, data, options });
|
|
5110
5115
|
await this.handleCalcQueue(ctx);
|
|
5111
5116
|
this.ctx = ctx;
|
|
@@ -5306,8 +5311,7 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5306
5311
|
return data;
|
|
5307
5312
|
}
|
|
5308
5313
|
update(data, scope) {
|
|
5309
|
-
if (!data || !Array.isArray(data.rows))
|
|
5310
|
-
return;
|
|
5314
|
+
if (!data || !Array.isArray(data.rows)) return;
|
|
5311
5315
|
usePositionStore.getState().actions.setPositions(this.symbol, data);
|
|
5312
5316
|
if (Array.isArray(data.rows) && useApiStatusStore.getState().apis.positions.loading) {
|
|
5313
5317
|
useApiStatusStore.getState().actions.updateApiLoading("positions", false);
|
|
@@ -5346,8 +5350,7 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5346
5350
|
return this.format(positions3, ctx);
|
|
5347
5351
|
}
|
|
5348
5352
|
calcByPosition(positions3, ctx) {
|
|
5349
|
-
if (positions3.rows.length === 0)
|
|
5350
|
-
return positions3;
|
|
5353
|
+
if (positions3.rows.length === 0) return positions3;
|
|
5351
5354
|
return this.format(positions3, ctx);
|
|
5352
5355
|
}
|
|
5353
5356
|
format(data, ctx) {
|
|
@@ -5560,8 +5563,7 @@ var IndexPriceCalculator = class extends BaseCalculator {
|
|
|
5560
5563
|
return data;
|
|
5561
5564
|
}
|
|
5562
5565
|
update(data) {
|
|
5563
|
-
if (!data)
|
|
5564
|
-
return;
|
|
5566
|
+
if (!data) return;
|
|
5565
5567
|
useIndexPriceStore.getState().actions.updateIndexPrice(data);
|
|
5566
5568
|
}
|
|
5567
5569
|
static getValue() {
|
|
@@ -5955,8 +5957,7 @@ var useOrderStream = (params, options) => {
|
|
|
5955
5957
|
registerKeyHandler?.(key.replace("orders", "algoOrders"), algoOrderKeyFn);
|
|
5956
5958
|
}
|
|
5957
5959
|
return () => {
|
|
5958
|
-
if (!options?.stopOnUnmount)
|
|
5959
|
-
return;
|
|
5960
|
+
if (!options?.stopOnUnmount) return;
|
|
5960
5961
|
unregisterKeyHandler(key);
|
|
5961
5962
|
if (algoOrderKeyFn) {
|
|
5962
5963
|
unregisterKeyHandler(key.replace("orders", "algoOrders"));
|
|
@@ -6522,8 +6523,7 @@ var useSubAccountDataObserver = (accountId) => {
|
|
|
6522
6523
|
tokensInfo
|
|
6523
6524
|
]);
|
|
6524
6525
|
useEffect(() => {
|
|
6525
|
-
if (!positionsInfo)
|
|
6526
|
-
return;
|
|
6526
|
+
if (!positionsInfo) return;
|
|
6527
6527
|
if (positionsInfo.rows?.length === 0) {
|
|
6528
6528
|
setPositions(positionsInfo);
|
|
6529
6529
|
return;
|
|
@@ -6555,8 +6555,7 @@ var useSubAccountDataObserver = (accountId) => {
|
|
|
6555
6555
|
}
|
|
6556
6556
|
}, [holdingRes]);
|
|
6557
6557
|
useEffect(() => {
|
|
6558
|
-
if (!accountId)
|
|
6559
|
-
return;
|
|
6558
|
+
if (!accountId) return;
|
|
6560
6559
|
const unsubscribe = ws.privateSubscribe(
|
|
6561
6560
|
{
|
|
6562
6561
|
id: "balance",
|
|
@@ -6581,8 +6580,7 @@ var useSubAccountDataObserver = (accountId) => {
|
|
|
6581
6580
|
return () => unsubscribe?.();
|
|
6582
6581
|
}, [accountId]);
|
|
6583
6582
|
useEffect(() => {
|
|
6584
|
-
if (!accountId)
|
|
6585
|
-
return;
|
|
6583
|
+
if (!accountId) return;
|
|
6586
6584
|
const key = ["/v1/positions", accountId];
|
|
6587
6585
|
const unsubscribe = ws.privateSubscribe("position", {
|
|
6588
6586
|
onMessage: (data) => {
|
|
@@ -7066,8 +7064,7 @@ var useLeverageBySymbol = (symbol) => {
|
|
|
7066
7064
|
}
|
|
7067
7065
|
);
|
|
7068
7066
|
useEffect(() => {
|
|
7069
|
-
if (!state.accountId || !symbol)
|
|
7070
|
-
return;
|
|
7067
|
+
if (!state.accountId || !symbol) return;
|
|
7071
7068
|
const unsubscribe = ws.privateSubscribe("account", {
|
|
7072
7069
|
onMessage: (data2) => {
|
|
7073
7070
|
const res = data2?.accountDetail?.symbolLeverage || {};
|
|
@@ -7096,8 +7093,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
7096
7093
|
const { data: markPrices } = useMarkPricesStream();
|
|
7097
7094
|
const symbolLeverage = useLeverageBySymbol(symbol);
|
|
7098
7095
|
const maxQty = useMemo(() => {
|
|
7099
|
-
if (!symbol)
|
|
7100
|
-
return 0;
|
|
7096
|
+
if (!symbol) return 0;
|
|
7101
7097
|
const positionQty = account.getQtyFromPositions(
|
|
7102
7098
|
positions3 === null ? [] : positions3,
|
|
7103
7099
|
symbol
|
|
@@ -7200,7 +7196,20 @@ var useMarginRatio = () => {
|
|
|
7200
7196
|
positionsNotional: notional
|
|
7201
7197
|
});
|
|
7202
7198
|
}, [rows, notional]);
|
|
7203
|
-
|
|
7199
|
+
const maintenanceMargin = useMemo(() => {
|
|
7200
|
+
if (!rows || rows.length <= 0 || notional == null) {
|
|
7201
|
+
return null;
|
|
7202
|
+
}
|
|
7203
|
+
let maintenanceMargin2 = zero;
|
|
7204
|
+
for (let index = 0; index < rows.length; index++) {
|
|
7205
|
+
const item = rows[index];
|
|
7206
|
+
if (item.mm !== null) {
|
|
7207
|
+
maintenanceMargin2 = maintenanceMargin2.add(item.mm);
|
|
7208
|
+
}
|
|
7209
|
+
}
|
|
7210
|
+
return maintenanceMargin2.toNumber();
|
|
7211
|
+
}, [rows, notional]);
|
|
7212
|
+
return { marginRatio, currentLeverage, mmr, maintenanceMargin };
|
|
7204
7213
|
};
|
|
7205
7214
|
var TestNetWhiteList = [
|
|
7206
7215
|
ARBITRUM_TESTNET_CHAINID,
|
|
@@ -7462,8 +7471,7 @@ function formatChains({
|
|
|
7462
7471
|
token_infos: [...tokenInfos, ...swapTokens]
|
|
7463
7472
|
};
|
|
7464
7473
|
if (typeof filter === "function") {
|
|
7465
|
-
if (!filter(_chain))
|
|
7466
|
-
continue;
|
|
7474
|
+
if (!filter(_chain)) continue;
|
|
7467
7475
|
}
|
|
7468
7476
|
chains.push(_chain);
|
|
7469
7477
|
}
|
|
@@ -7814,12 +7822,9 @@ var useDeposit = (options) => {
|
|
|
7814
7822
|
const getAllowance = async (inputs) => {
|
|
7815
7823
|
const { address, vaultAddress: vaultAddress2, decimals } = inputs;
|
|
7816
7824
|
const key = `${address}-${vaultAddress2}`;
|
|
7817
|
-
if (prevAddress.current === key)
|
|
7818
|
-
|
|
7819
|
-
if (
|
|
7820
|
-
return;
|
|
7821
|
-
if (isNativeTokenChecker(address))
|
|
7822
|
-
return;
|
|
7825
|
+
if (prevAddress.current === key) return;
|
|
7826
|
+
if (!address || !vaultAddress2) return;
|
|
7827
|
+
if (isNativeTokenChecker(address)) return;
|
|
7823
7828
|
prevAddress.current = key;
|
|
7824
7829
|
const allowance2 = await account9.assetsManager.getAllowance({
|
|
7825
7830
|
address,
|
|
@@ -7831,10 +7836,8 @@ var useDeposit = (options) => {
|
|
|
7831
7836
|
};
|
|
7832
7837
|
const getAllowanceByDefaultAddress = async (inputs) => {
|
|
7833
7838
|
const { address, decimals } = inputs;
|
|
7834
|
-
if (prevAddress.current === address)
|
|
7835
|
-
|
|
7836
|
-
if (!address || isNativeTokenChecker(address))
|
|
7837
|
-
return;
|
|
7839
|
+
if (prevAddress.current === address) return;
|
|
7840
|
+
if (!address || isNativeTokenChecker(address)) return;
|
|
7838
7841
|
prevAddress.current = address;
|
|
7839
7842
|
const allowance2 = await account9.assetsManager.getAllowance({
|
|
7840
7843
|
address,
|
|
@@ -7877,8 +7880,7 @@ var useDeposit = (options) => {
|
|
|
7877
7880
|
100
|
|
7878
7881
|
);
|
|
7879
7882
|
useEffect(() => {
|
|
7880
|
-
if (state.status < AccountStatusEnum.Connected)
|
|
7881
|
-
return;
|
|
7883
|
+
if (state.status < AccountStatusEnum.Connected) return;
|
|
7882
7884
|
setBalanceRevalidating(true);
|
|
7883
7885
|
queryBalance(options.address, options.decimals);
|
|
7884
7886
|
if (account9.walletAdapter?.chainNamespace === ChainNamespace.solana) {
|
|
@@ -8082,8 +8084,7 @@ var useDeposit = (options) => {
|
|
|
8082
8084
|
balanceRef.current = balance2;
|
|
8083
8085
|
loopGetBalance();
|
|
8084
8086
|
} catch (err) {
|
|
8085
|
-
if (currentAddressRef.current !== options.address)
|
|
8086
|
-
return;
|
|
8087
|
+
if (currentAddressRef.current !== options.address) return;
|
|
8087
8088
|
loopGetBalance(1e3);
|
|
8088
8089
|
} finally {
|
|
8089
8090
|
if (balanceRef.current !== "" && currentAddressRef.current === options.address) {
|
|
@@ -8291,8 +8292,7 @@ var useWalletTopic = (options) => {
|
|
|
8291
8292
|
const ws = useWS();
|
|
8292
8293
|
const { state } = useAccount();
|
|
8293
8294
|
useEffect(() => {
|
|
8294
|
-
if (!state.accountId)
|
|
8295
|
-
return;
|
|
8295
|
+
if (!state.accountId) return;
|
|
8296
8296
|
const unsubscribe = ws.privateSubscribe(
|
|
8297
8297
|
{
|
|
8298
8298
|
id: "wallet",
|
|
@@ -8313,8 +8313,7 @@ var useBalanceTopic = (options) => {
|
|
|
8313
8313
|
const ws = useWS();
|
|
8314
8314
|
const { state } = useAccount();
|
|
8315
8315
|
useEffect(() => {
|
|
8316
|
-
if (!state.accountId)
|
|
8317
|
-
return;
|
|
8316
|
+
if (!state.accountId) return;
|
|
8318
8317
|
const unsubscribe = ws.privateSubscribe(
|
|
8319
8318
|
{
|
|
8320
8319
|
id: "balance",
|
|
@@ -8414,8 +8413,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
8414
8413
|
}
|
|
8415
8414
|
);
|
|
8416
8415
|
useEffect(() => {
|
|
8417
|
-
if (!account9.accountId)
|
|
8418
|
-
return;
|
|
8416
|
+
if (!account9.accountId) return;
|
|
8419
8417
|
const unsubscribe = ws.privateSubscribe(
|
|
8420
8418
|
{
|
|
8421
8419
|
id: "balance",
|
|
@@ -8511,10 +8509,8 @@ var usePrivateDataObserver = (options) => {
|
|
|
8511
8509
|
return () => unsubscribe?.();
|
|
8512
8510
|
}, [state.accountId, subOrder]);
|
|
8513
8511
|
useEffect(() => {
|
|
8514
|
-
if (!state.accountId)
|
|
8515
|
-
|
|
8516
|
-
if (subOrder !== true)
|
|
8517
|
-
return;
|
|
8512
|
+
if (!state.accountId) return;
|
|
8513
|
+
if (subOrder !== true) return;
|
|
8518
8514
|
const unsubscribe = ws.privateSubscribe("algoexecutionreport", {
|
|
8519
8515
|
onMessage: (data) => {
|
|
8520
8516
|
updateOrders(data, true);
|
|
@@ -8523,8 +8519,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
8523
8519
|
return () => unsubscribe?.();
|
|
8524
8520
|
}, [state.accountId, subOrder]);
|
|
8525
8521
|
useEffect(() => {
|
|
8526
|
-
if (!state.accountId)
|
|
8527
|
-
return;
|
|
8522
|
+
if (!state.accountId) return;
|
|
8528
8523
|
const key = ["/v1/positions", state.accountId];
|
|
8529
8524
|
const unsubscribe = ws.privateSubscribe("account", {
|
|
8530
8525
|
onMessage: (data) => {
|
|
@@ -8886,8 +8881,7 @@ var BaseOrderCreator = class {
|
|
|
8886
8881
|
}
|
|
8887
8882
|
orders.push(orderItem);
|
|
8888
8883
|
}
|
|
8889
|
-
if (!orders.length)
|
|
8890
|
-
return null;
|
|
8884
|
+
if (!orders.length) return null;
|
|
8891
8885
|
return {
|
|
8892
8886
|
symbol: data.symbol,
|
|
8893
8887
|
algo_type: algoType,
|
|
@@ -8897,8 +8891,7 @@ var BaseOrderCreator = class {
|
|
|
8897
8891
|
validateBracketOrder(values, config, errors) {
|
|
8898
8892
|
const { tp_trigger_price, sl_trigger_price, side, order_price } = values;
|
|
8899
8893
|
const { markPrice } = config;
|
|
8900
|
-
if (!tp_trigger_price && !sl_trigger_price)
|
|
8901
|
-
return errors;
|
|
8894
|
+
if (!tp_trigger_price && !sl_trigger_price) return errors;
|
|
8902
8895
|
const hasTPPrice = !!tp_trigger_price;
|
|
8903
8896
|
const hasSLPrice = !!sl_trigger_price;
|
|
8904
8897
|
const { symbol } = config;
|
|
@@ -10397,6 +10390,7 @@ var OrderFactory = class {
|
|
|
10397
10390
|
return new ScaledOrderCreator();
|
|
10398
10391
|
case OrderType.TRAILING_STOP:
|
|
10399
10392
|
return new TrailingStopOrderCreator();
|
|
10393
|
+
// algo order
|
|
10400
10394
|
case AlgoOrderRootType.TP_SL:
|
|
10401
10395
|
return new TPSLOrderCreator();
|
|
10402
10396
|
case AlgoOrderRootType.POSITIONAL_TP_SL:
|
|
@@ -10479,11 +10473,9 @@ var getPriceAndQty = (order, symbolInfo, askAndBid) => {
|
|
|
10479
10473
|
var calcEstLiqPrice = (order$1, askAndBid, inputs) => {
|
|
10480
10474
|
const { symbolInfo } = inputs;
|
|
10481
10475
|
const result = getPriceAndQty(order$1, symbolInfo, askAndBid);
|
|
10482
|
-
if (!result)
|
|
10483
|
-
return null;
|
|
10476
|
+
if (!result) return null;
|
|
10484
10477
|
const { price, quantity } = result;
|
|
10485
|
-
if (!price || !quantity)
|
|
10486
|
-
return null;
|
|
10478
|
+
if (!price || !quantity) return null;
|
|
10487
10479
|
const {
|
|
10488
10480
|
symbol,
|
|
10489
10481
|
imr_factor,
|
|
@@ -10511,18 +10503,15 @@ var calcEstLiqPrice = (order$1, askAndBid, inputs) => {
|
|
|
10511
10503
|
symbol
|
|
10512
10504
|
}
|
|
10513
10505
|
});
|
|
10514
|
-
if (liqPrice <= 0)
|
|
10515
|
-
return null;
|
|
10506
|
+
if (liqPrice <= 0) return null;
|
|
10516
10507
|
return liqPrice;
|
|
10517
10508
|
};
|
|
10518
10509
|
var calcEstLeverage = (order$1, askAndBid, inputs) => {
|
|
10519
10510
|
const { totalCollateral, positions: positions3, symbol, symbolInfo } = inputs;
|
|
10520
10511
|
const result = getPriceAndQty(order$1, symbolInfo, askAndBid);
|
|
10521
|
-
if (!result)
|
|
10522
|
-
return null;
|
|
10512
|
+
if (!result) return null;
|
|
10523
10513
|
const { price, quantity } = result;
|
|
10524
|
-
if (!price || !quantity)
|
|
10525
|
-
return null;
|
|
10514
|
+
if (!price || !quantity) return null;
|
|
10526
10515
|
return order.estLeverage({
|
|
10527
10516
|
totalCollateral,
|
|
10528
10517
|
positions: positions3,
|
|
@@ -10587,8 +10576,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
10587
10576
|
});
|
|
10588
10577
|
const { orderMetadata } = useOrderlyContext();
|
|
10589
10578
|
useEffect(() => {
|
|
10590
|
-
if (!isEditing || !options?.defaultOrder)
|
|
10591
|
-
return;
|
|
10579
|
+
if (!isEditing || !options?.defaultOrder) return;
|
|
10592
10580
|
const trigger_prices = findTPSLFromOrder(options.defaultOrder);
|
|
10593
10581
|
const order2 = {};
|
|
10594
10582
|
if (trigger_prices.tp_trigger_price) {
|
|
@@ -10746,8 +10734,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
10746
10734
|
};
|
|
10747
10735
|
const compare = () => {
|
|
10748
10736
|
const quantityNum = Number(order.quantity);
|
|
10749
|
-
if (isNaN(quantityNum))
|
|
10750
|
-
return false;
|
|
10737
|
+
if (isNaN(quantityNum)) return false;
|
|
10751
10738
|
return quantityNum === Math.abs(Number(position.position_qty));
|
|
10752
10739
|
};
|
|
10753
10740
|
const getOrderCreator2 = () => {
|
|
@@ -11599,8 +11586,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11599
11586
|
);
|
|
11600
11587
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
11601
11588
|
const diffOrderEntry = (prev, current) => {
|
|
11602
|
-
if (!prev)
|
|
11603
|
-
return null;
|
|
11589
|
+
if (!prev) return null;
|
|
11604
11590
|
let key, value, preValue;
|
|
11605
11591
|
const keys = Object.keys(current);
|
|
11606
11592
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -11616,14 +11602,12 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11616
11602
|
break;
|
|
11617
11603
|
}
|
|
11618
11604
|
}
|
|
11619
|
-
if (!key)
|
|
11620
|
-
return null;
|
|
11605
|
+
if (!key) return null;
|
|
11621
11606
|
return { key, value, preValue };
|
|
11622
11607
|
};
|
|
11623
11608
|
const maxQty = useMaxQty(symbol, sideValue, isReduceOnly);
|
|
11624
11609
|
const parseString2Number = (order, key, dp) => {
|
|
11625
|
-
if (typeof order[key] !== "string")
|
|
11626
|
-
return;
|
|
11610
|
+
if (typeof order[key] !== "string") return;
|
|
11627
11611
|
if (order[key] && order[key].startsWith(".")) {
|
|
11628
11612
|
order[key] = `0${order[key]}`;
|
|
11629
11613
|
}
|
|
@@ -11827,8 +11811,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11827
11811
|
return values;
|
|
11828
11812
|
}, [parsedData, markPrice]);
|
|
11829
11813
|
useEffect(() => {
|
|
11830
|
-
if (!markPrice || symbolInfo.isNil)
|
|
11831
|
-
return;
|
|
11814
|
+
if (!markPrice || symbolInfo.isNil) return;
|
|
11832
11815
|
validator(formattedOrder)?.then((err) => {
|
|
11833
11816
|
setErrors(err);
|
|
11834
11817
|
}).catch((err) => {
|
|
@@ -11902,14 +11885,11 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11902
11885
|
return { price, quantity };
|
|
11903
11886
|
};
|
|
11904
11887
|
const estLiqPrice = useMemo(() => {
|
|
11905
|
-
if (!accountInfo || !parsedData || !markPrice)
|
|
11906
|
-
return null;
|
|
11888
|
+
if (!accountInfo || !parsedData || !markPrice) return null;
|
|
11907
11889
|
const result = getPriceAndQty2(formattedOrder);
|
|
11908
|
-
if (result === null)
|
|
11909
|
-
return null;
|
|
11890
|
+
if (result === null) return null;
|
|
11910
11891
|
const { price, quantity } = result;
|
|
11911
|
-
if (!price || !quantity)
|
|
11912
|
-
return null;
|
|
11892
|
+
if (!price || !quantity) return null;
|
|
11913
11893
|
const orderFee = order.orderFee({
|
|
11914
11894
|
qty: quantity,
|
|
11915
11895
|
price,
|
|
@@ -11929,8 +11909,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11929
11909
|
symbol: parsedData.symbol
|
|
11930
11910
|
}
|
|
11931
11911
|
});
|
|
11932
|
-
if (liqPrice <= 0)
|
|
11933
|
-
return null;
|
|
11912
|
+
if (liqPrice <= 0) return null;
|
|
11934
11913
|
return liqPrice;
|
|
11935
11914
|
}, [
|
|
11936
11915
|
markPrice,
|
|
@@ -11944,11 +11923,9 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
11944
11923
|
accountInfo
|
|
11945
11924
|
]);
|
|
11946
11925
|
const estLeverage = useMemo(() => {
|
|
11947
|
-
if (!accountInfo || !parsedData)
|
|
11948
|
-
return null;
|
|
11926
|
+
if (!accountInfo || !parsedData) return null;
|
|
11949
11927
|
const result = getPriceAndQty2(formattedOrder);
|
|
11950
|
-
if (result === null || !result.price || !result.quantity)
|
|
11951
|
-
return null;
|
|
11928
|
+
if (result === null || !result.price || !result.quantity) return null;
|
|
11952
11929
|
const leverage = order.estLeverage({
|
|
11953
11930
|
totalCollateral,
|
|
11954
11931
|
positions: positions3 === null ? [] : positions3,
|
|
@@ -12465,8 +12442,7 @@ var PosterPainter = class {
|
|
|
12465
12442
|
requestAnimationFrame(() => this._draw.bind(this)(options));
|
|
12466
12443
|
}
|
|
12467
12444
|
async _draw(options) {
|
|
12468
|
-
if (this.ctx === null)
|
|
12469
|
-
return;
|
|
12445
|
+
if (this.ctx === null) return;
|
|
12470
12446
|
await new BackgroundPaint(this.ctx, this).draw(options);
|
|
12471
12447
|
await new DataPaint(this.ctx, this).draw(options);
|
|
12472
12448
|
}
|
|
@@ -12572,8 +12548,7 @@ var usePoster = (data, options) => {
|
|
|
12572
12548
|
[target]
|
|
12573
12549
|
);
|
|
12574
12550
|
const ref = (ref2) => {
|
|
12575
|
-
if (!ref2)
|
|
12576
|
-
return;
|
|
12551
|
+
if (!ref2) return;
|
|
12577
12552
|
if (ref2.tagName.toUpperCase() !== "CANVAS") {
|
|
12578
12553
|
setError(new SDKError("The ref must be a canvas element"));
|
|
12579
12554
|
return;
|
|
@@ -17813,8 +17788,7 @@ var useApiKeyManager = (queryParams) => {
|
|
|
17813
17788
|
];
|
|
17814
17789
|
};
|
|
17815
17790
|
function getQueryParamsFromObject(obj) {
|
|
17816
|
-
if (typeof obj === "undefined")
|
|
17817
|
-
return "";
|
|
17791
|
+
if (typeof obj === "undefined") return "";
|
|
17818
17792
|
const queryParams = new URLSearchParams();
|
|
17819
17793
|
for (const [key, value] of Object.entries(obj)) {
|
|
17820
17794
|
if (value !== void 0) {
|
|
@@ -18043,8 +18017,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18043
18017
|
};
|
|
18044
18018
|
const onMarkPriceUpdated = useCallback(
|
|
18045
18019
|
(markPrice, baseOn = []) => {
|
|
18046
|
-
if (!options.symbolInfo)
|
|
18047
|
-
return;
|
|
18020
|
+
if (!options.symbolInfo) return;
|
|
18048
18021
|
let newValues = { ...orderEntity };
|
|
18049
18022
|
if (baseOn.length === 0) {
|
|
18050
18023
|
newValues = calculate2(
|
|
@@ -18855,16 +18828,12 @@ var ERROR_MSG_CODES = {
|
|
|
18855
18828
|
|
|
18856
18829
|
// src/next/tpsl/useTpslPriceChecker.ts
|
|
18857
18830
|
var isEqual = (a, b) => {
|
|
18858
|
-
if (a === b)
|
|
18859
|
-
|
|
18860
|
-
if (a === null || b === null)
|
|
18861
|
-
return false;
|
|
18831
|
+
if (a === b) return true;
|
|
18832
|
+
if (a === null || b === null) return false;
|
|
18862
18833
|
const aItem = a.sl_trigger_price;
|
|
18863
18834
|
const bItem = b.sl_trigger_price;
|
|
18864
|
-
if (aItem === bItem)
|
|
18865
|
-
|
|
18866
|
-
if (aItem === void 0 || bItem === void 0)
|
|
18867
|
-
return false;
|
|
18835
|
+
if (aItem === bItem) return true;
|
|
18836
|
+
if (aItem === void 0 || bItem === void 0) return false;
|
|
18868
18837
|
return aItem.type === bItem.type && aItem.message === bItem.message;
|
|
18869
18838
|
};
|
|
18870
18839
|
var useTpslPriceChecker = (params) => {
|
|
@@ -18921,5 +18890,5 @@ var useEstLiqPriceBySymbol = (symbol) => {
|
|
|
18921
18890
|
};
|
|
18922
18891
|
|
|
18923
18892
|
export { DefaultLayoutConfig, DistributionId, ENVType2 as ENVType, ERROR_MSG_CODES, EpochStatus, ExtendedConfigStore, MaintenanceStatus, MarketsStorageKey, MarketsType, ORDERLY_ORDERBOOK_DEPTH_KEY, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, StatusProvider, TWType, WalletConnectorContext, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, getMinNotional, getPriceKey, indexedDBManager, initializeAppDatabase, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, persistIndexedDB, resetTimestampOffsetState, timestampWaitingMiddleware, useAccount, useAccountInfo2 as useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAppStore, useAssetsHistory, useAudioPlayer, useBalanceSubscription, useBalanceTopic, useBoolean, useChain, useChainInfo, useChains, useCheckReferralCode, useCollateral, useCommission, useComputedLTV, useConfig, useConvert, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEstLiqPriceBySymbol, useEventEmitter, useFeeState, useFundingDetails, useFundingFeeHistory, useFundingRate, useFundingRateBySymbol, useFundingRateHistory, useFundingRates, useFundingRatesStore, useGetClaimed, useGetEnv, useGetReferralCode, useGetRwaSymbolCloseTimeInterval, useGetRwaSymbolInfo, useGetRwaSymbolOpenStatus, useGetRwaSymbolOpenTimeInterval, useHoldingStream, useIndexPrice, useIndexPricesStream, useInfiniteQuery, useInitRwaSymbolsRuntime, useInternalTransfer, useKeyStore, useLazyQuery, useLeverage, useLeverageBySymbol, useLocalStorage, useMainTokenStore, useMainnetChainsStore, useMaintenanceStatus, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketList, useMarketMap, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxLeverage, useMaxQty, useMaxWithdrawal, useMediaQuery, useMemoizedFn, useMutation, useNetworkInfo, useOdosQuote, useOrderEntity, useOrderEntry2 as useOrderEntry, useOrderEntry as useOrderEntry_deprecated, useOrderStore2 as useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedInfo, useRwaSymbolsInfo, useRwaSymbolsInfoStore, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useStorageChain, useStorageLedgerAddress, useSubAccountAlgoOrderStream, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useSubAccountMutation, useSubAccountQuery, useSubAccountWS, useSwapSupportStore, useSymbolInfo, useSymbolLeverage, useSymbolPriceRange, useSymbolsInfo, useSymbolsInfoStore, useTPSLOrder, useTestTokenStore, useTestnetChainsStore, useTickerStream, useTokenInfo, useTokensInfo, useTpslPriceChecker, useTrack, useTrackingInstance, useTradingRewardsStatus, useTransfer, useTransferHistory, useUpdatedRef, useVaultsHistory, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWalletTopic, useWithdraw, useWsStatus, utils_exports as utils, version_default as version };
|
|
18924
|
-
//# sourceMappingURL=
|
|
18893
|
+
//# sourceMappingURL=index.mjs.map
|
|
18925
18894
|
//# sourceMappingURL=index.mjs.map
|