@orderly.network/hooks 0.0.84 → 0.0.85

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.mjs CHANGED
@@ -1028,7 +1028,6 @@ var parseHolding = (holding, markPrices) => {
1028
1028
  };
1029
1029
  var usePositionStream = (symbol, options) => {
1030
1030
  const symbolInfo = useSymbolsInfo();
1031
- useEventEmitter();
1032
1031
  const { data: accountInfo } = usePrivateQuery("/v1/client/info");
1033
1032
  const { data: holding } = usePrivateQuery(
1034
1033
  "/v1/client/holding",
@@ -1068,12 +1067,27 @@ var usePositionStream = (symbol, options) => {
1068
1067
  item.symbol,
1069
1068
  markPrices
1070
1069
  );
1070
+ const info = symbolInfo?.[item.symbol];
1071
1071
  const notional = positions.notional(item.position_qty, price);
1072
1072
  const unrealPnl = positions.unrealizedPnL({
1073
1073
  qty: item.position_qty,
1074
1074
  openPrice: item.average_open_price,
1075
1075
  markPrice: price
1076
1076
  });
1077
+ const imr = account.IMR({
1078
+ maxLeverage: accountInfo.max_leverage,
1079
+ baseIMR: info("base_imr"),
1080
+ IMR_Factor: accountInfo.imr_factor[item.symbol],
1081
+ positionNotional: notional,
1082
+ ordersNotional: 0,
1083
+ IMR_factor_power: 4 / 5
1084
+ });
1085
+ const unrealPnlROI = positions.unrealizedPnLROI({
1086
+ positionQty: item.position_qty,
1087
+ openPrice: item.average_open_price,
1088
+ IMR: imr,
1089
+ unrealizedPnL: unrealPnl
1090
+ });
1077
1091
  const unsettlementPnL = positions.unsettlementPnL({
1078
1092
  positionQty: item.position_qty,
1079
1093
  markPrice: price,
@@ -1093,7 +1107,8 @@ var usePositionStream = (symbol, options) => {
1093
1107
  mm: 0,
1094
1108
  notional,
1095
1109
  unsettlement_pnl: unsettlementPnL,
1096
- unrealized_pnl: unrealPnl
1110
+ unrealized_pnl: unrealPnl,
1111
+ unsettled_pnl_ROI: unrealPnlROI
1097
1112
  };
1098
1113
  });
1099
1114
  return [
@@ -1448,7 +1463,7 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1448
1463
  }
1449
1464
  validate(values, config) {
1450
1465
  return this.baseValidate(values, config).then((errors) => {
1451
- const { order_price } = values;
1466
+ const { order_price, side } = values;
1452
1467
  if (!order_price) {
1453
1468
  errors.order_price = {
1454
1469
  type: "required",
@@ -1460,20 +1475,21 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1460
1475
  const { price_range } = symbol;
1461
1476
  const maxPriceNumber = maxPrice(config.markPrice, price_range);
1462
1477
  const minPriceNumber = minPrice(config.markPrice, price_range);
1463
- if (price.lt(minPriceNumber)) {
1464
- errors.order_price = {
1465
- type: "min",
1466
- message: `price must be greater than ${new Decimal(
1467
- minPriceNumber
1468
- ).todp(symbol.quote_dp)}`
1469
- };
1470
- } else if (price.gt(maxPriceNumber)) {
1478
+ console.log(`side: ${side} value:`, values);
1479
+ if (side === "BUY" && price.gt(maxPriceNumber)) {
1471
1480
  errors.order_price = {
1472
1481
  type: "max",
1473
1482
  message: `price must be less than ${new Decimal(
1474
1483
  maxPriceNumber
1475
1484
  ).todp(symbol.quote_dp)}`
1476
1485
  };
1486
+ } else if (side === "SELL" && price.lt(minPriceNumber)) {
1487
+ errors.order_price = {
1488
+ type: "min",
1489
+ message: `price must be greater than ${new Decimal(
1490
+ minPriceNumber
1491
+ ).todp(symbol.quote_dp)}`
1492
+ };
1477
1493
  }
1478
1494
  }
1479
1495
  return errors;