@pear-protocol/hyperliquid-sdk 0.0.7 → 0.0.9

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 { PaginatedTradeHistoryResponseDto, RawPositionDto, OpenLimitOrderDto, AccountSummaryResponseDto, WebData2Response, WsAllMidsData } from './types';
7
7
  interface WebSocketData {
8
8
  tradeHistories: PaginatedTradeHistoryResponseDto | null;
9
- openPositions: OpenPositionDto[] | null;
9
+ openPositions: RawPositionDto[] | null;
10
10
  openOrders: OpenLimitOrderDto[] | null;
11
11
  accountSummary: AccountSummaryResponseDto | null;
12
12
  }
package/dist/types.d.ts CHANGED
@@ -496,13 +496,13 @@ export interface AssetPosition {
496
496
  returnOnEquity: string;
497
497
  szi: string;
498
498
  unrealizedPnl: string;
499
+ cumFunding: {
500
+ allTime: string;
501
+ sinceChange: string;
502
+ sinceOpen: string;
503
+ };
499
504
  };
500
505
  type: string;
501
- cumFunding: {
502
- allTime: string;
503
- sinceChange: string;
504
- sinceOpen: string;
505
- };
506
506
  }
507
507
  /**
508
508
  * Asset information detail
@@ -520,3 +520,27 @@ export interface AssetInformationDetail {
520
520
  priceChange: number;
521
521
  assetIndex: number;
522
522
  }
523
+ /**
524
+ * Raw asset data from open-positions channel
525
+ */
526
+ export interface RawAssetDto {
527
+ coin: string;
528
+ entryPrice: number;
529
+ size: number;
530
+ side: string;
531
+ }
532
+ /**
533
+ * Raw position data from open-positions channel
534
+ */
535
+ export interface RawPositionDto {
536
+ positionId: string;
537
+ address: string;
538
+ leverage: number;
539
+ stopLoss: number | null;
540
+ takeProfit: number | null;
541
+ status: string;
542
+ createdAt: string;
543
+ updatedAt: string;
544
+ longAssets: RawAssetDto[];
545
+ shortAssets: RawAssetDto[];
546
+ }
@@ -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 { PaginatedTradeHistoryResponseDto, OpenLimitOrderDto, AccountSummaryResponseDto, RawPositionDto } from './types';
3
3
  interface WebSocketData {
4
4
  tradeHistories: PaginatedTradeHistoryResponseDto | null;
5
- openPositions: OpenPositionDto[] | 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.7",
3
+ "version": "0.0.9",
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,76 +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
- * Position calculation utility class
11
- */
12
- export declare class PositionCalculator {
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
- */
27
- calculateOpenPositions(platformPositions: OpenPositionDto[]): OpenPositionDto[];
28
- /**
29
- * Sync a single position with HyperLiquid data
30
- */
31
- private syncPositionWithHyperliquid;
32
- /**
33
- * Group assets by their base currency
34
- */
35
- private groupAssetsByBaseCurrency;
36
- /**
37
- * Sync a group of assets (same base currency) with HyperLiquid position data
38
- */
39
- private syncAssetGroupWithHyperliquid;
40
- /**
41
- * Determine sync status based on asset sync results
42
- */
43
- private determineSyncStatus;
44
- /**
45
- * Build updated position with synced data
46
- */
47
- private buildUpdatedPosition;
48
- /**
49
- * Map sync result to PositionAssetDetailDto
50
- */
51
- private mapSyncResultToAssetDto;
52
- /**
53
- * Calculate entry ratio (weighted long entry value / weighted short entry value)
54
- */
55
- private calculateEntryRatio;
56
- /**
57
- * Calculate mark ratio (weighted long mark value / weighted short mark value)
58
- */
59
- private calculateMarkRatio;
60
- /**
61
- * Calculate net funding from sync results
62
- */
63
- private calculateNetFundingFromSyncResults;
64
- /**
65
- * Calculate total unrealized PnL from sync results
66
- */
67
- private calculateTotalUnrealizedPnlFromSyncResults;
68
- /**
69
- * Calculate current total position value using market prices
70
- */
71
- private calculateCurrentTotalPositionValue;
72
- /**
73
- * Calculate entry total position value using entry prices
74
- */
75
- private calculateEntryTotalPositionValue;
76
- }