@orderly.network/ui-positions 2.8.9-alpha.0 → 2.8.10-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
@@ -195,6 +195,7 @@ interface UseReversePositionScriptOptions {
195
195
  position: API.PositionExt | API.PositionTPSLExt;
196
196
  onSuccess?: () => void;
197
197
  onError?: (error: any) => void;
198
+ calcMode?: "markPrice" | "lastPrice";
198
199
  }
199
200
  type ReversePositionValidationError = "belowMin" | null;
200
201
  /**
@@ -221,6 +222,8 @@ declare const useReversePositionScript: (options?: UseReversePositionScriptOptio
221
222
  markPrice: string;
222
223
  leverage: number;
223
224
  isLong: boolean;
225
+ unrealizedPnL: number | undefined;
226
+ pnlNotionalDecimalPrecision: any;
224
227
  } | null;
225
228
  positionQty: number;
226
229
  reverseQty: number;
@@ -269,6 +272,10 @@ interface OrderInfoCardProps {
269
272
  baseDp: number;
270
273
  /** Price label, defaults to "Market" */
271
274
  estLiqPrice?: React.ReactNode;
275
+ /** Estimated PnL value */
276
+ estPnL?: string;
277
+ /** PnL decimal precision */
278
+ pnlNotionalDecimalPrecision?: number;
272
279
  /** Custom class name */
273
280
  className?: string;
274
281
  }
package/dist/index.d.ts CHANGED
@@ -195,6 +195,7 @@ interface UseReversePositionScriptOptions {
195
195
  position: API.PositionExt | API.PositionTPSLExt;
196
196
  onSuccess?: () => void;
197
197
  onError?: (error: any) => void;
198
+ calcMode?: "markPrice" | "lastPrice";
198
199
  }
199
200
  type ReversePositionValidationError = "belowMin" | null;
200
201
  /**
@@ -221,6 +222,8 @@ declare const useReversePositionScript: (options?: UseReversePositionScriptOptio
221
222
  markPrice: string;
222
223
  leverage: number;
223
224
  isLong: boolean;
225
+ unrealizedPnL: number | undefined;
226
+ pnlNotionalDecimalPrecision: any;
224
227
  } | null;
225
228
  positionQty: number;
226
229
  reverseQty: number;
@@ -269,6 +272,10 @@ interface OrderInfoCardProps {
269
272
  baseDp: number;
270
273
  /** Price label, defaults to "Market" */
271
274
  estLiqPrice?: React.ReactNode;
275
+ /** Estimated PnL value */
276
+ estPnL?: string;
277
+ /** PnL decimal precision */
278
+ pnlNotionalDecimalPrecision?: number;
272
279
  /** Custom class name */
273
280
  className?: string;
274
281
  }
package/dist/index.js CHANGED
@@ -901,6 +901,7 @@ var groupDataByAccount = (data, options) => {
901
901
 
902
902
  // src/constants.ts
903
903
  var TRADING_POSITIONS_SORT_STORAGE_KEY = "orderly_trading_positions_sort";
904
+ var LIQ_DISTANCE_THRESHOLD = 10;
904
905
  var compareValues = (aValue, bValue) => {
905
906
  if (aValue == null && bValue == null)
906
907
  return 0;
@@ -969,6 +970,8 @@ var OrderInfoCard = ({
969
970
  qty,
970
971
  baseDp,
971
972
  estLiqPrice,
973
+ estPnL,
974
+ pnlNotionalDecimalPrecision = 2,
972
975
  className
973
976
  }) => {
974
977
  const { t } = i18n.useTranslation();
@@ -997,6 +1000,7 @@ var OrderInfoCard = ({
997
1000
  justify: "between",
998
1001
  itemAlign: "center",
999
1002
  width: "100%",
1003
+ gap: 1,
1000
1004
  children: [
1001
1005
  /* @__PURE__ */ jsxRuntime.jsxs(
1002
1006
  ui.Flex,
@@ -1026,6 +1030,29 @@ var OrderInfoCard = ({
1026
1030
  ]
1027
1031
  }
1028
1032
  ),
1033
+ estPnL && /* @__PURE__ */ jsxRuntime.jsxs(
1034
+ ui.Flex,
1035
+ {
1036
+ direction: "row",
1037
+ justify: "between",
1038
+ itemAlign: "center",
1039
+ width: "100%",
1040
+ gap: 1,
1041
+ children: [
1042
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "sm", intensity: 54, children: t("orderEntry.estPnL") }),
1043
+ /* @__PURE__ */ jsxRuntime.jsx(
1044
+ ui.Text.pnl,
1045
+ {
1046
+ dp: pnlNotionalDecimalPrecision,
1047
+ coloring: true,
1048
+ size: "sm",
1049
+ weight: "semibold",
1050
+ children: estPnL
1051
+ }
1052
+ )
1053
+ ]
1054
+ }
1055
+ ),
1029
1056
  estLiqPrice && /* @__PURE__ */ jsxRuntime.jsxs(
1030
1057
  ui.Flex,
1031
1058
  {
@@ -1070,7 +1097,9 @@ var ReversePosition = (props) => {
1070
1097
  reverseQty,
1071
1098
  markPrice,
1072
1099
  leverage,
1073
- isLong
1100
+ isLong,
1101
+ unrealizedPnL,
1102
+ pnlNotionalDecimalPrecision
1074
1103
  } = displayInfo;
1075
1104
  const closeSide = !isLong ? types.OrderSide.SELL : types.OrderSide.BUY;
1076
1105
  const openSide = isLong ? types.OrderSide.SELL : types.OrderSide.BUY;
@@ -1121,7 +1150,9 @@ var ReversePosition = (props) => {
1121
1150
  side: closeSide,
1122
1151
  leverage,
1123
1152
  qty: positionQty,
1124
- baseDp
1153
+ baseDp,
1154
+ estPnL: unrealizedPnL?.toString(),
1155
+ pnlNotionalDecimalPrecision
1125
1156
  }
1126
1157
  ),
1127
1158
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "row", itemAlign: "center", width: "100%", children: [
@@ -1185,10 +1216,28 @@ var useReversePositionEnabled = () => {
1185
1216
  var useReversePositionScript = (options) => {
1186
1217
  const { position, onSuccess, onError } = options || {};
1187
1218
  const { isEnabled, setEnabled } = useReversePositionEnabled();
1219
+ const [pnlNotionalDecimalPrecision] = hooks.useLocalStorage(
1220
+ "pnlNotionalDecimalPrecision",
1221
+ 2
1222
+ );
1188
1223
  const symbolsInfo = hooks.useSymbolsInfo();
1189
1224
  const symbol = position?.symbol || "";
1190
1225
  const { data: symbolMarketPrice } = hooks.useMarkPrice(symbol);
1191
1226
  const symbolInfo = symbolsInfo?.[symbol];
1227
+ const calcMode = options?.calcMode || "markPrice";
1228
+ const [positionData] = hooks.usePositionStream(symbol, {
1229
+ calcMode,
1230
+ includedPendingOrder: false
1231
+ });
1232
+ const rawPositionRows = reactApp.useDataTap(positionData?.rows, { fallbackData: [] });
1233
+ const unrealizedPnL = React2.useMemo(() => {
1234
+ if (!rawPositionRows || !symbol)
1235
+ return position?.unrealized_pnl;
1236
+ const currentPosition = rawPositionRows.find(
1237
+ (p) => p.symbol === symbol && p.position_qty !== 0
1238
+ );
1239
+ return currentPosition?.unrealized_pnl ?? position?.unrealized_pnl;
1240
+ }, [rawPositionRows, symbol]);
1192
1241
  const baseMin = React2.useMemo(() => {
1193
1242
  if (!symbolInfo)
1194
1243
  return 0;
@@ -1347,7 +1396,9 @@ var useReversePositionScript = (options) => {
1347
1396
  reverseQty: new utils.Decimal(reverseQty).todp(baseDp2).toString(),
1348
1397
  markPrice: symbolMarketPrice ? new utils.Decimal(symbolMarketPrice).todp(quoteDp).toString() : "--",
1349
1398
  leverage,
1350
- isLong
1399
+ isLong,
1400
+ unrealizedPnL,
1401
+ pnlNotionalDecimalPrecision
1351
1402
  };
1352
1403
  }, [
1353
1404
  position,
@@ -1355,7 +1406,9 @@ var useReversePositionScript = (options) => {
1355
1406
  symbolInfo,
1356
1407
  positionQty,
1357
1408
  reverseQty,
1358
- isLong
1409
+ isLong,
1410
+ unrealizedPnL,
1411
+ pnlNotionalDecimalPrecision
1359
1412
  ]);
1360
1413
  return {
1361
1414
  isEnabled,
@@ -2884,12 +2937,17 @@ var useColumn = (config) => {
2884
2937
  width: 100,
2885
2938
  onSort: true,
2886
2939
  dataIndex: "est_liq_price",
2887
- render: (value) => {
2888
- return Number(value) === 0 ? "--" : /* @__PURE__ */ jsxRuntime.jsx(
2940
+ render: (value, record) => {
2941
+ const liqPrice = Number(value);
2942
+ const markPrice = record.mark_price;
2943
+ if (liqPrice === 0 || !markPrice || markPrice === 0 || Math.abs(liqPrice - markPrice) / markPrice >= LIQ_DISTANCE_THRESHOLD) {
2944
+ return "--";
2945
+ }
2946
+ return /* @__PURE__ */ jsxRuntime.jsx(
2889
2947
  NumeralWithCtx,
2890
2948
  {
2891
2949
  rm: utils.Decimal.ROUND_DOWN,
2892
- className: Number(value) > 0 ? "oui-text-warning-light" : "",
2950
+ className: liqPrice > 0 ? "oui-text-warning-light" : "",
2893
2951
  children: value ?? "--"
2894
2952
  }
2895
2953
  );
@@ -3218,7 +3276,18 @@ var MarkPrice = (props) => {
3218
3276
  var LiqPrice = (props) => {
3219
3277
  const { item } = props;
3220
3278
  const { t } = i18n.useTranslation();
3221
- const liqPrice = item.est_liq_price && item.est_liq_price > 0 ? item.est_liq_price : "-";
3279
+ const liqPrice = React2.useMemo(() => {
3280
+ const estLiqPrice = item.est_liq_price;
3281
+ const markPrice = item.mark_price;
3282
+ if (!estLiqPrice || estLiqPrice <= 0)
3283
+ return "-";
3284
+ if (!markPrice || markPrice === 0)
3285
+ return "-";
3286
+ if (Math.abs(estLiqPrice - markPrice) / markPrice >= LIQ_DISTANCE_THRESHOLD) {
3287
+ return "-";
3288
+ }
3289
+ return estLiqPrice;
3290
+ }, [item.est_liq_price, item.mark_price]);
3222
3291
  return /* @__PURE__ */ jsxRuntime.jsx(
3223
3292
  ui.Statistic,
3224
3293
  {