@orderly.network/hooks 3.0.0-beta.0 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +198 -111
- package/dist/index.d.ts +198 -111
- package/dist/index.js +465 -185
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +461 -186
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var net = require('@orderly.network/net');
|
|
4
3
|
var React = require('react');
|
|
4
|
+
var net = require('@orderly.network/net');
|
|
5
5
|
var useSWR5 = require('swr');
|
|
6
|
-
var types = require('@orderly.network/types');
|
|
7
6
|
var pluginCore = require('@orderly.network/plugin-core');
|
|
7
|
+
var types = require('@orderly.network/types');
|
|
8
8
|
var utils = require('@orderly.network/utils');
|
|
9
9
|
var useSWRMutation = require('swr/mutation');
|
|
10
10
|
var useConstant = require('use-constant');
|
|
@@ -61,13 +61,24 @@ var __export = (target, all) => {
|
|
|
61
61
|
for (var name in all)
|
|
62
62
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
63
63
|
};
|
|
64
|
+
var MarketCategoriesConfigContext = React.createContext(void 0);
|
|
65
|
+
var MarketCategoriesConfigProvider = ({ value, children }) => {
|
|
66
|
+
return React.createElement(
|
|
67
|
+
MarketCategoriesConfigContext.Provider,
|
|
68
|
+
{ value },
|
|
69
|
+
children
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
function useMarketCategoriesConfig() {
|
|
73
|
+
return React.useContext(MarketCategoriesConfigContext);
|
|
74
|
+
}
|
|
64
75
|
|
|
65
76
|
// src/version.ts
|
|
66
77
|
if (typeof window !== "undefined") {
|
|
67
78
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
68
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-beta.
|
|
79
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-beta.2";
|
|
69
80
|
}
|
|
70
|
-
var version_default = "3.0.0-beta.
|
|
81
|
+
var version_default = "3.0.0-beta.2";
|
|
71
82
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
72
83
|
var noCacheConfig = {
|
|
73
84
|
dedupingInterval: 0,
|
|
@@ -98,6 +109,8 @@ function useConfig(key, defaultValue) {
|
|
|
98
109
|
}
|
|
99
110
|
return configStore;
|
|
100
111
|
}
|
|
112
|
+
|
|
113
|
+
// src/useQuery.ts
|
|
101
114
|
var PLUGIN_ID_HEADER = "X-Orderly-Plugin-Id";
|
|
102
115
|
var useQuery = (query, options) => {
|
|
103
116
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
@@ -2608,16 +2621,12 @@ var createDataStore = (config) => {
|
|
|
2608
2621
|
const brokerIdQuery = typeof options?.brokerId === "string" && options?.brokerId !== "orderly" ? `?broker_id=${options?.brokerId}` : "";
|
|
2609
2622
|
const url = `${dynamicBaseUrl || baseUrl || ""}${endpoint}${brokerIdQuery}`;
|
|
2610
2623
|
const data = await fetcher(url, {}, { formatter });
|
|
2611
|
-
const dataWithBrokerId = data.map((item) => ({
|
|
2612
|
-
...item,
|
|
2613
|
-
broker_id: options?.brokerId
|
|
2614
|
-
}));
|
|
2615
2624
|
set({
|
|
2616
|
-
data
|
|
2625
|
+
data,
|
|
2617
2626
|
loading: false,
|
|
2618
2627
|
error: null
|
|
2619
2628
|
});
|
|
2620
|
-
return
|
|
2629
|
+
return data;
|
|
2621
2630
|
} catch (error) {
|
|
2622
2631
|
set({ error, loading: false });
|
|
2623
2632
|
return null;
|
|
@@ -3436,7 +3445,10 @@ var useGetRwaSymbolOpenTimeInterval = (symbol, thresholdMinutes = 30) => {
|
|
|
3436
3445
|
};
|
|
3437
3446
|
var useSymbolsInfo = () => {
|
|
3438
3447
|
const symbolsInfo = useAppStore((state) => state.symbolsInfo);
|
|
3439
|
-
return React.useMemo(
|
|
3448
|
+
return React.useMemo(
|
|
3449
|
+
() => createGetter(symbolsInfo ? { ...symbolsInfo } : symbolsInfo),
|
|
3450
|
+
[symbolsInfo]
|
|
3451
|
+
);
|
|
3440
3452
|
};
|
|
3441
3453
|
var useSymbolsInfoStore = () => {
|
|
3442
3454
|
return useAppStore((state) => state.symbolsInfo);
|
|
@@ -3449,6 +3461,7 @@ var MarketsType = /* @__PURE__ */ ((MarketsType2) => {
|
|
|
3449
3461
|
MarketsType2[MarketsType2["ALL"] = 2] = "ALL";
|
|
3450
3462
|
MarketsType2[MarketsType2["RWA"] = 3] = "RWA";
|
|
3451
3463
|
MarketsType2[MarketsType2["NEW_LISTING"] = 4] = "NEW_LISTING";
|
|
3464
|
+
MarketsType2[MarketsType2["COMMUNITY"] = 5] = "COMMUNITY";
|
|
3452
3465
|
return MarketsType2;
|
|
3453
3466
|
})(MarketsType || {});
|
|
3454
3467
|
var MarketsStorageKey = "orderly_markets";
|
|
@@ -3618,6 +3631,8 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
|
|
|
3618
3631
|
const rwaInfo = !rwaSymbolsInfo.isNil ? rwaSymbolsInfo[item.symbol]() : null;
|
|
3619
3632
|
return {
|
|
3620
3633
|
...item,
|
|
3634
|
+
broker_id: item.broker_id,
|
|
3635
|
+
display_symbol_name: item.display_symbol_name,
|
|
3621
3636
|
quote_dp: info("quote_dp"),
|
|
3622
3637
|
created_time: info("created_time"),
|
|
3623
3638
|
displayName: info("displayName"),
|
|
@@ -3639,7 +3654,7 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
|
|
|
3639
3654
|
var filterMarkets = (params) => {
|
|
3640
3655
|
const { markets, favorites, recent, newListing, type } = params;
|
|
3641
3656
|
let curData = [];
|
|
3642
|
-
if (type === 2 /* ALL */) {
|
|
3657
|
+
if (type === 2 /* ALL */ || type === 5 /* COMMUNITY */) {
|
|
3643
3658
|
curData = markets;
|
|
3644
3659
|
} else if (type === 3 /* RWA */) {
|
|
3645
3660
|
curData = markets.filter((item) => item.isRwa);
|
|
@@ -4561,7 +4576,7 @@ var useMarket = (type) => {
|
|
|
4561
4576
|
const getData = (type2) => {
|
|
4562
4577
|
const localData = type2 === 0 /* FAVORITES */ ? [...favorites] : [...recent];
|
|
4563
4578
|
const keys = localData.map((item) => item.name);
|
|
4564
|
-
const filter = type2 == 2 /* ALL */ ? marketsList : marketsList?.filter((item) => keys.includes(item.symbol));
|
|
4579
|
+
const filter = type2 == 2 /* ALL */ || type2 == 4 /* COMMUNITY */ ? marketsList : marketsList?.filter((item) => keys.includes(item.symbol));
|
|
4565
4580
|
const favoritesData = [...favorites];
|
|
4566
4581
|
const favoriteKeys = favoritesData.map((item) => item.name);
|
|
4567
4582
|
if (filter) {
|
|
@@ -4760,6 +4775,80 @@ var useSymbolLeverageMap = () => {
|
|
|
4760
4775
|
refresh: mutate6
|
|
4761
4776
|
};
|
|
4762
4777
|
};
|
|
4778
|
+
|
|
4779
|
+
// src/trading-rewards/useAllBrokers.ts
|
|
4780
|
+
var useAllBrokers = () => {
|
|
4781
|
+
const { data } = useQuery("/v1/public/broker/name", {
|
|
4782
|
+
formatter: (res) => {
|
|
4783
|
+
const { rows } = res;
|
|
4784
|
+
return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
4785
|
+
},
|
|
4786
|
+
revalidateOnFocus: false
|
|
4787
|
+
});
|
|
4788
|
+
return [data];
|
|
4789
|
+
};
|
|
4790
|
+
|
|
4791
|
+
// src/useBadgeBySymbol.ts
|
|
4792
|
+
function brokerNameBaseFromRaw(rawBrokerName) {
|
|
4793
|
+
if (!rawBrokerName) return void 0;
|
|
4794
|
+
const first = rawBrokerName.trim().split(/[ _-]/, 1)[0]?.trim() ?? "";
|
|
4795
|
+
return first.length > 0 ? first : void 0;
|
|
4796
|
+
}
|
|
4797
|
+
var useBadgeBySymbol = (symbol) => {
|
|
4798
|
+
const symbolsInfo = useSymbolsInfo();
|
|
4799
|
+
const [brokers] = useAllBrokers();
|
|
4800
|
+
return React.useMemo(() => {
|
|
4801
|
+
if (!symbol || symbolsInfo.isNil) {
|
|
4802
|
+
return {
|
|
4803
|
+
displayName: symbol ?? "",
|
|
4804
|
+
brokerId: void 0,
|
|
4805
|
+
brokerName: void 0,
|
|
4806
|
+
brokerNameRaw: void 0
|
|
4807
|
+
};
|
|
4808
|
+
}
|
|
4809
|
+
const getter = symbolsInfo[symbol];
|
|
4810
|
+
const info = typeof getter === "function" ? getter() : void 0;
|
|
4811
|
+
const displayName = info?.displayName ?? info?.display_symbol_name ?? symbol;
|
|
4812
|
+
const brokerId = info?.broker_id ?? void 0;
|
|
4813
|
+
const rawBrokerName = brokerId ? brokers?.[brokerId] : void 0;
|
|
4814
|
+
const base = brokerNameBaseFromRaw(rawBrokerName);
|
|
4815
|
+
const brokerName = base ? base.length > 7 ? `${base.slice(0, 7)}...` : base : void 0;
|
|
4816
|
+
return {
|
|
4817
|
+
displayName,
|
|
4818
|
+
brokerId,
|
|
4819
|
+
brokerName,
|
|
4820
|
+
brokerNameRaw: rawBrokerName
|
|
4821
|
+
};
|
|
4822
|
+
}, [brokers, symbolsInfo, symbol]);
|
|
4823
|
+
};
|
|
4824
|
+
function formatSymbolWithBroker(symbol, symbolsInfo, brokers) {
|
|
4825
|
+
if (!symbol) return "";
|
|
4826
|
+
let brokerNameBase;
|
|
4827
|
+
if (!symbolsInfo.isNil) {
|
|
4828
|
+
const getter = symbolsInfo[symbol];
|
|
4829
|
+
const info = typeof getter === "function" ? getter() : void 0;
|
|
4830
|
+
const brokerId = info?.broker_id ?? void 0;
|
|
4831
|
+
const rawBrokerName = brokerId ? brokers?.[brokerId] : void 0;
|
|
4832
|
+
brokerNameBase = brokerNameBaseFromRaw(rawBrokerName);
|
|
4833
|
+
}
|
|
4834
|
+
const parts = symbol.split("_");
|
|
4835
|
+
const base = parts.length >= 3 ? parts[1] ?? "" : symbol.match(/^([A-Za-z]+)/)?.[1] ?? symbol;
|
|
4836
|
+
const hasBrokerSuffix = symbol.includes("-") || symbol.split("_").length > 3;
|
|
4837
|
+
if (brokerNameBase && hasBrokerSuffix) {
|
|
4838
|
+
return `${base}-${brokerNameBase}`;
|
|
4839
|
+
}
|
|
4840
|
+
return base;
|
|
4841
|
+
}
|
|
4842
|
+
var useSymbolWithBroker = (symbol) => {
|
|
4843
|
+
const symbolsInfo = useSymbolsInfo();
|
|
4844
|
+
const [brokers] = useAllBrokers();
|
|
4845
|
+
return React.useMemo(
|
|
4846
|
+
() => formatSymbolWithBroker(symbol, symbolsInfo, brokers),
|
|
4847
|
+
[brokers, symbolsInfo, symbol]
|
|
4848
|
+
);
|
|
4849
|
+
};
|
|
4850
|
+
|
|
4851
|
+
// src/orderly/useMarginModes.ts
|
|
4763
4852
|
var useMarginModes = () => {
|
|
4764
4853
|
const { data, error, isLoading, mutate: mutate6 } = usePrivateQuery("/v1/client/margin_modes", {
|
|
4765
4854
|
revalidateOnFocus: false,
|
|
@@ -4801,22 +4890,28 @@ var useMarginModes = () => {
|
|
|
4801
4890
|
};
|
|
4802
4891
|
var useMarginModeBySymbol = (symbol, fallback = types.MarginMode.CROSS) => {
|
|
4803
4892
|
const { marginModes, isLoading, error, refresh, updateMarginMode } = useMarginModes();
|
|
4804
|
-
const
|
|
4893
|
+
const { brokerId } = useBadgeBySymbol(symbol);
|
|
4894
|
+
const marginMode = React.useMemo(() => {
|
|
4895
|
+
if (brokerId) return types.MarginMode.ISOLATED;
|
|
4896
|
+
return fallback === null ? marginModes[symbol] : marginModes[symbol] ?? fallback;
|
|
4897
|
+
}, [brokerId, fallback, marginModes, symbol]);
|
|
4805
4898
|
const update = React.useCallback(
|
|
4806
4899
|
async (mode) => {
|
|
4900
|
+
if (brokerId) mode = types.MarginMode.ISOLATED;
|
|
4807
4901
|
return updateMarginMode({
|
|
4808
4902
|
symbol_list: [symbol],
|
|
4809
4903
|
default_margin_mode: mode
|
|
4810
4904
|
});
|
|
4811
4905
|
},
|
|
4812
|
-
[symbol, updateMarginMode]
|
|
4906
|
+
[brokerId, symbol, updateMarginMode]
|
|
4813
4907
|
);
|
|
4814
4908
|
return {
|
|
4815
4909
|
marginMode,
|
|
4816
4910
|
isLoading,
|
|
4817
4911
|
error,
|
|
4818
4912
|
refresh,
|
|
4819
|
-
update
|
|
4913
|
+
update,
|
|
4914
|
+
isPermissionlessListing: !!brokerId
|
|
4820
4915
|
};
|
|
4821
4916
|
};
|
|
4822
4917
|
|
|
@@ -5459,7 +5554,7 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5459
5554
|
if (!accountInfo || !fundingRates || !symbolsInfo) {
|
|
5460
5555
|
return data;
|
|
5461
5556
|
}
|
|
5462
|
-
let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
|
|
5557
|
+
let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero, totalUnsettledIsolatedPnl = utils.zero, totalUnsettledCrossPnl = utils.zero;
|
|
5463
5558
|
let rows = data.rows.map((item) => {
|
|
5464
5559
|
const info = symbolsInfo[item.symbol];
|
|
5465
5560
|
const sum_unitary_funding = fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0;
|
|
@@ -5522,6 +5617,12 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5522
5617
|
unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
|
|
5523
5618
|
notional_total = notional_total.add(notional);
|
|
5524
5619
|
unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
|
|
5620
|
+
if (item.margin_mode === types.MarginMode.CROSS) {
|
|
5621
|
+
totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
|
|
5622
|
+
}
|
|
5623
|
+
if (item.margin_mode === types.MarginMode.ISOLATED) {
|
|
5624
|
+
totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
|
|
5625
|
+
}
|
|
5525
5626
|
const fundingFee = new utils.Decimal(sum_unitary_funding).sub(item.last_sum_unitary_funding).mul(item.position_qty).negated().toNumber();
|
|
5526
5627
|
return {
|
|
5527
5628
|
...item,
|
|
@@ -5537,7 +5638,8 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5537
5638
|
unrealized_pnl: unrealPnl,
|
|
5538
5639
|
unrealized_pnl_index: unrealPnl_index,
|
|
5539
5640
|
unrealized_pnl_ROI: unrealPnlROI,
|
|
5540
|
-
unrealized_pnl_ROI_index: unrealPnlROI_index
|
|
5641
|
+
unrealized_pnl_ROI_index: unrealPnlROI_index,
|
|
5642
|
+
unsettled_pnl: unsettlementPnL2
|
|
5541
5643
|
};
|
|
5542
5644
|
});
|
|
5543
5645
|
const totalUnrealPnl = unrealPnL_total.toNumber();
|
|
@@ -5549,18 +5651,34 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5549
5651
|
rows = rows.map((item) => {
|
|
5550
5652
|
const info = symbolsInfo[item.symbol];
|
|
5551
5653
|
const totalCollateral = item.margin_mode === types.MarginMode.ISOLATED ? new utils.Decimal(item.margin ?? 0).add(item.unsettlement_pnl ?? 0).toNumber() : crossMarginCollateral.toNumber();
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5654
|
+
let est_liq_price;
|
|
5655
|
+
if (item.margin_mode === types.MarginMode.ISOLATED) {
|
|
5656
|
+
est_liq_price = perp.positions.liquidationPriceIsolated({
|
|
5657
|
+
isolatedPositionMargin: item.margin ?? 0,
|
|
5658
|
+
costPosition: item.cost_position ?? 0,
|
|
5659
|
+
positionQty: item.position_qty ?? 0,
|
|
5660
|
+
sumUnitaryFunding: fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0,
|
|
5661
|
+
lastSumUnitaryFunding: item.last_sum_unitary_funding ?? 0,
|
|
5662
|
+
baseMMR: info?.["base_mmr"] ?? 0,
|
|
5663
|
+
baseIMR: info?.["base_imr"] ?? 0,
|
|
5664
|
+
IMRFactor: accountInfo.imr_factor[item.symbol],
|
|
5665
|
+
referencePrice: item.mark_price,
|
|
5666
|
+
leverage: item.leverage ?? 0
|
|
5667
|
+
});
|
|
5668
|
+
} else {
|
|
5669
|
+
est_liq_price = perp.positions.liqPrice({
|
|
5670
|
+
symbol: item.symbol,
|
|
5671
|
+
markPrice: item.mark_price,
|
|
5672
|
+
totalCollateral,
|
|
5673
|
+
positionQty: item.position_qty,
|
|
5674
|
+
positions: rows,
|
|
5675
|
+
MMR: item.mmr,
|
|
5676
|
+
baseMMR: info?.["base_mmr"],
|
|
5677
|
+
baseIMR: info?.["base_imr"],
|
|
5678
|
+
IMRFactor: accountInfo.imr_factor[item.symbol],
|
|
5679
|
+
costPosition: item.cost_position
|
|
5680
|
+
});
|
|
5681
|
+
}
|
|
5564
5682
|
return {
|
|
5565
5683
|
...item,
|
|
5566
5684
|
est_liq_price
|
|
@@ -5587,6 +5705,8 @@ var PositionCalculator = class extends BaseCalculator {
|
|
|
5587
5705
|
total_unsettled_pnl: unsettlementPnL,
|
|
5588
5706
|
unrealPnlROI: totalUnrealizedROI,
|
|
5589
5707
|
unrealPnlROI_index: totalUnrealizedROI_index,
|
|
5708
|
+
total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
|
|
5709
|
+
total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
|
|
5590
5710
|
rows
|
|
5591
5711
|
};
|
|
5592
5712
|
}
|
|
@@ -5749,13 +5869,9 @@ var PortfolioCalculator = class extends BaseCalculator {
|
|
|
5749
5869
|
if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo) {
|
|
5750
5870
|
return null;
|
|
5751
5871
|
}
|
|
5752
|
-
const
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
);
|
|
5756
|
-
const totalUnsettlementPnL = positions3.rows.reduce(
|
|
5757
|
-
(sum, pos) => sum + (pos.unsettled_pnl ?? 0),
|
|
5758
|
-
0
|
|
5872
|
+
const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
|
|
5873
|
+
const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(
|
|
5874
|
+
positions3
|
|
5759
5875
|
);
|
|
5760
5876
|
const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
|
|
5761
5877
|
const [USDC_holding, nonUSDC] = parseHolding(
|
|
@@ -5767,7 +5883,7 @@ var PortfolioCalculator = class extends BaseCalculator {
|
|
|
5767
5883
|
const totalCollateral = perp.account.totalCollateral({
|
|
5768
5884
|
USDCHolding: USDC_holding,
|
|
5769
5885
|
nonUSDCHolding: nonUSDC,
|
|
5770
|
-
unsettlementPnL:
|
|
5886
|
+
unsettlementPnL: unsettledCrossPnL,
|
|
5771
5887
|
usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
|
|
5772
5888
|
usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
|
|
5773
5889
|
});
|
|
@@ -5778,7 +5894,7 @@ var PortfolioCalculator = class extends BaseCalculator {
|
|
|
5778
5894
|
return acc.add(curr.margin ?? 0);
|
|
5779
5895
|
}, utils.zero);
|
|
5780
5896
|
const totalValue = perp.account.totalValue({
|
|
5781
|
-
totalUnsettlementPnL,
|
|
5897
|
+
totalUnsettlementPnL: unsettledPnL,
|
|
5782
5898
|
USDCHolding: USDC_holding,
|
|
5783
5899
|
nonUSDCHolding: nonUSDC,
|
|
5784
5900
|
totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
|
|
@@ -5822,7 +5938,7 @@ var PortfolioCalculator = class extends BaseCalculator {
|
|
|
5822
5938
|
totalUnrealizedROI,
|
|
5823
5939
|
freeCollateral,
|
|
5824
5940
|
availableBalance,
|
|
5825
|
-
unsettledPnL
|
|
5941
|
+
unsettledPnL,
|
|
5826
5942
|
holding,
|
|
5827
5943
|
usdcHolding: USDC_holding,
|
|
5828
5944
|
freeCollateralUSDCOnly
|
|
@@ -5941,7 +6057,7 @@ var usePositionStream = (symbol = "all", options) => {
|
|
|
5941
6057
|
total_unreal_pnl: total_unreal_pnl_index,
|
|
5942
6058
|
unrealPnlROI: unrealPnlROI_index
|
|
5943
6059
|
};
|
|
5944
|
-
}, [calcMode]);
|
|
6060
|
+
}, [calcMode, formattedPositions]);
|
|
5945
6061
|
let rows = formattedPositions[0];
|
|
5946
6062
|
{
|
|
5947
6063
|
if (!rows) {
|
|
@@ -6431,14 +6547,8 @@ function formatPortfolio(inputs) {
|
|
|
6431
6547
|
if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo || symbolsInfo?.isNil) {
|
|
6432
6548
|
return null;
|
|
6433
6549
|
}
|
|
6434
|
-
const
|
|
6435
|
-
|
|
6436
|
-
0
|
|
6437
|
-
);
|
|
6438
|
-
const totalUnsettlementPnL = positions3.rows.reduce(
|
|
6439
|
-
(sum, pos) => sum + (pos.unsettled_pnl ?? 0),
|
|
6440
|
-
0
|
|
6441
|
-
);
|
|
6550
|
+
const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
|
|
6551
|
+
const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(positions3);
|
|
6442
6552
|
const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
|
|
6443
6553
|
const [USDC_holding, nonUSDC] = parseHolding(
|
|
6444
6554
|
holding,
|
|
@@ -6449,7 +6559,7 @@ function formatPortfolio(inputs) {
|
|
|
6449
6559
|
const totalCollateral = perp.account.totalCollateral({
|
|
6450
6560
|
USDCHolding: USDC_holding,
|
|
6451
6561
|
nonUSDCHolding: nonUSDC,
|
|
6452
|
-
unsettlementPnL:
|
|
6562
|
+
unsettlementPnL: unsettledCrossPnL,
|
|
6453
6563
|
usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
|
|
6454
6564
|
usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
|
|
6455
6565
|
});
|
|
@@ -6460,7 +6570,7 @@ function formatPortfolio(inputs) {
|
|
|
6460
6570
|
return acc.add(curr.margin ?? 0);
|
|
6461
6571
|
}, utils.zero);
|
|
6462
6572
|
const totalValue = perp.account.totalValue({
|
|
6463
|
-
totalUnsettlementPnL,
|
|
6573
|
+
totalUnsettlementPnL: unsettledPnL,
|
|
6464
6574
|
USDCHolding: USDC_holding,
|
|
6465
6575
|
nonUSDCHolding: nonUSDC,
|
|
6466
6576
|
totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
|
|
@@ -6504,7 +6614,7 @@ function formatPortfolio(inputs) {
|
|
|
6504
6614
|
totalUnrealizedROI,
|
|
6505
6615
|
freeCollateral,
|
|
6506
6616
|
availableBalance,
|
|
6507
|
-
unsettledPnL
|
|
6617
|
+
unsettledPnL,
|
|
6508
6618
|
holding,
|
|
6509
6619
|
freeCollateralUSDCOnly
|
|
6510
6620
|
};
|
|
@@ -6513,7 +6623,7 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
|
|
|
6513
6623
|
if (!accountInfo || !fundingRates || !symbolsInfo) {
|
|
6514
6624
|
return data;
|
|
6515
6625
|
}
|
|
6516
|
-
let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
|
|
6626
|
+
let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero, totalUnsettledIsolatedPnl = utils.zero, totalUnsettledCrossPnl = utils.zero;
|
|
6517
6627
|
const rows = data.rows.map((item) => {
|
|
6518
6628
|
const info = symbolsInfo[item.symbol];
|
|
6519
6629
|
const notional = perp.positions.notional(item.position_qty, item.mark_price);
|
|
@@ -6575,6 +6685,12 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
|
|
|
6575
6685
|
unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
|
|
6576
6686
|
notional_total = notional_total.add(notional);
|
|
6577
6687
|
unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
|
|
6688
|
+
if (item.margin_mode === types.MarginMode.CROSS) {
|
|
6689
|
+
totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
|
|
6690
|
+
}
|
|
6691
|
+
if (item.margin_mode === types.MarginMode.ISOLATED) {
|
|
6692
|
+
totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
|
|
6693
|
+
}
|
|
6578
6694
|
return {
|
|
6579
6695
|
...item,
|
|
6580
6696
|
mm: perp.positions.maintenanceMargin({
|
|
@@ -6588,7 +6704,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
|
|
|
6588
6704
|
unrealized_pnl: unrealPnl,
|
|
6589
6705
|
unrealized_pnl_index: unrealPnl_index,
|
|
6590
6706
|
unrealized_pnl_ROI: unrealPnlROI,
|
|
6591
|
-
unrealized_pnl_ROI_index: unrealPnlROI_index
|
|
6707
|
+
unrealized_pnl_ROI_index: unrealPnlROI_index,
|
|
6708
|
+
unsettled_pnl: unsettlementPnL2
|
|
6592
6709
|
};
|
|
6593
6710
|
});
|
|
6594
6711
|
const totalUnrealPnl = unrealPnL_total.toNumber();
|
|
@@ -6602,6 +6719,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
|
|
|
6602
6719
|
notional: notional_total.toNumber(),
|
|
6603
6720
|
unsettledPnL: unsettlementPnL,
|
|
6604
6721
|
total_unsettled_pnl: unsettlementPnL,
|
|
6722
|
+
total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
|
|
6723
|
+
total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
|
|
6605
6724
|
rows
|
|
6606
6725
|
};
|
|
6607
6726
|
}
|
|
@@ -7984,7 +8103,9 @@ var useDeposit = (options) => {
|
|
|
7984
8103
|
const depositPromise = isNativeToken ? account9.assetsManager.depositNativeToken(inputs) : account9.assetsManager.deposit(inputs);
|
|
7985
8104
|
return depositPromise.then((result) => {
|
|
7986
8105
|
updateAllowanceWhenTxSuccess(result.hash);
|
|
7987
|
-
setBalance(
|
|
8106
|
+
setBalance(
|
|
8107
|
+
(value) => value ? new utils.Decimal(value).sub(quantity).toString() : "0"
|
|
8108
|
+
);
|
|
7988
8109
|
track2(types.TrackerEventName.depositSuccess, {
|
|
7989
8110
|
wallet: state?.connectWallet?.name,
|
|
7990
8111
|
network: targetChain?.network_infos.name,
|
|
@@ -8036,16 +8157,16 @@ var useDeposit = (options) => {
|
|
|
8036
8157
|
};
|
|
8037
8158
|
function useBalance(options) {
|
|
8038
8159
|
const { srcToken, address, decimals, account: account9, status } = options;
|
|
8039
|
-
const [balance, setBalance] = React.useState(
|
|
8160
|
+
const [balance, setBalance] = React.useState(null);
|
|
8040
8161
|
const fetchBalance = React.useCallback(
|
|
8041
8162
|
async (address2, decimals2) => {
|
|
8042
8163
|
try {
|
|
8043
8164
|
if (types.isNativeTokenChecker(address2)) {
|
|
8044
|
-
return account9.assetsManager.getNativeBalance({
|
|
8165
|
+
return await account9.assetsManager.getNativeBalance({
|
|
8045
8166
|
decimals: decimals2
|
|
8046
8167
|
});
|
|
8047
8168
|
}
|
|
8048
|
-
return account9.assetsManager.getBalance(address2, {
|
|
8169
|
+
return await account9.assetsManager.getBalance(address2, {
|
|
8049
8170
|
decimals: decimals2
|
|
8050
8171
|
});
|
|
8051
8172
|
} catch (err) {
|
|
@@ -8094,11 +8215,13 @@ function useBalance(options) {
|
|
|
8094
8215
|
React.useEffect(() => {
|
|
8095
8216
|
if (swrBalance !== void 0) {
|
|
8096
8217
|
setBalance(swrBalance || "0");
|
|
8218
|
+
} else {
|
|
8219
|
+
setBalance(null);
|
|
8097
8220
|
}
|
|
8098
|
-
}, [swrBalance]);
|
|
8221
|
+
}, [swrBalance, address]);
|
|
8099
8222
|
return {
|
|
8100
8223
|
balance,
|
|
8101
|
-
balanceRevalidating,
|
|
8224
|
+
balanceRevalidating: balanceRevalidating || balance === null,
|
|
8102
8225
|
setBalance,
|
|
8103
8226
|
fetchBalance,
|
|
8104
8227
|
fetchBalances
|
|
@@ -9628,6 +9751,9 @@ var PriceValidationStrategy = class {
|
|
|
9628
9751
|
}
|
|
9629
9752
|
const price = new utils.Decimal(order_price);
|
|
9630
9753
|
const { symbol } = config;
|
|
9754
|
+
if (!symbol) {
|
|
9755
|
+
return;
|
|
9756
|
+
}
|
|
9631
9757
|
const { quote_max, quote_min, quote_dp, price_range, price_scope } = symbol;
|
|
9632
9758
|
const maxPriceNumber = perp.order.maxPrice(config.markPrice, price_range);
|
|
9633
9759
|
const minPriceNumber = perp.order.minPrice(config.markPrice, price_range);
|
|
@@ -9674,6 +9800,9 @@ var TriggerPriceValidationStrategy = class {
|
|
|
9674
9800
|
validate(values, config) {
|
|
9675
9801
|
const { trigger_price } = values;
|
|
9676
9802
|
const { symbol } = config;
|
|
9803
|
+
if (!symbol) {
|
|
9804
|
+
return;
|
|
9805
|
+
}
|
|
9677
9806
|
const { quote_max, quote_min } = symbol;
|
|
9678
9807
|
if (!trigger_price) {
|
|
9679
9808
|
return OrderValidation.required("trigger_price");
|
|
@@ -9720,6 +9849,9 @@ var QuantityValidationStrategy = class {
|
|
|
9720
9849
|
validate(values, config) {
|
|
9721
9850
|
let { order_quantity, total, order_price } = values;
|
|
9722
9851
|
const { maxQty, symbol } = config;
|
|
9852
|
+
if (!symbol) {
|
|
9853
|
+
return;
|
|
9854
|
+
}
|
|
9723
9855
|
const { base_min, base_dp, quote_dp } = symbol;
|
|
9724
9856
|
if (!order_quantity && total && order_price) {
|
|
9725
9857
|
const totalNumber = new utils.Decimal(total);
|
|
@@ -10975,7 +11107,7 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
|
|
|
10975
11107
|
totalCollateral,
|
|
10976
11108
|
futures_taker_fee_rate,
|
|
10977
11109
|
positions: positions3,
|
|
10978
|
-
|
|
11110
|
+
symbolLeverage,
|
|
10979
11111
|
sumUnitaryFunding
|
|
10980
11112
|
} = inputs;
|
|
10981
11113
|
const orderFee = perp.order.orderFee({
|
|
@@ -11000,7 +11132,7 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
|
|
|
11000
11132
|
}
|
|
11001
11133
|
});
|
|
11002
11134
|
} else {
|
|
11003
|
-
let isolatedPositionMargin = 0, costPosition = 0, positionQty = 0, lastSumUnitaryFunding = 0, leverage = 1;
|
|
11135
|
+
let isolatedPositionMargin = 0, costPosition = 0, positionQty = 0, lastSumUnitaryFunding = 0, leverage = symbolLeverage ?? 1;
|
|
11004
11136
|
if (positions3) {
|
|
11005
11137
|
const position = positions3.find(
|
|
11006
11138
|
(p) => p.symbol === symbol && p.margin_mode === types.MarginMode.ISOLATED
|
|
@@ -12690,6 +12822,12 @@ var DataPaint = class extends BasePaint {
|
|
|
12690
12822
|
this.DEFAULT_LOSS_COLOR = "rgb(255,103,194)";
|
|
12691
12823
|
this.transformTop = 0;
|
|
12692
12824
|
this.QRCODE_SIZE = 56;
|
|
12825
|
+
this.BROKER_BADGE_HEIGHT = 18;
|
|
12826
|
+
this.BROKER_BADGE_PADDING_X = 8;
|
|
12827
|
+
this.BROKER_BADGE_RADIUS = 4;
|
|
12828
|
+
}
|
|
12829
|
+
formatMarginMode(marginMode) {
|
|
12830
|
+
return marginMode === types.MarginMode.ISOLATED ? "Isolated" : "Cross";
|
|
12693
12831
|
}
|
|
12694
12832
|
async draw(options) {
|
|
12695
12833
|
const needDrawDetails = Array.isArray(options.data?.position?.informations) && (options.data?.position?.informations?.length ?? 0) > 0;
|
|
@@ -12776,6 +12914,49 @@ var DataPaint = class extends BasePaint {
|
|
|
12776
12914
|
fontSize: this._ratio(fontSize),
|
|
12777
12915
|
fontFamily: options.fontFamily
|
|
12778
12916
|
});
|
|
12917
|
+
const brokerName = options.data?.position.brokerName?.trim();
|
|
12918
|
+
if (brokerName) {
|
|
12919
|
+
left += (prevElementBoundingBox.width ?? 0) + this._ratio(10);
|
|
12920
|
+
const badgeHeight = this._ratio(this.BROKER_BADGE_HEIGHT);
|
|
12921
|
+
const badgePaddingX = this._ratio(this.BROKER_BADGE_PADDING_X);
|
|
12922
|
+
const badgeRadius = this._ratio(this.BROKER_BADGE_RADIUS);
|
|
12923
|
+
const badgeFontSize = this._ratio(12);
|
|
12924
|
+
const badgeFontWeight = 600;
|
|
12925
|
+
const textMetrics = this._drawText(
|
|
12926
|
+
brokerName,
|
|
12927
|
+
{
|
|
12928
|
+
left: 0,
|
|
12929
|
+
top: 0,
|
|
12930
|
+
fontSize: badgeFontSize,
|
|
12931
|
+
fontWeight: badgeFontWeight,
|
|
12932
|
+
fontFamily: options.fontFamily
|
|
12933
|
+
},
|
|
12934
|
+
true
|
|
12935
|
+
);
|
|
12936
|
+
const badgeWidth = (textMetrics.width ?? 0) + badgePaddingX * 2;
|
|
12937
|
+
const badgeTop = this._ratio(top) - badgeHeight / 2;
|
|
12938
|
+
this._fillRoundedRect(
|
|
12939
|
+
left,
|
|
12940
|
+
badgeTop,
|
|
12941
|
+
badgeWidth,
|
|
12942
|
+
badgeHeight,
|
|
12943
|
+
badgeRadius,
|
|
12944
|
+
"rgba(255,255,255,0.06)"
|
|
12945
|
+
);
|
|
12946
|
+
this._drawText(brokerName, {
|
|
12947
|
+
color: "rgba(255,255,255,0.36)",
|
|
12948
|
+
left: left + badgePaddingX,
|
|
12949
|
+
top: badgeTop + badgeHeight / 2,
|
|
12950
|
+
fontSize: badgeFontSize,
|
|
12951
|
+
fontWeight: badgeFontWeight,
|
|
12952
|
+
fontFamily: options.fontFamily,
|
|
12953
|
+
textBaseline: "middle"
|
|
12954
|
+
});
|
|
12955
|
+
prevElementBoundingBox = {
|
|
12956
|
+
...prevElementBoundingBox,
|
|
12957
|
+
width: badgeWidth
|
|
12958
|
+
};
|
|
12959
|
+
}
|
|
12779
12960
|
}
|
|
12780
12961
|
const marginMode = options.data?.position.marginMode;
|
|
12781
12962
|
if (marginMode) {
|
|
@@ -12790,7 +12971,7 @@ var DataPaint = class extends BasePaint {
|
|
|
12790
12971
|
});
|
|
12791
12972
|
}
|
|
12792
12973
|
left += (prevElementBoundingBox.width ?? 0) + this._ratio(7);
|
|
12793
|
-
const marginModeText =
|
|
12974
|
+
const marginModeText = this.formatMarginMode(marginMode);
|
|
12794
12975
|
prevElementBoundingBox = this._drawText(marginModeText, {
|
|
12795
12976
|
color: layout.color,
|
|
12796
12977
|
left,
|
|
@@ -12823,6 +13004,20 @@ var DataPaint = class extends BasePaint {
|
|
|
12823
13004
|
);
|
|
12824
13005
|
}
|
|
12825
13006
|
}
|
|
13007
|
+
_fillRoundedRect(x, y, width, height, radius, color) {
|
|
13008
|
+
const r = Math.min(radius, width / 2, height / 2);
|
|
13009
|
+
this.ctx.save();
|
|
13010
|
+
this.ctx.fillStyle = color;
|
|
13011
|
+
this.ctx.beginPath();
|
|
13012
|
+
this.ctx.moveTo(x + r, y);
|
|
13013
|
+
this.ctx.arcTo(x + width, y, x + width, y + height, r);
|
|
13014
|
+
this.ctx.arcTo(x + width, y + height, x, y + height, r);
|
|
13015
|
+
this.ctx.arcTo(x, y + height, x, y, r);
|
|
13016
|
+
this.ctx.arcTo(x, y, x + width, y, r);
|
|
13017
|
+
this.ctx.closePath();
|
|
13018
|
+
this.ctx.fill();
|
|
13019
|
+
this.ctx.restore();
|
|
13020
|
+
}
|
|
12826
13021
|
drawUnrealizedPnL(options, offsetTop = 0) {
|
|
12827
13022
|
const layout = ramda.path(
|
|
12828
13023
|
["layout", "unrealizedPnl"],
|
|
@@ -13276,18 +13471,6 @@ var useEpochInfo = (type) => {
|
|
|
13276
13471
|
}, [epochInfo]);
|
|
13277
13472
|
return [epochInfo, { isLoading, curEpochInfo, isNotStared, refresh }];
|
|
13278
13473
|
};
|
|
13279
|
-
|
|
13280
|
-
// src/trading-rewards/useAllBrokers.ts
|
|
13281
|
-
var useAllBrokers = () => {
|
|
13282
|
-
const { data } = useQuery("/v1/public/broker/name", {
|
|
13283
|
-
formatter: (res) => {
|
|
13284
|
-
const { rows } = res;
|
|
13285
|
-
return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
13286
|
-
},
|
|
13287
|
-
revalidateOnFocus: false
|
|
13288
|
-
});
|
|
13289
|
-
return [data];
|
|
13290
|
-
};
|
|
13291
13474
|
var useCurEpochEstimate = (type) => {
|
|
13292
13475
|
const [data, setData] = React.useState(void 0);
|
|
13293
13476
|
const { account: account9 } = useAccount();
|
|
@@ -18423,108 +18606,65 @@ var initialOrderState = {
|
|
|
18423
18606
|
tp_trigger_price: "",
|
|
18424
18607
|
sl_trigger_price: "",
|
|
18425
18608
|
total: "",
|
|
18426
|
-
symbol: ""
|
|
18609
|
+
symbol: "",
|
|
18610
|
+
side: types.OrderSide.BUY,
|
|
18611
|
+
order_type: types.OrderType.LIMIT,
|
|
18612
|
+
margin_mode: types.MarginMode.CROSS
|
|
18427
18613
|
};
|
|
18428
|
-
var
|
|
18429
|
-
|
|
18430
|
-
|
|
18431
|
-
|
|
18432
|
-
|
|
18433
|
-
...
|
|
18434
|
-
|
|
18435
|
-
|
|
18436
|
-
|
|
18437
|
-
|
|
18438
|
-
|
|
18439
|
-
initOrder: (
|
|
18440
|
-
|
|
18441
|
-
|
|
18442
|
-
|
|
18443
|
-
|
|
18444
|
-
|
|
18445
|
-
|
|
18446
|
-
margin_mode: options?.margin_mode ?? types.MarginMode.CROSS
|
|
18447
|
-
};
|
|
18448
|
-
state.estLeverage = null;
|
|
18449
|
-
state.estLiquidationPrice = null;
|
|
18450
|
-
state.errors = {};
|
|
18614
|
+
var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
18615
|
+
const { symbolInfo, symbolLeverage } = options;
|
|
18616
|
+
const [orderEntity, setOrderEntity] = React.useState(
|
|
18617
|
+
() => ({
|
|
18618
|
+
...initialOrderState,
|
|
18619
|
+
...options.initialOrder,
|
|
18620
|
+
symbol
|
|
18621
|
+
})
|
|
18622
|
+
);
|
|
18623
|
+
const actions = React.useMemo(
|
|
18624
|
+
() => ({
|
|
18625
|
+
initOrder: (sym, opts) => {
|
|
18626
|
+
setOrderEntity({
|
|
18627
|
+
...initialOrderState,
|
|
18628
|
+
symbol: sym,
|
|
18629
|
+
side: opts?.side ?? types.OrderSide.BUY,
|
|
18630
|
+
order_type: opts?.order_type ?? types.OrderType.LIMIT,
|
|
18631
|
+
margin_mode: opts?.margin_mode ?? types.MarginMode.CROSS
|
|
18451
18632
|
});
|
|
18452
18633
|
},
|
|
18453
|
-
hasTP_SL: () => {
|
|
18454
|
-
const order = get3().entry;
|
|
18455
|
-
return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
|
|
18456
|
-
},
|
|
18457
|
-
updateOrderComputed: (data) => {
|
|
18458
|
-
set(
|
|
18459
|
-
(state) => {
|
|
18460
|
-
state.estLeverage = data.estLeverage;
|
|
18461
|
-
state.estLiquidationPrice = data.estLiquidationPrice;
|
|
18462
|
-
},
|
|
18463
|
-
false
|
|
18464
|
-
// "updateOrderComputed"
|
|
18465
|
-
);
|
|
18466
|
-
},
|
|
18467
18634
|
updateOrder: (order) => {
|
|
18468
|
-
|
|
18469
|
-
(state) => {
|
|
18470
|
-
state.entry = {
|
|
18471
|
-
...state.entry,
|
|
18472
|
-
...order
|
|
18473
|
-
};
|
|
18474
|
-
},
|
|
18475
|
-
false
|
|
18476
|
-
// "updateOrder"
|
|
18477
|
-
);
|
|
18635
|
+
setOrderEntity((prev) => ({ ...prev, ...order }));
|
|
18478
18636
|
},
|
|
18479
18637
|
updateOrderByKey: (key, value) => {
|
|
18480
|
-
|
|
18481
|
-
(state) => {
|
|
18482
|
-
state.entry[key] = value;
|
|
18483
|
-
},
|
|
18484
|
-
false
|
|
18485
|
-
// "updateOrderByKey"
|
|
18486
|
-
);
|
|
18487
|
-
},
|
|
18488
|
-
restoreOrder: (order) => {
|
|
18489
|
-
set(
|
|
18490
|
-
(state) => {
|
|
18491
|
-
state.entry = order;
|
|
18492
|
-
},
|
|
18493
|
-
false
|
|
18494
|
-
// "restoreOrder"
|
|
18495
|
-
);
|
|
18638
|
+
setOrderEntity((prev) => ({ ...prev, [key]: value }));
|
|
18496
18639
|
},
|
|
18497
18640
|
resetOrder: (_order) => {
|
|
18498
|
-
|
|
18499
|
-
|
|
18500
|
-
|
|
18501
|
-
|
|
18502
|
-
|
|
18503
|
-
|
|
18504
|
-
|
|
18505
|
-
|
|
18506
|
-
|
|
18507
|
-
|
|
18508
|
-
|
|
18509
|
-
|
|
18510
|
-
|
|
18511
|
-
|
|
18512
|
-
|
|
18513
|
-
|
|
18514
|
-
|
|
18515
|
-
|
|
18641
|
+
setOrderEntity((prev) => ({
|
|
18642
|
+
...prev,
|
|
18643
|
+
order_price: "",
|
|
18644
|
+
order_quantity: "",
|
|
18645
|
+
trigger_price: "",
|
|
18646
|
+
total: "",
|
|
18647
|
+
tp_trigger_price: "",
|
|
18648
|
+
tp_pnl: "",
|
|
18649
|
+
tp_offset: "",
|
|
18650
|
+
tp_offset_percentage: "",
|
|
18651
|
+
sl_trigger_price: "",
|
|
18652
|
+
sl_pnl: "",
|
|
18653
|
+
sl_offset: "",
|
|
18654
|
+
sl_offset_percentage: ""
|
|
18655
|
+
}));
|
|
18656
|
+
},
|
|
18657
|
+
hasTP_SL: () => {
|
|
18658
|
+
const order = orderEntity;
|
|
18659
|
+
return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
|
|
18516
18660
|
}
|
|
18517
|
-
}
|
|
18518
|
-
|
|
18519
|
-
);
|
|
18520
|
-
var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
18521
|
-
const { symbolInfo, symbolLeverage } = options;
|
|
18522
|
-
const orderEntity = useOrderStore((state) => state.entry);
|
|
18523
|
-
const orderEntryActions = useOrderStore((state) => state.actions);
|
|
18661
|
+
}),
|
|
18662
|
+
[orderEntity]
|
|
18663
|
+
);
|
|
18524
18664
|
React.useEffect(() => {
|
|
18525
|
-
|
|
18665
|
+
actions.initOrder(symbol, options.initialOrder);
|
|
18526
18666
|
if (options.initialOrder) {
|
|
18527
|
-
|
|
18667
|
+
actions.updateOrder(options.initialOrder);
|
|
18528
18668
|
}
|
|
18529
18669
|
}, [symbol]);
|
|
18530
18670
|
const calculate2 = React.useCallback(
|
|
@@ -18542,10 +18682,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18542
18682
|
);
|
|
18543
18683
|
const setValue = (key, value, additional) => {
|
|
18544
18684
|
if (!symbolInfo) {
|
|
18545
|
-
|
|
18685
|
+
actions.updateOrderByKey(key, value);
|
|
18546
18686
|
return;
|
|
18547
18687
|
}
|
|
18548
|
-
const currentEntry =
|
|
18688
|
+
const currentEntry = orderEntity;
|
|
18549
18689
|
const { markPrice } = additional ?? { markPrice: 0 };
|
|
18550
18690
|
let newValues = calculate2(
|
|
18551
18691
|
{ ...currentEntry },
|
|
@@ -18579,7 +18719,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18579
18719
|
if (sl_ROI) {
|
|
18580
18720
|
newValues.sl_ROI = sl_ROI;
|
|
18581
18721
|
}
|
|
18582
|
-
|
|
18722
|
+
actions.updateOrder(newValues);
|
|
18583
18723
|
return newValues;
|
|
18584
18724
|
};
|
|
18585
18725
|
const calculateTPSL = (key, newValues, markPrice, symbolInfo2) => {
|
|
@@ -18626,11 +18766,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18626
18766
|
};
|
|
18627
18767
|
const setValues = (values, additional) => {
|
|
18628
18768
|
if (!symbolInfo) {
|
|
18629
|
-
|
|
18769
|
+
actions.updateOrder(values);
|
|
18630
18770
|
return;
|
|
18631
18771
|
}
|
|
18632
|
-
|
|
18633
|
-
let newValues = { ...currentEntry };
|
|
18772
|
+
let newValues = { ...orderEntity };
|
|
18634
18773
|
Object.keys(values).forEach((key) => {
|
|
18635
18774
|
newValues = calculate2(
|
|
18636
18775
|
newValues,
|
|
@@ -18640,17 +18779,28 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18640
18779
|
symbolInfo
|
|
18641
18780
|
);
|
|
18642
18781
|
});
|
|
18643
|
-
|
|
18782
|
+
actions.updateOrder(newValues);
|
|
18783
|
+
return newValues;
|
|
18784
|
+
};
|
|
18785
|
+
const setValuesRaw = (values) => {
|
|
18786
|
+
if (!symbolInfo) {
|
|
18787
|
+
actions.updateOrder(values);
|
|
18788
|
+
return;
|
|
18789
|
+
}
|
|
18790
|
+
const newValues = {
|
|
18791
|
+
...orderEntity,
|
|
18792
|
+
...values
|
|
18793
|
+
};
|
|
18794
|
+
actions.updateOrder(newValues);
|
|
18644
18795
|
return newValues;
|
|
18645
18796
|
};
|
|
18646
18797
|
const onMarkPriceUpdated = React.useCallback(
|
|
18647
18798
|
(markPrice, baseOn = []) => {
|
|
18648
18799
|
if (!options.symbolInfo) return;
|
|
18649
|
-
|
|
18650
|
-
let newValues = { ...currentEntry };
|
|
18800
|
+
let newValues = { ...orderEntity };
|
|
18651
18801
|
if (baseOn.length === 0) {
|
|
18652
18802
|
newValues = calculate2(
|
|
18653
|
-
{ ...
|
|
18803
|
+
{ ...orderEntity },
|
|
18654
18804
|
"order_price",
|
|
18655
18805
|
markPrice,
|
|
18656
18806
|
markPrice,
|
|
@@ -18661,7 +18811,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18661
18811
|
newValues = calculate2(
|
|
18662
18812
|
{ ...newValues },
|
|
18663
18813
|
key,
|
|
18664
|
-
|
|
18814
|
+
orderEntity[key],
|
|
18665
18815
|
markPrice,
|
|
18666
18816
|
options.symbolInfo
|
|
18667
18817
|
);
|
|
@@ -18680,9 +18830,9 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18680
18830
|
newValues.sl_ROI = sl_ROI;
|
|
18681
18831
|
}
|
|
18682
18832
|
}
|
|
18683
|
-
|
|
18833
|
+
actions.updateOrder(newValues);
|
|
18684
18834
|
},
|
|
18685
|
-
[calculate2, options.symbolInfo,
|
|
18835
|
+
[calculate2, options.symbolInfo, symbolLeverage, orderEntity]
|
|
18686
18836
|
);
|
|
18687
18837
|
const validate = (order, creator, options2) => {
|
|
18688
18838
|
return creator?.validate(order, {
|
|
@@ -18700,12 +18850,13 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
|
|
|
18700
18850
|
const submitOrder = React.useCallback(() => {
|
|
18701
18851
|
}, [orderEntity]);
|
|
18702
18852
|
const resetOrder = (order) => {
|
|
18703
|
-
|
|
18853
|
+
actions.resetOrder(order);
|
|
18704
18854
|
};
|
|
18705
18855
|
return {
|
|
18706
18856
|
formattedOrder: orderEntity,
|
|
18707
18857
|
setValue,
|
|
18708
18858
|
setValues,
|
|
18859
|
+
setValuesRaw,
|
|
18709
18860
|
submit: submitOrder,
|
|
18710
18861
|
reset: resetOrder,
|
|
18711
18862
|
generateOrder,
|
|
@@ -18721,6 +18872,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18721
18872
|
}
|
|
18722
18873
|
const ee = useEventEmitter();
|
|
18723
18874
|
const { track: track2 } = useTrack();
|
|
18875
|
+
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
18876
|
+
const fetchSymbols = useSymbolStore((state) => state.fetchData);
|
|
18724
18877
|
const [meta, setMeta] = React.useState({
|
|
18725
18878
|
dirty: {},
|
|
18726
18879
|
submitted: false,
|
|
@@ -18740,8 +18893,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18740
18893
|
const symbolConfig = useSymbolsInfo();
|
|
18741
18894
|
const accountInfo = useAccountInfo();
|
|
18742
18895
|
const positions3 = usePositions();
|
|
18743
|
-
const
|
|
18744
|
-
const effectiveMarginMode = options?.initialOrder?.margin_mode ?? entry?.margin_mode ?? types.MarginMode.CROSS;
|
|
18896
|
+
const effectiveMarginMode = options?.initialOrder?.margin_mode ?? types.MarginMode.CROSS;
|
|
18745
18897
|
const symbolLeverage = useLeverageBySymbol(symbol, effectiveMarginMode);
|
|
18746
18898
|
const symbolInfo = symbolConfig[symbol]();
|
|
18747
18899
|
const markPrice = actions.getMarkPriceBySymbol(symbol);
|
|
@@ -18750,6 +18902,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18750
18902
|
formattedOrder,
|
|
18751
18903
|
setValue: setValueInternal,
|
|
18752
18904
|
setValues: setValuesInternal,
|
|
18905
|
+
setValuesRaw: setValuesRawInternal,
|
|
18753
18906
|
validate,
|
|
18754
18907
|
generateOrder,
|
|
18755
18908
|
reset,
|
|
@@ -18974,6 +19127,21 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
18974
19127
|
interactiveValidate(newValues);
|
|
18975
19128
|
}
|
|
18976
19129
|
};
|
|
19130
|
+
const setValuesRaw = (values) => {
|
|
19131
|
+
if (!Object.keys(values).every(
|
|
19132
|
+
(key) => canSetTPSLPrice(
|
|
19133
|
+
key,
|
|
19134
|
+
values[key],
|
|
19135
|
+
formattedOrder.order_type
|
|
19136
|
+
)
|
|
19137
|
+
)) {
|
|
19138
|
+
return;
|
|
19139
|
+
}
|
|
19140
|
+
const newValues = setValuesRawInternal(values);
|
|
19141
|
+
if (newValues) {
|
|
19142
|
+
interactiveValidate(newValues);
|
|
19143
|
+
}
|
|
19144
|
+
};
|
|
18977
19145
|
async function validateFunc(order) {
|
|
18978
19146
|
const creator = getOrderCreator(order);
|
|
18979
19147
|
return validate(order, creator, prepareData());
|
|
@@ -19028,11 +19196,12 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
19028
19196
|
markPrice: markPrice2,
|
|
19029
19197
|
totalCollateral,
|
|
19030
19198
|
futures_taker_fee_rate: accountInfo.futures_taker_fee_rate,
|
|
19031
|
-
imr_factor: accountInfo.imr_factor[symbol],
|
|
19199
|
+
imr_factor: accountInfo.imr_factor?.[symbol] ?? 0,
|
|
19032
19200
|
symbol,
|
|
19033
19201
|
positions: positions3,
|
|
19034
19202
|
symbolInfo,
|
|
19035
|
-
sumUnitaryFunding
|
|
19203
|
+
sumUnitaryFunding,
|
|
19204
|
+
symbolLeverage
|
|
19036
19205
|
});
|
|
19037
19206
|
return estLiqPrice2;
|
|
19038
19207
|
}, [
|
|
@@ -19043,7 +19212,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
19043
19212
|
symbol,
|
|
19044
19213
|
maxQty,
|
|
19045
19214
|
symbolInfo,
|
|
19046
|
-
fundingRates
|
|
19215
|
+
fundingRates,
|
|
19216
|
+
symbolLeverage
|
|
19047
19217
|
]);
|
|
19048
19218
|
const estLiqPriceDistance = React.useMemo(() => {
|
|
19049
19219
|
if (!estLiqPrice) {
|
|
@@ -19115,6 +19285,9 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
19115
19285
|
orders: appendOrderMetadata(order.orders, orderMetadata)
|
|
19116
19286
|
} : appendOrderMetadata(order, orderMetadata);
|
|
19117
19287
|
const result = await doCreateOrder(params);
|
|
19288
|
+
if (!result.success && (order.order_type === types.OrderType.MARKET || order.order_type === types.OrderType.STOP_MARKET)) {
|
|
19289
|
+
void fetchSymbols(apiBaseUrl);
|
|
19290
|
+
}
|
|
19118
19291
|
if (result.success) {
|
|
19119
19292
|
let trackParams = {
|
|
19120
19293
|
side: order.side,
|
|
@@ -19182,6 +19355,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
19182
19355
|
freeCollateral: effectiveMarginMode === types.MarginMode.ISOLATED ? freeCollateralUSDCOnly : freeCollateral,
|
|
19183
19356
|
setValue: useMemoizedFn(setValue),
|
|
19184
19357
|
setValues: useMemoizedFn(setValues),
|
|
19358
|
+
setValuesRaw: useMemoizedFn(setValuesRaw),
|
|
19185
19359
|
symbolInfo: symbolInfo || types.EMPTY_OBJECT,
|
|
19186
19360
|
metaState: meta,
|
|
19187
19361
|
isMutating,
|
|
@@ -19189,6 +19363,107 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
19189
19363
|
symbolLeverage
|
|
19190
19364
|
};
|
|
19191
19365
|
};
|
|
19366
|
+
var initialOrderState2 = {
|
|
19367
|
+
order_price: "",
|
|
19368
|
+
order_quantity: "",
|
|
19369
|
+
trigger_price: "",
|
|
19370
|
+
tp_trigger_price: "",
|
|
19371
|
+
sl_trigger_price: "",
|
|
19372
|
+
total: "",
|
|
19373
|
+
symbol: ""
|
|
19374
|
+
};
|
|
19375
|
+
var useOrderStore = zustand.create()(
|
|
19376
|
+
immer.immer((set, get3) => ({
|
|
19377
|
+
entry: {
|
|
19378
|
+
side: types.OrderSide.BUY,
|
|
19379
|
+
order_type: types.OrderType.LIMIT,
|
|
19380
|
+
...initialOrderState2
|
|
19381
|
+
},
|
|
19382
|
+
estLeverage: null,
|
|
19383
|
+
estLiquidationPrice: null,
|
|
19384
|
+
errors: {},
|
|
19385
|
+
actions: {
|
|
19386
|
+
initOrder: (symbol, options) => {
|
|
19387
|
+
set((state) => {
|
|
19388
|
+
state.entry = {
|
|
19389
|
+
...initialOrderState2,
|
|
19390
|
+
symbol,
|
|
19391
|
+
side: options?.side ?? types.OrderSide.BUY,
|
|
19392
|
+
order_type: options?.order_type ?? types.OrderType.LIMIT,
|
|
19393
|
+
margin_mode: options?.margin_mode ?? types.MarginMode.CROSS
|
|
19394
|
+
};
|
|
19395
|
+
state.estLeverage = null;
|
|
19396
|
+
state.estLiquidationPrice = null;
|
|
19397
|
+
state.errors = {};
|
|
19398
|
+
});
|
|
19399
|
+
},
|
|
19400
|
+
hasTP_SL: () => {
|
|
19401
|
+
const order = get3().entry;
|
|
19402
|
+
return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
|
|
19403
|
+
},
|
|
19404
|
+
updateOrderComputed: (data) => {
|
|
19405
|
+
set(
|
|
19406
|
+
(state) => {
|
|
19407
|
+
state.estLeverage = data.estLeverage;
|
|
19408
|
+
state.estLiquidationPrice = data.estLiquidationPrice;
|
|
19409
|
+
},
|
|
19410
|
+
false
|
|
19411
|
+
// "updateOrderComputed"
|
|
19412
|
+
);
|
|
19413
|
+
},
|
|
19414
|
+
updateOrder: (order) => {
|
|
19415
|
+
set(
|
|
19416
|
+
(state) => {
|
|
19417
|
+
state.entry = {
|
|
19418
|
+
...state.entry,
|
|
19419
|
+
...order
|
|
19420
|
+
};
|
|
19421
|
+
},
|
|
19422
|
+
false
|
|
19423
|
+
// "updateOrder"
|
|
19424
|
+
);
|
|
19425
|
+
},
|
|
19426
|
+
updateOrderByKey: (key, value) => {
|
|
19427
|
+
set(
|
|
19428
|
+
(state) => {
|
|
19429
|
+
state.entry[key] = value;
|
|
19430
|
+
},
|
|
19431
|
+
false
|
|
19432
|
+
// "updateOrderByKey"
|
|
19433
|
+
);
|
|
19434
|
+
},
|
|
19435
|
+
restoreOrder: (order) => {
|
|
19436
|
+
set(
|
|
19437
|
+
(state) => {
|
|
19438
|
+
state.entry = order;
|
|
19439
|
+
},
|
|
19440
|
+
false
|
|
19441
|
+
// "restoreOrder"
|
|
19442
|
+
);
|
|
19443
|
+
},
|
|
19444
|
+
resetOrder: (_order) => {
|
|
19445
|
+
set(
|
|
19446
|
+
(state) => {
|
|
19447
|
+
state.entry.order_price = "";
|
|
19448
|
+
state.entry.order_quantity = "";
|
|
19449
|
+
state.entry.trigger_price = "";
|
|
19450
|
+
state.entry.total = "";
|
|
19451
|
+
state.entry.tp_trigger_price = "";
|
|
19452
|
+
state.entry.tp_pnl = "";
|
|
19453
|
+
state.entry.tp_offset = "";
|
|
19454
|
+
state.entry.tp_offset_percentage = "";
|
|
19455
|
+
state.entry.sl_trigger_price = "";
|
|
19456
|
+
state.entry.sl_pnl = "";
|
|
19457
|
+
state.entry.sl_offset = "";
|
|
19458
|
+
state.entry.sl_offset_percentage = "";
|
|
19459
|
+
},
|
|
19460
|
+
true
|
|
19461
|
+
// "resetOrder"
|
|
19462
|
+
);
|
|
19463
|
+
}
|
|
19464
|
+
}
|
|
19465
|
+
}))
|
|
19466
|
+
);
|
|
19192
19467
|
var useOrderEntity = (order, options) => {
|
|
19193
19468
|
const { symbol } = order;
|
|
19194
19469
|
const { maxQty } = options || {};
|
|
@@ -19663,6 +19938,7 @@ exports.EpochStatus = EpochStatus;
|
|
|
19663
19938
|
exports.ExtendedConfigStore = ExtendedConfigStore;
|
|
19664
19939
|
exports.FlagKeys = FlagKeys;
|
|
19665
19940
|
exports.MaintenanceStatus = MaintenanceStatus;
|
|
19941
|
+
exports.MarketCategoriesConfigProvider = MarketCategoriesConfigProvider;
|
|
19666
19942
|
exports.MarketsStorageKey = MarketsStorageKey;
|
|
19667
19943
|
exports.MarketsType = MarketsType;
|
|
19668
19944
|
exports.ORDERLY_ORDERBOOK_DEPTH_KEY = ORDERLY_ORDERBOOK_DEPTH_KEY;
|
|
@@ -19679,6 +19955,7 @@ exports.fetcher = fetcher;
|
|
|
19679
19955
|
exports.findPositionTPSLFromOrders = findPositionTPSLFromOrders;
|
|
19680
19956
|
exports.findTPSLFromOrder = findTPSLFromOrder;
|
|
19681
19957
|
exports.findTPSLOrderPriceFromOrder = findTPSLOrderPriceFromOrder;
|
|
19958
|
+
exports.formatSymbolWithBroker = formatSymbolWithBroker;
|
|
19682
19959
|
exports.getMinNotional = getMinNotional;
|
|
19683
19960
|
exports.getPriceKey = getPriceKey;
|
|
19684
19961
|
exports.indexedDBManager = indexedDBManager;
|
|
@@ -19699,6 +19976,7 @@ exports.useApiKeyManager = useApiKeyManager;
|
|
|
19699
19976
|
exports.useAppStore = useAppStore;
|
|
19700
19977
|
exports.useAssetsHistory = useAssetsHistory;
|
|
19701
19978
|
exports.useAudioPlayer = useAudioPlayer;
|
|
19979
|
+
exports.useBadgeBySymbol = useBadgeBySymbol;
|
|
19702
19980
|
exports.useBalanceSubscription = useBalanceSubscription;
|
|
19703
19981
|
exports.useBalanceTopic = useBalanceTopic;
|
|
19704
19982
|
exports.useBoolean = useBoolean;
|
|
@@ -19757,6 +20035,7 @@ exports.useMarkPrice = useMarkPrice;
|
|
|
19757
20035
|
exports.useMarkPriceBySymbol = useMarkPriceBySymbol;
|
|
19758
20036
|
exports.useMarkPricesStream = useMarkPricesStream;
|
|
19759
20037
|
exports.useMarket = useMarket;
|
|
20038
|
+
exports.useMarketCategoriesConfig = useMarketCategoriesConfig;
|
|
19760
20039
|
exports.useMarketList = useMarketList;
|
|
19761
20040
|
exports.useMarketMap = useMarketMap;
|
|
19762
20041
|
exports.useMarketTradeStream = useMarketTradeStream;
|
|
@@ -19814,6 +20093,7 @@ exports.useSymbolInfo = useSymbolInfo;
|
|
|
19814
20093
|
exports.useSymbolLeverage = useSymbolLeverage;
|
|
19815
20094
|
exports.useSymbolLeverageMap = useSymbolLeverageMap;
|
|
19816
20095
|
exports.useSymbolPriceRange = useSymbolPriceRange;
|
|
20096
|
+
exports.useSymbolWithBroker = useSymbolWithBroker;
|
|
19817
20097
|
exports.useSymbolsInfo = useSymbolsInfo;
|
|
19818
20098
|
exports.useSymbolsInfoStore = useSymbolsInfoStore;
|
|
19819
20099
|
exports.useTPSLOrder = useTPSLOrder;
|