@pear-protocol/hyperliquid-sdk 0.0.26 → 0.0.29
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/clients/orders.d.ts +24 -0
- package/dist/clients/positions.d.ts +40 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useOrders.d.ts +10 -0
- package/dist/hooks/usePosition.d.ts +4 -1
- package/dist/index.d.ts +79 -2
- package/dist/index.js +181 -44
- package/dist/store/userSelection.d.ts +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/dist/client.d.ts +0 -36
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ApiResponse } from '../types';
|
|
2
|
+
export interface AdjustOrderRequestInput {
|
|
3
|
+
limitRatio?: number;
|
|
4
|
+
usdValue?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AdjustOrderResponseDto {
|
|
7
|
+
orderId: string;
|
|
8
|
+
limitRatio: number;
|
|
9
|
+
usdValue: number;
|
|
10
|
+
updatedAt: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function adjustOrder(baseUrl: string, accessToken: string, orderId: string, payload: AdjustOrderRequestInput): Promise<ApiResponse<AdjustOrderResponseDto>>;
|
|
13
|
+
export interface CancelOrderResponseDto {
|
|
14
|
+
orderId: string;
|
|
15
|
+
status: string;
|
|
16
|
+
cancelledAt: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function cancelOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelOrderResponseDto>>;
|
|
19
|
+
export interface CancelTwapResponseDto {
|
|
20
|
+
orderId: string;
|
|
21
|
+
status: string;
|
|
22
|
+
cancelledAt: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function cancelTwapOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
@@ -47,3 +47,43 @@ export interface CreatePositionResponseDto {
|
|
|
47
47
|
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
48
48
|
*/
|
|
49
49
|
export declare function createPosition(baseUrl: string, accessToken: string, payload: CreatePositionRequestInput): Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
50
|
+
export interface UpdateRiskParametersRequestInput {
|
|
51
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
52
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
53
|
+
}
|
|
54
|
+
export interface UpdateRiskParametersResponseDto {
|
|
55
|
+
positionId: string;
|
|
56
|
+
stopLoss: TpSlThresholdInput | null;
|
|
57
|
+
takeProfit: TpSlThresholdInput | null;
|
|
58
|
+
updatedAt: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function updateRiskParameters(baseUrl: string, accessToken: string, positionId: string, payload: UpdateRiskParametersRequestInput): Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
61
|
+
export type CloseExecutionType = 'MARKET' | 'TWAP';
|
|
62
|
+
export interface ClosePositionRequestInput {
|
|
63
|
+
executionType: CloseExecutionType;
|
|
64
|
+
twapDuration?: number;
|
|
65
|
+
randomizeExecution?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface ClosePositionResponseDto {
|
|
68
|
+
orderId: string;
|
|
69
|
+
executionTime?: string;
|
|
70
|
+
chunksScheduled?: number;
|
|
71
|
+
}
|
|
72
|
+
export declare function closePosition(baseUrl: string, accessToken: string, positionId: string, payload: ClosePositionRequestInput): Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
73
|
+
export type AdjustExecutionType = 'MARKET' | 'LIMIT';
|
|
74
|
+
export type PositionAdjustmentType = 'REDUCE' | 'INCREASE';
|
|
75
|
+
export interface AdjustPositionRequestInput {
|
|
76
|
+
adjustmentType: PositionAdjustmentType;
|
|
77
|
+
adjustmentSize: number;
|
|
78
|
+
executionType: AdjustExecutionType;
|
|
79
|
+
limitRatio?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface AdjustPositionResponseDto {
|
|
82
|
+
orderId: string;
|
|
83
|
+
status: string;
|
|
84
|
+
adjustmentType: PositionAdjustmentType;
|
|
85
|
+
adjustmentSize: number;
|
|
86
|
+
newSize: number;
|
|
87
|
+
executedAt: string;
|
|
88
|
+
}
|
|
89
|
+
export declare function adjustPosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustPositionRequestInput): Promise<ApiResponse<AdjustPositionResponseDto>>;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ApiResponse } from '../types';
|
|
2
|
+
import type { OpenLimitOrderDto } from '../types';
|
|
3
|
+
import { type AdjustOrderRequestInput, type AdjustOrderResponseDto, type CancelOrderResponseDto, type CancelTwapResponseDto } from '../clients/orders';
|
|
4
|
+
export declare function useOrders(): {
|
|
5
|
+
readonly adjustOrder: (orderId: string, payload: AdjustOrderRequestInput) => Promise<ApiResponse<AdjustOrderResponseDto>>;
|
|
6
|
+
readonly cancelOrder: (orderId: string) => Promise<ApiResponse<CancelOrderResponseDto>>;
|
|
7
|
+
readonly cancelTwapOrder: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
8
|
+
readonly openOrders: OpenLimitOrderDto[] | null;
|
|
9
|
+
readonly isLoading: boolean;
|
|
10
|
+
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { type CreatePositionRequestInput, type CreatePositionResponseDto } from '../clients/positions';
|
|
1
|
+
import { type CreatePositionRequestInput, type CreatePositionResponseDto, type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type AdjustPositionRequestInput, type AdjustPositionResponseDto } from '../clients/positions';
|
|
2
2
|
import type { ApiResponse, OpenPositionDto } from '../types';
|
|
3
3
|
export declare function usePosition(): {
|
|
4
4
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
5
|
+
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
6
|
+
readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
7
|
+
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
5
8
|
readonly openPositions: OpenPositionDto[] | null;
|
|
6
9
|
readonly isLoading: boolean;
|
|
7
10
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ interface WebSocketDataMessage<T = unknown> {
|
|
|
58
58
|
*/
|
|
59
59
|
interface TradeHistoryAssetDataDto {
|
|
60
60
|
coin: string;
|
|
61
|
+
entryWeight: number;
|
|
61
62
|
entryPrice: number;
|
|
62
63
|
limitPrice: number;
|
|
63
64
|
size: number;
|
|
@@ -615,6 +616,7 @@ interface UserSelectionState {
|
|
|
615
616
|
addToken: (isLong: boolean) => void;
|
|
616
617
|
removeToken: (isLong: boolean, index: number) => void;
|
|
617
618
|
handleTokenSelect: (selectedToken: string) => void;
|
|
619
|
+
setTokenSelections: (longTokens: TokenSelection[], shortTokens: TokenSelection[]) => void;
|
|
618
620
|
resetToDefaults: () => void;
|
|
619
621
|
}
|
|
620
622
|
|
|
@@ -801,13 +803,88 @@ interface CreatePositionResponseDto {
|
|
|
801
803
|
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
802
804
|
*/
|
|
803
805
|
declare function createPosition(baseUrl: string, accessToken: string, payload: CreatePositionRequestInput): Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
806
|
+
interface UpdateRiskParametersRequestInput {
|
|
807
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
808
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
809
|
+
}
|
|
810
|
+
interface UpdateRiskParametersResponseDto {
|
|
811
|
+
positionId: string;
|
|
812
|
+
stopLoss: TpSlThresholdInput | null;
|
|
813
|
+
takeProfit: TpSlThresholdInput | null;
|
|
814
|
+
updatedAt: string;
|
|
815
|
+
}
|
|
816
|
+
declare function updateRiskParameters(baseUrl: string, accessToken: string, positionId: string, payload: UpdateRiskParametersRequestInput): Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
817
|
+
type CloseExecutionType = 'MARKET' | 'TWAP';
|
|
818
|
+
interface ClosePositionRequestInput {
|
|
819
|
+
executionType: CloseExecutionType;
|
|
820
|
+
twapDuration?: number;
|
|
821
|
+
randomizeExecution?: boolean;
|
|
822
|
+
}
|
|
823
|
+
interface ClosePositionResponseDto {
|
|
824
|
+
orderId: string;
|
|
825
|
+
executionTime?: string;
|
|
826
|
+
chunksScheduled?: number;
|
|
827
|
+
}
|
|
828
|
+
declare function closePosition(baseUrl: string, accessToken: string, positionId: string, payload: ClosePositionRequestInput): Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
829
|
+
type AdjustExecutionType = 'MARKET' | 'LIMIT';
|
|
830
|
+
type PositionAdjustmentType = 'REDUCE' | 'INCREASE';
|
|
831
|
+
interface AdjustPositionRequestInput {
|
|
832
|
+
adjustmentType: PositionAdjustmentType;
|
|
833
|
+
adjustmentSize: number;
|
|
834
|
+
executionType: AdjustExecutionType;
|
|
835
|
+
limitRatio?: number;
|
|
836
|
+
}
|
|
837
|
+
interface AdjustPositionResponseDto {
|
|
838
|
+
orderId: string;
|
|
839
|
+
status: string;
|
|
840
|
+
adjustmentType: PositionAdjustmentType;
|
|
841
|
+
adjustmentSize: number;
|
|
842
|
+
newSize: number;
|
|
843
|
+
executedAt: string;
|
|
844
|
+
}
|
|
845
|
+
declare function adjustPosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustPositionRequestInput): Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
804
846
|
|
|
805
847
|
declare function usePosition(): {
|
|
806
848
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
849
|
+
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
850
|
+
readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
851
|
+
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
807
852
|
readonly openPositions: OpenPositionDto[] | null;
|
|
808
853
|
readonly isLoading: boolean;
|
|
809
854
|
};
|
|
810
855
|
|
|
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
|
+
declare function useOrders(): {
|
|
881
|
+
readonly adjustOrder: (orderId: string, payload: AdjustOrderRequestInput) => Promise<ApiResponse<AdjustOrderResponseDto>>;
|
|
882
|
+
readonly cancelOrder: (orderId: string) => Promise<ApiResponse<CancelOrderResponseDto>>;
|
|
883
|
+
readonly cancelTwapOrder: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
884
|
+
readonly openOrders: OpenLimitOrderDto[] | null;
|
|
885
|
+
readonly isLoading: boolean;
|
|
886
|
+
};
|
|
887
|
+
|
|
811
888
|
interface UseHyperliquidWebSocketProps {
|
|
812
889
|
wsUrl: string;
|
|
813
890
|
address: string | null;
|
|
@@ -931,5 +1008,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
931
1008
|
*/
|
|
932
1009
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
933
1010
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -2705,6 +2705,19 @@ const useUserSelection$1 = create((set, get) => ({
|
|
|
2705
2705
|
}
|
|
2706
2706
|
});
|
|
2707
2707
|
},
|
|
2708
|
+
setTokenSelections: (longTokens, shortTokens) => {
|
|
2709
|
+
set((prev) => {
|
|
2710
|
+
const longTotal = longTokens.reduce((s, t) => s + t.weight, 0);
|
|
2711
|
+
const shortTotal = shortTokens.reduce((s, t) => s + t.weight, 0);
|
|
2712
|
+
const isWeightBalanced = longTotal + shortTotal === 100;
|
|
2713
|
+
return {
|
|
2714
|
+
...prev,
|
|
2715
|
+
longTokens,
|
|
2716
|
+
shortTokens,
|
|
2717
|
+
isWeightBalanced,
|
|
2718
|
+
};
|
|
2719
|
+
});
|
|
2720
|
+
},
|
|
2708
2721
|
resetToDefaults: () => set((prev) => ({ ...prev, ...DEFAULT_STATE })),
|
|
2709
2722
|
}));
|
|
2710
2723
|
|
|
@@ -6883,7 +6896,7 @@ function useAgentWallet({ baseUrl }) {
|
|
|
6883
6896
|
const setAccountSummary = useUserData((state) => state.setAccountSummary);
|
|
6884
6897
|
const agentWallet = {
|
|
6885
6898
|
address: ((_a = accountSummary === null || accountSummary === void 0 ? void 0 : accountSummary.agentWallet) === null || _a === void 0 ? void 0 : _a.address) || null,
|
|
6886
|
-
name: '
|
|
6899
|
+
name: 'Pear Protocol',
|
|
6887
6900
|
status: ((_b = accountSummary === null || accountSummary === void 0 ? void 0 : accountSummary.agentWallet) === null || _b === void 0 ? void 0 : _b.status) || null,
|
|
6888
6901
|
isActive: ((_c = accountSummary === null || accountSummary === void 0 ? void 0 : accountSummary.agentWallet) === null || _c === void 0 ? void 0 : _c.status) === 'ACTIVE',
|
|
6889
6902
|
};
|
|
@@ -7297,14 +7310,14 @@ const useTokenSelectionMetadataStore = create((set) => ({
|
|
|
7297
7310
|
const metadata = longTokensMetadata[token.symbol];
|
|
7298
7311
|
if ((metadata === null || metadata === void 0 ? void 0 : metadata.netFunding) && token.weight > 0) {
|
|
7299
7312
|
const weightFactor = token.weight / 100;
|
|
7300
|
-
totalFunding += metadata.netFunding * weightFactor;
|
|
7313
|
+
totalFunding += -metadata.netFunding * weightFactor;
|
|
7301
7314
|
}
|
|
7302
7315
|
});
|
|
7303
7316
|
shortTokens.forEach((token) => {
|
|
7304
7317
|
const metadata = shortTokensMetadata[token.symbol];
|
|
7305
7318
|
if ((metadata === null || metadata === void 0 ? void 0 : metadata.netFunding) && token.weight > 0) {
|
|
7306
7319
|
const weightFactor = token.weight / 100;
|
|
7307
|
-
totalFunding
|
|
7320
|
+
totalFunding += metadata.netFunding * weightFactor;
|
|
7308
7321
|
}
|
|
7309
7322
|
});
|
|
7310
7323
|
return totalFunding;
|
|
@@ -7522,35 +7535,33 @@ const useHistoricalPriceDataStore = create((set, get) => ({
|
|
|
7522
7535
|
}));
|
|
7523
7536
|
|
|
7524
7537
|
/**
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
* @param startTime - Start time in milliseconds
|
|
7528
|
-
* @param endTime - End time in milliseconds
|
|
7529
|
-
* @param interval - Candle interval
|
|
7530
|
-
* @returns Promise with historical candle data
|
|
7531
|
-
*/
|
|
7538
|
+
* Fetch historical candle data from HyperLiquid API
|
|
7539
|
+
*/
|
|
7532
7540
|
const fetchHistoricalCandles = async (coin, startTime, endTime, interval) => {
|
|
7533
7541
|
const request = {
|
|
7534
|
-
req: {
|
|
7535
|
-
|
|
7536
|
-
startTime,
|
|
7537
|
-
endTime,
|
|
7538
|
-
interval
|
|
7539
|
-
},
|
|
7540
|
-
type: "candleSnapshot"
|
|
7542
|
+
req: { coin, startTime, endTime, interval },
|
|
7543
|
+
type: 'candleSnapshot',
|
|
7541
7544
|
};
|
|
7542
7545
|
try {
|
|
7543
7546
|
const response = await axios$1.post('https://api.hyperliquid.xyz/info', request, {
|
|
7544
|
-
headers: {
|
|
7545
|
-
'Content-Type': 'application/json',
|
|
7546
|
-
},
|
|
7547
|
-
timeout: 30000,
|
|
7547
|
+
headers: { 'Content-Type': 'application/json' },
|
|
7548
7548
|
});
|
|
7549
|
-
return {
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7549
|
+
return { data: response.data, status: response.status, headers: response.headers };
|
|
7550
|
+
}
|
|
7551
|
+
catch (error) {
|
|
7552
|
+
throw toApiError(error);
|
|
7553
|
+
}
|
|
7554
|
+
};
|
|
7555
|
+
/**
|
|
7556
|
+
* Retrieve recent user fills from HyperLiquid and map to ExternalFillDto[]
|
|
7557
|
+
*/
|
|
7558
|
+
const fetchUserFillsFromHyperliquid = async (user, aggregateByTime = true) => {
|
|
7559
|
+
const request = { type: 'userFills', user, aggregateByTime };
|
|
7560
|
+
try {
|
|
7561
|
+
const response = await axios$1.post('https://api.hyperliquid.xyz/info', request, {
|
|
7562
|
+
headers: { 'Content-Type': 'application/json' },
|
|
7563
|
+
});
|
|
7564
|
+
return { data: response.data, status: response.status, headers: response.headers };
|
|
7554
7565
|
}
|
|
7555
7566
|
catch (error) {
|
|
7556
7567
|
throw toApiError(error);
|
|
@@ -8144,22 +8155,6 @@ function useAuth() {
|
|
|
8144
8155
|
};
|
|
8145
8156
|
}
|
|
8146
8157
|
|
|
8147
|
-
/**
|
|
8148
|
-
* Retrieve recent user fills from HyperLiquid and map to ExternalFillDto[]
|
|
8149
|
-
*/
|
|
8150
|
-
const fetchUserFillsFromHyperliquid = async (user, aggregateByTime = true) => {
|
|
8151
|
-
const request = { type: 'userFills', user, aggregateByTime };
|
|
8152
|
-
try {
|
|
8153
|
-
const response = await axios$1.post('https://api.hyperliquid.xyz/info', request, {
|
|
8154
|
-
headers: { 'Content-Type': 'application/json' },
|
|
8155
|
-
});
|
|
8156
|
-
return { data: response.data, status: response.status, headers: response.headers };
|
|
8157
|
-
}
|
|
8158
|
-
catch (error) {
|
|
8159
|
-
throw toApiError(error);
|
|
8160
|
-
}
|
|
8161
|
-
};
|
|
8162
|
-
|
|
8163
8158
|
/**
|
|
8164
8159
|
* Sync external fills into Pear Hyperliquid service (POST /sync/fills)
|
|
8165
8160
|
*/
|
|
@@ -8266,6 +8261,36 @@ async function createPosition(baseUrl, accessToken, payload) {
|
|
|
8266
8261
|
throw toApiError(error);
|
|
8267
8262
|
}
|
|
8268
8263
|
}
|
|
8264
|
+
async function updateRiskParameters(baseUrl, accessToken, positionId, payload) {
|
|
8265
|
+
const url = joinUrl(baseUrl, `/positions/${positionId}/riskParameters`);
|
|
8266
|
+
try {
|
|
8267
|
+
const resp = await axios$1.put(url, payload, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
|
|
8268
|
+
return { data: resp.data, status: resp.status, headers: resp.headers };
|
|
8269
|
+
}
|
|
8270
|
+
catch (error) {
|
|
8271
|
+
throw toApiError(error);
|
|
8272
|
+
}
|
|
8273
|
+
}
|
|
8274
|
+
async function closePosition(baseUrl, accessToken, positionId, payload) {
|
|
8275
|
+
const url = joinUrl(baseUrl, `/positions/${positionId}/close`);
|
|
8276
|
+
try {
|
|
8277
|
+
const resp = await axios$1.post(url, payload, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
|
|
8278
|
+
return { data: resp.data, status: resp.status, headers: resp.headers };
|
|
8279
|
+
}
|
|
8280
|
+
catch (error) {
|
|
8281
|
+
throw toApiError(error);
|
|
8282
|
+
}
|
|
8283
|
+
}
|
|
8284
|
+
async function adjustPosition(baseUrl, accessToken, positionId, payload) {
|
|
8285
|
+
const url = joinUrl(baseUrl, `/positions/${positionId}/adjust`);
|
|
8286
|
+
try {
|
|
8287
|
+
const resp = await axios$1.post(url, payload, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
|
|
8288
|
+
return { data: resp.data, status: resp.status, headers: resp.headers };
|
|
8289
|
+
}
|
|
8290
|
+
catch (error) {
|
|
8291
|
+
throw toApiError(error);
|
|
8292
|
+
}
|
|
8293
|
+
}
|
|
8269
8294
|
|
|
8270
8295
|
const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage, cumFunding, isLong = true) => {
|
|
8271
8296
|
const initialPositionValue = asset.entryPrice * asset.size;
|
|
@@ -8302,6 +8327,8 @@ const buildPositionValue = (rawPositions, webData2, allMids) => {
|
|
|
8302
8327
|
unrealizedPnl: 0,
|
|
8303
8328
|
netFunding: 0,
|
|
8304
8329
|
positionValue: 0,
|
|
8330
|
+
takeProfit: position.takeProfit,
|
|
8331
|
+
stopLoss: position.stopLoss,
|
|
8305
8332
|
};
|
|
8306
8333
|
const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0) +
|
|
8307
8334
|
position.shortAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0);
|
|
@@ -8350,6 +8377,24 @@ function usePosition() {
|
|
|
8350
8377
|
throw new Error('Not authenticated');
|
|
8351
8378
|
return createPosition(apiBaseUrl, accessToken, payload);
|
|
8352
8379
|
};
|
|
8380
|
+
// Update TP/SL risk parameters for a position
|
|
8381
|
+
const updateRiskParameters$1 = async (positionId, payload) => {
|
|
8382
|
+
if (!accessToken)
|
|
8383
|
+
throw new Error('Not authenticated');
|
|
8384
|
+
return updateRiskParameters(apiBaseUrl, accessToken, positionId, payload);
|
|
8385
|
+
};
|
|
8386
|
+
// Close a position (MARKET or TWAP)
|
|
8387
|
+
const closePosition$1 = async (positionId, payload) => {
|
|
8388
|
+
if (!accessToken)
|
|
8389
|
+
throw new Error('Not authenticated');
|
|
8390
|
+
return closePosition(apiBaseUrl, accessToken, positionId, payload);
|
|
8391
|
+
};
|
|
8392
|
+
// Adjust a position (REDUCE/INCREASE by %; MARKET or LIMIT)
|
|
8393
|
+
const adjustPosition$1 = async (positionId, payload) => {
|
|
8394
|
+
if (!accessToken)
|
|
8395
|
+
throw new Error('Not authenticated');
|
|
8396
|
+
return adjustPosition(apiBaseUrl, accessToken, positionId, payload);
|
|
8397
|
+
};
|
|
8353
8398
|
// Open positions using WS data, with derived values
|
|
8354
8399
|
const userOpenPositions = useUserData((state) => state.rawOpenPositions);
|
|
8355
8400
|
const webData2 = useHyperliquidData((state) => state.webData2);
|
|
@@ -8362,7 +8407,99 @@ function usePosition() {
|
|
|
8362
8407
|
return null;
|
|
8363
8408
|
return buildPositionValue(userOpenPositions, webData2, allMids);
|
|
8364
8409
|
}, [userOpenPositions, webData2, allMids]);
|
|
8365
|
-
return { createPosition: createPosition$1, openPositions, isLoading };
|
|
8410
|
+
return { createPosition: createPosition$1, updateRiskParameters: updateRiskParameters$1, closePosition: closePosition$1, adjustPosition: adjustPosition$1, openPositions, isLoading };
|
|
8411
|
+
}
|
|
8412
|
+
|
|
8413
|
+
async function adjustOrder(baseUrl, accessToken, orderId, payload) {
|
|
8414
|
+
const url = joinUrl(baseUrl, `/orders/${orderId}/adjust`);
|
|
8415
|
+
try {
|
|
8416
|
+
const resp = await axios$1.put(url, payload, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
|
|
8417
|
+
return { data: resp.data, status: resp.status, headers: resp.headers };
|
|
8418
|
+
}
|
|
8419
|
+
catch (error) {
|
|
8420
|
+
throw toApiError(error);
|
|
8421
|
+
}
|
|
8422
|
+
}
|
|
8423
|
+
async function cancelOrder(baseUrl, accessToken, orderId) {
|
|
8424
|
+
const url = joinUrl(baseUrl, `/orders/${orderId}/cancel`);
|
|
8425
|
+
try {
|
|
8426
|
+
const resp = await axios$1.delete(url, { headers: { Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
|
|
8427
|
+
return { data: resp.data, status: resp.status, headers: resp.headers };
|
|
8428
|
+
}
|
|
8429
|
+
catch (error) {
|
|
8430
|
+
throw toApiError(error);
|
|
8431
|
+
}
|
|
8432
|
+
}
|
|
8433
|
+
async function cancelTwapOrder(baseUrl, accessToken, orderId) {
|
|
8434
|
+
const url = joinUrl(baseUrl, `/orders/${orderId}/twap/cancel`);
|
|
8435
|
+
try {
|
|
8436
|
+
const resp = await axios$1.post(url, {}, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
|
|
8437
|
+
return { data: resp.data, status: resp.status, headers: resp.headers };
|
|
8438
|
+
}
|
|
8439
|
+
catch (error) {
|
|
8440
|
+
throw toApiError(error);
|
|
8441
|
+
}
|
|
8442
|
+
}
|
|
8443
|
+
|
|
8444
|
+
function useOrders() {
|
|
8445
|
+
const context = useContext(PearHyperliquidContext);
|
|
8446
|
+
if (!context)
|
|
8447
|
+
throw new Error('useOrders must be used within a PearHyperliquidProvider');
|
|
8448
|
+
const { apiBaseUrl, accessToken } = context;
|
|
8449
|
+
const openOrders = useUserData((state) => state.openOrders);
|
|
8450
|
+
const isLoading = useMemo(() => openOrders === null && context.isConnected, [openOrders, context.isConnected]);
|
|
8451
|
+
const { openPositions } = usePosition();
|
|
8452
|
+
const positionsById = useMemo(() => {
|
|
8453
|
+
const map = new Map();
|
|
8454
|
+
if (openPositions) {
|
|
8455
|
+
for (const p of openPositions)
|
|
8456
|
+
map.set(p.positionId, p);
|
|
8457
|
+
}
|
|
8458
|
+
return map;
|
|
8459
|
+
}, [openPositions]);
|
|
8460
|
+
const enrichedOpenOrders = useMemo(() => {
|
|
8461
|
+
if (!openOrders)
|
|
8462
|
+
return null;
|
|
8463
|
+
return openOrders.map((ord) => {
|
|
8464
|
+
var _a, _b, _c, _d;
|
|
8465
|
+
const isTpSl = ord.orderType === 'TP' || ord.orderType === 'SL';
|
|
8466
|
+
const hasAssets = ((_b = (_a = ord.longAssets) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 || ((_d = (_c = ord.shortAssets) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 0;
|
|
8467
|
+
const pos = positionsById.get(ord.positionId);
|
|
8468
|
+
if (!isTpSl || !pos)
|
|
8469
|
+
return ord;
|
|
8470
|
+
// Build order assets from position weights when TP/SL has no assets
|
|
8471
|
+
const mapAssets = (arr) => arr.map((a) => ({ asset: a.coin, weight: a.initialWeight }));
|
|
8472
|
+
if (!hasAssets) {
|
|
8473
|
+
return {
|
|
8474
|
+
...ord,
|
|
8475
|
+
leverage: pos.leverage,
|
|
8476
|
+
longAssets: mapAssets(pos.longAssets),
|
|
8477
|
+
shortAssets: mapAssets(pos.shortAssets),
|
|
8478
|
+
};
|
|
8479
|
+
}
|
|
8480
|
+
// Always sync leverage from position for TP/SL
|
|
8481
|
+
if (ord.leverage !== pos.leverage) {
|
|
8482
|
+
return { ...ord, leverage: pos.leverage };
|
|
8483
|
+
}
|
|
8484
|
+
return ord;
|
|
8485
|
+
});
|
|
8486
|
+
}, [openOrders, positionsById]);
|
|
8487
|
+
const adjustOrder$1 = async (orderId, payload) => {
|
|
8488
|
+
if (!accessToken)
|
|
8489
|
+
throw new Error('Not authenticated');
|
|
8490
|
+
return adjustOrder(apiBaseUrl, accessToken, orderId, payload);
|
|
8491
|
+
};
|
|
8492
|
+
const cancelOrder$1 = async (orderId) => {
|
|
8493
|
+
if (!accessToken)
|
|
8494
|
+
throw new Error('Not authenticated');
|
|
8495
|
+
return cancelOrder(apiBaseUrl, accessToken, orderId);
|
|
8496
|
+
};
|
|
8497
|
+
const cancelTwapOrder$1 = async (orderId) => {
|
|
8498
|
+
if (!accessToken)
|
|
8499
|
+
throw new Error('Not authenticated');
|
|
8500
|
+
return cancelTwapOrder(apiBaseUrl, accessToken, orderId);
|
|
8501
|
+
};
|
|
8502
|
+
return { adjustOrder: adjustOrder$1, cancelOrder: cancelOrder$1, cancelTwapOrder: cancelTwapOrder$1, openOrders: enrichedOpenOrders, isLoading };
|
|
8366
8503
|
}
|
|
8367
8504
|
|
|
8368
8505
|
const PearHyperliquidContext = createContext(undefined);
|
|
@@ -8663,4 +8800,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
8663
8800
|
}
|
|
8664
8801
|
}
|
|
8665
8802
|
|
|
8666
|
-
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 };
|
|
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 };
|
|
@@ -19,6 +19,7 @@ interface UserSelectionState {
|
|
|
19
19
|
addToken: (isLong: boolean) => void;
|
|
20
20
|
removeToken: (isLong: boolean, index: number) => void;
|
|
21
21
|
handleTokenSelect: (selectedToken: string) => void;
|
|
22
|
+
setTokenSelections: (longTokens: TokenSelection[], shortTokens: TokenSelection[]) => void;
|
|
22
23
|
resetToDefaults: () => void;
|
|
23
24
|
}
|
|
24
25
|
export declare const useUserSelection: any;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/dist/client.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ApiResponse, CandleInterval, CandleData, SyncFillsRequestDto, SyncFillsResponseDto, ExternalFillDto, GetEIP712MessageResponse, AuthenticateRequest, AuthenticateResponse, RefreshTokenResponse, LogoutResponse, GetAgentWalletResponseDto, CreateAgentWalletResponseDto } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Fetch historical candle data from HyperLiquid API
|
|
4
|
-
* @param coin - Token symbol (e.g., 'BTC', 'ETH')
|
|
5
|
-
* @param startTime - Start time in milliseconds
|
|
6
|
-
* @param endTime - End time in milliseconds
|
|
7
|
-
* @param interval - Candle interval
|
|
8
|
-
* @returns Promise with historical candle data
|
|
9
|
-
*/
|
|
10
|
-
export declare const fetchHistoricalCandles: (coin: string, startTime: number, endTime: number, interval: CandleInterval) => Promise<ApiResponse<CandleData[]>>;
|
|
11
|
-
/**
|
|
12
|
-
* Retrieve recent fills for a user from HyperLiquid and map to ExternalFillDto[]
|
|
13
|
-
* @param user - EVM address (0x...)
|
|
14
|
-
* @param aggregateByTime - Combine partial fills for the same crossing order
|
|
15
|
-
*/
|
|
16
|
-
export declare const fetchUserFillsFromHyperliquid: (user: string, aggregateByTime?: boolean) => Promise<ApiResponse<ExternalFillDto[]>>;
|
|
17
|
-
/**
|
|
18
|
-
* Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
|
|
19
|
-
* Returns the Pear backend SyncFillsResponseDto
|
|
20
|
-
*/
|
|
21
|
-
export declare const syncUserFillsFromHyperliquid: (baseUrl: string, accessToken: string, user: string, aggregateByTime?: boolean) => Promise<ApiResponse<SyncFillsResponseDto>>;
|
|
22
|
-
export declare function getEIP712Message(baseUrl: string, address: string, clientId: string): Promise<ApiResponse<GetEIP712MessageResponse>>;
|
|
23
|
-
export declare function authenticate(baseUrl: string, body: AuthenticateRequest): Promise<ApiResponse<AuthenticateResponse>>;
|
|
24
|
-
export declare function refreshToken(baseUrl: string, refreshTokenVal: string): Promise<ApiResponse<RefreshTokenResponse>>;
|
|
25
|
-
export declare function logout(baseUrl: string, refreshTokenVal: string): Promise<ApiResponse<LogoutResponse>>;
|
|
26
|
-
export declare function getAgentWallet(baseUrl: string, accessToken: string): Promise<ApiResponse<GetAgentWalletResponseDto>>;
|
|
27
|
-
export declare function createAgentWallet(baseUrl: string, accessToken: string): Promise<ApiResponse<CreateAgentWalletResponseDto>>;
|
|
28
|
-
/**
|
|
29
|
-
* Sync external fills into Pear Hyperliquid service
|
|
30
|
-
* Mirrors POST /sync/fills in pear-hyperliquid service
|
|
31
|
-
* @param baseUrl - Base URL of Pear Hyperliquid API (e.g., 'http://localhost:3000')
|
|
32
|
-
* @param accessToken - Bearer access token for Authorization header
|
|
33
|
-
* @param payload - Sync fills request body
|
|
34
|
-
* @returns Promise with sync result summary
|
|
35
|
-
*/
|
|
36
|
-
export declare const syncFills: (baseUrl: string, accessToken: string, payload: SyncFillsRequestDto) => Promise<ApiResponse<SyncFillsResponseDto>>;
|