@pear-protocol/hyperliquid-sdk 0.0.9 → 0.0.11
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/useTokenSelection.d.ts +33 -0
- package/dist/hooks/useTrading.d.ts +20 -8
- package/dist/index.d.ts +148 -23
- package/dist/index.esm.js +616 -105
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +617 -103
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +16 -2
- package/dist/types.d.ts +47 -12
- package/dist/utils/conflict-detector.d.ts +14 -0
- package/dist/utils/token-metadata-extractor.d.ts +29 -0
- package/dist/websocket.d.ts +2 -2
- package/package.json +1 -1
package/dist/provider.d.ts
CHANGED
|
@@ -3,13 +3,25 @@ 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 {
|
|
6
|
+
import type { RawPositionDto, OpenLimitOrderDto, AccountSummaryResponseDto, WebData2Response, WsAllMidsData, TradeHistoryDataDto, TokenSelection, TokenConflict } from './types';
|
|
7
7
|
interface WebSocketData {
|
|
8
|
-
tradeHistories:
|
|
8
|
+
tradeHistories: TradeHistoryDataDto[] | null;
|
|
9
9
|
openPositions: RawPositionDto[] | null;
|
|
10
10
|
openOrders: OpenLimitOrderDto[] | null;
|
|
11
11
|
accountSummary: AccountSummaryResponseDto | null;
|
|
12
12
|
}
|
|
13
|
+
export interface TokenSelectorConfig {
|
|
14
|
+
isLong: boolean;
|
|
15
|
+
index: number;
|
|
16
|
+
}
|
|
17
|
+
interface TokenSelectionState {
|
|
18
|
+
longTokens: TokenSelection[];
|
|
19
|
+
shortTokens: TokenSelection[];
|
|
20
|
+
openTokenSelector: boolean;
|
|
21
|
+
selectorConfig: TokenSelectorConfig | null;
|
|
22
|
+
openConflictModal: boolean;
|
|
23
|
+
conflicts: TokenConflict[];
|
|
24
|
+
}
|
|
13
25
|
export interface PearHyperliquidContextType {
|
|
14
26
|
client: PearHyperliquidClient;
|
|
15
27
|
migrationSDK: PearMigrationSDK;
|
|
@@ -24,6 +36,8 @@ export interface PearHyperliquidContextType {
|
|
|
24
36
|
nativeLastError: string | null;
|
|
25
37
|
webData2: WebData2Response | null;
|
|
26
38
|
allMids: WsAllMidsData | null;
|
|
39
|
+
tokenSelection: TokenSelectionState;
|
|
40
|
+
setTokenSelection: React.Dispatch<React.SetStateAction<TokenSelectionState>>;
|
|
27
41
|
}
|
|
28
42
|
export declare const PearHyperliquidContext: React.Context<PearHyperliquidContextType | undefined>;
|
|
29
43
|
interface PearHyperliquidProviderProps {
|
package/dist/types.d.ts
CHANGED
|
@@ -265,15 +265,6 @@ export interface TradeHistoryDataDto {
|
|
|
265
265
|
shortAssets: TradeHistoryAssetDataDto[];
|
|
266
266
|
createdAt: string;
|
|
267
267
|
}
|
|
268
|
-
/**
|
|
269
|
-
* Paginated trade history response
|
|
270
|
-
*/
|
|
271
|
-
export interface PaginatedTradeHistoryResponseDto {
|
|
272
|
-
data: TradeHistoryDataDto[];
|
|
273
|
-
hasMore: boolean;
|
|
274
|
-
nextCursor?: string;
|
|
275
|
-
count: number;
|
|
276
|
-
}
|
|
277
268
|
/**
|
|
278
269
|
* Cumulative funding information
|
|
279
270
|
*/
|
|
@@ -334,18 +325,31 @@ export interface OrderAssetDto {
|
|
|
334
325
|
* Order status
|
|
335
326
|
*/
|
|
336
327
|
export type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
|
|
328
|
+
/**
|
|
329
|
+
* Order type
|
|
330
|
+
*/
|
|
331
|
+
export type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET';
|
|
332
|
+
/**
|
|
333
|
+
* TP/SL trigger type
|
|
334
|
+
*/
|
|
335
|
+
export type TpSlTriggerType = 'RATIO' | 'PERCENTAGE' | 'PNL';
|
|
337
336
|
/**
|
|
338
337
|
* Open limit order data structure
|
|
339
338
|
*/
|
|
340
339
|
export interface OpenLimitOrderDto {
|
|
341
340
|
orderId: string;
|
|
342
341
|
address: string;
|
|
342
|
+
clientId: string | null;
|
|
343
|
+
positionId: string;
|
|
343
344
|
leverage: number;
|
|
344
345
|
usdValue: number;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
346
|
+
triggerValue: number;
|
|
347
|
+
twapDuration: number | null;
|
|
348
|
+
tpSlTriggerType: TpSlTriggerType;
|
|
349
|
+
randomizeFlag: boolean;
|
|
350
|
+
reduceOnlyFlag: boolean;
|
|
348
351
|
status: OrderStatus;
|
|
352
|
+
orderType: OrderType;
|
|
349
353
|
longAssets: OrderAssetDto[];
|
|
350
354
|
shortAssets: OrderAssetDto[];
|
|
351
355
|
createdAt: string;
|
|
@@ -544,3 +548,34 @@ export interface RawPositionDto {
|
|
|
544
548
|
longAssets: RawAssetDto[];
|
|
545
549
|
shortAssets: RawAssetDto[];
|
|
546
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Token metadata from WebData2 and AllMids
|
|
553
|
+
*/
|
|
554
|
+
export interface TokenMetadata {
|
|
555
|
+
currentPrice: number;
|
|
556
|
+
prevDayPrice: number;
|
|
557
|
+
priceChange24h: number;
|
|
558
|
+
priceChange24hPercent: number;
|
|
559
|
+
netFunding: number;
|
|
560
|
+
maxLeverage: number;
|
|
561
|
+
markPrice: number;
|
|
562
|
+
oraclePrice: number;
|
|
563
|
+
openInterest: string;
|
|
564
|
+
dayVolume: string;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Enhanced token selection with weight and metadata for basket trading
|
|
568
|
+
*/
|
|
569
|
+
export interface TokenSelection {
|
|
570
|
+
symbol: string;
|
|
571
|
+
weight: number;
|
|
572
|
+
metadata?: TokenMetadata;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Token conflict information for position conflicts
|
|
576
|
+
*/
|
|
577
|
+
export interface TokenConflict {
|
|
578
|
+
symbol: string;
|
|
579
|
+
conflictType: 'long' | 'short';
|
|
580
|
+
conflictMessage: string;
|
|
581
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TokenSelection, TokenConflict } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Detects conflicts between selected tokens and existing positions
|
|
4
|
+
*/
|
|
5
|
+
export declare class ConflictDetector {
|
|
6
|
+
/**
|
|
7
|
+
* Detects conflicts between token selections and open positions
|
|
8
|
+
* @param longTokens - Selected long tokens
|
|
9
|
+
* @param shortTokens - Selected short tokens
|
|
10
|
+
* @param openPositions - Current open positions from API
|
|
11
|
+
* @returns Array of detected conflicts
|
|
12
|
+
*/
|
|
13
|
+
static detectConflicts(longTokens: TokenSelection[], shortTokens: TokenSelection[], openPositions: any[] | null): TokenConflict[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { WebData2Response, WsAllMidsData, TokenMetadata } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts token metadata from WebData2 and AllMids data
|
|
4
|
+
*/
|
|
5
|
+
export declare class TokenMetadataExtractor {
|
|
6
|
+
/**
|
|
7
|
+
* Extracts comprehensive token metadata
|
|
8
|
+
* @param symbol - Token symbol
|
|
9
|
+
* @param webData2 - WebData2 response containing asset context and universe data
|
|
10
|
+
* @param allMids - AllMids data containing current prices
|
|
11
|
+
* @returns TokenMetadata or null if token not found
|
|
12
|
+
*/
|
|
13
|
+
static extractTokenMetadata(symbol: string, webData2: WebData2Response | null, allMids: WsAllMidsData | null): TokenMetadata | null;
|
|
14
|
+
/**
|
|
15
|
+
* Extracts metadata for multiple tokens
|
|
16
|
+
* @param symbols - Array of token symbols
|
|
17
|
+
* @param webData2 - WebData2 response
|
|
18
|
+
* @param allMids - AllMids data
|
|
19
|
+
* @returns Record of symbol to TokenMetadata
|
|
20
|
+
*/
|
|
21
|
+
static extractMultipleTokensMetadata(symbols: string[], webData2: WebData2Response | null, allMids: WsAllMidsData | null): Record<string, TokenMetadata | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if token data is available in WebData2
|
|
24
|
+
* @param symbol - Token symbol
|
|
25
|
+
* @param webData2 - WebData2 response
|
|
26
|
+
* @returns boolean indicating if token exists in universe
|
|
27
|
+
*/
|
|
28
|
+
static isTokenAvailable(symbol: string, webData2: WebData2Response | null): boolean;
|
|
29
|
+
}
|
package/dist/websocket.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReadyState } from 'react-use-websocket';
|
|
2
|
-
import type {
|
|
2
|
+
import type { OpenLimitOrderDto, AccountSummaryResponseDto, RawPositionDto, TradeHistoryDataDto } from './types';
|
|
3
3
|
interface WebSocketData {
|
|
4
|
-
tradeHistories:
|
|
4
|
+
tradeHistories: TradeHistoryDataDto[] | null;
|
|
5
5
|
openPositions: RawPositionDto[] | null;
|
|
6
6
|
openOrders: OpenLimitOrderDto[] | null;
|
|
7
7
|
accountSummary: AccountSummaryResponseDto | null;
|