@orderly.network/hooks 2.6.1 → 2.6.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 +38 -9
- package/dist/index.d.ts +38 -9
- package/dist/index.js +462 -327
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +462 -329
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -22
package/dist/index.js
CHANGED
|
@@ -61,9 +61,9 @@ var __export = (target, all) => {
|
|
|
61
61
|
// src/version.ts
|
|
62
62
|
if (typeof window !== "undefined") {
|
|
63
63
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
64
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.6.
|
|
64
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.6.2";
|
|
65
65
|
}
|
|
66
|
-
var version_default = "2.6.
|
|
66
|
+
var version_default = "2.6.2";
|
|
67
67
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
68
68
|
var OrderlyContext = React2.createContext({
|
|
69
69
|
// configStore: new MemoryConfigStore(),
|
|
@@ -72,6 +72,8 @@ var useOrderlyContext = () => {
|
|
|
72
72
|
return React2.useContext(OrderlyContext);
|
|
73
73
|
};
|
|
74
74
|
var OrderlyProvider = OrderlyContext.Provider;
|
|
75
|
+
|
|
76
|
+
// src/useConfig.ts
|
|
75
77
|
function useConfig(key, defaultValue) {
|
|
76
78
|
const { configStore } = React2.useContext(OrderlyContext);
|
|
77
79
|
if (!configStore) {
|
|
@@ -303,7 +305,7 @@ var useWS = () => {
|
|
|
303
305
|
networkId: configStore.get("networkId"),
|
|
304
306
|
publicUrl: configStore.get("publicWsUrl"),
|
|
305
307
|
privateUrl: configStore.get("privateWsUrl"),
|
|
306
|
-
onSigntureRequest: async (
|
|
308
|
+
onSigntureRequest: async () => {
|
|
307
309
|
const signer = account9.signer;
|
|
308
310
|
const timestamp = utils.getTimestamp();
|
|
309
311
|
const result = await signer.signText(timestamp.toString());
|
|
@@ -705,10 +707,28 @@ var apiKeyMap = {
|
|
|
705
707
|
staging: "dffc00e003479b86d410c448e00f2304",
|
|
706
708
|
prod: "3ab9ae56ed16cc57bc2ac97ffc1098c2"
|
|
707
709
|
};
|
|
710
|
+
function getAmplitudeConfig(env, amplitudeConfig) {
|
|
711
|
+
if (!amplitudeConfig) {
|
|
712
|
+
return {
|
|
713
|
+
amplitudeId: apiKeyMap[env],
|
|
714
|
+
options: {
|
|
715
|
+
serverZone: "EU"
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
const { amplitudeId, serverZone } = amplitudeConfig;
|
|
720
|
+
return {
|
|
721
|
+
amplitudeId,
|
|
722
|
+
options: serverZone ? {
|
|
723
|
+
serverZone
|
|
724
|
+
} : {}
|
|
725
|
+
};
|
|
726
|
+
}
|
|
708
727
|
var AmplitudeTracker = class {
|
|
709
|
-
constructor(env, sdkInfo) {
|
|
728
|
+
constructor(env, amplitudeConfig, sdkInfo) {
|
|
710
729
|
this._ee = core.SimpleDI.get("EE");
|
|
711
|
-
|
|
730
|
+
const { amplitudeId, options } = getAmplitudeConfig(env, amplitudeConfig);
|
|
731
|
+
amplitude__namespace.init(amplitudeId, options);
|
|
712
732
|
this.setSdkInfo(sdkInfo);
|
|
713
733
|
this._bindEvents();
|
|
714
734
|
}
|
|
@@ -760,15 +780,16 @@ AmplitudeTracker.instanceName = "amplitudeTracker";
|
|
|
760
780
|
|
|
761
781
|
// src/useTrackInstance.ts
|
|
762
782
|
var useTrackingInstance = () => {
|
|
763
|
-
const { configStore } = React2.useContext(OrderlyContext);
|
|
764
|
-
if (!configStore)
|
|
783
|
+
const { configStore, amplitudeConfig } = React2.useContext(OrderlyContext);
|
|
784
|
+
if (!configStore) {
|
|
765
785
|
throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
786
|
+
}
|
|
766
787
|
const env = configStore.get("env");
|
|
767
788
|
const brokerId = configStore.get("brokerId");
|
|
768
789
|
const trackInstace = useConstant__default.default(() => {
|
|
769
790
|
let instance = core.SimpleDI.get("amplitudeTracker");
|
|
770
791
|
if (!instance) {
|
|
771
|
-
instance = new AmplitudeTracker(env, {
|
|
792
|
+
instance = new AmplitudeTracker(env, amplitudeConfig ?? void 0, {
|
|
772
793
|
brokerId,
|
|
773
794
|
sdk_version: window?.__ORDERLY_VERSION__?.["@orderly.network/net"] ?? ""
|
|
774
795
|
});
|
|
@@ -845,6 +866,9 @@ var DEFAULT_TICK_SIZES = {
|
|
|
845
866
|
PERP_ETH_USDC: "0.1",
|
|
846
867
|
PERP_SOL_USDC: "0.01"
|
|
847
868
|
};
|
|
869
|
+
var DEFAULT_SYMBOL_DEPTHS = {
|
|
870
|
+
PERP_ETH_USDC: [0.01, 0.1, 0.5, 1, 10]
|
|
871
|
+
};
|
|
848
872
|
var ProxyConfigStore = class {
|
|
849
873
|
constructor(_originConfigStore) {
|
|
850
874
|
this._originConfigStore = _originConfigStore;
|
|
@@ -1958,8 +1982,9 @@ var CalculatorService = class {
|
|
|
1958
1982
|
this.ctx?.clearCache();
|
|
1959
1983
|
}
|
|
1960
1984
|
get windowIsVisible() {
|
|
1961
|
-
if (typeof document === "undefined")
|
|
1985
|
+
if (typeof document === "undefined") {
|
|
1962
1986
|
return true;
|
|
1987
|
+
}
|
|
1963
1988
|
return document.visibilityState === "visible";
|
|
1964
1989
|
}
|
|
1965
1990
|
};
|
|
@@ -2443,7 +2468,7 @@ var PortfolioCalculator = class extends BaseCalculator {
|
|
|
2443
2468
|
accountInfo,
|
|
2444
2469
|
symbolsInfo,
|
|
2445
2470
|
indexPrices,
|
|
2446
|
-
tokensInfo: tokensInfo ??
|
|
2471
|
+
tokensInfo: tokensInfo ?? types.EMPTY_LIST
|
|
2447
2472
|
});
|
|
2448
2473
|
}
|
|
2449
2474
|
getPortfolio(ctx) {
|
|
@@ -2510,7 +2535,7 @@ var PortfolioCalculator = class extends BaseCalculator {
|
|
|
2510
2535
|
};
|
|
2511
2536
|
}
|
|
2512
2537
|
update(data, scope) {
|
|
2513
|
-
if (
|
|
2538
|
+
if (data) {
|
|
2514
2539
|
useAppStore.getState().actions.batchUpdateForPortfolio({
|
|
2515
2540
|
totalCollateral: data.totalCollateral,
|
|
2516
2541
|
totalValue: data.totalValue,
|
|
@@ -2655,8 +2680,12 @@ var OrderbookService = class _OrderbookService {
|
|
|
2655
2680
|
}
|
|
2656
2681
|
const askMap = /* @__PURE__ */ new Map();
|
|
2657
2682
|
const bidMap = /* @__PURE__ */ new Map();
|
|
2658
|
-
rawOrderBook.asks.forEach((ask) =>
|
|
2659
|
-
|
|
2683
|
+
rawOrderBook.asks.forEach((ask) => {
|
|
2684
|
+
askMap.set(ask[0], ask[1]);
|
|
2685
|
+
});
|
|
2686
|
+
rawOrderBook.bids.forEach((bid) => {
|
|
2687
|
+
bidMap.set(bid[0], bid[1]);
|
|
2688
|
+
});
|
|
2660
2689
|
update.asks.forEach(
|
|
2661
2690
|
(ask) => ask[1] === 0 ? askMap.delete(ask[0]) : askMap.set(ask[0], ask[1])
|
|
2662
2691
|
);
|
|
@@ -2672,9 +2701,9 @@ var OrderbookService = class _OrderbookService {
|
|
|
2672
2701
|
rawOrderBook.ts = update.ts;
|
|
2673
2702
|
}
|
|
2674
2703
|
applyBufferedUpdatesToRawOrderBooks(symbol) {
|
|
2675
|
-
this.bufferedOrderBookUpdates[symbol]?.forEach(
|
|
2676
|
-
|
|
2677
|
-
);
|
|
2704
|
+
this.bufferedOrderBookUpdates[symbol]?.forEach((update) => {
|
|
2705
|
+
this.applyUpdateToRawOrderBook(symbol, update);
|
|
2706
|
+
});
|
|
2678
2707
|
}
|
|
2679
2708
|
deleteBufferedOrderBookUpdates(symbol) {
|
|
2680
2709
|
delete this.bufferedOrderBookUpdates[symbol];
|
|
@@ -2901,63 +2930,56 @@ var useTickerStream = (symbol) => {
|
|
|
2901
2930
|
};
|
|
2902
2931
|
|
|
2903
2932
|
// src/orderly/useOrderbookStream.ts
|
|
2904
|
-
var paddingFn = (len) => Array(len).fill([
|
|
2905
|
-
|
|
2906
|
-
Number.
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2933
|
+
var paddingFn = (len) => Array(len).fill([Number.NaN, Number.NaN, Number.NaN, Number.NaN]);
|
|
2934
|
+
var isNumber = (val) => {
|
|
2935
|
+
return typeof val === "number" && !Number.isNaN(val);
|
|
2936
|
+
};
|
|
2937
|
+
var getPriceKey = (rawPrice, depth, isAsks) => {
|
|
2938
|
+
return new utils.Decimal(rawPrice).div(depth).toDecimalPlaces(0, isAsks ? utils.Decimal.ROUND_CEIL : utils.Decimal.ROUND_FLOOR).mul(depth).toNumber();
|
|
2939
|
+
};
|
|
2940
|
+
var reduceItems = (depth, data, isAsks) => {
|
|
2911
2941
|
if (!Array.isArray(data) || data.length === 0) {
|
|
2912
2942
|
return [];
|
|
2913
2943
|
}
|
|
2914
2944
|
let newData = [...data];
|
|
2915
2945
|
const result = [];
|
|
2916
2946
|
if (typeof depth !== "undefined") {
|
|
2917
|
-
const
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2947
|
+
const pricesMap = /* @__PURE__ */ new Map();
|
|
2948
|
+
const len = data.length;
|
|
2949
|
+
for (let i = 0; i < len; i++) {
|
|
2950
|
+
const [rawPrice, quantity] = data[i];
|
|
2951
|
+
if (!isNumber(rawPrice) || !isNumber(quantity)) {
|
|
2921
2952
|
continue;
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
const index = priceStr.indexOf(".");
|
|
2931
|
-
const decimal = priceStr.slice(index + 1);
|
|
2932
|
-
const decimalDepth = utils.removeTrailingZeros(depth).toString().slice(2).length;
|
|
2933
|
-
const decimalStr = decimal.slice(0, ramda.min(decimal.length, decimalDepth));
|
|
2934
|
-
priceKey = new utils.Decimal(
|
|
2935
|
-
priceStr.slice(0, index) + "." + decimalStr
|
|
2936
|
-
).toNumber();
|
|
2937
|
-
}
|
|
2938
|
-
if (prices.has(priceKey)) {
|
|
2939
|
-
const item = prices.get(priceKey);
|
|
2940
|
-
const itemPrice = new utils.Decimal(item[1]).add(quantity).toNumber();
|
|
2941
|
-
prices.set(priceKey, [priceKey, itemPrice]);
|
|
2953
|
+
}
|
|
2954
|
+
const priceKey = getPriceKey(rawPrice, depth, isAsks);
|
|
2955
|
+
const amtByRaw = new utils.Decimal(rawPrice).mul(quantity).toNumber();
|
|
2956
|
+
if (pricesMap.has(priceKey)) {
|
|
2957
|
+
const item = pricesMap.get(priceKey);
|
|
2958
|
+
const sumQty = new utils.Decimal(item[1]).add(quantity).toNumber();
|
|
2959
|
+
const sumAmtByRaw = new utils.Decimal(item[2] ?? 0).add(amtByRaw).toNumber();
|
|
2960
|
+
pricesMap.set(priceKey, [priceKey, sumQty, sumAmtByRaw]);
|
|
2942
2961
|
} else {
|
|
2943
|
-
|
|
2962
|
+
pricesMap.set(priceKey, [priceKey, quantity, amtByRaw]);
|
|
2944
2963
|
}
|
|
2945
2964
|
}
|
|
2946
|
-
newData = Array.from(
|
|
2965
|
+
newData = Array.from(pricesMap.values());
|
|
2947
2966
|
}
|
|
2948
2967
|
for (let i = 0; i < newData.length; i++) {
|
|
2949
|
-
const [price, quantity] = newData[i];
|
|
2950
|
-
if (
|
|
2968
|
+
const [price, quantity, sumAmtByRaw] = newData[i];
|
|
2969
|
+
if (!isNumber(price) || !isNumber(quantity)) {
|
|
2951
2970
|
continue;
|
|
2952
|
-
|
|
2953
|
-
const
|
|
2971
|
+
}
|
|
2972
|
+
const resLen = result.length;
|
|
2973
|
+
const newQuantity = new utils.Decimal(quantity).add(resLen ? result[resLen - 1][2] : 0).toNumber();
|
|
2974
|
+
const pieceAmount = isNumber(sumAmtByRaw) ? sumAmtByRaw : new utils.Decimal(quantity).mul(price).toNumber();
|
|
2975
|
+
const newAmount = new utils.Decimal(pieceAmount).add(resLen ? result[resLen - 1][3] : 0).toNumber();
|
|
2954
2976
|
result.push([price, quantity, newQuantity, newAmount]);
|
|
2955
2977
|
}
|
|
2956
2978
|
return result;
|
|
2957
2979
|
};
|
|
2958
2980
|
var reduceOrderbook = (depth, level, padding, data) => {
|
|
2959
|
-
let asks = reduceItems(depth,
|
|
2960
|
-
let bids = reduceItems(depth,
|
|
2981
|
+
let asks = reduceItems(depth, data.asks, true);
|
|
2982
|
+
let bids = reduceItems(depth, data.bids, false);
|
|
2961
2983
|
if (asks.length !== 0 && bids.length !== 0 && asks[0][0] <= bids[0][0]) {
|
|
2962
2984
|
if (asks.length === 1) {
|
|
2963
2985
|
const [price, qty, newQuantity, newAmount] = asks[0];
|
|
@@ -2974,14 +2996,14 @@ var reduceOrderbook = (depth, level, padding, data) => {
|
|
|
2974
2996
|
const [askPrice, askQty, newQuantity, newAmount] = asks[0];
|
|
2975
2997
|
if (askPrice <= bidPrice) {
|
|
2976
2998
|
asks.shift();
|
|
2977
|
-
for (let
|
|
2978
|
-
if (
|
|
2979
|
-
const quantity = asks[
|
|
2980
|
-
asks[
|
|
2981
|
-
asks[
|
|
2982
|
-
asks[
|
|
2999
|
+
for (let i = 0; i < asks.length; i++) {
|
|
3000
|
+
if (i === 0) {
|
|
3001
|
+
const quantity = new utils.Decimal(asks[i][1]).add(askQty);
|
|
3002
|
+
asks[i][1] = quantity.toNumber();
|
|
3003
|
+
asks[i][2] = quantity.toNumber();
|
|
3004
|
+
asks[i][3] = quantity.toDecimalPlaces(0, utils.Decimal.ROUND_CEIL).mul(asks[i][0]).toNumber();
|
|
2983
3005
|
} else {
|
|
2984
|
-
asks[
|
|
3006
|
+
asks[i][3] = new utils.Decimal(asks[i][0]).mul(asks[i][1]).add(asks[i - 1][3]).toNumber();
|
|
2985
3007
|
}
|
|
2986
3008
|
}
|
|
2987
3009
|
} else {
|
|
@@ -3000,6 +3022,7 @@ var reduceOrderbook = (depth, level, padding, data) => {
|
|
|
3000
3022
|
bids
|
|
3001
3023
|
};
|
|
3002
3024
|
};
|
|
3025
|
+
var ORDERLY_ORDERBOOK_DEPTH_KEY = "orderly_orderbook_depth_key";
|
|
3003
3026
|
var INIT_DATA = {
|
|
3004
3027
|
asks: [],
|
|
3005
3028
|
bids: []
|
|
@@ -3012,14 +3035,23 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
3012
3035
|
const padding = options?.padding ?? true;
|
|
3013
3036
|
const symbolRef = React2.useRef(symbol);
|
|
3014
3037
|
symbolRef.current = symbol;
|
|
3015
|
-
const {
|
|
3038
|
+
const {
|
|
3039
|
+
defaultOrderbookTickSizes: DEFAULT_TICK_SIZES2 = {},
|
|
3040
|
+
defaultOrderbookSymbolDepths: DEFAULT_SYMBOL_DEPTHS2 = {}
|
|
3041
|
+
} = React2.useContext(OrderlyContext);
|
|
3016
3042
|
const [data, setData] = React2.useState(initial);
|
|
3017
3043
|
const [isLoading, setIsLoading] = React2.useState(true);
|
|
3018
3044
|
const config = useSymbolsInfo()[symbol];
|
|
3019
|
-
const [
|
|
3045
|
+
const [depthObject, setDepthObject] = useLocalStorage(
|
|
3046
|
+
ORDERLY_ORDERBOOK_DEPTH_KEY,
|
|
3047
|
+
{}
|
|
3048
|
+
);
|
|
3020
3049
|
const prevMiddlePrice = React2.useRef(0);
|
|
3050
|
+
const tick = config("quote_tick");
|
|
3021
3051
|
const depths = React2.useMemo(() => {
|
|
3022
|
-
|
|
3052
|
+
if (DEFAULT_SYMBOL_DEPTHS2[symbol]) {
|
|
3053
|
+
return DEFAULT_SYMBOL_DEPTHS2[symbol];
|
|
3054
|
+
}
|
|
3023
3055
|
if (typeof tick === "undefined") {
|
|
3024
3056
|
return [];
|
|
3025
3057
|
}
|
|
@@ -3031,26 +3063,40 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
3031
3063
|
base.mul(100).toNumber(),
|
|
3032
3064
|
base.mul(1e3).toNumber()
|
|
3033
3065
|
];
|
|
3034
|
-
} catch
|
|
3066
|
+
} catch {
|
|
3035
3067
|
}
|
|
3036
3068
|
return [tick];
|
|
3037
|
-
}, [
|
|
3069
|
+
}, [symbol, tick]);
|
|
3038
3070
|
React2.useEffect(() => {
|
|
3071
|
+
if (depthObject[symbol]) {
|
|
3072
|
+
return;
|
|
3073
|
+
}
|
|
3039
3074
|
if (DEFAULT_TICK_SIZES2[symbol]) {
|
|
3040
|
-
|
|
3075
|
+
setDepthObject((prev) => ({
|
|
3076
|
+
...prev,
|
|
3077
|
+
[symbol]: Number(DEFAULT_TICK_SIZES2[symbol])
|
|
3078
|
+
}));
|
|
3041
3079
|
} else {
|
|
3042
|
-
|
|
3080
|
+
setDepthObject((prev) => ({
|
|
3081
|
+
...prev,
|
|
3082
|
+
[symbol]: tick
|
|
3083
|
+
}));
|
|
3043
3084
|
}
|
|
3044
|
-
}, [
|
|
3085
|
+
}, [depthObject, tick, symbol, DEFAULT_TICK_SIZES2]);
|
|
3086
|
+
const onDepthChange = React2.useCallback(
|
|
3087
|
+
(val) => {
|
|
3088
|
+
setDepthObject((prev) => ({ ...prev, [symbol]: val }));
|
|
3089
|
+
},
|
|
3090
|
+
[symbol]
|
|
3091
|
+
);
|
|
3045
3092
|
const ws = useWS();
|
|
3046
3093
|
const ticker = useTickerStream(symbol);
|
|
3047
3094
|
const eventEmitter = useEventEmitter();
|
|
3048
3095
|
React2.useEffect(() => {
|
|
3049
3096
|
let needRequestFullOrderbook = true;
|
|
3050
3097
|
setIsLoading(true);
|
|
3051
|
-
let orderBookUpdateSub;
|
|
3052
3098
|
let fullOrderBookUpdateSub;
|
|
3053
|
-
orderBookUpdateSub = ws.subscribe(
|
|
3099
|
+
const orderBookUpdateSub = ws.subscribe(
|
|
3054
3100
|
{
|
|
3055
3101
|
event: "subscribe",
|
|
3056
3102
|
topic: `${symbol}@orderbookupdate`
|
|
@@ -3067,7 +3113,9 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
3067
3113
|
orderbook_service_default.updateOrderbook(
|
|
3068
3114
|
symbol2,
|
|
3069
3115
|
{ asks, bids, ts, prevTs },
|
|
3070
|
-
() =>
|
|
3116
|
+
() => {
|
|
3117
|
+
needRequestFullOrderbook = true;
|
|
3118
|
+
}
|
|
3071
3119
|
);
|
|
3072
3120
|
const data2 = orderbook_service_default.getRawOrderbook(symbol2);
|
|
3073
3121
|
setData({ bids: data2.bids, asks: data2.asks });
|
|
@@ -3112,25 +3160,23 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
3112
3160
|
const onItemClick = React2.useCallback((item) => {
|
|
3113
3161
|
eventEmitter.emit("orderbook:item:click", item);
|
|
3114
3162
|
}, []);
|
|
3115
|
-
const
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
const reducedData = reduceOrderbook(depth, level, padding, {
|
|
3119
|
-
asks: [...data.asks],
|
|
3120
|
-
bids: [...data.bids]
|
|
3163
|
+
const reducedData = reduceOrderbook(depthObject[symbol], level, padding, {
|
|
3164
|
+
asks: data.asks,
|
|
3165
|
+
bids: data.bids
|
|
3121
3166
|
});
|
|
3122
3167
|
React2.useEffect(() => {
|
|
3123
3168
|
eventEmitter.emit("orderbook:update", reducedData);
|
|
3124
3169
|
}, [reducedData]);
|
|
3125
3170
|
const middlePrice = React2.useMemo(() => {
|
|
3126
|
-
let asksFrist = 0
|
|
3171
|
+
let asksFrist = 0;
|
|
3172
|
+
let bidsFirst = 0;
|
|
3127
3173
|
if (data.asks.length > 0) {
|
|
3128
3174
|
asksFrist = reducedData.asks?.[reducedData.asks.length - 1]?.[0];
|
|
3129
3175
|
}
|
|
3130
3176
|
if (data.bids.length > 0) {
|
|
3131
3177
|
bidsFirst = data.bids[0][0];
|
|
3132
3178
|
}
|
|
3133
|
-
if (
|
|
3179
|
+
if (!isNumber(asksFrist) || !isNumber(bidsFirst) || !ticker) {
|
|
3134
3180
|
return 0;
|
|
3135
3181
|
}
|
|
3136
3182
|
return [asksFrist, bidsFirst, ticker["24h_close"]].sort()[1];
|
|
@@ -3145,7 +3191,13 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
3145
3191
|
markPrice,
|
|
3146
3192
|
middlePrice: [prevMiddlePrice.current, middlePrice]
|
|
3147
3193
|
},
|
|
3148
|
-
{
|
|
3194
|
+
{
|
|
3195
|
+
onDepthChange,
|
|
3196
|
+
depth: depthObject[symbol],
|
|
3197
|
+
allDepths: depths,
|
|
3198
|
+
isLoading,
|
|
3199
|
+
onItemClick
|
|
3200
|
+
}
|
|
3149
3201
|
];
|
|
3150
3202
|
};
|
|
3151
3203
|
|
|
@@ -3163,6 +3215,8 @@ var useFundingRatesStore = () => {
|
|
|
3163
3215
|
const data = useAppStore((state) => state.fundingRates);
|
|
3164
3216
|
return data;
|
|
3165
3217
|
};
|
|
3218
|
+
|
|
3219
|
+
// src/orderly/useMarket.ts
|
|
3166
3220
|
var DefaultTab = { name: "Popular", id: 1 };
|
|
3167
3221
|
var marketsKey = "markets";
|
|
3168
3222
|
var useMarket = (type) => {
|
|
@@ -3202,12 +3256,13 @@ var useMarket = (type) => {
|
|
|
3202
3256
|
const curData = getStore("favorites", []);
|
|
3203
3257
|
const tabs = getFavoriteTabs;
|
|
3204
3258
|
const result = [];
|
|
3205
|
-
|
|
3259
|
+
const len = curData.length;
|
|
3260
|
+
for (let index = 0; index < len; index++) {
|
|
3206
3261
|
const favData = curData[index];
|
|
3207
|
-
|
|
3262
|
+
const favTabs = favData.tabs.filter(
|
|
3208
3263
|
(tab) => tabs.findIndex((item) => tab.id === item.id) !== -1
|
|
3209
3264
|
);
|
|
3210
|
-
if (favTabs.length
|
|
3265
|
+
if (favTabs.length) {
|
|
3211
3266
|
result.push({ ...favData, tabs: favTabs });
|
|
3212
3267
|
}
|
|
3213
3268
|
}
|
|
@@ -3231,7 +3286,7 @@ var useMarket = (type) => {
|
|
|
3231
3286
|
saveTabs(tab);
|
|
3232
3287
|
return;
|
|
3233
3288
|
}
|
|
3234
|
-
|
|
3289
|
+
const tabs = [...favoriteTabs];
|
|
3235
3290
|
const index = tabs.findIndex((item) => item.id === tab.id);
|
|
3236
3291
|
if (operator?.add) {
|
|
3237
3292
|
tabs.push(tab);
|
|
@@ -3374,7 +3429,7 @@ var useMarket = (type) => {
|
|
|
3374
3429
|
};
|
|
3375
3430
|
const markets = getData(type);
|
|
3376
3431
|
return [
|
|
3377
|
-
markets ||
|
|
3432
|
+
markets || types.EMPTY_LIST,
|
|
3378
3433
|
{
|
|
3379
3434
|
favoriteTabs,
|
|
3380
3435
|
favorites,
|
|
@@ -3430,13 +3485,13 @@ var useIndexPricesStream = () => {
|
|
|
3430
3485
|
getIndexPrice: useMemoizedFn(getIndexPrice)
|
|
3431
3486
|
};
|
|
3432
3487
|
};
|
|
3433
|
-
var generateLeverageLevers = (
|
|
3434
|
-
const
|
|
3488
|
+
var generateLeverageLevers = (max2) => {
|
|
3489
|
+
const min2 = 1;
|
|
3435
3490
|
const parts = 5;
|
|
3436
|
-
const step = (
|
|
3491
|
+
const step = (max2 - min2) / (parts - 1);
|
|
3437
3492
|
const result = [];
|
|
3438
3493
|
for (let i = 0; i < parts; i++) {
|
|
3439
|
-
result.push(Math.floor(
|
|
3494
|
+
result.push(Math.floor(min2 + step * i));
|
|
3440
3495
|
}
|
|
3441
3496
|
return result;
|
|
3442
3497
|
};
|
|
@@ -5758,12 +5813,12 @@ var OrderValidation = class {
|
|
|
5758
5813
|
value
|
|
5759
5814
|
};
|
|
5760
5815
|
}
|
|
5761
|
-
static range(key,
|
|
5816
|
+
static range(key, min2, max2) {
|
|
5762
5817
|
return {
|
|
5763
5818
|
type: "range",
|
|
5764
|
-
message: `${this.getLabel(key)} must be in the range of ${
|
|
5765
|
-
min:
|
|
5766
|
-
max:
|
|
5819
|
+
message: `${this.getLabel(key)} must be in the range of ${min2} to ${max2}`,
|
|
5820
|
+
min: min2,
|
|
5821
|
+
max: max2
|
|
5767
5822
|
};
|
|
5768
5823
|
}
|
|
5769
5824
|
};
|
|
@@ -6019,81 +6074,6 @@ var BBOOrderCreator = class extends BaseOrderCreator {
|
|
|
6019
6074
|
});
|
|
6020
6075
|
}
|
|
6021
6076
|
};
|
|
6022
|
-
var { maxPrice, minPrice, scopePrice } = perp.order;
|
|
6023
|
-
var LimitOrderCreator = class extends BaseOrderCreator {
|
|
6024
|
-
constructor() {
|
|
6025
|
-
super(...arguments);
|
|
6026
|
-
this.orderType = types.OrderType.LIMIT;
|
|
6027
|
-
}
|
|
6028
|
-
create(values2, config) {
|
|
6029
|
-
const order = {
|
|
6030
|
-
...this.baseOrder(values2),
|
|
6031
|
-
order_price: values2.order_price
|
|
6032
|
-
};
|
|
6033
|
-
this.totalToQuantity(order, config);
|
|
6034
|
-
return ramda.pick(
|
|
6035
|
-
[
|
|
6036
|
-
"symbol",
|
|
6037
|
-
"order_price",
|
|
6038
|
-
"order_quantity",
|
|
6039
|
-
"visible_quantity",
|
|
6040
|
-
"reduce_only",
|
|
6041
|
-
"side",
|
|
6042
|
-
"order_type",
|
|
6043
|
-
"algo_type",
|
|
6044
|
-
"child_orders"
|
|
6045
|
-
],
|
|
6046
|
-
order
|
|
6047
|
-
);
|
|
6048
|
-
}
|
|
6049
|
-
validate(values2, config) {
|
|
6050
|
-
return this.baseValidate(values2, config).then((errors) => {
|
|
6051
|
-
const { order_price, side } = values2;
|
|
6052
|
-
if (!order_price) {
|
|
6053
|
-
errors.order_price = OrderValidation.required("order_price");
|
|
6054
|
-
} else {
|
|
6055
|
-
const price = new utils.Decimal(order_price);
|
|
6056
|
-
const { symbol } = config;
|
|
6057
|
-
const { price_range, price_scope, quote_max, quote_min } = symbol;
|
|
6058
|
-
const maxPriceNumber = maxPrice(config.markPrice, price_range);
|
|
6059
|
-
const minPriceNumber = minPrice(config.markPrice, price_range);
|
|
6060
|
-
const scopePriceNumber = scopePrice(
|
|
6061
|
-
config.markPrice,
|
|
6062
|
-
price_scope,
|
|
6063
|
-
side
|
|
6064
|
-
);
|
|
6065
|
-
const priceRange = side === "BUY" ? {
|
|
6066
|
-
min: scopePriceNumber,
|
|
6067
|
-
max: maxPriceNumber
|
|
6068
|
-
} : {
|
|
6069
|
-
min: minPriceNumber,
|
|
6070
|
-
max: scopePriceNumber
|
|
6071
|
-
};
|
|
6072
|
-
if (price.gt(quote_max)) {
|
|
6073
|
-
errors.order_price = OrderValidation.max("order_price", quote_max);
|
|
6074
|
-
} else {
|
|
6075
|
-
if (price.gt(priceRange?.max)) {
|
|
6076
|
-
errors.order_price = OrderValidation.max(
|
|
6077
|
-
"order_price",
|
|
6078
|
-
new utils.Decimal(priceRange.max).todp(symbol.quote_dp).toString()
|
|
6079
|
-
);
|
|
6080
|
-
}
|
|
6081
|
-
}
|
|
6082
|
-
if (price.lt(quote_min)) {
|
|
6083
|
-
errors.order_price = OrderValidation.min("order_price", quote_min);
|
|
6084
|
-
} else {
|
|
6085
|
-
if (price.lt(priceRange?.min)) {
|
|
6086
|
-
errors.order_price = OrderValidation.min(
|
|
6087
|
-
"order_price",
|
|
6088
|
-
new utils.Decimal(priceRange.min).todp(symbol.quote_dp).toString()
|
|
6089
|
-
);
|
|
6090
|
-
}
|
|
6091
|
-
}
|
|
6092
|
-
}
|
|
6093
|
-
return errors;
|
|
6094
|
-
});
|
|
6095
|
-
}
|
|
6096
|
-
};
|
|
6097
6077
|
function getOrderPrice(order, askAndBid) {
|
|
6098
6078
|
const orderPrice = Number(order.order_price);
|
|
6099
6079
|
if (order.order_type === types.OrderType.MARKET || order.order_type === types.OrderType.STOP_MARKET) {
|
|
@@ -6326,6 +6306,81 @@ async function bracketOrderValidator(values2, config) {
|
|
|
6326
6306
|
}
|
|
6327
6307
|
return Object.keys(result).length > 0 ? result : null;
|
|
6328
6308
|
}
|
|
6309
|
+
var { maxPrice, minPrice, scopePrice } = perp.order;
|
|
6310
|
+
var LimitOrderCreator = class extends BaseOrderCreator {
|
|
6311
|
+
constructor() {
|
|
6312
|
+
super(...arguments);
|
|
6313
|
+
this.orderType = types.OrderType.LIMIT;
|
|
6314
|
+
}
|
|
6315
|
+
create(values2, config) {
|
|
6316
|
+
const order = {
|
|
6317
|
+
...this.baseOrder(values2),
|
|
6318
|
+
order_price: values2.order_price
|
|
6319
|
+
};
|
|
6320
|
+
this.totalToQuantity(order, config);
|
|
6321
|
+
return ramda.pick(
|
|
6322
|
+
[
|
|
6323
|
+
"symbol",
|
|
6324
|
+
"order_price",
|
|
6325
|
+
"order_quantity",
|
|
6326
|
+
"visible_quantity",
|
|
6327
|
+
"reduce_only",
|
|
6328
|
+
"side",
|
|
6329
|
+
"order_type",
|
|
6330
|
+
"algo_type",
|
|
6331
|
+
"child_orders"
|
|
6332
|
+
],
|
|
6333
|
+
order
|
|
6334
|
+
);
|
|
6335
|
+
}
|
|
6336
|
+
validate(values2, config) {
|
|
6337
|
+
return this.baseValidate(values2, config).then((errors) => {
|
|
6338
|
+
const { order_price, side } = values2;
|
|
6339
|
+
if (!order_price) {
|
|
6340
|
+
errors.order_price = OrderValidation.required("order_price");
|
|
6341
|
+
} else {
|
|
6342
|
+
const price = new utils.Decimal(order_price);
|
|
6343
|
+
const { symbol } = config;
|
|
6344
|
+
const { price_range, price_scope, quote_max, quote_min } = symbol;
|
|
6345
|
+
const maxPriceNumber = maxPrice(config.markPrice, price_range);
|
|
6346
|
+
const minPriceNumber = minPrice(config.markPrice, price_range);
|
|
6347
|
+
const scopePriceNumber = scopePrice(
|
|
6348
|
+
config.markPrice,
|
|
6349
|
+
price_scope,
|
|
6350
|
+
side
|
|
6351
|
+
);
|
|
6352
|
+
const priceRange = side === "BUY" ? {
|
|
6353
|
+
min: scopePriceNumber,
|
|
6354
|
+
max: maxPriceNumber
|
|
6355
|
+
} : {
|
|
6356
|
+
min: minPriceNumber,
|
|
6357
|
+
max: scopePriceNumber
|
|
6358
|
+
};
|
|
6359
|
+
if (price.gt(quote_max)) {
|
|
6360
|
+
errors.order_price = OrderValidation.max("order_price", quote_max);
|
|
6361
|
+
} else {
|
|
6362
|
+
if (price.gt(priceRange?.max)) {
|
|
6363
|
+
errors.order_price = OrderValidation.max(
|
|
6364
|
+
"order_price",
|
|
6365
|
+
new utils.Decimal(priceRange.max).todp(symbol.quote_dp).toString()
|
|
6366
|
+
);
|
|
6367
|
+
}
|
|
6368
|
+
}
|
|
6369
|
+
if (price.lt(quote_min)) {
|
|
6370
|
+
errors.order_price = OrderValidation.min("order_price", quote_min);
|
|
6371
|
+
} else {
|
|
6372
|
+
if (price.lt(priceRange?.min)) {
|
|
6373
|
+
errors.order_price = OrderValidation.min(
|
|
6374
|
+
"order_price",
|
|
6375
|
+
new utils.Decimal(priceRange.min).todp(symbol.quote_dp).toString()
|
|
6376
|
+
);
|
|
6377
|
+
}
|
|
6378
|
+
}
|
|
6379
|
+
}
|
|
6380
|
+
return errors;
|
|
6381
|
+
});
|
|
6382
|
+
}
|
|
6383
|
+
};
|
|
6329
6384
|
|
|
6330
6385
|
// src/services/orderCreator/bracketLimitOrderCreator.ts
|
|
6331
6386
|
var BracketLimitOrderCreator = class extends LimitOrderCreator {
|
|
@@ -6469,7 +6524,7 @@ function calcScaledOrderWeights(inputs) {
|
|
|
6469
6524
|
}
|
|
6470
6525
|
const sumWeights = weights.reduce((acc, cur) => acc.plus(cur), utils.zero);
|
|
6471
6526
|
const minWeight = weights.reduce(
|
|
6472
|
-
(
|
|
6527
|
+
(min2, current) => current.lt(min2) ? current : min2,
|
|
6473
6528
|
weights?.[0]
|
|
6474
6529
|
);
|
|
6475
6530
|
return {
|
|
@@ -6619,7 +6674,7 @@ function calcScaledOrderMinTotalAmountByMinNotional(order, symbolInfo, askAndBid
|
|
|
6619
6674
|
return new utils.Decimal(min_notional).mul(sumWeights).div(new utils.Decimal(weights[i]).mul(orderPrice));
|
|
6620
6675
|
});
|
|
6621
6676
|
const max_minQty = minQtys.reduce(
|
|
6622
|
-
(
|
|
6677
|
+
(max2, current) => current.gt(max2) ? current : max2,
|
|
6623
6678
|
minQtys?.[0]
|
|
6624
6679
|
);
|
|
6625
6680
|
return max_minQty.todp(base_dp, utils.Decimal.ROUND_UP).toNumber();
|
|
@@ -7327,6 +7382,152 @@ var OrderFactory = class {
|
|
|
7327
7382
|
}
|
|
7328
7383
|
}
|
|
7329
7384
|
};
|
|
7385
|
+
|
|
7386
|
+
// src/next/useOrderEntry/helper.ts
|
|
7387
|
+
var getCreateOrderUrl = (order) => {
|
|
7388
|
+
const isAlgoOrder = order?.order_type === types.OrderType.STOP_LIMIT || order?.order_type === types.OrderType.STOP_MARKET || order?.order_type === types.OrderType.CLOSE_POSITION || order.algo_type && order.algo_type === types.AlgoOrderRootType.BRACKET || isBracketOrder(order);
|
|
7389
|
+
if (order.order_type === types.OrderType.SCALED) {
|
|
7390
|
+
return "/v1/batch-order";
|
|
7391
|
+
}
|
|
7392
|
+
return isAlgoOrder ? "/v1/algo/order" : "/v1/order";
|
|
7393
|
+
};
|
|
7394
|
+
var getOrderCreator = (order) => {
|
|
7395
|
+
let type;
|
|
7396
|
+
if (isBracketOrder(order)) {
|
|
7397
|
+
type = `${types.AlgoOrderRootType.BRACKET}:${order.order_type}`;
|
|
7398
|
+
} else if (order.order_type === types.OrderType.LIMIT) {
|
|
7399
|
+
type = order.order_type_ext || order.order_type;
|
|
7400
|
+
} else {
|
|
7401
|
+
type = order.order_type;
|
|
7402
|
+
}
|
|
7403
|
+
return OrderFactory.create(type);
|
|
7404
|
+
};
|
|
7405
|
+
var tpslFields = [
|
|
7406
|
+
"tp_trigger_price",
|
|
7407
|
+
"sl_trigger_price",
|
|
7408
|
+
"tp_pnl",
|
|
7409
|
+
"sl_pnl",
|
|
7410
|
+
"tp_offset",
|
|
7411
|
+
"sl_offset",
|
|
7412
|
+
"tp_offset_percentage",
|
|
7413
|
+
"sl_offset_percentage"
|
|
7414
|
+
];
|
|
7415
|
+
var isBracketOrder = (order) => {
|
|
7416
|
+
if (order.sl_enable || order.tp_enable) {
|
|
7417
|
+
return true;
|
|
7418
|
+
}
|
|
7419
|
+
return !!order.tp_trigger_price || !!order.sl_trigger_price;
|
|
7420
|
+
};
|
|
7421
|
+
var hasTPSL = (order) => {
|
|
7422
|
+
return tpslFields.some((field) => !!order[field]);
|
|
7423
|
+
};
|
|
7424
|
+
var getPriceAndQty = (order, symbolInfo, askAndBid) => {
|
|
7425
|
+
let quantity = Number(order.order_quantity);
|
|
7426
|
+
const orderPrice = Number(order.order_price);
|
|
7427
|
+
if (isNaN(quantity) || quantity <= 0) {
|
|
7428
|
+
return null;
|
|
7429
|
+
}
|
|
7430
|
+
if (askAndBid.length === 0) {
|
|
7431
|
+
return null;
|
|
7432
|
+
}
|
|
7433
|
+
if ((order.order_type === types.OrderType.LIMIT || order.order_type === types.OrderType.STOP_LIMIT) && isNaN(orderPrice)) {
|
|
7434
|
+
return null;
|
|
7435
|
+
}
|
|
7436
|
+
let price;
|
|
7437
|
+
if (order.order_type === types.OrderType.SCALED) {
|
|
7438
|
+
price = calcScaledOrderAvgPrice(order, symbolInfo, askAndBid);
|
|
7439
|
+
const orders = calcScaledOrderBatchBody(order, symbolInfo);
|
|
7440
|
+
const sumQtys = orders.reduce((acc, order2) => {
|
|
7441
|
+
return acc.plus(new utils.Decimal(order2.order_quantity));
|
|
7442
|
+
}, utils.zero);
|
|
7443
|
+
quantity = sumQtys.todp(symbolInfo.base_dp).toNumber();
|
|
7444
|
+
if (!quantity || isNaN(quantity)) {
|
|
7445
|
+
return null;
|
|
7446
|
+
}
|
|
7447
|
+
} else {
|
|
7448
|
+
price = getOrderPrice(order, askAndBid);
|
|
7449
|
+
}
|
|
7450
|
+
if (!price || isNaN(price)) {
|
|
7451
|
+
return null;
|
|
7452
|
+
}
|
|
7453
|
+
if (order.side === types.OrderSide.SELL) {
|
|
7454
|
+
quantity = -quantity;
|
|
7455
|
+
}
|
|
7456
|
+
return { price, quantity };
|
|
7457
|
+
};
|
|
7458
|
+
var calcEstLiqPrice = (order, askAndBid, inputs) => {
|
|
7459
|
+
const { symbolInfo } = inputs;
|
|
7460
|
+
const result = getPriceAndQty(order, symbolInfo, askAndBid);
|
|
7461
|
+
if (!result)
|
|
7462
|
+
return null;
|
|
7463
|
+
const { price, quantity } = result;
|
|
7464
|
+
if (!price || !quantity)
|
|
7465
|
+
return null;
|
|
7466
|
+
const {
|
|
7467
|
+
symbol,
|
|
7468
|
+
imr_factor,
|
|
7469
|
+
markPrice,
|
|
7470
|
+
totalCollateral,
|
|
7471
|
+
futures_taker_fee_rate,
|
|
7472
|
+
positions: positions3
|
|
7473
|
+
} = inputs;
|
|
7474
|
+
const orderFee = perp.order.orderFee({
|
|
7475
|
+
qty: quantity,
|
|
7476
|
+
price,
|
|
7477
|
+
futuresTakeFeeRate: Number(futures_taker_fee_rate) / 1e4
|
|
7478
|
+
});
|
|
7479
|
+
const liqPrice = perp.order.estLiqPrice({
|
|
7480
|
+
markPrice,
|
|
7481
|
+
baseIMR: symbolInfo.base_imr,
|
|
7482
|
+
baseMMR: symbolInfo.base_mmr,
|
|
7483
|
+
totalCollateral,
|
|
7484
|
+
positions: positions3 == null ? [] : positions3,
|
|
7485
|
+
IMR_Factor: imr_factor,
|
|
7486
|
+
orderFee,
|
|
7487
|
+
newOrder: {
|
|
7488
|
+
qty: quantity,
|
|
7489
|
+
price,
|
|
7490
|
+
symbol
|
|
7491
|
+
}
|
|
7492
|
+
});
|
|
7493
|
+
if (liqPrice <= 0)
|
|
7494
|
+
return null;
|
|
7495
|
+
return liqPrice;
|
|
7496
|
+
};
|
|
7497
|
+
var calcEstLeverage = (order, askAndBid, inputs) => {
|
|
7498
|
+
const { totalCollateral, positions: positions3, symbol, symbolInfo } = inputs;
|
|
7499
|
+
const result = getPriceAndQty(order, symbolInfo, askAndBid);
|
|
7500
|
+
if (!result)
|
|
7501
|
+
return null;
|
|
7502
|
+
const { price, quantity } = result;
|
|
7503
|
+
if (!price || !quantity)
|
|
7504
|
+
return null;
|
|
7505
|
+
return perp.order.estLeverage({
|
|
7506
|
+
totalCollateral,
|
|
7507
|
+
positions: positions3,
|
|
7508
|
+
newOrder: {
|
|
7509
|
+
symbol,
|
|
7510
|
+
qty: result.quantity,
|
|
7511
|
+
price: result.price
|
|
7512
|
+
}
|
|
7513
|
+
});
|
|
7514
|
+
};
|
|
7515
|
+
function isBBOOrder(options) {
|
|
7516
|
+
const { order_type, order_type_ext } = options;
|
|
7517
|
+
return order_type === types.OrderType.LIMIT && [types.OrderType.ASK, types.OrderType.BID].includes(order_type_ext);
|
|
7518
|
+
}
|
|
7519
|
+
function appendOrderMetadata(order, orderMetadata) {
|
|
7520
|
+
if (Array.isArray(order)) {
|
|
7521
|
+
return order.map((item) => ({
|
|
7522
|
+
...item,
|
|
7523
|
+
...typeof orderMetadata === "function" ? orderMetadata(item) : orderMetadata
|
|
7524
|
+
}));
|
|
7525
|
+
}
|
|
7526
|
+
return {
|
|
7527
|
+
...order,
|
|
7528
|
+
...typeof orderMetadata === "function" ? orderMetadata(order) : orderMetadata
|
|
7529
|
+
};
|
|
7530
|
+
}
|
|
7330
7531
|
function useSubAccountQuery(query, options) {
|
|
7331
7532
|
const { formatter, accountId, ...swrOptions } = options || {};
|
|
7332
7533
|
const { state, account: account9 } = useAccount();
|
|
@@ -8166,6 +8367,13 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
8166
8367
|
const [doUpdateOrder, { isMutating: isUpdateMutating }] = useSubAccountMutation("/v1/algo/order", "PUT");
|
|
8167
8368
|
const [doDeleteOrder] = useMutation("/v1/algo/order", "DELETE");
|
|
8168
8369
|
const [errors, setErrors] = React2.useState(null);
|
|
8370
|
+
const [meta, setMeta] = React2.useState({
|
|
8371
|
+
dirty: {},
|
|
8372
|
+
submitted: false,
|
|
8373
|
+
validated: false,
|
|
8374
|
+
errors: null
|
|
8375
|
+
});
|
|
8376
|
+
const { orderMetadata } = useOrderlyContext();
|
|
8169
8377
|
React2.useEffect(() => {
|
|
8170
8378
|
if (!isEditing || !options?.defaultOrder)
|
|
8171
8379
|
return;
|
|
@@ -8204,6 +8412,14 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
8204
8412
|
symbol: symbolInfo
|
|
8205
8413
|
}
|
|
8206
8414
|
);
|
|
8415
|
+
const newValueAll = {
|
|
8416
|
+
...prev,
|
|
8417
|
+
...newValue,
|
|
8418
|
+
ignoreValidate: options2?.ignoreValidate
|
|
8419
|
+
};
|
|
8420
|
+
interactiveValidate(
|
|
8421
|
+
newValueAll
|
|
8422
|
+
);
|
|
8207
8423
|
return {
|
|
8208
8424
|
...prev,
|
|
8209
8425
|
...newValue,
|
|
@@ -8244,19 +8460,28 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
8244
8460
|
maxQty: Math.abs(position.position_qty),
|
|
8245
8461
|
markPrice
|
|
8246
8462
|
};
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8463
|
+
const interactiveValidate = (order2) => {
|
|
8464
|
+
validateFunc(order2).then((errors2) => {
|
|
8465
|
+
const keys = Object.keys(errors2 ?? {});
|
|
8466
|
+
if (keys.length > 0) {
|
|
8467
|
+
setMeta(
|
|
8468
|
+
immer$1.produce((draft) => {
|
|
8469
|
+
draft.errors = errors2;
|
|
8470
|
+
})
|
|
8471
|
+
);
|
|
8472
|
+
} else {
|
|
8473
|
+
setMeta(
|
|
8474
|
+
immer$1.produce((draft) => {
|
|
8475
|
+
draft.errors = null;
|
|
8476
|
+
})
|
|
8477
|
+
);
|
|
8253
8478
|
}
|
|
8254
|
-
const orderCreator = getOrderCreator2();
|
|
8255
|
-
orderCreator.validate(order, valueConfig).then((errors2) => {
|
|
8256
|
-
setErrors(errors2);
|
|
8257
|
-
});
|
|
8258
8479
|
});
|
|
8259
|
-
}
|
|
8480
|
+
};
|
|
8481
|
+
const validateFunc = async (order2) => {
|
|
8482
|
+
const creator = getOrderCreator2();
|
|
8483
|
+
return creator.validate(order2, valueConfig);
|
|
8484
|
+
};
|
|
8260
8485
|
const setValues = (values2) => {
|
|
8261
8486
|
const keys = Object.keys(values2);
|
|
8262
8487
|
keys.forEach((key) => {
|
|
@@ -8274,6 +8499,21 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
8274
8499
|
valueConfig
|
|
8275
8500
|
).then((errors2) => {
|
|
8276
8501
|
if (errors2) {
|
|
8502
|
+
const keys = Object.keys(errors2);
|
|
8503
|
+
if (keys.length > 0) {
|
|
8504
|
+
setMeta(
|
|
8505
|
+
immer$1.produce((draft) => {
|
|
8506
|
+
draft.errors = errors2;
|
|
8507
|
+
})
|
|
8508
|
+
);
|
|
8509
|
+
if (!meta.validated) {
|
|
8510
|
+
setMeta(
|
|
8511
|
+
immer$1.produce((draft) => {
|
|
8512
|
+
draft.validated = true;
|
|
8513
|
+
})
|
|
8514
|
+
);
|
|
8515
|
+
}
|
|
8516
|
+
}
|
|
8277
8517
|
setErrors(errors2);
|
|
8278
8518
|
return reject(errors2);
|
|
8279
8519
|
}
|
|
@@ -8327,7 +8567,8 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
8327
8567
|
orderBody.child_orders = orderBody.child_orders.filter(
|
|
8328
8568
|
(order2) => order2.is_activated
|
|
8329
8569
|
);
|
|
8330
|
-
|
|
8570
|
+
const body = appendOrderMetadata(orderBody, orderMetadata);
|
|
8571
|
+
return doCreateOrder(body, {}, params);
|
|
8331
8572
|
};
|
|
8332
8573
|
const deleteOrder = (orderId, symbol) => {
|
|
8333
8574
|
return doDeleteOrder(null, {
|
|
@@ -8373,6 +8614,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
8373
8614
|
// createPositionTPSL: submit,
|
|
8374
8615
|
// createTPSL: submit,
|
|
8375
8616
|
validate,
|
|
8617
|
+
metaState: meta,
|
|
8376
8618
|
errors,
|
|
8377
8619
|
isCreateMutating,
|
|
8378
8620
|
isUpdateMutating
|
|
@@ -9150,7 +9392,12 @@ var OrderlyConfigProvider = (props) => {
|
|
|
9150
9392
|
enableSwapDeposit = false,
|
|
9151
9393
|
chainTransformer,
|
|
9152
9394
|
dataAdapter,
|
|
9153
|
-
notification
|
|
9395
|
+
notification,
|
|
9396
|
+
amplitudeConfig,
|
|
9397
|
+
orderbookDefaultTickSizes,
|
|
9398
|
+
orderbookDefaultSymbolDepths,
|
|
9399
|
+
children,
|
|
9400
|
+
orderMetadata
|
|
9154
9401
|
} = props;
|
|
9155
9402
|
if (typeof configStore !== "undefined" && !configStore.get("brokerId")) {
|
|
9156
9403
|
throw new types.SDKError(
|
|
@@ -9164,7 +9411,11 @@ var OrderlyConfigProvider = (props) => {
|
|
|
9164
9411
|
}
|
|
9165
9412
|
const innerConfigStore = React2.useMemo(() => {
|
|
9166
9413
|
return new ProxyConfigStore(
|
|
9167
|
-
configStore || new ExtendedConfigStore({
|
|
9414
|
+
configStore || new ExtendedConfigStore({
|
|
9415
|
+
brokerId,
|
|
9416
|
+
brokerName,
|
|
9417
|
+
networkId
|
|
9418
|
+
})
|
|
9168
9419
|
);
|
|
9169
9420
|
}, [configStore, brokerId, brokerName, networkId]);
|
|
9170
9421
|
const innerKeyStore = React2.useMemo(() => {
|
|
@@ -9177,8 +9428,11 @@ var OrderlyConfigProvider = (props) => {
|
|
|
9177
9428
|
];
|
|
9178
9429
|
}, [walletAdapters]);
|
|
9179
9430
|
const defaultOrderbookTickSizes = React2.useMemo(() => {
|
|
9180
|
-
return
|
|
9181
|
-
}, [
|
|
9431
|
+
return orderbookDefaultTickSizes || DEFAULT_TICK_SIZES;
|
|
9432
|
+
}, [orderbookDefaultTickSizes]);
|
|
9433
|
+
const defaultOrderbookSymbolDepths = React2.useMemo(() => {
|
|
9434
|
+
return orderbookDefaultSymbolDepths || DEFAULT_SYMBOL_DEPTHS;
|
|
9435
|
+
}, [orderbookDefaultSymbolDepths]);
|
|
9182
9436
|
React2.useLayoutEffect(() => {
|
|
9183
9437
|
let account10 = core.SimpleDI.get(core.Account.instanceName);
|
|
9184
9438
|
if (!account10) {
|
|
@@ -9200,7 +9454,7 @@ var OrderlyConfigProvider = (props) => {
|
|
|
9200
9454
|
return chainFilter(innerConfigStore);
|
|
9201
9455
|
}
|
|
9202
9456
|
return chainFilter;
|
|
9203
|
-
}, [
|
|
9457
|
+
}, [chainFilter, innerConfigStore]);
|
|
9204
9458
|
const memoizedValue = React2.useMemo(() => {
|
|
9205
9459
|
return {
|
|
9206
9460
|
configStore: innerConfigStore,
|
|
@@ -9211,9 +9465,12 @@ var OrderlyConfigProvider = (props) => {
|
|
|
9211
9465
|
customChains,
|
|
9212
9466
|
enableSwapDeposit,
|
|
9213
9467
|
defaultOrderbookTickSizes,
|
|
9468
|
+
defaultOrderbookSymbolDepths,
|
|
9214
9469
|
chainTransformer,
|
|
9215
9470
|
dataAdapter,
|
|
9216
|
-
notification
|
|
9471
|
+
notification,
|
|
9472
|
+
amplitudeConfig,
|
|
9473
|
+
orderMetadata
|
|
9217
9474
|
};
|
|
9218
9475
|
}, [
|
|
9219
9476
|
innerConfigStore,
|
|
@@ -9224,14 +9481,17 @@ var OrderlyConfigProvider = (props) => {
|
|
|
9224
9481
|
customChains,
|
|
9225
9482
|
enableSwapDeposit,
|
|
9226
9483
|
defaultOrderbookTickSizes,
|
|
9484
|
+
defaultOrderbookSymbolDepths,
|
|
9227
9485
|
dataAdapter,
|
|
9228
9486
|
notification,
|
|
9229
|
-
chainTransformer
|
|
9487
|
+
chainTransformer,
|
|
9488
|
+
amplitudeConfig,
|
|
9489
|
+
orderMetadata
|
|
9230
9490
|
]);
|
|
9231
9491
|
if (!account9) {
|
|
9232
9492
|
return null;
|
|
9233
9493
|
}
|
|
9234
|
-
return /* @__PURE__ */ jsxRuntime.jsx(OrderlyProvider, { value: memoizedValue, children: /* @__PURE__ */ jsxRuntime.jsx(StatusProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(DataCenterProvider, { children
|
|
9494
|
+
return /* @__PURE__ */ jsxRuntime.jsx(OrderlyProvider, { value: memoizedValue, children: /* @__PURE__ */ jsxRuntime.jsx(StatusProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(DataCenterProvider, { children }) }) });
|
|
9235
9495
|
};
|
|
9236
9496
|
var needNumberOnlyFields = [
|
|
9237
9497
|
"order_quantity",
|
|
@@ -16187,138 +16447,6 @@ function getQueryParamsFromObject(obj) {
|
|
|
16187
16447
|
}
|
|
16188
16448
|
return queryParams.toString();
|
|
16189
16449
|
}
|
|
16190
|
-
var getCreateOrderUrl = (order) => {
|
|
16191
|
-
const isAlgoOrder = order?.order_type === types.OrderType.STOP_LIMIT || order?.order_type === types.OrderType.STOP_MARKET || order?.order_type === types.OrderType.CLOSE_POSITION || order.algo_type && order.algo_type === types.AlgoOrderRootType.BRACKET || isBracketOrder(order);
|
|
16192
|
-
if (order.order_type === types.OrderType.SCALED) {
|
|
16193
|
-
return "/v1/batch-order";
|
|
16194
|
-
}
|
|
16195
|
-
return isAlgoOrder ? "/v1/algo/order" : "/v1/order";
|
|
16196
|
-
};
|
|
16197
|
-
var getOrderCreator = (order) => {
|
|
16198
|
-
let type;
|
|
16199
|
-
if (isBracketOrder(order)) {
|
|
16200
|
-
type = `${types.AlgoOrderRootType.BRACKET}:${order.order_type}`;
|
|
16201
|
-
} else if (order.order_type === types.OrderType.LIMIT) {
|
|
16202
|
-
type = order.order_type_ext || order.order_type;
|
|
16203
|
-
} else {
|
|
16204
|
-
type = order.order_type;
|
|
16205
|
-
}
|
|
16206
|
-
return OrderFactory.create(type);
|
|
16207
|
-
};
|
|
16208
|
-
var tpslFields = [
|
|
16209
|
-
"tp_trigger_price",
|
|
16210
|
-
"sl_trigger_price",
|
|
16211
|
-
"tp_pnl",
|
|
16212
|
-
"sl_pnl",
|
|
16213
|
-
"tp_offset",
|
|
16214
|
-
"sl_offset",
|
|
16215
|
-
"tp_offset_percentage",
|
|
16216
|
-
"sl_offset_percentage"
|
|
16217
|
-
];
|
|
16218
|
-
var isBracketOrder = (order) => {
|
|
16219
|
-
if (order.sl_enable || order.tp_enable) {
|
|
16220
|
-
return true;
|
|
16221
|
-
}
|
|
16222
|
-
return !!order.tp_trigger_price || !!order.sl_trigger_price;
|
|
16223
|
-
};
|
|
16224
|
-
var hasTPSL = (order) => {
|
|
16225
|
-
return tpslFields.some((field) => !!order[field]);
|
|
16226
|
-
};
|
|
16227
|
-
var getPriceAndQty = (order, symbolInfo, askAndBid) => {
|
|
16228
|
-
let quantity = Number(order.order_quantity);
|
|
16229
|
-
const orderPrice = Number(order.order_price);
|
|
16230
|
-
if (isNaN(quantity) || quantity <= 0) {
|
|
16231
|
-
return null;
|
|
16232
|
-
}
|
|
16233
|
-
if (askAndBid.length === 0) {
|
|
16234
|
-
return null;
|
|
16235
|
-
}
|
|
16236
|
-
if ((order.order_type === types.OrderType.LIMIT || order.order_type === types.OrderType.STOP_LIMIT) && isNaN(orderPrice)) {
|
|
16237
|
-
return null;
|
|
16238
|
-
}
|
|
16239
|
-
let price;
|
|
16240
|
-
if (order.order_type === types.OrderType.SCALED) {
|
|
16241
|
-
price = calcScaledOrderAvgPrice(order, symbolInfo, askAndBid);
|
|
16242
|
-
const orders = calcScaledOrderBatchBody(order, symbolInfo);
|
|
16243
|
-
const sumQtys = orders.reduce((acc, order2) => {
|
|
16244
|
-
return acc.plus(new utils.Decimal(order2.order_quantity));
|
|
16245
|
-
}, utils.zero);
|
|
16246
|
-
quantity = sumQtys.todp(symbolInfo.base_dp).toNumber();
|
|
16247
|
-
if (!quantity || isNaN(quantity)) {
|
|
16248
|
-
return null;
|
|
16249
|
-
}
|
|
16250
|
-
} else {
|
|
16251
|
-
price = getOrderPrice(order, askAndBid);
|
|
16252
|
-
}
|
|
16253
|
-
if (!price || isNaN(price)) {
|
|
16254
|
-
return null;
|
|
16255
|
-
}
|
|
16256
|
-
if (order.side === types.OrderSide.SELL) {
|
|
16257
|
-
quantity = -quantity;
|
|
16258
|
-
}
|
|
16259
|
-
return { price, quantity };
|
|
16260
|
-
};
|
|
16261
|
-
var calcEstLiqPrice = (order, askAndBid, inputs) => {
|
|
16262
|
-
const { symbolInfo } = inputs;
|
|
16263
|
-
const result = getPriceAndQty(order, symbolInfo, askAndBid);
|
|
16264
|
-
if (!result)
|
|
16265
|
-
return null;
|
|
16266
|
-
const { price, quantity } = result;
|
|
16267
|
-
if (!price || !quantity)
|
|
16268
|
-
return null;
|
|
16269
|
-
const {
|
|
16270
|
-
symbol,
|
|
16271
|
-
imr_factor,
|
|
16272
|
-
markPrice,
|
|
16273
|
-
totalCollateral,
|
|
16274
|
-
futures_taker_fee_rate,
|
|
16275
|
-
positions: positions3
|
|
16276
|
-
} = inputs;
|
|
16277
|
-
const orderFee = perp.order.orderFee({
|
|
16278
|
-
qty: quantity,
|
|
16279
|
-
price,
|
|
16280
|
-
futuresTakeFeeRate: Number(futures_taker_fee_rate) / 1e4
|
|
16281
|
-
});
|
|
16282
|
-
const liqPrice = perp.order.estLiqPrice({
|
|
16283
|
-
markPrice,
|
|
16284
|
-
baseIMR: symbolInfo.base_imr,
|
|
16285
|
-
baseMMR: symbolInfo.base_mmr,
|
|
16286
|
-
totalCollateral,
|
|
16287
|
-
positions: positions3 == null ? [] : positions3,
|
|
16288
|
-
IMR_Factor: imr_factor,
|
|
16289
|
-
orderFee,
|
|
16290
|
-
newOrder: {
|
|
16291
|
-
qty: quantity,
|
|
16292
|
-
price,
|
|
16293
|
-
symbol
|
|
16294
|
-
}
|
|
16295
|
-
});
|
|
16296
|
-
if (liqPrice <= 0)
|
|
16297
|
-
return null;
|
|
16298
|
-
return liqPrice;
|
|
16299
|
-
};
|
|
16300
|
-
var calcEstLeverage = (order, askAndBid, inputs) => {
|
|
16301
|
-
const { totalCollateral, positions: positions3, symbol, symbolInfo } = inputs;
|
|
16302
|
-
const result = getPriceAndQty(order, symbolInfo, askAndBid);
|
|
16303
|
-
if (!result)
|
|
16304
|
-
return null;
|
|
16305
|
-
const { price, quantity } = result;
|
|
16306
|
-
if (!price || !quantity)
|
|
16307
|
-
return null;
|
|
16308
|
-
return perp.order.estLeverage({
|
|
16309
|
-
totalCollateral,
|
|
16310
|
-
positions: positions3,
|
|
16311
|
-
newOrder: {
|
|
16312
|
-
symbol,
|
|
16313
|
-
qty: result.quantity,
|
|
16314
|
-
price: result.price
|
|
16315
|
-
}
|
|
16316
|
-
});
|
|
16317
|
-
};
|
|
16318
|
-
function isBBOOrder(options) {
|
|
16319
|
-
const { order_type, order_type_ext } = options;
|
|
16320
|
-
return order_type === types.OrderType.LIMIT && [types.OrderType.ASK, types.OrderType.BID].includes(order_type_ext);
|
|
16321
|
-
}
|
|
16322
16450
|
var initialOrderState = {
|
|
16323
16451
|
order_price: "",
|
|
16324
16452
|
order_quantity: "",
|
|
@@ -16631,6 +16759,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
16631
16759
|
const positions3 = usePositions();
|
|
16632
16760
|
const symbolInfo = symbolConfig[symbol]();
|
|
16633
16761
|
const markPrice = actions.getMarkPriceBySymbol(symbol);
|
|
16762
|
+
const { orderMetadata } = useOrderlyContext();
|
|
16634
16763
|
const {
|
|
16635
16764
|
formattedOrder,
|
|
16636
16765
|
setValue: setValueInternal,
|
|
@@ -16946,7 +17075,9 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
16946
17075
|
}
|
|
16947
17076
|
const order = generateOrder(creator, prepareData());
|
|
16948
17077
|
const isScaledOrder = order.order_type === types.OrderType.SCALED;
|
|
16949
|
-
const params = isScaledOrder ? {
|
|
17078
|
+
const params = isScaledOrder ? {
|
|
17079
|
+
orders: appendOrderMetadata(order.orders, orderMetadata)
|
|
17080
|
+
} : appendOrderMetadata(order, orderMetadata);
|
|
16950
17081
|
const result = await doCreateOrder(params);
|
|
16951
17082
|
if (result.success) {
|
|
16952
17083
|
let trackParams = {
|
|
@@ -17247,6 +17378,7 @@ var usePositionClose = (options) => {
|
|
|
17247
17378
|
const symbolsInfo = useSymbolsInfo();
|
|
17248
17379
|
const { data: markPrices } = useMarkPricesStream();
|
|
17249
17380
|
const markPricesRef = React2.useRef(markPrices);
|
|
17381
|
+
const { orderMetadata } = useOrderlyContext();
|
|
17250
17382
|
React2.useEffect(() => {
|
|
17251
17383
|
markPricesRef.current = markPrices;
|
|
17252
17384
|
}, [markPrices]);
|
|
@@ -17315,7 +17447,8 @@ var usePositionClose = (options) => {
|
|
|
17315
17447
|
if (Object.keys(errors2).length > 0) {
|
|
17316
17448
|
throw errors2;
|
|
17317
17449
|
}
|
|
17318
|
-
|
|
17450
|
+
const body = appendOrderMetadata(closeOrderData, orderMetadata);
|
|
17451
|
+
return doCreateOrder(body).then((res) => {
|
|
17319
17452
|
if (res.success) {
|
|
17320
17453
|
return res;
|
|
17321
17454
|
}
|
|
@@ -17323,7 +17456,7 @@ var usePositionClose = (options) => {
|
|
|
17323
17456
|
}).catch((err) => {
|
|
17324
17457
|
throw err;
|
|
17325
17458
|
});
|
|
17326
|
-
}, [validate, doCreateOrder, closeOrderData]);
|
|
17459
|
+
}, [validate, doCreateOrder, closeOrderData, orderMetadata]);
|
|
17327
17460
|
return {
|
|
17328
17461
|
submit,
|
|
17329
17462
|
isMutating,
|
|
@@ -17359,6 +17492,7 @@ exports.ExtendedConfigStore = ExtendedConfigStore;
|
|
|
17359
17492
|
exports.MaintenanceStatus = MaintenanceStatus;
|
|
17360
17493
|
exports.MarketsStorageKey = MarketsStorageKey;
|
|
17361
17494
|
exports.MarketsType = MarketsType;
|
|
17495
|
+
exports.ORDERLY_ORDERBOOK_DEPTH_KEY = ORDERLY_ORDERBOOK_DEPTH_KEY;
|
|
17362
17496
|
exports.OrderlyConfigProvider = OrderlyConfigProvider;
|
|
17363
17497
|
exports.OrderlyContext = OrderlyContext;
|
|
17364
17498
|
exports.OrderlyProvider = OrderlyProvider;
|
|
@@ -17373,6 +17507,7 @@ exports.findPositionTPSLFromOrders = findPositionTPSLFromOrders;
|
|
|
17373
17507
|
exports.findTPSLFromOrder = findTPSLFromOrder;
|
|
17374
17508
|
exports.findTPSLOrderPriceFromOrder = findTPSLOrderPriceFromOrder;
|
|
17375
17509
|
exports.getMinNotional = getMinNotional;
|
|
17510
|
+
exports.getPriceKey = getPriceKey;
|
|
17376
17511
|
exports.parseJSON = parseJSON;
|
|
17377
17512
|
exports.useAccount = useAccount;
|
|
17378
17513
|
exports.useAccountInfo = useAccountInfo2;
|