@pear-protocol/hyperliquid-sdk 0.0.4 → 0.0.5
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/useTrading.d.ts +19 -6
- package/dist/hyperliquid-service.d.ts +75 -0
- package/dist/index.d.ts +102 -5
- package/dist/index.esm.js +3040 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3040 -6
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +11 -0
- package/package.json +11 -3
|
@@ -1,16 +1,29 @@
|
|
|
1
|
+
import { OpenPositionDto, AccountSummaryResponseDto } from '../types';
|
|
1
2
|
/**
|
|
2
3
|
* Hook to access trade histories
|
|
3
4
|
*/
|
|
4
|
-
export declare const useTradeHistories: () => import("
|
|
5
|
+
export declare const useTradeHistories: () => import("../types").PaginatedTradeHistoryResponseDto | null;
|
|
5
6
|
/**
|
|
6
|
-
* Hook to access open positions
|
|
7
|
+
* Hook to access open positions with enhanced real-time synchronization
|
|
7
8
|
*/
|
|
8
|
-
export declare const useOpenPositions: () =>
|
|
9
|
+
export declare const useOpenPositions: () => {
|
|
10
|
+
positions: OpenPositionDto[];
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
lastSyncTime: Date | null;
|
|
13
|
+
rawWsPositions: OpenPositionDto[] | null;
|
|
14
|
+
resync: () => Promise<void>;
|
|
15
|
+
};
|
|
9
16
|
/**
|
|
10
17
|
* Hook to access open orders
|
|
11
18
|
*/
|
|
12
|
-
export declare const useOpenOrders: () => import("
|
|
19
|
+
export declare const useOpenOrders: () => import("../types").OpenLimitOrderDto[] | null;
|
|
13
20
|
/**
|
|
14
|
-
* Hook to access account summary
|
|
21
|
+
* Hook to access account summary with enhanced real-time data from Hyperliquid
|
|
15
22
|
*/
|
|
16
|
-
export declare const useAccountSummary: () =>
|
|
23
|
+
export declare const useAccountSummary: () => {
|
|
24
|
+
summary: AccountSummaryResponseDto | null;
|
|
25
|
+
isLoading: boolean;
|
|
26
|
+
lastSyncTime: Date | null;
|
|
27
|
+
rawWsSummary: AccountSummaryResponseDto | null;
|
|
28
|
+
resync: () => Promise<void>;
|
|
29
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as hl from '@nktkas/hyperliquid';
|
|
2
|
+
export interface AllAssetInformation {
|
|
3
|
+
universe: hl.PerpsUniverse;
|
|
4
|
+
assetsCtx: hl.PerpsAssetCtx;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Hyperliquid service client for direct API communication
|
|
8
|
+
*/
|
|
9
|
+
export declare class HyperliquidService {
|
|
10
|
+
private infoClient;
|
|
11
|
+
private subsClient?;
|
|
12
|
+
private wsTransport?;
|
|
13
|
+
private allMidsData;
|
|
14
|
+
private webData2;
|
|
15
|
+
private assetBySymbol;
|
|
16
|
+
private allAssetsCache;
|
|
17
|
+
constructor(wsUrl?: string, isTestnet?: boolean);
|
|
18
|
+
private initializeWebSocket;
|
|
19
|
+
/**
|
|
20
|
+
* Refresh asset cache when webData2 updates
|
|
21
|
+
*/
|
|
22
|
+
private refreshAssetCache;
|
|
23
|
+
/**
|
|
24
|
+
* Get asset information by symbol - O(1) lookup
|
|
25
|
+
*/
|
|
26
|
+
getAssetInfo(symbol: string): hl.PerpsUniverse | null;
|
|
27
|
+
/**
|
|
28
|
+
* Get asset context by symbol - O(1) lookup
|
|
29
|
+
*/
|
|
30
|
+
getAssetCtx(symbol: string): hl.PerpsAssetCtx | null;
|
|
31
|
+
/**
|
|
32
|
+
* Get asset index by symbol - O(1) lookup
|
|
33
|
+
*/
|
|
34
|
+
getAssetIndex(symbol: string): number | null;
|
|
35
|
+
/**
|
|
36
|
+
* Get all assets with caching
|
|
37
|
+
*/
|
|
38
|
+
getAllAssets(): AllAssetInformation[];
|
|
39
|
+
/**
|
|
40
|
+
* Get current market price for an asset
|
|
41
|
+
*/
|
|
42
|
+
getMarketPrice(symbol: string): number;
|
|
43
|
+
/**
|
|
44
|
+
* Get optimal decimal places for an asset
|
|
45
|
+
*/
|
|
46
|
+
getOptimalDecimal(symbol: string): number;
|
|
47
|
+
/**
|
|
48
|
+
* Get user's open positions from Hyperliquid
|
|
49
|
+
*/
|
|
50
|
+
getUserPositions(address: string): Promise<hl.AssetPosition[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Get user's account summary from Hyperliquid
|
|
53
|
+
*/
|
|
54
|
+
getAccountSummary(address: string): Promise<hl.PerpsClearinghouseState | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Get user's open orders from Hyperliquid
|
|
57
|
+
*/
|
|
58
|
+
getUserOrders(address: string): Promise<any[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Update the user address for webData2 subscription
|
|
61
|
+
*/
|
|
62
|
+
updateUserAddress(address: string | null): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get the info client instance
|
|
65
|
+
*/
|
|
66
|
+
getInfoClient(): hl.InfoClient;
|
|
67
|
+
/**
|
|
68
|
+
* Check if WebSocket is connected
|
|
69
|
+
*/
|
|
70
|
+
isWebSocketConnected(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Clean up resources
|
|
73
|
+
*/
|
|
74
|
+
cleanup(): Promise<void>;
|
|
75
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as hl from '@nktkas/hyperliquid';
|
|
1
2
|
import React, { ReactNode } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -497,6 +498,81 @@ declare class PearMigrationSDK {
|
|
|
497
498
|
getBaseUrl(): string;
|
|
498
499
|
}
|
|
499
500
|
|
|
501
|
+
interface AllAssetInformation {
|
|
502
|
+
universe: hl.PerpsUniverse;
|
|
503
|
+
assetsCtx: hl.PerpsAssetCtx;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Hyperliquid service client for direct API communication
|
|
507
|
+
*/
|
|
508
|
+
declare class HyperliquidService {
|
|
509
|
+
private infoClient;
|
|
510
|
+
private subsClient?;
|
|
511
|
+
private wsTransport?;
|
|
512
|
+
private allMidsData;
|
|
513
|
+
private webData2;
|
|
514
|
+
private assetBySymbol;
|
|
515
|
+
private allAssetsCache;
|
|
516
|
+
constructor(wsUrl?: string, isTestnet?: boolean);
|
|
517
|
+
private initializeWebSocket;
|
|
518
|
+
/**
|
|
519
|
+
* Refresh asset cache when webData2 updates
|
|
520
|
+
*/
|
|
521
|
+
private refreshAssetCache;
|
|
522
|
+
/**
|
|
523
|
+
* Get asset information by symbol - O(1) lookup
|
|
524
|
+
*/
|
|
525
|
+
getAssetInfo(symbol: string): hl.PerpsUniverse | null;
|
|
526
|
+
/**
|
|
527
|
+
* Get asset context by symbol - O(1) lookup
|
|
528
|
+
*/
|
|
529
|
+
getAssetCtx(symbol: string): hl.PerpsAssetCtx | null;
|
|
530
|
+
/**
|
|
531
|
+
* Get asset index by symbol - O(1) lookup
|
|
532
|
+
*/
|
|
533
|
+
getAssetIndex(symbol: string): number | null;
|
|
534
|
+
/**
|
|
535
|
+
* Get all assets with caching
|
|
536
|
+
*/
|
|
537
|
+
getAllAssets(): AllAssetInformation[];
|
|
538
|
+
/**
|
|
539
|
+
* Get current market price for an asset
|
|
540
|
+
*/
|
|
541
|
+
getMarketPrice(symbol: string): number;
|
|
542
|
+
/**
|
|
543
|
+
* Get optimal decimal places for an asset
|
|
544
|
+
*/
|
|
545
|
+
getOptimalDecimal(symbol: string): number;
|
|
546
|
+
/**
|
|
547
|
+
* Get user's open positions from Hyperliquid
|
|
548
|
+
*/
|
|
549
|
+
getUserPositions(address: string): Promise<hl.AssetPosition[]>;
|
|
550
|
+
/**
|
|
551
|
+
* Get user's account summary from Hyperliquid
|
|
552
|
+
*/
|
|
553
|
+
getAccountSummary(address: string): Promise<hl.PerpsClearinghouseState | null>;
|
|
554
|
+
/**
|
|
555
|
+
* Get user's open orders from Hyperliquid
|
|
556
|
+
*/
|
|
557
|
+
getUserOrders(address: string): Promise<any[]>;
|
|
558
|
+
/**
|
|
559
|
+
* Update the user address for webData2 subscription
|
|
560
|
+
*/
|
|
561
|
+
updateUserAddress(address: string | null): void;
|
|
562
|
+
/**
|
|
563
|
+
* Get the info client instance
|
|
564
|
+
*/
|
|
565
|
+
getInfoClient(): hl.InfoClient;
|
|
566
|
+
/**
|
|
567
|
+
* Check if WebSocket is connected
|
|
568
|
+
*/
|
|
569
|
+
isWebSocketConnected(): boolean;
|
|
570
|
+
/**
|
|
571
|
+
* Clean up resources
|
|
572
|
+
*/
|
|
573
|
+
cleanup(): Promise<void>;
|
|
574
|
+
}
|
|
575
|
+
|
|
500
576
|
interface PearHyperliquidProviderProps {
|
|
501
577
|
config: PearHyperliquidConfig;
|
|
502
578
|
/**
|
|
@@ -504,6 +580,11 @@ interface PearHyperliquidProviderProps {
|
|
|
504
580
|
* @default 'wss://hl-v2.pearprotocol.io/ws'
|
|
505
581
|
*/
|
|
506
582
|
wsUrl?: string;
|
|
583
|
+
/**
|
|
584
|
+
* Hyperliquid WebSocket URL
|
|
585
|
+
* @default 'wss://api.hyperliquid.xyz/ws'
|
|
586
|
+
*/
|
|
587
|
+
hyperliquidWsUrl?: string;
|
|
507
588
|
children: ReactNode;
|
|
508
589
|
}
|
|
509
590
|
/**
|
|
@@ -518,6 +599,10 @@ declare const usePearHyperliquidClient: () => PearHyperliquidClient;
|
|
|
518
599
|
* Hook to use migration SDK from context
|
|
519
600
|
*/
|
|
520
601
|
declare const useMigrationSDK: () => PearMigrationSDK;
|
|
602
|
+
/**
|
|
603
|
+
* Hook to use Hyperliquid service from context
|
|
604
|
+
*/
|
|
605
|
+
declare const useHyperliquidService: () => HyperliquidService;
|
|
521
606
|
|
|
522
607
|
/**
|
|
523
608
|
* Hook to manage address (login/logout functionality)
|
|
@@ -534,17 +619,29 @@ declare const useAddress: () => {
|
|
|
534
619
|
*/
|
|
535
620
|
declare const useTradeHistories: () => PaginatedTradeHistoryResponseDto | null;
|
|
536
621
|
/**
|
|
537
|
-
* Hook to access open positions
|
|
622
|
+
* Hook to access open positions with enhanced real-time synchronization
|
|
538
623
|
*/
|
|
539
|
-
declare const useOpenPositions: () =>
|
|
624
|
+
declare const useOpenPositions: () => {
|
|
625
|
+
positions: OpenPositionDto[];
|
|
626
|
+
isLoading: boolean;
|
|
627
|
+
lastSyncTime: Date | null;
|
|
628
|
+
rawWsPositions: OpenPositionDto[] | null;
|
|
629
|
+
resync: () => Promise<void>;
|
|
630
|
+
};
|
|
540
631
|
/**
|
|
541
632
|
* Hook to access open orders
|
|
542
633
|
*/
|
|
543
634
|
declare const useOpenOrders: () => OpenLimitOrderDto[] | null;
|
|
544
635
|
/**
|
|
545
|
-
* Hook to access account summary
|
|
636
|
+
* Hook to access account summary with enhanced real-time data from Hyperliquid
|
|
546
637
|
*/
|
|
547
|
-
declare const useAccountSummary: () =>
|
|
638
|
+
declare const useAccountSummary: () => {
|
|
639
|
+
summary: AccountSummaryResponseDto | null;
|
|
640
|
+
isLoading: boolean;
|
|
641
|
+
lastSyncTime: Date | null;
|
|
642
|
+
rawWsSummary: AccountSummaryResponseDto | null;
|
|
643
|
+
resync: () => Promise<void>;
|
|
644
|
+
};
|
|
548
645
|
|
|
549
|
-
export { PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PearHyperliquidClient as default, useAccountSummary, useAddress, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };
|
|
646
|
+
export { HyperliquidService, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PearHyperliquidClient as default, useAccountSummary, useAddress, useHyperliquidService, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };
|
|
550
647
|
export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, 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, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketResponse, WebSocketSubscribeMessage };
|