@lightconexyz/lightcone-sdk 0.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 (158) hide show
  1. package/README.md +232 -0
  2. package/dist/api/client.d.ts +225 -0
  3. package/dist/api/client.d.ts.map +1 -0
  4. package/dist/api/client.js +452 -0
  5. package/dist/api/client.js.map +1 -0
  6. package/dist/api/error.d.ts +58 -0
  7. package/dist/api/error.d.ts.map +1 -0
  8. package/dist/api/error.js +98 -0
  9. package/dist/api/error.js.map +1 -0
  10. package/dist/api/index.d.ts +23 -0
  11. package/dist/api/index.d.ts.map +1 -0
  12. package/dist/api/index.js +51 -0
  13. package/dist/api/index.js.map +1 -0
  14. package/dist/api/types/admin.d.ts +49 -0
  15. package/dist/api/types/admin.d.ts.map +1 -0
  16. package/dist/api/types/admin.js +13 -0
  17. package/dist/api/types/admin.js.map +1 -0
  18. package/dist/api/types/index.d.ts +14 -0
  19. package/dist/api/types/index.d.ts.map +1 -0
  20. package/dist/api/types/index.js +13 -0
  21. package/dist/api/types/index.js.map +1 -0
  22. package/dist/api/types/market.d.ts +186 -0
  23. package/dist/api/types/market.d.ts.map +1 -0
  24. package/dist/api/types/market.js +6 -0
  25. package/dist/api/types/market.js.map +1 -0
  26. package/dist/api/types/order.d.ts +190 -0
  27. package/dist/api/types/order.d.ts.map +1 -0
  28. package/dist/api/types/order.js +6 -0
  29. package/dist/api/types/order.js.map +1 -0
  30. package/dist/api/types/orderbook.d.ts +36 -0
  31. package/dist/api/types/orderbook.d.ts.map +1 -0
  32. package/dist/api/types/orderbook.js +6 -0
  33. package/dist/api/types/orderbook.js.map +1 -0
  34. package/dist/api/types/position.d.ts +60 -0
  35. package/dist/api/types/position.d.ts.map +1 -0
  36. package/dist/api/types/position.js +6 -0
  37. package/dist/api/types/position.js.map +1 -0
  38. package/dist/api/types/price_history.d.ts +68 -0
  39. package/dist/api/types/price_history.d.ts.map +1 -0
  40. package/dist/api/types/price_history.js +13 -0
  41. package/dist/api/types/price_history.js.map +1 -0
  42. package/dist/api/types/trade.d.ts +67 -0
  43. package/dist/api/types/trade.d.ts.map +1 -0
  44. package/dist/api/types/trade.js +13 -0
  45. package/dist/api/types/trade.js.map +1 -0
  46. package/dist/api/validation.d.ts +24 -0
  47. package/dist/api/validation.d.ts.map +1 -0
  48. package/dist/api/validation.js +53 -0
  49. package/dist/api/validation.js.map +1 -0
  50. package/dist/auth.d.ts +80 -0
  51. package/dist/auth.d.ts.map +1 -0
  52. package/dist/auth.js +149 -0
  53. package/dist/auth.js.map +1 -0
  54. package/dist/index.d.ts +55 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +107 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/network.d.ts +5 -0
  59. package/dist/network.d.ts.map +1 -0
  60. package/dist/network.js +8 -0
  61. package/dist/network.js.map +1 -0
  62. package/dist/program/accounts.d.ts +98 -0
  63. package/dist/program/accounts.d.ts.map +1 -0
  64. package/dist/program/accounts.js +319 -0
  65. package/dist/program/accounts.js.map +1 -0
  66. package/dist/program/builder.d.ts +94 -0
  67. package/dist/program/builder.d.ts.map +1 -0
  68. package/dist/program/builder.js +175 -0
  69. package/dist/program/builder.js.map +1 -0
  70. package/dist/program/client.d.ts +56 -0
  71. package/dist/program/client.d.ts.map +1 -0
  72. package/dist/program/client.js +288 -0
  73. package/dist/program/client.js.map +1 -0
  74. package/dist/program/constants.d.ts +108 -0
  75. package/dist/program/constants.d.ts.map +1 -0
  76. package/dist/program/constants.js +112 -0
  77. package/dist/program/constants.js.map +1 -0
  78. package/dist/program/index.d.ts +14 -0
  79. package/dist/program/index.d.ts.map +1 -0
  80. package/dist/program/index.js +149 -0
  81. package/dist/program/index.js.map +1 -0
  82. package/dist/program/instructions.d.ts +248 -0
  83. package/dist/program/instructions.d.ts.map +1 -0
  84. package/dist/program/instructions.js +692 -0
  85. package/dist/program/instructions.js.map +1 -0
  86. package/dist/program/orders.d.ts +151 -0
  87. package/dist/program/orders.d.ts.map +1 -0
  88. package/dist/program/orders.js +417 -0
  89. package/dist/program/orders.js.map +1 -0
  90. package/dist/program/pda.d.ts +73 -0
  91. package/dist/program/pda.d.ts.map +1 -0
  92. package/dist/program/pda.js +131 -0
  93. package/dist/program/pda.js.map +1 -0
  94. package/dist/program/types.d.ts +380 -0
  95. package/dist/program/types.d.ts.map +1 -0
  96. package/dist/program/types.js +27 -0
  97. package/dist/program/types.js.map +1 -0
  98. package/dist/program/utils.d.ts +91 -0
  99. package/dist/program/utils.d.ts.map +1 -0
  100. package/dist/program/utils.js +219 -0
  101. package/dist/program/utils.js.map +1 -0
  102. package/dist/shared/index.d.ts +8 -0
  103. package/dist/shared/index.d.ts.map +1 -0
  104. package/dist/shared/index.js +18 -0
  105. package/dist/shared/index.js.map +1 -0
  106. package/dist/shared/price.d.ts +41 -0
  107. package/dist/shared/price.d.ts.map +1 -0
  108. package/dist/shared/price.js +57 -0
  109. package/dist/shared/price.js.map +1 -0
  110. package/dist/shared/scaling.d.ts +45 -0
  111. package/dist/shared/scaling.d.ts.map +1 -0
  112. package/dist/shared/scaling.js +84 -0
  113. package/dist/shared/scaling.js.map +1 -0
  114. package/dist/shared/types.d.ts +19 -0
  115. package/dist/shared/types.d.ts.map +1 -0
  116. package/dist/shared/types.js +23 -0
  117. package/dist/shared/types.js.map +1 -0
  118. package/dist/websocket/client.d.ts +238 -0
  119. package/dist/websocket/client.d.ts.map +1 -0
  120. package/dist/websocket/client.js +580 -0
  121. package/dist/websocket/client.js.map +1 -0
  122. package/dist/websocket/error.d.ts +47 -0
  123. package/dist/websocket/error.d.ts.map +1 -0
  124. package/dist/websocket/error.js +83 -0
  125. package/dist/websocket/error.js.map +1 -0
  126. package/dist/websocket/handlers.d.ts +97 -0
  127. package/dist/websocket/handlers.d.ts.map +1 -0
  128. package/dist/websocket/handlers.js +277 -0
  129. package/dist/websocket/handlers.js.map +1 -0
  130. package/dist/websocket/index.d.ts +38 -0
  131. package/dist/websocket/index.d.ts.map +1 -0
  132. package/dist/websocket/index.js +75 -0
  133. package/dist/websocket/index.js.map +1 -0
  134. package/dist/websocket/state/index.d.ts +7 -0
  135. package/dist/websocket/state/index.d.ts.map +1 -0
  136. package/dist/websocket/state/index.js +14 -0
  137. package/dist/websocket/state/index.js.map +1 -0
  138. package/dist/websocket/state/orderbook.d.ts +107 -0
  139. package/dist/websocket/state/orderbook.d.ts.map +1 -0
  140. package/dist/websocket/state/orderbook.js +293 -0
  141. package/dist/websocket/state/orderbook.js.map +1 -0
  142. package/dist/websocket/state/price.d.ts +108 -0
  143. package/dist/websocket/state/price.d.ts.map +1 -0
  144. package/dist/websocket/state/price.js +243 -0
  145. package/dist/websocket/state/price.js.map +1 -0
  146. package/dist/websocket/state/user.d.ts +83 -0
  147. package/dist/websocket/state/user.d.ts.map +1 -0
  148. package/dist/websocket/state/user.js +228 -0
  149. package/dist/websocket/state/user.js.map +1 -0
  150. package/dist/websocket/subscriptions.d.ts +143 -0
  151. package/dist/websocket/subscriptions.d.ts.map +1 -0
  152. package/dist/websocket/subscriptions.js +244 -0
  153. package/dist/websocket/subscriptions.js.map +1 -0
  154. package/dist/websocket/types.d.ts +417 -0
  155. package/dist/websocket/types.d.ts.map +1 -0
  156. package/dist/websocket/types.js +195 -0
  157. package/dist/websocket/types.js.map +1 -0
  158. package/package.json +75 -0
@@ -0,0 +1,417 @@
1
+ /**
2
+ * Message types for the Lightcone WebSocket protocol.
3
+ *
4
+ * This module contains all request and response types for the WebSocket API.
5
+ */
6
+ import type { WebSocketError } from "./error";
7
+ /**
8
+ * Subscribe/Unsubscribe request wrapper.
9
+ */
10
+ export interface WsRequest {
11
+ method: string;
12
+ params?: SubscribeParams;
13
+ }
14
+ /**
15
+ * Subscription parameters (polymorphic).
16
+ */
17
+ export type SubscribeParams = BookUpdateParams | TradesParams | UserParams | PriceHistoryParams | MarketParams;
18
+ /**
19
+ * Book update subscription params.
20
+ */
21
+ export interface BookUpdateParams {
22
+ type: "book_update";
23
+ orderbook_ids: string[];
24
+ }
25
+ /**
26
+ * Trades subscription params.
27
+ */
28
+ export interface TradesParams {
29
+ type: "trades";
30
+ orderbook_ids: string[];
31
+ }
32
+ /**
33
+ * User subscription params.
34
+ */
35
+ export interface UserParams {
36
+ type: "user";
37
+ user: string;
38
+ }
39
+ /**
40
+ * Price history subscription params.
41
+ */
42
+ export interface PriceHistoryParams {
43
+ type: "price_history";
44
+ orderbook_id: string;
45
+ resolution: string;
46
+ include_ohlcv: boolean;
47
+ }
48
+ /**
49
+ * Market subscription params.
50
+ */
51
+ export interface MarketParams {
52
+ type: "market";
53
+ market_pubkey: string;
54
+ }
55
+ /**
56
+ * Create a subscribe request.
57
+ */
58
+ export declare function createSubscribeRequest(params: SubscribeParams): WsRequest;
59
+ /**
60
+ * Create an unsubscribe request.
61
+ */
62
+ export declare function createUnsubscribeRequest(params: SubscribeParams): WsRequest;
63
+ /**
64
+ * Create a ping request.
65
+ */
66
+ export declare function createPingRequest(): WsRequest;
67
+ /**
68
+ * Create book update subscription params.
69
+ */
70
+ export declare function bookUpdateParams(orderbookIds: string[]): BookUpdateParams;
71
+ /**
72
+ * Create trades subscription params.
73
+ */
74
+ export declare function tradesParams(orderbookIds: string[]): TradesParams;
75
+ /**
76
+ * Create user subscription params.
77
+ */
78
+ export declare function userParams(user: string): UserParams;
79
+ /**
80
+ * Create price history subscription params.
81
+ */
82
+ export declare function priceHistoryParams(orderbookId: string, resolution: string, includeOhlcv: boolean): PriceHistoryParams;
83
+ /**
84
+ * Create market subscription params.
85
+ */
86
+ export declare function marketParams(marketPubkey: string): MarketParams;
87
+ /**
88
+ * Auth response data.
89
+ */
90
+ export interface AuthData {
91
+ status: "authenticated" | "anonymous" | "error";
92
+ user_pubkey?: string;
93
+ message?: string;
94
+ }
95
+ /**
96
+ * Server → Client message (discriminated union).
97
+ * TypeScript automatically narrows the `data` type based on `type` field.
98
+ */
99
+ export type WsServerMessage = {
100
+ type: "book_update";
101
+ version: number;
102
+ data: BookUpdateData;
103
+ } | {
104
+ type: "trades";
105
+ version: number;
106
+ data: TradeData;
107
+ } | {
108
+ type: "user";
109
+ version: number;
110
+ data: UserEventData;
111
+ } | {
112
+ type: "price_history";
113
+ version: number;
114
+ data: PriceHistoryData;
115
+ } | {
116
+ type: "market";
117
+ version: number;
118
+ data: MarketEventData;
119
+ } | {
120
+ type: "auth";
121
+ version: number;
122
+ data: AuthData;
123
+ } | {
124
+ type: "pong";
125
+ version: number;
126
+ data: PongData;
127
+ } | {
128
+ type: "error";
129
+ version: number;
130
+ data: ErrorData;
131
+ };
132
+ /**
133
+ * Parse a WebSocket message from raw text.
134
+ * Single validation point at JSON.parse boundary.
135
+ */
136
+ export declare function parseWsMessage(text: string): WsServerMessage | null;
137
+ /**
138
+ * Generic WebSocket message wrapper.
139
+ */
140
+ export interface WsMessage<T> {
141
+ type: string;
142
+ version: number;
143
+ data: T;
144
+ }
145
+ /**
146
+ * Orderbook snapshot/delta data.
147
+ */
148
+ export interface BookUpdateData {
149
+ orderbook_id: string;
150
+ timestamp: string;
151
+ seq: number;
152
+ bids: PriceLevel[];
153
+ asks: PriceLevel[];
154
+ is_snapshot: boolean;
155
+ resync: boolean;
156
+ message?: string;
157
+ }
158
+ /**
159
+ * Price level in the orderbook.
160
+ */
161
+ export interface PriceLevel {
162
+ side: string;
163
+ /** Price as decimal string (e.g., "0.500000") */
164
+ price: string;
165
+ /** Size as decimal string */
166
+ size: string;
167
+ }
168
+ /**
169
+ * Trade execution data.
170
+ */
171
+ export interface TradeData {
172
+ orderbook_id: string;
173
+ /** Price as decimal string */
174
+ price: string;
175
+ /** Size as decimal string */
176
+ size: string;
177
+ side: string;
178
+ timestamp: string;
179
+ trade_id: string;
180
+ }
181
+ /**
182
+ * User event data (snapshot, order_update, balance_update).
183
+ */
184
+ export interface UserEventData {
185
+ event_type: string;
186
+ orders: Order[];
187
+ balances: Record<string, BalanceEntry>;
188
+ order?: OrderUpdate;
189
+ balance?: Balance;
190
+ market_pubkey?: string;
191
+ orderbook_id?: string;
192
+ deposit_mint?: string;
193
+ timestamp?: string;
194
+ }
195
+ /**
196
+ * User order from snapshot.
197
+ */
198
+ export interface Order {
199
+ order_hash: string;
200
+ market_pubkey: string;
201
+ orderbook_id: string;
202
+ /** 0 = BUY, 1 = SELL */
203
+ side: number;
204
+ /** Maker amount as decimal string */
205
+ maker_amount: string;
206
+ /** Taker amount as decimal string */
207
+ taker_amount: string;
208
+ /** Remaining amount as decimal string */
209
+ remaining: string;
210
+ /** Filled amount as decimal string */
211
+ filled: string;
212
+ /** Price as decimal string */
213
+ price: string;
214
+ created_at: number;
215
+ expiration: number;
216
+ }
217
+ /**
218
+ * Order update from real-time event.
219
+ */
220
+ export interface OrderUpdate {
221
+ order_hash: string;
222
+ /** Price as decimal string */
223
+ price: string;
224
+ /** Fill amount as decimal string */
225
+ fill_amount: string;
226
+ /** Remaining amount as decimal string */
227
+ remaining: string;
228
+ /** Filled amount as decimal string */
229
+ filled: string;
230
+ /** 0 = BUY, 1 = SELL */
231
+ side: number;
232
+ is_maker: boolean;
233
+ created_at: number;
234
+ balance?: Balance;
235
+ }
236
+ /**
237
+ * Balance containing outcome balances.
238
+ */
239
+ export interface Balance {
240
+ outcomes: OutcomeBalance[];
241
+ }
242
+ /**
243
+ * Individual outcome balance.
244
+ */
245
+ export interface OutcomeBalance {
246
+ outcome_index: number;
247
+ mint: string;
248
+ /** Idle balance as decimal string */
249
+ idle: string;
250
+ /** On-book balance as decimal string */
251
+ on_book: string;
252
+ }
253
+ /**
254
+ * Balance entry from user snapshot.
255
+ */
256
+ export interface BalanceEntry {
257
+ market_pubkey: string;
258
+ deposit_mint: string;
259
+ outcomes: OutcomeBalance[];
260
+ }
261
+ /**
262
+ * Price history data (snapshot, update, heartbeat).
263
+ */
264
+ export interface PriceHistoryData {
265
+ event_type: string;
266
+ orderbook_id?: string;
267
+ resolution?: string;
268
+ include_ohlcv?: boolean;
269
+ prices: Candle[];
270
+ last_timestamp?: number;
271
+ server_time?: number;
272
+ last_processed?: number;
273
+ t?: number;
274
+ o?: string;
275
+ h?: string;
276
+ l?: string;
277
+ c?: string;
278
+ v?: string;
279
+ m?: string;
280
+ bb?: string;
281
+ ba?: string;
282
+ }
283
+ /**
284
+ * Convert inline candle data to a Candle struct (for update events).
285
+ */
286
+ export declare function toCandle(data: PriceHistoryData): Candle | undefined;
287
+ /**
288
+ * OHLCV candle data.
289
+ */
290
+ export interface Candle {
291
+ /** Timestamp (Unix ms) */
292
+ t: number;
293
+ /** Open price as decimal string (null if no trades) */
294
+ o?: string;
295
+ /** High price as decimal string (null if no trades) */
296
+ h?: string;
297
+ /** Low price as decimal string (null if no trades) */
298
+ l?: string;
299
+ /** Close price as decimal string (null if no trades) */
300
+ c?: string;
301
+ /** Volume as decimal string (null if no trades) */
302
+ v?: string;
303
+ /** Midpoint: (best_bid + best_ask) / 2 as decimal string */
304
+ m?: string;
305
+ /** Best bid price as decimal string */
306
+ bb?: string;
307
+ /** Best ask price as decimal string */
308
+ ba?: string;
309
+ }
310
+ /**
311
+ * Market event data.
312
+ */
313
+ export interface MarketEventData {
314
+ /** Event type: "orderbook_created", "settled", "opened", "paused" */
315
+ event_type: string;
316
+ market_pubkey: string;
317
+ orderbook_id?: string;
318
+ timestamp: string;
319
+ }
320
+ /**
321
+ * Market event types.
322
+ */
323
+ export type MarketEventType = "OrderbookCreated" | "Settled" | "Opened" | "Paused" | "Unknown";
324
+ /**
325
+ * Parse market event type from string.
326
+ */
327
+ export declare function parseMarketEventType(s: string): MarketEventType;
328
+ /**
329
+ * Error response from server.
330
+ */
331
+ export interface ErrorData {
332
+ error: string;
333
+ code: string;
334
+ orderbook_id?: string;
335
+ }
336
+ /**
337
+ * Server error codes.
338
+ */
339
+ export type ErrorCode = "EngineUnavailable" | "InvalidJson" | "InvalidMethod" | "RateLimited" | "Unknown";
340
+ /**
341
+ * Parse error code from string.
342
+ */
343
+ export declare function parseErrorCode(s: string): ErrorCode;
344
+ /**
345
+ * Pong response data (empty).
346
+ */
347
+ export interface PongData {
348
+ }
349
+ /**
350
+ * Events emitted by the WebSocket client.
351
+ */
352
+ export type WsEvent = {
353
+ type: "Connected";
354
+ } | {
355
+ type: "Disconnected";
356
+ reason: string;
357
+ } | {
358
+ type: "BookUpdate";
359
+ orderbookId: string;
360
+ isSnapshot: boolean;
361
+ } | {
362
+ type: "Trade";
363
+ orderbookId: string;
364
+ trade: TradeData;
365
+ } | {
366
+ type: "UserUpdate";
367
+ eventType: string;
368
+ user: string;
369
+ } | {
370
+ type: "PriceUpdate";
371
+ orderbookId: string;
372
+ resolution: string;
373
+ } | {
374
+ type: "MarketEvent";
375
+ eventType: string;
376
+ marketPubkey: string;
377
+ } | {
378
+ type: "Error";
379
+ error: WebSocketError;
380
+ } | {
381
+ type: "ResyncRequired";
382
+ orderbookId: string;
383
+ } | {
384
+ type: "Pong";
385
+ } | {
386
+ type: "Reconnecting";
387
+ attempt: number;
388
+ };
389
+ /**
390
+ * Enum for all possible server message types.
391
+ */
392
+ export type MessageType = "BookUpdate" | "Trades" | "User" | "PriceHistory" | "Market" | "Error" | "Pong" | "Unknown";
393
+ /**
394
+ * Parse message type from string.
395
+ */
396
+ export declare function parseMessageType(s: string): MessageType;
397
+ /**
398
+ * Order side enum for user events.
399
+ */
400
+ export type Side = "Buy" | "Sell";
401
+ /**
402
+ * Parse side from number.
403
+ */
404
+ export declare function parseSide(value: number): Side;
405
+ /**
406
+ * Convert side to number.
407
+ */
408
+ export declare function sideToNumber(side: Side): number;
409
+ /**
410
+ * Price level side (from orderbook updates).
411
+ */
412
+ export type PriceLevelSide = "Bid" | "Ask";
413
+ /**
414
+ * Parse price level side from string.
415
+ */
416
+ export declare function parsePriceLevelSide(s: string): PriceLevelSide;
417
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/websocket/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,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
+ * This module contains all request and response types for the WebSocket API.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.createSubscribeRequest = createSubscribeRequest;
9
+ exports.createUnsubscribeRequest = createUnsubscribeRequest;
10
+ exports.createPingRequest = createPingRequest;
11
+ exports.bookUpdateParams = bookUpdateParams;
12
+ exports.tradesParams = tradesParams;
13
+ exports.userParams = userParams;
14
+ exports.priceHistoryParams = priceHistoryParams;
15
+ exports.marketParams = marketParams;
16
+ exports.parseWsMessage = parseWsMessage;
17
+ exports.toCandle = toCandle;
18
+ exports.parseMarketEventType = parseMarketEventType;
19
+ exports.parseErrorCode = parseErrorCode;
20
+ exports.parseMessageType = parseMessageType;
21
+ exports.parseSide = parseSide;
22
+ exports.sideToNumber = sideToNumber;
23
+ exports.parsePriceLevelSide = parsePriceLevelSide;
24
+ /**
25
+ * Create a subscribe request.
26
+ */
27
+ function createSubscribeRequest(params) {
28
+ return { method: "subscribe", params };
29
+ }
30
+ /**
31
+ * Create an unsubscribe request.
32
+ */
33
+ function createUnsubscribeRequest(params) {
34
+ return { method: "unsubscribe", params };
35
+ }
36
+ /**
37
+ * Create a ping request.
38
+ */
39
+ function createPingRequest() {
40
+ return { method: "ping" };
41
+ }
42
+ /**
43
+ * Create book update subscription params.
44
+ */
45
+ function bookUpdateParams(orderbookIds) {
46
+ return { type: "book_update", orderbook_ids: orderbookIds };
47
+ }
48
+ /**
49
+ * Create trades subscription params.
50
+ */
51
+ function tradesParams(orderbookIds) {
52
+ return { type: "trades", orderbook_ids: orderbookIds };
53
+ }
54
+ /**
55
+ * Create user subscription params.
56
+ */
57
+ function userParams(user) {
58
+ return { type: "user", user };
59
+ }
60
+ /**
61
+ * Create price history subscription params.
62
+ */
63
+ function priceHistoryParams(orderbookId, resolution, includeOhlcv) {
64
+ return {
65
+ type: "price_history",
66
+ orderbook_id: orderbookId,
67
+ resolution,
68
+ include_ohlcv: includeOhlcv,
69
+ };
70
+ }
71
+ /**
72
+ * Create market subscription params.
73
+ */
74
+ function marketParams(marketPubkey) {
75
+ return { type: "market", market_pubkey: marketPubkey };
76
+ }
77
+ /**
78
+ * Parse a WebSocket message from raw text.
79
+ * Single validation point at JSON.parse boundary.
80
+ */
81
+ function parseWsMessage(text) {
82
+ let raw;
83
+ try {
84
+ raw = JSON.parse(text);
85
+ }
86
+ catch {
87
+ return null;
88
+ }
89
+ if (typeof raw !== "object" || raw === null)
90
+ return null;
91
+ const obj = raw;
92
+ if (typeof obj.type !== "string" || typeof obj.version !== "number") {
93
+ return null;
94
+ }
95
+ // All message types except "pong" must have a data field
96
+ if (obj.type !== "pong" && (obj.data === undefined || obj.data === null)) {
97
+ return null;
98
+ }
99
+ // We trust the server sends correct data shapes for each type
100
+ return obj;
101
+ }
102
+ /**
103
+ * Convert inline candle data to a Candle struct (for update events).
104
+ */
105
+ function toCandle(data) {
106
+ if (data.t === undefined)
107
+ return undefined;
108
+ return {
109
+ t: data.t,
110
+ o: data.o,
111
+ h: data.h,
112
+ l: data.l,
113
+ c: data.c,
114
+ v: data.v,
115
+ m: data.m,
116
+ bb: data.bb,
117
+ ba: data.ba,
118
+ };
119
+ }
120
+ /**
121
+ * Parse market event type from string.
122
+ */
123
+ function parseMarketEventType(s) {
124
+ switch (s) {
125
+ case "orderbook_created":
126
+ return "OrderbookCreated";
127
+ case "settled":
128
+ return "Settled";
129
+ case "opened":
130
+ return "Opened";
131
+ case "paused":
132
+ return "Paused";
133
+ default:
134
+ return "Unknown";
135
+ }
136
+ }
137
+ /**
138
+ * Parse error code from string.
139
+ */
140
+ function parseErrorCode(s) {
141
+ switch (s) {
142
+ case "ENGINE_UNAVAILABLE":
143
+ return "EngineUnavailable";
144
+ case "INVALID_JSON":
145
+ return "InvalidJson";
146
+ case "INVALID_METHOD":
147
+ return "InvalidMethod";
148
+ case "RATE_LIMITED":
149
+ return "RateLimited";
150
+ default:
151
+ return "Unknown";
152
+ }
153
+ }
154
+ /**
155
+ * Parse message type from string.
156
+ */
157
+ function parseMessageType(s) {
158
+ switch (s) {
159
+ case "book_update":
160
+ return "BookUpdate";
161
+ case "trades":
162
+ return "Trades";
163
+ case "user":
164
+ return "User";
165
+ case "price_history":
166
+ return "PriceHistory";
167
+ case "market":
168
+ return "Market";
169
+ case "error":
170
+ return "Error";
171
+ case "pong":
172
+ return "Pong";
173
+ default:
174
+ return "Unknown";
175
+ }
176
+ }
177
+ /**
178
+ * Parse side from number.
179
+ */
180
+ function parseSide(value) {
181
+ return value === 0 ? "Buy" : "Sell";
182
+ }
183
+ /**
184
+ * Convert side to number.
185
+ */
186
+ function sideToNumber(side) {
187
+ return side === "Buy" ? 0 : 1;
188
+ }
189
+ /**
190
+ * Parse price level side from string.
191
+ */
192
+ function parsePriceLevelSide(s) {
193
+ return s === "bid" ? "Bid" : "Ask";
194
+ }
195
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/websocket/types.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAuEH,wDAEC;AAKD,4DAEC;AAKD,8CAEC;AAKD,4CAEC;AAKD,oCAEC;AAKD,gCAEC;AAKD,gDAWC;AAKD,oCAEC;AAiCD,wCAsBC;AAmLD,4BAaC;AAsDD,oDAaC;AA4BD,wCAaC;AAmDD,4CAmBC;AAcD,8BAEC;AAKD,oCAEC;AAUD,kDAEC;AA3gBD;;GAEG;AACH,SAAgB,sBAAsB,CAAC,MAAuB;IAC5D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CAAC,MAAuB;IAC9D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,YAAsB;I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AAgB,CAAC,CAAS;IACxC,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,aAAa;YAChB,OAAO,YAAY,CAAC;QACtB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,eAAe;YAClB,OAAO,cAAc,CAAC;QACxB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAWD;;GAEG;AACH,SAAgB,SAAS,CAAC,KAAa;IACrC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,IAAU;IACrC,OAAO,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC;AAOD;;GAEG;AACH,SAAgB,mBAAmB,CAAC,CAAS;IAC3C,OAAO,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AACrC,CAAC","sourcesContent":["/**\n * Message types for the Lightcone WebSocket protocol.\n *\n * This module contains all request and response types for the WebSocket API.\n */\n\nimport type { WebSocketError } from \"./error\";\n\n// ============================================================================\n// REQUEST TYPES (Client → Server)\n// ============================================================================\n\n/**\n * Subscribe/Unsubscribe request wrapper.\n */\nexport interface WsRequest {\n method: string;\n params?: SubscribeParams;\n}\n\n/**\n * Subscription parameters (polymorphic).\n */\nexport type SubscribeParams =\n | BookUpdateParams\n | TradesParams\n | UserParams\n | PriceHistoryParams\n | MarketParams;\n\n/**\n * Book update subscription params.\n */\nexport interface BookUpdateParams {\n type: \"book_update\";\n orderbook_ids: string[];\n}\n\n/**\n * Trades subscription params.\n */\nexport interface TradesParams {\n type: \"trades\";\n orderbook_ids: string[];\n}\n\n/**\n * User subscription params.\n */\nexport interface UserParams {\n type: \"user\";\n user: string;\n}\n\n/**\n * Price history subscription params.\n */\nexport interface PriceHistoryParams {\n type: \"price_history\";\n orderbook_id: string;\n resolution: string;\n include_ohlcv: boolean;\n}\n\n/**\n * Market subscription params.\n */\nexport interface MarketParams {\n type: \"market\";\n market_pubkey: string;\n}\n\n/**\n * Create a subscribe request.\n */\nexport function createSubscribeRequest(params: SubscribeParams): WsRequest {\n return { method: \"subscribe\", params };\n}\n\n/**\n * Create an unsubscribe request.\n */\nexport function createUnsubscribeRequest(params: SubscribeParams): WsRequest {\n return { method: \"unsubscribe\", params };\n}\n\n/**\n * Create a ping request.\n */\nexport function createPingRequest(): WsRequest {\n return { method: \"ping\" };\n}\n\n/**\n * Create book update subscription params.\n */\nexport function bookUpdateParams(orderbookIds: string[]): BookUpdateParams {\n return { type: \"book_update\", orderbook_ids: orderbookIds };\n}\n\n/**\n * Create trades subscription params.\n */\nexport function tradesParams(orderbookIds: string[]): TradesParams {\n return { type: \"trades\", orderbook_ids: orderbookIds };\n}\n\n/**\n * Create user subscription params.\n */\nexport function userParams(user: string): UserParams {\n return { type: \"user\", user };\n}\n\n/**\n * Create price history subscription params.\n */\nexport function priceHistoryParams(\n orderbookId: string,\n resolution: string,\n includeOhlcv: boolean\n): PriceHistoryParams {\n return {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: includeOhlcv,\n };\n}\n\n/**\n * Create market subscription params.\n */\nexport function marketParams(marketPubkey: string): MarketParams {\n return { type: \"market\", market_pubkey: marketPubkey };\n}\n\n// ============================================================================\n// RESPONSE TYPES (Server → Client)\n// ============================================================================\n\n/**\n * Auth response data.\n */\nexport interface AuthData {\n status: \"authenticated\" | \"anonymous\" | \"error\";\n user_pubkey?: string;\n message?: string;\n}\n\n/**\n * Server → Client message (discriminated union).\n * TypeScript automatically narrows the `data` type based on `type` field.\n */\nexport type WsServerMessage =\n | { type: \"book_update\"; version: number; data: BookUpdateData }\n | { type: \"trades\"; version: number; data: TradeData }\n | { type: \"user\"; version: number; data: UserEventData }\n | { type: \"price_history\"; version: number; data: PriceHistoryData }\n | { type: \"market\"; version: number; data: MarketEventData }\n | { type: \"auth\"; version: number; data: AuthData }\n | { type: \"pong\"; version: number; data: PongData }\n | { type: \"error\"; version: number; data: ErrorData };\n\n/**\n * Parse a WebSocket message from raw text.\n * Single validation point at JSON.parse boundary.\n */\nexport function parseWsMessage(text: string): WsServerMessage | null {\n let raw: unknown;\n try {\n raw = JSON.parse(text);\n } catch {\n return null;\n }\n\n if (typeof raw !== \"object\" || raw === null) return null;\n const obj = raw as Record<string, unknown>;\n\n if (typeof obj.type !== \"string\" || typeof obj.version !== \"number\") {\n return null;\n }\n\n // All message types except \"pong\" must have a data field\n if (obj.type !== \"pong\" && (obj.data === undefined || obj.data === null)) {\n return null;\n }\n\n // We trust the server sends correct data shapes for each type\n return obj as WsServerMessage;\n}\n\n/**\n * Generic WebSocket message wrapper.\n */\nexport interface WsMessage<T> {\n type: string;\n version: number;\n data: T;\n}\n\n// ============================================================================\n// BOOK UPDATE TYPES\n// ============================================================================\n\n/**\n * Orderbook snapshot/delta data.\n */\nexport interface BookUpdateData {\n orderbook_id: string;\n timestamp: string;\n seq: number;\n bids: PriceLevel[];\n asks: PriceLevel[];\n is_snapshot: boolean;\n resync: boolean;\n message?: string;\n}\n\n/**\n * Price level in the orderbook.\n */\nexport interface PriceLevel {\n side: string;\n /** Price as decimal string (e.g., \"0.500000\") */\n price: string;\n /** Size as decimal string */\n size: string;\n}\n\n// ============================================================================\n// TRADE TYPES\n// ============================================================================\n\n/**\n * Trade execution data.\n */\nexport interface TradeData {\n orderbook_id: string;\n /** Price as decimal string */\n price: string;\n /** Size as decimal string */\n size: string;\n side: string;\n timestamp: string;\n trade_id: string;\n}\n\n// ============================================================================\n// USER EVENT TYPES\n// ============================================================================\n\n/**\n * User event data (snapshot, order_update, balance_update).\n */\nexport interface UserEventData {\n event_type: string;\n orders: Order[];\n balances: Record<string, BalanceEntry>;\n order?: OrderUpdate;\n balance?: Balance;\n market_pubkey?: string;\n orderbook_id?: string;\n deposit_mint?: string;\n timestamp?: string;\n}\n\n/**\n * User order from snapshot.\n */\nexport interface Order {\n order_hash: string;\n market_pubkey: string;\n orderbook_id: string;\n /** 0 = BUY, 1 = SELL */\n side: number;\n /** Maker amount as decimal string */\n maker_amount: string;\n /** Taker amount as decimal string */\n taker_amount: string;\n /** Remaining amount as decimal string */\n remaining: string;\n /** Filled amount as decimal string */\n filled: string;\n /** Price as decimal string */\n price: string;\n created_at: number;\n expiration: number;\n}\n\n/**\n * Order update from real-time event.\n */\nexport interface OrderUpdate {\n order_hash: string;\n /** Price as decimal string */\n price: string;\n /** Fill amount as decimal string */\n fill_amount: string;\n /** Remaining amount as decimal string */\n remaining: string;\n /** Filled amount as decimal string */\n filled: string;\n /** 0 = BUY, 1 = SELL */\n side: number;\n is_maker: boolean;\n created_at: number;\n balance?: Balance;\n}\n\n/**\n * Balance containing outcome balances.\n */\nexport interface Balance {\n outcomes: OutcomeBalance[];\n}\n\n/**\n * Individual outcome balance.\n */\nexport interface OutcomeBalance {\n outcome_index: number;\n mint: string;\n /** Idle balance as decimal string */\n idle: string;\n /** On-book balance as decimal string */\n on_book: string;\n}\n\n/**\n * Balance entry from user snapshot.\n */\nexport interface BalanceEntry {\n market_pubkey: string;\n deposit_mint: string;\n outcomes: OutcomeBalance[];\n}\n\n// ============================================================================\n// PRICE HISTORY TYPES\n// ============================================================================\n\n/**\n * Price history data (snapshot, update, heartbeat).\n */\nexport interface PriceHistoryData {\n event_type: string;\n orderbook_id?: string;\n resolution?: string;\n include_ohlcv?: boolean;\n prices: Candle[];\n last_timestamp?: number;\n server_time?: number;\n last_processed?: number;\n // For updates (inline candle data)\n t?: number;\n o?: string;\n h?: string;\n l?: string;\n c?: string;\n v?: string;\n m?: string;\n bb?: string;\n ba?: string;\n}\n\n/**\n * Convert inline candle data to a Candle struct (for update events).\n */\nexport function toCandle(data: PriceHistoryData): Candle | undefined {\n if (data.t === undefined) return undefined;\n return {\n t: data.t,\n o: data.o,\n h: data.h,\n l: data.l,\n c: data.c,\n v: data.v,\n m: data.m,\n bb: data.bb,\n ba: data.ba,\n };\n}\n\n/**\n * OHLCV candle data.\n */\nexport interface Candle {\n /** Timestamp (Unix ms) */\n t: number;\n /** Open price as decimal string (null if no trades) */\n o?: string;\n /** High price as decimal string (null if no trades) */\n h?: string;\n /** Low price as decimal string (null if no trades) */\n l?: string;\n /** Close price as decimal string (null if no trades) */\n c?: string;\n /** Volume as decimal string (null if no trades) */\n v?: string;\n /** Midpoint: (best_bid + best_ask) / 2 as decimal string */\n m?: string;\n /** Best bid price as decimal string */\n bb?: string;\n /** Best ask price as decimal string */\n ba?: string;\n}\n\n// ============================================================================\n// MARKET EVENT TYPES\n// ============================================================================\n\n/**\n * Market event data.\n */\nexport interface MarketEventData {\n /** Event type: \"orderbook_created\", \"settled\", \"opened\", \"paused\" */\n event_type: string;\n market_pubkey: string;\n orderbook_id?: string;\n timestamp: string;\n}\n\n/**\n * Market event types.\n */\nexport type MarketEventType =\n | \"OrderbookCreated\"\n | \"Settled\"\n | \"Opened\"\n | \"Paused\"\n | \"Unknown\";\n\n/**\n * Parse market event type from string.\n */\nexport function parseMarketEventType(s: string): MarketEventType {\n switch (s) {\n case \"orderbook_created\":\n return \"OrderbookCreated\";\n case \"settled\":\n return \"Settled\";\n case \"opened\":\n return \"Opened\";\n case \"paused\":\n return \"Paused\";\n default:\n return \"Unknown\";\n }\n}\n\n// ============================================================================\n// ERROR TYPES\n// ============================================================================\n\n/**\n * Error response from server.\n */\nexport interface ErrorData {\n error: string;\n code: string;\n orderbook_id?: string;\n}\n\n/**\n * Server error codes.\n */\nexport type ErrorCode =\n | \"EngineUnavailable\"\n | \"InvalidJson\"\n | \"InvalidMethod\"\n | \"RateLimited\"\n | \"Unknown\";\n\n/**\n * Parse error code from string.\n */\nexport function parseErrorCode(s: string): ErrorCode {\n switch (s) {\n case \"ENGINE_UNAVAILABLE\":\n return \"EngineUnavailable\";\n case \"INVALID_JSON\":\n return \"InvalidJson\";\n case \"INVALID_METHOD\":\n return \"InvalidMethod\";\n case \"RATE_LIMITED\":\n return \"RateLimited\";\n default:\n return \"Unknown\";\n }\n}\n\n// ============================================================================\n// PONG TYPE\n// ============================================================================\n\n/**\n * Pong response data (empty).\n */\nexport interface PongData {}\n\n// ============================================================================\n// CLIENT EVENTS\n// ============================================================================\n\n/**\n * Events emitted by the WebSocket client.\n */\nexport type WsEvent =\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; reason: string }\n | { type: \"BookUpdate\"; orderbookId: string; isSnapshot: boolean }\n | { type: \"Trade\"; orderbookId: string; trade: TradeData }\n | { type: \"UserUpdate\"; eventType: string; user: string }\n | { type: \"PriceUpdate\"; orderbookId: string; resolution: string }\n | { type: \"MarketEvent\"; eventType: string; marketPubkey: string }\n | { type: \"Error\"; error: WebSocketError }\n | { type: \"ResyncRequired\"; orderbookId: string }\n | { type: \"Pong\" }\n | { type: \"Reconnecting\"; attempt: number };\n\n// ============================================================================\n// MESSAGE TYPE ENUM\n// ============================================================================\n\n/**\n * Enum for all possible server message types.\n */\nexport type MessageType =\n | \"BookUpdate\"\n | \"Trades\"\n | \"User\"\n | \"PriceHistory\"\n | \"Market\"\n | \"Error\"\n | \"Pong\"\n | \"Unknown\";\n\n/**\n * Parse message type from string.\n */\nexport function parseMessageType(s: string): MessageType {\n switch (s) {\n case \"book_update\":\n return \"BookUpdate\";\n case \"trades\":\n return \"Trades\";\n case \"user\":\n return \"User\";\n case \"price_history\":\n return \"PriceHistory\";\n case \"market\":\n return \"Market\";\n case \"error\":\n return \"Error\";\n case \"pong\":\n return \"Pong\";\n default:\n return \"Unknown\";\n }\n}\n\n// ============================================================================\n// SIDE HELPERS\n// ============================================================================\n\n/**\n * Order side enum for user events.\n */\nexport type Side = \"Buy\" | \"Sell\";\n\n/**\n * Parse side from number.\n */\nexport function parseSide(value: number): Side {\n return value === 0 ? \"Buy\" : \"Sell\";\n}\n\n/**\n * Convert side to number.\n */\nexport function sideToNumber(side: Side): number {\n return side === \"Buy\" ? 0 : 1;\n}\n\n/**\n * Price level side (from orderbook updates).\n */\nexport type PriceLevelSide = \"Bid\" | \"Ask\";\n\n/**\n * Parse price level side from string.\n */\nexport function parsePriceLevelSide(s: string): PriceLevelSide {\n return s === \"bid\" ? \"Bid\" : \"Ask\";\n}\n"]}