@lifi/perps-sdk-provider-hyperliquid 5.1.0 → 6.0.1
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/cjs/HyperliquidProvider.d.ts.map +1 -1
- package/dist/cjs/HyperliquidProvider.js +4 -0
- package/dist/cjs/HyperliquidProvider.js.map +1 -1
- package/dist/cjs/services/getAccount.d.ts.map +1 -1
- package/dist/cjs/services/getAccount.js +1 -1
- package/dist/cjs/services/getAccount.js.map +1 -1
- package/dist/cjs/services/getActivity.d.ts.map +1 -1
- package/dist/cjs/services/getActivity.js.map +1 -1
- package/dist/cjs/services/getFills.d.ts.map +1 -1
- package/dist/cjs/services/getFills.js.map +1 -1
- package/dist/cjs/services/getMarketSettings.d.ts +10 -0
- package/dist/cjs/services/getMarketSettings.d.ts.map +1 -0
- package/dist/cjs/services/getMarketSettings.js +26 -0
- package/dist/cjs/services/getMarketSettings.js.map +1 -0
- package/dist/cjs/services/getOrders.d.ts.map +1 -1
- package/dist/cjs/services/getOrders.js.map +1 -1
- package/dist/cjs/services/getPositions.d.ts.map +1 -1
- package/dist/cjs/services/getPositions.js +1 -1
- package/dist/cjs/services/getPositions.js.map +1 -1
- package/dist/cjs/signers/HyperliquidAgentStore.d.ts.map +1 -1
- package/dist/cjs/signers/HyperliquidAgentStore.js.map +1 -1
- package/dist/cjs/signers/signActions.d.ts.map +1 -1
- package/dist/cjs/signers/signActions.js.map +1 -1
- package/dist/cjs/types/account.d.ts +11 -0
- package/dist/cjs/types/account.d.ts.map +1 -1
- package/dist/cjs/types/account.js.map +1 -1
- package/dist/cjs/types/action.d.ts.map +1 -1
- package/dist/cjs/types/action.js.map +1 -1
- package/dist/cjs/types/asset.d.ts +1 -0
- package/dist/cjs/types/asset.d.ts.map +1 -1
- package/dist/cjs/types/fill.d.ts.map +1 -1
- package/dist/cjs/types/ledger.d.ts.map +1 -1
- package/dist/cjs/types/ledger.js.map +1 -1
- package/dist/cjs/types/order.d.ts.map +1 -1
- package/dist/cjs/types/ws.d.ts.map +1 -1
- package/dist/cjs/utils/assetId.d.ts.map +1 -1
- package/dist/cjs/utils/assetId.js.map +1 -1
- package/dist/cjs/utils/assetLogo.d.ts.map +1 -1
- package/dist/cjs/utils/assetLogo.js.map +1 -1
- package/dist/cjs/utils/decodeFastAssetCtxs.d.ts.map +1 -1
- package/dist/cjs/utils/decodeFastAssetCtxs.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +3 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/infoClient.d.ts.map +1 -1
- package/dist/cjs/utils/infoClient.js.map +1 -1
- package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
- package/dist/cjs/utils/mapActivity.js +13 -10
- package/dist/cjs/utils/mapActivity.js.map +1 -1
- package/dist/cjs/utils/mapFill.d.ts.map +1 -1
- package/dist/cjs/utils/mapFill.js.map +1 -1
- package/dist/cjs/utils/mapMarket.d.ts.map +1 -1
- package/dist/cjs/utils/mapMarket.js +6 -1
- package/dist/cjs/utils/mapMarket.js.map +1 -1
- package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
- package/dist/cjs/utils/mapOrder.js.map +1 -1
- package/dist/cjs/utils/mapPosition.d.ts +2 -2
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
- package/dist/cjs/utils/mapPosition.js +17 -10
- package/dist/cjs/utils/mapPosition.js.map +1 -1
- package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
- package/dist/cjs/utils/spotBalance.js.map +1 -1
- package/dist/cjs/utils/spotCollateral.d.ts.map +1 -1
- package/dist/cjs/utils/spotCollateral.js.map +1 -1
- package/dist/cjs/utils/transferMargin.d.ts +3 -0
- package/dist/cjs/utils/transferMargin.d.ts.map +1 -0
- package/dist/cjs/utils/transferMargin.js +40 -0
- package/dist/cjs/utils/transferMargin.js.map +1 -0
- package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.js +3 -1
- package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/esm/HyperliquidProvider.d.ts +14 -4
- package/dist/esm/HyperliquidProvider.d.ts.map +1 -1
- package/dist/esm/HyperliquidProvider.js +4 -0
- package/dist/esm/HyperliquidProvider.js.map +1 -1
- package/dist/esm/services/getAccount.d.ts.map +1 -1
- package/dist/esm/services/getAccount.js +2 -2
- package/dist/esm/services/getAccount.js.map +1 -1
- package/dist/esm/services/getActivity.d.ts +5 -1
- package/dist/esm/services/getActivity.d.ts.map +1 -1
- package/dist/esm/services/getActivity.js.map +1 -1
- package/dist/esm/services/getFills.d.ts +4 -3
- package/dist/esm/services/getFills.d.ts.map +1 -1
- package/dist/esm/services/getFills.js.map +1 -1
- package/dist/esm/services/getMarketSettings.d.ts +21 -0
- package/dist/esm/services/getMarketSettings.d.ts.map +1 -0
- package/dist/esm/services/getMarketSettings.js +29 -0
- package/dist/esm/services/getMarketSettings.js.map +1 -0
- package/dist/esm/services/getOrders.d.ts +2 -1
- package/dist/esm/services/getOrders.d.ts.map +1 -1
- package/dist/esm/services/getOrders.js.map +1 -1
- package/dist/esm/services/getPositions.d.ts +2 -2
- package/dist/esm/services/getPositions.d.ts.map +1 -1
- package/dist/esm/services/getPositions.js +2 -2
- package/dist/esm/services/getPositions.js.map +1 -1
- package/dist/esm/signers/HyperliquidAgentStore.d.ts +3 -3
- package/dist/esm/signers/HyperliquidAgentStore.d.ts.map +1 -1
- package/dist/esm/signers/HyperliquidAgentStore.js +1 -0
- package/dist/esm/signers/HyperliquidAgentStore.js.map +1 -1
- package/dist/esm/signers/signActions.d.ts +8 -6
- package/dist/esm/signers/signActions.d.ts.map +1 -1
- package/dist/esm/signers/signActions.js +8 -6
- package/dist/esm/signers/signActions.js.map +1 -1
- package/dist/esm/types/account.d.ts +68 -8
- package/dist/esm/types/account.d.ts.map +1 -1
- package/dist/esm/types/account.js.map +1 -1
- package/dist/esm/types/action.d.ts +28 -10
- package/dist/esm/types/action.d.ts.map +1 -1
- package/dist/esm/types/action.js +7 -7
- package/dist/esm/types/action.js.map +1 -1
- package/dist/esm/types/asset.d.ts +62 -15
- package/dist/esm/types/asset.d.ts.map +1 -1
- package/dist/esm/types/fill.d.ts +9 -3
- package/dist/esm/types/fill.d.ts.map +1 -1
- package/dist/esm/types/ledger.d.ts +24 -6
- package/dist/esm/types/ledger.d.ts.map +1 -1
- package/dist/esm/types/ledger.js.map +1 -1
- package/dist/esm/types/order.d.ts +19 -5
- package/dist/esm/types/order.d.ts.map +1 -1
- package/dist/esm/types/ws.d.ts +43 -14
- package/dist/esm/types/ws.d.ts.map +1 -1
- package/dist/esm/utils/assetId.d.ts +7 -7
- package/dist/esm/utils/assetId.d.ts.map +1 -1
- package/dist/esm/utils/assetId.js +7 -7
- package/dist/esm/utils/assetId.js.map +1 -1
- package/dist/esm/utils/assetLogo.d.ts +15 -13
- package/dist/esm/utils/assetLogo.d.ts.map +1 -1
- package/dist/esm/utils/assetLogo.js +15 -13
- package/dist/esm/utils/assetLogo.js.map +1 -1
- package/dist/esm/utils/decodeFastAssetCtxs.d.ts +7 -1
- package/dist/esm/utils/decodeFastAssetCtxs.d.ts.map +1 -1
- package/dist/esm/utils/decodeFastAssetCtxs.js +7 -1
- package/dist/esm/utils/decodeFastAssetCtxs.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/infoClient.d.ts +6 -1
- package/dist/esm/utils/infoClient.d.ts.map +1 -1
- package/dist/esm/utils/infoClient.js.map +1 -1
- package/dist/esm/utils/mapActivity.d.ts +10 -1
- package/dist/esm/utils/mapActivity.d.ts.map +1 -1
- package/dist/esm/utils/mapActivity.js +23 -11
- package/dist/esm/utils/mapActivity.js.map +1 -1
- package/dist/esm/utils/mapFill.d.ts +1 -0
- package/dist/esm/utils/mapFill.d.ts.map +1 -1
- package/dist/esm/utils/mapFill.js +1 -0
- package/dist/esm/utils/mapFill.js.map +1 -1
- package/dist/esm/utils/mapMarket.d.ts.map +1 -1
- package/dist/esm/utils/mapMarket.js +8 -1
- package/dist/esm/utils/mapMarket.js.map +1 -1
- package/dist/esm/utils/mapOrder.d.ts +15 -4
- package/dist/esm/utils/mapOrder.d.ts.map +1 -1
- package/dist/esm/utils/mapOrder.js +15 -4
- package/dist/esm/utils/mapOrder.js.map +1 -1
- package/dist/esm/utils/mapPosition.d.ts +8 -3
- package/dist/esm/utils/mapPosition.d.ts.map +1 -1
- package/dist/esm/utils/mapPosition.js +20 -11
- package/dist/esm/utils/mapPosition.js.map +1 -1
- package/dist/esm/utils/spotBalance.d.ts +9 -10
- package/dist/esm/utils/spotBalance.d.ts.map +1 -1
- package/dist/esm/utils/spotBalance.js +9 -10
- package/dist/esm/utils/spotBalance.js.map +1 -1
- package/dist/esm/utils/spotCollateral.d.ts +9 -5
- package/dist/esm/utils/spotCollateral.d.ts.map +1 -1
- package/dist/esm/utils/spotCollateral.js +4 -4
- package/dist/esm/utils/spotCollateral.js.map +1 -1
- package/dist/esm/utils/transferMargin.d.ts +14 -0
- package/dist/esm/utils/transferMargin.d.ts.map +1 -0
- package/dist/esm/utils/transferMargin.js +45 -0
- package/dist/esm/utils/transferMargin.js.map +1 -0
- package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/HyperliquidWsProvider.js +4 -2
- package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
- package/dist/types/HyperliquidProvider.d.ts +14 -4
- package/dist/types/HyperliquidProvider.d.ts.map +1 -1
- package/dist/types/services/getAccount.d.ts.map +1 -1
- package/dist/types/services/getActivity.d.ts +5 -1
- package/dist/types/services/getActivity.d.ts.map +1 -1
- package/dist/types/services/getFills.d.ts +4 -3
- package/dist/types/services/getFills.d.ts.map +1 -1
- package/dist/types/services/getMarketSettings.d.ts +21 -0
- package/dist/types/services/getMarketSettings.d.ts.map +1 -0
- package/dist/types/services/getOrders.d.ts +2 -1
- package/dist/types/services/getOrders.d.ts.map +1 -1
- package/dist/types/services/getPositions.d.ts +2 -2
- package/dist/types/services/getPositions.d.ts.map +1 -1
- package/dist/types/signers/HyperliquidAgentStore.d.ts +3 -3
- package/dist/types/signers/HyperliquidAgentStore.d.ts.map +1 -1
- package/dist/types/signers/signActions.d.ts +8 -6
- package/dist/types/signers/signActions.d.ts.map +1 -1
- package/dist/types/types/account.d.ts +68 -8
- package/dist/types/types/account.d.ts.map +1 -1
- package/dist/types/types/action.d.ts +28 -10
- package/dist/types/types/action.d.ts.map +1 -1
- package/dist/types/types/asset.d.ts +62 -15
- package/dist/types/types/asset.d.ts.map +1 -1
- package/dist/types/types/fill.d.ts +9 -3
- package/dist/types/types/fill.d.ts.map +1 -1
- package/dist/types/types/ledger.d.ts +24 -6
- package/dist/types/types/ledger.d.ts.map +1 -1
- package/dist/types/types/order.d.ts +19 -5
- package/dist/types/types/order.d.ts.map +1 -1
- package/dist/types/types/ws.d.ts +43 -14
- package/dist/types/types/ws.d.ts.map +1 -1
- package/dist/types/utils/assetId.d.ts +7 -7
- package/dist/types/utils/assetId.d.ts.map +1 -1
- package/dist/types/utils/assetLogo.d.ts +15 -13
- package/dist/types/utils/assetLogo.d.ts.map +1 -1
- package/dist/types/utils/decodeFastAssetCtxs.d.ts +7 -1
- package/dist/types/utils/decodeFastAssetCtxs.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/infoClient.d.ts +6 -1
- package/dist/types/utils/infoClient.d.ts.map +1 -1
- package/dist/types/utils/mapActivity.d.ts +10 -1
- package/dist/types/utils/mapActivity.d.ts.map +1 -1
- package/dist/types/utils/mapFill.d.ts +1 -0
- package/dist/types/utils/mapFill.d.ts.map +1 -1
- package/dist/types/utils/mapMarket.d.ts.map +1 -1
- package/dist/types/utils/mapOrder.d.ts +15 -4
- package/dist/types/utils/mapOrder.d.ts.map +1 -1
- package/dist/types/utils/mapPosition.d.ts +8 -3
- package/dist/types/utils/mapPosition.d.ts.map +1 -1
- package/dist/types/utils/spotBalance.d.ts +9 -10
- package/dist/types/utils/spotBalance.d.ts.map +1 -1
- package/dist/types/utils/spotCollateral.d.ts +9 -5
- package/dist/types/utils/spotCollateral.d.ts.map +1 -1
- package/dist/types/utils/transferMargin.d.ts +14 -0
- package/dist/types/utils/transferMargin.d.ts.map +1 -0
- package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/HyperliquidProvider.ts +30 -4
- package/src/services/getAccount.ts +7 -1
- package/src/services/getActivity.ts +5 -1
- package/src/services/getFills.ts +4 -3
- package/src/services/getMarketSettings.ts +56 -0
- package/src/services/getOrders.ts +2 -1
- package/src/services/getPositions.ts +13 -4
- package/src/signers/HyperliquidAgentStore.ts +3 -3
- package/src/signers/signActions.ts +8 -6
- package/src/types/account.ts +66 -8
- package/src/types/action.ts +28 -10
- package/src/types/asset.ts +62 -15
- package/src/types/fill.ts +9 -3
- package/src/types/ledger.ts +24 -6
- package/src/types/order.ts +19 -5
- package/src/types/ws.ts +43 -14
- package/src/utils/assetId.ts +7 -7
- package/src/utils/assetLogo.ts +15 -13
- package/src/utils/decodeFastAssetCtxs.ts +7 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/infoClient.ts +6 -1
- package/src/utils/mapActivity.ts +23 -11
- package/src/utils/mapFill.ts +1 -0
- package/src/utils/mapMarket.ts +10 -1
- package/src/utils/mapOrder.ts +15 -4
- package/src/utils/mapPosition.ts +24 -15
- package/src/utils/spotBalance.ts +9 -10
- package/src/utils/spotCollateral.ts +9 -5
- package/src/utils/transferMargin.ts +65 -0
- package/src/websocket/HyperliquidWsProvider.ts +4 -1
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type ProviderGetAccountParams,
|
|
12
12
|
type ProviderGetActivityParams,
|
|
13
13
|
type ProviderGetFillsParams,
|
|
14
|
+
type ProviderGetMarketSettingsParams,
|
|
14
15
|
type ProviderGetOrderParams,
|
|
15
16
|
type ProviderGetOrdersParams,
|
|
16
17
|
type ProviderGetPositionsParams,
|
|
@@ -30,6 +31,7 @@ import {
|
|
|
30
31
|
type ActivitiesResponse,
|
|
31
32
|
type FillsResponse,
|
|
32
33
|
type Market,
|
|
34
|
+
type MarketSettings,
|
|
33
35
|
type Order,
|
|
34
36
|
type OrdersResponse,
|
|
35
37
|
PerpsErrorCode,
|
|
@@ -56,6 +58,7 @@ import { getAccount } from './services/getAccount.js'
|
|
|
56
58
|
import { getAccountExists } from './services/getAccountExists.js'
|
|
57
59
|
import { getActivity } from './services/getActivity.js'
|
|
58
60
|
import { getFills } from './services/getFills.js'
|
|
61
|
+
import { getMarketSettings } from './services/getMarketSettings.js'
|
|
59
62
|
import { getOrder } from './services/getOrder.js'
|
|
60
63
|
import { getOrders } from './services/getOrders.js'
|
|
61
64
|
import { getPositions } from './services/getPositions.js'
|
|
@@ -68,6 +71,7 @@ import type { HlExtraAgents } from './types/index.js'
|
|
|
68
71
|
import { hlInfoOptions, infoRequest } from './utils/infoClient.js'
|
|
69
72
|
import { calculateLiquidationPrice } from './utils/liquidation.js'
|
|
70
73
|
import { formatOrderPrice, formatOrderSize } from './utils/orderFormatting.js'
|
|
74
|
+
import { positionMarginConstraints } from './utils/transferMargin.js'
|
|
71
75
|
|
|
72
76
|
/**
|
|
73
77
|
* Options for {@link hyperliquidProvider}.
|
|
@@ -97,15 +101,25 @@ export interface HyperliquidProviderOptions {
|
|
|
97
101
|
* persistence, and revocation. The base {@link PerpsProviderPlugin} contract
|
|
98
102
|
* stays provider-agnostic — this extension is opt-in for callers that
|
|
99
103
|
* explicitly type against it (e.g. to surface a "revoke agent" affordance).
|
|
104
|
+
* @public
|
|
100
105
|
*/
|
|
101
106
|
export interface HyperliquidPerpsProvider extends PerpsProviderPlugin {
|
|
102
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Resolve the stored agent wallet address for a user.
|
|
109
|
+
* @throws {PerpsError} With `AgentNotFound` when no agent has been created.
|
|
110
|
+
*/
|
|
103
111
|
getAgentAddress(address: Address): Promise<Address>
|
|
104
|
-
/**
|
|
112
|
+
/** Return whether a persisted agent keypair exists for the user address. */
|
|
105
113
|
hasAgent(address: Address): Promise<boolean>
|
|
106
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Remove the user's persisted agent keypair and local authorization.
|
|
116
|
+
* This does not submit an on-chain `APPROVE_AGENT` revocation.
|
|
117
|
+
*/
|
|
107
118
|
removeAgent(address: Address): Promise<void>
|
|
108
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* Validate, persist, and return an existing agent private key for a user.
|
|
121
|
+
* The returned private key is stored by the configured {@link StorageAdapter}.
|
|
122
|
+
*/
|
|
109
123
|
importAgent(address: Address, privateKey: Hex): Promise<HyperliquidAgent>
|
|
110
124
|
}
|
|
111
125
|
|
|
@@ -288,6 +302,16 @@ export function hyperliquidProvider(
|
|
|
288
302
|
opts
|
|
289
303
|
),
|
|
290
304
|
|
|
305
|
+
getMarketSettings: (
|
|
306
|
+
params: ProviderGetMarketSettingsParams,
|
|
307
|
+
opts?: SDKRequestOptions
|
|
308
|
+
): Promise<MarketSettings | undefined> =>
|
|
309
|
+
getMarketSettings(
|
|
310
|
+
contextRef.require(),
|
|
311
|
+
{ address: params.address, market: params.market },
|
|
312
|
+
opts
|
|
313
|
+
),
|
|
314
|
+
|
|
291
315
|
getOrders: (
|
|
292
316
|
params: ProviderGetOrdersParams,
|
|
293
317
|
opts?: SDKRequestOptions
|
|
@@ -383,6 +407,8 @@ export function hyperliquidProvider(
|
|
|
383
407
|
market.maxLeverage
|
|
384
408
|
),
|
|
385
409
|
|
|
410
|
+
positionMarginConstraints,
|
|
411
|
+
|
|
386
412
|
projectConfig: (
|
|
387
413
|
config: AccountConfig,
|
|
388
414
|
setup: ProviderAction[],
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
type ProviderGetAccountParams,
|
|
5
5
|
type SDKRequestOptions,
|
|
6
6
|
stringToFloat,
|
|
7
|
+
toPerpsMarketDisplay,
|
|
7
8
|
} from '@lifi/perps-sdk'
|
|
8
9
|
import type {
|
|
9
10
|
AccountResponse,
|
|
@@ -214,7 +215,12 @@ export const getAccount = async (
|
|
|
214
215
|
const positions: Position[] = stateResults.flatMap((state) =>
|
|
215
216
|
state.assetPositions
|
|
216
217
|
.filter(isOpenAssetPosition)
|
|
217
|
-
.map((ap) =>
|
|
218
|
+
.map((ap) =>
|
|
219
|
+
mapPosition(
|
|
220
|
+
ap,
|
|
221
|
+
toPerpsMarketDisplay(registry.require(ap.position.coin))
|
|
222
|
+
)
|
|
223
|
+
)
|
|
218
224
|
)
|
|
219
225
|
|
|
220
226
|
const stateByDex = new Map<string, HlClearinghouseState>()
|
|
@@ -31,11 +31,15 @@ import {
|
|
|
31
31
|
*/
|
|
32
32
|
export interface GetActivityParams {
|
|
33
33
|
address: Address
|
|
34
|
+
/** Maximum items returned; defaults to 50 and is capped at 200. */
|
|
34
35
|
limit?: number
|
|
35
|
-
/**
|
|
36
|
+
/** Millisecond timestamp cursor; rows strictly older than it are returned. */
|
|
36
37
|
cursor?: string
|
|
38
|
+
/** Inclusive lower bound in milliseconds since epoch; defaults to 90 days ago. */
|
|
37
39
|
startTime?: number
|
|
40
|
+
/** Inclusive upper bound in milliseconds since epoch. */
|
|
38
41
|
endTime?: number
|
|
42
|
+
/** Optional normalized activity-type filter applied after mapping. */
|
|
39
43
|
type?: ActivityType[]
|
|
40
44
|
}
|
|
41
45
|
|
package/src/services/getFills.ts
CHANGED
|
@@ -22,12 +22,13 @@ import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
|
22
22
|
*/
|
|
23
23
|
export interface GetFillsParams {
|
|
24
24
|
address: Address
|
|
25
|
+
/** Maximum items returned; defaults to 50 and is capped at 200. */
|
|
25
26
|
limit?: number
|
|
26
|
-
/** Opaque
|
|
27
|
+
/** Opaque cursor returned in the previous page's `pagination.cursor`. */
|
|
27
28
|
cursor?: string
|
|
28
|
-
/** Inclusive lower bound in
|
|
29
|
+
/** Inclusive lower bound in milliseconds; selects `userFillsByTime`. */
|
|
29
30
|
startTime?: number
|
|
30
|
-
/** Inclusive upper bound in
|
|
31
|
+
/** Inclusive upper bound in milliseconds; selects `userFillsByTime`. */
|
|
31
32
|
endTime?: number
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { SDKRequestOptions } from '@lifi/perps-sdk'
|
|
2
|
+
import {
|
|
3
|
+
MarginMode,
|
|
4
|
+
type MarketRef,
|
|
5
|
+
type MarketSettings,
|
|
6
|
+
} from '@lifi/perps-types'
|
|
7
|
+
import type { Address } from 'viem'
|
|
8
|
+
import { SPOT_MARKET_ID } from '../constants.js'
|
|
9
|
+
import type { HyperliquidContext } from '../context.js'
|
|
10
|
+
import type { HlActiveAssetData } from '../types/index.js'
|
|
11
|
+
import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for {@link getMarketSettings}.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export interface GetMarketSettingsParams {
|
|
19
|
+
address: Address
|
|
20
|
+
market: MarketRef
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The user's venue-stored margin mode and leverage for one perps market,
|
|
25
|
+
* read from `activeAssetData` — present whether or not a position is open.
|
|
26
|
+
* @throws {PerpsError} On Hyperliquid REST error, network, or parsing failures.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export const getMarketSettings = async (
|
|
30
|
+
{ client, apiUrl }: HyperliquidContext,
|
|
31
|
+
params: GetMarketSettingsParams,
|
|
32
|
+
options?: SDKRequestOptions
|
|
33
|
+
): Promise<MarketSettings | undefined> => {
|
|
34
|
+
// Spot markets carry no leverage state on the venue.
|
|
35
|
+
if (params.market.categoryId === SPOT_MARKET_ID) {
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
38
|
+
const data = await infoRequest<HlActiveAssetData>(
|
|
39
|
+
apiUrl,
|
|
40
|
+
{
|
|
41
|
+
type: 'activeAssetData',
|
|
42
|
+
user: params.address,
|
|
43
|
+
coin: params.market.marketId,
|
|
44
|
+
},
|
|
45
|
+
hlInfoOptions(client, options)
|
|
46
|
+
)
|
|
47
|
+
const leverage = data.leverage
|
|
48
|
+
if (!leverage) {
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
marginMode:
|
|
53
|
+
leverage.type === 'isolated' ? MarginMode.ISOLATED : MarginMode.CROSS,
|
|
54
|
+
leverage: leverage.value,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -22,8 +22,9 @@ import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
|
22
22
|
*/
|
|
23
23
|
export interface GetOrdersParams {
|
|
24
24
|
address: Address
|
|
25
|
-
/** Optional filter
|
|
25
|
+
/** Optional filter using the normalized opaque `Market.id`. */
|
|
26
26
|
marketId?: string
|
|
27
|
+
/** Page-size hint; Hyperliquid returns all open orders in one response. */
|
|
27
28
|
limit?: number
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getMarketRegistry,
|
|
3
|
+
type SDKRequestOptions,
|
|
4
|
+
toPerpsMarketDisplay,
|
|
5
|
+
} from '@lifi/perps-sdk'
|
|
2
6
|
import type { PositionsResponse } from '@lifi/perps-types'
|
|
3
7
|
import type { Address } from 'viem'
|
|
4
8
|
import { PROVIDER_KEY } from '../constants.js'
|
|
@@ -18,9 +22,9 @@ import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
|
|
|
18
22
|
*/
|
|
19
23
|
export interface GetPositionsParams {
|
|
20
24
|
address: Address
|
|
21
|
-
/**
|
|
25
|
+
/** Optional filter using the normalized opaque `Market.id`. */
|
|
22
26
|
marketId?: string
|
|
23
|
-
/** Page
|
|
27
|
+
/** Page-size hint; Hyperliquid returns all open positions in one response. */
|
|
24
28
|
limit?: number
|
|
25
29
|
}
|
|
26
30
|
|
|
@@ -58,7 +62,12 @@ export const getPositions = async (
|
|
|
58
62
|
let positions = stateResults.flatMap((state) =>
|
|
59
63
|
state.assetPositions
|
|
60
64
|
.filter(isOpenAssetPosition)
|
|
61
|
-
.map((ap) =>
|
|
65
|
+
.map((ap) =>
|
|
66
|
+
mapPosition(
|
|
67
|
+
ap,
|
|
68
|
+
toPerpsMarketDisplay(registry.require(ap.position.coin))
|
|
69
|
+
)
|
|
70
|
+
)
|
|
62
71
|
)
|
|
63
72
|
|
|
64
73
|
if (params.marketId !== undefined) {
|
|
@@ -15,12 +15,11 @@ const STORAGE_PREFIX = 'lifi-perps-agent'
|
|
|
15
15
|
/**
|
|
16
16
|
* Hyperliquid agent keypair — an EVM keypair the user approves (via
|
|
17
17
|
* `APPROVE_AGENT`) to sign trading actions on their behalf, so each order
|
|
18
|
-
* does not require a wallet prompt.
|
|
18
|
+
* does not require a wallet prompt. `privateKey` is a 32-byte EVM hex key.
|
|
19
|
+
* @public
|
|
19
20
|
*/
|
|
20
21
|
export interface HyperliquidAgent {
|
|
21
|
-
/** Agent wallet address. */
|
|
22
22
|
address: Address
|
|
23
|
-
/** Agent private key. */
|
|
24
23
|
privateKey: Hex
|
|
25
24
|
}
|
|
26
25
|
|
|
@@ -60,6 +59,7 @@ const isHyperliquidAgent = (value: unknown): value is HyperliquidAgent => {
|
|
|
60
59
|
* fully compromised page — a same-origin script can still drive this store to
|
|
61
60
|
* decrypt. Blast radius is limited to agent trading: fund withdrawal still
|
|
62
61
|
* requires L1 `APPROVE_AGENT` consent that the agent key alone cannot grant.
|
|
62
|
+
* @public
|
|
63
63
|
*/
|
|
64
64
|
export class HyperliquidAgentStore {
|
|
65
65
|
private storage: StorageAdapter
|
|
@@ -15,12 +15,14 @@ import type { Address, Hex } from 'viem'
|
|
|
15
15
|
import type { HyperliquidAgentStore } from './HyperliquidAgentStore.js'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Sign a batch of EIP-712 action steps.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
18
|
+
* Sign a batch of Hyperliquid EIP-712 action steps. `AGENT` descriptors use
|
|
19
|
+
* the persisted per-user agent keypair; `USER` descriptors use
|
|
20
|
+
* `ctx.userWallet`. Other signing methods are rejected because Hyperliquid
|
|
21
|
+
* declares no WASM_BLOB or EVM_TX action schemes.
|
|
22
|
+
*
|
|
23
|
+
* @throws {PerpsError} When the method is unsupported, the required agent is
|
|
24
|
+
* missing, or a user-signed action has no wallet.
|
|
25
|
+
* @public
|
|
24
26
|
*/
|
|
25
27
|
export async function hyperliquidSignActions(
|
|
26
28
|
agentStore: HyperliquidAgentStore,
|
package/src/types/account.ts
CHANGED
|
@@ -1,26 +1,52 @@
|
|
|
1
1
|
// Account-level types returned by Hyperliquid `/info`.
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Perpetual position payload from Hyperliquid `clearinghouseState`.
|
|
5
|
+
*
|
|
6
|
+
* Numeric values are decimal strings in quote-asset units except `szi`,
|
|
7
|
+
* which is signed size: positive for long and negative for short. `coin` is
|
|
8
|
+
* the Hyperliquid wire market identifier; `leverage.type` is typically
|
|
9
|
+
* `'cross'` or `'isolated'`.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
4
12
|
export type HlPosition = {
|
|
13
|
+
/** Hyperliquid wire market identifier. */
|
|
5
14
|
coin: string
|
|
15
|
+
/** Signed position size; positive is long and negative is short. */
|
|
6
16
|
szi: string
|
|
17
|
+
/** Average entry price as a decimal string. */
|
|
7
18
|
entryPx: string
|
|
19
|
+
/** Position notional value as a decimal string. */
|
|
8
20
|
positionValue: string
|
|
21
|
+
/** Estimated liquidation price; may be an empty string when unavailable. */
|
|
9
22
|
liquidationPx: string
|
|
23
|
+
/** Unrealized PnL in quote-asset units. */
|
|
10
24
|
unrealizedPnl: string
|
|
25
|
+
/** Margin currently assigned to this position. */
|
|
11
26
|
marginUsed: string
|
|
27
|
+
/** Leverage mode and numeric leverage multiplier. */
|
|
12
28
|
leverage: {
|
|
13
29
|
type: string
|
|
14
30
|
value: number
|
|
15
31
|
}
|
|
16
32
|
}
|
|
17
33
|
|
|
18
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Wrapper for a position in the `assetPositions` array of a clearinghouse
|
|
36
|
+
* state response.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
19
39
|
export type HlAssetPosition = {
|
|
20
40
|
position: HlPosition
|
|
21
41
|
}
|
|
22
42
|
|
|
23
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Perpetual clearinghouse account state returned by Hyperliquid `/info`.
|
|
45
|
+
* `assetPositions` includes zero-size rows that callers may discard. Monetary
|
|
46
|
+
* fields are decimal strings in the account's quote asset; `marginSummary`
|
|
47
|
+
* covers all positions while `crossMarginSummary` covers cross margin only.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
24
50
|
export type HlClearinghouseState = {
|
|
25
51
|
assetPositions: HlAssetPosition[]
|
|
26
52
|
marginSummary: {
|
|
@@ -33,7 +59,12 @@ export type HlClearinghouseState = {
|
|
|
33
59
|
}
|
|
34
60
|
}
|
|
35
61
|
|
|
36
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* One spot balance from Hyperliquid `spotClearinghouseState`.
|
|
64
|
+
* `token` is the numeric spot token index, and amounts are decimal strings in
|
|
65
|
+
* the token's native units.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
37
68
|
export type HlSpotBalance = {
|
|
38
69
|
coin: string
|
|
39
70
|
token: number
|
|
@@ -42,19 +73,31 @@ export type HlSpotBalance = {
|
|
|
42
73
|
entryNtl: string
|
|
43
74
|
}
|
|
44
75
|
|
|
45
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Spot clearinghouse state returned by Hyperliquid `/info`.
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
46
80
|
export type HlSpotClearinghouseState = {
|
|
47
81
|
balances: HlSpotBalance[]
|
|
48
82
|
}
|
|
49
83
|
|
|
50
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* User fee rates returned by Hyperliquid `userFees`.
|
|
86
|
+
* Rates are decimal fractions represented as strings, not percentage values
|
|
87
|
+
* (for example, `'0.00045'` is 0.045%).
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
51
90
|
export type HlUserFees = {
|
|
52
91
|
userAddRate: string
|
|
53
92
|
userCrossRate: string
|
|
54
93
|
activeReferralDiscount: string
|
|
55
94
|
}
|
|
56
95
|
|
|
57
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Entries returned by Hyperliquid `extraAgents`. The endpoint may add fields
|
|
98
|
+
* over time, so the provider retains each entry as an open record.
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
58
101
|
export type HlExtraAgents = Record<string, unknown>[]
|
|
59
102
|
|
|
60
103
|
/**
|
|
@@ -67,6 +110,21 @@ export type HlPreTransferCheck = {
|
|
|
67
110
|
userExists: boolean
|
|
68
111
|
}
|
|
69
112
|
|
|
113
|
+
/**
|
|
114
|
+
* `activeAssetData` info response: the user's live per-asset trading state.
|
|
115
|
+
* `leverage` reflects the venue-stored setting whether or not a position is
|
|
116
|
+
* open on the asset.
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export type HlActiveAssetData = {
|
|
120
|
+
user: string
|
|
121
|
+
coin: string
|
|
122
|
+
leverage: { type: 'cross' | 'isolated'; value: number }
|
|
123
|
+
maxTradeSzs: [string, string]
|
|
124
|
+
availableToTrade: [string, string]
|
|
125
|
+
markPx: string
|
|
126
|
+
}
|
|
127
|
+
|
|
70
128
|
/**
|
|
71
129
|
* Possible values returned by the `userAbstraction` info endpoint.
|
|
72
130
|
* `null` means abstraction has never been set; `'default'`/`'disabled'` are
|
|
@@ -81,6 +139,6 @@ export const HlAbstractionMode = {
|
|
|
81
139
|
DEX_ABSTRACTION: 'dexAbstraction',
|
|
82
140
|
} as const
|
|
83
141
|
|
|
84
|
-
/** @public */
|
|
142
|
+
/** Union of the exact `userAbstraction` wire values accepted by Hyperliquid. @public */
|
|
85
143
|
export type HlAbstractionMode =
|
|
86
144
|
(typeof HlAbstractionMode)[keyof typeof HlAbstractionMode]
|
package/src/types/action.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
// Hyperliquid `/exchange` request/response shapes + EIP-712 primary types.
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* EIP-712 `/exchange` request sent to Hyperliquid.
|
|
5
|
+
*
|
|
6
|
+
* `action` is the provider-specific action object; signature fields are the
|
|
7
|
+
* hex `r`/`s` values and recovery byte `v`; `nonce` is milliseconds since the
|
|
8
|
+
* Unix epoch. `vaultAddress` is included only when submitting for a vault.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
4
11
|
export type HlExchangeRequest = {
|
|
5
12
|
action: Record<string, unknown>
|
|
6
13
|
signature: {
|
|
@@ -12,7 +19,14 @@ export type HlExchangeRequest = {
|
|
|
12
19
|
vaultAddress?: string | null
|
|
13
20
|
}
|
|
14
21
|
|
|
15
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Response envelope returned by Hyperliquid `/exchange`.
|
|
24
|
+
*
|
|
25
|
+
* A successful response may contain per-order statuses such as `filled`,
|
|
26
|
+
* `resting`, or `error`; the provider keeps the upstream status strings and
|
|
27
|
+
* numeric order IDs unchanged.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
16
30
|
export type HlExchangeResponse = {
|
|
17
31
|
status: string
|
|
18
32
|
response?:
|
|
@@ -34,28 +48,32 @@ export type HlExchangeResponse = {
|
|
|
34
48
|
}
|
|
35
49
|
}
|
|
36
50
|
|
|
37
|
-
/** @public */
|
|
51
|
+
/** EIP-712 primary type for user approval of a Hyperliquid agent wallet. @public */
|
|
38
52
|
export const HL_PRIMARY_TYPE_APPROVE_AGENT =
|
|
39
53
|
'HyperliquidTransaction:ApproveAgent' as const
|
|
40
|
-
/** @public */
|
|
54
|
+
/** EIP-712 primary type for user approval of an integrator builder fee. @public */
|
|
41
55
|
export const HL_PRIMARY_TYPE_APPROVE_BUILDER_FEE =
|
|
42
56
|
'HyperliquidTransaction:ApproveBuilderFee' as const
|
|
43
|
-
/** @public */
|
|
57
|
+
/** EIP-712 primary type for changing the user's account abstraction mode. @public */
|
|
44
58
|
export const HL_PRIMARY_TYPE_USER_SET_ABSTRACTION =
|
|
45
59
|
'HyperliquidTransaction:UserSetAbstraction' as const
|
|
46
|
-
/** @public */
|
|
60
|
+
/** EIP-712 primary type for an agent wallet changing abstraction mode. @public */
|
|
47
61
|
export const HL_PRIMARY_TYPE_AGENT_SET_ABSTRACTION =
|
|
48
62
|
'HyperliquidTransaction:AgentSetAbstraction' as const
|
|
49
|
-
/** @public */
|
|
63
|
+
/** EIP-712 primary type for withdrawing assets from Hyperliquid. @public */
|
|
50
64
|
export const HL_PRIMARY_TYPE_WITHDRAW =
|
|
51
65
|
'HyperliquidTransaction:Withdraw' as const
|
|
52
|
-
/** @public */
|
|
66
|
+
/** EIP-712 primary type for sending assets between Hyperliquid accounts or DEXes. @public */
|
|
53
67
|
export const HL_PRIMARY_TYPE_SEND_ASSET =
|
|
54
68
|
'HyperliquidTransaction:SendAsset' as const
|
|
55
|
-
/** @public */
|
|
69
|
+
/** EIP-712 primary type used by the agent wallet authorization payload. @public */
|
|
56
70
|
export const HL_PRIMARY_TYPE_AGENT = 'Agent' as const
|
|
57
71
|
|
|
58
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Union of EIP-712 primary type names supported by Hyperliquid signing actions.
|
|
74
|
+
* Values are the exact strings required in the typed-data domain.
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
59
77
|
export type HlPrimaryType =
|
|
60
78
|
| typeof HL_PRIMARY_TYPE_APPROVE_AGENT
|
|
61
79
|
| typeof HL_PRIMARY_TYPE_APPROVE_BUILDER_FEE
|
package/src/types/asset.ts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
// Asset / market metadata returned by Hyperliquid `/info`.
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Perpetual market metadata from Hyperliquid `meta.universe`.
|
|
5
|
+
* `szDecimals` is the lot-size precision; `maxLeverage` is the venue cap.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
4
8
|
export type HlUniverseItem = {
|
|
5
9
|
name: string
|
|
6
10
|
szDecimals: number
|
|
7
11
|
maxLeverage: number
|
|
8
12
|
onlyIsolated?: boolean
|
|
13
|
+
/** Current replacement for deprecated `onlyIsolated`. */
|
|
14
|
+
marginMode?: 'strictIsolated' | 'noCross'
|
|
9
15
|
isDelisted?: boolean
|
|
10
16
|
}
|
|
11
17
|
|
|
12
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Perpetual metadata envelope returned by the Hyperliquid `meta` info query.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
13
22
|
export type HlMeta = {
|
|
14
23
|
universe: HlUniverseItem[]
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Live perpetual market context from Hyperliquid `metaAndAssetCtxs`.
|
|
28
|
+
* Prices, funding, open interest, and volume are decimal strings; `funding`
|
|
29
|
+
* is a rate and `dayNtlVlm` is 24-hour notional volume.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
18
32
|
export type HlAssetCtx = {
|
|
19
33
|
funding: string
|
|
20
34
|
openInterest: string
|
|
@@ -23,13 +37,21 @@ export type HlAssetCtx = {
|
|
|
23
37
|
markPx: string
|
|
24
38
|
}
|
|
25
39
|
|
|
26
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Tuple returned by `metaAndAssetCtxs`: static universe metadata followed by
|
|
42
|
+
* one live context per universe entry.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
27
45
|
export type HlMetaAndAssetCtxs = [HlMeta, HlAssetCtx[]]
|
|
28
46
|
|
|
29
|
-
/** @public */
|
|
47
|
+
/** Alias for the perpetual universe array in {@link HlMeta}. @public */
|
|
30
48
|
export type HlUniverse = HlMeta['universe']
|
|
31
49
|
|
|
32
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* OHLCV candle from Hyperliquid's candle feed. `t` is the opening timestamp
|
|
52
|
+
* in milliseconds; prices and volume are decimal strings.
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
33
55
|
export type HlCandle = {
|
|
34
56
|
t: number
|
|
35
57
|
o: string
|
|
@@ -39,26 +61,43 @@ export type HlCandle = {
|
|
|
39
61
|
v: string
|
|
40
62
|
}
|
|
41
63
|
|
|
42
|
-
/** @public */
|
|
64
|
+
/** Snapshot array of {@link HlCandle} values, ordered by the upstream feed. @public */
|
|
43
65
|
export type HlCandleSnapshot = HlCandle[]
|
|
44
66
|
|
|
45
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* One L2 order-book level. `px` is price, `sz` is aggregate size, and `n` is
|
|
69
|
+
* the number of orders at that price; numeric values are wire strings except
|
|
70
|
+
* for the order count.
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
46
73
|
export type HlLevel = {
|
|
47
74
|
px: string
|
|
48
75
|
sz: string
|
|
49
76
|
n: number
|
|
50
77
|
}
|
|
51
78
|
|
|
52
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* L2 order-book snapshot with bid levels at index 0 and ask levels at index 1.
|
|
81
|
+
* `time` is the snapshot timestamp in milliseconds.
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
53
84
|
export type HlL2Book = {
|
|
54
85
|
levels: [HlLevel[], HlLevel[]]
|
|
55
86
|
time: number
|
|
56
87
|
}
|
|
57
88
|
|
|
58
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* Perpetual DEX descriptors from Hyperliquid `perpDexs`; `null` represents the
|
|
91
|
+
* main DEX and named entries represent HIP-3 sub-DEXes.
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
59
94
|
export type HlPerpDexs = (null | { name: string })[]
|
|
60
95
|
|
|
61
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Spot token metadata. `index` is the numeric token index used by spot
|
|
98
|
+
* clearinghouse balances; `tokenId` is the venue's wire identifier.
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
62
101
|
export type HlSpotToken = {
|
|
63
102
|
name: string
|
|
64
103
|
index: number
|
|
@@ -66,7 +105,11 @@ export type HlSpotToken = {
|
|
|
66
105
|
szDecimals: number
|
|
67
106
|
}
|
|
68
107
|
|
|
69
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Spot universe entry describing a trading pair. `tokens` contains the two
|
|
110
|
+
* numeric token indexes used by the pair.
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
70
113
|
export type HlSpotUniverseEntry = {
|
|
71
114
|
name: string
|
|
72
115
|
tokens: [number, number]
|
|
@@ -74,13 +117,17 @@ export type HlSpotUniverseEntry = {
|
|
|
74
117
|
isCanonical: boolean
|
|
75
118
|
}
|
|
76
119
|
|
|
77
|
-
/** @public */
|
|
120
|
+
/** Spot metadata envelope containing token definitions and trading pairs. @public */
|
|
78
121
|
export type HlSpotMeta = {
|
|
79
122
|
tokens: HlSpotToken[]
|
|
80
123
|
universe: HlSpotUniverseEntry[]
|
|
81
124
|
}
|
|
82
125
|
|
|
83
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Live spot token context. Prices and 24-hour volume are decimal strings;
|
|
128
|
+
* `midPx` is `null` when the venue has no midpoint for the pair.
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
84
131
|
export type HlSpotAssetCtx = {
|
|
85
132
|
coin: string
|
|
86
133
|
prevDayPx: string
|
|
@@ -89,5 +136,5 @@ export type HlSpotAssetCtx = {
|
|
|
89
136
|
midPx: string | null
|
|
90
137
|
}
|
|
91
138
|
|
|
92
|
-
/** @public */
|
|
139
|
+
/** Tuple returned by the spot metadata/context info query. @public */
|
|
93
140
|
export type HlSpotMetaAndAssetCtxs = [HlSpotMeta, HlSpotAssetCtx[]]
|
package/src/types/fill.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// Fill shapes returned by Hyperliquid `/info`.
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* One user trade fill returned by Hyperliquid `userFills` or
|
|
5
|
+
* `userFillsByTime`. Prices, size, fee, PnL, and starting position are decimal
|
|
6
|
+
* strings; `time` is milliseconds since the Unix epoch and `tid`/`oid` are
|
|
7
|
+
* numeric trade and order IDs.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
4
10
|
export type HlUserFill = {
|
|
5
11
|
tid: number
|
|
6
12
|
oid: number
|
|
@@ -17,8 +23,8 @@ export type HlUserFill = {
|
|
|
17
23
|
startPosition: string
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
/** @public */
|
|
26
|
+
/** All fills returned by the unbounded `userFills` query. @public */
|
|
21
27
|
export type HlUserFills = HlUserFill[]
|
|
22
28
|
|
|
23
|
-
/** @public */
|
|
29
|
+
/** Fills returned by the time-bounded `userFillsByTime` query. @public */
|
|
24
30
|
export type HlUserFillsByTime = HlUserFill[]
|