@limitless-exchange/sdk 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +368 -0
- package/dist/index.d.mts +3015 -0
- package/dist/index.d.ts +3015 -0
- package/dist/index.js +2555 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2485 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +61 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3015 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Client type for authentication.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
type ClientType = 'eoa' | 'base' | 'etherspot';
|
|
9
|
+
/**
|
|
10
|
+
* Trading mode for user interface.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
type TradingMode = 'SIMPLE' | 'ADVANCED';
|
|
14
|
+
/**
|
|
15
|
+
* Authentication headers required for login.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
interface SignatureHeaders {
|
|
19
|
+
/**
|
|
20
|
+
* The Ethereum address of the user
|
|
21
|
+
*/
|
|
22
|
+
'x-account': string;
|
|
23
|
+
/**
|
|
24
|
+
* The signing message in hex format
|
|
25
|
+
*/
|
|
26
|
+
'x-signing-message': string;
|
|
27
|
+
/**
|
|
28
|
+
* The signature generated by signing the message with the user's wallet
|
|
29
|
+
*/
|
|
30
|
+
'x-signature': string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* User profile information returned after authentication.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
interface UserProfile {
|
|
37
|
+
/**
|
|
38
|
+
* User's Ethereum address (EOA)
|
|
39
|
+
*/
|
|
40
|
+
account: string;
|
|
41
|
+
/**
|
|
42
|
+
* Display name for the user
|
|
43
|
+
*/
|
|
44
|
+
displayName: string;
|
|
45
|
+
/**
|
|
46
|
+
* Smart wallet address (optional, required for ETHERSPOT client)
|
|
47
|
+
*/
|
|
48
|
+
smartWallet?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Client type used for authentication
|
|
51
|
+
*/
|
|
52
|
+
client: ClientType;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Mode information from authentication response.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
interface ModeInfo {
|
|
59
|
+
/**
|
|
60
|
+
* Trading interface mode
|
|
61
|
+
*/
|
|
62
|
+
mode: TradingMode;
|
|
63
|
+
/**
|
|
64
|
+
* Whether the user is new to the platform
|
|
65
|
+
*/
|
|
66
|
+
isUserNew: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* User data for order operations.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* Contains user-specific information needed for creating orders.
|
|
73
|
+
* Typically extracted from authentication result.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
interface UserData {
|
|
78
|
+
/**
|
|
79
|
+
* User ID (owner ID) from the API
|
|
80
|
+
*/
|
|
81
|
+
userId: number;
|
|
82
|
+
/**
|
|
83
|
+
* Fee rate in basis points for this user
|
|
84
|
+
* Common values: 100 (1%), 200 (2%), 300 (3%)
|
|
85
|
+
*/
|
|
86
|
+
feeRateBps: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Complete authentication result including session and profile.
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
interface AuthResult {
|
|
93
|
+
/**
|
|
94
|
+
* Session cookie value (JWT token)
|
|
95
|
+
*/
|
|
96
|
+
sessionCookie: string;
|
|
97
|
+
/**
|
|
98
|
+
* User profile information
|
|
99
|
+
*/
|
|
100
|
+
profile: UserProfile;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Options for login authentication.
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
interface LoginOptions {
|
|
107
|
+
/**
|
|
108
|
+
* Client type to use for authentication
|
|
109
|
+
* @defaultValue 'eoa'
|
|
110
|
+
*/
|
|
111
|
+
client?: ClientType;
|
|
112
|
+
/**
|
|
113
|
+
* Smart wallet address (required when client is 'etherspot')
|
|
114
|
+
*/
|
|
115
|
+
smartWallet?: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Logger interface for SDK integration.
|
|
120
|
+
* Allows users to inject their own logging implementation.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
interface ILogger {
|
|
125
|
+
/**
|
|
126
|
+
* Log debug information (verbose, development only)
|
|
127
|
+
*/
|
|
128
|
+
debug(message: string, meta?: Record<string, any>): void;
|
|
129
|
+
/**
|
|
130
|
+
* Log informational messages
|
|
131
|
+
*/
|
|
132
|
+
info(message: string, meta?: Record<string, any>): void;
|
|
133
|
+
/**
|
|
134
|
+
* Log warning messages
|
|
135
|
+
*/
|
|
136
|
+
warn(message: string, meta?: Record<string, any>): void;
|
|
137
|
+
/**
|
|
138
|
+
* Log error messages
|
|
139
|
+
*/
|
|
140
|
+
error(message: string, error?: Error, meta?: Record<string, any>): void;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* No-op logger (default) - does nothing.
|
|
144
|
+
* Zero performance overhead when logging is not needed.
|
|
145
|
+
*
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
declare class NoOpLogger implements ILogger {
|
|
149
|
+
debug(): void;
|
|
150
|
+
info(): void;
|
|
151
|
+
warn(): void;
|
|
152
|
+
error(): void;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Simple console logger for development.
|
|
156
|
+
* Can be used as a starting point or for debugging.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* import { ConsoleLogger } from '@limitless-exchange/sdk';
|
|
161
|
+
*
|
|
162
|
+
* const logger = new ConsoleLogger('debug');
|
|
163
|
+
* const authenticator = new Authenticator(httpClient, signer, logger);
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @public
|
|
167
|
+
*/
|
|
168
|
+
declare class ConsoleLogger implements ILogger {
|
|
169
|
+
private level;
|
|
170
|
+
constructor(level?: 'debug' | 'info' | 'warn' | 'error');
|
|
171
|
+
private shouldLog;
|
|
172
|
+
debug(message: string, meta?: Record<string, any>): void;
|
|
173
|
+
info(message: string, meta?: Record<string, any>): void;
|
|
174
|
+
warn(message: string, meta?: Record<string, any>): void;
|
|
175
|
+
error(message: string, error?: Error, meta?: Record<string, any>): void;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Order-related types for Limitless Exchange.
|
|
180
|
+
* @module types/orders
|
|
181
|
+
*/
|
|
182
|
+
/**
|
|
183
|
+
* Order side enum.
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
declare enum Side {
|
|
187
|
+
BUY = 0,
|
|
188
|
+
SELL = 1
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Order type enum.
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
declare enum OrderType {
|
|
195
|
+
/** Fill-or-Kill: Execute immediately or cancel */
|
|
196
|
+
FOK = "FOK",
|
|
197
|
+
/** Good-Til-Cancelled: Remain on orderbook until filled or cancelled */
|
|
198
|
+
GTC = "GTC"
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Market type enum.
|
|
202
|
+
* @public
|
|
203
|
+
*/
|
|
204
|
+
declare enum MarketType {
|
|
205
|
+
CLOB = "CLOB",
|
|
206
|
+
NEGRISK = "NEGRISK"
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Signature type enum.
|
|
210
|
+
* @public
|
|
211
|
+
*/
|
|
212
|
+
declare enum SignatureType {
|
|
213
|
+
/** Externally Owned Account */
|
|
214
|
+
EOA = 0,
|
|
215
|
+
/** Polymarket Proxy */
|
|
216
|
+
POLY_PROXY = 1,
|
|
217
|
+
/** Polymarket Gnosis Safe */
|
|
218
|
+
POLY_GNOSIS_SAFE = 2
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Base arguments shared by all order types.
|
|
222
|
+
* @public
|
|
223
|
+
*/
|
|
224
|
+
interface BaseOrderArgs {
|
|
225
|
+
/**
|
|
226
|
+
* Token ID for the outcome
|
|
227
|
+
*/
|
|
228
|
+
tokenId: string;
|
|
229
|
+
/**
|
|
230
|
+
* Order side (BUY or SELL)
|
|
231
|
+
*/
|
|
232
|
+
side: Side;
|
|
233
|
+
/**
|
|
234
|
+
* Market type (CLOB or NEGRISK)
|
|
235
|
+
* @defaultValue 'CLOB'
|
|
236
|
+
*/
|
|
237
|
+
marketType?: MarketType;
|
|
238
|
+
/**
|
|
239
|
+
* Expiration timestamp (0 for no expiration)
|
|
240
|
+
* @defaultValue '0'
|
|
241
|
+
*/
|
|
242
|
+
expiration?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Nonce for order replay protection
|
|
245
|
+
* @defaultValue 0
|
|
246
|
+
*/
|
|
247
|
+
nonce?: number;
|
|
248
|
+
/**
|
|
249
|
+
* Taker address (ZERO_ADDRESS for any taker)
|
|
250
|
+
* @defaultValue '0x0000000000000000000000000000000000000000'
|
|
251
|
+
*/
|
|
252
|
+
taker?: string;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Arguments for FOK (Fill-or-Kill) market orders.
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* FOK orders are market orders that execute immediately at the best available price.
|
|
259
|
+
* Specify the maker amount (human-readable, max 6 decimals).
|
|
260
|
+
*
|
|
261
|
+
* For BUY orders: Amount in USDC to spend (e.g., 50.0 = spend $50 USDC)
|
|
262
|
+
* For SELL orders: Number of shares to sell (e.g., 18.64 = sell 18.64 shares)
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* // BUY: Spend 50 USDC
|
|
267
|
+
* {
|
|
268
|
+
* tokenId: '123...',
|
|
269
|
+
* makerAmount: 50, // Spend $50 USDC
|
|
270
|
+
* side: Side.BUY
|
|
271
|
+
* }
|
|
272
|
+
*
|
|
273
|
+
* // SELL: Sell 18.64 shares
|
|
274
|
+
* {
|
|
275
|
+
* tokenId: '123...',
|
|
276
|
+
* makerAmount: 18.64, // Sell 18.64 shares
|
|
277
|
+
* side: Side.SELL
|
|
278
|
+
* }
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
interface FOKOrderArgs extends BaseOrderArgs {
|
|
284
|
+
/**
|
|
285
|
+
* Maker amount (human-readable, max 6 decimals)
|
|
286
|
+
*
|
|
287
|
+
* For BUY orders: Amount of USDC to spend
|
|
288
|
+
* For SELL orders: Number of shares to sell
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* // BUY examples
|
|
292
|
+
* 50 = Spend $50 USDC
|
|
293
|
+
* 1.5 = Spend $1.50 USDC
|
|
294
|
+
* 0.75 = Spend $0.75 USDC
|
|
295
|
+
*
|
|
296
|
+
* // SELL examples
|
|
297
|
+
* 18.64 = Sell 18.64 shares
|
|
298
|
+
* 44.111 = Sell 44.111 shares
|
|
299
|
+
*/
|
|
300
|
+
makerAmount: number;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Arguments for GTC (Good-Til-Cancelled) limit orders.
|
|
304
|
+
*
|
|
305
|
+
* @remarks
|
|
306
|
+
* GTC orders are limit orders that remain on the orderbook until filled or cancelled.
|
|
307
|
+
* You specify the price and number of shares.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* // BUY: Buy 10 shares at 0.65 price
|
|
312
|
+
* {
|
|
313
|
+
* tokenId: '123...',
|
|
314
|
+
* price: 0.65,
|
|
315
|
+
* size: 10,
|
|
316
|
+
* side: Side.BUY
|
|
317
|
+
* }
|
|
318
|
+
*
|
|
319
|
+
* // SELL: Sell 5 shares at 0.75 price
|
|
320
|
+
* {
|
|
321
|
+
* tokenId: '123...',
|
|
322
|
+
* price: 0.75,
|
|
323
|
+
* size: 5,
|
|
324
|
+
* side: Side.SELL
|
|
325
|
+
* }
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* @public
|
|
329
|
+
*/
|
|
330
|
+
interface GTCOrderArgs extends BaseOrderArgs {
|
|
331
|
+
/**
|
|
332
|
+
* Price per share (0.0 to 1.0)
|
|
333
|
+
*/
|
|
334
|
+
price: number;
|
|
335
|
+
/**
|
|
336
|
+
* Number of shares to trade
|
|
337
|
+
*/
|
|
338
|
+
size: number;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Union type for all order arguments.
|
|
342
|
+
* @public
|
|
343
|
+
*/
|
|
344
|
+
type OrderArgs = FOKOrderArgs | GTCOrderArgs;
|
|
345
|
+
/**
|
|
346
|
+
* Unsigned order payload.
|
|
347
|
+
* @public
|
|
348
|
+
*/
|
|
349
|
+
interface UnsignedOrder {
|
|
350
|
+
/**
|
|
351
|
+
* Unique salt for order identification
|
|
352
|
+
*/
|
|
353
|
+
salt: number;
|
|
354
|
+
/**
|
|
355
|
+
* Maker address (order creator)
|
|
356
|
+
*/
|
|
357
|
+
maker: string;
|
|
358
|
+
/**
|
|
359
|
+
* Signer address (must match maker for EOA)
|
|
360
|
+
*/
|
|
361
|
+
signer: string;
|
|
362
|
+
/**
|
|
363
|
+
* Taker address (ZERO_ADDRESS for any taker)
|
|
364
|
+
*/
|
|
365
|
+
taker: string;
|
|
366
|
+
/**
|
|
367
|
+
* Token ID for the outcome
|
|
368
|
+
*/
|
|
369
|
+
tokenId: string;
|
|
370
|
+
/**
|
|
371
|
+
* Maker amount in USDC units (6 decimals)
|
|
372
|
+
*/
|
|
373
|
+
makerAmount: number;
|
|
374
|
+
/**
|
|
375
|
+
* Taker amount in USDC units (6 decimals)
|
|
376
|
+
*/
|
|
377
|
+
takerAmount: number;
|
|
378
|
+
/**
|
|
379
|
+
* Expiration timestamp (0 for no expiration)
|
|
380
|
+
*/
|
|
381
|
+
expiration: string;
|
|
382
|
+
/**
|
|
383
|
+
* Nonce for replay protection
|
|
384
|
+
*/
|
|
385
|
+
nonce: number;
|
|
386
|
+
/**
|
|
387
|
+
* Fee rate in basis points
|
|
388
|
+
*/
|
|
389
|
+
feeRateBps: number;
|
|
390
|
+
/**
|
|
391
|
+
* Order side (BUY or SELL)
|
|
392
|
+
*/
|
|
393
|
+
side: Side;
|
|
394
|
+
/**
|
|
395
|
+
* Signature type (EOA, POLY_PROXY, etc.)
|
|
396
|
+
*/
|
|
397
|
+
signatureType: SignatureType;
|
|
398
|
+
/**
|
|
399
|
+
* Price per share (required for GTC orders)
|
|
400
|
+
*/
|
|
401
|
+
price?: number;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Signed order payload.
|
|
405
|
+
* @public
|
|
406
|
+
*/
|
|
407
|
+
interface SignedOrder extends UnsignedOrder {
|
|
408
|
+
/**
|
|
409
|
+
* EIP-712 signature
|
|
410
|
+
*/
|
|
411
|
+
signature: string;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Complete order payload for API submission.
|
|
415
|
+
* @public
|
|
416
|
+
*/
|
|
417
|
+
interface NewOrderPayload {
|
|
418
|
+
/**
|
|
419
|
+
* Signed order details
|
|
420
|
+
*/
|
|
421
|
+
order: SignedOrder;
|
|
422
|
+
/**
|
|
423
|
+
* Order type (FOK or GTC)
|
|
424
|
+
*/
|
|
425
|
+
orderType: OrderType;
|
|
426
|
+
/**
|
|
427
|
+
* Market slug identifier
|
|
428
|
+
*/
|
|
429
|
+
marketSlug: string;
|
|
430
|
+
/**
|
|
431
|
+
* Owner ID from user profile
|
|
432
|
+
*/
|
|
433
|
+
ownerId: number;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Clean order data returned from API.
|
|
437
|
+
*
|
|
438
|
+
* @remarks
|
|
439
|
+
* This is a minimal, user-friendly representation of an order
|
|
440
|
+
* that excludes unnecessary API metadata.
|
|
441
|
+
*
|
|
442
|
+
* @public
|
|
443
|
+
*/
|
|
444
|
+
interface CreatedOrder {
|
|
445
|
+
/**
|
|
446
|
+
* Order database ID
|
|
447
|
+
*/
|
|
448
|
+
id: string;
|
|
449
|
+
/**
|
|
450
|
+
* Creation timestamp (ISO 8601)
|
|
451
|
+
*/
|
|
452
|
+
createdAt: string;
|
|
453
|
+
/**
|
|
454
|
+
* Maker amount (USDC units with 6 decimals)
|
|
455
|
+
*/
|
|
456
|
+
makerAmount: number;
|
|
457
|
+
/**
|
|
458
|
+
* Taker amount (USDC units with 6 decimals)
|
|
459
|
+
*/
|
|
460
|
+
takerAmount: number;
|
|
461
|
+
/**
|
|
462
|
+
* Expiration timestamp (null for no expiration)
|
|
463
|
+
*/
|
|
464
|
+
expiration: string | null;
|
|
465
|
+
/**
|
|
466
|
+
* Signature type (0 = EOA, 1 = Polymarket Proxy, 2 = Gnosis Safe)
|
|
467
|
+
*/
|
|
468
|
+
signatureType: number;
|
|
469
|
+
/**
|
|
470
|
+
* Unique salt for order identification
|
|
471
|
+
*/
|
|
472
|
+
salt: number;
|
|
473
|
+
/**
|
|
474
|
+
* Maker address
|
|
475
|
+
*/
|
|
476
|
+
maker: string;
|
|
477
|
+
/**
|
|
478
|
+
* Signer address
|
|
479
|
+
*/
|
|
480
|
+
signer: string;
|
|
481
|
+
/**
|
|
482
|
+
* Taker address (zero address for any taker)
|
|
483
|
+
*/
|
|
484
|
+
taker: string;
|
|
485
|
+
/**
|
|
486
|
+
* Token ID for the outcome
|
|
487
|
+
*/
|
|
488
|
+
tokenId: string;
|
|
489
|
+
/**
|
|
490
|
+
* Order side (0 = BUY, 1 = SELL)
|
|
491
|
+
*/
|
|
492
|
+
side: Side;
|
|
493
|
+
/**
|
|
494
|
+
* Fee rate in basis points
|
|
495
|
+
*/
|
|
496
|
+
feeRateBps: number;
|
|
497
|
+
/**
|
|
498
|
+
* Nonce for replay protection
|
|
499
|
+
*/
|
|
500
|
+
nonce: number;
|
|
501
|
+
/**
|
|
502
|
+
* EIP-712 signature
|
|
503
|
+
*/
|
|
504
|
+
signature: string;
|
|
505
|
+
/**
|
|
506
|
+
* Order type (GTC or FOK)
|
|
507
|
+
*/
|
|
508
|
+
orderType: string;
|
|
509
|
+
/**
|
|
510
|
+
* Price per share (0.0 to 1.0) - only for GTC orders
|
|
511
|
+
*/
|
|
512
|
+
price: number | null;
|
|
513
|
+
/**
|
|
514
|
+
* Market database ID
|
|
515
|
+
*/
|
|
516
|
+
marketId: number;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Match information for filled orders.
|
|
520
|
+
*
|
|
521
|
+
* @remarks
|
|
522
|
+
* When a FOK order is filled or a GTC order is partially matched,
|
|
523
|
+
* this provides minimal information about the match.
|
|
524
|
+
*
|
|
525
|
+
* @public
|
|
526
|
+
*/
|
|
527
|
+
interface OrderMatch {
|
|
528
|
+
/**
|
|
529
|
+
* Match database ID
|
|
530
|
+
*/
|
|
531
|
+
id: string;
|
|
532
|
+
/**
|
|
533
|
+
* Creation timestamp (ISO 8601)
|
|
534
|
+
*/
|
|
535
|
+
createdAt: string;
|
|
536
|
+
/**
|
|
537
|
+
* Matched size (USDC units with 6 decimals)
|
|
538
|
+
*/
|
|
539
|
+
matchedSize: string;
|
|
540
|
+
/**
|
|
541
|
+
* Matched order ID
|
|
542
|
+
*/
|
|
543
|
+
orderId: string;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Clean order creation response.
|
|
547
|
+
*
|
|
548
|
+
* @remarks
|
|
549
|
+
* This is what users receive after successfully creating an order.
|
|
550
|
+
* For GTC orders, makerMatches will be undefined or empty.
|
|
551
|
+
* For FOK orders, makerMatches contains the fills.
|
|
552
|
+
*
|
|
553
|
+
* @public
|
|
554
|
+
*/
|
|
555
|
+
interface OrderResponse {
|
|
556
|
+
/**
|
|
557
|
+
* Created order data
|
|
558
|
+
*/
|
|
559
|
+
order: CreatedOrder;
|
|
560
|
+
/**
|
|
561
|
+
* Matches if order was filled (FOK) or partially matched (GTC)
|
|
562
|
+
*/
|
|
563
|
+
makerMatches?: OrderMatch[];
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Order signing configuration.
|
|
567
|
+
* @public
|
|
568
|
+
*/
|
|
569
|
+
interface OrderSigningConfig {
|
|
570
|
+
/**
|
|
571
|
+
* Blockchain chain ID
|
|
572
|
+
*/
|
|
573
|
+
chainId: number;
|
|
574
|
+
/**
|
|
575
|
+
* Contract address for verification
|
|
576
|
+
*/
|
|
577
|
+
contractAddress: string;
|
|
578
|
+
/**
|
|
579
|
+
* Market type (CLOB or NEGRISK)
|
|
580
|
+
*/
|
|
581
|
+
marketType: MarketType;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Market-related types for Limitless Exchange.
|
|
586
|
+
* @module types/markets
|
|
587
|
+
*/
|
|
588
|
+
/**
|
|
589
|
+
* Orderbook entry (bid or ask).
|
|
590
|
+
* @public
|
|
591
|
+
*/
|
|
592
|
+
interface OrderbookEntry {
|
|
593
|
+
/**
|
|
594
|
+
* Price per share
|
|
595
|
+
*/
|
|
596
|
+
price: number;
|
|
597
|
+
/**
|
|
598
|
+
* Size in shares (scaled by 1e6)
|
|
599
|
+
*/
|
|
600
|
+
size: number;
|
|
601
|
+
/**
|
|
602
|
+
* Order side (BUY or SELL)
|
|
603
|
+
*/
|
|
604
|
+
side: string;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Complete orderbook for a market.
|
|
608
|
+
* @public
|
|
609
|
+
*/
|
|
610
|
+
interface OrderBook {
|
|
611
|
+
/**
|
|
612
|
+
* Bid orders (buy orders)
|
|
613
|
+
*/
|
|
614
|
+
bids: OrderbookEntry[];
|
|
615
|
+
/**
|
|
616
|
+
* Ask orders (sell orders)
|
|
617
|
+
*/
|
|
618
|
+
asks: OrderbookEntry[];
|
|
619
|
+
/**
|
|
620
|
+
* Token ID for the orderbook (YES token)
|
|
621
|
+
*/
|
|
622
|
+
tokenId: string;
|
|
623
|
+
/**
|
|
624
|
+
* Minimum order size
|
|
625
|
+
*/
|
|
626
|
+
minSize: string;
|
|
627
|
+
/**
|
|
628
|
+
* Last trade price
|
|
629
|
+
*/
|
|
630
|
+
lastTradePrice?: number;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Market price information.
|
|
634
|
+
* @public
|
|
635
|
+
*/
|
|
636
|
+
interface MarketPrice {
|
|
637
|
+
/**
|
|
638
|
+
* Token ID
|
|
639
|
+
*/
|
|
640
|
+
tokenId: string;
|
|
641
|
+
/**
|
|
642
|
+
* Current price
|
|
643
|
+
*/
|
|
644
|
+
price: number;
|
|
645
|
+
/**
|
|
646
|
+
* Last update timestamp
|
|
647
|
+
*/
|
|
648
|
+
updatedAt?: string;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Market outcome information.
|
|
652
|
+
* @public
|
|
653
|
+
*/
|
|
654
|
+
interface MarketOutcome {
|
|
655
|
+
/**
|
|
656
|
+
* Outcome ID
|
|
657
|
+
*/
|
|
658
|
+
id: number;
|
|
659
|
+
/**
|
|
660
|
+
* Outcome title
|
|
661
|
+
*/
|
|
662
|
+
title: string;
|
|
663
|
+
/**
|
|
664
|
+
* Token ID for this outcome
|
|
665
|
+
*/
|
|
666
|
+
tokenId: string;
|
|
667
|
+
/**
|
|
668
|
+
* Current price
|
|
669
|
+
*/
|
|
670
|
+
price?: number;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Complete market information.
|
|
674
|
+
* @public
|
|
675
|
+
*/
|
|
676
|
+
interface Market {
|
|
677
|
+
/**
|
|
678
|
+
* Market database ID
|
|
679
|
+
*/
|
|
680
|
+
id: number;
|
|
681
|
+
/**
|
|
682
|
+
* Market contract address
|
|
683
|
+
*/
|
|
684
|
+
address: string | null;
|
|
685
|
+
/**
|
|
686
|
+
* Market title
|
|
687
|
+
*/
|
|
688
|
+
title: string;
|
|
689
|
+
/**
|
|
690
|
+
* Market proxy title
|
|
691
|
+
*/
|
|
692
|
+
proxyTitle: string | null;
|
|
693
|
+
/**
|
|
694
|
+
* Market description
|
|
695
|
+
*/
|
|
696
|
+
description: string;
|
|
697
|
+
/**
|
|
698
|
+
* Market slug identifier
|
|
699
|
+
*/
|
|
700
|
+
slug: string;
|
|
701
|
+
/**
|
|
702
|
+
* Market type (CLOB or AMM)
|
|
703
|
+
*/
|
|
704
|
+
type?: string;
|
|
705
|
+
/**
|
|
706
|
+
* Market outcomes
|
|
707
|
+
*/
|
|
708
|
+
outcomes?: MarketOutcome[];
|
|
709
|
+
/**
|
|
710
|
+
* Creation timestamp
|
|
711
|
+
*/
|
|
712
|
+
createdAt: string;
|
|
713
|
+
/**
|
|
714
|
+
* Last update timestamp
|
|
715
|
+
*/
|
|
716
|
+
updatedAt: string;
|
|
717
|
+
/**
|
|
718
|
+
* Market status
|
|
719
|
+
*/
|
|
720
|
+
status?: string;
|
|
721
|
+
/**
|
|
722
|
+
* Resolution timestamp
|
|
723
|
+
*/
|
|
724
|
+
resolutionDate?: string;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Markets list response.
|
|
728
|
+
* @public
|
|
729
|
+
*/
|
|
730
|
+
interface MarketsResponse {
|
|
731
|
+
/**
|
|
732
|
+
* Array of markets
|
|
733
|
+
*/
|
|
734
|
+
markets: Market[];
|
|
735
|
+
/**
|
|
736
|
+
* Total count
|
|
737
|
+
*/
|
|
738
|
+
total?: number;
|
|
739
|
+
/**
|
|
740
|
+
* Pagination offset
|
|
741
|
+
*/
|
|
742
|
+
offset?: number;
|
|
743
|
+
/**
|
|
744
|
+
* Pagination limit
|
|
745
|
+
*/
|
|
746
|
+
limit?: number;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Sort options for active markets.
|
|
750
|
+
* @public
|
|
751
|
+
*/
|
|
752
|
+
type ActiveMarketsSortBy = 'lp_rewards' | 'ending_soon' | 'newest' | 'high_value';
|
|
753
|
+
/**
|
|
754
|
+
* Query parameters for active markets endpoint.
|
|
755
|
+
* @public
|
|
756
|
+
*/
|
|
757
|
+
interface ActiveMarketsParams {
|
|
758
|
+
/**
|
|
759
|
+
* Maximum number of markets to return (max 25)
|
|
760
|
+
* @defaultValue 25
|
|
761
|
+
*/
|
|
762
|
+
limit?: number;
|
|
763
|
+
/**
|
|
764
|
+
* Page number for pagination (starts at 1)
|
|
765
|
+
* @defaultValue 1
|
|
766
|
+
*/
|
|
767
|
+
page?: number;
|
|
768
|
+
/**
|
|
769
|
+
* Sort order for markets
|
|
770
|
+
*/
|
|
771
|
+
sortBy?: ActiveMarketsSortBy;
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Active markets response from API.
|
|
775
|
+
* @public
|
|
776
|
+
*/
|
|
777
|
+
interface ActiveMarketsResponse {
|
|
778
|
+
/**
|
|
779
|
+
* Array of active markets
|
|
780
|
+
*/
|
|
781
|
+
data: Market[];
|
|
782
|
+
/**
|
|
783
|
+
* Total count of active markets
|
|
784
|
+
*/
|
|
785
|
+
totalMarketsCount: number;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Portfolio and position types for Limitless Exchange.
|
|
790
|
+
* @module types/portfolio
|
|
791
|
+
*/
|
|
792
|
+
/**
|
|
793
|
+
* Market information for a position.
|
|
794
|
+
*
|
|
795
|
+
* @public
|
|
796
|
+
*/
|
|
797
|
+
interface PositionMarket {
|
|
798
|
+
/**
|
|
799
|
+
* Market ID
|
|
800
|
+
*/
|
|
801
|
+
id: number | string;
|
|
802
|
+
/**
|
|
803
|
+
* Market slug
|
|
804
|
+
*/
|
|
805
|
+
slug: string;
|
|
806
|
+
/**
|
|
807
|
+
* Market title
|
|
808
|
+
*/
|
|
809
|
+
title: string;
|
|
810
|
+
/**
|
|
811
|
+
* Market status
|
|
812
|
+
*/
|
|
813
|
+
status?: string;
|
|
814
|
+
/**
|
|
815
|
+
* Whether market is closed
|
|
816
|
+
*/
|
|
817
|
+
closed: boolean;
|
|
818
|
+
/**
|
|
819
|
+
* Market deadline
|
|
820
|
+
*/
|
|
821
|
+
deadline: string;
|
|
822
|
+
/**
|
|
823
|
+
* Condition ID
|
|
824
|
+
*/
|
|
825
|
+
conditionId?: string;
|
|
826
|
+
/**
|
|
827
|
+
* Winning outcome index (null if unresolved)
|
|
828
|
+
*/
|
|
829
|
+
winningOutcomeIndex?: number | null;
|
|
830
|
+
/**
|
|
831
|
+
* Market group information
|
|
832
|
+
*/
|
|
833
|
+
group?: {
|
|
834
|
+
slug?: string;
|
|
835
|
+
title?: string;
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Position details for YES or NO side.
|
|
840
|
+
*
|
|
841
|
+
* @public
|
|
842
|
+
*/
|
|
843
|
+
interface PositionSide {
|
|
844
|
+
/**
|
|
845
|
+
* Cost basis (6 decimals)
|
|
846
|
+
*/
|
|
847
|
+
cost: string;
|
|
848
|
+
/**
|
|
849
|
+
* Fill price (6 decimals for CLOB, decimal string for AMM)
|
|
850
|
+
*/
|
|
851
|
+
fillPrice: string;
|
|
852
|
+
/**
|
|
853
|
+
* Current market value (6 decimals)
|
|
854
|
+
*/
|
|
855
|
+
marketValue: string;
|
|
856
|
+
/**
|
|
857
|
+
* Realized P&L (6 decimals)
|
|
858
|
+
*/
|
|
859
|
+
realisedPnl: string;
|
|
860
|
+
/**
|
|
861
|
+
* Unrealized P&L (6 decimals)
|
|
862
|
+
*/
|
|
863
|
+
unrealizedPnl: string;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Token balance for YES or NO side.
|
|
867
|
+
*
|
|
868
|
+
* @public
|
|
869
|
+
*/
|
|
870
|
+
interface TokenBalance {
|
|
871
|
+
/**
|
|
872
|
+
* YES token balance (6 decimals)
|
|
873
|
+
*/
|
|
874
|
+
yes: string;
|
|
875
|
+
/**
|
|
876
|
+
* NO token balance (6 decimals)
|
|
877
|
+
*/
|
|
878
|
+
no: string;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Latest trade information.
|
|
882
|
+
*
|
|
883
|
+
* @public
|
|
884
|
+
*/
|
|
885
|
+
interface LatestTrade {
|
|
886
|
+
/**
|
|
887
|
+
* Latest YES price (0.0 to 1.0)
|
|
888
|
+
*/
|
|
889
|
+
latestYesPrice: number;
|
|
890
|
+
/**
|
|
891
|
+
* Latest NO price (0.0 to 1.0)
|
|
892
|
+
*/
|
|
893
|
+
latestNoPrice: number;
|
|
894
|
+
/**
|
|
895
|
+
* Outcome token price (0.0 to 1.0)
|
|
896
|
+
*/
|
|
897
|
+
outcomeTokenPrice: number;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* CLOB (Central Limit Order Book) position.
|
|
901
|
+
*
|
|
902
|
+
* @public
|
|
903
|
+
*/
|
|
904
|
+
interface CLOBPosition {
|
|
905
|
+
/**
|
|
906
|
+
* Market information
|
|
907
|
+
*/
|
|
908
|
+
market: PositionMarket;
|
|
909
|
+
/**
|
|
910
|
+
* User's wallet address
|
|
911
|
+
*/
|
|
912
|
+
makerAddress: string;
|
|
913
|
+
/**
|
|
914
|
+
* Position details for YES and NO sides
|
|
915
|
+
*/
|
|
916
|
+
positions: {
|
|
917
|
+
yes: PositionSide;
|
|
918
|
+
no: PositionSide;
|
|
919
|
+
};
|
|
920
|
+
/**
|
|
921
|
+
* Token balances
|
|
922
|
+
*/
|
|
923
|
+
tokensBalance: TokenBalance;
|
|
924
|
+
/**
|
|
925
|
+
* Latest trade information
|
|
926
|
+
*/
|
|
927
|
+
latestTrade: LatestTrade;
|
|
928
|
+
/**
|
|
929
|
+
* Active orders information
|
|
930
|
+
*/
|
|
931
|
+
orders?: {
|
|
932
|
+
liveOrders: any[];
|
|
933
|
+
totalCollateralLocked: string;
|
|
934
|
+
};
|
|
935
|
+
/**
|
|
936
|
+
* Rewards information
|
|
937
|
+
*/
|
|
938
|
+
rewards?: {
|
|
939
|
+
epochs: any[];
|
|
940
|
+
isEarning: boolean;
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* AMM (Automated Market Maker) position.
|
|
945
|
+
*
|
|
946
|
+
* @public
|
|
947
|
+
*/
|
|
948
|
+
interface AMMPosition {
|
|
949
|
+
/**
|
|
950
|
+
* Market information
|
|
951
|
+
*/
|
|
952
|
+
market: PositionMarket;
|
|
953
|
+
/**
|
|
954
|
+
* User's wallet address
|
|
955
|
+
*/
|
|
956
|
+
account: string;
|
|
957
|
+
/**
|
|
958
|
+
* Outcome index (0 for YES, 1 for NO)
|
|
959
|
+
*/
|
|
960
|
+
outcomeIndex: number;
|
|
961
|
+
/**
|
|
962
|
+
* Collateral amount (decimal string)
|
|
963
|
+
*/
|
|
964
|
+
collateralAmount: string;
|
|
965
|
+
/**
|
|
966
|
+
* Outcome token amount (decimal string)
|
|
967
|
+
*/
|
|
968
|
+
outcomeTokenAmount: string;
|
|
969
|
+
/**
|
|
970
|
+
* Average fill price (decimal string)
|
|
971
|
+
*/
|
|
972
|
+
averageFillPrice: string;
|
|
973
|
+
/**
|
|
974
|
+
* Total buys cost (decimal string)
|
|
975
|
+
*/
|
|
976
|
+
totalBuysCost: string;
|
|
977
|
+
/**
|
|
978
|
+
* Total sells cost (decimal string)
|
|
979
|
+
*/
|
|
980
|
+
totalSellsCost: string;
|
|
981
|
+
/**
|
|
982
|
+
* Realized P&L (decimal string)
|
|
983
|
+
*/
|
|
984
|
+
realizedPnl: string;
|
|
985
|
+
/**
|
|
986
|
+
* Unrealized P&L (decimal string)
|
|
987
|
+
*/
|
|
988
|
+
unrealizedPnl: string;
|
|
989
|
+
/**
|
|
990
|
+
* Latest trade information
|
|
991
|
+
*/
|
|
992
|
+
latestTrade?: {
|
|
993
|
+
outcomeTokenPrice: string;
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* API response for /portfolio/positions endpoint.
|
|
998
|
+
*
|
|
999
|
+
* @public
|
|
1000
|
+
*/
|
|
1001
|
+
interface PortfolioPositionsResponse {
|
|
1002
|
+
/**
|
|
1003
|
+
* AMM positions
|
|
1004
|
+
*/
|
|
1005
|
+
amm: AMMPosition[];
|
|
1006
|
+
/**
|
|
1007
|
+
* CLOB positions
|
|
1008
|
+
*/
|
|
1009
|
+
clob: CLOBPosition[];
|
|
1010
|
+
/**
|
|
1011
|
+
* Group positions
|
|
1012
|
+
*/
|
|
1013
|
+
group: any[];
|
|
1014
|
+
/**
|
|
1015
|
+
* User points
|
|
1016
|
+
*/
|
|
1017
|
+
points?: string;
|
|
1018
|
+
/**
|
|
1019
|
+
* Accumulative points
|
|
1020
|
+
*/
|
|
1021
|
+
accumulativePoints?: string;
|
|
1022
|
+
/**
|
|
1023
|
+
* Rewards information
|
|
1024
|
+
*/
|
|
1025
|
+
rewards?: {
|
|
1026
|
+
todaysRewards: string;
|
|
1027
|
+
rewardsByEpoch: any[];
|
|
1028
|
+
rewardsChartData: any[];
|
|
1029
|
+
totalUnpaidRewards: string;
|
|
1030
|
+
totalUserRewardsLastEpoch: string;
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Simplified position for unified view.
|
|
1035
|
+
*
|
|
1036
|
+
* @public
|
|
1037
|
+
*/
|
|
1038
|
+
interface Position {
|
|
1039
|
+
/**
|
|
1040
|
+
* Position type
|
|
1041
|
+
*/
|
|
1042
|
+
type: 'CLOB' | 'AMM';
|
|
1043
|
+
/**
|
|
1044
|
+
* Market information
|
|
1045
|
+
*/
|
|
1046
|
+
market: PositionMarket;
|
|
1047
|
+
/**
|
|
1048
|
+
* Position side (YES or NO)
|
|
1049
|
+
*/
|
|
1050
|
+
side: 'YES' | 'NO';
|
|
1051
|
+
/**
|
|
1052
|
+
* Cost basis in USDC (6 decimals)
|
|
1053
|
+
*/
|
|
1054
|
+
costBasis: number;
|
|
1055
|
+
/**
|
|
1056
|
+
* Current market value in USDC (6 decimals)
|
|
1057
|
+
*/
|
|
1058
|
+
marketValue: number;
|
|
1059
|
+
/**
|
|
1060
|
+
* Unrealized P&L in USDC (6 decimals)
|
|
1061
|
+
*/
|
|
1062
|
+
unrealizedPnl: number;
|
|
1063
|
+
/**
|
|
1064
|
+
* Realized P&L in USDC (6 decimals)
|
|
1065
|
+
*/
|
|
1066
|
+
realizedPnl: number;
|
|
1067
|
+
/**
|
|
1068
|
+
* Current price (0.0 to 1.0)
|
|
1069
|
+
*/
|
|
1070
|
+
currentPrice: number;
|
|
1071
|
+
/**
|
|
1072
|
+
* Average entry price (0.0 to 1.0)
|
|
1073
|
+
*/
|
|
1074
|
+
avgPrice: number;
|
|
1075
|
+
/**
|
|
1076
|
+
* Token balance (6 decimals)
|
|
1077
|
+
*/
|
|
1078
|
+
tokenBalance: number;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Portfolio summary statistics.
|
|
1082
|
+
*
|
|
1083
|
+
* @public
|
|
1084
|
+
*/
|
|
1085
|
+
interface PortfolioSummary {
|
|
1086
|
+
/**
|
|
1087
|
+
* Total portfolio value in USDC (6 decimals)
|
|
1088
|
+
*/
|
|
1089
|
+
totalValue: number;
|
|
1090
|
+
/**
|
|
1091
|
+
* Total cost basis in USDC (6 decimals)
|
|
1092
|
+
*/
|
|
1093
|
+
totalCostBasis: number;
|
|
1094
|
+
/**
|
|
1095
|
+
* Total unrealized P&L in USDC (6 decimals)
|
|
1096
|
+
*/
|
|
1097
|
+
totalUnrealizedPnl: number;
|
|
1098
|
+
/**
|
|
1099
|
+
* Total realized P&L in USDC (6 decimals)
|
|
1100
|
+
*/
|
|
1101
|
+
totalRealizedPnl: number;
|
|
1102
|
+
/**
|
|
1103
|
+
* Total unrealized P&L percentage
|
|
1104
|
+
*/
|
|
1105
|
+
totalUnrealizedPnlPercent: number;
|
|
1106
|
+
/**
|
|
1107
|
+
* Number of open positions
|
|
1108
|
+
*/
|
|
1109
|
+
positionCount: number;
|
|
1110
|
+
/**
|
|
1111
|
+
* Number of markets with positions
|
|
1112
|
+
*/
|
|
1113
|
+
marketCount: number;
|
|
1114
|
+
/**
|
|
1115
|
+
* Breakdown by position type
|
|
1116
|
+
*/
|
|
1117
|
+
breakdown: {
|
|
1118
|
+
clob: {
|
|
1119
|
+
positions: number;
|
|
1120
|
+
value: number;
|
|
1121
|
+
pnl: number;
|
|
1122
|
+
};
|
|
1123
|
+
amm: {
|
|
1124
|
+
positions: number;
|
|
1125
|
+
value: number;
|
|
1126
|
+
pnl: number;
|
|
1127
|
+
};
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* WebSocket types for real-time data streaming.
|
|
1133
|
+
* @module types/websocket
|
|
1134
|
+
*/
|
|
1135
|
+
/**
|
|
1136
|
+
* WebSocket connection configuration.
|
|
1137
|
+
* @public
|
|
1138
|
+
*/
|
|
1139
|
+
interface WebSocketConfig {
|
|
1140
|
+
/**
|
|
1141
|
+
* WebSocket URL (default: wss://ws.limitless.exchange)
|
|
1142
|
+
*/
|
|
1143
|
+
url?: string;
|
|
1144
|
+
/**
|
|
1145
|
+
* Session cookie for authentication
|
|
1146
|
+
*/
|
|
1147
|
+
sessionCookie?: string;
|
|
1148
|
+
/**
|
|
1149
|
+
* Auto-reconnect on connection loss (default: true)
|
|
1150
|
+
*/
|
|
1151
|
+
autoReconnect?: boolean;
|
|
1152
|
+
/**
|
|
1153
|
+
* Reconnection delay in ms (default: 1000)
|
|
1154
|
+
*/
|
|
1155
|
+
reconnectDelay?: number;
|
|
1156
|
+
/**
|
|
1157
|
+
* Maximum reconnection attempts (default: Infinity)
|
|
1158
|
+
*/
|
|
1159
|
+
maxReconnectAttempts?: number;
|
|
1160
|
+
/**
|
|
1161
|
+
* Connection timeout in ms (default: 10000)
|
|
1162
|
+
*/
|
|
1163
|
+
timeout?: number;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* WebSocket connection state.
|
|
1167
|
+
* @public
|
|
1168
|
+
*/
|
|
1169
|
+
declare enum WebSocketState {
|
|
1170
|
+
DISCONNECTED = "disconnected",
|
|
1171
|
+
CONNECTING = "connecting",
|
|
1172
|
+
CONNECTED = "connected",
|
|
1173
|
+
RECONNECTING = "reconnecting",
|
|
1174
|
+
ERROR = "error"
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Subscription channels for WebSocket events.
|
|
1178
|
+
* @public
|
|
1179
|
+
*/
|
|
1180
|
+
type SubscriptionChannel = 'orderbook' | 'trades' | 'orders' | 'fills' | 'markets' | 'prices';
|
|
1181
|
+
/**
|
|
1182
|
+
* Orderbook update event.
|
|
1183
|
+
* @public
|
|
1184
|
+
*/
|
|
1185
|
+
interface OrderbookUpdate {
|
|
1186
|
+
marketSlug: string;
|
|
1187
|
+
bids: Array<{
|
|
1188
|
+
price: number;
|
|
1189
|
+
size: number;
|
|
1190
|
+
}>;
|
|
1191
|
+
asks: Array<{
|
|
1192
|
+
price: number;
|
|
1193
|
+
size: number;
|
|
1194
|
+
}>;
|
|
1195
|
+
timestamp: number;
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Trade event.
|
|
1199
|
+
* @public
|
|
1200
|
+
*/
|
|
1201
|
+
interface TradeEvent {
|
|
1202
|
+
marketSlug: string;
|
|
1203
|
+
side: 'BUY' | 'SELL';
|
|
1204
|
+
price: number;
|
|
1205
|
+
size: number;
|
|
1206
|
+
timestamp: number;
|
|
1207
|
+
tradeId: string;
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Order update event.
|
|
1211
|
+
* @public
|
|
1212
|
+
*/
|
|
1213
|
+
interface OrderUpdate {
|
|
1214
|
+
orderId: string;
|
|
1215
|
+
marketSlug: string;
|
|
1216
|
+
side: 'BUY' | 'SELL';
|
|
1217
|
+
price?: number;
|
|
1218
|
+
size: number;
|
|
1219
|
+
filled: number;
|
|
1220
|
+
status: 'OPEN' | 'FILLED' | 'CANCELLED' | 'PARTIALLY_FILLED';
|
|
1221
|
+
timestamp: number;
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Order fill event.
|
|
1225
|
+
* @public
|
|
1226
|
+
*/
|
|
1227
|
+
interface FillEvent {
|
|
1228
|
+
orderId: string;
|
|
1229
|
+
marketSlug: string;
|
|
1230
|
+
side: 'BUY' | 'SELL';
|
|
1231
|
+
price: number;
|
|
1232
|
+
size: number;
|
|
1233
|
+
timestamp: number;
|
|
1234
|
+
fillId: string;
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Market update event.
|
|
1238
|
+
* @public
|
|
1239
|
+
*/
|
|
1240
|
+
interface MarketUpdate {
|
|
1241
|
+
marketSlug: string;
|
|
1242
|
+
lastPrice?: number;
|
|
1243
|
+
volume24h?: number;
|
|
1244
|
+
priceChange24h?: number;
|
|
1245
|
+
timestamp: number;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Price update event.
|
|
1249
|
+
* @public
|
|
1250
|
+
*/
|
|
1251
|
+
interface PriceUpdate {
|
|
1252
|
+
marketSlug: string;
|
|
1253
|
+
price: number;
|
|
1254
|
+
timestamp: number;
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* WebSocket event types.
|
|
1258
|
+
* @public
|
|
1259
|
+
*/
|
|
1260
|
+
interface WebSocketEvents {
|
|
1261
|
+
/**
|
|
1262
|
+
* Connection established
|
|
1263
|
+
*/
|
|
1264
|
+
connect: () => void;
|
|
1265
|
+
/**
|
|
1266
|
+
* Connection lost
|
|
1267
|
+
*/
|
|
1268
|
+
disconnect: (reason: string) => void;
|
|
1269
|
+
/**
|
|
1270
|
+
* Connection error
|
|
1271
|
+
*/
|
|
1272
|
+
error: (error: Error) => void;
|
|
1273
|
+
/**
|
|
1274
|
+
* Reconnection attempt
|
|
1275
|
+
*/
|
|
1276
|
+
reconnecting: (attempt: number) => void;
|
|
1277
|
+
/**
|
|
1278
|
+
* Orderbook updates
|
|
1279
|
+
*/
|
|
1280
|
+
orderbook: (data: OrderbookUpdate) => void;
|
|
1281
|
+
/**
|
|
1282
|
+
* Trade events
|
|
1283
|
+
*/
|
|
1284
|
+
trade: (data: TradeEvent) => void;
|
|
1285
|
+
/**
|
|
1286
|
+
* Order updates
|
|
1287
|
+
*/
|
|
1288
|
+
order: (data: OrderUpdate) => void;
|
|
1289
|
+
/**
|
|
1290
|
+
* Order fill events
|
|
1291
|
+
*/
|
|
1292
|
+
fill: (data: FillEvent) => void;
|
|
1293
|
+
/**
|
|
1294
|
+
* Market updates
|
|
1295
|
+
*/
|
|
1296
|
+
market: (data: MarketUpdate) => void;
|
|
1297
|
+
/**
|
|
1298
|
+
* Price updates
|
|
1299
|
+
*/
|
|
1300
|
+
price: (data: PriceUpdate) => void;
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Subscription options.
|
|
1304
|
+
* @public
|
|
1305
|
+
*/
|
|
1306
|
+
interface SubscriptionOptions {
|
|
1307
|
+
/**
|
|
1308
|
+
* Market slug to subscribe to (required for market-specific channels)
|
|
1309
|
+
*/
|
|
1310
|
+
marketSlug?: string;
|
|
1311
|
+
/**
|
|
1312
|
+
* Market address to subscribe to (for AMM markets)
|
|
1313
|
+
*/
|
|
1314
|
+
marketAddress?: string;
|
|
1315
|
+
/**
|
|
1316
|
+
* Additional filters
|
|
1317
|
+
*/
|
|
1318
|
+
filters?: Record<string, any>;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
/**
|
|
1322
|
+
* Message signer for authentication.
|
|
1323
|
+
*
|
|
1324
|
+
* @remarks
|
|
1325
|
+
* This class handles signing messages with an Ethereum wallet and
|
|
1326
|
+
* creating authentication headers required by the Limitless Exchange API.
|
|
1327
|
+
*
|
|
1328
|
+
* @public
|
|
1329
|
+
*/
|
|
1330
|
+
declare class MessageSigner {
|
|
1331
|
+
private wallet;
|
|
1332
|
+
/**
|
|
1333
|
+
* Creates a new message signer instance.
|
|
1334
|
+
*
|
|
1335
|
+
* @param wallet - Ethers wallet instance for signing
|
|
1336
|
+
*/
|
|
1337
|
+
constructor(wallet: ethers.Wallet);
|
|
1338
|
+
/**
|
|
1339
|
+
* Creates authentication headers for API requests.
|
|
1340
|
+
*
|
|
1341
|
+
* @param signingMessage - Message to sign from the API
|
|
1342
|
+
* @returns Promise resolving to signature headers
|
|
1343
|
+
*
|
|
1344
|
+
* @example
|
|
1345
|
+
* ```typescript
|
|
1346
|
+
* const signer = new MessageSigner(wallet);
|
|
1347
|
+
* const headers = await signer.createAuthHeaders(message);
|
|
1348
|
+
* ```
|
|
1349
|
+
*/
|
|
1350
|
+
createAuthHeaders(signingMessage: string): Promise<SignatureHeaders>;
|
|
1351
|
+
/**
|
|
1352
|
+
* Signs EIP-712 typed data.
|
|
1353
|
+
*
|
|
1354
|
+
* @param domain - EIP-712 domain
|
|
1355
|
+
* @param types - EIP-712 types
|
|
1356
|
+
* @param value - Value to sign
|
|
1357
|
+
* @returns Promise resolving to signature string
|
|
1358
|
+
*
|
|
1359
|
+
* @example
|
|
1360
|
+
* ```typescript
|
|
1361
|
+
* const signature = await signer.signTypedData(domain, types, order);
|
|
1362
|
+
* ```
|
|
1363
|
+
*/
|
|
1364
|
+
signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, any>): Promise<string>;
|
|
1365
|
+
/**
|
|
1366
|
+
* Gets the wallet address.
|
|
1367
|
+
*
|
|
1368
|
+
* @returns Ethereum address
|
|
1369
|
+
*/
|
|
1370
|
+
getAddress(): string;
|
|
1371
|
+
/**
|
|
1372
|
+
* Converts a string to hex format.
|
|
1373
|
+
*
|
|
1374
|
+
* @param text - String to convert
|
|
1375
|
+
* @returns Hex string with 0x prefix
|
|
1376
|
+
* @internal
|
|
1377
|
+
*/
|
|
1378
|
+
private stringToHex;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Configuration options for the HTTP client.
|
|
1383
|
+
* @public
|
|
1384
|
+
*/
|
|
1385
|
+
interface HttpClientConfig {
|
|
1386
|
+
/**
|
|
1387
|
+
* Base URL for API requests
|
|
1388
|
+
* @defaultValue 'https://api.limitless.exchange'
|
|
1389
|
+
*/
|
|
1390
|
+
baseURL?: string;
|
|
1391
|
+
/**
|
|
1392
|
+
* Request timeout in milliseconds
|
|
1393
|
+
* @defaultValue 30000
|
|
1394
|
+
*/
|
|
1395
|
+
timeout?: number;
|
|
1396
|
+
/**
|
|
1397
|
+
* Session cookie for authenticated requests
|
|
1398
|
+
*/
|
|
1399
|
+
sessionCookie?: string;
|
|
1400
|
+
/**
|
|
1401
|
+
* Optional logger for debugging
|
|
1402
|
+
* @defaultValue NoOpLogger (no logging)
|
|
1403
|
+
*/
|
|
1404
|
+
logger?: ILogger;
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* HTTP client wrapper for Limitless Exchange API.
|
|
1408
|
+
*
|
|
1409
|
+
* @remarks
|
|
1410
|
+
* This class provides a centralized HTTP client with cookie management,
|
|
1411
|
+
* error handling, and request/response interceptors.
|
|
1412
|
+
*
|
|
1413
|
+
* @public
|
|
1414
|
+
*/
|
|
1415
|
+
declare class HttpClient {
|
|
1416
|
+
private client;
|
|
1417
|
+
private sessionCookie?;
|
|
1418
|
+
private logger;
|
|
1419
|
+
/**
|
|
1420
|
+
* Creates a new HTTP client instance.
|
|
1421
|
+
*
|
|
1422
|
+
* @param config - Configuration options for the HTTP client
|
|
1423
|
+
*/
|
|
1424
|
+
constructor(config?: HttpClientConfig);
|
|
1425
|
+
/**
|
|
1426
|
+
* Sets up request and response interceptors.
|
|
1427
|
+
* @internal
|
|
1428
|
+
*/
|
|
1429
|
+
private setupInterceptors;
|
|
1430
|
+
/**
|
|
1431
|
+
* Sets the session cookie for authenticated requests.
|
|
1432
|
+
*
|
|
1433
|
+
* @param cookie - Session cookie value
|
|
1434
|
+
*/
|
|
1435
|
+
setSessionCookie(cookie: string): void;
|
|
1436
|
+
/**
|
|
1437
|
+
* Clears the session cookie.
|
|
1438
|
+
*/
|
|
1439
|
+
clearSessionCookie(): void;
|
|
1440
|
+
/**
|
|
1441
|
+
* Performs a GET request.
|
|
1442
|
+
*
|
|
1443
|
+
* @param url - Request URL
|
|
1444
|
+
* @param config - Additional request configuration
|
|
1445
|
+
* @returns Promise resolving to the response data
|
|
1446
|
+
*/
|
|
1447
|
+
get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
1448
|
+
/**
|
|
1449
|
+
* Performs a POST request.
|
|
1450
|
+
*
|
|
1451
|
+
* @param url - Request URL
|
|
1452
|
+
* @param data - Request body data
|
|
1453
|
+
* @param config - Additional request configuration
|
|
1454
|
+
* @returns Promise resolving to the response data
|
|
1455
|
+
*/
|
|
1456
|
+
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
1457
|
+
/**
|
|
1458
|
+
* Performs a POST request and returns the full response object.
|
|
1459
|
+
* Useful when you need access to response headers (e.g., for cookie extraction).
|
|
1460
|
+
*
|
|
1461
|
+
* @param url - Request URL
|
|
1462
|
+
* @param data - Request body data
|
|
1463
|
+
* @param config - Additional request configuration
|
|
1464
|
+
* @returns Promise resolving to the full AxiosResponse object
|
|
1465
|
+
* @internal
|
|
1466
|
+
*/
|
|
1467
|
+
postWithResponse<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
|
1468
|
+
/**
|
|
1469
|
+
* Performs a DELETE request.
|
|
1470
|
+
*
|
|
1471
|
+
* @remarks
|
|
1472
|
+
* DELETE requests typically don't have a body, so we remove the Content-Type header
|
|
1473
|
+
* to avoid "Body cannot be empty" errors from the API.
|
|
1474
|
+
*
|
|
1475
|
+
* @param url - Request URL
|
|
1476
|
+
* @param config - Additional request configuration
|
|
1477
|
+
* @returns Promise resolving to the response data
|
|
1478
|
+
*/
|
|
1479
|
+
delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
1480
|
+
/**
|
|
1481
|
+
* Extracts cookies from response headers.
|
|
1482
|
+
*
|
|
1483
|
+
* @param response - Axios response object
|
|
1484
|
+
* @returns Object containing parsed cookies
|
|
1485
|
+
* @internal
|
|
1486
|
+
*/
|
|
1487
|
+
extractCookies(response: AxiosResponse): Record<string, string>;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
/**
|
|
1491
|
+
* Authenticator for Limitless Exchange API.
|
|
1492
|
+
*
|
|
1493
|
+
* @remarks
|
|
1494
|
+
* This class handles the complete authentication flow:
|
|
1495
|
+
* 1. Get signing message from API
|
|
1496
|
+
* 2. Sign message with wallet
|
|
1497
|
+
* 3. Login and obtain session cookie
|
|
1498
|
+
* 4. Verify authentication status
|
|
1499
|
+
*
|
|
1500
|
+
* @public
|
|
1501
|
+
*/
|
|
1502
|
+
declare class Authenticator {
|
|
1503
|
+
private httpClient;
|
|
1504
|
+
private signer;
|
|
1505
|
+
private logger;
|
|
1506
|
+
/**
|
|
1507
|
+
* Creates a new authenticator instance.
|
|
1508
|
+
*
|
|
1509
|
+
* @param httpClient - HTTP client for API requests
|
|
1510
|
+
* @param signer - Message signer for wallet operations
|
|
1511
|
+
* @param logger - Optional logger for debugging and monitoring (default: no logging)
|
|
1512
|
+
*
|
|
1513
|
+
* @example
|
|
1514
|
+
* ```typescript
|
|
1515
|
+
* // Without logging (default)
|
|
1516
|
+
* const authenticator = new Authenticator(httpClient, signer);
|
|
1517
|
+
*
|
|
1518
|
+
* // With logging
|
|
1519
|
+
* import { ConsoleLogger } from '@limitless-exchange/sdk';
|
|
1520
|
+
* const logger = new ConsoleLogger('debug');
|
|
1521
|
+
* const authenticator = new Authenticator(httpClient, signer, logger);
|
|
1522
|
+
* ```
|
|
1523
|
+
*/
|
|
1524
|
+
constructor(httpClient: HttpClient, signer: MessageSigner, logger?: ILogger);
|
|
1525
|
+
/**
|
|
1526
|
+
* Gets a signing message from the API.
|
|
1527
|
+
*
|
|
1528
|
+
* @returns Promise resolving to signing message string
|
|
1529
|
+
* @throws Error if API request fails
|
|
1530
|
+
*
|
|
1531
|
+
* @example
|
|
1532
|
+
* ```typescript
|
|
1533
|
+
* const message = await authenticator.getSigningMessage();
|
|
1534
|
+
* console.log(message);
|
|
1535
|
+
* ```
|
|
1536
|
+
*/
|
|
1537
|
+
getSigningMessage(): Promise<string>;
|
|
1538
|
+
/**
|
|
1539
|
+
* Authenticates with the API and obtains session cookie.
|
|
1540
|
+
*
|
|
1541
|
+
* @param options - Login options including client type and smart wallet
|
|
1542
|
+
* @returns Promise resolving to authentication result
|
|
1543
|
+
* @throws Error if authentication fails or smart wallet is required but not provided
|
|
1544
|
+
*
|
|
1545
|
+
* @example
|
|
1546
|
+
* ```typescript
|
|
1547
|
+
* // EOA authentication
|
|
1548
|
+
* const result = await authenticator.authenticate({ client: 'eoa' });
|
|
1549
|
+
*
|
|
1550
|
+
* // ETHERSPOT with smart wallet
|
|
1551
|
+
* const result = await authenticator.authenticate({
|
|
1552
|
+
* client: 'etherspot',
|
|
1553
|
+
* smartWallet: '0x...'
|
|
1554
|
+
* });
|
|
1555
|
+
* ```
|
|
1556
|
+
*/
|
|
1557
|
+
authenticate(options?: LoginOptions): Promise<AuthResult>;
|
|
1558
|
+
/**
|
|
1559
|
+
* Verifies the current authentication status.
|
|
1560
|
+
*
|
|
1561
|
+
* @param sessionCookie - Session cookie to verify
|
|
1562
|
+
* @returns Promise resolving to user's Ethereum address
|
|
1563
|
+
* @throws Error if session is invalid
|
|
1564
|
+
*
|
|
1565
|
+
* @example
|
|
1566
|
+
* ```typescript
|
|
1567
|
+
* const address = await authenticator.verifyAuth(sessionCookie);
|
|
1568
|
+
* console.log(`Authenticated as: ${address}`);
|
|
1569
|
+
* ```
|
|
1570
|
+
*/
|
|
1571
|
+
verifyAuth(sessionCookie: string): Promise<string>;
|
|
1572
|
+
/**
|
|
1573
|
+
* Logs out and clears the session.
|
|
1574
|
+
*
|
|
1575
|
+
* @param sessionCookie - Session cookie to invalidate
|
|
1576
|
+
* @throws Error if logout request fails
|
|
1577
|
+
*
|
|
1578
|
+
* @example
|
|
1579
|
+
* ```typescript
|
|
1580
|
+
* await authenticator.logout(sessionCookie);
|
|
1581
|
+
* console.log('Logged out successfully');
|
|
1582
|
+
* ```
|
|
1583
|
+
*/
|
|
1584
|
+
logout(sessionCookie: string): Promise<void>;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/**
|
|
1588
|
+
* Optional helper for automatic authentication retry on token expiration.
|
|
1589
|
+
* @module auth/authenticated-client
|
|
1590
|
+
*/
|
|
1591
|
+
|
|
1592
|
+
/**
|
|
1593
|
+
* Configuration for authenticated client with auto-retry.
|
|
1594
|
+
* @public
|
|
1595
|
+
*/
|
|
1596
|
+
interface AuthenticatedClientConfig {
|
|
1597
|
+
/**
|
|
1598
|
+
* HTTP client instance
|
|
1599
|
+
*/
|
|
1600
|
+
httpClient: HttpClient;
|
|
1601
|
+
/**
|
|
1602
|
+
* Authenticator instance
|
|
1603
|
+
*/
|
|
1604
|
+
authenticator: Authenticator;
|
|
1605
|
+
/**
|
|
1606
|
+
* Authentication client type ('eoa' or 'etherspot')
|
|
1607
|
+
*/
|
|
1608
|
+
client: 'eoa' | 'etherspot';
|
|
1609
|
+
/**
|
|
1610
|
+
* Optional smart wallet address (required for 'etherspot')
|
|
1611
|
+
*/
|
|
1612
|
+
smartWallet?: string;
|
|
1613
|
+
/**
|
|
1614
|
+
* Optional logger for debugging
|
|
1615
|
+
*/
|
|
1616
|
+
logger?: ILogger;
|
|
1617
|
+
/**
|
|
1618
|
+
* Maximum retry attempts for auth errors (default: 1)
|
|
1619
|
+
*/
|
|
1620
|
+
maxRetries?: number;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Optional helper class that automatically re-authenticates on token expiration.
|
|
1624
|
+
*
|
|
1625
|
+
* @remarks
|
|
1626
|
+
* This is an optional convenience wrapper. Users can choose to handle
|
|
1627
|
+
* authentication retry manually or use this helper for automatic retry logic.
|
|
1628
|
+
*
|
|
1629
|
+
* @example
|
|
1630
|
+
* ```typescript
|
|
1631
|
+
* // Create authenticated client with auto-retry
|
|
1632
|
+
* const authClient = new AuthenticatedClient({
|
|
1633
|
+
* httpClient,
|
|
1634
|
+
* authenticator,
|
|
1635
|
+
* client: 'eoa'
|
|
1636
|
+
* });
|
|
1637
|
+
*
|
|
1638
|
+
* // Use withRetry for automatic re-authentication
|
|
1639
|
+
* const portfolioFetcher = new PortfolioFetcher(httpClient);
|
|
1640
|
+
* const positions = await authClient.withRetry(() =>
|
|
1641
|
+
* portfolioFetcher.getPositions()
|
|
1642
|
+
* );
|
|
1643
|
+
* ```
|
|
1644
|
+
*
|
|
1645
|
+
* @public
|
|
1646
|
+
*/
|
|
1647
|
+
declare class AuthenticatedClient {
|
|
1648
|
+
private httpClient;
|
|
1649
|
+
private authenticator;
|
|
1650
|
+
private client;
|
|
1651
|
+
private smartWallet?;
|
|
1652
|
+
private logger;
|
|
1653
|
+
private maxRetries;
|
|
1654
|
+
/**
|
|
1655
|
+
* Creates a new authenticated client with auto-retry capability.
|
|
1656
|
+
*
|
|
1657
|
+
* @param config - Configuration for authenticated client
|
|
1658
|
+
*/
|
|
1659
|
+
constructor(config: AuthenticatedClientConfig);
|
|
1660
|
+
/**
|
|
1661
|
+
* Executes a function with automatic retry on authentication errors.
|
|
1662
|
+
*
|
|
1663
|
+
* @param fn - Function to execute with auth retry
|
|
1664
|
+
* @returns Promise resolving to the function result
|
|
1665
|
+
* @throws Error if max retries exceeded or non-auth error occurs
|
|
1666
|
+
*
|
|
1667
|
+
* @example
|
|
1668
|
+
* ```typescript
|
|
1669
|
+
* // Automatic retry on 401/403
|
|
1670
|
+
* const positions = await authClient.withRetry(() =>
|
|
1671
|
+
* portfolioFetcher.getPositions()
|
|
1672
|
+
* );
|
|
1673
|
+
*
|
|
1674
|
+
* // Works with any async operation
|
|
1675
|
+
* const order = await authClient.withRetry(() =>
|
|
1676
|
+
* orderClient.createOrder({ ... })
|
|
1677
|
+
* );
|
|
1678
|
+
* ```
|
|
1679
|
+
*/
|
|
1680
|
+
withRetry<T>(fn: () => Promise<T>): Promise<T>;
|
|
1681
|
+
/**
|
|
1682
|
+
* Re-authenticates with the API.
|
|
1683
|
+
*
|
|
1684
|
+
* @internal
|
|
1685
|
+
*/
|
|
1686
|
+
private reauthenticate;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
/**
|
|
1690
|
+
* API error types for Limitless Exchange SDK.
|
|
1691
|
+
* @module api/errors
|
|
1692
|
+
*/
|
|
1693
|
+
/**
|
|
1694
|
+
* Custom error class for API errors that preserves the original response data.
|
|
1695
|
+
*
|
|
1696
|
+
* @remarks
|
|
1697
|
+
* This error class allows users to access the raw API response for custom error handling.
|
|
1698
|
+
*
|
|
1699
|
+
* @example
|
|
1700
|
+
* ```typescript
|
|
1701
|
+
* try {
|
|
1702
|
+
* await orderClient.createOrder(...);
|
|
1703
|
+
* } catch (error) {
|
|
1704
|
+
* if (error instanceof APIError) {
|
|
1705
|
+
* console.log('Status:', error.status);
|
|
1706
|
+
* console.log('Raw response:', error.data);
|
|
1707
|
+
* console.log('Message:', error.message);
|
|
1708
|
+
* }
|
|
1709
|
+
* }
|
|
1710
|
+
* ```
|
|
1711
|
+
*
|
|
1712
|
+
* @public
|
|
1713
|
+
*/
|
|
1714
|
+
declare class APIError extends Error {
|
|
1715
|
+
/**
|
|
1716
|
+
* HTTP status code (e.g., 400, 404, 500)
|
|
1717
|
+
*/
|
|
1718
|
+
readonly status: number;
|
|
1719
|
+
/**
|
|
1720
|
+
* Raw API response data (original JSON from API)
|
|
1721
|
+
*/
|
|
1722
|
+
readonly data: any;
|
|
1723
|
+
/**
|
|
1724
|
+
* Request URL that failed
|
|
1725
|
+
*/
|
|
1726
|
+
readonly url?: string;
|
|
1727
|
+
/**
|
|
1728
|
+
* Request method (GET, POST, etc.)
|
|
1729
|
+
*/
|
|
1730
|
+
readonly method?: string;
|
|
1731
|
+
/**
|
|
1732
|
+
* Creates a new API error.
|
|
1733
|
+
*
|
|
1734
|
+
* @param message - Human-readable error message
|
|
1735
|
+
* @param status - HTTP status code
|
|
1736
|
+
* @param data - Raw API response data
|
|
1737
|
+
* @param url - Request URL
|
|
1738
|
+
* @param method - Request method
|
|
1739
|
+
*/
|
|
1740
|
+
constructor(message: string, status: number, data: any, url?: string, method?: string);
|
|
1741
|
+
/**
|
|
1742
|
+
* Checks if this error is an authentication/authorization error.
|
|
1743
|
+
*
|
|
1744
|
+
* @returns True if the error is due to expired or invalid authentication
|
|
1745
|
+
*
|
|
1746
|
+
* @example
|
|
1747
|
+
* ```typescript
|
|
1748
|
+
* try {
|
|
1749
|
+
* await portfolioFetcher.getPositions();
|
|
1750
|
+
* } catch (error) {
|
|
1751
|
+
* if (error instanceof APIError && error.isAuthError()) {
|
|
1752
|
+
* // Re-authenticate and retry
|
|
1753
|
+
* await authenticator.authenticate({ client: 'eoa' });
|
|
1754
|
+
* await portfolioFetcher.getPositions();
|
|
1755
|
+
* }
|
|
1756
|
+
* }
|
|
1757
|
+
* ```
|
|
1758
|
+
*/
|
|
1759
|
+
isAuthError(): boolean;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
/**
|
|
1763
|
+
* Retry mechanism for handling transient API failures.
|
|
1764
|
+
*
|
|
1765
|
+
* @remarks
|
|
1766
|
+
* This module provides flexible retry logic for handling rate limits (429),
|
|
1767
|
+
* server errors (500, 502, 503), and other transient failures.
|
|
1768
|
+
*
|
|
1769
|
+
* @example
|
|
1770
|
+
* ```typescript
|
|
1771
|
+
* // Decorator approach
|
|
1772
|
+
* @retryOnErrors({ statusCodes: [429, 500], maxRetries: 3, delays: [2, 5, 10] })
|
|
1773
|
+
* async function createOrder() {
|
|
1774
|
+
* return await orderClient.createOrder(...);
|
|
1775
|
+
* }
|
|
1776
|
+
*
|
|
1777
|
+
* // Wrapper approach
|
|
1778
|
+
* const retryConfig = new RetryConfig({ statusCodes: [429, 500], maxRetries: 3 });
|
|
1779
|
+
* const retryableClient = new RetryableClient(httpClient, retryConfig);
|
|
1780
|
+
* const markets = await retryableClient.get('/markets');
|
|
1781
|
+
* ```
|
|
1782
|
+
*
|
|
1783
|
+
* @module api/retry
|
|
1784
|
+
* @public
|
|
1785
|
+
*/
|
|
1786
|
+
|
|
1787
|
+
/**
|
|
1788
|
+
* Configuration options for retry behavior.
|
|
1789
|
+
*
|
|
1790
|
+
* @public
|
|
1791
|
+
*/
|
|
1792
|
+
interface RetryConfigOptions {
|
|
1793
|
+
/**
|
|
1794
|
+
* HTTP status codes to retry on
|
|
1795
|
+
* @defaultValue [429, 500, 502, 503, 504]
|
|
1796
|
+
*/
|
|
1797
|
+
statusCodes?: number[];
|
|
1798
|
+
/**
|
|
1799
|
+
* Maximum number of retry attempts
|
|
1800
|
+
* @defaultValue 3
|
|
1801
|
+
*/
|
|
1802
|
+
maxRetries?: number;
|
|
1803
|
+
/**
|
|
1804
|
+
* List of delays in seconds for each retry attempt.
|
|
1805
|
+
* If not provided, exponential backoff will be used.
|
|
1806
|
+
* @defaultValue undefined (use exponential backoff)
|
|
1807
|
+
*/
|
|
1808
|
+
delays?: number[];
|
|
1809
|
+
/**
|
|
1810
|
+
* Base for exponential backoff calculation (delay = base^attempt)
|
|
1811
|
+
* @defaultValue 2
|
|
1812
|
+
*/
|
|
1813
|
+
exponentialBase?: number;
|
|
1814
|
+
/**
|
|
1815
|
+
* Maximum delay in seconds for exponential backoff
|
|
1816
|
+
* @defaultValue 60
|
|
1817
|
+
*/
|
|
1818
|
+
maxDelay?: number;
|
|
1819
|
+
/**
|
|
1820
|
+
* Optional callback called before each retry attempt
|
|
1821
|
+
* @param attempt - Retry attempt number (0-based)
|
|
1822
|
+
* @param error - The error that triggered the retry
|
|
1823
|
+
* @param delay - Delay in seconds before retry
|
|
1824
|
+
*/
|
|
1825
|
+
onRetry?: (attempt: number, error: Error, delay: number) => void;
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Configuration class for retry behavior.
|
|
1829
|
+
*
|
|
1830
|
+
* @public
|
|
1831
|
+
*/
|
|
1832
|
+
declare class RetryConfig {
|
|
1833
|
+
/**
|
|
1834
|
+
* HTTP status codes to retry on
|
|
1835
|
+
*/
|
|
1836
|
+
readonly statusCodes: Set<number>;
|
|
1837
|
+
/**
|
|
1838
|
+
* Maximum number of retry attempts
|
|
1839
|
+
*/
|
|
1840
|
+
readonly maxRetries: number;
|
|
1841
|
+
/**
|
|
1842
|
+
* List of delays in seconds for each retry
|
|
1843
|
+
*/
|
|
1844
|
+
readonly delays?: number[];
|
|
1845
|
+
/**
|
|
1846
|
+
* Base for exponential backoff
|
|
1847
|
+
*/
|
|
1848
|
+
readonly exponentialBase: number;
|
|
1849
|
+
/**
|
|
1850
|
+
* Maximum delay in seconds
|
|
1851
|
+
*/
|
|
1852
|
+
readonly maxDelay: number;
|
|
1853
|
+
/**
|
|
1854
|
+
* Optional retry callback
|
|
1855
|
+
*/
|
|
1856
|
+
readonly onRetry?: (attempt: number, error: Error, delay: number) => void;
|
|
1857
|
+
/**
|
|
1858
|
+
* Creates a new retry configuration.
|
|
1859
|
+
*
|
|
1860
|
+
* @param options - Configuration options
|
|
1861
|
+
*/
|
|
1862
|
+
constructor(options?: RetryConfigOptions);
|
|
1863
|
+
/**
|
|
1864
|
+
* Calculates delay for a given retry attempt.
|
|
1865
|
+
*
|
|
1866
|
+
* @param attempt - Retry attempt number (0-based)
|
|
1867
|
+
* @returns Delay in seconds
|
|
1868
|
+
*/
|
|
1869
|
+
getDelay(attempt: number): number;
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* Decorator to add retry logic to async functions.
|
|
1873
|
+
*
|
|
1874
|
+
* @remarks
|
|
1875
|
+
* This decorator automatically retries failed API calls based on HTTP status codes.
|
|
1876
|
+
* Useful for handling transient errors like rate limits (429) or server errors (500, 502, 503).
|
|
1877
|
+
*
|
|
1878
|
+
* @param options - Retry configuration options
|
|
1879
|
+
* @returns Method decorator
|
|
1880
|
+
*
|
|
1881
|
+
* @example
|
|
1882
|
+
* ```typescript
|
|
1883
|
+
* class MyService {
|
|
1884
|
+
* @retryOnErrors({ statusCodes: [429, 500], maxRetries: 3, delays: [2, 5, 10] })
|
|
1885
|
+
* async createOrder() {
|
|
1886
|
+
* return await this.orderClient.createOrder(...);
|
|
1887
|
+
* }
|
|
1888
|
+
* }
|
|
1889
|
+
* ```
|
|
1890
|
+
*
|
|
1891
|
+
* @public
|
|
1892
|
+
*/
|
|
1893
|
+
declare function retryOnErrors(options?: RetryConfigOptions): (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1894
|
+
/**
|
|
1895
|
+
* Standalone retry function for wrapping async operations.
|
|
1896
|
+
*
|
|
1897
|
+
* @remarks
|
|
1898
|
+
* This function wraps any async operation with retry logic.
|
|
1899
|
+
* More flexible than the decorator approach for one-off retries.
|
|
1900
|
+
*
|
|
1901
|
+
* @param fn - Async function to execute with retry
|
|
1902
|
+
* @param options - Retry configuration options
|
|
1903
|
+
* @param logger - Optional logger for retry information
|
|
1904
|
+
* @returns Promise resolving to the function result
|
|
1905
|
+
*
|
|
1906
|
+
* @example
|
|
1907
|
+
* ```typescript
|
|
1908
|
+
* const result = await withRetry(
|
|
1909
|
+
* async () => await orderClient.createOrder(...),
|
|
1910
|
+
* { statusCodes: [429, 500], maxRetries: 3, delays: [2, 5, 10] }
|
|
1911
|
+
* );
|
|
1912
|
+
* ```
|
|
1913
|
+
*
|
|
1914
|
+
* @public
|
|
1915
|
+
*/
|
|
1916
|
+
declare function withRetry<T>(fn: () => Promise<T>, options?: RetryConfigOptions, logger?: ILogger): Promise<T>;
|
|
1917
|
+
/**
|
|
1918
|
+
* HTTP client wrapper that adds retry logic to all requests.
|
|
1919
|
+
*
|
|
1920
|
+
* @remarks
|
|
1921
|
+
* This class wraps an HttpClient and automatically retries failed requests
|
|
1922
|
+
* based on configured retry settings.
|
|
1923
|
+
*
|
|
1924
|
+
* @example
|
|
1925
|
+
* ```typescript
|
|
1926
|
+
* const httpClient = new HttpClient({ logger });
|
|
1927
|
+
* const retryConfig = new RetryConfig({ statusCodes: [429, 500], maxRetries: 3 });
|
|
1928
|
+
* const retryableClient = new RetryableClient(httpClient, retryConfig);
|
|
1929
|
+
*
|
|
1930
|
+
* // All requests automatically retry on 429, 500
|
|
1931
|
+
* const markets = await retryableClient.get('/markets');
|
|
1932
|
+
* ```
|
|
1933
|
+
*
|
|
1934
|
+
* @public
|
|
1935
|
+
*/
|
|
1936
|
+
declare class RetryableClient {
|
|
1937
|
+
private httpClient;
|
|
1938
|
+
private retryConfig;
|
|
1939
|
+
private logger;
|
|
1940
|
+
/**
|
|
1941
|
+
* Creates a new retryable client wrapper.
|
|
1942
|
+
*
|
|
1943
|
+
* @param httpClient - HTTP client to wrap
|
|
1944
|
+
* @param retryConfig - Retry configuration
|
|
1945
|
+
* @param logger - Optional logger
|
|
1946
|
+
*/
|
|
1947
|
+
constructor(httpClient: any, retryConfig?: RetryConfig, logger?: ILogger);
|
|
1948
|
+
/**
|
|
1949
|
+
* Performs a GET request with retry logic.
|
|
1950
|
+
*
|
|
1951
|
+
* @param url - Request URL
|
|
1952
|
+
* @param config - Additional request configuration
|
|
1953
|
+
* @returns Promise resolving to the response data
|
|
1954
|
+
*/
|
|
1955
|
+
get<T = any>(url: string, config?: any): Promise<T>;
|
|
1956
|
+
/**
|
|
1957
|
+
* Performs a POST request with retry logic.
|
|
1958
|
+
*
|
|
1959
|
+
* @param url - Request URL
|
|
1960
|
+
* @param data - Request body data
|
|
1961
|
+
* @param config - Additional request configuration
|
|
1962
|
+
* @returns Promise resolving to the response data
|
|
1963
|
+
*/
|
|
1964
|
+
post<T = any>(url: string, data?: any, config?: any): Promise<T>;
|
|
1965
|
+
/**
|
|
1966
|
+
* Performs a DELETE request with retry logic.
|
|
1967
|
+
*
|
|
1968
|
+
* @param url - Request URL
|
|
1969
|
+
* @param config - Additional request configuration
|
|
1970
|
+
* @returns Promise resolving to the response data
|
|
1971
|
+
*/
|
|
1972
|
+
delete<T = any>(url: string, config?: any): Promise<T>;
|
|
1973
|
+
/**
|
|
1974
|
+
* Forwards any other method calls to the wrapped HTTP client.
|
|
1975
|
+
*
|
|
1976
|
+
* @param method - Method name
|
|
1977
|
+
*/
|
|
1978
|
+
[key: string]: any;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
/**
|
|
1982
|
+
* Default API endpoints and configuration constants.
|
|
1983
|
+
* @public
|
|
1984
|
+
*/
|
|
1985
|
+
/**
|
|
1986
|
+
* Default Limitless Exchange API URL.
|
|
1987
|
+
* @public
|
|
1988
|
+
*/
|
|
1989
|
+
declare const DEFAULT_API_URL = "https://api.limitless.exchange";
|
|
1990
|
+
/**
|
|
1991
|
+
* Default WebSocket URL for real-time data.
|
|
1992
|
+
* @public
|
|
1993
|
+
*/
|
|
1994
|
+
declare const DEFAULT_WS_URL = "wss://ws.limitless.exchange";
|
|
1995
|
+
/**
|
|
1996
|
+
* Default chain ID (Base mainnet).
|
|
1997
|
+
* @public
|
|
1998
|
+
*/
|
|
1999
|
+
declare const DEFAULT_CHAIN_ID = 8453;
|
|
2000
|
+
/**
|
|
2001
|
+
* Base Sepolia testnet chain ID.
|
|
2002
|
+
* @public
|
|
2003
|
+
*/
|
|
2004
|
+
declare const BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
2005
|
+
/**
|
|
2006
|
+
* Signing message template used by the API.
|
|
2007
|
+
* @internal
|
|
2008
|
+
*/
|
|
2009
|
+
declare const SIGNING_MESSAGE_TEMPLATE = "Welcome to Limitless.exchange! Please sign this message to verify your identity.\n\nNonce: {NONCE}";
|
|
2010
|
+
/**
|
|
2011
|
+
* Zero address constant.
|
|
2012
|
+
* @public
|
|
2013
|
+
*/
|
|
2014
|
+
declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
2015
|
+
/**
|
|
2016
|
+
* Contract addresses by network
|
|
2017
|
+
* @public
|
|
2018
|
+
*/
|
|
2019
|
+
declare const CONTRACT_ADDRESSES: {
|
|
2020
|
+
readonly 8453: {
|
|
2021
|
+
readonly CLOB: "0xa4409D988CA2218d956BeEFD3874100F444f0DC3";
|
|
2022
|
+
readonly NEGRISK: "0x5a38afc17F7E97ad8d6C547ddb837E40B4aEDfC6";
|
|
2023
|
+
};
|
|
2024
|
+
readonly 84532: {
|
|
2025
|
+
readonly CLOB: "0x...";
|
|
2026
|
+
readonly NEGRISK: "0x...";
|
|
2027
|
+
};
|
|
2028
|
+
};
|
|
2029
|
+
/**
|
|
2030
|
+
* Get contract address for a specific market type and chain
|
|
2031
|
+
*
|
|
2032
|
+
* @param marketType - Market type (CLOB or NEGRISK)
|
|
2033
|
+
* @param chainId - Chain ID (default: 8453 for Base mainnet)
|
|
2034
|
+
* @returns Contract address
|
|
2035
|
+
*
|
|
2036
|
+
* @throws Error if contract address not found for chain
|
|
2037
|
+
*
|
|
2038
|
+
* @public
|
|
2039
|
+
*/
|
|
2040
|
+
declare function getContractAddress(marketType: 'CLOB' | 'NEGRISK', chainId?: number): string;
|
|
2041
|
+
|
|
2042
|
+
/**
|
|
2043
|
+
* Order builder for constructing unsigned order payloads.
|
|
2044
|
+
* @module orders/builder
|
|
2045
|
+
*/
|
|
2046
|
+
|
|
2047
|
+
/**
|
|
2048
|
+
* Order builder for constructing unsigned order payloads.
|
|
2049
|
+
*
|
|
2050
|
+
* @remarks
|
|
2051
|
+
* This class handles the construction of unsigned orders matching the
|
|
2052
|
+
* Limitless Exchange API format. It generates unique salts, calculates
|
|
2053
|
+
* maker/taker amounts with proper tick alignment, and validates inputs.
|
|
2054
|
+
*
|
|
2055
|
+
* **Tick Alignment Requirements**:
|
|
2056
|
+
* - Prices must align to tick size (default: 0.001 = 3 decimals)
|
|
2057
|
+
* - Size must produce takerAmount divisible by sharesStep (priceScale / tickInt = 1000 for 0.001 tick)
|
|
2058
|
+
* - SDK validates inputs and throws clear errors rather than auto-rounding
|
|
2059
|
+
* - This ensures `price * contracts` yields whole number collateral
|
|
2060
|
+
*
|
|
2061
|
+
* **Validation Strategy**:
|
|
2062
|
+
* - FAILS FAST: Invalid inputs throw errors with helpful suggestions
|
|
2063
|
+
* - NO AUTO-ROUNDING: Users maintain full control over order amounts
|
|
2064
|
+
* - TRANSPARENCY: Error messages show valid alternatives
|
|
2065
|
+
* - Example: size=22.123896 → Error: "Try 22.123 (rounded down) or 22.124 (rounded up) instead"
|
|
2066
|
+
*
|
|
2067
|
+
* @public
|
|
2068
|
+
*/
|
|
2069
|
+
declare class OrderBuilder {
|
|
2070
|
+
private makerAddress;
|
|
2071
|
+
private feeRateBps;
|
|
2072
|
+
private priceTick;
|
|
2073
|
+
/**
|
|
2074
|
+
* Creates a new order builder instance.
|
|
2075
|
+
*
|
|
2076
|
+
* @param makerAddress - Ethereum address of the order maker
|
|
2077
|
+
* @param feeRateBps - Fee rate in basis points (e.g., 100 = 1%)
|
|
2078
|
+
* @param priceTick - Price tick size (default: 0.001 for 3 decimals)
|
|
2079
|
+
*
|
|
2080
|
+
* @example
|
|
2081
|
+
* ```typescript
|
|
2082
|
+
* const builder = new OrderBuilder(
|
|
2083
|
+
* '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
|
|
2084
|
+
* 300, // 3% fee
|
|
2085
|
+
* 0.001 // 3 decimal price precision
|
|
2086
|
+
* );
|
|
2087
|
+
* ```
|
|
2088
|
+
*/
|
|
2089
|
+
constructor(makerAddress: string, feeRateBps: number, priceTick?: number);
|
|
2090
|
+
/**
|
|
2091
|
+
* Builds an unsigned order payload.
|
|
2092
|
+
*
|
|
2093
|
+
* @param args - Order arguments (FOK or GTC)
|
|
2094
|
+
* @returns Unsigned order ready for signing
|
|
2095
|
+
*
|
|
2096
|
+
* @throws Error if validation fails or tick alignment fails
|
|
2097
|
+
*
|
|
2098
|
+
* @example
|
|
2099
|
+
* ```typescript
|
|
2100
|
+
* // FOK order (market order)
|
|
2101
|
+
* const fokOrder = builder.buildOrder({
|
|
2102
|
+
* tokenId: '123456',
|
|
2103
|
+
* makerAmount: 50, // 50 USDC to spend
|
|
2104
|
+
* side: Side.BUY,
|
|
2105
|
+
* marketType: MarketType.CLOB
|
|
2106
|
+
* });
|
|
2107
|
+
*
|
|
2108
|
+
* // GTC order (price + size)
|
|
2109
|
+
* const gtcOrder = builder.buildOrder({
|
|
2110
|
+
* tokenId: '123456',
|
|
2111
|
+
* price: 0.38,
|
|
2112
|
+
* size: 22.123, // Will be rounded to tick-aligned: 22.123 shares
|
|
2113
|
+
* side: Side.BUY,
|
|
2114
|
+
* marketType: MarketType.CLOB
|
|
2115
|
+
* });
|
|
2116
|
+
* ```
|
|
2117
|
+
*/
|
|
2118
|
+
buildOrder(args: OrderArgs): UnsignedOrder;
|
|
2119
|
+
/**
|
|
2120
|
+
* Type guard to check if order arguments are for FOK order.
|
|
2121
|
+
*
|
|
2122
|
+
* @param args - Order arguments
|
|
2123
|
+
* @returns True if FOK order arguments
|
|
2124
|
+
*
|
|
2125
|
+
* @internal
|
|
2126
|
+
*/
|
|
2127
|
+
private isFOKOrder;
|
|
2128
|
+
/**
|
|
2129
|
+
* Generates a unique salt using timestamp + nano-offset pattern.
|
|
2130
|
+
*
|
|
2131
|
+
* @remarks
|
|
2132
|
+
* This follows the reference implementation pattern:
|
|
2133
|
+
* salt = timestamp * 1000 + nanoOffset + 24h
|
|
2134
|
+
*
|
|
2135
|
+
* This ensures uniqueness even when creating orders rapidly.
|
|
2136
|
+
*
|
|
2137
|
+
* @returns Unique salt value
|
|
2138
|
+
*
|
|
2139
|
+
* @internal
|
|
2140
|
+
*/
|
|
2141
|
+
private generateSalt;
|
|
2142
|
+
/**
|
|
2143
|
+
* Parses decimal string to scaled BigInt.
|
|
2144
|
+
*
|
|
2145
|
+
* @param value - Decimal string (e.g., "0.38")
|
|
2146
|
+
* @param scale - Scale factor (e.g., 1_000_000n for 6 decimals)
|
|
2147
|
+
* @returns Scaled BigInt value
|
|
2148
|
+
*
|
|
2149
|
+
* @internal
|
|
2150
|
+
*/
|
|
2151
|
+
private parseDecToInt;
|
|
2152
|
+
/**
|
|
2153
|
+
* Ceiling division for BigInt.
|
|
2154
|
+
*
|
|
2155
|
+
* @param numerator - Numerator
|
|
2156
|
+
* @param denominator - Denominator
|
|
2157
|
+
* @returns Ceiling of numerator / denominator
|
|
2158
|
+
*
|
|
2159
|
+
* @internal
|
|
2160
|
+
*/
|
|
2161
|
+
private divCeil;
|
|
2162
|
+
/**
|
|
2163
|
+
* Calculates maker and taker amounts for GTC orders with tick alignment validation.
|
|
2164
|
+
*
|
|
2165
|
+
* @remarks
|
|
2166
|
+
* Validates and calculates amounts to ensure:
|
|
2167
|
+
* 1. Price aligns to tick size (e.g., 0.001 for 3 decimals)
|
|
2168
|
+
* 2. Size produces takerAmount divisible by sharesStep
|
|
2169
|
+
* 3. No auto-rounding - fails fast if values are invalid
|
|
2170
|
+
* 4. Transparent error messages guide users to valid values
|
|
2171
|
+
*
|
|
2172
|
+
* **Algorithm**:
|
|
2173
|
+
* - sharesStep = priceScale / tickInt (e.g., 1000 for 0.001 tick)
|
|
2174
|
+
* - Validates shares are divisible by sharesStep
|
|
2175
|
+
* - Calculates collateral from shares × price (ceil for BUY, floor for SELL)
|
|
2176
|
+
* - Assigns maker/taker based on side:
|
|
2177
|
+
* - BUY: maker = collateral, taker = shares
|
|
2178
|
+
* - SELL: maker = shares, taker = collateral
|
|
2179
|
+
* - Throws clear error if size is not tick-aligned
|
|
2180
|
+
*
|
|
2181
|
+
* @param price - Price per share (0.0 to 1.0, max 3 decimals)
|
|
2182
|
+
* @param size - Number of shares (must be tick-aligned)
|
|
2183
|
+
* @param side - Order side (BUY or SELL)
|
|
2184
|
+
* @returns Object with validated makerAmount, takerAmount, and price
|
|
2185
|
+
*
|
|
2186
|
+
* @throws Error if price or size not tick-aligned
|
|
2187
|
+
*
|
|
2188
|
+
* @internal
|
|
2189
|
+
*/
|
|
2190
|
+
private calculateGTCAmountsTickAligned;
|
|
2191
|
+
/**
|
|
2192
|
+
* Calculates maker and taker amounts for FOK (market) orders.
|
|
2193
|
+
*
|
|
2194
|
+
* @remarks
|
|
2195
|
+
* FOK orders use makerAmount for both BUY and SELL:
|
|
2196
|
+
* - BUY: makerAmount = USDC amount to spend (e.g., 50 = $50 USDC)
|
|
2197
|
+
* - SELL: makerAmount = number of shares to sell (e.g., 18.64 shares)
|
|
2198
|
+
*
|
|
2199
|
+
* takerAmount is always 1 (constant for FOK orders)
|
|
2200
|
+
*
|
|
2201
|
+
* @param makerAmount - Amount in human-readable format (max 6 decimals)
|
|
2202
|
+
* @returns Object with makerAmount (scaled), takerAmount (always 1), and undefined price
|
|
2203
|
+
*
|
|
2204
|
+
* @internal
|
|
2205
|
+
*/
|
|
2206
|
+
private calculateFOKAmounts;
|
|
2207
|
+
/**
|
|
2208
|
+
* Validates order arguments.
|
|
2209
|
+
*
|
|
2210
|
+
* @param args - Order arguments to validate
|
|
2211
|
+
* @throws Error if validation fails
|
|
2212
|
+
*
|
|
2213
|
+
* @internal
|
|
2214
|
+
*/
|
|
2215
|
+
private validateOrderArgs;
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
/**
|
|
2219
|
+
* EIP-712 order signer for Limitless Exchange.
|
|
2220
|
+
* @module orders/signer
|
|
2221
|
+
*/
|
|
2222
|
+
|
|
2223
|
+
/**
|
|
2224
|
+
* EIP-712 order signer.
|
|
2225
|
+
*
|
|
2226
|
+
* @remarks
|
|
2227
|
+
* This class handles EIP-712 signing for Limitless Exchange orders.
|
|
2228
|
+
* It creates signatures that match the API's verification requirements.
|
|
2229
|
+
*
|
|
2230
|
+
* Domain: "Limitless CTF Exchange"
|
|
2231
|
+
* Version: "1"
|
|
2232
|
+
*
|
|
2233
|
+
* @public
|
|
2234
|
+
*/
|
|
2235
|
+
declare class OrderSigner {
|
|
2236
|
+
private wallet;
|
|
2237
|
+
private logger;
|
|
2238
|
+
/**
|
|
2239
|
+
* Creates a new order signer instance.
|
|
2240
|
+
*
|
|
2241
|
+
* @param wallet - Ethers wallet for signing
|
|
2242
|
+
* @param logger - Optional logger for debugging (default: no logging)
|
|
2243
|
+
*
|
|
2244
|
+
* @example
|
|
2245
|
+
* ```typescript
|
|
2246
|
+
* import { ethers } from 'ethers';
|
|
2247
|
+
* import { OrderSigner } from '@limitless-exchange/sdk';
|
|
2248
|
+
*
|
|
2249
|
+
* const wallet = new ethers.Wallet(privateKey);
|
|
2250
|
+
* const signer = new OrderSigner(wallet);
|
|
2251
|
+
* ```
|
|
2252
|
+
*/
|
|
2253
|
+
constructor(wallet: ethers.Wallet, logger?: ILogger);
|
|
2254
|
+
/**
|
|
2255
|
+
* Signs an order with EIP-712.
|
|
2256
|
+
*
|
|
2257
|
+
* @param order - Unsigned order to sign
|
|
2258
|
+
* @param config - Signing configuration (chainId, contract address, market type)
|
|
2259
|
+
* @returns Promise resolving to EIP-712 signature
|
|
2260
|
+
*
|
|
2261
|
+
* @throws Error if wallet address doesn't match order signer
|
|
2262
|
+
* @throws Error if signing fails
|
|
2263
|
+
*
|
|
2264
|
+
* @example
|
|
2265
|
+
* ```typescript
|
|
2266
|
+
* const signature = await signer.signOrder(unsignedOrder, {
|
|
2267
|
+
* chainId: 8453,
|
|
2268
|
+
* contractAddress: '0x...',
|
|
2269
|
+
* marketType: MarketType.CLOB
|
|
2270
|
+
* });
|
|
2271
|
+
* ```
|
|
2272
|
+
*/
|
|
2273
|
+
signOrder(order: UnsignedOrder, config: OrderSigningConfig): Promise<string>;
|
|
2274
|
+
/**
|
|
2275
|
+
* Gets the EIP-712 domain for signing.
|
|
2276
|
+
*
|
|
2277
|
+
* @param config - Signing configuration
|
|
2278
|
+
* @returns EIP-712 domain object
|
|
2279
|
+
*
|
|
2280
|
+
* @internal
|
|
2281
|
+
*/
|
|
2282
|
+
private getDomain;
|
|
2283
|
+
/**
|
|
2284
|
+
* Gets the EIP-712 type definitions.
|
|
2285
|
+
*
|
|
2286
|
+
* @remarks
|
|
2287
|
+
* This matches the order structure expected by the Limitless Exchange
|
|
2288
|
+
* smart contracts.
|
|
2289
|
+
*
|
|
2290
|
+
* @returns EIP-712 types definition
|
|
2291
|
+
*
|
|
2292
|
+
* @internal
|
|
2293
|
+
*/
|
|
2294
|
+
private getTypes;
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
/**
|
|
2298
|
+
* Order validation utilities.
|
|
2299
|
+
* @module orders/validator
|
|
2300
|
+
*/
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* Validation error class.
|
|
2304
|
+
* @public
|
|
2305
|
+
*/
|
|
2306
|
+
declare class ValidationError extends Error {
|
|
2307
|
+
constructor(message: string);
|
|
2308
|
+
}
|
|
2309
|
+
/**
|
|
2310
|
+
* Validates order arguments before building.
|
|
2311
|
+
*
|
|
2312
|
+
* @param args - Order arguments to validate (FOK or GTC)
|
|
2313
|
+
* @throws ValidationError if validation fails
|
|
2314
|
+
*
|
|
2315
|
+
* @public
|
|
2316
|
+
*
|
|
2317
|
+
* @example
|
|
2318
|
+
* ```typescript
|
|
2319
|
+
* try {
|
|
2320
|
+
* validateOrderArgs(orderArgs);
|
|
2321
|
+
* } catch (error) {
|
|
2322
|
+
* console.error('Validation failed:', error.message);
|
|
2323
|
+
* }
|
|
2324
|
+
* ```
|
|
2325
|
+
*/
|
|
2326
|
+
declare function validateOrderArgs(args: OrderArgs): void;
|
|
2327
|
+
/**
|
|
2328
|
+
* Validates an unsigned order.
|
|
2329
|
+
*
|
|
2330
|
+
* @param order - Unsigned order to validate
|
|
2331
|
+
* @throws ValidationError if validation fails
|
|
2332
|
+
*
|
|
2333
|
+
* @public
|
|
2334
|
+
*
|
|
2335
|
+
* @example
|
|
2336
|
+
* ```typescript
|
|
2337
|
+
* validateUnsignedOrder(unsignedOrder);
|
|
2338
|
+
* ```
|
|
2339
|
+
*/
|
|
2340
|
+
declare function validateUnsignedOrder(order: UnsignedOrder): void;
|
|
2341
|
+
/**
|
|
2342
|
+
* Validates a signed order.
|
|
2343
|
+
*
|
|
2344
|
+
* @param order - Signed order to validate
|
|
2345
|
+
* @throws ValidationError if validation fails
|
|
2346
|
+
*
|
|
2347
|
+
* @public
|
|
2348
|
+
*
|
|
2349
|
+
* @example
|
|
2350
|
+
* ```typescript
|
|
2351
|
+
* validateSignedOrder(signedOrder);
|
|
2352
|
+
* ```
|
|
2353
|
+
*/
|
|
2354
|
+
declare function validateSignedOrder(order: SignedOrder): void;
|
|
2355
|
+
|
|
2356
|
+
/**
|
|
2357
|
+
* Order client for managing orders on Limitless Exchange.
|
|
2358
|
+
* @module orders/client
|
|
2359
|
+
*/
|
|
2360
|
+
|
|
2361
|
+
/**
|
|
2362
|
+
* Configuration for the order client.
|
|
2363
|
+
*
|
|
2364
|
+
* @remarks
|
|
2365
|
+
* The order client supports two configuration modes:
|
|
2366
|
+
* 1. Simple mode: Provide userData and marketType (auto-configures signing)
|
|
2367
|
+
* 2. Advanced mode: Provide userData and custom signingConfig
|
|
2368
|
+
*
|
|
2369
|
+
* @public
|
|
2370
|
+
*/
|
|
2371
|
+
interface OrderClientConfig {
|
|
2372
|
+
/**
|
|
2373
|
+
* HTTP client for API requests
|
|
2374
|
+
*/
|
|
2375
|
+
httpClient: HttpClient;
|
|
2376
|
+
/**
|
|
2377
|
+
* Wallet for signing orders
|
|
2378
|
+
*/
|
|
2379
|
+
wallet: ethers.Wallet;
|
|
2380
|
+
/**
|
|
2381
|
+
* User data containing userId and feeRateBps
|
|
2382
|
+
*
|
|
2383
|
+
* @example
|
|
2384
|
+
* ```typescript
|
|
2385
|
+
* {
|
|
2386
|
+
* userId: 123, // From auth result
|
|
2387
|
+
* feeRateBps: 300 // User's fee rate (3%)
|
|
2388
|
+
* }
|
|
2389
|
+
* ```
|
|
2390
|
+
*/
|
|
2391
|
+
userData: UserData;
|
|
2392
|
+
/**
|
|
2393
|
+
* Market type for auto-configuration (optional if signingConfig provided)
|
|
2394
|
+
*
|
|
2395
|
+
* @remarks
|
|
2396
|
+
* When provided without signingConfig, automatically loads contract address
|
|
2397
|
+
* from environment variables or SDK defaults.
|
|
2398
|
+
*
|
|
2399
|
+
* @defaultValue MarketType.CLOB
|
|
2400
|
+
*/
|
|
2401
|
+
marketType?: MarketType;
|
|
2402
|
+
/**
|
|
2403
|
+
* Custom signing configuration (optional)
|
|
2404
|
+
*
|
|
2405
|
+
* @remarks
|
|
2406
|
+
* If not provided, SDK will auto-configure based on marketType.
|
|
2407
|
+
* Useful for custom deployments or testing.
|
|
2408
|
+
*/
|
|
2409
|
+
signingConfig?: OrderSigningConfig;
|
|
2410
|
+
/**
|
|
2411
|
+
* Optional logger
|
|
2412
|
+
*/
|
|
2413
|
+
logger?: ILogger;
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2416
|
+
* Order client for creating and managing orders.
|
|
2417
|
+
*
|
|
2418
|
+
* @remarks
|
|
2419
|
+
* This class provides high-level methods for order operations,
|
|
2420
|
+
* abstracting away HTTP details and order signing complexity.
|
|
2421
|
+
*
|
|
2422
|
+
* @example
|
|
2423
|
+
* ```typescript
|
|
2424
|
+
* const orderClient = new OrderClient({
|
|
2425
|
+
* httpClient,
|
|
2426
|
+
* wallet,
|
|
2427
|
+
* ownerId: 123,
|
|
2428
|
+
* feeRateBps: 100,
|
|
2429
|
+
* signingConfig: {
|
|
2430
|
+
* chainId: 8453,
|
|
2431
|
+
* contractAddress: '0x...',
|
|
2432
|
+
* marketType: MarketType.CLOB
|
|
2433
|
+
* }
|
|
2434
|
+
* });
|
|
2435
|
+
*
|
|
2436
|
+
* const order = await orderClient.createOrder({
|
|
2437
|
+
* tokenId: '123...',
|
|
2438
|
+
* price: 0.65,
|
|
2439
|
+
* size: 100,
|
|
2440
|
+
* side: Side.BUY,
|
|
2441
|
+
* orderType: OrderType.GTC,
|
|
2442
|
+
* marketSlug: 'market-slug'
|
|
2443
|
+
* });
|
|
2444
|
+
* ```
|
|
2445
|
+
*
|
|
2446
|
+
* @public
|
|
2447
|
+
*/
|
|
2448
|
+
declare class OrderClient {
|
|
2449
|
+
private httpClient;
|
|
2450
|
+
private orderBuilder;
|
|
2451
|
+
private orderSigner;
|
|
2452
|
+
private ownerId;
|
|
2453
|
+
private signingConfig;
|
|
2454
|
+
private logger;
|
|
2455
|
+
/**
|
|
2456
|
+
* Creates a new order client instance.
|
|
2457
|
+
*
|
|
2458
|
+
* @param config - Order client configuration
|
|
2459
|
+
*
|
|
2460
|
+
* @throws Error if neither marketType nor signingConfig is provided
|
|
2461
|
+
*/
|
|
2462
|
+
constructor(config: OrderClientConfig);
|
|
2463
|
+
/**
|
|
2464
|
+
* Creates and submits a new order.
|
|
2465
|
+
*
|
|
2466
|
+
* @remarks
|
|
2467
|
+
* This method handles the complete order creation flow:
|
|
2468
|
+
* 1. Build unsigned order
|
|
2469
|
+
* 2. Sign with EIP-712
|
|
2470
|
+
* 3. Submit to API
|
|
2471
|
+
*
|
|
2472
|
+
* @param params - Order parameters
|
|
2473
|
+
* @returns Promise resolving to order response
|
|
2474
|
+
*
|
|
2475
|
+
* @throws Error if order creation fails
|
|
2476
|
+
*
|
|
2477
|
+
* @example
|
|
2478
|
+
* ```typescript
|
|
2479
|
+
* const order = await orderClient.createOrder({
|
|
2480
|
+
* tokenId: '123456',
|
|
2481
|
+
* price: 0.65,
|
|
2482
|
+
* size: 100,
|
|
2483
|
+
* side: Side.BUY,
|
|
2484
|
+
* orderType: OrderType.GTC,
|
|
2485
|
+
* marketSlug: 'market-slug'
|
|
2486
|
+
* });
|
|
2487
|
+
*
|
|
2488
|
+
* console.log(`Order created: ${order.order.id}`);
|
|
2489
|
+
* ```
|
|
2490
|
+
*/
|
|
2491
|
+
createOrder(params: OrderArgs & {
|
|
2492
|
+
orderType: OrderType;
|
|
2493
|
+
marketSlug: string;
|
|
2494
|
+
}): Promise<OrderResponse>;
|
|
2495
|
+
/**
|
|
2496
|
+
* Transforms raw API response to clean OrderResponse DTO.
|
|
2497
|
+
*
|
|
2498
|
+
* @param apiResponse - Raw API response with nested objects
|
|
2499
|
+
* @returns Clean OrderResponse with only essential fields
|
|
2500
|
+
*
|
|
2501
|
+
* @internal
|
|
2502
|
+
*/
|
|
2503
|
+
private transformOrderResponse;
|
|
2504
|
+
/**
|
|
2505
|
+
* Cancels an existing order by ID.
|
|
2506
|
+
*
|
|
2507
|
+
* @param orderId - Order ID to cancel
|
|
2508
|
+
* @returns Promise resolving to cancellation message
|
|
2509
|
+
*
|
|
2510
|
+
* @throws Error if cancellation fails
|
|
2511
|
+
*
|
|
2512
|
+
* @example
|
|
2513
|
+
* ```typescript
|
|
2514
|
+
* const result = await orderClient.cancel('order-id-123');
|
|
2515
|
+
* console.log(result.message); // "Order canceled successfully"
|
|
2516
|
+
* ```
|
|
2517
|
+
*/
|
|
2518
|
+
cancel(orderId: string): Promise<{
|
|
2519
|
+
message: string;
|
|
2520
|
+
}>;
|
|
2521
|
+
/**
|
|
2522
|
+
* Cancels all orders for a specific market.
|
|
2523
|
+
*
|
|
2524
|
+
* @param marketSlug - Market slug to cancel all orders for
|
|
2525
|
+
* @returns Promise resolving to cancellation message
|
|
2526
|
+
*
|
|
2527
|
+
* @throws Error if cancellation fails
|
|
2528
|
+
*
|
|
2529
|
+
* @example
|
|
2530
|
+
* ```typescript
|
|
2531
|
+
* const result = await orderClient.cancelAll('market-slug-123');
|
|
2532
|
+
* console.log(result.message); // "Orders canceled successfully"
|
|
2533
|
+
* ```
|
|
2534
|
+
*/
|
|
2535
|
+
cancelAll(marketSlug: string): Promise<{
|
|
2536
|
+
message: string;
|
|
2537
|
+
}>;
|
|
2538
|
+
/**
|
|
2539
|
+
* @deprecated Use `cancel()` instead
|
|
2540
|
+
*/
|
|
2541
|
+
cancelOrder(orderId: string): Promise<void>;
|
|
2542
|
+
/**
|
|
2543
|
+
* Gets an order by ID.
|
|
2544
|
+
*
|
|
2545
|
+
* @param orderId - Order ID to fetch
|
|
2546
|
+
* @returns Promise resolving to order details
|
|
2547
|
+
*
|
|
2548
|
+
* @throws Error if order not found
|
|
2549
|
+
*
|
|
2550
|
+
* @example
|
|
2551
|
+
* ```typescript
|
|
2552
|
+
* const order = await orderClient.getOrder('order-id-123');
|
|
2553
|
+
* console.log(order.order.side);
|
|
2554
|
+
* ```
|
|
2555
|
+
*/
|
|
2556
|
+
getOrder(orderId: string): Promise<OrderResponse>;
|
|
2557
|
+
/**
|
|
2558
|
+
* Builds an unsigned order without submitting.
|
|
2559
|
+
*
|
|
2560
|
+
* @remarks
|
|
2561
|
+
* Useful for advanced use cases where you need the unsigned order
|
|
2562
|
+
* before signing and submission.
|
|
2563
|
+
*
|
|
2564
|
+
* @param params - Order parameters
|
|
2565
|
+
* @returns Unsigned order
|
|
2566
|
+
*
|
|
2567
|
+
* @example
|
|
2568
|
+
* ```typescript
|
|
2569
|
+
* const unsignedOrder = orderClient.buildUnsignedOrder({
|
|
2570
|
+
* tokenId: '123456',
|
|
2571
|
+
* price: 0.65,
|
|
2572
|
+
* size: 100,
|
|
2573
|
+
* side: Side.BUY
|
|
2574
|
+
* });
|
|
2575
|
+
* ```
|
|
2576
|
+
*/
|
|
2577
|
+
buildUnsignedOrder(params: OrderArgs): UnsignedOrder;
|
|
2578
|
+
/**
|
|
2579
|
+
* Signs an unsigned order without submitting.
|
|
2580
|
+
*
|
|
2581
|
+
* @remarks
|
|
2582
|
+
* Useful for advanced use cases where you need to inspect
|
|
2583
|
+
* the signature before submission.
|
|
2584
|
+
*
|
|
2585
|
+
* @param order - Unsigned order to sign
|
|
2586
|
+
* @returns Promise resolving to signature
|
|
2587
|
+
*
|
|
2588
|
+
* @example
|
|
2589
|
+
* ```typescript
|
|
2590
|
+
* const signature = await orderClient.signOrder(unsignedOrder);
|
|
2591
|
+
* ```
|
|
2592
|
+
*/
|
|
2593
|
+
signOrder(order: UnsignedOrder): Promise<string>;
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
/**
|
|
2597
|
+
* Market data fetcher for Limitless Exchange.
|
|
2598
|
+
* @module markets/fetcher
|
|
2599
|
+
*/
|
|
2600
|
+
|
|
2601
|
+
/**
|
|
2602
|
+
* Market data fetcher for retrieving market information and orderbooks.
|
|
2603
|
+
*
|
|
2604
|
+
* @remarks
|
|
2605
|
+
* This class provides methods to fetch market data, orderbooks, and prices
|
|
2606
|
+
* from the Limitless Exchange API.
|
|
2607
|
+
*
|
|
2608
|
+
* @public
|
|
2609
|
+
*/
|
|
2610
|
+
declare class MarketFetcher {
|
|
2611
|
+
private httpClient;
|
|
2612
|
+
private logger;
|
|
2613
|
+
/**
|
|
2614
|
+
* Creates a new market fetcher instance.
|
|
2615
|
+
*
|
|
2616
|
+
* @param httpClient - HTTP client for API requests
|
|
2617
|
+
* @param logger - Optional logger for debugging (default: no logging)
|
|
2618
|
+
*
|
|
2619
|
+
* @example
|
|
2620
|
+
* ```typescript
|
|
2621
|
+
* const fetcher = new MarketFetcher(httpClient);
|
|
2622
|
+
* ```
|
|
2623
|
+
*/
|
|
2624
|
+
constructor(httpClient: HttpClient, logger?: ILogger);
|
|
2625
|
+
/**
|
|
2626
|
+
* Gets active markets with query parameters and pagination support.
|
|
2627
|
+
*
|
|
2628
|
+
* @param params - Query parameters for filtering and pagination
|
|
2629
|
+
* @returns Promise resolving to active markets response
|
|
2630
|
+
* @throws Error if API request fails
|
|
2631
|
+
*
|
|
2632
|
+
* @example
|
|
2633
|
+
* ```typescript
|
|
2634
|
+
* // Get 8 markets sorted by LP rewards
|
|
2635
|
+
* const response = await fetcher.getActiveMarkets({
|
|
2636
|
+
* limit: 8,
|
|
2637
|
+
* sortBy: 'lp_rewards'
|
|
2638
|
+
* });
|
|
2639
|
+
* console.log(`Found ${response.data.length} of ${response.totalMarketsCount} markets`);
|
|
2640
|
+
*
|
|
2641
|
+
* // Get page 2
|
|
2642
|
+
* const page2 = await fetcher.getActiveMarkets({
|
|
2643
|
+
* limit: 8,
|
|
2644
|
+
* page: 2,
|
|
2645
|
+
* sortBy: 'ending_soon'
|
|
2646
|
+
* });
|
|
2647
|
+
* ```
|
|
2648
|
+
*/
|
|
2649
|
+
getActiveMarkets(params?: ActiveMarketsParams): Promise<ActiveMarketsResponse>;
|
|
2650
|
+
/**
|
|
2651
|
+
* Gets a single market by slug.
|
|
2652
|
+
*
|
|
2653
|
+
* @param slug - Market slug identifier
|
|
2654
|
+
* @returns Promise resolving to market details
|
|
2655
|
+
* @throws Error if API request fails or market not found
|
|
2656
|
+
*
|
|
2657
|
+
* @example
|
|
2658
|
+
* ```typescript
|
|
2659
|
+
* const market = await fetcher.getMarket('bitcoin-price-2024');
|
|
2660
|
+
* console.log(`Market: ${market.title}`);
|
|
2661
|
+
* ```
|
|
2662
|
+
*/
|
|
2663
|
+
getMarket(slug: string): Promise<Market>;
|
|
2664
|
+
/**
|
|
2665
|
+
* Gets the orderbook for a CLOB market.
|
|
2666
|
+
*
|
|
2667
|
+
* @param slug - Market slug identifier
|
|
2668
|
+
* @returns Promise resolving to orderbook data
|
|
2669
|
+
* @throws Error if API request fails
|
|
2670
|
+
*
|
|
2671
|
+
* @example
|
|
2672
|
+
* ```typescript
|
|
2673
|
+
* const orderbook = await fetcher.getOrderBook('bitcoin-price-2024');
|
|
2674
|
+
* console.log(`Bids: ${orderbook.bids.length}, Asks: ${orderbook.asks.length}`);
|
|
2675
|
+
* ```
|
|
2676
|
+
*/
|
|
2677
|
+
getOrderBook(slug: string): Promise<OrderBook>;
|
|
2678
|
+
/**
|
|
2679
|
+
* Gets the current price for a token.
|
|
2680
|
+
*
|
|
2681
|
+
* @param tokenId - Token ID
|
|
2682
|
+
* @returns Promise resolving to price information
|
|
2683
|
+
* @throws Error if API request fails
|
|
2684
|
+
*
|
|
2685
|
+
* @example
|
|
2686
|
+
* ```typescript
|
|
2687
|
+
* const price = await fetcher.getPrice('123456');
|
|
2688
|
+
* console.log(`Current price: ${price.price}`);
|
|
2689
|
+
* ```
|
|
2690
|
+
*/
|
|
2691
|
+
getPrice(tokenId: string): Promise<MarketPrice>;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
/**
|
|
2695
|
+
* Portfolio data fetcher for Limitless Exchange.
|
|
2696
|
+
* @module portfolio/fetcher
|
|
2697
|
+
*/
|
|
2698
|
+
|
|
2699
|
+
/**
|
|
2700
|
+
* Portfolio data fetcher for retrieving user positions and portfolio information.
|
|
2701
|
+
*
|
|
2702
|
+
* @remarks
|
|
2703
|
+
* This class provides methods to fetch user positions and calculate portfolio statistics
|
|
2704
|
+
* from the Limitless Exchange API. Requires an authenticated HttpClient.
|
|
2705
|
+
*
|
|
2706
|
+
* @public
|
|
2707
|
+
*/
|
|
2708
|
+
declare class PortfolioFetcher {
|
|
2709
|
+
private httpClient;
|
|
2710
|
+
private logger;
|
|
2711
|
+
/**
|
|
2712
|
+
* Creates a new portfolio fetcher instance.
|
|
2713
|
+
*
|
|
2714
|
+
* @param httpClient - Authenticated HTTP client for API requests
|
|
2715
|
+
* @param logger - Optional logger for debugging (default: no logging)
|
|
2716
|
+
*
|
|
2717
|
+
* @example
|
|
2718
|
+
* ```typescript
|
|
2719
|
+
* // Create authenticated client
|
|
2720
|
+
* const httpClient = new HttpClient({ baseURL: API_URL });
|
|
2721
|
+
* await authenticator.authenticate({ client: 'eoa' });
|
|
2722
|
+
*
|
|
2723
|
+
* // Create portfolio fetcher
|
|
2724
|
+
* const portfolioFetcher = new PortfolioFetcher(httpClient);
|
|
2725
|
+
* ```
|
|
2726
|
+
*/
|
|
2727
|
+
constructor(httpClient: HttpClient, logger?: ILogger);
|
|
2728
|
+
/**
|
|
2729
|
+
* Gets raw portfolio positions response from API.
|
|
2730
|
+
*
|
|
2731
|
+
* @returns Promise resolving to portfolio positions response with CLOB and AMM positions
|
|
2732
|
+
* @throws Error if API request fails or user is not authenticated
|
|
2733
|
+
*
|
|
2734
|
+
* @example
|
|
2735
|
+
* ```typescript
|
|
2736
|
+
* const response = await portfolioFetcher.getPositions();
|
|
2737
|
+
* console.log(`CLOB positions: ${response.clob.length}`);
|
|
2738
|
+
* console.log(`AMM positions: ${response.amm.length}`);
|
|
2739
|
+
* console.log(`Total points: ${response.accumulativePoints}`);
|
|
2740
|
+
* ```
|
|
2741
|
+
*/
|
|
2742
|
+
getPositions(): Promise<PortfolioPositionsResponse>;
|
|
2743
|
+
/**
|
|
2744
|
+
* Gets CLOB positions only.
|
|
2745
|
+
*
|
|
2746
|
+
* @returns Promise resolving to array of CLOB positions
|
|
2747
|
+
* @throws Error if API request fails
|
|
2748
|
+
*
|
|
2749
|
+
* @example
|
|
2750
|
+
* ```typescript
|
|
2751
|
+
* const clobPositions = await portfolioFetcher.getCLOBPositions();
|
|
2752
|
+
* clobPositions.forEach(pos => {
|
|
2753
|
+
* console.log(`${pos.market.title}: YES ${pos.positions.yes.unrealizedPnl} P&L`);
|
|
2754
|
+
* });
|
|
2755
|
+
* ```
|
|
2756
|
+
*/
|
|
2757
|
+
getCLOBPositions(): Promise<CLOBPosition[]>;
|
|
2758
|
+
/**
|
|
2759
|
+
* Gets AMM positions only.
|
|
2760
|
+
*
|
|
2761
|
+
* @returns Promise resolving to array of AMM positions
|
|
2762
|
+
* @throws Error if API request fails
|
|
2763
|
+
*
|
|
2764
|
+
* @example
|
|
2765
|
+
* ```typescript
|
|
2766
|
+
* const ammPositions = await portfolioFetcher.getAMMPositions();
|
|
2767
|
+
* ammPositions.forEach(pos => {
|
|
2768
|
+
* console.log(`${pos.market.title}: ${pos.unrealizedPnl} P&L`);
|
|
2769
|
+
* });
|
|
2770
|
+
* ```
|
|
2771
|
+
*/
|
|
2772
|
+
getAMMPositions(): Promise<AMMPosition[]>;
|
|
2773
|
+
/**
|
|
2774
|
+
* Flattens positions into a unified format for easier consumption.
|
|
2775
|
+
*
|
|
2776
|
+
* @remarks
|
|
2777
|
+
* Converts CLOB positions (which have YES/NO sides) and AMM positions
|
|
2778
|
+
* into a unified Position array. Only includes positions with non-zero values.
|
|
2779
|
+
*
|
|
2780
|
+
* @returns Promise resolving to array of flattened positions
|
|
2781
|
+
* @throws Error if API request fails
|
|
2782
|
+
*
|
|
2783
|
+
* @example
|
|
2784
|
+
* ```typescript
|
|
2785
|
+
* const positions = await portfolioFetcher.getFlattenedPositions();
|
|
2786
|
+
* positions.forEach(pos => {
|
|
2787
|
+
* const pnlPercent = (pos.unrealizedPnl / pos.costBasis) * 100;
|
|
2788
|
+
* console.log(`${pos.market.title} (${pos.side}): ${pnlPercent.toFixed(2)}% P&L`);
|
|
2789
|
+
* });
|
|
2790
|
+
* ```
|
|
2791
|
+
*/
|
|
2792
|
+
getFlattenedPositions(): Promise<Position[]>;
|
|
2793
|
+
/**
|
|
2794
|
+
* Calculates portfolio summary statistics from raw API response.
|
|
2795
|
+
*
|
|
2796
|
+
* @param response - Portfolio positions response from API
|
|
2797
|
+
* @returns Portfolio summary with totals and statistics
|
|
2798
|
+
*
|
|
2799
|
+
* @example
|
|
2800
|
+
* ```typescript
|
|
2801
|
+
* const response = await portfolioFetcher.getPositions();
|
|
2802
|
+
* const summary = portfolioFetcher.calculateSummary(response);
|
|
2803
|
+
*
|
|
2804
|
+
* console.log(`Total Portfolio Value: $${(summary.totalValue / 1e6).toFixed(2)}`);
|
|
2805
|
+
* console.log(`Total P&L: ${summary.totalUnrealizedPnlPercent.toFixed(2)}%`);
|
|
2806
|
+
* console.log(`CLOB Positions: ${summary.breakdown.clob.positions}`);
|
|
2807
|
+
* console.log(`AMM Positions: ${summary.breakdown.amm.positions}`);
|
|
2808
|
+
* ```
|
|
2809
|
+
*/
|
|
2810
|
+
calculateSummary(response: PortfolioPositionsResponse): PortfolioSummary;
|
|
2811
|
+
/**
|
|
2812
|
+
* Gets positions and calculates summary in a single call.
|
|
2813
|
+
*
|
|
2814
|
+
* @returns Promise resolving to response and summary
|
|
2815
|
+
* @throws Error if API request fails or user is not authenticated
|
|
2816
|
+
*
|
|
2817
|
+
* @example
|
|
2818
|
+
* ```typescript
|
|
2819
|
+
* const { response, summary } = await portfolioFetcher.getPortfolio();
|
|
2820
|
+
*
|
|
2821
|
+
* console.log('Portfolio Summary:');
|
|
2822
|
+
* console.log(` Total Value: $${(summary.totalValue / 1e6).toFixed(2)}`);
|
|
2823
|
+
* console.log(` Total P&L: $${(summary.totalUnrealizedPnl / 1e6).toFixed(2)}`);
|
|
2824
|
+
* console.log(` P&L %: ${summary.totalUnrealizedPnlPercent.toFixed(2)}%`);
|
|
2825
|
+
* console.log(`\nCLOB Positions: ${response.clob.length}`);
|
|
2826
|
+
* console.log(`AMM Positions: ${response.amm.length}`);
|
|
2827
|
+
* ```
|
|
2828
|
+
*/
|
|
2829
|
+
getPortfolio(): Promise<{
|
|
2830
|
+
response: PortfolioPositionsResponse;
|
|
2831
|
+
summary: PortfolioSummary;
|
|
2832
|
+
}>;
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
/**
|
|
2836
|
+
* WebSocket client for real-time data streaming.
|
|
2837
|
+
* @module websocket/client
|
|
2838
|
+
*/
|
|
2839
|
+
|
|
2840
|
+
/**
|
|
2841
|
+
* WebSocket client for real-time data streaming from Limitless Exchange.
|
|
2842
|
+
*
|
|
2843
|
+
* @remarks
|
|
2844
|
+
* This client uses Socket.IO to connect to the WebSocket server and provides
|
|
2845
|
+
* typed event subscriptions for orderbook, trades, orders, and market data.
|
|
2846
|
+
*
|
|
2847
|
+
* @example
|
|
2848
|
+
* ```typescript
|
|
2849
|
+
* // Create client
|
|
2850
|
+
* const wsClient = new WebSocketClient({
|
|
2851
|
+
* sessionCookie: 'your-session-cookie',
|
|
2852
|
+
* autoReconnect: true,
|
|
2853
|
+
* });
|
|
2854
|
+
*
|
|
2855
|
+
* // Subscribe to orderbook updates
|
|
2856
|
+
* wsClient.on('orderbook', (data) => {
|
|
2857
|
+
* console.log('Orderbook update:', data);
|
|
2858
|
+
* });
|
|
2859
|
+
*
|
|
2860
|
+
* // Connect and subscribe
|
|
2861
|
+
* await wsClient.connect();
|
|
2862
|
+
* await wsClient.subscribe('orderbook', { marketSlug: 'market-123' });
|
|
2863
|
+
* ```
|
|
2864
|
+
*
|
|
2865
|
+
* @public
|
|
2866
|
+
*/
|
|
2867
|
+
declare class WebSocketClient {
|
|
2868
|
+
private socket;
|
|
2869
|
+
private config;
|
|
2870
|
+
private logger;
|
|
2871
|
+
private state;
|
|
2872
|
+
private reconnectAttempts;
|
|
2873
|
+
private subscriptions;
|
|
2874
|
+
private pendingListeners;
|
|
2875
|
+
/**
|
|
2876
|
+
* Creates a new WebSocket client.
|
|
2877
|
+
*
|
|
2878
|
+
* @param config - WebSocket configuration
|
|
2879
|
+
* @param logger - Optional logger for debugging
|
|
2880
|
+
*/
|
|
2881
|
+
constructor(config?: WebSocketConfig, logger?: ILogger);
|
|
2882
|
+
/**
|
|
2883
|
+
* Gets current connection state.
|
|
2884
|
+
*
|
|
2885
|
+
* @returns Current WebSocket state
|
|
2886
|
+
*/
|
|
2887
|
+
getState(): WebSocketState;
|
|
2888
|
+
/**
|
|
2889
|
+
* Checks if client is connected.
|
|
2890
|
+
*
|
|
2891
|
+
* @returns True if connected
|
|
2892
|
+
*/
|
|
2893
|
+
isConnected(): boolean;
|
|
2894
|
+
/**
|
|
2895
|
+
* Sets the session cookie for authentication.
|
|
2896
|
+
*
|
|
2897
|
+
* @param sessionCookie - Session cookie value
|
|
2898
|
+
*/
|
|
2899
|
+
setSessionCookie(sessionCookie: string): void;
|
|
2900
|
+
/**
|
|
2901
|
+
* Connects to the WebSocket server.
|
|
2902
|
+
*
|
|
2903
|
+
* @returns Promise that resolves when connected
|
|
2904
|
+
* @throws Error if connection fails
|
|
2905
|
+
*
|
|
2906
|
+
* @example
|
|
2907
|
+
* ```typescript
|
|
2908
|
+
* await wsClient.connect();
|
|
2909
|
+
* console.log('Connected!');
|
|
2910
|
+
* ```
|
|
2911
|
+
*/
|
|
2912
|
+
connect(): Promise<void>;
|
|
2913
|
+
/**
|
|
2914
|
+
* Disconnects from the WebSocket server.
|
|
2915
|
+
*
|
|
2916
|
+
* @example
|
|
2917
|
+
* ```typescript
|
|
2918
|
+
* wsClient.disconnect();
|
|
2919
|
+
* ```
|
|
2920
|
+
*/
|
|
2921
|
+
disconnect(): void;
|
|
2922
|
+
/**
|
|
2923
|
+
* Subscribes to a channel.
|
|
2924
|
+
*
|
|
2925
|
+
* @param channel - Channel to subscribe to
|
|
2926
|
+
* @param options - Subscription options
|
|
2927
|
+
* @returns Promise that resolves when subscribed
|
|
2928
|
+
* @throws Error if not connected
|
|
2929
|
+
*
|
|
2930
|
+
* @example
|
|
2931
|
+
* ```typescript
|
|
2932
|
+
* // Subscribe to orderbook for a specific market
|
|
2933
|
+
* await wsClient.subscribe('orderbook', { marketSlug: 'market-123' });
|
|
2934
|
+
*
|
|
2935
|
+
* // Subscribe to all trades
|
|
2936
|
+
* await wsClient.subscribe('trades');
|
|
2937
|
+
*
|
|
2938
|
+
* // Subscribe to your orders
|
|
2939
|
+
* await wsClient.subscribe('orders');
|
|
2940
|
+
* ```
|
|
2941
|
+
*/
|
|
2942
|
+
subscribe(channel: SubscriptionChannel, options?: SubscriptionOptions): Promise<void>;
|
|
2943
|
+
/**
|
|
2944
|
+
* Unsubscribes from a channel.
|
|
2945
|
+
*
|
|
2946
|
+
* @param channel - Channel to unsubscribe from
|
|
2947
|
+
* @param options - Subscription options (must match subscribe call)
|
|
2948
|
+
* @returns Promise that resolves when unsubscribed
|
|
2949
|
+
*
|
|
2950
|
+
* @example
|
|
2951
|
+
* ```typescript
|
|
2952
|
+
* await wsClient.unsubscribe('orderbook', { marketSlug: 'market-123' });
|
|
2953
|
+
* ```
|
|
2954
|
+
*/
|
|
2955
|
+
unsubscribe(channel: SubscriptionChannel, options?: SubscriptionOptions): Promise<void>;
|
|
2956
|
+
/**
|
|
2957
|
+
* Registers an event listener.
|
|
2958
|
+
*
|
|
2959
|
+
* @param event - Event name
|
|
2960
|
+
* @param handler - Event handler
|
|
2961
|
+
* @returns This client for chaining
|
|
2962
|
+
*
|
|
2963
|
+
* @example
|
|
2964
|
+
* ```typescript
|
|
2965
|
+
* wsClient
|
|
2966
|
+
* .on('orderbook', (data) => console.log('Orderbook:', data))
|
|
2967
|
+
* .on('trade', (data) => console.log('Trade:', data))
|
|
2968
|
+
* .on('error', (error) => console.error('Error:', error));
|
|
2969
|
+
* ```
|
|
2970
|
+
*/
|
|
2971
|
+
on<K extends keyof WebSocketEvents>(event: K, handler: WebSocketEvents[K]): this;
|
|
2972
|
+
/**
|
|
2973
|
+
* Registers a one-time event listener.
|
|
2974
|
+
*
|
|
2975
|
+
* @param event - Event name
|
|
2976
|
+
* @param handler - Event handler
|
|
2977
|
+
* @returns This client for chaining
|
|
2978
|
+
*/
|
|
2979
|
+
once<K extends keyof WebSocketEvents>(event: K, handler: WebSocketEvents[K]): this;
|
|
2980
|
+
/**
|
|
2981
|
+
* Removes an event listener.
|
|
2982
|
+
*
|
|
2983
|
+
* @param event - Event name
|
|
2984
|
+
* @param handler - Event handler to remove
|
|
2985
|
+
* @returns This client for chaining
|
|
2986
|
+
*/
|
|
2987
|
+
off<K extends keyof WebSocketEvents>(event: K, handler: WebSocketEvents[K]): this;
|
|
2988
|
+
/**
|
|
2989
|
+
* Attach any pending event listeners that were added before connect().
|
|
2990
|
+
* @internal
|
|
2991
|
+
*/
|
|
2992
|
+
private attachPendingListeners;
|
|
2993
|
+
/**
|
|
2994
|
+
* Setup internal event handlers for connection management.
|
|
2995
|
+
* @internal
|
|
2996
|
+
*/
|
|
2997
|
+
private setupEventHandlers;
|
|
2998
|
+
/**
|
|
2999
|
+
* Re-subscribes to all previous subscriptions after reconnection.
|
|
3000
|
+
* @internal
|
|
3001
|
+
*/
|
|
3002
|
+
private resubscribeAll;
|
|
3003
|
+
/**
|
|
3004
|
+
* Creates a unique subscription key.
|
|
3005
|
+
* @internal
|
|
3006
|
+
*/
|
|
3007
|
+
private getSubscriptionKey;
|
|
3008
|
+
/**
|
|
3009
|
+
* Extracts channel from subscription key.
|
|
3010
|
+
* @internal
|
|
3011
|
+
*/
|
|
3012
|
+
private getChannelFromKey;
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
export { type AMMPosition, APIError, type ActiveMarketsParams, type ActiveMarketsResponse, type ActiveMarketsSortBy, type AuthResult, AuthenticatedClient, type AuthenticatedClientConfig, Authenticator, BASE_SEPOLIA_CHAIN_ID, type BaseOrderArgs, type CLOBPosition, CONTRACT_ADDRESSES, type ClientType, ConsoleLogger, type CreatedOrder, DEFAULT_API_URL, DEFAULT_CHAIN_ID, DEFAULT_WS_URL, type FOKOrderArgs, type FillEvent, type GTCOrderArgs, HttpClient, type HttpClientConfig, type ILogger, type LatestTrade, type LoginOptions, type Market, MarketFetcher, type MarketOutcome, type MarketPrice, MarketType, type MarketUpdate, type MarketsResponse, MessageSigner, type ModeInfo, type NewOrderPayload, NoOpLogger, type OrderArgs, type OrderBook, OrderBuilder, OrderClient, type OrderClientConfig, type OrderMatch, type OrderResponse, OrderSigner, type OrderSigningConfig, OrderType, type OrderUpdate, type OrderbookEntry, type OrderbookUpdate, PortfolioFetcher, type PortfolioPositionsResponse, type PortfolioSummary, type Position, type PositionMarket, type PositionSide, type PriceUpdate, RetryConfig, type RetryConfigOptions, RetryableClient, SIGNING_MESSAGE_TEMPLATE, Side, type SignatureHeaders, SignatureType, type SignedOrder, type SubscriptionChannel, type SubscriptionOptions, type TokenBalance, type TradeEvent, type TradingMode, type UnsignedOrder, type UserData, type UserProfile, ValidationError, WebSocketClient, type WebSocketConfig, type WebSocketEvents, WebSocketState, ZERO_ADDRESS, getContractAddress, retryOnErrors, validateOrderArgs, validateSignedOrder, validateUnsignedOrder, withRetry };
|