@pear-protocol/hyperliquid-sdk 0.0.37 → 0.0.39

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.
@@ -25,6 +25,7 @@ export interface CreatePositionRequestInput {
25
25
  triggerValue?: number;
26
26
  direction?: 'MORE_THAN' | 'LESS_THAN';
27
27
  twapDuration?: number;
28
+ twapIntervalSeconds?: number;
28
29
  randomizeExecution?: boolean;
29
30
  ladderConfig?: LadderConfigInput;
30
31
  takeProfit?: TpSlThresholdInput | null;
@@ -69,6 +70,7 @@ export type CloseExecutionType = 'MARKET' | 'TWAP';
69
70
  export interface ClosePositionRequestInput {
70
71
  executionType: CloseExecutionType;
71
72
  twapDuration?: number;
73
+ twapIntervalSeconds?: number;
72
74
  randomizeExecution?: boolean;
73
75
  }
74
76
  export interface ClosePositionResponseDto {
@@ -1,6 +1,6 @@
1
- import type { ApiResponse } from '../types';
1
+ import type { ApiResponse, TwapMonitoringDto } from '../types';
2
2
  import type { CancelTwapResponseDto } from '../clients/orders';
3
3
  export declare function useTwap(): {
4
- readonly orders: any;
4
+ readonly orders: TwapMonitoringDto[];
5
5
  readonly cancelTwap: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
6
6
  };
package/dist/index.d.ts CHANGED
@@ -92,6 +92,8 @@ interface TwapMonitoringDto {
92
92
  filledUsdValue: number;
93
93
  remainingUsdValue: number;
94
94
  twapDuration: string;
95
+ twapInternalSeconds?: number | null;
96
+ twapChunkUsdValue?: number | null;
95
97
  randomizeExecution: boolean;
96
98
  reduceOnly: boolean;
97
99
  chunks: TwapChunkStatusDto[];
@@ -150,7 +152,7 @@ interface PositionAssetDetailDto {
150
152
  entryPrice: number;
151
153
  platformSize: number;
152
154
  actualSize: number;
153
- cumFunding: CumFundingDto;
155
+ leverage: number;
154
156
  marginUsed: number;
155
157
  entryPositionValue: number;
156
158
  positionValue: number;
@@ -168,12 +170,10 @@ interface TpSlThreshold {
168
170
  interface OpenPositionDto {
169
171
  positionId: string;
170
172
  address: string;
171
- leverage: number;
172
173
  stopLoss: TpSlThreshold | null;
173
174
  takeProfit: TpSlThreshold | null;
174
175
  entryRatio: number;
175
176
  markRatio: number;
176
- netFunding: number;
177
177
  entryPositionValue: number;
178
178
  positionValue: number;
179
179
  marginUsed: number;
@@ -854,6 +854,7 @@ interface CreatePositionRequestInput {
854
854
  triggerValue?: number;
855
855
  direction?: 'MORE_THAN' | 'LESS_THAN';
856
856
  twapDuration?: number;
857
+ twapIntervalSeconds?: number;
857
858
  randomizeExecution?: boolean;
858
859
  ladderConfig?: LadderConfigInput;
859
860
  takeProfit?: TpSlThresholdInput | null;
@@ -898,6 +899,7 @@ type CloseExecutionType = 'MARKET' | 'TWAP';
898
899
  interface ClosePositionRequestInput {
899
900
  executionType: CloseExecutionType;
900
901
  twapDuration?: number;
902
+ twapIntervalSeconds?: number;
901
903
  randomizeExecution?: boolean;
902
904
  }
903
905
  interface ClosePositionResponseDto {
@@ -954,7 +956,7 @@ declare function useOrders(): {
954
956
  };
955
957
 
956
958
  declare function useTwap(): {
957
- readonly orders: any;
959
+ readonly orders: TwapMonitoringDto[];
958
960
  readonly cancelTwap: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
959
961
  };
960
962
 
package/dist/index.js CHANGED
@@ -8348,74 +8348,62 @@ async function cancelTwap(baseUrl, accessToken, orderId) {
8348
8348
  }
8349
8349
  }
8350
8350
 
8351
- const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage, cumFunding, isLong = true) => {
8352
- const initialPositionValue = asset.entryPrice * asset.size;
8353
- const positionValue = currentPrice * asset.size;
8354
- const marginUsed = positionValue / leverage;
8351
+ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage, isLong = true) => {
8352
+ const entryNotional = asset.entryPrice * asset.size;
8353
+ const currentNotional = currentPrice * asset.size;
8354
+ const marginUsed = currentNotional / (leverage || 1);
8355
8355
  const unrealizedPnl = isLong
8356
- ? positionValue - initialPositionValue
8357
- : initialPositionValue - positionValue;
8356
+ ? currentNotional - entryNotional
8357
+ : entryNotional - currentNotional;
8358
8358
  return {
8359
8359
  coin: asset.coin,
8360
8360
  entryPrice: asset.entryPrice,
8361
8361
  actualSize: asset.size,
8362
+ leverage: leverage,
8362
8363
  marginUsed: marginUsed,
8363
- positionValue: positionValue,
8364
+ positionValue: currentNotional,
8364
8365
  unrealizedPnl: unrealizedPnl,
8365
- entryPositionValue: initialPositionValue,
8366
- initialWeight: initialPositionValue / totalInitialPositionSize,
8367
- cumFunding: {
8368
- allTime: parseFloat((cumFunding === null || cumFunding === void 0 ? void 0 : cumFunding.allTime) || "0"),
8369
- sinceChange: parseFloat((cumFunding === null || cumFunding === void 0 ? void 0 : cumFunding.sinceChange) || "0"),
8370
- sinceOpen: parseFloat((cumFunding === null || cumFunding === void 0 ? void 0 : cumFunding.sinceOpen) || "0"),
8371
- }
8366
+ entryPositionValue: entryNotional,
8367
+ initialWeight: totalInitialPositionSize > 0 ? entryNotional / totalInitialPositionSize : 0,
8372
8368
  };
8373
8369
  };
8374
8370
  const buildPositionValue = (rawPositions, webData2, allMids) => {
8375
8371
  return rawPositions.map((position) => {
8376
- const webData2Position = webData2.clearinghouseState.assetPositions.find(ap => {
8377
- var _a, _b, _c, _d;
8378
- const longCoin = (_b = (_a = position.longAssets) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.coin;
8379
- const shortCoin = (_d = (_c = position.shortAssets) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.coin;
8380
- return ap.position.coin === longCoin || ap.position.coin === shortCoin;
8381
- });
8382
8372
  let mappedPosition = {
8383
8373
  positionId: position.positionId,
8384
8374
  address: position.address,
8385
- leverage: webData2Position === null || webData2Position === void 0 ? void 0 : webData2Position.position.leverage.value, // TODO: consider if user manually change leverage from the HL UI
8386
8375
  entryRatio: 1,
8387
8376
  marginUsed: 0,
8388
8377
  markRatio: 1,
8389
8378
  unrealizedPnl: 0,
8390
- netFunding: 0,
8391
8379
  positionValue: 0,
8380
+ entryPositionValue: 0,
8392
8381
  takeProfit: position.takeProfit,
8393
8382
  stopLoss: position.stopLoss,
8394
8383
  };
8395
8384
  const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0) +
8396
8385
  position.shortAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0);
8397
8386
  mappedPosition.longAssets = position.longAssets.map(longAsset => {
8398
- var _a;
8387
+ var _a, _b, _c;
8399
8388
  const currentPrice = parseFloat(allMids.mids[longAsset.coin]);
8400
- const cumFunding = (_a = webData2.clearinghouseState.assetPositions.find(ap => ap.position.coin === longAsset.coin)) === null || _a === void 0 ? void 0 : _a.position.cumFunding;
8401
- const mappedPositionAssets = calculatePositionAsset(longAsset, currentPrice, totalInitialPositionSize, mappedPosition.leverage, cumFunding, true);
8389
+ const assetState = (_a = webData2.clearinghouseState.assetPositions.find(ap => ap.position.coin === longAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
8390
+ const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 0;
8391
+ const mappedPositionAssets = calculatePositionAsset(longAsset, currentPrice, totalInitialPositionSize, leverage, true);
8402
8392
  mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
8403
8393
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
8404
8394
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
8405
8395
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
8406
- mappedPosition.netFunding += mappedPositionAssets.cumFunding.sinceOpen;
8407
- // Calculate weighted entry and mark ratios for long positions
8408
8396
  mappedPosition.entryRatio *= Math.pow(longAsset.entryPrice, mappedPositionAssets.initialWeight);
8409
8397
  mappedPosition.markRatio *= Math.pow(currentPrice, mappedPositionAssets.initialWeight);
8410
8398
  return mappedPositionAssets;
8411
8399
  });
8412
8400
  mappedPosition.shortAssets = position.shortAssets.map(shortAsset => {
8413
- var _a;
8401
+ var _a, _b, _c;
8414
8402
  const currentPrice = parseFloat(allMids.mids[shortAsset.coin]);
8415
- const cumFunding = (_a = webData2.clearinghouseState.assetPositions.find(ap => ap.position.coin === shortAsset.coin)) === null || _a === void 0 ? void 0 : _a.position.cumFunding;
8416
- const mappedPositionAssets = calculatePositionAsset(shortAsset, currentPrice, totalInitialPositionSize, mappedPosition.leverage, cumFunding, false);
8403
+ const assetState = (_a = webData2.clearinghouseState.assetPositions.find(ap => ap.position.coin === shortAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
8404
+ const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 0;
8405
+ const mappedPositionAssets = calculatePositionAsset(shortAsset, currentPrice, totalInitialPositionSize, leverage, false);
8417
8406
  mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
8418
- mappedPosition.netFunding += mappedPositionAssets.cumFunding.sinceOpen;
8419
8407
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
8420
8408
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
8421
8409
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
@@ -8423,6 +8411,7 @@ const buildPositionValue = (rawPositions, webData2, allMids) => {
8423
8411
  mappedPosition.markRatio *= Math.pow(currentPrice, -mappedPositionAssets.initialWeight);
8424
8412
  return mappedPositionAssets;
8425
8413
  });
8414
+ mappedPosition.positionValue = mappedPosition.entryPositionValue + mappedPosition.unrealizedPnl;
8426
8415
  return mappedPosition;
8427
8416
  });
8428
8417
  };
@@ -8540,15 +8529,11 @@ function useOrders() {
8540
8529
  if (!hasAssets) {
8541
8530
  return {
8542
8531
  ...ord,
8543
- leverage: pos.leverage,
8544
8532
  longAssets: mapAssets(pos.longAssets),
8545
8533
  shortAssets: mapAssets(pos.shortAssets),
8546
8534
  };
8547
8535
  }
8548
- // Always sync leverage from position for TP/SL
8549
- if (ord.leverage !== pos.leverage) {
8550
- return { ...ord, leverage: pos.leverage };
8551
- }
8536
+ // Leverage is now tracked per-asset in positions; keep order leverage as-is
8552
8537
  return ord;
8553
8538
  });
8554
8539
  }, [openOrders, positionsById]);
package/dist/types.d.ts CHANGED
@@ -113,6 +113,8 @@ export interface TwapMonitoringDto {
113
113
  filledUsdValue: number;
114
114
  remainingUsdValue: number;
115
115
  twapDuration: string;
116
+ twapInternalSeconds?: number | null;
117
+ twapChunkUsdValue?: number | null;
116
118
  randomizeExecution: boolean;
117
119
  reduceOnly: boolean;
118
120
  chunks: TwapChunkStatusDto[];
@@ -171,7 +173,7 @@ export interface PositionAssetDetailDto {
171
173
  entryPrice: number;
172
174
  platformSize: number;
173
175
  actualSize: number;
174
- cumFunding: CumFundingDto;
176
+ leverage: number;
175
177
  marginUsed: number;
176
178
  entryPositionValue: number;
177
179
  positionValue: number;
@@ -189,12 +191,10 @@ export interface TpSlThreshold {
189
191
  export interface OpenPositionDto {
190
192
  positionId: string;
191
193
  address: string;
192
- leverage: number;
193
194
  stopLoss: TpSlThreshold | null;
194
195
  takeProfit: TpSlThreshold | null;
195
196
  entryRatio: number;
196
197
  markRatio: number;
197
- netFunding: number;
198
198
  entryPositionValue: number;
199
199
  positionValue: number;
200
200
  marginUsed: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",