@pear-protocol/hyperliquid-sdk 0.0.4 → 0.0.7
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/index.d.ts +2 -0
- package/dist/hooks/useCalculatedAccountSummary.d.ts +5 -0
- package/dist/hooks/useCalculatedPositions.d.ts +5 -0
- package/dist/hooks/useTrading.d.ts +2 -2
- package/dist/hyperliquid-websocket.d.ts +13 -0
- package/dist/index.d.ts +289 -13
- package/dist/index.esm.js +665 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +669 -17
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +6 -1
- package/dist/types.d.ts +119 -1
- package/dist/utils/account-summary-calculator.d.ts +41 -0
- package/dist/utils/position-calculator.d.ts +76 -0
- package/dist/websocket.d.ts +20 -0
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { useAddress } from './useAddress';
|
|
2
2
|
export { useTradeHistories, useOpenPositions, useOpenOrders, useAccountSummary } from './useTrading';
|
|
3
|
+
export { useCalculatedOpenPositions } from './useCalculatedPositions';
|
|
4
|
+
export { useCalculatedAccountSummary } from './useCalculatedAccountSummary';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AccountSummaryResponseDto, WebData2Response, OpenLimitOrderDto } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that calculates account summary by syncing platform data with HyperLiquid real-time data
|
|
4
|
+
*/
|
|
5
|
+
export declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, webData2: WebData2Response | null, agentWalletAddress?: string, agentWalletStatus?: string) => AccountSummaryResponseDto | null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OpenPositionDto, WebData2Response, WsAllMidsData } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
|
|
4
|
+
*/
|
|
5
|
+
export declare const useCalculatedOpenPositions: (platformPositions: OpenPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare const useTradeHistories: () => import("..").PaginatedTradeHistoryResponseDto | null;
|
|
5
5
|
/**
|
|
6
|
-
* Hook to access open positions
|
|
6
|
+
* Hook to access open positions with real-time calculations
|
|
7
7
|
*/
|
|
8
8
|
export declare const useOpenPositions: () => import("..").OpenPositionDto[] | null;
|
|
9
9
|
/**
|
|
@@ -11,6 +11,6 @@ export declare const useOpenPositions: () => import("..").OpenPositionDto[] | nu
|
|
|
11
11
|
*/
|
|
12
12
|
export declare const useOpenOrders: () => import("..").OpenLimitOrderDto[] | null;
|
|
13
13
|
/**
|
|
14
|
-
* Hook to access account summary
|
|
14
|
+
* Hook to access account summary with real-time calculations
|
|
15
15
|
*/
|
|
16
16
|
export declare const useAccountSummary: () => import("..").AccountSummaryResponseDto | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReadyState } from 'react-use-websocket';
|
|
2
|
+
import type { WebData2Response, WsAllMidsData } from './types';
|
|
3
|
+
export interface UseHyperliquidNativeWebSocketProps {
|
|
4
|
+
address: string | null;
|
|
5
|
+
}
|
|
6
|
+
export interface UseHyperliquidNativeWebSocketReturn {
|
|
7
|
+
webData2: WebData2Response | null;
|
|
8
|
+
allMids: WsAllMidsData | null;
|
|
9
|
+
connectionStatus: ReadyState;
|
|
10
|
+
isConnected: boolean;
|
|
11
|
+
lastError: string | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const useHyperliquidNativeWebSocket: ({ address }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ReadyState } from 'react-use-websocket';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Raw value data for trade history positions
|
|
@@ -214,7 +215,7 @@ type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'e
|
|
|
214
215
|
/**
|
|
215
216
|
* WebSocket channels
|
|
216
217
|
*/
|
|
217
|
-
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary';
|
|
218
|
+
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'webData2' | 'allMids';
|
|
218
219
|
/**
|
|
219
220
|
* WebSocket subscription message
|
|
220
221
|
*/
|
|
@@ -222,14 +223,6 @@ interface WebSocketSubscribeMessage {
|
|
|
222
223
|
action?: 'subscribe' | 'unsubscribe';
|
|
223
224
|
address: string;
|
|
224
225
|
}
|
|
225
|
-
/**
|
|
226
|
-
* WebSocket response message
|
|
227
|
-
*/
|
|
228
|
-
interface WebSocketResponse {
|
|
229
|
-
success?: boolean;
|
|
230
|
-
message?: string;
|
|
231
|
-
error?: string;
|
|
232
|
-
}
|
|
233
226
|
/**
|
|
234
227
|
* WebSocket data message
|
|
235
228
|
*/
|
|
@@ -395,6 +388,132 @@ interface AccountSummaryResponseDto {
|
|
|
395
388
|
balanceSummary: BalanceSummaryDto;
|
|
396
389
|
agentWallet: AgentWalletDto;
|
|
397
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* WebSocket message from HyperLiquid native API
|
|
393
|
+
*/
|
|
394
|
+
interface WebSocketMessage {
|
|
395
|
+
method: "subscribe" | "unsubscribe";
|
|
396
|
+
subscription: {
|
|
397
|
+
type: string;
|
|
398
|
+
coin?: string;
|
|
399
|
+
interval?: string;
|
|
400
|
+
user?: string;
|
|
401
|
+
aggregateByTime?: boolean;
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* WebSocket response message
|
|
406
|
+
*/
|
|
407
|
+
interface WebSocketResponse {
|
|
408
|
+
success?: boolean;
|
|
409
|
+
message?: string;
|
|
410
|
+
error?: string;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* WebSocket response from HyperLiquid native API
|
|
414
|
+
*/
|
|
415
|
+
interface WebSocketResponse {
|
|
416
|
+
channel: string;
|
|
417
|
+
data: any;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* All mids data structure
|
|
421
|
+
*/
|
|
422
|
+
interface WsAllMidsData {
|
|
423
|
+
mids: Record<string, string>;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Asset context data
|
|
427
|
+
*/
|
|
428
|
+
interface AssetCtx {
|
|
429
|
+
funding: string;
|
|
430
|
+
openInterest: string;
|
|
431
|
+
prevDayPx: string;
|
|
432
|
+
dayNtlVlm: string;
|
|
433
|
+
markPx: string;
|
|
434
|
+
midPx?: string;
|
|
435
|
+
impactPxs?: string[];
|
|
436
|
+
oraclePx: string;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Universe asset metadata
|
|
440
|
+
*/
|
|
441
|
+
interface UniverseAsset {
|
|
442
|
+
name: string;
|
|
443
|
+
szDecimals: number;
|
|
444
|
+
maxLeverage: number;
|
|
445
|
+
onlyIsolated: boolean;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* WebData2 response structure
|
|
449
|
+
*/
|
|
450
|
+
interface WebData2Response {
|
|
451
|
+
assetCtxs: AssetCtx[];
|
|
452
|
+
meta: {
|
|
453
|
+
universe: UniverseAsset[];
|
|
454
|
+
};
|
|
455
|
+
clearinghouseState: {
|
|
456
|
+
assetPositions: AssetPosition[];
|
|
457
|
+
crossMaintenanceMarginUsed: string;
|
|
458
|
+
crossMarginSummary: {
|
|
459
|
+
accountValue: string;
|
|
460
|
+
totalMarginUsed: string;
|
|
461
|
+
totalNtlPos: string;
|
|
462
|
+
totalRawUsd: string;
|
|
463
|
+
};
|
|
464
|
+
marginSummary: {
|
|
465
|
+
accountValue: string;
|
|
466
|
+
totalMarginUsed: string;
|
|
467
|
+
totalNtlPos: string;
|
|
468
|
+
totalRawUsd: string;
|
|
469
|
+
};
|
|
470
|
+
time: number;
|
|
471
|
+
withdrawable: string;
|
|
472
|
+
};
|
|
473
|
+
perpsAtOpenInterestCap?: string[];
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Asset position data
|
|
477
|
+
*/
|
|
478
|
+
interface AssetPosition {
|
|
479
|
+
position: {
|
|
480
|
+
coin: string;
|
|
481
|
+
entryPx?: string;
|
|
482
|
+
leverage: {
|
|
483
|
+
type: string;
|
|
484
|
+
value: number;
|
|
485
|
+
};
|
|
486
|
+
liquidationPx?: string;
|
|
487
|
+
marginUsed: string;
|
|
488
|
+
maxLeverage: number;
|
|
489
|
+
positionValue: string;
|
|
490
|
+
returnOnEquity: string;
|
|
491
|
+
szi: string;
|
|
492
|
+
unrealizedPnl: string;
|
|
493
|
+
};
|
|
494
|
+
type: string;
|
|
495
|
+
cumFunding: {
|
|
496
|
+
allTime: string;
|
|
497
|
+
sinceChange: string;
|
|
498
|
+
sinceOpen: string;
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Asset information detail
|
|
503
|
+
*/
|
|
504
|
+
interface AssetInformationDetail {
|
|
505
|
+
name: string;
|
|
506
|
+
funding: string;
|
|
507
|
+
openInterest: string;
|
|
508
|
+
prevDayPx: string;
|
|
509
|
+
dayNtlVlm: string;
|
|
510
|
+
oraclePx: string;
|
|
511
|
+
markPx: string;
|
|
512
|
+
midPx?: string;
|
|
513
|
+
dayBaseVlm: string;
|
|
514
|
+
priceChange: number;
|
|
515
|
+
assetIndex: number;
|
|
516
|
+
}
|
|
398
517
|
|
|
399
518
|
/**
|
|
400
519
|
* Main SDK client for Pear Protocol Hyperliquid API integration
|
|
@@ -534,7 +653,7 @@ declare const useAddress: () => {
|
|
|
534
653
|
*/
|
|
535
654
|
declare const useTradeHistories: () => PaginatedTradeHistoryResponseDto | null;
|
|
536
655
|
/**
|
|
537
|
-
* Hook to access open positions
|
|
656
|
+
* Hook to access open positions with real-time calculations
|
|
538
657
|
*/
|
|
539
658
|
declare const useOpenPositions: () => OpenPositionDto[] | null;
|
|
540
659
|
/**
|
|
@@ -542,9 +661,166 @@ declare const useOpenPositions: () => OpenPositionDto[] | null;
|
|
|
542
661
|
*/
|
|
543
662
|
declare const useOpenOrders: () => OpenLimitOrderDto[] | null;
|
|
544
663
|
/**
|
|
545
|
-
* Hook to access account summary
|
|
664
|
+
* Hook to access account summary with real-time calculations
|
|
546
665
|
*/
|
|
547
666
|
declare const useAccountSummary: () => AccountSummaryResponseDto | null;
|
|
548
667
|
|
|
549
|
-
|
|
550
|
-
|
|
668
|
+
/**
|
|
669
|
+
* Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
|
|
670
|
+
*/
|
|
671
|
+
declare const useCalculatedOpenPositions: (platformPositions: OpenPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Hook that calculates account summary by syncing platform data with HyperLiquid real-time data
|
|
675
|
+
*/
|
|
676
|
+
declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, webData2: WebData2Response | null, agentWalletAddress?: string, agentWalletStatus?: string) => AccountSummaryResponseDto | null;
|
|
677
|
+
|
|
678
|
+
interface WebSocketData {
|
|
679
|
+
tradeHistories: PaginatedTradeHistoryResponseDto | null;
|
|
680
|
+
openPositions: OpenPositionDto[] | null;
|
|
681
|
+
openOrders: OpenLimitOrderDto[] | null;
|
|
682
|
+
accountSummary: AccountSummaryResponseDto | null;
|
|
683
|
+
}
|
|
684
|
+
interface UseHyperliquidWebSocketProps {
|
|
685
|
+
wsUrl: string;
|
|
686
|
+
address: string | null;
|
|
687
|
+
}
|
|
688
|
+
interface UseHyperliquidWebSocketReturn {
|
|
689
|
+
data: WebSocketData;
|
|
690
|
+
connectionStatus: ReadyState;
|
|
691
|
+
isConnected: boolean;
|
|
692
|
+
lastError: string | null;
|
|
693
|
+
}
|
|
694
|
+
declare const useHyperliquidWebSocket: ({ wsUrl, address }: UseHyperliquidWebSocketProps) => UseHyperliquidWebSocketReturn;
|
|
695
|
+
|
|
696
|
+
interface UseHyperliquidNativeWebSocketProps {
|
|
697
|
+
address: string | null;
|
|
698
|
+
}
|
|
699
|
+
interface UseHyperliquidNativeWebSocketReturn {
|
|
700
|
+
webData2: WebData2Response | null;
|
|
701
|
+
allMids: WsAllMidsData | null;
|
|
702
|
+
connectionStatus: ReadyState;
|
|
703
|
+
isConnected: boolean;
|
|
704
|
+
lastError: string | null;
|
|
705
|
+
}
|
|
706
|
+
declare const useHyperliquidNativeWebSocket: ({ address }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Position side enum for calculations
|
|
710
|
+
*/
|
|
711
|
+
declare enum PositionSide {
|
|
712
|
+
LONG = "LONG",
|
|
713
|
+
SHORT = "SHORT"
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Position calculation utility class
|
|
717
|
+
*/
|
|
718
|
+
declare class PositionCalculator {
|
|
719
|
+
private webData2;
|
|
720
|
+
private allMids;
|
|
721
|
+
constructor(webData2: WebData2Response | null, allMids: WsAllMidsData | null);
|
|
722
|
+
/**
|
|
723
|
+
* Get market price for a coin from allMids data
|
|
724
|
+
*/
|
|
725
|
+
getMarketPrice(coin: string): number;
|
|
726
|
+
/**
|
|
727
|
+
* Get user positions from webData2
|
|
728
|
+
*/
|
|
729
|
+
getUserPositions(): AssetPosition[];
|
|
730
|
+
/**
|
|
731
|
+
* Calculate updated open positions by syncing platform positions with HyperLiquid data
|
|
732
|
+
*/
|
|
733
|
+
calculateOpenPositions(platformPositions: OpenPositionDto[]): OpenPositionDto[];
|
|
734
|
+
/**
|
|
735
|
+
* Sync a single position with HyperLiquid data
|
|
736
|
+
*/
|
|
737
|
+
private syncPositionWithHyperliquid;
|
|
738
|
+
/**
|
|
739
|
+
* Group assets by their base currency
|
|
740
|
+
*/
|
|
741
|
+
private groupAssetsByBaseCurrency;
|
|
742
|
+
/**
|
|
743
|
+
* Sync a group of assets (same base currency) with HyperLiquid position data
|
|
744
|
+
*/
|
|
745
|
+
private syncAssetGroupWithHyperliquid;
|
|
746
|
+
/**
|
|
747
|
+
* Determine sync status based on asset sync results
|
|
748
|
+
*/
|
|
749
|
+
private determineSyncStatus;
|
|
750
|
+
/**
|
|
751
|
+
* Build updated position with synced data
|
|
752
|
+
*/
|
|
753
|
+
private buildUpdatedPosition;
|
|
754
|
+
/**
|
|
755
|
+
* Map sync result to PositionAssetDetailDto
|
|
756
|
+
*/
|
|
757
|
+
private mapSyncResultToAssetDto;
|
|
758
|
+
/**
|
|
759
|
+
* Calculate entry ratio (weighted long entry value / weighted short entry value)
|
|
760
|
+
*/
|
|
761
|
+
private calculateEntryRatio;
|
|
762
|
+
/**
|
|
763
|
+
* Calculate mark ratio (weighted long mark value / weighted short mark value)
|
|
764
|
+
*/
|
|
765
|
+
private calculateMarkRatio;
|
|
766
|
+
/**
|
|
767
|
+
* Calculate net funding from sync results
|
|
768
|
+
*/
|
|
769
|
+
private calculateNetFundingFromSyncResults;
|
|
770
|
+
/**
|
|
771
|
+
* Calculate total unrealized PnL from sync results
|
|
772
|
+
*/
|
|
773
|
+
private calculateTotalUnrealizedPnlFromSyncResults;
|
|
774
|
+
/**
|
|
775
|
+
* Calculate current total position value using market prices
|
|
776
|
+
*/
|
|
777
|
+
private calculateCurrentTotalPositionValue;
|
|
778
|
+
/**
|
|
779
|
+
* Calculate entry total position value using entry prices
|
|
780
|
+
*/
|
|
781
|
+
private calculateEntryTotalPositionValue;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Account summary calculation utility class
|
|
786
|
+
*/
|
|
787
|
+
declare class AccountSummaryCalculator {
|
|
788
|
+
private webData2;
|
|
789
|
+
constructor(webData2: WebData2Response | null);
|
|
790
|
+
/**
|
|
791
|
+
* Calculate account summary from webData2 and platform orders
|
|
792
|
+
*/
|
|
793
|
+
calculateAccountSummary(platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, agentWalletAddress?: string, agentWalletStatus?: string): AccountSummaryResponseDto | null;
|
|
794
|
+
/**
|
|
795
|
+
* Calculate total USD value of open limit orders
|
|
796
|
+
*/
|
|
797
|
+
private calculateTotalLimitOrderValue;
|
|
798
|
+
/**
|
|
799
|
+
* Get real-time clearinghouse state from webData2
|
|
800
|
+
*/
|
|
801
|
+
getClearinghouseState(): {
|
|
802
|
+
assetPositions: AssetPosition[];
|
|
803
|
+
crossMaintenanceMarginUsed: string;
|
|
804
|
+
crossMarginSummary: {
|
|
805
|
+
accountValue: string;
|
|
806
|
+
totalMarginUsed: string;
|
|
807
|
+
totalNtlPos: string;
|
|
808
|
+
totalRawUsd: string;
|
|
809
|
+
};
|
|
810
|
+
marginSummary: {
|
|
811
|
+
accountValue: string;
|
|
812
|
+
totalMarginUsed: string;
|
|
813
|
+
totalNtlPos: string;
|
|
814
|
+
totalRawUsd: string;
|
|
815
|
+
};
|
|
816
|
+
time: number;
|
|
817
|
+
withdrawable: string;
|
|
818
|
+
} | null;
|
|
819
|
+
/**
|
|
820
|
+
* Check if real-time data is available
|
|
821
|
+
*/
|
|
822
|
+
hasRealTimeData(): boolean;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
export { AccountSummaryCalculator, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PositionCalculator, PositionSide, PearHyperliquidClient as default, useAccountSummary, useAddress, useCalculatedAccountSummary, useCalculatedOpenPositions, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };
|
|
826
|
+
export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetPosition, BalanceSummaryDto, CrossMarginSummaryDto, CumFundingDto, MarginSummaryDto, MigrationHookState, MigrationHooks, OpenLimitOrderDto, OpenOrderV1Dto, OpenPositionDto, OpenPositionV1Dto, OrderAssetDto, OrderStatus, PaginatedTradeHistoryResponseDto, PearHyperliquidConfig, PnlDto, PositionAssetDetailDto, PositionSideDto, PositionSyncStatus, RawValueDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, TpSlDto, TradeHistoryAssetDataDto, TradeHistoryDataDto, TradeHistoryV1Dto, UniverseAsset, WebData2Response, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketResponse, WebSocketSubscribeMessage, WsAllMidsData };
|