@lifi/perps-types 0.1.1-alpha.19 → 0.1.1-alpha.21

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 (139) hide show
  1. package/package.json +1 -1
  2. package/src/_cjs/{market.js → action.js} +1 -1
  3. package/src/_cjs/action.js.map +1 -0
  4. package/src/_cjs/{trading.js → asset.js} +1 -1
  5. package/src/_cjs/asset.js.map +1 -0
  6. package/src/_cjs/enums.js +55 -20
  7. package/src/_cjs/enums.js.map +1 -1
  8. package/src/_cjs/index.js +3 -4
  9. package/src/_cjs/index.js.map +1 -1
  10. package/src/_cjs/providers/hyperliquid/assetId.js +11 -9
  11. package/src/_cjs/providers/hyperliquid/assetId.js.map +1 -1
  12. package/src/_cjs/providers/hyperliquid/mappers/activity.js +16 -6
  13. package/src/_cjs/providers/hyperliquid/mappers/activity.js.map +1 -1
  14. package/src/_cjs/providers/hyperliquid/mappers/{market.js → asset.js} +9 -9
  15. package/src/_cjs/providers/hyperliquid/mappers/asset.js.map +1 -0
  16. package/src/_cjs/providers/hyperliquid/mappers/fill.js +64 -0
  17. package/src/_cjs/providers/hyperliquid/mappers/fill.js.map +1 -0
  18. package/src/_cjs/providers/hyperliquid/mappers/index.js +9 -7
  19. package/src/_cjs/providers/hyperliquid/mappers/index.js.map +1 -1
  20. package/src/_cjs/providers/hyperliquid/mappers/order.js +59 -16
  21. package/src/_cjs/providers/hyperliquid/mappers/order.js.map +1 -1
  22. package/src/_cjs/providers/hyperliquid/mappers/position.js +7 -5
  23. package/src/_cjs/providers/hyperliquid/mappers/position.js.map +1 -1
  24. package/src/_cjs/providers/hyperliquid/mappers/shared.js +0 -10
  25. package/src/_cjs/providers/hyperliquid/mappers/shared.js.map +1 -1
  26. package/src/_cjs/providers/hyperliquid/types.js.map +1 -1
  27. package/src/_cjs/{withdrawal.js → providers.js} +1 -1
  28. package/src/_cjs/providers.js.map +1 -0
  29. package/src/_esm/action.js +2 -0
  30. package/src/_esm/action.js.map +1 -0
  31. package/src/_esm/asset.js +2 -0
  32. package/src/_esm/asset.js.map +1 -0
  33. package/src/_esm/enums.js +54 -19
  34. package/src/_esm/enums.js.map +1 -1
  35. package/src/_esm/index.js +3 -4
  36. package/src/_esm/index.js.map +1 -1
  37. package/src/_esm/providers/hyperliquid/assetId.js +13 -11
  38. package/src/_esm/providers/hyperliquid/assetId.js.map +1 -1
  39. package/src/_esm/providers/hyperliquid/mappers/activity.js +16 -6
  40. package/src/_esm/providers/hyperliquid/mappers/activity.js.map +1 -1
  41. package/src/_esm/providers/hyperliquid/mappers/{market.js → asset.js} +7 -7
  42. package/src/_esm/providers/hyperliquid/mappers/asset.js.map +1 -0
  43. package/src/_esm/providers/hyperliquid/mappers/fill.js +62 -0
  44. package/src/_esm/providers/hyperliquid/mappers/fill.js.map +1 -0
  45. package/src/_esm/providers/hyperliquid/mappers/index.js +3 -4
  46. package/src/_esm/providers/hyperliquid/mappers/index.js.map +1 -1
  47. package/src/_esm/providers/hyperliquid/mappers/order.js +56 -15
  48. package/src/_esm/providers/hyperliquid/mappers/order.js.map +1 -1
  49. package/src/_esm/providers/hyperliquid/mappers/position.js +7 -5
  50. package/src/_esm/providers/hyperliquid/mappers/position.js.map +1 -1
  51. package/src/_esm/providers/hyperliquid/mappers/shared.js +1 -12
  52. package/src/_esm/providers/hyperliquid/mappers/shared.js.map +1 -1
  53. package/src/_esm/providers/hyperliquid/types.js.map +1 -1
  54. package/src/_esm/providers.js +2 -0
  55. package/src/_esm/providers.js.map +1 -0
  56. package/src/_types/account.d.ts +38 -22
  57. package/src/_types/account.d.ts.map +1 -1
  58. package/src/_types/action.d.ts +136 -0
  59. package/src/_types/action.d.ts.map +1 -0
  60. package/src/_types/asset.d.ts +61 -0
  61. package/src/_types/asset.d.ts.map +1 -0
  62. package/src/_types/enums.d.ts +40 -7
  63. package/src/_types/enums.d.ts.map +1 -1
  64. package/src/_types/index.d.ts +3 -4
  65. package/src/_types/index.d.ts.map +1 -1
  66. package/src/_types/providers/hyperliquid/assetId.d.ts +8 -6
  67. package/src/_types/providers/hyperliquid/assetId.d.ts.map +1 -1
  68. package/src/_types/providers/hyperliquid/mappers/activity.d.ts +2 -2
  69. package/src/_types/providers/hyperliquid/mappers/activity.d.ts.map +1 -1
  70. package/src/_types/providers/hyperliquid/mappers/asset.d.ts +4 -0
  71. package/src/_types/providers/hyperliquid/mappers/asset.d.ts.map +1 -0
  72. package/src/_types/providers/hyperliquid/mappers/fill.d.ts +6 -0
  73. package/src/_types/providers/hyperliquid/mappers/fill.d.ts.map +1 -0
  74. package/src/_types/providers/hyperliquid/mappers/index.d.ts +3 -4
  75. package/src/_types/providers/hyperliquid/mappers/index.d.ts.map +1 -1
  76. package/src/_types/providers/hyperliquid/mappers/order.d.ts +8 -3
  77. package/src/_types/providers/hyperliquid/mappers/order.d.ts.map +1 -1
  78. package/src/_types/providers/hyperliquid/mappers/position.d.ts +1 -1
  79. package/src/_types/providers/hyperliquid/mappers/position.d.ts.map +1 -1
  80. package/src/_types/providers/hyperliquid/mappers/shared.d.ts +0 -6
  81. package/src/_types/providers/hyperliquid/mappers/shared.d.ts.map +1 -1
  82. package/src/_types/providers/hyperliquid/types.d.ts +3 -1
  83. package/src/_types/providers/hyperliquid/types.d.ts.map +1 -1
  84. package/src/_types/providers.d.ts +22 -0
  85. package/src/_types/providers.d.ts.map +1 -0
  86. package/src/_types/subscriptions.d.ts +9 -18
  87. package/src/_types/subscriptions.d.ts.map +1 -1
  88. package/src/account.ts +42 -22
  89. package/src/action.ts +182 -0
  90. package/src/asset.ts +88 -0
  91. package/src/enums.ts +48 -7
  92. package/src/index.ts +3 -4
  93. package/src/providers/hyperliquid/assetId.ts +18 -12
  94. package/src/providers/hyperliquid/mappers/activity.ts +16 -6
  95. package/src/providers/hyperliquid/mappers/{market.ts → asset.ts} +9 -12
  96. package/src/providers/hyperliquid/mappers/fill.ts +77 -0
  97. package/src/providers/hyperliquid/mappers/index.ts +9 -4
  98. package/src/providers/hyperliquid/mappers/order.ts +62 -21
  99. package/src/providers/hyperliquid/mappers/position.ts +7 -10
  100. package/src/providers/hyperliquid/mappers/shared.ts +0 -15
  101. package/src/providers/hyperliquid/types.ts +3 -1
  102. package/src/providers.ts +25 -0
  103. package/src/subscriptions.ts +7 -20
  104. package/src/_cjs/authorization.js +0 -3
  105. package/src/_cjs/authorization.js.map +0 -1
  106. package/src/_cjs/market.js.map +0 -1
  107. package/src/_cjs/providers/hyperliquid/mappers/history.js +0 -22
  108. package/src/_cjs/providers/hyperliquid/mappers/history.js.map +0 -1
  109. package/src/_cjs/providers/hyperliquid/mappers/market.js.map +0 -1
  110. package/src/_cjs/trading.js.map +0 -1
  111. package/src/_cjs/withdrawal.js.map +0 -1
  112. package/src/_esm/authorization.js +0 -2
  113. package/src/_esm/authorization.js.map +0 -1
  114. package/src/_esm/market.js +0 -2
  115. package/src/_esm/market.js.map +0 -1
  116. package/src/_esm/providers/hyperliquid/mappers/history.js +0 -18
  117. package/src/_esm/providers/hyperliquid/mappers/history.js.map +0 -1
  118. package/src/_esm/providers/hyperliquid/mappers/market.js.map +0 -1
  119. package/src/_esm/trading.js +0 -2
  120. package/src/_esm/trading.js.map +0 -1
  121. package/src/_esm/withdrawal.js +0 -2
  122. package/src/_esm/withdrawal.js.map +0 -1
  123. package/src/_types/authorization.d.ts +0 -42
  124. package/src/_types/authorization.d.ts.map +0 -1
  125. package/src/_types/market.d.ts +0 -75
  126. package/src/_types/market.d.ts.map +0 -1
  127. package/src/_types/providers/hyperliquid/mappers/history.d.ts +0 -4
  128. package/src/_types/providers/hyperliquid/mappers/history.d.ts.map +0 -1
  129. package/src/_types/providers/hyperliquid/mappers/market.d.ts +0 -4
  130. package/src/_types/providers/hyperliquid/mappers/market.d.ts.map +0 -1
  131. package/src/_types/trading.d.ts +0 -135
  132. package/src/_types/trading.d.ts.map +0 -1
  133. package/src/_types/withdrawal.d.ts +0 -37
  134. package/src/_types/withdrawal.d.ts.map +0 -1
  135. package/src/authorization.ts +0 -49
  136. package/src/market.ts +0 -101
  137. package/src/providers/hyperliquid/mappers/history.ts +0 -25
  138. package/src/trading.ts +0 -168
  139. package/src/withdrawal.ts +0 -44
@@ -1,26 +1,32 @@
1
+ /** Spot asset IDs use the @pairIndex format (e.g. "@230"). */
2
+ export const assetIsSpot = (assetId: string): boolean => assetId.startsWith('@')
3
+
1
4
  /**
2
- * Calculate the asset ID for a given DEX index and asset index.
5
+ * Calculate the asset ID for a given provider index and asset index.
3
6
  *
4
- * Main DEX (dex = ''): assetId = indexInDex
5
- * HIP-3 DEXes (dex = 'xyz'): assetId = 100_000 + perpDexIndex * 10_000 + indexInDex
7
+ * Main provider (provider = ''): assetId = indexInProvider
8
+ * HIP-3 providers (provider = 'xyz'): assetId = 100_000 + perpDexIndex * 10_000 + indexInProvider
6
9
  */
7
10
  export const calculateAssetId = (
8
- dexIndex: number,
9
- indexInDex: number
11
+ providerIndex: number,
12
+ indexInProvider: number
10
13
  ): number => {
11
- if (dexIndex === 0) {
12
- return indexInDex
14
+ if (providerIndex === 0) {
15
+ return indexInProvider
13
16
  }
14
- return 100_000 + dexIndex * 10_000 + indexInDex
17
+ return 100_000 + providerIndex * 10_000 + indexInProvider
15
18
  }
16
19
 
17
20
  /**
18
- * Get the DEX index from the given list of dex names.
21
+ * Get the provider index from the given list of provider names.
19
22
  */
20
- export const getDexIndex = (dex: string, dexNames: string[]): number => {
21
- const index = dexNames.indexOf(dex)
23
+ export const getProviderIndex = (
24
+ provider: string,
25
+ providerNames: string[]
26
+ ): number => {
27
+ const index = providerNames.indexOf(provider)
22
28
  if (index === -1) {
23
- throw new Error(`Unknown sub-dex: ${dex}`)
29
+ throw new Error(`Unknown sub-provider: ${provider}`)
24
30
  }
25
31
  return index
26
32
  }
@@ -15,12 +15,12 @@ import type { HlLedgerUpdate, HlFundingUpdate } from '../types.js'
15
15
  */
16
16
  export const mapLedgerEntry = (
17
17
  entry: HlLedgerUpdate,
18
- dexKey: string
18
+ providerKey: string
19
19
  ): ActivityItem | null => {
20
20
  const { delta } = entry
21
21
  const base = {
22
22
  id: entry.hash,
23
- dex: dexKey,
23
+ provider: providerKey,
24
24
  timestamp: new Date(entry.time).toISOString(),
25
25
  }
26
26
 
@@ -55,7 +55,12 @@ export const mapLedgerEntry = (
55
55
  accountValue: d.accountValue,
56
56
  leverageType: d.leverageType,
57
57
  liquidatedPositions: (d.liquidatedPositions ?? []).map((p) => ({
58
- symbol: p.coin,
58
+ asset: {
59
+ assetId: p.coin,
60
+ market: '',
61
+ displaySymbol: p.coin,
62
+ displayQuote: null,
63
+ },
59
64
  size: p.szi,
60
65
  })),
61
66
  } satisfies LiquidationActivity
@@ -71,13 +76,18 @@ export const mapLedgerEntry = (
71
76
  */
72
77
  export const mapFundingActivity = (
73
78
  entry: HlFundingUpdate,
74
- dexKey: string
79
+ providerKey: string
75
80
  ): FundingActivity => ({
76
81
  id: entry.hash,
77
- dex: dexKey,
82
+ provider: providerKey,
78
83
  timestamp: new Date(entry.time).toISOString(),
79
84
  type: ActivityType.FUNDING,
80
- symbol: entry.delta.coin,
85
+ asset: {
86
+ assetId: entry.delta.coin,
87
+ market: '',
88
+ displaySymbol: entry.delta.coin,
89
+ displayQuote: null,
90
+ },
81
91
  amount: entry.delta.usdc,
82
92
  positionSize: entry.delta.szi,
83
93
  fundingRate: entry.delta.fundingRate,
@@ -1,26 +1,22 @@
1
- import type { Market } from '../../../market.js'
2
- import { calculateAssetId } from '../assetId.js'
1
+ import type { Asset } from '../../../asset.js'
3
2
  import type { HlAssetCtx, HlUniverseItem } from '../types.js'
4
3
 
5
4
  const NEXT_FUNDING_INTERVAL_MS = 60 * 60 * 1000 // 1 hour
6
5
 
7
- export const mapMarket = (
6
+ export const mapAsset = (
8
7
  universe: HlUniverseItem,
9
- assetCtx: HlAssetCtx,
10
- dexIndex: number,
11
- indexInDex: number,
12
- dexKey: string
13
- ): Market => {
8
+ assetCtx: HlAssetCtx
9
+ ): Asset => {
14
10
  const now = Date.now()
15
11
  const nextFundingTime =
16
12
  Math.ceil(now / NEXT_FUNDING_INTERVAL_MS) * NEXT_FUNDING_INTERVAL_MS
17
13
 
18
14
  return {
19
- symbol: universe.name,
20
- name: universe.name,
15
+ assetId: universe.name,
16
+ market: '',
17
+ displaySymbol: universe.name,
18
+ displayQuote: null,
21
19
  logoURI: `https://app.hyperliquid.xyz/coins/${universe.name}.svg`,
22
- assetId: calculateAssetId(dexIndex, indexInDex),
23
- dex: dexKey,
24
20
  szDecimals: universe.szDecimals,
25
21
  maxLeverage: universe.maxLeverage,
26
22
  onlyIsolated: universe.onlyIsolated === true,
@@ -30,6 +26,7 @@ export const mapMarket = (
30
26
  },
31
27
  openInterest: assetCtx.openInterest,
32
28
  volume24h: assetCtx.dayNtlVlm,
29
+ prevDayPrice: assetCtx.prevDayPx,
33
30
  markPrice: assetCtx.markPx,
34
31
  }
35
32
  }
@@ -0,0 +1,77 @@
1
+ import {
2
+ FillClassification,
3
+ FillStatus,
4
+ OrderSide,
5
+ OrderType,
6
+ } from '../../../enums.js'
7
+ import type { Fill } from '../../../account.js'
8
+ import type { HlUserFill } from '../types.js'
9
+ import { assetIsSpot } from '../assetId.js'
10
+
11
+ export function classifyFillFromPosition(
12
+ startPosition: string,
13
+ side: string,
14
+ sz: string
15
+ ): FillClassification {
16
+ const start = parseFloat(startPosition)
17
+ const delta = side === 'B' ? parseFloat(sz) : -parseFloat(sz)
18
+ const end = start + delta
19
+
20
+ // Position was flat → opening
21
+ if (start === 0) {
22
+ return end > 0
23
+ ? FillClassification.OPENED_LONG
24
+ : FillClassification.OPENED_SHORT
25
+ }
26
+
27
+ // Position was long
28
+ if (start > 0) {
29
+ if (end === 0) {
30
+ return FillClassification.CLOSED_LONG
31
+ }
32
+ if (end < 0) {
33
+ return FillClassification.SWITCHED_SHORT
34
+ }
35
+ if (end > start) {
36
+ return FillClassification.INCREASED_LONG
37
+ }
38
+ return FillClassification.REDUCED_LONG
39
+ }
40
+
41
+ // Position was short (start < 0)
42
+ if (end === 0) {
43
+ return FillClassification.CLOSED_SHORT
44
+ }
45
+ if (end > 0) {
46
+ return FillClassification.SWITCHED_LONG
47
+ }
48
+ if (end < start) {
49
+ return FillClassification.INCREASED_SHORT
50
+ }
51
+ return FillClassification.REDUCED_SHORT
52
+ }
53
+
54
+ export const mapFill = (fill: HlUserFill): Fill => ({
55
+ id: String(fill.tid),
56
+ asset: {
57
+ assetId: fill.coin,
58
+ market: '',
59
+ displaySymbol: fill.coin,
60
+ displayQuote: null,
61
+ },
62
+ side: fill.side === 'B' ? OrderSide.BUY : OrderSide.SELL,
63
+ type: fill.dir?.includes('Limit') ? OrderType.LIMIT : OrderType.MARKET,
64
+ size: fill.sz,
65
+ price: fill.px,
66
+ status: FillStatus.FILLED,
67
+ filledSize: fill.sz,
68
+ fee: fill.fee,
69
+ realizedPnl: fill.closedPnl === '0' ? null : fill.closedPnl,
70
+ startPosition: fill.startPosition,
71
+ classification: assetIsSpot(fill.coin)
72
+ ? fill.side === 'B'
73
+ ? FillClassification.SPOT_BUY
74
+ : FillClassification.SPOT_SELL
75
+ : classifyFillFromPosition(fill.startPosition, fill.side, fill.sz),
76
+ createdAt: new Date(fill.time).toISOString(),
77
+ })
@@ -1,6 +1,11 @@
1
- export { resolveAssetIdFromLookup } from './shared.js'
2
- export { mapMarket } from './market.js'
3
- export { mapOpenOrder, mapOrder } from './order.js'
1
+ export { mapAsset } from './asset.js'
2
+ export {
3
+ isTriggerType,
4
+ mapOpenOrder,
5
+ mapOrder,
6
+ mapOrderType,
7
+ mapTriggerOrder,
8
+ } from './order.js'
4
9
  export { mapPosition } from './position.js'
5
- export { mapHistoryItem } from './history.js'
10
+ export { classifyFillFromPosition, mapFill } from './fill.js'
6
11
  export { mapLedgerEntry, mapFundingActivity } from './activity.js'
@@ -4,39 +4,75 @@ import {
4
4
  OrderType,
5
5
  TimeInForce,
6
6
  } from '../../../enums.js'
7
- import type { OpenOrder } from '../../../account.js'
8
- import type { Order } from '../../../trading.js'
7
+ import type { OpenOrder, TriggerOrder } from '../../../account.js'
8
+ import type { Order } from '../../../action.js'
9
9
  import type { HlFrontendOpenOrder, HlOrderDetail } from '../types.js'
10
10
 
11
- import { resolveAssetIdFromLookup } from './shared.js'
11
+ /** Map a Hyperliquid orderType string to the OrderType enum. */
12
+ export const mapOrderType = (orderType: string): OrderType => {
13
+ switch (orderType) {
14
+ case 'Take Profit Market':
15
+ return OrderType.TAKE_PROFIT_MARKET
16
+ case 'Take Profit Limit':
17
+ return OrderType.TAKE_PROFIT_LIMIT
18
+ case 'Stop Market':
19
+ return OrderType.STOP_MARKET
20
+ case 'Stop Limit':
21
+ return OrderType.STOP_LIMIT
22
+ case 'Market':
23
+ return OrderType.MARKET
24
+ default:
25
+ return OrderType.LIMIT
26
+ }
27
+ }
28
+
29
+ export const isTriggerType = (type: OrderType): boolean =>
30
+ type === OrderType.TAKE_PROFIT_MARKET ||
31
+ type === OrderType.TAKE_PROFIT_LIMIT ||
32
+ type === OrderType.STOP_MARKET ||
33
+ type === OrderType.STOP_LIMIT
12
34
 
13
- export const mapOpenOrder = (
14
- o: HlFrontendOpenOrder,
15
- dexKey: string,
16
- assetIdLookup: Map<string, number>
17
- ): OpenOrder => ({
35
+ export const mapOpenOrder = (o: HlFrontendOpenOrder): OpenOrder => ({
18
36
  id: String(o.oid),
19
- symbol: o.coin,
20
- assetId: resolveAssetIdFromLookup(assetIdLookup, o.coin),
21
- dex: dexKey,
37
+ asset: {
38
+ assetId: o.coin,
39
+ market: '',
40
+ displaySymbol: o.coin,
41
+ displayQuote: null,
42
+ },
22
43
  side: o.side === 'B' ? OrderSide.BUY : OrderSide.SELL,
23
- type: o.orderType.includes('Limit') ? OrderType.LIMIT : OrderType.MARKET,
44
+ type: mapOrderType(o.orderType),
24
45
  size: o.sz,
25
46
  price: o.limitPx,
26
47
  filledSize: o.origSz
27
48
  ? (parseFloat(o.origSz) - parseFloat(o.sz)).toString()
28
49
  : '0',
29
50
  reduceOnly: o.reduceOnly ?? false,
30
- providerData: {
31
- label: o.orderType,
32
- isTrigger: o.isTrigger,
33
- isPositionTpsl: o.isPositionTpsl,
34
- triggerPrice: o.triggerPx,
35
- triggerCondition: o.triggerCondition,
36
- },
51
+ label: o.isTrigger ? o.triggerCondition : undefined,
37
52
  createdAt: new Date(o.timestamp).toISOString(),
38
53
  })
39
54
 
55
+ export const mapTriggerOrder = (o: HlFrontendOpenOrder): TriggerOrder => {
56
+ const type = mapOrderType(o.orderType)
57
+ const isLimit =
58
+ type === OrderType.TAKE_PROFIT_LIMIT || type === OrderType.STOP_LIMIT
59
+ return {
60
+ id: String(o.oid),
61
+ asset: {
62
+ assetId: o.coin,
63
+ market: '',
64
+ displaySymbol: o.coin,
65
+ displayQuote: null,
66
+ },
67
+ type,
68
+ size: o.sz,
69
+ triggerPrice: o.triggerPx,
70
+ ...(isLimit ? { limitPrice: o.limitPx } : {}),
71
+ label: o.triggerCondition,
72
+ createdAt: new Date(o.timestamp).toISOString(),
73
+ }
74
+ }
75
+
40
76
  const mapOrderStatus = (status: string): OrderStatus => {
41
77
  switch (status) {
42
78
  case 'open':
@@ -77,9 +113,14 @@ export const mapOrder = (detail: HlOrderDetail): Order => {
77
113
 
78
114
  return {
79
115
  orderId: String(o.oid),
80
- symbol: o.coin,
116
+ asset: {
117
+ assetId: o.coin,
118
+ market: '',
119
+ displaySymbol: o.coin,
120
+ displayQuote: null,
121
+ },
81
122
  side: o.side === 'B' ? OrderSide.BUY : OrderSide.SELL,
82
- type: o.orderType.includes('Limit') ? OrderType.LIMIT : OrderType.MARKET,
123
+ type: mapOrderType(o.orderType),
83
124
  price: o.limitPx,
84
125
  originalSize: o.origSz,
85
126
  remainingSize: o.sz,
@@ -2,20 +2,17 @@ import { MarginMode, PositionSide } from '../../../enums.js'
2
2
  import type { Position } from '../../../account.js'
3
3
  import type { HlAssetPosition } from '../types.js'
4
4
 
5
- import { resolveAssetIdFromLookup } from './shared.js'
6
-
7
- export const mapPosition = (
8
- ap: HlAssetPosition,
9
- dexKey: string,
10
- assetIdLookup: Map<string, number>
11
- ): Position => {
5
+ export const mapPosition = (ap: HlAssetPosition): Position => {
12
6
  const pos = ap.position
13
7
  const szi = parseFloat(pos.szi)
14
8
 
15
9
  return {
16
- symbol: pos.coin,
17
- assetId: resolveAssetIdFromLookup(assetIdLookup, pos.coin),
18
- dex: dexKey,
10
+ asset: {
11
+ assetId: pos.coin,
12
+ market: '',
13
+ displaySymbol: pos.coin,
14
+ displayQuote: null,
15
+ },
19
16
  side: szi >= 0 ? PositionSide.LONG : PositionSide.SHORT,
20
17
  size: Math.abs(szi).toString(),
21
18
  entryPrice: pos.entryPx ?? '0',
@@ -1,15 +0,0 @@
1
- /**
2
- * Look up an asset ID by symbol, throwing if the symbol is unknown.
3
- * Asset ID 0 is a valid Hyperliquid asset (BTC-PERP), so a fallback
4
- * to 0 would silently corrupt data.
5
- */
6
- export const resolveAssetIdFromLookup = (
7
- lookup: Map<string, number>,
8
- symbol: string
9
- ): number => {
10
- const id = lookup.get(symbol)
11
- if (id === undefined) {
12
- throw new Error(`Unknown asset symbol: ${symbol}`)
13
- }
14
- return id
15
- }
@@ -20,6 +20,7 @@ export type HlAssetCtx = {
20
20
  funding: string
21
21
  openInterest: string
22
22
  dayNtlVlm: string
23
+ prevDayPx: string
23
24
  markPx: string
24
25
  }
25
26
 
@@ -127,7 +128,7 @@ export type HlFrontendOpenOrder = {
127
128
  isPositionTpsl: boolean
128
129
  triggerCondition: string
129
130
  triggerPx: string
130
- children: unknown[]
131
+ children: HlFrontendOpenOrder[]
131
132
  tif: string | null
132
133
  cloid: string | null
133
134
  }
@@ -150,6 +151,7 @@ export type HlUserFill = {
150
151
  fee: string
151
152
  closedPnl: string
152
153
  time: number
154
+ startPosition: string
153
155
  }
154
156
 
155
157
  export type HlUserFills = HlUserFill[]
@@ -0,0 +1,25 @@
1
+ import type { ActionType, PerpsSigner } from './enums.js'
2
+
3
+ export interface ActionDescriptor {
4
+ type: ActionType
5
+ signers: PerpsSigner[]
6
+ }
7
+
8
+ export interface ProviderMarketInfo {
9
+ id: string
10
+ quoteAsset: string | null
11
+ }
12
+
13
+ export interface Provider {
14
+ key: string
15
+ name: string
16
+ logoURI: string
17
+ prepareAccountActions: ActionDescriptor[]
18
+ actions: ActionDescriptor[]
19
+ markets: ProviderMarketInfo[]
20
+ wsUrl?: string
21
+ }
22
+
23
+ export interface ProvidersResponse {
24
+ providers: Provider[]
25
+ }
@@ -1,12 +1,7 @@
1
1
  import type { Address } from './typedData.js'
2
- import type {
3
- Candle,
4
- OhlcvInterval,
5
- OrderbookResponse,
6
- PricesResponse,
7
- } from './market.js'
8
- import type { HistoryItem, Position } from './account.js'
9
- import type { Order } from './trading.js'
2
+ import type { Candle, OhlcvInterval, OrderbookResponse } from './asset.js'
3
+ import type { Fill, Position } from './account.js'
4
+ import type { Order } from './action.js'
10
5
 
11
6
  // --- Channels the user can subscribe to ---
12
7
 
@@ -14,18 +9,13 @@ export type PricesSubscription = { channel: 'prices'; dex: string }
14
9
  export type OrderbookSubscription = {
15
10
  channel: 'orderbook'
16
11
  dex: string
17
- symbol: string
12
+ assetId: string
18
13
  depth?: number
19
14
  }
20
- export type TradesSubscription = {
21
- channel: 'trades'
22
- dex: string
23
- symbol: string
24
- }
25
15
  export type CandleSubscription = {
26
16
  channel: 'candle'
27
17
  dex: string
28
- symbol: string
18
+ assetId: string
29
19
  interval: OhlcvInterval
30
20
  }
31
21
  export type OrderUpdatesSubscription = {
@@ -52,7 +42,6 @@ export type SpotBalancesSubscription = {
52
42
  export type Subscription =
53
43
  | PricesSubscription
54
44
  | OrderbookSubscription
55
- | TradesSubscription
56
45
  | CandleSubscription
57
46
  | OrderUpdatesSubscription
58
47
  | FillsSubscription
@@ -67,19 +56,17 @@ export interface SpotBalance {
67
56
  hold: string
68
57
  }
69
58
 
70
- export type PricesEvent = { channel: 'prices'; data: PricesResponse }
59
+ export type PricesEvent = { channel: 'prices'; data: Record<string, string> }
71
60
  export type OrderbookEvent = { channel: 'orderbook'; data: OrderbookResponse }
72
- export type TradesEvent = { channel: 'trades'; data: HistoryItem[] }
73
61
  export type CandleEvent = { channel: 'candle'; data: Candle }
74
62
  export type OrderUpdatesEvent = { channel: 'orderUpdates'; data: Order[] }
75
- export type FillsEvent = { channel: 'fills'; data: HistoryItem[] }
63
+ export type FillsEvent = { channel: 'fills'; data: Fill[] }
76
64
  export type PositionsEvent = { channel: 'positions'; data: Position[] }
77
65
  export type SpotBalancesEvent = { channel: 'spotBalances'; data: SpotBalance[] }
78
66
 
79
67
  export type SubscriptionEvent =
80
68
  | PricesEvent
81
69
  | OrderbookEvent
82
- | TradesEvent
83
70
  | CandleEvent
84
71
  | OrderUpdatesEvent
85
72
  | FillsEvent
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=authorization.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../authorization.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"market.js","sourceRoot":"","sources":["../market.ts"],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapHistoryItem = void 0;
4
- const enums_js_1 = require("../../../enums.js");
5
- const shared_js_1 = require("./shared.js");
6
- const mapHistoryItem = (fill, dexKey, assetIdLookup) => ({
7
- id: String(fill.tid),
8
- symbol: fill.coin,
9
- assetId: (0, shared_js_1.resolveAssetIdFromLookup)(assetIdLookup, fill.coin),
10
- dex: dexKey,
11
- side: fill.side === 'B' ? enums_js_1.OrderSide.BUY : enums_js_1.OrderSide.SELL,
12
- type: fill.dir?.includes('Limit') ? enums_js_1.OrderType.LIMIT : enums_js_1.OrderType.MARKET,
13
- size: fill.sz,
14
- price: fill.px,
15
- status: enums_js_1.HistoryItemStatus.FILLED,
16
- filledSize: fill.sz,
17
- fee: fill.fee,
18
- realizedPnl: fill.closedPnl === '0' ? null : fill.closedPnl,
19
- createdAt: new Date(fill.time).toISOString(),
20
- });
21
- exports.mapHistoryItem = mapHistoryItem;
22
- //# sourceMappingURL=history.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.js","sourceRoot":"","sources":["../../../../providers/hyperliquid/mappers/history.ts"],"names":[],"mappings":";;;AAAA,gDAA2E;AAI3E,2CAAsD;AAE/C,MAAM,cAAc,GAAG,CAC5B,IAAgB,EAChB,MAAc,EACd,aAAkC,EACrB,EAAE,CAAC,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;IACpB,MAAM,EAAE,IAAI,CAAC,IAAI;IACjB,OAAO,EAAE,IAAA,oCAAwB,EAAC,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC;IAC3D,GAAG,EAAE,MAAM;IACX,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,oBAAS,CAAC,GAAG,CAAC,CAAC,CAAC,oBAAS,CAAC,IAAI;IACxD,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,oBAAS,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAS,CAAC,MAAM;IACtE,IAAI,EAAE,IAAI,CAAC,EAAE;IACb,KAAK,EAAE,IAAI,CAAC,EAAE;IACd,MAAM,EAAE,4BAAiB,CAAC,MAAM;IAChC,UAAU,EAAE,IAAI,CAAC,EAAE;IACnB,GAAG,EAAE,IAAI,CAAC,GAAG;IACb,WAAW,EAAE,IAAI,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS;IAC3D,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE;CAC7C,CAAC,CAAA;AAlBW,QAAA,cAAc,kBAkBzB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"market.js","sourceRoot":"","sources":["../../../../providers/hyperliquid/mappers/market.ts"],"names":[],"mappings":";;;AACA,8CAAgD;AAGhD,MAAM,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAExC,MAAM,SAAS,GAAG,CACvB,QAAwB,EACxB,QAAoB,EACpB,QAAgB,EAChB,UAAkB,EAClB,MAAc,EACN,EAAE;IACV,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,MAAM,EAAE,QAAQ,CAAC,IAAI;QACrB,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,OAAO,EAAE,qCAAqC,QAAQ,CAAC,IAAI,MAAM;QACjE,OAAO,EAAE,IAAA,6BAAgB,EAAC,QAAQ,EAAE,UAAU,CAAC;QAC/C,GAAG,EAAE,MAAM;QACX,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,YAAY,EAAE,QAAQ,CAAC,YAAY,KAAK,IAAI;QAC5C,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ,CAAC,OAAO;YACtB,eAAe;SAChB;QACD,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,SAAS,EAAE,QAAQ,CAAC,MAAM;KAC3B,CAAA;AACH,CAAC,CAAA;AA5BY,QAAA,SAAS,aA4BrB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"trading.js","sourceRoot":"","sources":["../trading.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"withdrawal.js","sourceRoot":"","sources":["../withdrawal.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=authorization.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../authorization.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=market.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"market.js","sourceRoot":"","sources":["../market.ts"],"names":[],"mappings":""}
@@ -1,18 +0,0 @@
1
- import { HistoryItemStatus, OrderSide, OrderType } from '../../../enums.js';
2
- import { resolveAssetIdFromLookup } from './shared.js';
3
- export const mapHistoryItem = (fill, dexKey, assetIdLookup) => ({
4
- id: String(fill.tid),
5
- symbol: fill.coin,
6
- assetId: resolveAssetIdFromLookup(assetIdLookup, fill.coin),
7
- dex: dexKey,
8
- side: fill.side === 'B' ? OrderSide.BUY : OrderSide.SELL,
9
- type: fill.dir?.includes('Limit') ? OrderType.LIMIT : OrderType.MARKET,
10
- size: fill.sz,
11
- price: fill.px,
12
- status: HistoryItemStatus.FILLED,
13
- filledSize: fill.sz,
14
- fee: fill.fee,
15
- realizedPnl: fill.closedPnl === '0' ? null : fill.closedPnl,
16
- createdAt: new Date(fill.time).toISOString(),
17
- });
18
- //# sourceMappingURL=history.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.js","sourceRoot":"","sources":["../../../../providers/hyperliquid/mappers/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAI3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,IAAgB,EAChB,MAAc,EACd,aAAkC,EACrB,EAAE,CAAC,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;IACpB,MAAM,EAAE,IAAI,CAAC,IAAI;IACjB,OAAO,EAAE,wBAAwB,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC;IAC3D,GAAG,EAAE,MAAM;IACX,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI;IACxD,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM;IACtE,IAAI,EAAE,IAAI,CAAC,EAAE;IACb,KAAK,EAAE,IAAI,CAAC,EAAE;IACd,MAAM,EAAE,iBAAiB,CAAC,MAAM;IAChC,UAAU,EAAE,IAAI,CAAC,EAAE;IACnB,GAAG,EAAE,IAAI,CAAC,GAAG;IACb,WAAW,EAAE,IAAI,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS;IAC3D,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE;CAC7C,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"market.js","sourceRoot":"","sources":["../../../../providers/hyperliquid/mappers/market.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAGhD,MAAM,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,SAAS;AAEzD,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,QAAwB,EACxB,QAAoB,EACpB,QAAgB,EAChB,UAAkB,EAClB,MAAc,EACN,EAAE;IACV,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,MAAM,EAAE,QAAQ,CAAC,IAAI;QACrB,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,OAAO,EAAE,qCAAqC,QAAQ,CAAC,IAAI,MAAM;QACjE,OAAO,EAAE,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC/C,GAAG,EAAE,MAAM;QACX,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,YAAY,EAAE,QAAQ,CAAC,YAAY,KAAK,IAAI;QAC5C,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ,CAAC,OAAO;YACtB,eAAe;SAChB;QACD,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,SAAS,EAAE,QAAQ,CAAC,MAAM;KAC3B,CAAA;AACH,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=trading.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trading.js","sourceRoot":"","sources":["../trading.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=withdrawal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withdrawal.js","sourceRoot":"","sources":["../withdrawal.ts"],"names":[],"mappings":""}
@@ -1,42 +0,0 @@
1
- import type { Address, Hex, PerpsTypedData } from './typedData.js';
2
- import type { PerpsSigner } from './enums.js';
3
- export interface AuthorizationInput {
4
- key: string;
5
- params?: Record<string, unknown>;
6
- }
7
- export interface CreateAuthorizationRequest {
8
- dex: string;
9
- address: Address;
10
- signerAddress?: Address;
11
- authorizations: AuthorizationInput[];
12
- }
13
- export interface AuthorizationAction {
14
- action: string;
15
- description?: string;
16
- typedData: PerpsTypedData;
17
- signer?: PerpsSigner;
18
- optional?: boolean;
19
- }
20
- export interface CreateAuthorizationResponse {
21
- actions: AuthorizationAction[];
22
- }
23
- export interface SignedAuthorization {
24
- action: string;
25
- typedData: PerpsTypedData;
26
- signature: Hex;
27
- }
28
- export interface AuthorizationsRequest {
29
- dex: string;
30
- address: Address;
31
- signerAddress?: Address;
32
- actions: SignedAuthorization[];
33
- }
34
- export interface AuthorizationResult {
35
- action: string;
36
- success: boolean;
37
- error?: string;
38
- }
39
- export interface AuthorizationsResponse {
40
- results: AuthorizationResult[];
41
- }
42
- //# sourceMappingURL=authorization.d.ts.map