@pear-protocol/hyperliquid-sdk 0.0.60-beta-usdh → 0.0.60-beta-usdh-2
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 +41 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useSpotOrder.d.ts +13 -0
- package/dist/index.d.ts +57 -2
- package/dist/index.js +137 -7
- package/dist/types.d.ts +2 -0
- package/package.json +1 -2
package/dist/clients/orders.d.ts
CHANGED
|
@@ -22,3 +22,44 @@ export interface CancelTwapResponseDto {
|
|
|
22
22
|
cancelledAt: string;
|
|
23
23
|
}
|
|
24
24
|
export declare function cancelTwapOrder(baseUrl: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
25
|
+
export interface SpotOrderRequestInput {
|
|
26
|
+
/** Asset to buy/sell (e.g., "USDH") */
|
|
27
|
+
asset: string;
|
|
28
|
+
/** Whether to buy (true) or sell (false) the asset */
|
|
29
|
+
isBuy: boolean;
|
|
30
|
+
/** Amount of asset to buy/sell (minimum: 11) */
|
|
31
|
+
amount: number;
|
|
32
|
+
}
|
|
33
|
+
/** Filled order status from Hyperliquid */
|
|
34
|
+
export interface SpotOrderFilledStatus {
|
|
35
|
+
filled: {
|
|
36
|
+
totalSz: string;
|
|
37
|
+
avgPx: string;
|
|
38
|
+
oid: number;
|
|
39
|
+
cloid: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Hyperliquid order response data */
|
|
43
|
+
export interface SpotOrderHyperliquidData {
|
|
44
|
+
statuses: SpotOrderFilledStatus[];
|
|
45
|
+
}
|
|
46
|
+
/** Hyperliquid result from spot order execution */
|
|
47
|
+
export interface SpotOrderHyperliquidResult {
|
|
48
|
+
status: 'ok' | 'error';
|
|
49
|
+
response: {
|
|
50
|
+
type: 'order';
|
|
51
|
+
data: SpotOrderHyperliquidData;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface SpotOrderResponseDto {
|
|
55
|
+
orderId: string;
|
|
56
|
+
status: 'EXECUTED' | 'FAILED' | 'PENDING';
|
|
57
|
+
asset: string;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
hyperliquidResult?: SpotOrderHyperliquidResult;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Execute a spot order (swap) using Pear Hyperliquid service
|
|
63
|
+
* POST /orders/spot
|
|
64
|
+
*/
|
|
65
|
+
export declare function executeSpotOrder(baseUrl: string, payload: SpotOrderRequestInput): Promise<ApiResponse<SpotOrderResponseDto>>;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './useAgentWallet';
|
|
|
10
10
|
export * from './useAutoSyncFills';
|
|
11
11
|
export * from './usePosition';
|
|
12
12
|
export * from './useOrders';
|
|
13
|
+
export * from './useSpotOrder';
|
|
13
14
|
export * from './useTwap';
|
|
14
15
|
export * from './useNotifications';
|
|
15
16
|
export * from './useMarketData';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiResponse, ApiErrorResponse } from '../types';
|
|
2
|
+
import { type SpotOrderRequestInput, type SpotOrderResponseDto } from '../clients/orders';
|
|
3
|
+
export interface UseSpotOrderResult {
|
|
4
|
+
executeSpotOrder: (payload: SpotOrderRequestInput) => Promise<ApiResponse<SpotOrderResponseDto>>;
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
error: ApiErrorResponse | null;
|
|
7
|
+
resetError: () => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hook for executing spot orders (swaps) on Hyperliquid
|
|
11
|
+
* Use this to swap between USDC and USDH or other spot assets
|
|
12
|
+
*/
|
|
13
|
+
export declare function useSpotOrder(): UseSpotOrderResult;
|
package/dist/index.d.ts
CHANGED
|
@@ -178,6 +178,8 @@ interface TradeHistoryAssetDataDto {
|
|
|
178
178
|
externalFeePaid: number;
|
|
179
179
|
builderFeePaid: number;
|
|
180
180
|
realizedPnl: number;
|
|
181
|
+
marketPrefix?: string | null;
|
|
182
|
+
collateralToken?: CollateralToken;
|
|
181
183
|
}
|
|
182
184
|
/**
|
|
183
185
|
* Trade history data structure
|
|
@@ -920,6 +922,47 @@ interface CancelTwapResponseDto {
|
|
|
920
922
|
cancelledAt: string;
|
|
921
923
|
}
|
|
922
924
|
declare function cancelTwapOrder(baseUrl: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
925
|
+
interface SpotOrderRequestInput {
|
|
926
|
+
/** Asset to buy/sell (e.g., "USDH") */
|
|
927
|
+
asset: string;
|
|
928
|
+
/** Whether to buy (true) or sell (false) the asset */
|
|
929
|
+
isBuy: boolean;
|
|
930
|
+
/** Amount of asset to buy/sell (minimum: 11) */
|
|
931
|
+
amount: number;
|
|
932
|
+
}
|
|
933
|
+
/** Filled order status from Hyperliquid */
|
|
934
|
+
interface SpotOrderFilledStatus {
|
|
935
|
+
filled: {
|
|
936
|
+
totalSz: string;
|
|
937
|
+
avgPx: string;
|
|
938
|
+
oid: number;
|
|
939
|
+
cloid: string;
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
/** Hyperliquid order response data */
|
|
943
|
+
interface SpotOrderHyperliquidData {
|
|
944
|
+
statuses: SpotOrderFilledStatus[];
|
|
945
|
+
}
|
|
946
|
+
/** Hyperliquid result from spot order execution */
|
|
947
|
+
interface SpotOrderHyperliquidResult {
|
|
948
|
+
status: 'ok' | 'error';
|
|
949
|
+
response: {
|
|
950
|
+
type: 'order';
|
|
951
|
+
data: SpotOrderHyperliquidData;
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
interface SpotOrderResponseDto {
|
|
955
|
+
orderId: string;
|
|
956
|
+
status: 'EXECUTED' | 'FAILED' | 'PENDING';
|
|
957
|
+
asset: string;
|
|
958
|
+
createdAt: string;
|
|
959
|
+
hyperliquidResult?: SpotOrderHyperliquidResult;
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Execute a spot order (swap) using Pear Hyperliquid service
|
|
963
|
+
* POST /orders/spot
|
|
964
|
+
*/
|
|
965
|
+
declare function executeSpotOrder(baseUrl: string, payload: SpotOrderRequestInput): Promise<ApiResponse<SpotOrderResponseDto>>;
|
|
923
966
|
|
|
924
967
|
type ExecutionType = "MARKET" | "LIMIT" | "TWAP" | "LADDER" | "LIMIT_BTCDOM";
|
|
925
968
|
type TpSlThresholdType = "PERCENTAGE" | "DOLLAR" | "POSITION_VALUE";
|
|
@@ -1066,6 +1109,18 @@ declare function useOrders(): {
|
|
|
1066
1109
|
readonly isLoading: boolean;
|
|
1067
1110
|
};
|
|
1068
1111
|
|
|
1112
|
+
interface UseSpotOrderResult {
|
|
1113
|
+
executeSpotOrder: (payload: SpotOrderRequestInput) => Promise<ApiResponse<SpotOrderResponseDto>>;
|
|
1114
|
+
isLoading: boolean;
|
|
1115
|
+
error: ApiErrorResponse | null;
|
|
1116
|
+
resetError: () => void;
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Hook for executing spot orders (swaps) on Hyperliquid
|
|
1120
|
+
* Use this to swap between USDC and USDH or other spot assets
|
|
1121
|
+
*/
|
|
1122
|
+
declare function useSpotOrder(): UseSpotOrderResult;
|
|
1123
|
+
|
|
1069
1124
|
declare function useTwap(): {
|
|
1070
1125
|
readonly orders: TwapMonitoringDto[];
|
|
1071
1126
|
readonly cancelTwap: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
@@ -1390,5 +1445,5 @@ declare function isHip3Market(symbol: string): boolean;
|
|
|
1390
1445
|
|
|
1391
1446
|
declare const useMarketData: any;
|
|
1392
1447
|
|
|
1393
|
-
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
1394
|
-
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CollateralFilter, CollateralToken, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, MarketDataBySymbol, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
1448
|
+
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
1449
|
+
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CollateralFilter, CollateralToken, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, MarketDataBySymbol, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -1013,16 +1013,69 @@ const useAccountSummary = () => {
|
|
|
1013
1013
|
return { data: calculated, isLoading };
|
|
1014
1014
|
};
|
|
1015
1015
|
|
|
1016
|
+
// Helper to find asset metadata from perpMetaAssets
|
|
1017
|
+
function findAssetMeta$2(coinName, perpMetaAssets) {
|
|
1018
|
+
var _a, _b, _c, _d;
|
|
1019
|
+
if (!perpMetaAssets) {
|
|
1020
|
+
return { collateralToken: 'USDC', marketPrefix: null };
|
|
1021
|
+
}
|
|
1022
|
+
// Try exact match first (for prefixed assets like "xyz:TSLA")
|
|
1023
|
+
const exactMatch = perpMetaAssets.find((a) => a.name === coinName);
|
|
1024
|
+
if (exactMatch) {
|
|
1025
|
+
return {
|
|
1026
|
+
collateralToken: (_a = exactMatch.collateralToken) !== null && _a !== void 0 ? _a : 'USDC',
|
|
1027
|
+
marketPrefix: (_b = exactMatch.marketPrefix) !== null && _b !== void 0 ? _b : null,
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
// Try matching by base symbol (for non-prefixed names in data)
|
|
1031
|
+
const baseMatch = perpMetaAssets.find((a) => {
|
|
1032
|
+
const baseName = a.name.includes(':') ? a.name.split(':')[1] : a.name;
|
|
1033
|
+
return baseName === coinName;
|
|
1034
|
+
});
|
|
1035
|
+
if (baseMatch) {
|
|
1036
|
+
return {
|
|
1037
|
+
collateralToken: (_c = baseMatch.collateralToken) !== null && _c !== void 0 ? _c : 'USDC',
|
|
1038
|
+
marketPrefix: (_d = baseMatch.marketPrefix) !== null && _d !== void 0 ? _d : null,
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
return { collateralToken: 'USDC', marketPrefix: null };
|
|
1042
|
+
}
|
|
1043
|
+
// Enrich trade history assets with market prefix and collateral token
|
|
1044
|
+
function enrichTradeHistoryAssets(assets, perpMetaAssets) {
|
|
1045
|
+
return assets.map((asset) => {
|
|
1046
|
+
const meta = findAssetMeta$2(asset.coin, perpMetaAssets);
|
|
1047
|
+
return {
|
|
1048
|
+
...asset,
|
|
1049
|
+
marketPrefix: meta.marketPrefix,
|
|
1050
|
+
collateralToken: meta.collateralToken,
|
|
1051
|
+
};
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
// Enrich all trade histories with market metadata
|
|
1055
|
+
function enrichTradeHistories(histories, perpMetaAssets) {
|
|
1056
|
+
return histories.map((history) => ({
|
|
1057
|
+
...history,
|
|
1058
|
+
closedLongAssets: enrichTradeHistoryAssets(history.closedLongAssets, perpMetaAssets),
|
|
1059
|
+
closedShortAssets: enrichTradeHistoryAssets(history.closedShortAssets, perpMetaAssets),
|
|
1060
|
+
}));
|
|
1061
|
+
}
|
|
1016
1062
|
const useTradeHistories = () => {
|
|
1017
1063
|
const context = useContext(PearHyperliquidContext);
|
|
1018
1064
|
if (!context) {
|
|
1019
1065
|
throw new Error('useTradeHistories must be used within a PearHyperliquidProvider');
|
|
1020
1066
|
}
|
|
1021
1067
|
const tradeHistories = useUserData((state) => state.tradeHistories);
|
|
1068
|
+
const perpMetaAssets = useHyperliquidData((state) => state.perpMetaAssets);
|
|
1022
1069
|
const isLoading = useMemo(() => {
|
|
1023
1070
|
return tradeHistories === null && context.isConnected;
|
|
1024
1071
|
}, [tradeHistories, context.isConnected]);
|
|
1025
|
-
|
|
1072
|
+
// Enrich trade histories with market prefix and collateral token
|
|
1073
|
+
const enrichedTradeHistories = useMemo(() => {
|
|
1074
|
+
if (!tradeHistories)
|
|
1075
|
+
return null;
|
|
1076
|
+
return enrichTradeHistories(tradeHistories, perpMetaAssets);
|
|
1077
|
+
}, [tradeHistories, perpMetaAssets]);
|
|
1078
|
+
return { data: enrichedTradeHistories, isLoading };
|
|
1026
1079
|
};
|
|
1027
1080
|
/**
|
|
1028
1081
|
* Hook to access open orders with loading state
|
|
@@ -6928,8 +6981,15 @@ function usePosition() {
|
|
|
6928
6981
|
async function adjustOrder(baseUrl, orderId, payload) {
|
|
6929
6982
|
const url = joinUrl(baseUrl, `/orders/${orderId}/adjust`);
|
|
6930
6983
|
try {
|
|
6931
|
-
const resp = await apiClient.put(url, payload, {
|
|
6932
|
-
|
|
6984
|
+
const resp = await apiClient.put(url, payload, {
|
|
6985
|
+
headers: { 'Content-Type': 'application/json' },
|
|
6986
|
+
timeout: 60000,
|
|
6987
|
+
});
|
|
6988
|
+
return {
|
|
6989
|
+
data: resp.data,
|
|
6990
|
+
status: resp.status,
|
|
6991
|
+
headers: resp.headers,
|
|
6992
|
+
};
|
|
6933
6993
|
}
|
|
6934
6994
|
catch (error) {
|
|
6935
6995
|
throw toApiError(error);
|
|
@@ -6938,8 +6998,14 @@ async function adjustOrder(baseUrl, orderId, payload) {
|
|
|
6938
6998
|
async function cancelOrder(baseUrl, orderId) {
|
|
6939
6999
|
const url = joinUrl(baseUrl, `/orders/${orderId}/cancel`);
|
|
6940
7000
|
try {
|
|
6941
|
-
const resp = await apiClient.delete(url, {
|
|
6942
|
-
|
|
7001
|
+
const resp = await apiClient.delete(url, {
|
|
7002
|
+
timeout: 60000,
|
|
7003
|
+
});
|
|
7004
|
+
return {
|
|
7005
|
+
data: resp.data,
|
|
7006
|
+
status: resp.status,
|
|
7007
|
+
headers: resp.headers,
|
|
7008
|
+
};
|
|
6943
7009
|
}
|
|
6944
7010
|
catch (error) {
|
|
6945
7011
|
throw toApiError(error);
|
|
@@ -6949,7 +7015,32 @@ async function cancelTwapOrder(baseUrl, orderId) {
|
|
|
6949
7015
|
const url = joinUrl(baseUrl, `/orders/${orderId}/twap/cancel`);
|
|
6950
7016
|
try {
|
|
6951
7017
|
const resp = await apiClient.post(url, {}, { headers: { 'Content-Type': 'application/json' }, timeout: 60000 });
|
|
6952
|
-
return {
|
|
7018
|
+
return {
|
|
7019
|
+
data: resp.data,
|
|
7020
|
+
status: resp.status,
|
|
7021
|
+
headers: resp.headers,
|
|
7022
|
+
};
|
|
7023
|
+
}
|
|
7024
|
+
catch (error) {
|
|
7025
|
+
throw toApiError(error);
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
7028
|
+
/**
|
|
7029
|
+
* Execute a spot order (swap) using Pear Hyperliquid service
|
|
7030
|
+
* POST /orders/spot
|
|
7031
|
+
*/
|
|
7032
|
+
async function executeSpotOrder(baseUrl, payload) {
|
|
7033
|
+
const url = joinUrl(baseUrl, '/orders/spot');
|
|
7034
|
+
try {
|
|
7035
|
+
const resp = await apiClient.post(url, payload, {
|
|
7036
|
+
headers: { 'Content-Type': 'application/json' },
|
|
7037
|
+
timeout: 60000,
|
|
7038
|
+
});
|
|
7039
|
+
return {
|
|
7040
|
+
data: resp.data,
|
|
7041
|
+
status: resp.status,
|
|
7042
|
+
headers: resp.headers,
|
|
7043
|
+
};
|
|
6953
7044
|
}
|
|
6954
7045
|
catch (error) {
|
|
6955
7046
|
throw toApiError(error);
|
|
@@ -7005,6 +7096,45 @@ function useOrders() {
|
|
|
7005
7096
|
return { adjustOrder: adjustOrder$1, cancelOrder: cancelOrder$1, cancelTwapOrder: cancelTwapOrder$1, openOrders: enrichedOpenOrders, isLoading };
|
|
7006
7097
|
}
|
|
7007
7098
|
|
|
7099
|
+
/**
|
|
7100
|
+
* Hook for executing spot orders (swaps) on Hyperliquid
|
|
7101
|
+
* Use this to swap between USDC and USDH or other spot assets
|
|
7102
|
+
*/
|
|
7103
|
+
function useSpotOrder() {
|
|
7104
|
+
const context = useContext(PearHyperliquidContext);
|
|
7105
|
+
if (!context) {
|
|
7106
|
+
throw new Error('useSpotOrder must be used within a PearHyperliquidProvider');
|
|
7107
|
+
}
|
|
7108
|
+
const { apiBaseUrl } = context;
|
|
7109
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
7110
|
+
const [error, setError] = useState(null);
|
|
7111
|
+
const resetError = useCallback(() => {
|
|
7112
|
+
setError(null);
|
|
7113
|
+
}, []);
|
|
7114
|
+
const executeSpotOrder$1 = useCallback(async (payload) => {
|
|
7115
|
+
setIsLoading(true);
|
|
7116
|
+
setError(null);
|
|
7117
|
+
try {
|
|
7118
|
+
const response = await executeSpotOrder(apiBaseUrl, payload);
|
|
7119
|
+
return response;
|
|
7120
|
+
}
|
|
7121
|
+
catch (err) {
|
|
7122
|
+
const apiError = err;
|
|
7123
|
+
setError(apiError);
|
|
7124
|
+
throw apiError;
|
|
7125
|
+
}
|
|
7126
|
+
finally {
|
|
7127
|
+
setIsLoading(false);
|
|
7128
|
+
}
|
|
7129
|
+
}, [apiBaseUrl]);
|
|
7130
|
+
return {
|
|
7131
|
+
executeSpotOrder: executeSpotOrder$1,
|
|
7132
|
+
isLoading,
|
|
7133
|
+
error,
|
|
7134
|
+
resetError,
|
|
7135
|
+
};
|
|
7136
|
+
}
|
|
7137
|
+
|
|
7008
7138
|
function useTwap() {
|
|
7009
7139
|
const twapDetails = useUserData(state => state.twapDetails);
|
|
7010
7140
|
const context = useContext(PearHyperliquidContext);
|
|
@@ -7763,4 +7893,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
7763
7893
|
}
|
|
7764
7894
|
}
|
|
7765
7895
|
|
|
7766
|
-
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
7896
|
+
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/hyperliquid-sdk",
|
|
3
|
-
"version": "0.0.60-beta-usdh",
|
|
3
|
+
"version": "0.0.60-beta-usdh-2",
|
|
4
4
|
"description": "React SDK for Pear Protocol Hyperliquid API integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"@types/react": "^18.0.0",
|
|
39
39
|
"concurrently": "^9.2.1",
|
|
40
40
|
"esbuild": "^0.25.9",
|
|
41
|
-
|
|
42
41
|
"rimraf": "^5.0.0",
|
|
43
42
|
"rollup": "^3.0.0",
|
|
44
43
|
"rollup-plugin-dts": "^6.0.0",
|