@pear-protocol/hyperliquid-sdk 0.0.29 → 0.0.30

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.
@@ -1,4 +1,5 @@
1
1
  import type { ApiResponse } from '../types';
2
+ import type { CancelTwapResponseDto } from './orders';
2
3
  export type ExecutionType = 'MARKET' | 'LIMIT' | 'TWAP' | 'LADDER' | 'LIMIT_BTCDOM';
3
4
  export type TpSlThresholdType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
4
5
  export interface PairAssetInput {
@@ -9,6 +10,11 @@ export interface TpSlThresholdInput {
9
10
  type: TpSlThresholdType;
10
11
  value: number;
11
12
  }
13
+ export interface LadderConfigInput {
14
+ ratioStart: number;
15
+ ratioEnd: number;
16
+ numberOfLevels: number;
17
+ }
12
18
  export interface CreatePositionRequestInput {
13
19
  slippage: number;
14
20
  executionType: ExecutionType;
@@ -20,6 +26,7 @@ export interface CreatePositionRequestInput {
20
26
  direction?: 'MORE_THAN' | 'LESS_THAN';
21
27
  twapDuration?: number;
22
28
  randomizeExecution?: boolean;
29
+ ladderConfig?: LadderConfigInput;
23
30
  takeProfit?: TpSlThresholdInput | null;
24
31
  stopLoss?: TpSlThresholdInput | null;
25
32
  }
@@ -87,3 +94,4 @@ export interface AdjustPositionResponseDto {
87
94
  executedAt: string;
88
95
  }
89
96
  export declare function adjustPosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustPositionRequestInput): Promise<ApiResponse<AdjustPositionResponseDto>>;
97
+ export declare function cancelTwap(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
@@ -11,3 +11,4 @@ export * from './useAgentWallet';
11
11
  export * from './useAutoSyncFills';
12
12
  export * from './usePosition';
13
13
  export * from './useOrders';
14
+ export * from './useTwap';
@@ -0,0 +1,6 @@
1
+ import type { ApiResponse } from '../types';
2
+ import type { CancelTwapResponseDto } from '../clients/orders';
3
+ export declare function useTwap(): {
4
+ readonly orders: any;
5
+ readonly cancelTwap: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
6
+ };
package/dist/index.d.ts CHANGED
@@ -30,7 +30,7 @@ type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'e
30
30
  /**
31
31
  * WebSocket channels
32
32
  */
33
- type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'webData2' | 'allMids' | 'activeAssetData';
33
+ type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'webData2' | 'allMids' | 'activeAssetData';
34
34
  /**
35
35
  * WebSocket subscription message
36
36
  */
@@ -755,6 +755,30 @@ interface AutoSyncFillsState {
755
755
  */
756
756
  declare function useAutoSyncFills(options: AutoSyncFillsOptions): AutoSyncFillsState;
757
757
 
758
+ interface AdjustOrderRequestInput {
759
+ limitRatio?: number;
760
+ usdValue?: number;
761
+ }
762
+ interface AdjustOrderResponseDto {
763
+ orderId: string;
764
+ limitRatio: number;
765
+ usdValue: number;
766
+ updatedAt: string;
767
+ }
768
+ declare function adjustOrder(baseUrl: string, accessToken: string, orderId: string, payload: AdjustOrderRequestInput): Promise<ApiResponse<AdjustOrderResponseDto>>;
769
+ interface CancelOrderResponseDto {
770
+ orderId: string;
771
+ status: string;
772
+ cancelledAt: string;
773
+ }
774
+ declare function cancelOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelOrderResponseDto>>;
775
+ interface CancelTwapResponseDto {
776
+ orderId: string;
777
+ status: string;
778
+ cancelledAt: string;
779
+ }
780
+ declare function cancelTwapOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
781
+
758
782
  type ExecutionType = 'MARKET' | 'LIMIT' | 'TWAP' | 'LADDER' | 'LIMIT_BTCDOM';
759
783
  type TpSlThresholdType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
760
784
  interface PairAssetInput {
@@ -765,6 +789,11 @@ interface TpSlThresholdInput {
765
789
  type: TpSlThresholdType;
766
790
  value: number;
767
791
  }
792
+ interface LadderConfigInput {
793
+ ratioStart: number;
794
+ ratioEnd: number;
795
+ numberOfLevels: number;
796
+ }
768
797
  interface CreatePositionRequestInput {
769
798
  slippage: number;
770
799
  executionType: ExecutionType;
@@ -776,6 +805,7 @@ interface CreatePositionRequestInput {
776
805
  direction?: 'MORE_THAN' | 'LESS_THAN';
777
806
  twapDuration?: number;
778
807
  randomizeExecution?: boolean;
808
+ ladderConfig?: LadderConfigInput;
779
809
  takeProfit?: TpSlThresholdInput | null;
780
810
  stopLoss?: TpSlThresholdInput | null;
781
811
  }
@@ -843,6 +873,7 @@ interface AdjustPositionResponseDto {
843
873
  executedAt: string;
844
874
  }
845
875
  declare function adjustPosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustPositionRequestInput): Promise<ApiResponse<AdjustPositionResponseDto>>;
876
+ declare function cancelTwap(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
846
877
 
847
878
  declare function usePosition(): {
848
879
  readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
@@ -853,30 +884,6 @@ declare function usePosition(): {
853
884
  readonly isLoading: boolean;
854
885
  };
855
886
 
856
- interface AdjustOrderRequestInput {
857
- limitRatio?: number;
858
- usdValue?: number;
859
- }
860
- interface AdjustOrderResponseDto {
861
- orderId: string;
862
- limitRatio: number;
863
- usdValue: number;
864
- updatedAt: string;
865
- }
866
- declare function adjustOrder(baseUrl: string, accessToken: string, orderId: string, payload: AdjustOrderRequestInput): Promise<ApiResponse<AdjustOrderResponseDto>>;
867
- interface CancelOrderResponseDto {
868
- orderId: string;
869
- status: string;
870
- cancelledAt: string;
871
- }
872
- declare function cancelOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelOrderResponseDto>>;
873
- interface CancelTwapResponseDto {
874
- orderId: string;
875
- status: string;
876
- cancelledAt: string;
877
- }
878
- declare function cancelTwapOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
879
-
880
887
  declare function useOrders(): {
881
888
  readonly adjustOrder: (orderId: string, payload: AdjustOrderRequestInput) => Promise<ApiResponse<AdjustOrderResponseDto>>;
882
889
  readonly cancelOrder: (orderId: string) => Promise<ApiResponse<CancelOrderResponseDto>>;
@@ -885,6 +892,11 @@ declare function useOrders(): {
885
892
  readonly isLoading: boolean;
886
893
  };
887
894
 
895
+ declare function useTwap(): {
896
+ readonly orders: any;
897
+ readonly cancelTwap: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
898
+ };
899
+
888
900
  interface UseHyperliquidWebSocketProps {
889
901
  wsUrl: string;
890
902
  address: string | null;
@@ -1008,5 +1020,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
1008
1020
  */
1009
1021
  declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
1010
1022
 
1011
- export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useUserSelection, useWebData };
1012
- export type { AccountSummaryResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, MarginSummaryDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetInput, PerformanceOverlay, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
1023
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
1024
+ export type { AccountSummaryResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetInput, PerformanceOverlay, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
package/dist/index.js CHANGED
@@ -2433,20 +2433,23 @@ const useUserData = create((set) => ({
2433
2433
  rawOpenPositions: null,
2434
2434
  openOrders: null,
2435
2435
  accountSummary: null,
2436
+ twapDetails: null,
2436
2437
  setTradeHistories: (value) => set({ tradeHistories: value }),
2437
2438
  setRawOpenPositions: (value) => set({ rawOpenPositions: value }),
2438
2439
  setOpenOrders: (value) => set({ openOrders: value }),
2439
2440
  setAccountSummary: (value) => set({ accountSummary: value }),
2441
+ setTwapDetails: (value) => set({ twapDetails: value }),
2440
2442
  clean: () => set({
2441
2443
  tradeHistories: null,
2442
2444
  rawOpenPositions: null,
2443
2445
  openOrders: null,
2444
2446
  accountSummary: null,
2447
+ twapDetails: null,
2445
2448
  }),
2446
2449
  }));
2447
2450
 
2448
2451
  const useHyperliquidWebSocket = ({ wsUrl, address }) => {
2449
- const { setTradeHistories, setRawOpenPositions, setOpenOrders, setAccountSummary, clean } = useUserData();
2452
+ const { setTradeHistories, setRawOpenPositions, setOpenOrders, setAccountSummary, setTwapDetails, clean } = useUserData();
2450
2453
  const [lastError, setLastError] = useState(null);
2451
2454
  const [lastSubscribedAddress, setLastSubscribedAddress] = useState(null);
2452
2455
  // WebSocket connection
@@ -2487,6 +2490,10 @@ const useHyperliquidWebSocket = ({ wsUrl, address }) => {
2487
2490
  case 'account-summary':
2488
2491
  setAccountSummary(dataMessage.data);
2489
2492
  break;
2493
+ case 'twap-details':
2494
+ // @ts-ignore: setTwapDetails exists in store
2495
+ setTwapDetails && setTwapDetails(dataMessage.data);
2496
+ break;
2490
2497
  }
2491
2498
  }
2492
2499
  }
@@ -8291,6 +8298,18 @@ async function adjustPosition(baseUrl, accessToken, positionId, payload) {
8291
8298
  throw toApiError(error);
8292
8299
  }
8293
8300
  }
8301
+ // ---------------- Cancel TWAP (by orderId) ----------------
8302
+ // Convenience API colocated with position operations
8303
+ async function cancelTwap(baseUrl, accessToken, orderId) {
8304
+ const url = joinUrl(baseUrl, `/orders/${orderId}/twap/cancel`);
8305
+ try {
8306
+ const resp = await axios$1.post(url, {}, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
8307
+ return { data: resp.data, status: resp.status, headers: resp.headers };
8308
+ }
8309
+ catch (error) {
8310
+ throw toApiError(error);
8311
+ }
8312
+ }
8294
8313
 
8295
8314
  const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage, cumFunding, isLong = true) => {
8296
8315
  const initialPositionValue = asset.entryPrice * asset.size;
@@ -8502,6 +8521,21 @@ function useOrders() {
8502
8521
  return { adjustOrder: adjustOrder$1, cancelOrder: cancelOrder$1, cancelTwapOrder: cancelTwapOrder$1, openOrders: enrichedOpenOrders, isLoading };
8503
8522
  }
8504
8523
 
8524
+ function useTwap() {
8525
+ const twapDetails = useUserData(state => state.twapDetails);
8526
+ const context = useContext(PearHyperliquidContext);
8527
+ if (!context)
8528
+ throw new Error('useTwap must be used within a PearHyperliquidProvider');
8529
+ const { apiBaseUrl, accessToken } = context;
8530
+ const orders = useMemo(() => twapDetails !== null && twapDetails !== void 0 ? twapDetails : [], [twapDetails]);
8531
+ const cancelTwap$1 = async (orderId) => {
8532
+ if (!accessToken)
8533
+ throw new Error('Not authenticated');
8534
+ return cancelTwap(apiBaseUrl, accessToken, orderId);
8535
+ };
8536
+ return { orders, cancelTwap: cancelTwap$1 };
8537
+ }
8538
+
8505
8539
  const PearHyperliquidContext = createContext(undefined);
8506
8540
  /**
8507
8541
  * React Provider for PearHyperliquidClient
@@ -8800,4 +8834,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
8800
8834
  }
8801
8835
  }
8802
8836
 
8803
- export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useUserSelection, useWebData };
8837
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
package/dist/types.d.ts CHANGED
@@ -51,7 +51,7 @@ export type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnecte
51
51
  /**
52
52
  * WebSocket channels
53
53
  */
54
- export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'webData2' | 'allMids' | 'activeAssetData';
54
+ export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'webData2' | 'allMids' | 'activeAssetData';
55
55
  /**
56
56
  * WebSocket subscription message
57
57
  */
@@ -74,6 +74,44 @@ export interface WebSocketDataMessage<T = unknown> {
74
74
  channel: WebSocketChannel;
75
75
  data: T;
76
76
  }
77
+ export interface ChunkFillDto {
78
+ fillId: string;
79
+ assetName: string;
80
+ price: number;
81
+ size: number;
82
+ executedAt: string;
83
+ }
84
+ export type TwapChunkStatus = 'PENDING' | 'SCHEDULED' | 'EXECUTING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
85
+ export interface TwapChunkStatusDto {
86
+ chunkId: string;
87
+ chunkIndex: number;
88
+ scheduledTime: string;
89
+ executedTime?: string;
90
+ status: TwapChunkStatus;
91
+ chunkSize: number;
92
+ fills: ChunkFillDto[];
93
+ errorMessage?: string;
94
+ }
95
+ export type TwapOrderOverallStatus = 'OPEN' | 'EXECUTING' | 'COMPLETED' | 'PARTIALLY_COMPLETED' | 'FAILED' | 'CANCELLED';
96
+ export interface TwapMonitoringDto {
97
+ orderId: string;
98
+ positionId?: string;
99
+ address: string;
100
+ orderType: string;
101
+ status: TwapOrderOverallStatus;
102
+ totalUsdValue: number;
103
+ filledUsdValue: number;
104
+ remainingUsdValue: number;
105
+ twapDuration: string;
106
+ randomizeExecution: boolean;
107
+ reduceOnly: boolean;
108
+ chunks: TwapChunkStatusDto[];
109
+ estimatedCompletionTime?: string;
110
+ actualCompletionTime?: string;
111
+ remainingChunks: number;
112
+ createdAt: string;
113
+ updatedAt: string;
114
+ }
77
115
  /**
78
116
  * Trade history asset data
79
117
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",