@orderly.network/ui-tpsl 2.10.2-alpha.0 → 2.11.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -72,6 +72,7 @@ declare const useTPSLBuilder: (options: TPSLBuilderOptions$1 & PropsWithTriggerP
72
72
  validated: boolean;
73
73
  errors: {
74
74
  symbol?: _orderly_network_hooks.OrderValidationItem | undefined;
75
+ margin_mode?: _orderly_network_hooks.OrderValidationItem | undefined;
75
76
  order_type_ext?: _orderly_network_hooks.OrderValidationItem | undefined;
76
77
  order_price?: _orderly_network_hooks.OrderValidationItem | undefined;
77
78
  order_quantity?: _orderly_network_hooks.OrderValidationItem | undefined;
@@ -121,6 +122,7 @@ declare const useTPSLBuilder: (options: TPSLBuilderOptions$1 & PropsWithTriggerP
121
122
  };
122
123
  readonly errors: {
123
124
  symbol?: _orderly_network_hooks.OrderValidationItem | undefined;
125
+ margin_mode?: _orderly_network_hooks.OrderValidationItem | undefined;
124
126
  order_type_ext?: _orderly_network_hooks.OrderValidationItem | undefined;
125
127
  order_price?: _orderly_network_hooks.OrderValidationItem | undefined;
126
128
  order_quantity?: _orderly_network_hooks.OrderValidationItem | undefined;
@@ -236,7 +238,7 @@ declare const useTPSLAdvanced: (props: Props$3) => {
236
238
  slPriceError: OrderValidationResult | null;
237
239
  estLiqPrice: number | null;
238
240
  estLiqPriceDistance: number | null;
239
- setValue: (key: "symbol" | "type" | "order_type" | "order_type_ext" | "order_price" | "order_quantity" | "order_amount" | "visible_quantity" | "side" | "reduce_only" | "slippage" | "order_tag" | "level" | "post_only_adjust" | "client_order_id" | "total" | "start_price" | "end_price" | "total_orders" | "distribution_type" | "skew" | "activated_price" | "callback_value" | "callback_rate" | "quantity" | "price" | "algo_type" | "trigger_price_type" | "trigger_price" | "child_orders" | "position_type" | "tp_pnl" | "tp_offset" | "tp_offset_percentage" | "tp_ROI" | "tp_trigger_price" | "tp_order_price" | "tp_order_type" | "sl_pnl" | "sl_offset" | "sl_offset_percentage" | "sl_ROI" | "sl_trigger_price" | "sl_order_price" | "sl_order_type", value: any, options?: {
241
+ setValue: (key: "symbol" | "type" | "order_type" | "margin_mode" | "order_type_ext" | "order_price" | "order_quantity" | "order_amount" | "visible_quantity" | "side" | "reduce_only" | "slippage" | "order_tag" | "level" | "post_only_adjust" | "client_order_id" | "total" | "start_price" | "end_price" | "total_orders" | "distribution_type" | "skew" | "activated_price" | "callback_value" | "callback_rate" | "quantity" | "price" | "algo_type" | "trigger_price_type" | "trigger_price" | "child_orders" | "position_type" | "tp_pnl" | "tp_offset" | "tp_offset_percentage" | "tp_ROI" | "tp_trigger_price" | "tp_order_price" | "tp_order_type" | "sl_pnl" | "sl_offset" | "sl_offset_percentage" | "sl_ROI" | "sl_trigger_price" | "sl_order_price" | "sl_order_type", value: any, options?: {
240
242
  shouldUpdateLastChangedField?: boolean;
241
243
  }) => void;
242
244
  setValues: (values: Partial<OrderlyOrder>) => void;
@@ -312,6 +314,7 @@ declare const useTPSLSimpleDialog: (options: TPSLBuilderOptions) => {
312
314
  readonly onSubmit: () => Promise<boolean | undefined>;
313
315
  readonly errors: {
314
316
  symbol?: _orderly_network_hooks.OrderValidationItem | undefined;
317
+ margin_mode?: _orderly_network_hooks.OrderValidationItem | undefined;
315
318
  order_type_ext?: _orderly_network_hooks.OrderValidationItem | undefined;
316
319
  order_price?: _orderly_network_hooks.OrderValidationItem | undefined;
317
320
  order_quantity?: _orderly_network_hooks.OrderValidationItem | undefined;
@@ -362,7 +365,7 @@ declare const useTPSLSimpleDialog: (options: TPSLBuilderOptions) => {
362
365
  readonly isCreateMutating: boolean;
363
366
  readonly isUpdateMutating: boolean;
364
367
  };
365
- readonly position: API.PositionTPSLExt;
368
+ readonly position: API.PositionTPSLExt | undefined;
366
369
  readonly setValues: (values: Partial<ComputedAlgoOrder>) => void;
367
370
  readonly type: "tp" | "sl";
368
371
  readonly triggerPrice: number | undefined;
package/dist/index.d.ts CHANGED
@@ -72,6 +72,7 @@ declare const useTPSLBuilder: (options: TPSLBuilderOptions$1 & PropsWithTriggerP
72
72
  validated: boolean;
73
73
  errors: {
74
74
  symbol?: _orderly_network_hooks.OrderValidationItem | undefined;
75
+ margin_mode?: _orderly_network_hooks.OrderValidationItem | undefined;
75
76
  order_type_ext?: _orderly_network_hooks.OrderValidationItem | undefined;
76
77
  order_price?: _orderly_network_hooks.OrderValidationItem | undefined;
77
78
  order_quantity?: _orderly_network_hooks.OrderValidationItem | undefined;
@@ -121,6 +122,7 @@ declare const useTPSLBuilder: (options: TPSLBuilderOptions$1 & PropsWithTriggerP
121
122
  };
122
123
  readonly errors: {
123
124
  symbol?: _orderly_network_hooks.OrderValidationItem | undefined;
125
+ margin_mode?: _orderly_network_hooks.OrderValidationItem | undefined;
124
126
  order_type_ext?: _orderly_network_hooks.OrderValidationItem | undefined;
125
127
  order_price?: _orderly_network_hooks.OrderValidationItem | undefined;
126
128
  order_quantity?: _orderly_network_hooks.OrderValidationItem | undefined;
@@ -236,7 +238,7 @@ declare const useTPSLAdvanced: (props: Props$3) => {
236
238
  slPriceError: OrderValidationResult | null;
237
239
  estLiqPrice: number | null;
238
240
  estLiqPriceDistance: number | null;
239
- setValue: (key: "symbol" | "type" | "order_type" | "order_type_ext" | "order_price" | "order_quantity" | "order_amount" | "visible_quantity" | "side" | "reduce_only" | "slippage" | "order_tag" | "level" | "post_only_adjust" | "client_order_id" | "total" | "start_price" | "end_price" | "total_orders" | "distribution_type" | "skew" | "activated_price" | "callback_value" | "callback_rate" | "quantity" | "price" | "algo_type" | "trigger_price_type" | "trigger_price" | "child_orders" | "position_type" | "tp_pnl" | "tp_offset" | "tp_offset_percentage" | "tp_ROI" | "tp_trigger_price" | "tp_order_price" | "tp_order_type" | "sl_pnl" | "sl_offset" | "sl_offset_percentage" | "sl_ROI" | "sl_trigger_price" | "sl_order_price" | "sl_order_type", value: any, options?: {
241
+ setValue: (key: "symbol" | "type" | "order_type" | "margin_mode" | "order_type_ext" | "order_price" | "order_quantity" | "order_amount" | "visible_quantity" | "side" | "reduce_only" | "slippage" | "order_tag" | "level" | "post_only_adjust" | "client_order_id" | "total" | "start_price" | "end_price" | "total_orders" | "distribution_type" | "skew" | "activated_price" | "callback_value" | "callback_rate" | "quantity" | "price" | "algo_type" | "trigger_price_type" | "trigger_price" | "child_orders" | "position_type" | "tp_pnl" | "tp_offset" | "tp_offset_percentage" | "tp_ROI" | "tp_trigger_price" | "tp_order_price" | "tp_order_type" | "sl_pnl" | "sl_offset" | "sl_offset_percentage" | "sl_ROI" | "sl_trigger_price" | "sl_order_price" | "sl_order_type", value: any, options?: {
240
242
  shouldUpdateLastChangedField?: boolean;
241
243
  }) => void;
242
244
  setValues: (values: Partial<OrderlyOrder>) => void;
@@ -312,6 +314,7 @@ declare const useTPSLSimpleDialog: (options: TPSLBuilderOptions) => {
312
314
  readonly onSubmit: () => Promise<boolean | undefined>;
313
315
  readonly errors: {
314
316
  symbol?: _orderly_network_hooks.OrderValidationItem | undefined;
317
+ margin_mode?: _orderly_network_hooks.OrderValidationItem | undefined;
315
318
  order_type_ext?: _orderly_network_hooks.OrderValidationItem | undefined;
316
319
  order_price?: _orderly_network_hooks.OrderValidationItem | undefined;
317
320
  order_quantity?: _orderly_network_hooks.OrderValidationItem | undefined;
@@ -362,7 +365,7 @@ declare const useTPSLSimpleDialog: (options: TPSLBuilderOptions) => {
362
365
  readonly isCreateMutating: boolean;
363
366
  readonly isUpdateMutating: boolean;
364
367
  };
365
- readonly position: API.PositionTPSLExt;
368
+ readonly position: API.PositionTPSLExt | undefined;
366
369
  readonly setValues: (values: Partial<ComputedAlgoOrder>) => void;
367
370
  readonly type: "tp" | "sl";
368
371
  readonly triggerPrice: number | undefined;
package/dist/index.js CHANGED
@@ -18,7 +18,10 @@ var OrderInfo = (props) => {
18
18
  const { symbol } = order2;
19
19
  const markPrice = hooks.useMarkPrice(symbol);
20
20
  const indexPrice = hooks.useIndexPrice(symbol);
21
- const leverage = hooks.useLeverageBySymbol(symbolLeverage ? void 0 : symbol);
21
+ const leverage = hooks.useLeverageBySymbol(
22
+ symbolLeverage ? void 0 : symbol,
23
+ props.marginMode
24
+ );
22
25
  const currentLeverage = symbolLeverage || leverage;
23
26
  return /* @__PURE__ */ jsxRuntime.jsxs(
24
27
  ui.Flex,
@@ -51,6 +54,14 @@ var OrderInfo = (props) => {
51
54
  }
52
55
  )
53
56
  ] }),
57
+ props.marginMode && /* @__PURE__ */ jsxRuntime.jsx(
58
+ ui.Text,
59
+ {
60
+ size: "2xs",
61
+ className: "oui-h-[18px] oui-rounded oui-bg-base-7 oui-px-2 oui-font-semibold oui-text-base-contrast-36",
62
+ children: ui.capitalizeFirstLetter(props.marginMode)
63
+ }
64
+ ),
54
65
  /* @__PURE__ */ jsxRuntime.jsxs(
55
66
  ui.Text,
56
67
  {
@@ -217,7 +228,8 @@ var PnlInfo = (props) => {
217
228
  var useTPSLInputRowScript = (props) => {
218
229
  const { values, side, type, rootOrderPrice } = props;
219
230
  const symbolLeverage = hooks.useLeverageBySymbol(
220
- props.symbolLeverage ? void 0 : props.symbol
231
+ props.symbolLeverage ? void 0 : props.symbol,
232
+ props.marginMode
221
233
  );
222
234
  const leverage = props.symbolLeverage || symbolLeverage;
223
235
  const roi = react.useMemo(() => {
@@ -948,6 +960,7 @@ var TPSL = (props) => {
948
960
  order_quantity: position.position_qty.toString(),
949
961
  order_price: position.average_open_price.toString()
950
962
  },
963
+ marginMode: position.margin_mode ?? types.MarginMode.CROSS,
951
964
  symbolLeverage: position.leverage
952
965
  }
953
966
  ),
@@ -1328,11 +1341,17 @@ var useTPSLBuilder = (options) => {
1328
1341
  const { state } = hooks.useAccount();
1329
1342
  const ee = hooks.useEventEmitter();
1330
1343
  const [needConfirm] = hooks.useLocalStorage("orderly_order_confirm", true);
1344
+ const { marginMode: symbolMarginMode } = hooks.useMarginModeBySymbol(symbol);
1331
1345
  const [{ rows: positions }] = hooks.usePositionStream();
1332
- const mainAccountPosition = positions.find((item) => item.symbol === symbol);
1346
+ const mainAccountPosition = positions.find(
1347
+ (item) => item.symbol === symbol && item.margin_mode === (options.position?.margin_mode ?? symbolMarginMode)
1348
+ );
1333
1349
  const isSubAccount = options.position?.account_id && options.position?.account_id !== state.mainAccountId;
1334
1350
  const position = isSubAccount ? options.position : mainAccountPosition;
1335
- const estLiqPrice = hooks.useEstLiqPriceBySymbol(symbol);
1351
+ const estLiqPrice = hooks.useEstLiqPriceBySymbol(
1352
+ symbol,
1353
+ position?.margin_mode ?? options.position?.margin_mode ?? types.MarginMode.CROSS
1354
+ );
1336
1355
  react.useEffect(() => {
1337
1356
  if (!position) {
1338
1357
  options.close?.();
@@ -1355,7 +1374,9 @@ var useTPSLBuilder = (options) => {
1355
1374
  {
1356
1375
  symbol,
1357
1376
  position_qty: position?.position_qty ?? 0,
1358
- average_open_price: position?.average_open_price ?? 0
1377
+ average_open_price: position?.average_open_price ?? 0,
1378
+ // Prefer options.position?.margin_mode: mainAccountPosition (from stream) often has wrong default CROSS
1379
+ margin_mode: options.position?.margin_mode ?? position?.margin_mode
1359
1380
  },
1360
1381
  {
1361
1382
  defaultOrder: order2,
@@ -1918,7 +1939,8 @@ var useTPSLAdvanced = (props) => {
1918
1939
  sl_offset_percentage: order2.sl_offset_percentage,
1919
1940
  tp_pnl: order2.tp_pnl,
1920
1941
  tp_offset: order2.tp_offset,
1921
- tp_offset_percentage: order2.tp_offset_percentage
1942
+ tp_offset_percentage: order2.tp_offset_percentage,
1943
+ margin_mode: order2.margin_mode
1922
1944
  }
1923
1945
  });
1924
1946
  const slPriceError = hooks.useTpslPriceChecker({
@@ -1969,6 +1991,7 @@ ui.registerSimpleDialog(TPSLAdvancedDialogId, TPSLAdvancedWidget, {
1969
1991
  var useTPSLDetail = (props) => {
1970
1992
  const { position } = props;
1971
1993
  const symbol = position.symbol;
1994
+ const marginMode = position.margin_mode;
1972
1995
  const symbolInfo = hooks.useSymbolsInfo()[symbol];
1973
1996
  const ee = hooks.useEventEmitter();
1974
1997
  const { state } = hooks.useAccount();
@@ -2056,11 +2079,11 @@ var useTPSLDetail = (props) => {
2056
2079
  };
2057
2080
  react.useEffect(() => {
2058
2081
  if (tpslOrders) {
2059
- const { fullPositionOrder, partialPositionOrders: partialPositionOrders2 } = hooks.findPositionTPSLFromOrders(tpslOrders, symbol);
2082
+ const { fullPositionOrder, partialPositionOrders: partialPositionOrders2 } = hooks.findPositionTPSLFromOrders(tpslOrders, symbol, marginMode);
2060
2083
  setFullPositionOrders(fullPositionOrder ? [fullPositionOrder] : []);
2061
2084
  setPartialPositionOrders(partialPositionOrders2 ?? []);
2062
2085
  }
2063
- }, [tpslOrders, symbol]);
2086
+ }, [tpslOrders, symbol, marginMode]);
2064
2087
  return {
2065
2088
  symbolInfo,
2066
2089
  position,
@@ -2077,7 +2100,10 @@ var useTPSLDetail = (props) => {
2077
2100
  var TPSLDetailContext = react.createContext({});
2078
2101
  var TPSLDetailProvider = (props) => {
2079
2102
  const symbolInfo = hooks.useSymbolsInfo()[props.symbol];
2080
- const estLiqPrice = hooks.useEstLiqPriceBySymbol(props.symbol);
2103
+ const estLiqPrice = hooks.useEstLiqPriceBySymbol(
2104
+ props.symbol,
2105
+ props.position.margin_mode ?? types.MarginMode.CROSS
2106
+ );
2081
2107
  return /* @__PURE__ */ jsxRuntime.jsx(
2082
2108
  TPSLDetailContext.Provider,
2083
2109
  {
@@ -2596,6 +2622,7 @@ var TPSLDetailUI = (props) => {
2596
2622
  /* @__PURE__ */ jsxRuntime.jsx(
2597
2623
  OrderInfo,
2598
2624
  {
2625
+ marginMode: position.margin_mode ?? types.MarginMode.CROSS,
2599
2626
  order: {
2600
2627
  symbol: position.symbol,
2601
2628
  order_quantity: position.position_qty.toString(),
@@ -2887,8 +2914,9 @@ ui.registerSimpleSheet(TPSLDetailSheetId, TPSLDetailWidget, {
2887
2914
  var useTPSLSimpleDialog = (options) => {
2888
2915
  const { type, triggerPrice, symbol } = options;
2889
2916
  const symbolInfo = hooks.useSymbolsInfo();
2917
+ const { marginMode } = hooks.useMarginModeBySymbol(symbol ?? "");
2890
2918
  const [{ rows: positions }, positionsInfo] = hooks.usePositionStream(symbol);
2891
- const position = positions?.[0];
2919
+ const position = positions?.find((item) => item.margin_mode === marginMode);
2892
2920
  react.useRef(types.AlgoOrderRootType.TP_SL);
2893
2921
  const [needConfirm] = hooks.useLocalStorage("orderly_order_confirm", true);
2894
2922
  const { t } = i18n.useTranslation();
@@ -2907,8 +2935,9 @@ var useTPSLSimpleDialog = (options) => {
2907
2935
  ] = hooks.useTPSLOrder(
2908
2936
  {
2909
2937
  symbol,
2910
- position_qty: position?.position_qty,
2911
- average_open_price: position?.average_open_price
2938
+ position_qty: position?.position_qty ?? 0,
2939
+ average_open_price: position?.average_open_price ?? 0,
2940
+ margin_mode: position?.margin_mode
2912
2941
  },
2913
2942
  {
2914
2943
  defaultOrder: void 0,
@@ -2927,8 +2956,8 @@ var useTPSLSimpleDialog = (options) => {
2927
2956
  setValue(type2, value);
2928
2957
  };
2929
2958
  const maxQty = react.useMemo(
2930
- () => Math.abs(Number(position.position_qty)),
2931
- [position.position_qty]
2959
+ () => Math.abs(Number(position?.position_qty ?? 0)),
2960
+ [position?.position_qty]
2932
2961
  );
2933
2962
  react.useEffect(() => {
2934
2963
  if (!maxQty) {
@@ -2942,6 +2971,9 @@ var useTPSLSimpleDialog = (options) => {
2942
2971
  }
2943
2972
  }, [type, triggerPrice, maxQty]);
2944
2973
  const onSubmit = async () => {
2974
+ if (!position) {
2975
+ return Promise.reject(new Error("Position is required"));
2976
+ }
2945
2977
  try {
2946
2978
  const validOrder = await validate();
2947
2979
  if (validOrder) {
@@ -3392,7 +3424,10 @@ var useEditBracketOrder = (props) => {
3392
3424
  };
3393
3425
  function useEditOrderMaxQty(order2, positionQty) {
3394
3426
  const { reduce_only } = order2;
3395
- const maxQty = hooks.useMaxQty(order2.symbol, order2.side, reduce_only);
3427
+ const maxQty = hooks.useMaxQty(order2.symbol, order2.side, {
3428
+ reduceOnly: reduce_only,
3429
+ marginMode: order2.margin_mode ?? types.MarginMode.CROSS
3430
+ });
3396
3431
  return react.useMemo(() => {
3397
3432
  if (reduce_only) {
3398
3433
  return Math.abs(positionQty ?? 0);
@@ -3533,7 +3568,8 @@ var EditBracketOrderUI = (props) => {
3533
3568
  onChange: (key, value) => {
3534
3569
  setOrderValue(key, value);
3535
3570
  },
3536
- positionType: formattedOrder.position_type ?? types.PositionType.PARTIAL
3571
+ positionType: formattedOrder.position_type ?? types.PositionType.PARTIAL,
3572
+ marginMode: formattedOrder.margin_mode
3537
3573
  }
3538
3574
  ),
3539
3575
  /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { className: "oui-w-full" }),
@@ -3561,7 +3597,8 @@ var EditBracketOrderUI = (props) => {
3561
3597
  positionType: formattedOrder.position_type ?? types.PositionType.PARTIAL,
3562
3598
  onChange: (key, value) => {
3563
3599
  setOrderValue(key, value);
3564
- }
3600
+ },
3601
+ marginMode: formattedOrder.margin_mode
3565
3602
  }
3566
3603
  )
3567
3604
  ] }),