@lifi/perps-types 12.2.0 → 13.0.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 (62) hide show
  1. package/dist/cjs/account.d.ts +34 -23
  2. package/dist/cjs/account.d.ts.map +1 -1
  3. package/dist/cjs/action.d.ts +2 -34
  4. package/dist/cjs/action.d.ts.map +1 -1
  5. package/dist/cjs/enums.d.ts +0 -21
  6. package/dist/cjs/enums.d.ts.map +1 -1
  7. package/dist/cjs/enums.js +1 -26
  8. package/dist/cjs/enums.js.map +1 -1
  9. package/dist/cjs/index.d.ts +1 -0
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +1 -0
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/portfolioHistory.d.ts +13 -0
  14. package/dist/cjs/portfolioHistory.d.ts.map +1 -0
  15. package/dist/cjs/portfolioHistory.js +3 -0
  16. package/dist/cjs/portfolioHistory.js.map +1 -0
  17. package/dist/cjs/primitives.d.ts +1 -0
  18. package/dist/cjs/primitives.d.ts.map +1 -1
  19. package/dist/cjs/subscriptions.d.ts +2 -3
  20. package/dist/cjs/subscriptions.d.ts.map +1 -1
  21. package/dist/esm/account.d.ts +54 -57
  22. package/dist/esm/account.d.ts.map +1 -1
  23. package/dist/esm/action.d.ts +2 -53
  24. package/dist/esm/action.d.ts.map +1 -1
  25. package/dist/esm/enums.d.ts +9 -26
  26. package/dist/esm/enums.d.ts.map +1 -1
  27. package/dist/esm/enums.js +9 -30
  28. package/dist/esm/enums.js.map +1 -1
  29. package/dist/esm/index.d.ts +1 -0
  30. package/dist/esm/index.d.ts.map +1 -1
  31. package/dist/esm/index.js +1 -0
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/portfolioHistory.d.ts +26 -0
  34. package/dist/esm/portfolioHistory.d.ts.map +1 -0
  35. package/dist/esm/portfolioHistory.js +2 -0
  36. package/dist/esm/portfolioHistory.js.map +1 -0
  37. package/dist/esm/primitives.d.ts +2 -0
  38. package/dist/esm/primitives.d.ts.map +1 -1
  39. package/dist/esm/subscriptions.d.ts +3 -9
  40. package/dist/esm/subscriptions.d.ts.map +1 -1
  41. package/dist/types/account.d.ts +54 -57
  42. package/dist/types/account.d.ts.map +1 -1
  43. package/dist/types/action.d.ts +2 -53
  44. package/dist/types/action.d.ts.map +1 -1
  45. package/dist/types/enums.d.ts +9 -26
  46. package/dist/types/enums.d.ts.map +1 -1
  47. package/dist/types/index.d.ts +1 -0
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/portfolioHistory.d.ts +26 -0
  50. package/dist/types/portfolioHistory.d.ts.map +1 -0
  51. package/dist/types/primitives.d.ts +2 -0
  52. package/dist/types/primitives.d.ts.map +1 -1
  53. package/dist/types/subscriptions.d.ts +3 -9
  54. package/dist/types/subscriptions.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/src/account.ts +64 -58
  57. package/src/action.ts +1 -57
  58. package/src/enums.ts +9 -30
  59. package/src/index.ts +1 -0
  60. package/src/portfolioHistory.ts +27 -0
  61. package/src/primitives.ts +3 -0
  62. package/src/subscriptions.ts +3 -10
package/src/account.ts CHANGED
@@ -3,15 +3,17 @@ import type {
3
3
  ActionType,
4
4
  ActivityType,
5
5
  FillClassification,
6
- FillStatus,
7
6
  LiquidityRole,
8
7
  MarginMode,
9
8
  OrderSide,
9
+ OrderStatus,
10
10
  OrderType,
11
11
  PositionSide,
12
+ TimeInForce,
13
+ TriggerCondition,
12
14
  } from './enums.js'
13
15
  import type { MarketDisplay, PerpsMarketDisplay } from './market.js'
14
- import type { Address } from './primitives.js'
16
+ import type { Address, ProviderId } from './primitives.js'
15
17
 
16
18
  /**
17
19
  * Maker and taker fee rates for the account's current venue tier.
@@ -80,33 +82,63 @@ export interface PositionMarginConstraints {
80
82
  amountIncrement: string
81
83
  }
82
84
 
83
- /**
84
- * Normalized non-trigger order currently open at a provider.
85
- *
86
- * @public
87
- */
88
- export interface OpenOrder {
85
+ /** Shared identity, quantities, and lifecycle of a venue order. */
86
+ export interface OrderBase {
87
+ /** Venue-assigned id: Hyperliquid `oid`, Lighter `order_index`, Ondo `orderId`. */
89
88
  orderId: string
89
+ /** Client-set id, absent when the placer set none. */
90
+ clientOrderId?: string
90
91
  market: MarketDisplay
91
92
  side: OrderSide
92
- type: OrderType
93
- /** Quantity the order was submitted for, in base-asset units. */
93
+ status: OrderStatus
94
+ /** Venue text for a REJECTED or CANCELLED order, when the venue gives one. */
95
+ statusReason?: string
94
96
  originalSize: string
95
- /** Quantity still resting on the book, in base-asset units. */
96
97
  remainingSize: string
97
- /** Limit/order price in quote-asset units. */
98
- price: string
99
- /** Quantity already filled in base-asset units. */
100
98
  filledSize: string
99
+ averagePrice?: string
101
100
  reduceOnly: boolean
102
- label?: string
103
- /** ISO-8601 creation timestamp. */
101
+ /** Parent of a placement TP/SL leg or TWAP child; absent on position-level triggers. */
102
+ parentOrderId?: string
103
+ /** Set only when the venue row carries a transaction hash. */
104
+ explorerLink?: string
104
105
  createdAt: string
106
+ updatedAt: string
107
+ }
108
+
109
+ /** Market or limit order with a time-in-force policy. */
110
+ export interface RegularOrder extends OrderBase {
111
+ type: OrderType.MARKET | OrderType.LIMIT
112
+ price?: string
113
+ timeInForce: TimeInForce
114
+ expiresAt?: string
105
115
  }
106
116
 
117
+ /** Price-activated take-profit or stop-loss order. */
118
+ export interface TriggerOrder extends OrderBase {
119
+ type:
120
+ | OrderType.STOP_MARKET
121
+ | OrderType.STOP_LIMIT
122
+ | OrderType.TAKE_PROFIT_MARKET
123
+ | OrderType.TAKE_PROFIT_LIMIT
124
+ triggerPrice: string
125
+ triggerCondition: TriggerCondition
126
+ limitPrice?: string
127
+ }
128
+
129
+ /** Time-weighted execution parent. */
130
+ export interface TwapOrder extends OrderBase {
131
+ type: OrderType.TWAP
132
+ durationSeconds: number
133
+ startedAt: string
134
+ }
135
+
136
+ /** Venue order discriminated only by its execution type. */
137
+ export type Order = RegularOrder | TriggerOrder | TwapOrder
138
+
107
139
  /**
108
- * Asset balance normalized across providers. `units` and `valueUsd` are
109
- * decimal strings; `valueUsd` is the balance's USD valuation.
140
+ * Asset balance normalized across providers. `units`, `price` and `valueUsd`
141
+ * are decimal strings; `valueUsd` is the balance's USD valuation.
110
142
  *
111
143
  * @public
112
144
  */
@@ -117,6 +149,8 @@ export interface Balance {
117
149
  units: string
118
150
  /** USD value the SDK fills from the prices map; consumers render with zero math. */
119
151
  valueUsd: string
152
+ /** USD price of one unit. Absent when the provider holds no price for the asset. */
153
+ price?: string
120
154
  /**
121
155
  * Fraction of `valueUsd` that backs available margin (a loan-to-value
122
156
  * ratio). Absent means 1 — full value. Set below 1 for collateral the
@@ -179,25 +213,6 @@ export interface MarketSettings {
179
213
  leverage: number
180
214
  }
181
215
 
182
- /**
183
- * Normalized take-profit or stop-loss order waiting for its trigger condition.
184
- *
185
- * @public
186
- */
187
- export interface TriggerOrder {
188
- orderId: string
189
- market: MarketDisplay
190
- type: OrderType
191
- /** Triggered quantity in base-asset units. */
192
- size: string
193
- /** Price at which the trigger activates, in quote-asset units. */
194
- triggerPrice: string
195
- /** Optional limit price submitted after activation, in quote-asset units. */
196
- limitPrice?: string
197
- label?: string
198
- createdAt: string
199
- }
200
-
201
216
  /**
202
217
  * Paginated open-position response for one provider and account.
203
218
  *
@@ -209,15 +224,10 @@ export interface PositionsResponse {
209
224
  pagination: Pagination
210
225
  }
211
226
 
212
- /**
213
- * Paginated open-order response containing regular and trigger orders.
214
- *
215
- * @public
216
- */
227
+ /** Paginated order response for the requested lifecycle statuses. */
217
228
  export interface OrdersResponse {
218
- provider: string
219
- openOrders: OpenOrder[]
220
- triggerOrders: TriggerOrder[]
229
+ provider: ProviderId
230
+ orders: Order[]
221
231
  pagination: Pagination
222
232
  }
223
233
 
@@ -258,7 +268,6 @@ export interface Fill {
258
268
  type?: OrderType
259
269
  size: string
260
270
  price: string
261
- status: FillStatus
262
271
  liquidity: LiquidityRole
263
272
  filledSize?: string
264
273
  /** Absent when the venue reports no fee for the fill. */
@@ -334,11 +343,7 @@ export interface BaseActivity {
334
343
  */
335
344
  export interface DepositActivity extends BaseActivity {
336
345
  type: ActivityType.DEPOSIT
337
- /**
338
- * Display symbol of the deposited asset, resolved by the provider adapter.
339
- * Falls back to the venue's own asset id when the registry knows no symbol.
340
- */
341
- asset: string
346
+ asset: Asset
342
347
  amount: string
343
348
  /**
344
349
  * Address the deposited funds came from, as the venue reports it. Absent
@@ -357,11 +362,7 @@ export interface DepositActivity extends BaseActivity {
357
362
  */
358
363
  export interface WithdrawalActivity extends BaseActivity {
359
364
  type: ActivityType.WITHDRAWAL
360
- /**
361
- * Display symbol of the withdrawn asset, resolved by the provider adapter.
362
- * Falls back to the venue's own asset id when the registry knows no symbol.
363
- */
364
- asset: string
365
+ asset: Asset
365
366
  amount: string
366
367
  /** Absent when the venue reports no fee for the withdrawal. */
367
368
  fee?: Fee
@@ -439,7 +440,7 @@ export interface FundingActivity extends BaseActivity {
439
440
  export type TransferActivity = BaseActivity & {
440
441
  type: ActivityType.TRANSFER
441
442
  direction: 'IN' | 'OUT'
442
- asset: string
443
+ asset: Asset
443
444
  amount: string
444
445
  /**
445
446
  * Every fee the venue charged for the transfer, in the order the venue
@@ -552,7 +553,12 @@ export interface LighterAccountConfig {
552
553
  */
553
554
  apiKeyIndex?: number
554
555
  apiKeyRegistered: boolean
555
- /** Lighter `account_type`. Upstream documents no integer for any tier. */
556
+ /**
557
+ * Lighter `account_type`: the `SubAccountType` of this account
558
+ * (`Main` = 0, `Sub` = 1, `Public` = 2, `LighterPublic` = 3,
559
+ * `Staking` = 4). It is not an account tier — the tier is
560
+ * {@link LighterAccountConfig.userTierName}.
561
+ */
556
562
  accountType: number
557
563
  /**
558
564
  * Lighter `user_tier_name` from `/accountLimits`, in the tier vocabulary
package/src/action.ts CHANGED
@@ -3,14 +3,11 @@ import type {
3
3
  ActionType,
4
4
  MarginMode,
5
5
  OrderSide,
6
- OrderStatus,
7
6
  OrderType,
8
7
  PerpsErrorCode,
9
8
  TimeInForce,
10
- TriggerCondition,
11
- TwapOrderStatus,
12
9
  } from './enums.js'
13
- import type { MarketDisplay, MarketRef } from './market.js'
10
+ import type { MarketRef } from './market.js'
14
11
  import type { Address, Hex } from './primitives.js'
15
12
  import type { CreateReferralCodeParams, OnboardParams } from './referral.js'
16
13
  import type { PerpsTypedData } from './typedData.js'
@@ -296,35 +293,6 @@ export interface ModifyOrderInput {
296
293
  limitPrice?: string
297
294
  }
298
295
 
299
- /**
300
- * Normalized order returned by a provider, including lifecycle and trigger
301
- * metadata. Quantities and prices are decimal strings.
302
- *
303
- * @public
304
- */
305
- export interface Order {
306
- orderId: string
307
- market: MarketDisplay
308
- side: OrderSide
309
- type: OrderType
310
- price?: string
311
- originalSize: string
312
- remainingSize: string
313
- filledSize: string
314
- timeInForce?: TimeInForce
315
- expiresAt?: string
316
- reduceOnly?: boolean
317
- isTrigger?: boolean
318
- triggerPrice?: string
319
- triggerCondition?: TriggerCondition
320
- status: OrderStatus
321
- /** Human-readable reason for a terminal non-FILLED status; undefined when no actionable detail. */
322
- statusReason?: string
323
- averagePrice?: string
324
- createdAt: string
325
- updatedAt: string
326
- }
327
-
328
296
  /**
329
297
  * Parameters for placing a regular order on a market.
330
298
  *
@@ -403,30 +371,6 @@ export interface CancelTwapOrderParams {
403
371
  twapId: string
404
372
  }
405
373
 
406
- /**
407
- * Normalized running-TWAP read model returned by provider TWAP queries.
408
- * Quantities and prices are decimal strings.
409
- *
410
- * @public
411
- */
412
- export interface TwapOrder {
413
- /** Provider-native TWAP identifier, stringified (see {@link CancelTwapOrderParams.twapId}). */
414
- twapId: string
415
- market: MarketDisplay
416
- side: OrderSide
417
- /** Total base-asset size the TWAP was placed for. */
418
- totalSize: string
419
- /** Base-asset size executed so far. */
420
- filledSize: string
421
- /** Volume-weighted average fill price; absent until the first child fill. */
422
- avgFillPrice?: string
423
- /** ISO-8601 timestamp at which the TWAP started executing. */
424
- startedAt: string
425
- /** Total execution window in seconds. */
426
- durationSeconds: number
427
- status: TwapOrderStatus
428
- }
429
-
430
374
  /**
431
375
  * Parameters for cancelling one or more venue orders.
432
376
  *
package/src/enums.ts CHANGED
@@ -82,8 +82,7 @@ export enum OrderType {
82
82
  STOP_LIMIT = 'STOP_LIMIT',
83
83
  TAKE_PROFIT_MARKET = 'TAKE_PROFIT_MARKET',
84
84
  TAKE_PROFIT_LIMIT = 'TAKE_PROFIT_LIMIT',
85
- TRIGGER_ONLY = 'TRIGGER_ONLY',
86
- /** Read-side only: TWAP parents/children surfaced in venue order feeds. Excluded from `PlaceOrderParams.type` — placement goes through `ActionType.PLACE_TWAP_ORDER`. */
85
+ /** Returned on SDK reads; placement uses `ActionType.PLACE_TWAP_ORDER`. */
87
86
  TWAP = 'TWAP',
88
87
  }
89
88
 
@@ -119,24 +118,24 @@ export enum TimeInForce {
119
118
 
120
119
  /** Lifecycle status of a provider order. @public */
121
120
  export enum OrderStatus {
121
+ /** A placement TP/SL leg waits for its parent order to fill. */
122
122
  PENDING = 'PENDING',
123
+ /** Live on the book, or an armed trigger waiting for its trigger price. */
123
124
  OPEN = 'OPEN',
125
+ /** Open with a positive filled size. */
124
126
  PARTIALLY_FILLED = 'PARTIALLY_FILLED',
127
+ /** Terminal: the order filled. */
125
128
  FILLED = 'FILLED',
129
+ /** Terminal: the order was cancelled; statusReason carries the venue reason. */
126
130
  CANCELLED = 'CANCELLED',
131
+ /** Terminal: the order was rejected; statusReason carries the venue reason. */
127
132
  REJECTED = 'REJECTED',
133
+ /** Terminal: the order expired. */
128
134
  EXPIRED = 'EXPIRED',
135
+ /** The trigger price was hit and the order went live. */
129
136
  TRIGGERED = 'TRIGGERED',
130
137
  }
131
138
 
132
- /** Lifecycle status of an execution/fill. @public */
133
- export enum FillStatus {
134
- FILLED = 'FILLED',
135
- PARTIALLY_FILLED = 'PARTIALLY_FILLED',
136
- CANCELLED = 'CANCELLED',
137
- REJECTED = 'REJECTED',
138
- }
139
-
140
139
  /** Whether a fill supplied maker or taker liquidity. @public */
141
140
  export enum LiquidityRole {
142
141
  MAKER = 'maker',
@@ -194,26 +193,6 @@ export enum TriggerCondition {
194
193
  BELOW = 'BELOW',
195
194
  }
196
195
 
197
- /** Take-profit or stop-loss trigger order classification. @public */
198
- export enum TriggerOrderType {
199
- TAKE_PROFIT = 'TAKE_PROFIT',
200
- STOP_LOSS = 'STOP_LOSS',
201
- }
202
-
203
- /** Lifecycle status of a trigger order. @public */
204
- export enum TriggerOrderStatus {
205
- WAITING = 'WAITING',
206
- TRIGGERED = 'TRIGGERED',
207
- CANCELLED = 'CANCELLED',
208
- }
209
-
210
- /** Lifecycle status of a running TWAP order. @public */
211
- export enum TwapOrderStatus {
212
- RUNNING = 'RUNNING',
213
- COMPLETED = 'COMPLETED',
214
- CANCELLED = 'CANCELLED',
215
- }
216
-
217
196
  /** Account activity record categories. @public */
218
197
  export enum ActivityType {
219
198
  DEPOSIT = 'DEPOSIT',
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ export * from './errors.js'
16
16
  export * from './market.js'
17
17
  export * from './meta.js'
18
18
  export * from './metaProvider.js'
19
+ export * from './portfolioHistory.js'
19
20
  export * from './positionMargin.js'
20
21
  export * from './primitives.js'
21
22
  export * from './providers.js'
@@ -0,0 +1,27 @@
1
+ /** Lookback window of a portfolio history read. @public */
2
+ export type PortfolioHistoryRange = '24h' | '7d' | '30d' | 'all'
3
+
4
+ /**
5
+ * One sample of the account's portfolio over time. All values are decimal
6
+ * strings in USD.
7
+ * @public
8
+ */
9
+ export interface PortfolioHistoryPoint {
10
+ /** Unix milliseconds. */
11
+ timestamp: number
12
+ accountValue: string
13
+ /** Cumulative PnL from the start of the requested window. */
14
+ pnl: string
15
+ }
16
+
17
+ /**
18
+ * Account portfolio value over the requested window, oldest point first.
19
+ * `volume` and `totalPnl` are window totals a venue may not report.
20
+ * @public
21
+ */
22
+ export interface PortfolioHistoryResponse {
23
+ range: PortfolioHistoryRange
24
+ points: PortfolioHistoryPoint[]
25
+ volume?: string
26
+ totalPnl?: string
27
+ }
package/src/primitives.ts CHANGED
@@ -13,3 +13,6 @@ export type Address = `0x${string}`
13
13
  * @public
14
14
  */
15
15
  export type Hex = `0x${string}`
16
+
17
+ /** Opaque provider key assigned by the provider registry. */
18
+ export type ProviderId = string
@@ -2,9 +2,8 @@ import type {
2
2
  AccountSummary,
3
3
  Balance,
4
4
  Fill,
5
- OpenOrder,
5
+ Order,
6
6
  Position,
7
- TriggerOrder,
8
7
  } from './account.js'
9
8
  import type {
10
9
  Candle,
@@ -121,14 +120,8 @@ export type TradesEvent = { channel: 'trades'; data: Trade[] }
121
120
  export type OrderUpdatesEvent = {
122
121
  channel: 'orderUpdates'
123
122
  data: {
124
- /** Upserts — active orders, non-trigger. */
125
- openOrders: OpenOrder[]
126
- /** Upserts — active orders with trigger semantics (TP/SL). */
127
- triggerOrders: TriggerOrder[]
128
- /**
129
- * orderIds whose status just transitioned to terminal (filled, cancelled,
130
- * rejected, expired). Consumers should evict these from both buckets.
131
- */
123
+ orders: Order[]
124
+ /** Terminal order ids to evict from an active-order cache. */
132
125
  terminated: string[]
133
126
  }
134
127
  }