@pear-protocol/hyperliquid-sdk 0.0.3 → 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 +118 -7
- package/dist/index.esm.js +3083 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3083 -29
- package/dist/index.js.map +1 -1
- package/dist/migration-sdk.d.ts +16 -2
- 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
|
/**
|
|
@@ -444,7 +445,9 @@ declare class PearHyperliquidClient {
|
|
|
444
445
|
*/
|
|
445
446
|
declare class PearMigrationSDK {
|
|
446
447
|
private client;
|
|
447
|
-
private
|
|
448
|
+
private isTradeHistorySyncRunning;
|
|
449
|
+
private isOpenPositionsSyncRunning;
|
|
450
|
+
private isOpenOrdersSyncRunning;
|
|
448
451
|
constructor(client: PearHyperliquidClient);
|
|
449
452
|
/**
|
|
450
453
|
* Sync trade history data - can only run one at a time
|
|
@@ -462,9 +465,21 @@ declare class PearMigrationSDK {
|
|
|
462
465
|
*/
|
|
463
466
|
syncOpenOrders(payload: SyncOpenOrderDto): Promise<ApiResponse<SyncOpenOrderResponseDto> | null>;
|
|
464
467
|
/**
|
|
465
|
-
* Check if sync is currently running
|
|
468
|
+
* Check if any sync is currently running
|
|
466
469
|
*/
|
|
467
470
|
isSyncInProgress(): boolean;
|
|
471
|
+
/**
|
|
472
|
+
* Check if trade history sync is currently running
|
|
473
|
+
*/
|
|
474
|
+
isTradeHistorySyncInProgress(): boolean;
|
|
475
|
+
/**
|
|
476
|
+
* Check if open positions sync is currently running
|
|
477
|
+
*/
|
|
478
|
+
isOpenPositionsSyncInProgress(): boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Check if open orders sync is currently running
|
|
481
|
+
*/
|
|
482
|
+
isOpenOrdersSyncInProgress(): boolean;
|
|
468
483
|
/**
|
|
469
484
|
* Get the underlying client instance
|
|
470
485
|
*/
|
|
@@ -483,6 +498,81 @@ declare class PearMigrationSDK {
|
|
|
483
498
|
getBaseUrl(): string;
|
|
484
499
|
}
|
|
485
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
|
+
|
|
486
576
|
interface PearHyperliquidProviderProps {
|
|
487
577
|
config: PearHyperliquidConfig;
|
|
488
578
|
/**
|
|
@@ -490,6 +580,11 @@ interface PearHyperliquidProviderProps {
|
|
|
490
580
|
* @default 'wss://hl-v2.pearprotocol.io/ws'
|
|
491
581
|
*/
|
|
492
582
|
wsUrl?: string;
|
|
583
|
+
/**
|
|
584
|
+
* Hyperliquid WebSocket URL
|
|
585
|
+
* @default 'wss://api.hyperliquid.xyz/ws'
|
|
586
|
+
*/
|
|
587
|
+
hyperliquidWsUrl?: string;
|
|
493
588
|
children: ReactNode;
|
|
494
589
|
}
|
|
495
590
|
/**
|
|
@@ -504,6 +599,10 @@ declare const usePearHyperliquidClient: () => PearHyperliquidClient;
|
|
|
504
599
|
* Hook to use migration SDK from context
|
|
505
600
|
*/
|
|
506
601
|
declare const useMigrationSDK: () => PearMigrationSDK;
|
|
602
|
+
/**
|
|
603
|
+
* Hook to use Hyperliquid service from context
|
|
604
|
+
*/
|
|
605
|
+
declare const useHyperliquidService: () => HyperliquidService;
|
|
507
606
|
|
|
508
607
|
/**
|
|
509
608
|
* Hook to manage address (login/logout functionality)
|
|
@@ -520,17 +619,29 @@ declare const useAddress: () => {
|
|
|
520
619
|
*/
|
|
521
620
|
declare const useTradeHistories: () => PaginatedTradeHistoryResponseDto | null;
|
|
522
621
|
/**
|
|
523
|
-
* Hook to access open positions
|
|
622
|
+
* Hook to access open positions with enhanced real-time synchronization
|
|
524
623
|
*/
|
|
525
|
-
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
|
+
};
|
|
526
631
|
/**
|
|
527
632
|
* Hook to access open orders
|
|
528
633
|
*/
|
|
529
634
|
declare const useOpenOrders: () => OpenLimitOrderDto[] | null;
|
|
530
635
|
/**
|
|
531
|
-
* Hook to access account summary
|
|
636
|
+
* Hook to access account summary with enhanced real-time data from Hyperliquid
|
|
532
637
|
*/
|
|
533
|
-
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
|
+
};
|
|
534
645
|
|
|
535
|
-
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 };
|
|
536
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 };
|