@pear-protocol/hyperliquid-sdk 0.0.8 → 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.
- package/dist/hooks/useCalculatedPositions.d.ts +2 -2
- package/dist/index.d.ts +32 -89
- package/dist/index.esm.js +152 -248
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +153 -250
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +2 -2
- package/dist/types.d.ts +29 -5
- package/dist/utils/position-processor.d.ts +22 -0
- package/dist/websocket.d.ts +2 -2
- package/package.json +1 -1
- package/dist/utils/aggregate-position-calculator.d.ts +0 -81
package/dist/provider.d.ts
CHANGED
|
@@ -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,
|
|
6
|
+
import type { PaginatedTradeHistoryResponseDto, RawPositionDto, OpenLimitOrderDto, AccountSummaryResponseDto, WebData2Response, WsAllMidsData } from './types';
|
|
7
7
|
interface WebSocketData {
|
|
8
8
|
tradeHistories: PaginatedTradeHistoryResponseDto | null;
|
|
9
|
-
openPositions:
|
|
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
|
+
}
|
package/dist/websocket.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReadyState } from 'react-use-websocket';
|
|
2
|
-
import type { PaginatedTradeHistoryResponseDto,
|
|
2
|
+
import type { PaginatedTradeHistoryResponseDto, OpenLimitOrderDto, AccountSummaryResponseDto, RawPositionDto } from './types';
|
|
3
3
|
interface WebSocketData {
|
|
4
4
|
tradeHistories: PaginatedTradeHistoryResponseDto | null;
|
|
5
|
-
openPositions:
|
|
5
|
+
openPositions: RawPositionDto[] | null;
|
|
6
6
|
openOrders: OpenLimitOrderDto[] | null;
|
|
7
7
|
accountSummary: AccountSummaryResponseDto | null;
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -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
|
-
}
|