@lifi/perps-types 0.1.1-alpha.3 → 0.1.1-alpha.4

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.
@@ -1,290 +1,221 @@
1
- import { Type, type Static } from '@sinclair/typebox'
2
-
3
1
  // ---------------------------------------------------------------------------
4
- // Hyperliquid /info response schemas (TypeBox)
5
- //
6
- // Each schema produces both a JSON Schema object (for AJV validation) and a
7
- // TypeScript type via Static<>. The derived types are structurally identical
8
- // to the hand-written ones they replace.
9
- //
10
- // All schemas use additionalProperties: true (TypeBox default) so that new
11
- // fields added by Hyperliquid pass through without breaking validation.
2
+ // Hyperliquid /info response types
12
3
  // ---------------------------------------------------------------------------
13
4
 
14
5
  // -- metaAndAssetCtxs -------------------------------------------------------
15
6
 
16
- export const HlUniverseItemSchema = Type.Object({
17
- name: Type.String(),
18
- szDecimals: Type.Number(),
19
- maxLeverage: Type.Number(),
20
- onlyIsolated: Type.Boolean(),
21
- isDelisted: Type.Boolean(),
22
- })
23
- export type HlUniverseItem = Static<typeof HlUniverseItemSchema>
24
-
25
- export const HlMetaSchema = Type.Object({
26
- universe: Type.Array(HlUniverseItemSchema),
27
- })
28
- export type HlMeta = Static<typeof HlMetaSchema>
29
-
30
- export const HlAssetCtxSchema = Type.Object({
31
- funding: Type.String(),
32
- openInterest: Type.String(),
33
- dayNtlVlm: Type.String(),
34
- markPx: Type.String(),
35
- })
36
- export type HlAssetCtx = Static<typeof HlAssetCtxSchema>
37
-
38
- export const HlMetaAndAssetCtxsSchema = Type.Tuple([
39
- HlMetaSchema,
40
- Type.Array(HlAssetCtxSchema),
41
- ])
42
- export type HlMetaAndAssetCtxs = Static<typeof HlMetaAndAssetCtxsSchema>
7
+ export type HlUniverseItem = {
8
+ name: string
9
+ szDecimals: number
10
+ maxLeverage: number
11
+ onlyIsolated: boolean
12
+ isDelisted: boolean
13
+ }
14
+
15
+ export type HlMeta = {
16
+ universe: HlUniverseItem[]
17
+ }
18
+
19
+ export type HlAssetCtx = {
20
+ funding: string
21
+ openInterest: string
22
+ dayNtlVlm: string
23
+ markPx: string
24
+ }
25
+
26
+ export type HlMetaAndAssetCtxs = [HlMeta, HlAssetCtx[]]
43
27
 
44
28
  export type HlUniverse = HlMeta['universe']
45
29
 
46
30
  // -- allMids ----------------------------------------------------------------
47
31
 
48
- export const HlAllMidsSchema = Type.Record(Type.String(), Type.String())
49
- export type HlAllMids = Static<typeof HlAllMidsSchema>
32
+ export type HlAllMids = Record<string, string>
50
33
 
51
34
  // -- candleSnapshot ---------------------------------------------------------
52
35
 
53
- export const HlCandleSchema = Type.Object({
54
- t: Type.Number(),
55
- o: Type.String(),
56
- h: Type.String(),
57
- l: Type.String(),
58
- c: Type.String(),
59
- v: Type.String(),
60
- })
61
- export type HlCandle = Static<typeof HlCandleSchema>
36
+ export type HlCandle = {
37
+ t: number
38
+ o: string
39
+ h: string
40
+ l: string
41
+ c: string
42
+ v: string
43
+ }
62
44
 
63
- export const HlCandleSnapshotSchema = Type.Array(HlCandleSchema)
64
- export type HlCandleSnapshot = Static<typeof HlCandleSnapshotSchema>
45
+ export type HlCandleSnapshot = HlCandle[]
65
46
 
66
47
  // -- l2Book -----------------------------------------------------------------
67
48
 
68
- export const HlLevelSchema = Type.Object({
69
- px: Type.String(),
70
- sz: Type.String(),
71
- n: Type.Number(),
72
- })
73
- export type HlLevel = Static<typeof HlLevelSchema>
49
+ export type HlLevel = {
50
+ px: string
51
+ sz: string
52
+ n: number
53
+ }
74
54
 
75
- export const HlL2BookSchema = Type.Object({
76
- levels: Type.Tuple([Type.Array(HlLevelSchema), Type.Array(HlLevelSchema)]),
77
- time: Type.Number(),
78
- })
79
- export type HlL2Book = Static<typeof HlL2BookSchema>
55
+ export type HlL2Book = {
56
+ levels: [HlLevel[], HlLevel[]]
57
+ time: number
58
+ }
80
59
 
81
60
  // -- clearinghouseState -----------------------------------------------------
82
61
 
83
- export const HlPositionSchema = Type.Object({
84
- coin: Type.String(),
85
- szi: Type.String(),
86
- entryPx: Type.String(),
87
- positionValue: Type.String(),
88
- liquidationPx: Type.String(),
89
- unrealizedPnl: Type.String(),
90
- marginUsed: Type.String(),
91
- leverage: Type.Object({
92
- type: Type.String(),
93
- value: Type.Number(),
94
- }),
95
- })
96
- export type HlPosition = Static<typeof HlPositionSchema>
97
-
98
- export const HlAssetPositionSchema = Type.Object({
99
- position: HlPositionSchema,
100
- })
101
- export type HlAssetPosition = Static<typeof HlAssetPositionSchema>
102
-
103
- export const HlClearinghouseStateSchema = Type.Object({
104
- assetPositions: Type.Array(HlAssetPositionSchema),
105
- marginSummary: Type.Object({
106
- accountValue: Type.String(),
107
- totalMarginUsed: Type.String(),
108
- }),
109
- crossMarginSummary: Type.Object({
110
- accountValue: Type.String(),
111
- totalMarginUsed: Type.String(),
112
- }),
113
- })
114
- export type HlClearinghouseState = Static<typeof HlClearinghouseStateSchema>
62
+ export type HlPosition = {
63
+ coin: string
64
+ szi: string
65
+ entryPx: string
66
+ positionValue: string
67
+ liquidationPx: string
68
+ unrealizedPnl: string
69
+ marginUsed: string
70
+ leverage: {
71
+ type: string
72
+ value: number
73
+ }
74
+ }
75
+
76
+ export type HlAssetPosition = {
77
+ position: HlPosition
78
+ }
79
+
80
+ export type HlClearinghouseState = {
81
+ assetPositions: HlAssetPosition[]
82
+ marginSummary: {
83
+ accountValue: string
84
+ totalMarginUsed: string
85
+ }
86
+ crossMarginSummary: {
87
+ accountValue: string
88
+ totalMarginUsed: string
89
+ }
90
+ }
115
91
 
116
92
  // -- spotClearinghouseState -------------------------------------------------
117
93
 
118
- export const HlSpotBalanceSchema = Type.Object({
119
- coin: Type.String(),
120
- token: Type.Number(),
121
- total: Type.String(),
122
- hold: Type.String(),
123
- entryNtl: Type.String(),
124
- })
125
- export type HlSpotBalance = Static<typeof HlSpotBalanceSchema>
126
-
127
- export const HlSpotClearinghouseStateSchema = Type.Object({
128
- balances: Type.Array(HlSpotBalanceSchema),
129
- })
130
- export type HlSpotClearinghouseState = Static<
131
- typeof HlSpotClearinghouseStateSchema
132
- >
94
+ export type HlSpotBalance = {
95
+ coin: string
96
+ token: number
97
+ total: string
98
+ hold: string
99
+ entryNtl: string
100
+ }
101
+
102
+ export type HlSpotClearinghouseState = {
103
+ balances: HlSpotBalance[]
104
+ }
133
105
 
134
106
  // -- userFees ---------------------------------------------------------------
135
107
 
136
- export const HlUserFeesSchema = Type.Object({
137
- userAddRate: Type.String(),
138
- userCrossRate: Type.String(),
139
- activeReferralDiscount: Type.String(),
140
- })
141
- export type HlUserFees = Static<typeof HlUserFeesSchema>
108
+ export type HlUserFees = {
109
+ userAddRate: string
110
+ userCrossRate: string
111
+ activeReferralDiscount: string
112
+ }
142
113
 
143
114
  // -- frontendOpenOrders -----------------------------------------------------
144
115
 
145
- export const HlFrontendOpenOrderSchema = Type.Object({
146
- oid: Type.Number(),
147
- coin: Type.String(),
148
- side: Type.String(),
149
- sz: Type.String(),
150
- limitPx: Type.String(),
151
- orderType: Type.String(),
152
- origSz: Type.String(),
153
- reduceOnly: Type.Boolean(),
154
- timestamp: Type.Number(),
155
- })
156
- export type HlFrontendOpenOrder = Static<typeof HlFrontendOpenOrderSchema>
157
-
158
- export const HlFrontendOpenOrdersSchema = Type.Array(
159
- HlFrontendOpenOrderSchema
160
- )
161
- export type HlFrontendOpenOrders = Static<typeof HlFrontendOpenOrdersSchema>
116
+ export type HlFrontendOpenOrder = {
117
+ oid: number
118
+ coin: string
119
+ side: string
120
+ sz: string
121
+ limitPx: string
122
+ orderType: string
123
+ origSz: string
124
+ reduceOnly: boolean
125
+ timestamp: number
126
+ }
127
+
128
+ export type HlFrontendOpenOrders = HlFrontendOpenOrder[]
162
129
 
163
130
  // -- extraAgents ------------------------------------------------------------
164
131
 
165
- export const HlExtraAgentsSchema = Type.Array(
166
- Type.Record(Type.String(), Type.Unknown())
167
- )
168
- export type HlExtraAgents = Static<typeof HlExtraAgentsSchema>
132
+ export type HlExtraAgents = Record<string, unknown>[]
169
133
 
170
134
  // -- userFills / userFillsByTime --------------------------------------------
171
135
 
172
- export const HlUserFillSchema = Type.Object({
173
- tid: Type.Number(),
174
- coin: Type.String(),
175
- side: Type.String(),
176
- sz: Type.String(),
177
- px: Type.String(),
178
- dir: Type.String(),
179
- fee: Type.String(),
180
- closedPnl: Type.String(),
181
- time: Type.Number(),
182
- })
183
- export type HlUserFill = Static<typeof HlUserFillSchema>
184
-
185
- export const HlUserFillsSchema = Type.Array(HlUserFillSchema)
186
- export type HlUserFills = Static<typeof HlUserFillsSchema>
187
-
188
- export const HlUserFillsByTimeSchema = Type.Array(HlUserFillSchema)
189
- export type HlUserFillsByTime = Static<typeof HlUserFillsByTimeSchema>
136
+ export type HlUserFill = {
137
+ tid: number
138
+ coin: string
139
+ side: string
140
+ sz: string
141
+ px: string
142
+ dir: string
143
+ fee: string
144
+ closedPnl: string
145
+ time: number
146
+ }
147
+
148
+ export type HlUserFills = HlUserFill[]
149
+
150
+ export type HlUserFillsByTime = HlUserFill[]
190
151
 
191
152
  // -- orderStatus ------------------------------------------------------------
192
153
 
193
- export const HlOrderDetailSchema = Type.Object({
194
- order: Type.Object({
195
- oid: Type.Number(),
196
- coin: Type.String(),
197
- side: Type.String(),
198
- sz: Type.String(),
199
- limitPx: Type.String(),
200
- orderType: Type.String(),
201
- origSz: Type.String(),
202
- reduceOnly: Type.Boolean(),
203
- timestamp: Type.Number(),
204
- tif: Type.Union([Type.String(), Type.Null()]),
205
- cloid: Type.Union([Type.String(), Type.Null()]),
206
- triggerCondition: Type.String(),
207
- triggerPx: Type.Union([Type.String(), Type.Null()]),
208
- }),
209
- status: Type.String(),
210
- statusTimestamp: Type.Number(),
211
- })
212
- export type HlOrderDetail = Static<typeof HlOrderDetailSchema>
213
-
214
- export const HlOrderStatusFoundSchema = Type.Object({
215
- status: Type.Literal('order'),
216
- order: HlOrderDetailSchema,
217
- })
218
- export type HlOrderStatusFound = Static<typeof HlOrderStatusFoundSchema>
219
-
220
- export const HlOrderStatusResponseSchema = Type.Union([
221
- HlOrderStatusFoundSchema,
222
- Type.Object({ status: Type.Literal('unknownOid') }),
223
- ])
224
- export type HlOrderStatusResponse = Static<
225
- typeof HlOrderStatusResponseSchema
226
- >
154
+ export type HlOrderDetail = {
155
+ order: {
156
+ oid: number
157
+ coin: string
158
+ side: string
159
+ sz: string
160
+ limitPx: string
161
+ orderType: string
162
+ origSz: string
163
+ reduceOnly: boolean
164
+ timestamp: number
165
+ tif: string | null
166
+ cloid: string | null
167
+ triggerCondition: string
168
+ triggerPx: string | null
169
+ }
170
+ status: string
171
+ statusTimestamp: number
172
+ }
173
+
174
+ export type HlOrderStatusFound = {
175
+ status: 'order'
176
+ order: HlOrderDetail
177
+ }
178
+
179
+ export type HlOrderStatusResponse =
180
+ | HlOrderStatusFound
181
+ | { status: 'unknownOid' }
227
182
 
228
183
  // -- perpDexs ---------------------------------------------------------------
229
184
 
230
- export const HlPerpDexsSchema = Type.Array(
231
- Type.Union([Type.Null(), Type.Object({ name: Type.String() })])
232
- )
233
- export type HlPerpDexs = Static<typeof HlPerpDexsSchema>
185
+ export type HlPerpDexs = (null | { name: string })[]
234
186
 
235
187
  // ---------------------------------------------------------------------------
236
- // Exchange request / response schemas
188
+ // Exchange request / response types
237
189
  // ---------------------------------------------------------------------------
238
190
 
239
- export const HlExchangeRequestSchema = Type.Object({
240
- action: Type.Record(Type.String(), Type.Unknown()),
241
- signature: Type.Object({
242
- r: Type.String(),
243
- s: Type.String(),
244
- v: Type.Number(),
245
- }),
246
- nonce: Type.Number(),
247
- vaultAddress: Type.Optional(Type.Union([Type.String(), Type.Null()])),
248
- })
249
- export type HlExchangeRequest = Static<typeof HlExchangeRequestSchema>
250
-
251
- export const HlExchangeResponseSchema = Type.Object({
252
- status: Type.String(),
253
- response: Type.Optional(
254
- Type.Union([
255
- Type.String(),
256
- Type.Object({
257
- type: Type.String(),
258
- data: Type.Optional(
259
- Type.Object({
260
- statuses: Type.Optional(
261
- Type.Array(
262
- Type.Union([
263
- Type.String(),
264
- Type.Object({
265
- filled: Type.Object({
266
- totalSz: Type.String(),
267
- avgPx: Type.String(),
268
- oid: Type.Number(),
269
- }),
270
- }),
271
- Type.Object({ resting: Type.Object({ oid: Type.Number() }) }),
272
- Type.Object({
273
- waitingForFill: Type.Object({ oid: Type.Number() }),
274
- }),
275
- Type.Object({
276
- waitingForTrigger: Type.Object({ oid: Type.Number() }),
277
- }),
278
- Type.Object({ success: Type.Literal(true) }),
279
- Type.Object({ error: Type.String() }),
280
- ])
281
- )
282
- ),
283
- status: Type.Optional(Type.Unknown()),
284
- })
285
- ),
286
- }),
287
- ])
288
- ),
289
- })
290
- export type HlExchangeResponse = Static<typeof HlExchangeResponseSchema>
191
+ export type HlExchangeRequest = {
192
+ action: Record<string, unknown>
193
+ signature: {
194
+ r: string
195
+ s: string
196
+ v: number
197
+ }
198
+ nonce: number
199
+ vaultAddress?: string | null
200
+ }
201
+
202
+ export type HlExchangeResponse = {
203
+ status: string
204
+ response?:
205
+ | string
206
+ | {
207
+ type: string
208
+ data?: {
209
+ statuses?: (
210
+ | string
211
+ | { filled: { totalSz: string; avgPx: string; oid: number } }
212
+ | { resting: { oid: number } }
213
+ | { waitingForFill: { oid: number } }
214
+ | { waitingForTrigger: { oid: number } }
215
+ | { success: true }
216
+ | { error: string }
217
+ )[]
218
+ status?: unknown
219
+ }
220
+ }
221
+ }