@pear-protocol/hyperliquid-sdk 0.0.8 → 0.0.10

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.
@@ -3,10 +3,10 @@ import { ReadyState } from 'react-use-websocket';
3
3
  import { PearHyperliquidClient } from './client';
4
4
  import { PearHyperliquidConfig } from './types';
5
5
  import { PearMigrationSDK } from './migration-sdk';
6
- import type { PaginatedTradeHistoryResponseDto, OpenPositionDto, OpenLimitOrderDto, AccountSummaryResponseDto, WebData2Response, WsAllMidsData } from './types';
6
+ import type { RawPositionDto, OpenLimitOrderDto, AccountSummaryResponseDto, WebData2Response, WsAllMidsData, TradeHistoryDataDto } from './types';
7
7
  interface WebSocketData {
8
- tradeHistories: PaginatedTradeHistoryResponseDto | null;
9
- openPositions: OpenPositionDto[] | null;
8
+ tradeHistories: TradeHistoryDataDto[] | null;
9
+ openPositions: RawPositionDto[] | null;
10
10
  openOrders: OpenLimitOrderDto[] | null;
11
11
  accountSummary: AccountSummaryResponseDto | null;
12
12
  }
package/dist/types.d.ts CHANGED
@@ -265,15 +265,6 @@ export interface TradeHistoryDataDto {
265
265
  shortAssets: TradeHistoryAssetDataDto[];
266
266
  createdAt: string;
267
267
  }
268
- /**
269
- * Paginated trade history response
270
- */
271
- export interface PaginatedTradeHistoryResponseDto {
272
- data: TradeHistoryDataDto[];
273
- hasMore: boolean;
274
- nextCursor?: string;
275
- count: number;
276
- }
277
268
  /**
278
269
  * Cumulative funding information
279
270
  */
@@ -334,18 +325,31 @@ export interface OrderAssetDto {
334
325
  * Order status
335
326
  */
336
327
  export type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
328
+ /**
329
+ * Order type
330
+ */
331
+ export type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET';
332
+ /**
333
+ * TP/SL trigger type
334
+ */
335
+ export type TpSlTriggerType = 'RATIO' | 'PERCENTAGE' | 'PNL';
337
336
  /**
338
337
  * Open limit order data structure
339
338
  */
340
339
  export interface OpenLimitOrderDto {
341
340
  orderId: string;
342
341
  address: string;
342
+ clientId: string | null;
343
+ positionId: string;
343
344
  leverage: number;
344
345
  usdValue: number;
345
- limitRatio: number;
346
- stopLoss: number | null;
347
- takeProfit: number | null;
346
+ triggerValue: number;
347
+ twapDuration: number | null;
348
+ tpSlTriggerType: TpSlTriggerType;
349
+ randomizeFlag: boolean;
350
+ reduceOnlyFlag: boolean;
348
351
  status: OrderStatus;
352
+ orderType: OrderType;
349
353
  longAssets: OrderAssetDto[];
350
354
  shortAssets: OrderAssetDto[];
351
355
  createdAt: string;
@@ -496,13 +500,13 @@ export interface AssetPosition {
496
500
  returnOnEquity: string;
497
501
  szi: string;
498
502
  unrealizedPnl: string;
503
+ cumFunding: {
504
+ allTime: string;
505
+ sinceChange: string;
506
+ sinceOpen: string;
507
+ };
499
508
  };
500
509
  type: string;
501
- cumFunding: {
502
- allTime: string;
503
- sinceChange: string;
504
- sinceOpen: string;
505
- };
506
510
  }
507
511
  /**
508
512
  * Asset information detail
@@ -520,3 +524,27 @@ export interface AssetInformationDetail {
520
524
  priceChange: number;
521
525
  assetIndex: number;
522
526
  }
527
+ /**
528
+ * Raw asset data from open-positions channel
529
+ */
530
+ export interface RawAssetDto {
531
+ coin: string;
532
+ entryPrice: number;
533
+ size: number;
534
+ side: string;
535
+ }
536
+ /**
537
+ * Raw position data from open-positions channel
538
+ */
539
+ export interface RawPositionDto {
540
+ positionId: string;
541
+ address: string;
542
+ leverage: number;
543
+ stopLoss: number | null;
544
+ takeProfit: number | null;
545
+ status: string;
546
+ createdAt: string;
547
+ updatedAt: string;
548
+ longAssets: RawAssetDto[];
549
+ shortAssets: RawAssetDto[];
550
+ }
@@ -0,0 +1,22 @@
1
+ import type { OpenPositionDto, WebData2Response, WsAllMidsData, RawPositionDto } from '../types';
2
+ export declare class PositionProcessor {
3
+ private webData2;
4
+ private allMids;
5
+ constructor(webData2: WebData2Response | null, allMids: WsAllMidsData | null);
6
+ execute(rawPositions: RawPositionDto[]): OpenPositionDto[];
7
+ private getUserPositions;
8
+ private getMarketPrice;
9
+ private calculatePlatformTotalsByAsset;
10
+ private extractBaseCurrency;
11
+ private syncPositionWithAggregateData;
12
+ private determineSyncStatus;
13
+ private syncAssetWithAggregateData;
14
+ private mapPositionToDtoWithSyncData;
15
+ private mapAssetToDetailDto;
16
+ private calculateEntryRatio;
17
+ private calculateMarkRatio;
18
+ private calculateNetFundingFromSyncResults;
19
+ private calculateTotalUnrealizedPnlFromSyncResults;
20
+ private calculateCurrentTotalPositionValue;
21
+ private calculateEntryTotalPositionValue;
22
+ }
@@ -1,8 +1,8 @@
1
1
  import { ReadyState } from 'react-use-websocket';
2
- import type { PaginatedTradeHistoryResponseDto, OpenPositionDto, OpenLimitOrderDto, AccountSummaryResponseDto } from './types';
2
+ import type { OpenLimitOrderDto, AccountSummaryResponseDto, RawPositionDto, TradeHistoryDataDto } from './types';
3
3
  interface WebSocketData {
4
- tradeHistories: PaginatedTradeHistoryResponseDto | null;
5
- openPositions: OpenPositionDto[] | null;
4
+ tradeHistories: TradeHistoryDataDto[] | null;
5
+ openPositions: RawPositionDto[] | null;
6
6
  openOrders: OpenLimitOrderDto[] | null;
7
7
  accountSummary: AccountSummaryResponseDto | null;
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -1,81 +0,0 @@
1
- import type { OpenPositionDto, AssetPosition, WebData2Response, WsAllMidsData } from '../types';
2
- /**
3
- * Position side enum for calculations
4
- */
5
- export declare enum PositionSide {
6
- LONG = "LONG",
7
- SHORT = "SHORT"
8
- }
9
- /**
10
- * Aggregate position calculation utility class that handles cross-position asset syncing
11
- */
12
- export declare class AggregatePositionCalculator {
13
- private webData2;
14
- private allMids;
15
- constructor(webData2: WebData2Response | null, allMids: WsAllMidsData | null);
16
- /**
17
- * Get market price for a coin from allMids data
18
- */
19
- getMarketPrice(coin: string): number;
20
- /**
21
- * Get user positions from webData2
22
- */
23
- getUserPositions(): AssetPosition[];
24
- /**
25
- * Calculate updated open positions by syncing platform positions with HyperLiquid data
26
- * Uses aggregate totals across all positions for accurate cross-position sync
27
- */
28
- calculateOpenPositions(platformPositions: OpenPositionDto[]): OpenPositionDto[];
29
- /**
30
- * Calculate total platform sizes per asset across all positions
31
- */
32
- private calculatePlatformTotalsByAsset;
33
- /**
34
- * Extract base currency from asset name (handles "LINK/USD" -> "LINK")
35
- */
36
- private extractBaseCurrency;
37
- /**
38
- * Sync a single position with HyperLiquid data using aggregate totals
39
- */
40
- private syncPositionWithAggregateData;
41
- /**
42
- * Sync individual asset with aggregate data awareness
43
- */
44
- private syncAssetWithAggregateData;
45
- /**
46
- * Determine sync status with sophisticated side-aware logic
47
- */
48
- private determineSyncStatus;
49
- /**
50
- * Build updated position with synced data
51
- */
52
- private buildUpdatedPosition;
53
- /**
54
- * Map sync result to PositionAssetDetailDto
55
- */
56
- private mapSyncResultToAssetDto;
57
- /**
58
- * Calculate entry ratio using actual sizes from sync results
59
- */
60
- private calculateEntryRatio;
61
- /**
62
- * Calculate mark ratio using actual sizes and current prices
63
- */
64
- private calculateMarkRatio;
65
- /**
66
- * Calculate net funding from sync results
67
- */
68
- private calculateNetFundingFromSyncResults;
69
- /**
70
- * Calculate total unrealized PnL from sync results
71
- */
72
- private calculateTotalUnrealizedPnlFromSyncResults;
73
- /**
74
- * Calculate current total position value using market prices
75
- */
76
- private calculateCurrentTotalPositionValue;
77
- /**
78
- * Calculate entry total position value using entry prices
79
- */
80
- private calculateEntryTotalPositionValue;
81
- }