@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.js CHANGED
@@ -1037,7 +1037,6 @@ var parseHolding = (holding, markPrices) => {
1037
1037
  };
1038
1038
  var usePositionStream = (symbol, options) => {
1039
1039
  const symbolInfo = useSymbolsInfo();
1040
- useEventEmitter();
1041
1040
  const { data: accountInfo } = usePrivateQuery("/v1/client/info");
1042
1041
  const { data: holding } = usePrivateQuery(
1043
1042
  "/v1/client/holding",
@@ -1077,12 +1076,27 @@ var usePositionStream = (symbol, options) => {
1077
1076
  item.symbol,
1078
1077
  markPrices
1079
1078
  );
1079
+ const info = symbolInfo?.[item.symbol];
1080
1080
  const notional = futures.positions.notional(item.position_qty, price);
1081
1081
  const unrealPnl = futures.positions.unrealizedPnL({
1082
1082
  qty: item.position_qty,
1083
1083
  openPrice: item.average_open_price,
1084
1084
  markPrice: price
1085
1085
  });
1086
+ const imr = futures.account.IMR({
1087
+ maxLeverage: accountInfo.max_leverage,
1088
+ baseIMR: info("base_imr"),
1089
+ IMR_Factor: accountInfo.imr_factor[item.symbol],
1090
+ positionNotional: notional,
1091
+ ordersNotional: 0,
1092
+ IMR_factor_power: 4 / 5
1093
+ });
1094
+ const unrealPnlROI = futures.positions.unrealizedPnLROI({
1095
+ positionQty: item.position_qty,
1096
+ openPrice: item.average_open_price,
1097
+ IMR: imr,
1098
+ unrealizedPnL: unrealPnl
1099
+ });
1086
1100
  const unsettlementPnL = futures.positions.unsettlementPnL({
1087
1101
  positionQty: item.position_qty,
1088
1102
  markPrice: price,
@@ -1102,7 +1116,8 @@ var usePositionStream = (symbol, options) => {
1102
1116
  mm: 0,
1103
1117
  notional,
1104
1118
  unsettlement_pnl: unsettlementPnL,
1105
- unrealized_pnl: unrealPnl
1119
+ unrealized_pnl: unrealPnl,
1120
+ unsettled_pnl_ROI: unrealPnlROI
1106
1121
  };
1107
1122
  });
1108
1123
  return [
@@ -1457,7 +1472,7 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1457
1472
  }
1458
1473
  validate(values, config) {
1459
1474
  return this.baseValidate(values, config).then((errors) => {
1460
- const { order_price } = values;
1475
+ const { order_price, side } = values;
1461
1476
  if (!order_price) {
1462
1477
  errors.order_price = {
1463
1478
  type: "required",
@@ -1469,20 +1484,21 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1469
1484
  const { price_range } = symbol;
1470
1485
  const maxPriceNumber = maxPrice(config.markPrice, price_range);
1471
1486
  const minPriceNumber = minPrice(config.markPrice, price_range);
1472
- if (price.lt(minPriceNumber)) {
1473
- errors.order_price = {
1474
- type: "min",
1475
- message: `price must be greater than ${new utils.Decimal(
1476
- minPriceNumber
1477
- ).todp(symbol.quote_dp)}`
1478
- };
1479
- } else if (price.gt(maxPriceNumber)) {
1487
+ console.log(`side: ${side} value:`, values);
1488
+ if (side === "BUY" && price.gt(maxPriceNumber)) {
1480
1489
  errors.order_price = {
1481
1490
  type: "max",
1482
1491
  message: `price must be less than ${new utils.Decimal(
1483
1492
  maxPriceNumber
1484
1493
  ).todp(symbol.quote_dp)}`
1485
1494
  };
1495
+ } else if (side === "SELL" && price.lt(minPriceNumber)) {
1496
+ errors.order_price = {
1497
+ type: "min",
1498
+ message: `price must be greater than ${new utils.Decimal(
1499
+ minPriceNumber
1500
+ ).todp(symbol.quote_dp)}`
1501
+ };
1486
1502
  }
1487
1503
  }
1488
1504
  return errors;