@limitless-exchange/sdk 0.0.2 → 1.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/README.md +216 -77
- package/dist/index.d.mts +1103 -1123
- package/dist/index.d.ts +1103 -1123
- package/dist/index.js +747 -1039
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +743 -1035
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# Limitless Exchange TypeScript SDK
|
|
2
2
|
|
|
3
|
+
**v1.0.0 LTS (Long-Term Support)** | Production-Ready | Type-Safe | Fully Documented
|
|
4
|
+
|
|
3
5
|
A TypeScript SDK for interacting with the Limitless Exchange platform, providing type-safe access to CLOB and NegRisk prediction markets.
|
|
4
6
|
|
|
7
|
+
> 🎉 **v1.0.0 LTS Release**: This is the first stable, production-ready release with long-term support. Recommended for all production deployments. See [Changelog](#changelog) for details.
|
|
8
|
+
|
|
5
9
|
## ⚠️ Disclaimer
|
|
6
10
|
|
|
7
11
|
**USE AT YOUR OWN RISK**
|
|
@@ -23,16 +27,22 @@ For production use, we strongly recommend:
|
|
|
23
27
|
3. Monitoring all transactions carefully
|
|
24
28
|
4. Having proper error handling and recovery mechanisms
|
|
25
29
|
|
|
30
|
+
**Feedback Welcome**: We encourage you to report any bugs, suggest improvements, or contribute to the project. Please submit issues or pull requests on our GitHub repository.
|
|
31
|
+
|
|
32
|
+
## 🌍 Geographic Restrictions
|
|
33
|
+
|
|
34
|
+
**Important**: Limitless restricts order placement from US locations due to regulatory requirements and compliance with international sanctions. Before placing orders, builders should verify their location complies with applicable regulations.
|
|
35
|
+
|
|
26
36
|
## Features
|
|
27
37
|
|
|
28
|
-
- ✅ **Authentication**:
|
|
38
|
+
- ✅ **Authentication**: API key authentication with X-API-Key header
|
|
29
39
|
- ✅ **Order Management**: Create, cancel, and manage orders on CLOB and NegRisk markets
|
|
30
40
|
- ✅ **Market Data**: Access real-time market data and orderbooks
|
|
31
41
|
- ✅ **NegRisk Markets**: Full support for group markets with multiple outcomes
|
|
32
42
|
- ✅ **Error Handling & Retry**: Automatic retry logic for rate limits and transient failures
|
|
33
43
|
- ✅ **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
34
44
|
- ✅ **TSDoc Documentation**: Complete API documentation with examples
|
|
35
|
-
- ✅ **WebSocket**: Real-time price and position updates
|
|
45
|
+
- ✅ **WebSocket**: Real-time price and position updates with API key auth
|
|
36
46
|
|
|
37
47
|
## Installation
|
|
38
48
|
|
|
@@ -58,7 +68,6 @@ const httpClient = new HttpClient({
|
|
|
58
68
|
// Optional: Add custom headers to all requests
|
|
59
69
|
additionalHeaders: {
|
|
60
70
|
'X-Custom-Header': 'my-value',
|
|
61
|
-
'X-API-Version': 'v1',
|
|
62
71
|
},
|
|
63
72
|
});
|
|
64
73
|
|
|
@@ -84,48 +93,110 @@ See [examples/project-integration/src/active-markets.ts](./examples/project-inte
|
|
|
84
93
|
|
|
85
94
|
### Authentication
|
|
86
95
|
|
|
96
|
+
The SDK uses API keys for authentication. API keys can be obtained from your Limitless Exchange account settings.
|
|
97
|
+
|
|
87
98
|
```typescript
|
|
88
|
-
import {
|
|
89
|
-
import { HttpClient, MessageSigner, Authenticator } from '@limitless-exchange/sdk';
|
|
99
|
+
import { HttpClient } from '@limitless-exchange/sdk';
|
|
90
100
|
|
|
91
|
-
//
|
|
92
|
-
|
|
101
|
+
// Option 1: Automatic from environment variable (recommended)
|
|
102
|
+
// Set LIMITLESS_API_KEY in your .env file
|
|
103
|
+
const httpClient = new HttpClient({
|
|
104
|
+
baseURL: 'https://api.limitless.exchange',
|
|
105
|
+
});
|
|
93
106
|
|
|
94
|
-
//
|
|
107
|
+
// Option 2: Explicit API key
|
|
95
108
|
const httpClient = new HttpClient({
|
|
96
109
|
baseURL: 'https://api.limitless.exchange',
|
|
110
|
+
apiKey: process.env.LIMITLESS_API_KEY,
|
|
97
111
|
});
|
|
98
112
|
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
// All requests automatically include X-API-Key header
|
|
114
|
+
// For authenticated endpoints like portfolio, orders, etc.
|
|
115
|
+
```
|
|
101
116
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
**Environment Variables:**
|
|
118
|
+
|
|
119
|
+
Create a `.env` file:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Required for authenticated endpoints
|
|
123
|
+
LIMITLESS_API_KEY=sk_live_your_api_key_here
|
|
124
|
+
|
|
125
|
+
# Optional: Private key for order signing (EIP-712)
|
|
126
|
+
PRIVATE_KEY=0x...
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Token Approvals
|
|
130
|
+
|
|
131
|
+
**Important**: Before placing orders, you must approve tokens for the exchange contracts. This is a **one-time setup** per wallet.
|
|
132
|
+
|
|
133
|
+
#### Required Approvals
|
|
134
|
+
|
|
135
|
+
**CLOB Markets:**
|
|
136
|
+
|
|
137
|
+
- **BUY orders**: Approve USDC → `market.venue.exchange`
|
|
138
|
+
- **SELL orders**: Approve Conditional Tokens → `market.venue.exchange`
|
|
139
|
+
|
|
140
|
+
**NegRisk Markets:**
|
|
141
|
+
|
|
142
|
+
- **BUY orders**: Approve USDC → `market.venue.exchange`
|
|
143
|
+
- **SELL orders**: Approve Conditional Tokens → **both** `market.venue.exchange` AND `market.venue.adapter`
|
|
144
|
+
|
|
145
|
+
#### Quick Setup
|
|
146
|
+
|
|
147
|
+
Run the approval setup script:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Copy .env.example and configure your wallet
|
|
151
|
+
cp docs/code-samples/.env.example docs/code-samples/.env
|
|
106
152
|
|
|
107
|
-
|
|
108
|
-
|
|
153
|
+
# Edit .env and set your PRIVATE_KEY and market slug
|
|
154
|
+
# Then run the approval script
|
|
155
|
+
npx tsx docs/code-samples/setup-approvals.ts
|
|
109
156
|
```
|
|
110
157
|
|
|
111
|
-
|
|
158
|
+
#### Manual Approval Example
|
|
112
159
|
|
|
113
160
|
```typescript
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
161
|
+
import { ethers } from 'ethers';
|
|
162
|
+
import { MarketFetcher, getContractAddress } from '@limitless-exchange/sdk';
|
|
163
|
+
|
|
164
|
+
// 1. Fetch market to get venue addresses
|
|
165
|
+
const market = await marketFetcher.getMarket('market-slug');
|
|
166
|
+
|
|
167
|
+
// 2. Create contract instances
|
|
168
|
+
const usdc = new ethers.Contract(
|
|
169
|
+
getContractAddress('USDC'),
|
|
170
|
+
['function approve(address spender, uint256 amount) returns (bool)'],
|
|
171
|
+
wallet
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const ctf = new ethers.Contract(
|
|
175
|
+
getContractAddress('CTF'),
|
|
176
|
+
['function setApprovalForAll(address operator, bool approved)'],
|
|
177
|
+
wallet
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// 3. Approve USDC for BUY orders
|
|
181
|
+
await usdc.approve(market.venue.exchange, ethers.MaxUint256);
|
|
182
|
+
|
|
183
|
+
// 4. Approve CT for SELL orders
|
|
184
|
+
await ctf.setApprovalForAll(market.venue.exchange, true);
|
|
185
|
+
|
|
186
|
+
// 5. For NegRisk SELL orders, also approve adapter
|
|
187
|
+
if (market.negRiskRequestId) {
|
|
188
|
+
await ctf.setApprovalForAll(market.venue.adapter, true);
|
|
189
|
+
}
|
|
118
190
|
```
|
|
119
191
|
|
|
192
|
+
For complete examples, see [docs/code-samples/setup-approvals.ts](./docs/code-samples/setup-approvals.ts).
|
|
193
|
+
|
|
120
194
|
### Trading on NegRisk Markets
|
|
121
195
|
|
|
122
196
|
NegRisk markets are group markets with multiple related outcomes. Here's a quick example:
|
|
123
197
|
|
|
124
198
|
```typescript
|
|
125
|
-
import { OrderClient, MarketFetcher,
|
|
126
|
-
|
|
127
|
-
// Set the NegRisk contract address
|
|
128
|
-
process.env.NEGRISK_CONTRACT_ADDRESS = '0x5a38afc17F7E97ad8d6C547ddb837E40B4aEDfC6';
|
|
199
|
+
import { OrderClient, MarketFetcher, Side, OrderType } from '@limitless-exchange/sdk';
|
|
129
200
|
|
|
130
201
|
// 1. Fetch NegRisk group market
|
|
131
202
|
const marketFetcher = new MarketFetcher(httpClient);
|
|
@@ -135,15 +206,10 @@ const groupMarket = await marketFetcher.getMarket('largest-company-end-of-2025-1
|
|
|
135
206
|
const appleMarket = groupMarket.markets[0];
|
|
136
207
|
const marketDetails = await marketFetcher.getMarket(appleMarket.slug);
|
|
137
208
|
|
|
138
|
-
// 3. Create order client
|
|
209
|
+
// 3. Create order client (userData fetched automatically from profile)
|
|
139
210
|
const orderClient = new OrderClient({
|
|
140
211
|
httpClient,
|
|
141
212
|
wallet,
|
|
142
|
-
userData: {
|
|
143
|
-
userId: (authResult.profile as any).id,
|
|
144
|
-
feeRateBps: (authResult.profile as any).rank?.feeRateBps || 300,
|
|
145
|
-
},
|
|
146
|
-
marketType: MarketType.NEGRISK, // Important: Use NEGRISK
|
|
147
213
|
});
|
|
148
214
|
|
|
149
215
|
// 4. Place order on submarket (not group!)
|
|
@@ -161,6 +227,53 @@ const order = await orderClient.createOrder({
|
|
|
161
227
|
|
|
162
228
|
For more details, see the [NegRisk Trading Guide](./docs/orders/README.md#negrisk-markets).
|
|
163
229
|
|
|
230
|
+
### FOK Orders (Fill-or-Kill Market Orders)
|
|
231
|
+
|
|
232
|
+
FOK orders execute immediately at the best available price or cancel entirely. Unlike GTC orders that use `price` + `size`, FOK orders use `makerAmount`.
|
|
233
|
+
|
|
234
|
+
**Parameter Semantics**:
|
|
235
|
+
|
|
236
|
+
- **BUY**: `makerAmount` = total USDC to spend
|
|
237
|
+
- **SELL**: `makerAmount` = number of shares to sell
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
import { OrderClient, Side, OrderType } from '@limitless-exchange/sdk';
|
|
241
|
+
|
|
242
|
+
// BUY FOK - spend 50 USDC at market price
|
|
243
|
+
const buyOrder = await orderClient.createOrder({
|
|
244
|
+
tokenId: marketDetails.tokens.yes,
|
|
245
|
+
makerAmount: 50, // 50 USDC to spend
|
|
246
|
+
side: Side.BUY,
|
|
247
|
+
orderType: OrderType.FOK,
|
|
248
|
+
marketSlug: 'market-slug',
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// SELL FOK - sell 120 shares at market price
|
|
252
|
+
const sellOrder = await orderClient.createOrder({
|
|
253
|
+
tokenId: marketDetails.tokens.no,
|
|
254
|
+
makerAmount: 120, // 120 shares to sell
|
|
255
|
+
side: Side.SELL,
|
|
256
|
+
orderType: OrderType.FOK,
|
|
257
|
+
marketSlug: 'market-slug',
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// Check execution
|
|
261
|
+
if (buyOrder.makerMatches && buyOrder.makerMatches.length > 0) {
|
|
262
|
+
console.log(`Order filled: ${buyOrder.makerMatches.length} matches`);
|
|
263
|
+
} else {
|
|
264
|
+
console.log('Order cancelled (no liquidity)');
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**Key Differences from GTC**:
|
|
269
|
+
|
|
270
|
+
- FOK uses `makerAmount` (not `price` + `size`)
|
|
271
|
+
- Executes immediately or cancels (no orderbook placement)
|
|
272
|
+
- All-or-nothing execution (no partial fills)
|
|
273
|
+
- Best for immediate execution at market price
|
|
274
|
+
|
|
275
|
+
For complete examples, see [docs/code-samples/clob-fok-order.ts](./docs/code-samples/clob-fok-order.ts).
|
|
276
|
+
|
|
164
277
|
### Error Handling & Retry
|
|
165
278
|
|
|
166
279
|
The SDK provides automatic retry logic for handling transient failures like rate limits and server errors:
|
|
@@ -205,54 +318,21 @@ For detailed documentation, see the [Error Handling & Retry Guide](./docs/api/RE
|
|
|
205
318
|
|
|
206
319
|
### Authentication
|
|
207
320
|
|
|
208
|
-
#### `MessageSigner`
|
|
209
|
-
|
|
210
|
-
Handles message signing for authentication.
|
|
211
|
-
|
|
212
|
-
```typescript
|
|
213
|
-
const signer = new MessageSigner(wallet);
|
|
214
|
-
|
|
215
|
-
// Create authentication headers
|
|
216
|
-
const headers = await signer.createAuthHeaders(signingMessage);
|
|
217
|
-
|
|
218
|
-
// Sign EIP-712 typed data
|
|
219
|
-
const signature = await signer.signTypedData(domain, types, value);
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
#### `Authenticator`
|
|
223
|
-
|
|
224
|
-
Manages the authentication flow.
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
const authenticator = new Authenticator(httpClient, signer);
|
|
228
|
-
|
|
229
|
-
// Get signing message
|
|
230
|
-
const message = await authenticator.getSigningMessage();
|
|
231
|
-
|
|
232
|
-
// Authenticate
|
|
233
|
-
const result = await authenticator.authenticate({ client: 'eoa' });
|
|
234
|
-
|
|
235
|
-
// Verify authentication
|
|
236
|
-
const address = await authenticator.verifyAuth(sessionCookie);
|
|
237
|
-
|
|
238
|
-
// Logout
|
|
239
|
-
await authenticator.logout(sessionCookie);
|
|
240
|
-
```
|
|
241
|
-
|
|
242
321
|
#### `HttpClient`
|
|
243
322
|
|
|
244
|
-
HTTP client with
|
|
323
|
+
HTTP client with API key authentication.
|
|
245
324
|
|
|
246
325
|
```typescript
|
|
247
326
|
const httpClient = new HttpClient({
|
|
248
327
|
baseURL: 'https://api.limitless.exchange',
|
|
328
|
+
apiKey: process.env.LIMITLESS_API_KEY, // Optional - auto-loads from env
|
|
249
329
|
timeout: 30000,
|
|
250
330
|
});
|
|
251
331
|
|
|
252
|
-
// Set
|
|
253
|
-
httpClient.
|
|
332
|
+
// Set or update API key
|
|
333
|
+
httpClient.setApiKey('sk_live_...');
|
|
254
334
|
|
|
255
|
-
// Make requests
|
|
335
|
+
// Make requests - X-API-Key header automatically included
|
|
256
336
|
const data = await httpClient.get('/endpoint');
|
|
257
337
|
await httpClient.post('/endpoint', { data });
|
|
258
338
|
```
|
|
@@ -262,10 +342,10 @@ await httpClient.post('/endpoint', { data });
|
|
|
262
342
|
For detailed documentation, see the [docs](./docs) directory:
|
|
263
343
|
|
|
264
344
|
- **[Complete Documentation](./docs/README.md)** - Full SDK documentation
|
|
265
|
-
- **[Authentication Guide](./docs/
|
|
345
|
+
- **[Authentication Guide](./docs/api/README.md)** - API key authentication and HTTP client
|
|
266
346
|
- **[Trading & Orders](./docs/orders/README.md)** - Order creation, management, and NegRisk markets
|
|
267
347
|
- **[Market Data](./docs/markets/README.md)** - Market discovery and orderbook access
|
|
268
|
-
- **[Portfolio & Positions](./docs/portfolio/README.md)** - Position tracking and
|
|
348
|
+
- **[Portfolio & Positions](./docs/portfolio/README.md)** - Position tracking and user history
|
|
269
349
|
- **[WebSocket Streaming](./docs/websocket/README.md)** - Real-time data updates
|
|
270
350
|
- **[Error Handling & Retry](./docs/api/README.md)** - API error handling and retry mechanisms
|
|
271
351
|
- **[Logging](./docs/logging/LOGGING.md)** - Logging configuration
|
|
@@ -276,8 +356,7 @@ Production-ready code samples are available in [docs/code-samples](./docs/code-s
|
|
|
276
356
|
|
|
277
357
|
### Authentication Examples
|
|
278
358
|
|
|
279
|
-
- `basic-auth.ts` -
|
|
280
|
-
- `smart-wallet.ts` - Etherspot smart wallet integration
|
|
359
|
+
- `basic-auth.ts` - API key authentication setup
|
|
281
360
|
- `with-logging.ts` - Authentication with custom logging
|
|
282
361
|
- `auth-retry.ts` - Authentication with retry logic
|
|
283
362
|
- `error-handling.ts` - Comprehensive error handling
|
|
@@ -336,11 +415,12 @@ src/
|
|
|
336
415
|
├── types/ # TypeScript type definitions
|
|
337
416
|
│ ├── markets.ts # Market and active markets types
|
|
338
417
|
│ ├── orders.ts # Order types
|
|
339
|
-
│ ├── auth.ts #
|
|
418
|
+
│ ├── auth.ts # User profile types
|
|
340
419
|
│ └── ...
|
|
341
|
-
├──
|
|
342
|
-
│ ├──
|
|
343
|
-
│
|
|
420
|
+
├── api/ # HTTP client and API utilities
|
|
421
|
+
│ ├── http.ts # HTTP client with API key auth
|
|
422
|
+
│ ├── errors.ts # Error handling
|
|
423
|
+
│ └── retry.ts # Retry logic
|
|
344
424
|
├── markets/ # Market data modules
|
|
345
425
|
│ ├── fetcher.ts # Market and orderbook fetching
|
|
346
426
|
│ └── index.ts
|
|
@@ -369,6 +449,65 @@ docs/
|
|
|
369
449
|
|
|
370
450
|
```
|
|
371
451
|
|
|
452
|
+
## Changelog
|
|
453
|
+
|
|
454
|
+
### v1.0.0 (LTS - Long-Term Support Release)
|
|
455
|
+
|
|
456
|
+
**Release Date**: January 2026
|
|
457
|
+
|
|
458
|
+
This is the first stable, production-ready release of the Limitless Exchange TypeScript SDK, designated as a Long-Term Support (LTS) version.
|
|
459
|
+
|
|
460
|
+
#### Highlights
|
|
461
|
+
|
|
462
|
+
- ✅ **Production-Ready**: Thoroughly tested and validated against Base mainnet
|
|
463
|
+
- 🔒 **Type-Safe**: Full TypeScript support with comprehensive type definitions
|
|
464
|
+
- 📚 **Well-Documented**: 17 production-ready code samples + comprehensive guides
|
|
465
|
+
- ⚡ **Performance Optimized**: Venue caching system and connection pooling
|
|
466
|
+
- 🔄 **Robust Error Handling**: Automatic retry logic with multiple strategies
|
|
467
|
+
- 🌐 **Real-Time Updates**: WebSocket support for orderbook and position streaming
|
|
468
|
+
- 🎯 **NegRisk Support**: Full support for group markets with multiple outcomes
|
|
469
|
+
|
|
470
|
+
#### Core Features
|
|
471
|
+
|
|
472
|
+
- **Authentication**: API key authentication, EIP-712 signing, EOA support
|
|
473
|
+
- **Market Data**: Active markets with sorting, orderbook access, venue caching
|
|
474
|
+
- **Order Management**: GTC and FOK orders, tick alignment, automatic signing
|
|
475
|
+
- **Portfolio**: Position tracking, user history
|
|
476
|
+
- **WebSocket**: Real-time orderbook, price updates, event streaming
|
|
477
|
+
- **Error Handling**: Decorator and wrapper retry patterns, configurable strategies
|
|
478
|
+
- **Token Approvals**: Complete setup script, CLOB and NegRisk workflows
|
|
479
|
+
|
|
480
|
+
#### Documentation Enhancements (v1.0.0)
|
|
481
|
+
|
|
482
|
+
- Added FOK order examples to README with clear `makerAmount` semantics
|
|
483
|
+
- Created comprehensive CHANGELOG.md following Keep a Changelog format
|
|
484
|
+
- All 17 code samples include step-by-step comments and error handling
|
|
485
|
+
- Detailed guides for authentication, trading, markets, portfolio, and WebSocket
|
|
486
|
+
|
|
487
|
+
For complete release notes, see [CHANGELOG.md](./CHANGELOG.md).
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
### Pre-Release Versions
|
|
492
|
+
|
|
493
|
+
- **v0.0.3** - WebSocket streaming, enhanced code samples, NegRisk examples
|
|
494
|
+
- **v0.0.2** - Venue caching, retry mechanisms, portfolio fetcher
|
|
495
|
+
- **v0.0.1** - Initial release with core functionality
|
|
496
|
+
|
|
497
|
+
---
|
|
498
|
+
|
|
499
|
+
## LTS Support Policy
|
|
500
|
+
|
|
501
|
+
**v1.0.0 LTS** will receive:
|
|
502
|
+
|
|
503
|
+
- Security updates and critical bug fixes
|
|
504
|
+
- Compatibility maintenance with Limitless Exchange API
|
|
505
|
+
- Community support and issue resolution
|
|
506
|
+
- Documentation updates and improvements
|
|
507
|
+
- Long-term stability for production deployments
|
|
508
|
+
|
|
509
|
+
**Recommended for production use.** We commit to maintaining backward compatibility and providing timely security updates for this LTS release.
|
|
510
|
+
|
|
372
511
|
## License
|
|
373
512
|
|
|
374
513
|
MIT - See [LICENSE](./LICENSE) file for details
|