@pear-protocol/hyperliquid-sdk 0.0.16 → 0.0.18
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/client.d.ts +2 -2
- package/dist/hooks/useTrading.d.ts +7 -4
- package/dist/hooks/useUserSelection.d.ts +1 -1
- package/dist/hooks/useWebData.d.ts +3 -3
- package/dist/index.d.ts +69 -55
- package/dist/index.js +1360 -2932
- package/dist/types.d.ts +30 -22
- package/dist/utils/account-summary-calculator.d.ts +1 -18
- package/dist/utils/conflict-detector.d.ts +2 -2
- package/package.json +17 -5
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PearHyperliquidConfig, ApiResponse, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, CandleData } from './types';
|
|
1
|
+
import { PearHyperliquidConfig, ApiResponse, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, CandleData, CandleInterval } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Main SDK client for Pear Protocol Hyperliquid API integration
|
|
4
4
|
*/
|
|
@@ -48,5 +48,5 @@ export declare class PearHyperliquidClient {
|
|
|
48
48
|
* @param interval - Candle interval
|
|
49
49
|
* @returns Promise with historical candle data
|
|
50
50
|
*/
|
|
51
|
-
fetchHistoricalCandles(coin: string, startTime: number, endTime: number, interval:
|
|
51
|
+
fetchHistoricalCandles(coin: string, startTime: number, endTime: number, interval: CandleInterval): Promise<ApiResponse<CandleData[]>>;
|
|
52
52
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { AccountSummaryResponseDto, OpenLimitOrderDto } from '../types';
|
|
2
|
+
import type { TradeHistoryDataDto } from '../types';
|
|
3
|
+
import type { OpenPositionDto } from '../types';
|
|
1
4
|
export declare const useTradeHistories: () => {
|
|
2
|
-
data:
|
|
5
|
+
data: TradeHistoryDataDto[] | null;
|
|
3
6
|
isLoading: boolean;
|
|
4
7
|
};
|
|
5
8
|
/**
|
|
@@ -9,20 +12,20 @@ export declare const useOpenPositions: () => {
|
|
|
9
12
|
data: null;
|
|
10
13
|
isLoading: boolean;
|
|
11
14
|
} | {
|
|
12
|
-
data:
|
|
15
|
+
data: OpenPositionDto[];
|
|
13
16
|
isLoading: boolean;
|
|
14
17
|
};
|
|
15
18
|
/**
|
|
16
19
|
* Hook to access open orders with loading state
|
|
17
20
|
*/
|
|
18
21
|
export declare const useOpenOrders: () => {
|
|
19
|
-
data:
|
|
22
|
+
data: OpenLimitOrderDto[] | null;
|
|
20
23
|
isLoading: boolean;
|
|
21
24
|
};
|
|
22
25
|
/**
|
|
23
26
|
* Hook to access account summary with real-time calculations and loading state
|
|
24
27
|
*/
|
|
25
28
|
export declare const useAccountSummary: () => {
|
|
26
|
-
data:
|
|
29
|
+
data: AccountSummaryResponseDto | null;
|
|
27
30
|
isLoading: boolean;
|
|
28
31
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { useUserSelection } from "../store/userSelection";
|
|
2
2
|
export type { UserSelectionState } from "../store/userSelection";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { AssetMarketData } from '../types';
|
|
1
|
+
import type { AssetMarketData, ClearinghouseState } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Hook to access webData and native WebSocket state
|
|
4
4
|
*/
|
|
5
5
|
export declare const useWebData: () => {
|
|
6
|
-
clearinghouseState:
|
|
7
|
-
perpsAtOpenInterestCap:
|
|
6
|
+
clearinghouseState: ClearinghouseState | undefined;
|
|
7
|
+
perpsAtOpenInterestCap: string[] | undefined;
|
|
8
8
|
marketDataBySymbol: Record<string, AssetMarketData>;
|
|
9
9
|
isConnected: boolean;
|
|
10
10
|
connectionStatus: import("react-use-websocket").ReadyState;
|
package/dist/index.d.ts
CHANGED
|
@@ -224,6 +224,14 @@ interface WebSocketSubscribeMessage {
|
|
|
224
224
|
action?: 'subscribe' | 'unsubscribe';
|
|
225
225
|
address: string;
|
|
226
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* WebSocket response message
|
|
229
|
+
*/
|
|
230
|
+
interface WebSocketAckResponse {
|
|
231
|
+
success?: boolean;
|
|
232
|
+
message?: string;
|
|
233
|
+
error?: string;
|
|
234
|
+
}
|
|
227
235
|
/**
|
|
228
236
|
* WebSocket data message
|
|
229
237
|
*/
|
|
@@ -406,20 +414,19 @@ interface WebSocketMessage {
|
|
|
406
414
|
aggregateByTime?: boolean;
|
|
407
415
|
};
|
|
408
416
|
}
|
|
409
|
-
/**
|
|
410
|
-
* WebSocket response message
|
|
411
|
-
*/
|
|
412
|
-
interface WebSocketResponse {
|
|
413
|
-
success?: boolean;
|
|
414
|
-
message?: string;
|
|
415
|
-
error?: string;
|
|
416
|
-
}
|
|
417
417
|
/**
|
|
418
418
|
* WebSocket response from HyperLiquid native API
|
|
419
419
|
*/
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
type HLChannel = 'webData2' | 'allMids' | 'activeAssetData' | 'candle';
|
|
421
|
+
interface HLChannelDataMap {
|
|
422
|
+
webData2: WebData2Response;
|
|
423
|
+
allMids: WsAllMidsData;
|
|
424
|
+
activeAssetData: ActiveAssetData;
|
|
425
|
+
candle: CandleData;
|
|
426
|
+
}
|
|
427
|
+
interface HLWebSocketResponse<T extends HLChannel = HLChannel> {
|
|
428
|
+
channel: T;
|
|
429
|
+
data: HLChannelDataMap[T];
|
|
423
430
|
}
|
|
424
431
|
/**
|
|
425
432
|
* All mids data structure
|
|
@@ -458,26 +465,27 @@ interface WebData2Response {
|
|
|
458
465
|
meta: {
|
|
459
466
|
universe: UniverseAsset[];
|
|
460
467
|
};
|
|
461
|
-
clearinghouseState:
|
|
462
|
-
assetPositions: AssetPosition[];
|
|
463
|
-
crossMaintenanceMarginUsed: string;
|
|
464
|
-
crossMarginSummary: {
|
|
465
|
-
accountValue: string;
|
|
466
|
-
totalMarginUsed: string;
|
|
467
|
-
totalNtlPos: string;
|
|
468
|
-
totalRawUsd: string;
|
|
469
|
-
};
|
|
470
|
-
marginSummary: {
|
|
471
|
-
accountValue: string;
|
|
472
|
-
totalMarginUsed: string;
|
|
473
|
-
totalNtlPos: string;
|
|
474
|
-
totalRawUsd: string;
|
|
475
|
-
};
|
|
476
|
-
time: number;
|
|
477
|
-
withdrawable: string;
|
|
478
|
-
};
|
|
468
|
+
clearinghouseState: ClearinghouseState;
|
|
479
469
|
perpsAtOpenInterestCap?: string[];
|
|
480
470
|
}
|
|
471
|
+
interface ClearinghouseState {
|
|
472
|
+
assetPositions: AssetPosition[];
|
|
473
|
+
crossMaintenanceMarginUsed: string;
|
|
474
|
+
crossMarginSummary: {
|
|
475
|
+
accountValue: string;
|
|
476
|
+
totalMarginUsed: string;
|
|
477
|
+
totalNtlPos: string;
|
|
478
|
+
totalRawUsd: string;
|
|
479
|
+
};
|
|
480
|
+
marginSummary: {
|
|
481
|
+
accountValue: string;
|
|
482
|
+
totalMarginUsed: string;
|
|
483
|
+
totalNtlPos: string;
|
|
484
|
+
totalRawUsd: string;
|
|
485
|
+
};
|
|
486
|
+
time: number;
|
|
487
|
+
withdrawable: string;
|
|
488
|
+
}
|
|
481
489
|
/**
|
|
482
490
|
* Asset position data
|
|
483
491
|
*/
|
|
@@ -520,6 +528,30 @@ interface AssetInformationDetail {
|
|
|
520
528
|
priceChange: number;
|
|
521
529
|
assetIndex: number;
|
|
522
530
|
}
|
|
531
|
+
/**
|
|
532
|
+
* Raw asset data from open-positions channel
|
|
533
|
+
*/
|
|
534
|
+
interface RawAssetDto {
|
|
535
|
+
coin: string;
|
|
536
|
+
entryPrice: number;
|
|
537
|
+
size: number;
|
|
538
|
+
side: string;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Raw position data from open-positions channel
|
|
542
|
+
*/
|
|
543
|
+
interface RawPositionDto {
|
|
544
|
+
positionId: string;
|
|
545
|
+
address: string;
|
|
546
|
+
leverage: number;
|
|
547
|
+
stopLoss: number | null;
|
|
548
|
+
takeProfit: number | null;
|
|
549
|
+
status: string;
|
|
550
|
+
createdAt: string;
|
|
551
|
+
updatedAt: string;
|
|
552
|
+
longAssets: RawAssetDto[];
|
|
553
|
+
shortAssets: RawAssetDto[];
|
|
554
|
+
}
|
|
523
555
|
/**
|
|
524
556
|
* Leverage information from activeAssetData
|
|
525
557
|
*/
|
|
@@ -674,7 +706,7 @@ declare class PearHyperliquidClient {
|
|
|
674
706
|
* @param interval - Candle interval
|
|
675
707
|
* @returns Promise with historical candle data
|
|
676
708
|
*/
|
|
677
|
-
fetchHistoricalCandles(coin: string, startTime: number, endTime: number, interval:
|
|
709
|
+
fetchHistoricalCandles(coin: string, startTime: number, endTime: number, interval: CandleInterval): Promise<ApiResponse<CandleData[]>>;
|
|
678
710
|
}
|
|
679
711
|
|
|
680
712
|
/**
|
|
@@ -772,7 +804,7 @@ declare const useAddress: () => {
|
|
|
772
804
|
};
|
|
773
805
|
|
|
774
806
|
declare const useTradeHistories: () => {
|
|
775
|
-
data:
|
|
807
|
+
data: TradeHistoryDataDto[] | null;
|
|
776
808
|
isLoading: boolean;
|
|
777
809
|
};
|
|
778
810
|
/**
|
|
@@ -789,7 +821,7 @@ declare const useOpenPositions: () => {
|
|
|
789
821
|
* Hook to access open orders with loading state
|
|
790
822
|
*/
|
|
791
823
|
declare const useOpenOrders: () => {
|
|
792
|
-
data:
|
|
824
|
+
data: OpenLimitOrderDto[] | null;
|
|
793
825
|
isLoading: boolean;
|
|
794
826
|
};
|
|
795
827
|
/**
|
|
@@ -821,15 +853,14 @@ interface UserSelectionState {
|
|
|
821
853
|
handleTokenSelect: (selectedToken: string) => void;
|
|
822
854
|
resetToDefaults: () => void;
|
|
823
855
|
}
|
|
824
|
-
|
|
825
856
|
declare const useUserSelection: any;
|
|
826
857
|
|
|
827
858
|
/**
|
|
828
859
|
* Hook to access webData and native WebSocket state
|
|
829
860
|
*/
|
|
830
861
|
declare const useWebData: () => {
|
|
831
|
-
clearinghouseState:
|
|
832
|
-
perpsAtOpenInterestCap:
|
|
862
|
+
clearinghouseState: ClearinghouseState | undefined;
|
|
863
|
+
perpsAtOpenInterestCap: string[] | undefined;
|
|
833
864
|
marketDataBySymbol: Record<string, AssetMarketData>;
|
|
834
865
|
isConnected: boolean;
|
|
835
866
|
connectionStatus: react_use_websocket.ReadyState;
|
|
@@ -910,24 +941,7 @@ declare class AccountSummaryCalculator {
|
|
|
910
941
|
/**
|
|
911
942
|
* Get real-time clearinghouse state from webData2
|
|
912
943
|
*/
|
|
913
|
-
getClearinghouseState():
|
|
914
|
-
assetPositions: AssetPosition[];
|
|
915
|
-
crossMaintenanceMarginUsed: string;
|
|
916
|
-
crossMarginSummary: {
|
|
917
|
-
accountValue: string;
|
|
918
|
-
totalMarginUsed: string;
|
|
919
|
-
totalNtlPos: string;
|
|
920
|
-
totalRawUsd: string;
|
|
921
|
-
};
|
|
922
|
-
marginSummary: {
|
|
923
|
-
accountValue: string;
|
|
924
|
-
totalMarginUsed: string;
|
|
925
|
-
totalNtlPos: string;
|
|
926
|
-
totalRawUsd: string;
|
|
927
|
-
};
|
|
928
|
-
time: number;
|
|
929
|
-
withdrawable: string;
|
|
930
|
-
} | null;
|
|
944
|
+
getClearinghouseState(): ClearinghouseState | null;
|
|
931
945
|
/**
|
|
932
946
|
* Check if real-time data is available
|
|
933
947
|
*/
|
|
@@ -945,7 +959,7 @@ declare class ConflictDetector {
|
|
|
945
959
|
* @param openPositions - Current open positions from API
|
|
946
960
|
* @returns Array of detected conflicts
|
|
947
961
|
*/
|
|
948
|
-
static detectConflicts(longTokens: TokenSelection[], shortTokens: TokenSelection[], openPositions:
|
|
962
|
+
static detectConflicts(longTokens: TokenSelection[], shortTokens: TokenSelection[], openPositions: RawPositionDto[] | null): TokenConflict[];
|
|
949
963
|
}
|
|
950
964
|
|
|
951
965
|
/**
|
|
@@ -1017,4 +1031,4 @@ interface TokenHistoricalPriceData {
|
|
|
1017
1031
|
declare const useHistoricalPriceDataStore: any;
|
|
1018
1032
|
|
|
1019
1033
|
export { AccountSummaryCalculator, ConflictDetector, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, TokenMetadataExtractor, calculateWeightedRatio, computeBasketCandles, createCandleLookups, PearHyperliquidClient as default, getCompleteTimestamps, useAccountSummary, useAddress, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTokenSelectionMetadata, useTradeHistories, useUserSelection, useWebData };
|
|
1020
|
-
export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetPosition, BalanceSummaryDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, CrossMarginSummaryDto, CumFundingDto, HistoricalRange, MarginSummaryDto, MigrationHookState, MigrationHooks, OpenLimitOrderDto, OpenOrderV1Dto, OpenPositionDto, OpenPositionV1Dto, OrderAssetDto, OrderStatus, PearHyperliquidConfig, PnlDto, PositionAssetDetailDto, PositionSideDto, PositionSyncStatus, RawValueDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlDto, TradeHistoryAssetDataDto, TradeHistoryDataDto, TradeHistoryV1Dto, UniverseAsset, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseTokenSelectionMetadataReturn, UserSelectionState, WebData2Response, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage,
|
|
1034
|
+
export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetPosition, BalanceSummaryDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CrossMarginSummaryDto, CumFundingDto, HLWebSocketResponse, HistoricalRange, MarginSummaryDto, MigrationHookState, MigrationHooks, OpenLimitOrderDto, OpenOrderV1Dto, OpenPositionDto, OpenPositionV1Dto, OrderAssetDto, OrderStatus, PearHyperliquidConfig, PnlDto, PositionAssetDetailDto, PositionSideDto, PositionSyncStatus, RawValueDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlDto, TradeHistoryAssetDataDto, TradeHistoryDataDto, TradeHistoryV1Dto, UniverseAsset, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseTokenSelectionMetadataReturn, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WeightedCandleData, WsAllMidsData };
|