@lifi/perps-sdk-provider-hyperliquid 1.0.1 → 1.1.0

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.
Files changed (79) hide show
  1. package/dist/cjs/services/getAccount.js +1 -1
  2. package/dist/cjs/services/getAccount.js.map +1 -1
  3. package/dist/cjs/types/asset.d.ts +0 -1
  4. package/dist/cjs/types/asset.d.ts.map +1 -1
  5. package/dist/cjs/types/ws.d.ts +17 -4
  6. package/dist/cjs/types/ws.d.ts.map +1 -1
  7. package/dist/cjs/utils/decodeFastAssetCtxs.d.ts +3 -0
  8. package/dist/cjs/utils/decodeFastAssetCtxs.d.ts.map +1 -0
  9. package/dist/cjs/utils/decodeFastAssetCtxs.js +12 -0
  10. package/dist/cjs/utils/decodeFastAssetCtxs.js.map +1 -0
  11. package/dist/cjs/utils/index.d.ts +2 -1
  12. package/dist/cjs/utils/index.d.ts.map +1 -1
  13. package/dist/cjs/utils/index.js +5 -3
  14. package/dist/cjs/utils/index.js.map +1 -1
  15. package/dist/cjs/utils/mapMarketContext.d.ts +4 -0
  16. package/dist/cjs/utils/mapMarketContext.d.ts.map +1 -0
  17. package/dist/cjs/utils/mapMarketContext.js +23 -0
  18. package/dist/cjs/utils/mapMarketContext.js.map +1 -0
  19. package/dist/cjs/websocket/HyperliquidWsProvider.d.ts +8 -5
  20. package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  21. package/dist/cjs/websocket/HyperliquidWsProvider.js +85 -38
  22. package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
  23. package/dist/esm/services/getAccount.js +2 -2
  24. package/dist/esm/services/getAccount.js.map +1 -1
  25. package/dist/esm/types/asset.d.ts +0 -2
  26. package/dist/esm/types/asset.d.ts.map +1 -1
  27. package/dist/esm/types/ws.d.ts +34 -5
  28. package/dist/esm/types/ws.d.ts.map +1 -1
  29. package/dist/esm/utils/decodeFastAssetCtxs.d.ts +11 -0
  30. package/dist/esm/utils/decodeFastAssetCtxs.d.ts.map +1 -0
  31. package/dist/esm/utils/decodeFastAssetCtxs.js +17 -0
  32. package/dist/esm/utils/decodeFastAssetCtxs.js.map +1 -0
  33. package/dist/esm/utils/index.d.ts +2 -1
  34. package/dist/esm/utils/index.d.ts.map +1 -1
  35. package/dist/esm/utils/index.js +2 -1
  36. package/dist/esm/utils/index.js.map +1 -1
  37. package/dist/esm/utils/mapMarket.d.ts +2 -2
  38. package/dist/esm/utils/mapMarket.js +2 -2
  39. package/dist/esm/utils/mapMarketContext.d.ts +10 -0
  40. package/dist/esm/utils/mapMarketContext.d.ts.map +1 -0
  41. package/dist/esm/utils/mapMarketContext.js +25 -0
  42. package/dist/esm/utils/mapMarketContext.js.map +1 -0
  43. package/dist/esm/websocket/HyperliquidWsProvider.d.ts +32 -13
  44. package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  45. package/dist/esm/websocket/HyperliquidWsProvider.js +124 -50
  46. package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
  47. package/dist/types/types/asset.d.ts +0 -2
  48. package/dist/types/types/asset.d.ts.map +1 -1
  49. package/dist/types/types/ws.d.ts +34 -5
  50. package/dist/types/types/ws.d.ts.map +1 -1
  51. package/dist/types/utils/decodeFastAssetCtxs.d.ts +11 -0
  52. package/dist/types/utils/decodeFastAssetCtxs.d.ts.map +1 -0
  53. package/dist/types/utils/index.d.ts +2 -1
  54. package/dist/types/utils/index.d.ts.map +1 -1
  55. package/dist/types/utils/mapMarket.d.ts +2 -2
  56. package/dist/types/utils/mapMarketContext.d.ts +10 -0
  57. package/dist/types/utils/mapMarketContext.d.ts.map +1 -0
  58. package/dist/types/websocket/HyperliquidWsProvider.d.ts +32 -13
  59. package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  60. package/package.json +5 -5
  61. package/src/services/getAccount.ts +2 -2
  62. package/src/types/asset.ts +0 -3
  63. package/src/types/ws.ts +36 -5
  64. package/src/utils/decodeFastAssetCtxs.ts +20 -0
  65. package/src/utils/index.ts +2 -1
  66. package/src/utils/mapMarket.ts +2 -2
  67. package/src/utils/mapMarketContext.ts +33 -0
  68. package/src/websocket/HyperliquidWsProvider.ts +135 -57
  69. package/dist/cjs/utils/mapMarketPrice.d.ts +0 -4
  70. package/dist/cjs/utils/mapMarketPrice.d.ts.map +0 -1
  71. package/dist/cjs/utils/mapMarketPrice.js +0 -22
  72. package/dist/cjs/utils/mapMarketPrice.js.map +0 -1
  73. package/dist/esm/utils/mapMarketPrice.d.ts +0 -10
  74. package/dist/esm/utils/mapMarketPrice.d.ts.map +0 -1
  75. package/dist/esm/utils/mapMarketPrice.js +0 -24
  76. package/dist/esm/utils/mapMarketPrice.js.map +0 -1
  77. package/dist/types/utils/mapMarketPrice.d.ts +0 -10
  78. package/dist/types/utils/mapMarketPrice.d.ts.map +0 -1
  79. package/src/utils/mapMarketPrice.ts +0 -33
@@ -12,6 +12,7 @@ import {
12
12
  wsLog,
13
13
  } from '@lifi/perps-sdk'
14
14
  import {
15
+ type MarketContext,
15
16
  type OpenOrder,
16
17
  OrderSide,
17
18
  OrderType,
@@ -23,18 +24,22 @@ import type {
23
24
  HlAssetPosition,
24
25
  HlOrderDetail,
25
26
  HlUserFill,
27
+ HlWsAllDexsAssetCtxsData,
26
28
  HlWsAllDexsClearinghouseStateData,
27
- HlWsAllMidsData,
28
29
  HlWsCandleData,
30
+ HlWsFastAssetCtx,
29
31
  HlWsL2BookData,
30
32
  HlWsMessage,
33
+ HlWsPerpAssetCtx,
31
34
  HlWsSpotStateData,
32
35
  HlWsUserFillsData,
33
36
  } from '../types/index.js'
34
37
  import {
38
+ decodeFastAssetCtxs,
35
39
  isOpenAssetPosition,
36
40
  isTriggerOrder,
37
41
  mapFill,
42
+ mapMarketContext,
38
43
  mapOrderStatus,
39
44
  mapOrderType,
40
45
  mapPosition,
@@ -51,23 +56,20 @@ const HL_L2_BOOK_MAX_LEVELS_PER_SIDE = 20
51
56
  * `WsProviderFactory` constructor for Hyperliquid — pass to
52
57
  * `new PerpsWsClient(client, { wsProviders: { hyperliquid: hyperliquidWsProvider() } })`.
53
58
  *
54
- * Derives the active sub-DEX set from the `markets` list `PerpsWsClient`
55
- * passes in (the provider's own key and `'spot'` are excluded — they
56
- * aren't sub-DEX subscriptions on the HL wire). Higher-order shape mirrors
57
- * `lighterWsProvider(options)` so the two factories register identically.
59
+ * Higher-order shape mirrors `lighterWsProvider(options)` so the two factories
60
+ * register identically.
58
61
  *
59
62
  * @public
60
63
  */
61
64
  export const hyperliquidWsProvider =
62
65
  (): WsProviderFactory =>
63
- ({ provider, wsUrl, markets, client }) => {
64
- const subDexes = markets.filter((m) => m !== provider && m !== 'spot')
65
- return new HyperliquidWsProvider(wsUrl, provider, subDexes, client)
66
- }
66
+ ({ provider, wsUrl, client }) =>
67
+ new HyperliquidWsProvider(wsUrl, provider, client)
67
68
 
68
69
  /**
69
- * Hyperliquid realtime {@link WsProvider}: multiplexes prices, positions,
70
- * orders, fills and spot balances over a single {@link ReconnectingWebSocket}.
70
+ * Hyperliquid realtime {@link WsProvider}: multiplexes markets context,
71
+ * positions, orders, fills and spot balances over a single
72
+ * {@link ReconnectingWebSocket}.
71
73
  * Construct via {@link hyperliquidWsProvider}.
72
74
  *
73
75
  * `orderUpdates` supports a single address per provider instance: HL delivers
@@ -80,22 +82,23 @@ export const hyperliquidWsProvider =
80
82
  */
81
83
  export class HyperliquidWsProvider extends WsProviderBase<object> {
82
84
  private orderUpdatesKey: string | undefined
83
- private readonly subDexes: string[]
84
85
  private readonly client: PerpsSDKClient | undefined
85
86
  private readonly registry: MarketRegistry | undefined
86
- private midsBySubDex = new Map<string, Record<string, string>>()
87
-
88
- constructor(
89
- wsUrl: string,
90
- providerKey: string,
91
- subDexes: string[],
92
- client?: PerpsSDKClient
93
- ) {
87
+ private perpCtxBySubDex = new Map<string, Record<string, HlWsPerpAssetCtx>>()
88
+ // Latest mid/mark per `Market.id` from the high-frequency `fastAssetCtxs`
89
+ // feed (all dexes, incl. builder/sub-dex coins). Merged incrementally —
90
+ // frames carry only changed coins — and overlaid onto the slower
91
+ // `allDexsAssetCtxs` context (which supplies oracle/funding/OI/metadata).
92
+ private fastCtxByMarketId: Record<string, HlWsFastAssetCtx> = {}
93
+ // `fastAssetCtxs` payloads are base64 + raw-DEFLATE; decode is async, so
94
+ // chain decodes to apply incremental frames in arrival order.
95
+ private fastDecodeChain: Promise<void> = Promise.resolve()
96
+
97
+ constructor(wsUrl: string, providerKey: string, client?: PerpsSDKClient) {
94
98
  super(
95
99
  new ReconnectingWebSocket(wsUrl, { pingPayload: '{"method":"ping"}' }),
96
100
  providerKey
97
101
  )
98
- this.subDexes = subDexes
99
102
  this.client = client
100
103
  this.registry = client && getMarketRegistry(client, providerKey)
101
104
  }
@@ -130,9 +133,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
130
133
 
131
134
  await this.registry?.sync()
132
135
 
133
- // Prices require multi-sub-dex allMids subscriptions under one logical key.
134
- if (sub.channel === 'prices') {
135
- const entries = this.getPriceSubEntries()
136
+ // Markets context aggregates the all-dexs perp asset-context feed
137
+ // (oracle, funding, OI, metadata) with the high-frequency `fastAssetCtxs`
138
+ // feed, which supplies fast mid + mark for every market across all dexes.
139
+ if (sub.channel === 'marketsContext') {
140
+ const entries = this.getMarketsContextSubEntries()
136
141
 
137
142
  for (const { subKey, payload } of entries) {
138
143
  await this.registerSub(subKey, payload)
@@ -147,7 +152,8 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
147
152
  JSON.stringify({ method: 'unsubscribe', subscription: payload })
148
153
  )
149
154
  }
150
- this.midsBySubDex.clear()
155
+ this.perpCtxBySubDex.clear()
156
+ this.fastCtxByMarketId = {}
151
157
  }
152
158
  }
153
159
 
@@ -192,22 +198,24 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
192
198
  this.orderUpdatesKey = key
193
199
  }
194
200
 
195
- /** Build sub-key + payload pairs for each sub-dex allMids subscription. */
196
- private getPriceSubEntries(): Array<{ subKey: string; payload: object }> {
201
+ /**
202
+ * Sub-key + payload pairs for the markets-context aggregation: the all-dexs
203
+ * perp asset-context feed (oracle/funding/OI/metadata) plus the compressed
204
+ * `fastAssetCtxs` feed (high-frequency mid + mark across every dex).
205
+ */
206
+ private getMarketsContextSubEntries(): Array<{
207
+ subKey: string
208
+ payload: object
209
+ }> {
197
210
  return [
198
- {
199
- subKey: 'allMids:default',
200
- payload: { type: 'allMids' },
201
- },
202
- ...this.subDexes.map((dex) => ({
203
- subKey: `allMids:${dex}`,
204
- payload: { type: 'allMids', dex },
205
- })),
211
+ { subKey: 'allDexsAssetCtxs', payload: { type: 'allDexsAssetCtxs' } },
212
+ { subKey: 'fastAssetCtxs', payload: { type: 'fastAssetCtxs' } },
206
213
  ]
207
214
  }
208
215
 
209
216
  protected override onClose(): void {
210
- this.midsBySubDex.clear()
217
+ this.perpCtxBySubDex.clear()
218
+ this.fastCtxByMarketId = {}
211
219
  this.orderUpdatesKey = undefined
212
220
  }
213
221
 
@@ -219,8 +227,8 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
219
227
 
220
228
  protected toKey(sub: Subscription): string {
221
229
  switch (sub.channel) {
222
- case 'prices':
223
- return 'allMids'
230
+ case 'marketsContext':
231
+ return 'marketsContext'
224
232
  case 'orderbook':
225
233
  return `l2Book:${sub.marketId}`
226
234
  case 'candle':
@@ -238,10 +246,10 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
238
246
 
239
247
  private toHlPayload(sub: Subscription): object {
240
248
  switch (sub.channel) {
241
- case 'prices':
242
- // Prices are handled via getPriceSubEntries in subscribe()
243
- // and never reach toHlPayload, but TS requires exhaustive cases.
244
- return { type: 'allMids' }
249
+ case 'marketsContext':
250
+ // Handled via getMarketsContextSubEntries in openChannel; never reaches
251
+ // toHlPayload, but TS requires an exhaustive switch.
252
+ return { type: 'allDexsAssetCtxs' }
245
253
  case 'orderbook':
246
254
  return {
247
255
  type: 'l2Book',
@@ -301,8 +309,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
301
309
 
302
310
  try {
303
311
  switch (msg.channel) {
304
- case 'allMids':
305
- this.handleAllMids(msg.data as HlWsAllMidsData)
312
+ case 'allDexsAssetCtxs':
313
+ this.handleAllDexsAssetCtxs(msg.data as HlWsAllDexsAssetCtxsData)
314
+ break
315
+ case 'fastAssetCtxs':
316
+ this.handleFastAssetCtxs(msg.data as string)
306
317
  break
307
318
  case 'l2Book':
308
319
  this.handleL2Book(msg.data as HlWsL2BookData)
@@ -330,23 +341,86 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
330
341
  }
331
342
  }
332
343
 
333
- private handleAllMids(data: HlWsAllMidsData) {
334
- const subDexKey = data.dex || 'default'
335
- this.midsBySubDex.set(subDexKey, data.mids)
336
-
337
- const merged: Record<string, string> = {}
338
- for (const mids of this.midsBySubDex.values()) {
339
- Object.assign(merged, mids)
344
+ private handleAllDexsAssetCtxs(data: HlWsAllDexsAssetCtxsData) {
345
+ for (const [dex, ctxs] of data.assetCtxs) {
346
+ const byMarketId: Record<string, HlWsPerpAssetCtx> = {}
347
+ for (const ctx of ctxs) {
348
+ byMarketId[ctx.coin] = ctx
349
+ }
350
+ this.perpCtxBySubDex.set(dex || 'default', byMarketId)
340
351
  }
352
+ this.emitMarketsContext()
353
+ }
354
+
355
+ /**
356
+ * Decode a `fastAssetCtxs` frame (base64 + raw-DEFLATE) and merge its changed
357
+ * coins into the per-market fast-context store. Frames are incremental, so a
358
+ * field absent from this frame keeps its prior value. Decodes are chained to
359
+ * preserve arrival order across the async boundary.
360
+ */
361
+ private handleFastAssetCtxs(base64: string) {
362
+ this.fastDecodeChain = this.fastDecodeChain
363
+ .then(async () => {
364
+ const ctxs = await decodeFastAssetCtxs(base64)
365
+ for (const [marketId, ctx] of Object.entries(ctxs)) {
366
+ const prev = this.fastCtxByMarketId[marketId]
367
+ this.fastCtxByMarketId[marketId] = {
368
+ markPx: 'markPx' in ctx ? ctx.markPx : prev?.markPx,
369
+ midPx: 'midPx' in ctx ? ctx.midPx : prev?.midPx,
370
+ }
371
+ }
372
+ this.emitMarketsContext()
373
+ })
374
+ .catch((error) => wsLog.handlerFailure(this.providerKey, error))
375
+ }
341
376
 
342
- this.emit('allMids', { channel: 'prices', data: merged })
377
+ /**
378
+ * Build the all-markets context map: every perp asset context across sub-dexs
379
+ * (oracle/funding/OI/metadata), with mid + mark overlaid from the
380
+ * high-frequency `fastAssetCtxs` feed. A market present in `fastAssetCtxs` but
381
+ * without an asset-context frame yet (the aggregate feed is slow/idle) still
382
+ * gets a mid+mark entry, so price ticks without waiting on the aggregate.
383
+ */
384
+ private emitMarketsContext() {
385
+ const data: Record<string, MarketContext> = {}
386
+ for (const byMarketId of this.perpCtxBySubDex.values()) {
387
+ for (const [marketId, ctx] of Object.entries(byMarketId)) {
388
+ const base = mapMarketContext(marketId, ctx)
389
+ const fast = this.fastCtxByMarketId[marketId]
390
+ data[marketId] = {
391
+ ...base,
392
+ midPrice: fast?.midPx != null ? fast.midPx : base.midPrice,
393
+ markPrice: fast?.markPx != null ? fast.markPx : base.markPrice,
394
+ }
395
+ }
396
+ }
397
+ for (const [marketId, fast] of Object.entries(this.fastCtxByMarketId)) {
398
+ if (data[marketId] !== undefined) {
399
+ continue
400
+ }
401
+ // No asset-context frame for this market yet — each price stands in for
402
+ // the other where the fast feed carries only one of mid/mark.
403
+ const midPrice = fast.midPx ?? fast.markPx
404
+ const markPrice = fast.markPx ?? fast.midPx
405
+ if (midPrice != null && markPrice != null) {
406
+ data[marketId] = { marketId, midPrice, markPrice }
407
+ }
408
+ }
409
+ this.emit('marketsContext', { channel: 'marketsContext', data })
343
410
  }
344
411
 
345
- /** Latest mid per `Market.id`, merged across sub-dex allMids frames. */
412
+ /** Latest mid per `Market.id` across the perp ctx feed and `fastAssetCtxs`. */
346
413
  private mergedMids(): Map<string, number> {
347
414
  const map = new Map<string, number>()
348
- for (const mids of this.midsBySubDex.values()) {
349
- for (const [id, mid] of Object.entries(mids)) {
415
+ for (const byMarketId of this.perpCtxBySubDex.values()) {
416
+ for (const [id, ctx] of Object.entries(byMarketId)) {
417
+ const mid = ctx.midPx ?? ctx.markPx
418
+ map.set(id, Number(mid))
419
+ }
420
+ }
421
+ for (const [id, fast] of Object.entries(this.fastCtxByMarketId)) {
422
+ const mid = fast.midPx ?? fast.markPx
423
+ if (mid != null) {
350
424
  map.set(id, Number(mid))
351
425
  }
352
426
  }
@@ -497,12 +571,16 @@ const isObject = (v: unknown): v is Record<string, unknown> =>
497
571
  * to the dispatch switch, which silently ignores them.
498
572
  */
499
573
  function isValidHlFrame(channel: string, data: unknown): boolean {
574
+ // `fastAssetCtxs` carries a base64 string payload, not an object.
575
+ if (channel === 'fastAssetCtxs') {
576
+ return typeof data === 'string'
577
+ }
500
578
  if (!isObject(data)) {
501
579
  return false
502
580
  }
503
581
  switch (channel) {
504
- case 'allMids':
505
- return isObject(data.mids)
582
+ case 'allDexsAssetCtxs':
583
+ return Array.isArray(data.assetCtxs)
506
584
  case 'l2Book':
507
585
  return (
508
586
  typeof data.coin === 'string' &&
@@ -1,4 +0,0 @@
1
- import type { MarketPrice } from '@lifi/perps-types';
2
- import type { HlAssetCtx } from '../types/index.js';
3
- export declare const mapMarketPrice: (marketId: string, assetCtx: HlAssetCtx, mid: string) => MarketPrice;
4
- //# sourceMappingURL=mapMarketPrice.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapMarketPrice.d.ts","sourceRoot":"","sources":["../../../src/utils/mapMarketPrice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAUnD,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,UAAU,UAAU,EACpB,KAAK,MAAM,KACV,WAiBF,CAAA"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapMarketPrice = void 0;
4
- const NEXT_FUNDING_INTERVAL_MS = 60 * 60 * 1000;
5
- const mapMarketPrice = (marketId, assetCtx, mid) => {
6
- const now = Date.now();
7
- const nextFundingTime = Math.ceil(now / NEXT_FUNDING_INTERVAL_MS) * NEXT_FUNDING_INTERVAL_MS;
8
- return {
9
- marketId,
10
- price: mid,
11
- markPrice: assetCtx.markPx,
12
- prevDayPrice: assetCtx.prevDayPx,
13
- volume24h: assetCtx.dayNtlVlm,
14
- openInterest: assetCtx.openInterest,
15
- funding: {
16
- rate: assetCtx.funding,
17
- nextFundingTime,
18
- },
19
- };
20
- };
21
- exports.mapMarketPrice = mapMarketPrice;
22
- //# sourceMappingURL=mapMarketPrice.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapMarketPrice.js","sourceRoot":"","sources":["../../../src/utils/mapMarketPrice.ts"],"names":[],"mappings":";;;AAGA,MAAM,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAQxC,MAAM,cAAc,GAAG,CAC5B,QAAgB,EAChB,QAAoB,EACpB,GAAW,EACE,EAAE;IACf,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACtB,MAAM,eAAe,GACnB,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,wBAAwB,CAAC,GAAG,wBAAwB,CAAA;IAEtE,OAAO;QACL,QAAQ;QACR,KAAK,EAAE,GAAG;QACV,SAAS,EAAE,QAAQ,CAAC,MAAM;QAC1B,YAAY,EAAE,QAAQ,CAAC,SAAS;QAChC,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ,CAAC,OAAO;YACtB,eAAe;SAChB;KACF,CAAA;AACH,CAAC,CAAA;AArBY,QAAA,cAAc,kBAqB1B"}
@@ -1,10 +0,0 @@
1
- import type { MarketPrice } from '@lifi/perps-types';
2
- import type { HlAssetCtx } from '../types/index.js';
3
- /**
4
- * Map a Hyperliquid asset context plus its mid to a {@link MarketPrice} — the
5
- * live mark/stats data for the `/prices` item. `mid` is the market mid from
6
- * `allMids`, known to the caller; `HlAssetCtx` carries no mid of its own.
7
- * @public
8
- */
9
- export declare const mapMarketPrice: (marketId: string, assetCtx: HlAssetCtx, mid: string) => MarketPrice;
10
- //# sourceMappingURL=mapMarketPrice.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapMarketPrice.d.ts","sourceRoot":"","sources":["../../../src/utils/mapMarketPrice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAInD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,UAAU,UAAU,EACpB,KAAK,MAAM,KACV,WAiBF,CAAA"}
@@ -1,24 +0,0 @@
1
- const NEXT_FUNDING_INTERVAL_MS = 60 * 60 * 1000; // 1 hour
2
- /**
3
- * Map a Hyperliquid asset context plus its mid to a {@link MarketPrice} — the
4
- * live mark/stats data for the `/prices` item. `mid` is the market mid from
5
- * `allMids`, known to the caller; `HlAssetCtx` carries no mid of its own.
6
- * @public
7
- */
8
- export const mapMarketPrice = (marketId, assetCtx, mid) => {
9
- const now = Date.now();
10
- const nextFundingTime = Math.ceil(now / NEXT_FUNDING_INTERVAL_MS) * NEXT_FUNDING_INTERVAL_MS;
11
- return {
12
- marketId,
13
- price: mid,
14
- markPrice: assetCtx.markPx,
15
- prevDayPrice: assetCtx.prevDayPx,
16
- volume24h: assetCtx.dayNtlVlm,
17
- openInterest: assetCtx.openInterest,
18
- funding: {
19
- rate: assetCtx.funding,
20
- nextFundingTime,
21
- },
22
- };
23
- };
24
- //# sourceMappingURL=mapMarketPrice.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapMarketPrice.js","sourceRoot":"","sources":["../../../src/utils/mapMarketPrice.ts"],"names":[],"mappings":"AAGA,MAAM,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,SAAS;AAEzD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,QAAgB,EAChB,QAAoB,EACpB,GAAW,EACE,EAAE;IACf,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACtB,MAAM,eAAe,GACnB,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,wBAAwB,CAAC,GAAG,wBAAwB,CAAA;IAEtE,OAAO;QACL,QAAQ;QACR,KAAK,EAAE,GAAG;QACV,SAAS,EAAE,QAAQ,CAAC,MAAM;QAC1B,YAAY,EAAE,QAAQ,CAAC,SAAS;QAChC,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ,CAAC,OAAO;YACtB,eAAe;SAChB;KACF,CAAA;AACH,CAAC,CAAA"}
@@ -1,10 +0,0 @@
1
- import type { MarketPrice } from '@lifi/perps-types';
2
- import type { HlAssetCtx } from '../types/index.js';
3
- /**
4
- * Map a Hyperliquid asset context plus its mid to a {@link MarketPrice} — the
5
- * live mark/stats data for the `/prices` item. `mid` is the market mid from
6
- * `allMids`, known to the caller; `HlAssetCtx` carries no mid of its own.
7
- * @public
8
- */
9
- export declare const mapMarketPrice: (marketId: string, assetCtx: HlAssetCtx, mid: string) => MarketPrice;
10
- //# sourceMappingURL=mapMarketPrice.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapMarketPrice.d.ts","sourceRoot":"","sources":["../../../src/utils/mapMarketPrice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAInD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,UAAU,UAAU,EACpB,KAAK,MAAM,KACV,WAiBF,CAAA"}
@@ -1,33 +0,0 @@
1
- import type { MarketPrice } from '@lifi/perps-types'
2
- import type { HlAssetCtx } from '../types/index.js'
3
-
4
- const NEXT_FUNDING_INTERVAL_MS = 60 * 60 * 1000 // 1 hour
5
-
6
- /**
7
- * Map a Hyperliquid asset context plus its mid to a {@link MarketPrice} — the
8
- * live mark/stats data for the `/prices` item. `mid` is the market mid from
9
- * `allMids`, known to the caller; `HlAssetCtx` carries no mid of its own.
10
- * @public
11
- */
12
- export const mapMarketPrice = (
13
- marketId: string,
14
- assetCtx: HlAssetCtx,
15
- mid: string
16
- ): MarketPrice => {
17
- const now = Date.now()
18
- const nextFundingTime =
19
- Math.ceil(now / NEXT_FUNDING_INTERVAL_MS) * NEXT_FUNDING_INTERVAL_MS
20
-
21
- return {
22
- marketId,
23
- price: mid,
24
- markPrice: assetCtx.markPx,
25
- prevDayPrice: assetCtx.prevDayPx,
26
- volume24h: assetCtx.dayNtlVlm,
27
- openInterest: assetCtx.openInterest,
28
- funding: {
29
- rate: assetCtx.funding,
30
- nextFundingTime,
31
- },
32
- }
33
- }