@pear-protocol/hyperliquid-sdk 0.0.22 → 0.0.26

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/index.d.ts CHANGED
@@ -2,74 +2,11 @@ import React, { ReactNode } from 'react';
2
2
  import * as react_use_websocket from 'react-use-websocket';
3
3
  import { ReadyState } from 'react-use-websocket';
4
4
 
5
- /**
6
- * Raw value data for trade history positions
7
- */
8
- interface RawValueDto {
9
- coin: string;
10
- size: string;
11
- leverage: number;
12
- openPx: string;
13
- closePx: string;
14
- marginUsed: string;
15
- positionValue: string;
16
- }
17
- /**
18
- * Trade history data structure from V1 API
19
- */
20
- interface TradeHistoryV1Dto {
21
- pearId: string;
22
- openedDate: string;
23
- closedDate: string;
24
- time: string;
25
- pair: string;
26
- direction: Record<string, string>;
27
- closedPrice: number;
28
- openedPrice: number;
29
- size: string;
30
- longPositionValue: number;
31
- shortPositionValue: number;
32
- positionValue: number;
33
- fee: number;
34
- builderFee: number;
35
- closedPNL: number;
36
- closedPnlPercentage: number;
37
- leverage: number;
38
- rawLongValue: RawValueDto;
39
- rawShortValue: RawValueDto;
40
- }
41
- /**
42
- * Request payload for syncing trade history
43
- */
44
- interface SyncTradeHistoryDto {
45
- address: string;
46
- data: TradeHistoryV1Dto[];
47
- }
48
- /**
49
- * Response from sync trade history endpoint
50
- */
51
- interface SyncTradeHistoryResponseDto {
52
- success: boolean;
53
- positionId: string;
54
- tradeHistoryId: string;
55
- message: string;
56
- }
57
- /**
58
- * Base API error response
59
- */
60
5
  interface ApiErrorResponse {
61
6
  statusCode: number;
62
7
  message: string;
63
8
  error?: string;
64
9
  }
65
- /**
66
- * Configuration options for the SDK
67
- */
68
- interface PearHyperliquidConfig {
69
- baseUrl: string;
70
- timeout?: number;
71
- headers?: Record<string, string>;
72
- }
73
10
  /**
74
11
  * HTTP client response wrapper
75
12
  */
@@ -78,136 +15,13 @@ interface ApiResponse<T> {
78
15
  status: number;
79
16
  headers: Record<string, string>;
80
17
  }
81
- /**
82
- * Hook state interface for migration operations
83
- */
84
- interface MigrationHookState<T> {
85
- loading: boolean;
86
- error: ApiErrorResponse | null;
87
- data: T | null;
88
- }
89
- /**
90
- * PnL data structure for open positions
91
- */
92
- interface PnlDto {
93
- value: number;
94
- percentage: number;
95
- }
96
- /**
97
- * Take profit and stop loss data structure
98
- */
99
- interface TpSlDto {
100
- takeProfit?: number;
101
- stopLoss?: number;
102
- }
103
- /**
104
- * Position side data structure for open positions
105
- */
106
- interface PositionSideDto {
107
- coin: string;
108
- size: string;
109
- leverage: number;
110
- entryPx: string;
111
- marginUsed: string;
112
- liquidationPx: string | undefined;
113
- unrealizedPnl: string;
114
- roe: string;
115
- positionValue: string;
116
- funding: string;
117
- }
118
- /**
119
- * Open position data structure from V1 API
120
- */
121
- interface OpenPositionV1Dto {
122
- pair: string;
123
- leverage: number;
124
- size: number;
125
- longPositionValue?: number;
126
- shortPositionValue?: number;
127
- positionValue: number;
128
- entryPrice: number;
129
- markPrice: number;
130
- pnl: PnlDto;
131
- liqPrice: string | number;
132
- margin: number;
133
- funding: number;
134
- pearId: string;
135
- openedDate: string;
136
- tpsl: TpSlDto;
137
- long: PositionSideDto;
138
- short: PositionSideDto;
139
- }
140
- /**
141
- * Request payload for syncing open positions
142
- */
143
- interface SyncOpenPositionDto {
144
- address: string;
145
- data: OpenPositionV1Dto[];
146
- }
147
- /**
148
- * Response from sync open positions endpoint
149
- */
150
- interface SyncOpenPositionResponseDto {
151
- success: boolean;
152
- positionIds: string[];
153
- count: number;
154
- message: string;
155
- }
156
- /**
157
- * Open order data structure from V1 API
158
- */
159
- interface OpenOrderV1Dto {
160
- id: string;
161
- time: string;
162
- pair: string;
163
- type: string;
164
- orderValue: number;
165
- price: number;
166
- triggerConditions: string;
167
- status: string;
168
- leverage?: string;
169
- }
170
- /**
171
- * Request payload for syncing open orders
172
- */
173
- interface SyncOpenOrderDto {
174
- address: string;
175
- data: OpenOrderV1Dto[];
176
- }
177
- /**
178
- * Response from sync open orders endpoint
179
- */
180
- interface SyncOpenOrderResponseDto {
181
- success: boolean;
182
- orderIds: string[];
183
- count: number;
184
- message: string;
185
- }
186
- /**
187
- * Migration hooks interface
188
- */
189
- interface MigrationHooks {
190
- tradeHistory: {
191
- sync: (payload: SyncTradeHistoryDto) => Promise<ApiResponse<SyncTradeHistoryResponseDto>>;
192
- loading: boolean;
193
- error: ApiErrorResponse | null;
194
- data: SyncTradeHistoryResponseDto | null;
195
- reset: () => void;
196
- };
197
- openPositions: {
198
- sync: (payload: SyncOpenPositionDto) => Promise<ApiResponse<SyncOpenPositionResponseDto>>;
199
- loading: boolean;
200
- error: ApiErrorResponse | null;
201
- data: SyncOpenPositionResponseDto | null;
202
- reset: () => void;
203
- };
204
- openOrders: {
205
- sync: (payload: SyncOpenOrderDto) => Promise<ApiResponse<SyncOpenOrderResponseDto>>;
206
- loading: boolean;
207
- error: ApiErrorResponse | null;
208
- data: SyncOpenOrderResponseDto | null;
209
- reset: () => void;
210
- };
18
+ interface SyncFillsResponseDto {
19
+ insertedFills: number;
20
+ skippedDuplicates: number;
21
+ createdOrders: number;
22
+ updatedPositions: number;
23
+ createdPositions: number;
24
+ closedPositions: number;
211
25
  }
212
26
  /**
213
27
  * WebSocket connection states
@@ -261,6 +75,7 @@ interface TradeHistoryDataDto {
261
75
  externalFeePaid: number;
262
76
  builderFeePaid: number;
263
77
  realizedPnl: number;
78
+ totalEntryValue: number;
264
79
  totalValue: number;
265
80
  entryRatio: number;
266
81
  exitRatio: number;
@@ -287,15 +102,16 @@ interface PositionAssetDetailDto {
287
102
  actualSize: number;
288
103
  cumFunding: CumFundingDto;
289
104
  marginUsed: number;
105
+ entryPositionValue: number;
290
106
  positionValue: number;
291
107
  unrealizedPnl: number;
292
108
  liquidationPrice: number;
293
- isExternallyModified: boolean;
109
+ initialWeight: number;
110
+ }
111
+ interface TpSlThreshold {
112
+ type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
113
+ value: number;
294
114
  }
295
- /**
296
- * Position sync status
297
- */
298
- type PositionSyncStatus = 'SYNCED' | 'EXTERNALLY_MODIFIED' | 'EXTERNALLY_CLOSED' | 'PAIR_BROKEN';
299
115
  /**
300
116
  * Open position data structure
301
117
  */
@@ -303,18 +119,17 @@ interface OpenPositionDto {
303
119
  positionId: string;
304
120
  address: string;
305
121
  leverage: number;
306
- stopLoss: number | null;
307
- takeProfit: number | null;
122
+ stopLoss: TpSlThreshold | null;
123
+ takeProfit: TpSlThreshold | null;
308
124
  entryRatio: number;
309
125
  markRatio: number;
310
126
  netFunding: number;
127
+ entryPositionValue: number;
311
128
  positionValue: number;
312
129
  marginUsed: number;
313
130
  unrealizedPnl: number;
314
131
  longAssets: PositionAssetDetailDto[];
315
132
  shortAssets: PositionAssetDetailDto[];
316
- syncStatus: PositionSyncStatus;
317
- lastSyncAt: string;
318
133
  createdAt: string;
319
134
  updatedAt: string;
320
135
  }
@@ -401,6 +216,40 @@ interface AccountSummaryResponseDto {
401
216
  balanceSummary: BalanceSummaryDto;
402
217
  agentWallet: AgentWalletDto;
403
218
  }
219
+ declare enum AuthStatus {
220
+ Idle = "idle",
221
+ Authenticating = "authenticating",
222
+ Authenticated = "authenticated",
223
+ Error = "error"
224
+ }
225
+ interface UseAuthOptions {
226
+ baseUrl: string;
227
+ clientId: string;
228
+ }
229
+ interface UserProfile {
230
+ userId: string;
231
+ address: string;
232
+ appId: string;
233
+ }
234
+ type AgentWalletStatus = 'ACTIVE' | 'EXPIRED' | 'NOT_FOUND';
235
+ interface GetAgentWalletResponseDto {
236
+ agentWalletAddress?: string;
237
+ agentName: string;
238
+ status: AgentWalletStatus;
239
+ }
240
+ interface CreateAgentWalletResponseDto {
241
+ agentWalletAddress: string;
242
+ message: string;
243
+ }
244
+ interface UseAgentWalletOptions {
245
+ baseUrl: string;
246
+ }
247
+ interface AgentWalletState {
248
+ address: string | null;
249
+ name: string | null;
250
+ status: AgentWalletStatus | 'PENDING' | null;
251
+ isActive: boolean;
252
+ }
404
253
  /**
405
254
  * WebSocket message from HyperLiquid native API
406
255
  */
@@ -615,16 +464,13 @@ type CandleInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" |
615
464
  * Candle data structure from WebSocket
616
465
  */
617
466
  interface CandleData {
467
+ s?: string;
618
468
  t: number;
619
469
  T: number;
620
- s: string;
621
- i: string;
622
- o: string;
623
- c: string;
624
- h: string;
625
- l: string;
626
- v: string;
627
- n: number;
470
+ o: number;
471
+ c: number;
472
+ h: number;
473
+ l: number;
628
474
  }
629
475
  /**
630
476
  * Candle chart data organized by symbol only
@@ -643,155 +489,82 @@ interface CandleSnapshotRequest {
643
489
  };
644
490
  type: "candleSnapshot";
645
491
  }
646
- /**
647
- * Weighted candle data for chart visualization
648
- */
649
- interface WeightedCandleData {
650
- t: number;
651
- T: number;
652
- o: number;
653
- c: number;
654
- h: number;
655
- l: number;
656
- v: number;
657
- n: number;
658
- }
659
-
660
- /**
661
- * Main SDK client for Pear Protocol Hyperliquid API integration
662
- */
663
- declare class PearHyperliquidClient {
664
- private httpClient;
665
- private baseUrl;
666
- constructor(config: PearHyperliquidConfig);
667
- /**
668
- * Get the configured base URL
669
- */
670
- getBaseUrl(): string;
671
- /**
672
- * Update request headers
673
- */
674
- setHeaders(headers: Record<string, string>): void;
675
- /**
676
- * Set authorization header
677
- */
678
- setAuthToken(token: string): void;
679
- /**
680
- * Make a generic HTTP request
681
- */
682
- private makeRequest;
683
- /**
684
- * Sync trade history data from old database structure to new database format
685
- * @param payload - Trade history data with user address
686
- * @returns Promise with sync result
687
- */
688
- syncTradeHistory(payload: SyncTradeHistoryDto): Promise<ApiResponse<SyncTradeHistoryResponseDto>>;
689
- /**
690
- * Sync open positions data from old database structure to new database format
691
- * @param payload - Open positions data with user address
692
- * @returns Promise with sync result
693
- */
694
- syncOpenPositions(payload: SyncOpenPositionDto): Promise<ApiResponse<SyncOpenPositionResponseDto>>;
695
- /**
696
- * Sync open orders data from old database structure to new database format
697
- * @param payload - Open orders data with user address
698
- * @returns Promise with sync result
699
- */
700
- syncOpenOrders(payload: SyncOpenOrderDto): Promise<ApiResponse<SyncOpenOrderResponseDto>>;
701
- /**
702
- * Fetch historical candle data from HyperLiquid API
703
- * @param coin - Token symbol (e.g., 'BTC', 'ETH')
704
- * @param startTime - Start time in milliseconds
705
- * @param endTime - End time in milliseconds
706
- * @param interval - Candle interval
707
- * @returns Promise with historical candle data
708
- */
709
- fetchHistoricalCandles(coin: string, startTime: number, endTime: number, interval: CandleInterval): Promise<ApiResponse<CandleData[]>>;
710
- }
711
-
712
- /**
713
- * Main Migration SDK Class - Simple request/response pattern
714
- */
715
- declare class PearMigrationSDK {
716
- private client;
717
- private isTradeHistorySyncRunning;
718
- private isOpenPositionsSyncRunning;
719
- private isOpenOrdersSyncRunning;
720
- constructor(client: PearHyperliquidClient);
721
- /**
722
- * Sync trade history data - can only run one at a time
723
- * If called while already running, returns immediately without making request
724
- */
725
- syncTradeHistory(payload: SyncTradeHistoryDto): Promise<ApiResponse<SyncTradeHistoryResponseDto> | null>;
726
- /**
727
- * Sync open positions data - can only run one at a time
728
- * If called while already running, returns immediately without making request
729
- */
730
- syncOpenPositions(payload: SyncOpenPositionDto): Promise<ApiResponse<SyncOpenPositionResponseDto> | null>;
731
- /**
732
- * Sync open orders data - can only run one at a time
733
- * If called while already running, returns immediately without making request
734
- */
735
- syncOpenOrders(payload: SyncOpenOrderDto): Promise<ApiResponse<SyncOpenOrderResponseDto> | null>;
736
- /**
737
- * Check if any sync is currently running
738
- */
739
- isSyncInProgress(): boolean;
740
- /**
741
- * Check if trade history sync is currently running
742
- */
743
- isTradeHistorySyncInProgress(): boolean;
744
- /**
745
- * Check if open positions sync is currently running
746
- */
747
- isOpenPositionsSyncInProgress(): boolean;
748
- /**
749
- * Check if open orders sync is currently running
750
- */
751
- isOpenOrdersSyncInProgress(): boolean;
752
- /**
753
- * Get the underlying client instance
754
- */
755
- getClient(): PearHyperliquidClient;
756
- /**
757
- * Set authorization token on the client
758
- */
759
- setAuthToken(token: string): void;
760
- /**
761
- * Set custom headers on the client
762
- */
763
- setHeaders(headers: Record<string, string>): void;
764
- /**
765
- * Get base URL from client
766
- */
767
- getBaseUrl(): string;
768
- }
769
-
770
492
  interface TokenSelectorConfig {
771
493
  isLong: boolean;
772
494
  index: number;
773
495
  }
496
+
497
+ interface PearHyperliquidContextType {
498
+ apiBaseUrl: string;
499
+ wsUrl: string;
500
+ address: string | null;
501
+ setAddress: (address: string | null) => void;
502
+ connectionStatus: ReadyState;
503
+ isConnected: boolean;
504
+ lastError: string | null;
505
+ nativeConnectionStatus: ReadyState;
506
+ nativeIsConnected: boolean;
507
+ nativeLastError: string | null;
508
+ authStatus: AuthStatus;
509
+ isAuthenticated: boolean;
510
+ accessToken: string | null;
511
+ user: UserProfile | null;
512
+ authError: string | null;
513
+ getEip712: (address: string) => Promise<any>;
514
+ loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
515
+ loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
516
+ refreshTokens: () => Promise<any>;
517
+ logout: () => Promise<void>;
518
+ agentWallet: AgentWalletState;
519
+ isAgentWalletReady: boolean;
520
+ agentWalletError: string | null;
521
+ agentWalletLoading: boolean;
522
+ refreshAgentWalletStatus: () => Promise<any>;
523
+ createAgentWallet: () => Promise<any>;
524
+ notifyAgentWalletApproved: () => Promise<any>;
525
+ }
774
526
  interface PearHyperliquidProviderProps {
775
- config: PearHyperliquidConfig;
776
- /**
777
- * WebSocket server URL
778
- * @default 'wss://hl-v2.pearprotocol.io/ws'
779
- */
780
- wsUrl?: string;
781
527
  children: ReactNode;
528
+ apiBaseUrl?: string;
529
+ clientId?: string;
530
+ wsUrl?: string;
782
531
  }
783
532
  /**
784
533
  * React Provider for PearHyperliquidClient
785
534
  */
786
535
  declare const PearHyperliquidProvider: React.FC<PearHyperliquidProviderProps>;
787
536
  /**
788
- * Hook to use PearHyperliquidClient from context
537
+ * Hook to access the entire Pear Hyperliquid context.
538
+ * Prefer using the more specific hooks below when possible.
539
+ */
540
+ declare function usePearHyperliquid(): PearHyperliquidContextType;
541
+ /**
542
+ * Provider-aware Auth hook. Uses auth state/actions provided by PearHyperliquidProvider.
543
+ * Callers do not need to pass baseUrl/clientId.
789
544
  */
790
- declare const usePearHyperliquidClient: () => PearHyperliquidClient;
545
+ declare function usePearAuth(): {
546
+ readonly status: AuthStatus;
547
+ readonly isAuthenticated: boolean;
548
+ readonly user: UserProfile | null;
549
+ readonly error: string | null;
550
+ readonly getEip712: (address: string) => Promise<any>;
551
+ readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
552
+ readonly loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
553
+ readonly refreshTokens: () => Promise<any>;
554
+ readonly logout: () => Promise<void>;
555
+ };
791
556
  /**
792
- * Hook to use migration SDK from context
557
+ * Provider-aware Agent Wallet hook. Uses agent wallet state/actions provided by PearHyperliquidProvider.
793
558
  */
794
- declare const useMigrationSDK: () => PearMigrationSDK;
559
+ declare function usePearAgentWallet(): {
560
+ readonly agentWallet: AgentWalletState;
561
+ readonly isReady: boolean;
562
+ readonly loading: boolean;
563
+ readonly error: string | null;
564
+ readonly refreshAgentWalletStatus: () => Promise<any>;
565
+ readonly createAgentWallet: () => Promise<any>;
566
+ readonly notifyAgentWalletApproved: () => Promise<any>;
567
+ };
795
568
 
796
569
  /**
797
570
  * Hook to manage address (login/logout functionality)
@@ -807,16 +580,6 @@ declare const useTradeHistories: () => {
807
580
  data: TradeHistoryDataDto[] | null;
808
581
  isLoading: boolean;
809
582
  };
810
- /**
811
- * Hook to access open positions with real-time calculations and loading state
812
- */
813
- declare const useOpenPositions: () => {
814
- data: null;
815
- isLoading: boolean;
816
- } | {
817
- data: OpenPositionDto[];
818
- isLoading: boolean;
819
- };
820
583
  /**
821
584
  * Hook to access open orders with loading state
822
585
  */
@@ -883,17 +646,33 @@ interface UseTokenSelectionMetadataReturn {
883
646
  }
884
647
  declare const useTokenSelectionMetadata: () => UseTokenSelectionMetadataReturn;
885
648
 
649
+ interface HistoricalRange {
650
+ start: number;
651
+ end: number;
652
+ }
653
+ interface TokenHistoricalPriceData {
654
+ symbol: string;
655
+ interval: CandleInterval;
656
+ candles: CandleData[];
657
+ oldestTime: number | null;
658
+ latestTime: number | null;
659
+ }
660
+ declare const useHistoricalPriceDataStore: any;
661
+
886
662
  interface UseHistoricalPriceDataReturn {
887
663
  fetchHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval, callback?: (data: Record<string, CandleData[]>) => void) => Promise<Record<string, CandleData[]>>;
888
664
  hasHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => boolean;
889
665
  getHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => Record<string, CandleData[]>;
666
+ getAllHistoricalPriceData(): Promise<Record<string, TokenHistoricalPriceData>>;
890
667
  isLoading: (symbol?: string) => boolean;
891
668
  clearCache: () => void;
892
669
  }
893
670
  declare const useHistoricalPriceData: () => UseHistoricalPriceDataReturn;
894
671
 
895
672
  interface UseBasketCandlesReturn {
896
- fetchBasketCandles: (startTime: number, endTime: number, interval: CandleInterval) => Promise<WeightedCandleData[]>;
673
+ fetchBasketCandles: (startTime: number, endTime: number, interval: CandleInterval) => Promise<CandleData[]>;
674
+ fetchPerformanceCandles: (startTime: number, endTime: number, interval: CandleInterval, symbol: string) => Promise<CandleData[]>;
675
+ fetchOverallPerformanceCandles: (startTime: number, endTime: number, interval: CandleInterval) => Promise<CandleData[]>;
897
676
  isLoading: boolean;
898
677
  addRealtimeListener: (cb: RealtimeBarsCallback) => string;
899
678
  removeRealtimeListener: (id: string) => void;
@@ -915,6 +694,120 @@ type RealtimeBarsCallback = (bar: RealtimeBar) => void;
915
694
  */
916
695
  declare const useBasketCandles: () => UseBasketCandlesReturn;
917
696
 
697
+ interface PerformanceOverlay {
698
+ id: string;
699
+ symbol: string;
700
+ label: string;
701
+ color: string;
702
+ enabled: boolean;
703
+ type: 'asset' | 'portfolio';
704
+ weight?: number;
705
+ }
706
+ interface UsePerformanceOverlaysReturn {
707
+ overlays: PerformanceOverlay[];
708
+ generateOverlaySymbols: () => string[];
709
+ }
710
+ declare const usePerformanceOverlays: () => UsePerformanceOverlaysReturn;
711
+
712
+ declare function useAuth(): {
713
+ readonly status: AuthStatus;
714
+ readonly isAuthenticated: boolean;
715
+ readonly accessToken: string | null;
716
+ readonly user: UserProfile | null;
717
+ readonly error: string | null;
718
+ readonly getEip712: (address: string) => Promise<any>;
719
+ readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
720
+ readonly loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
721
+ readonly refreshTokens: () => Promise<any>;
722
+ readonly logout: () => Promise<void>;
723
+ };
724
+
725
+ declare function useAgentWallet({ baseUrl }: UseAgentWalletOptions): {
726
+ readonly agentWallet: AgentWalletState;
727
+ readonly isReady: boolean;
728
+ readonly loading: false;
729
+ readonly error: null;
730
+ readonly refreshAgentWalletStatus: () => Promise<GetAgentWalletResponseDto>;
731
+ readonly createAgentWallet: () => Promise<CreateAgentWalletResponseDto>;
732
+ readonly notifyAgentWalletApproved: () => Promise<GetAgentWalletResponseDto>;
733
+ };
734
+
735
+ interface AutoSyncFillsOptions {
736
+ baseUrl: string;
737
+ accessToken: string;
738
+ address: string | null;
739
+ intervalMs?: number;
740
+ aggregateByTime?: boolean;
741
+ enabled?: boolean;
742
+ }
743
+ interface AutoSyncFillsState {
744
+ lastRunAt: number | null;
745
+ lastResult: SyncFillsResponseDto | null;
746
+ error: string | null;
747
+ isSyncing: boolean;
748
+ triggerSync: () => Promise<void>;
749
+ }
750
+ /**
751
+ * Listens to address changes and periodically syncs user fills
752
+ * Defaults: aggregate=true, interval=60s
753
+ */
754
+ declare function useAutoSyncFills(options: AutoSyncFillsOptions): AutoSyncFillsState;
755
+
756
+ type ExecutionType = 'MARKET' | 'LIMIT' | 'TWAP' | 'LADDER' | 'LIMIT_BTCDOM';
757
+ type TpSlThresholdType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
758
+ interface PairAssetInput {
759
+ asset: string;
760
+ weight?: number;
761
+ }
762
+ interface TpSlThresholdInput {
763
+ type: TpSlThresholdType;
764
+ value: number;
765
+ }
766
+ interface CreatePositionRequestInput {
767
+ slippage: number;
768
+ executionType: ExecutionType;
769
+ leverage: number;
770
+ usdValue: number;
771
+ longAssets?: PairAssetInput[];
772
+ shortAssets?: PairAssetInput[];
773
+ triggerValue?: number;
774
+ direction?: 'MORE_THAN' | 'LESS_THAN';
775
+ twapDuration?: number;
776
+ randomizeExecution?: boolean;
777
+ takeProfit?: TpSlThresholdInput | null;
778
+ stopLoss?: TpSlThresholdInput | null;
779
+ }
780
+ type PositionResponseStatus = 'SUCCESS' | 'FAILED' | 'PENDING' | 'PARTIALLY_FILLED' | 'OPEN';
781
+ interface PositionAssetSummaryDto {
782
+ asset: string;
783
+ side: 'LONG' | 'SHORT';
784
+ size: number;
785
+ entryRatio: number;
786
+ usdValue: number;
787
+ orderId: string;
788
+ }
789
+ interface CreatePositionResponseDto {
790
+ positionId: string | null;
791
+ orderId: string;
792
+ status: PositionResponseStatus;
793
+ createdAt: string;
794
+ assets?: PositionAssetSummaryDto[];
795
+ stopLoss?: TpSlThresholdInput | null;
796
+ takeProfit?: TpSlThresholdInput | null;
797
+ hyperliquidResult?: any;
798
+ }
799
+ /**
800
+ * Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
801
+ * Caller should supply an accessToken from localStorage.getItem('accessToken')
802
+ */
803
+ declare function createPosition(baseUrl: string, accessToken: string, payload: CreatePositionRequestInput): Promise<ApiResponse<CreatePositionResponseDto>>;
804
+
805
+ declare function usePosition(): {
806
+ readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
807
+ readonly openPositions: OpenPositionDto[] | null;
808
+ readonly isLoading: boolean;
809
+ };
810
+
918
811
  interface UseHyperliquidWebSocketProps {
919
812
  wsUrl: string;
920
813
  address: string | null;
@@ -1027,7 +920,7 @@ declare const getCompleteTimestamps: (candleLookups: Record<string, Map<number,
1027
920
  * Compute basket candles from individual token candles using weighted ratios
1028
921
  * Optimized version that creates lookup maps once and reuses them
1029
922
  */
1030
- declare const computeBasketCandles: (longTokens: TokenSelection[], shortTokens: TokenSelection[], tokenCandles: Record<string, CandleData[]>) => WeightedCandleData[];
923
+ declare const computeBasketCandles: (longTokens: TokenSelection[], shortTokens: TokenSelection[], tokenCandles: Record<string, CandleData[]>) => CandleData[];
1031
924
 
1032
925
  /**
1033
926
  * Maps TradingView ResolutionString to CandleInterval
@@ -1038,18 +931,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
1038
931
  */
1039
932
  declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
1040
933
 
1041
- interface HistoricalRange {
1042
- start: number;
1043
- end: number;
1044
- }
1045
- interface TokenHistoricalPriceData {
1046
- symbol: string;
1047
- interval: CandleInterval;
1048
- candles: CandleData[];
1049
- oldestTime: number | null;
1050
- latestTime: number | null;
1051
- }
1052
- declare const useHistoricalPriceDataStore: any;
1053
-
1054
- export { AccountSummaryCalculator, ConflictDetector, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, TokenMetadataExtractor, calculateWeightedRatio, computeBasketCandles, createCandleLookups, PearHyperliquidClient as default, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, useAccountSummary, useAddress, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTokenSelectionMetadata, useTradeHistories, useUserSelection, useWebData };
1055
- export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, 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, RealtimeBar, RealtimeBarsCallback, 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 };
934
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, calculateWeightedRatio, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useOpenOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useUserSelection, useWebData };
935
+ export type { AccountSummaryResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, MarginSummaryDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetInput, PerformanceOverlay, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, UniverseAsset, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };