@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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Limitless Exchange
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
# Limitless Exchange TypeScript SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with the Limitless Exchange platform, providing type-safe access to CLOB and NegRisk prediction markets.
|
|
4
|
+
|
|
5
|
+
## ⚠️ Disclaimer
|
|
6
|
+
|
|
7
|
+
**USE AT YOUR OWN RISK**
|
|
8
|
+
|
|
9
|
+
This SDK is provided "as-is" without any warranties or guarantees. Trading on prediction markets involves financial risk. By using this SDK, you acknowledge that:
|
|
10
|
+
|
|
11
|
+
- You are responsible for testing the SDK thoroughly before using it in production
|
|
12
|
+
- The SDK authors are not liable for any financial losses or damages
|
|
13
|
+
- You should review and understand the code before executing any trades
|
|
14
|
+
- It is recommended to test all functionality on testnet or with small amounts first
|
|
15
|
+
- The SDK may contain bugs or unexpected behavior despite best efforts
|
|
16
|
+
|
|
17
|
+
**ALWAYS TEST BEFORE USING IN PRODUCTION WITH REAL FUNDS**
|
|
18
|
+
|
|
19
|
+
For production use, we strongly recommend:
|
|
20
|
+
|
|
21
|
+
1. Running comprehensive tests with your specific use case
|
|
22
|
+
2. Starting with small transaction amounts
|
|
23
|
+
3. Monitoring all transactions carefully
|
|
24
|
+
4. Having proper error handling and recovery mechanisms
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- ✅ **Authentication**: Simple wallet-based authentication with session management
|
|
29
|
+
- ✅ **Order Management**: Create, cancel, and manage orders on CLOB and NegRisk markets
|
|
30
|
+
- ✅ **Market Data**: Access real-time market data and orderbooks
|
|
31
|
+
- ✅ **NegRisk Markets**: Full support for group markets with multiple outcomes
|
|
32
|
+
- ✅ **Error Handling & Retry**: Automatic retry logic for rate limits and transient failures
|
|
33
|
+
- ✅ **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
34
|
+
- ✅ **TSDoc Documentation**: Complete API documentation with examples
|
|
35
|
+
- ✅ **WebSocket**: Real-time price and position updates
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @limitless-exchange/sdk
|
|
41
|
+
# or
|
|
42
|
+
yarn add @limitless-exchange/sdk
|
|
43
|
+
# or
|
|
44
|
+
pnpm add @limitless-exchange/sdk
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
### Fetching Active Markets (No Authentication Required)
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { HttpClient, MarketFetcher } from '@limitless-exchange/sdk';
|
|
53
|
+
|
|
54
|
+
// Create HTTP client (no authentication needed)
|
|
55
|
+
const httpClient = new HttpClient({
|
|
56
|
+
baseURL: 'https://api.limitless.exchange',
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const marketFetcher = new MarketFetcher(httpClient);
|
|
60
|
+
|
|
61
|
+
// Get markets sorted by LP rewards
|
|
62
|
+
const markets = await marketFetcher.getActiveMarkets({
|
|
63
|
+
limit: 8,
|
|
64
|
+
sortBy: 'lp_rewards', // 'lp_rewards' | 'ending_soon' | 'newest' | 'high_value'
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log(`Found ${markets.data.length} of ${markets.totalMarketsCount} markets`);
|
|
68
|
+
|
|
69
|
+
// Pagination (page-based)
|
|
70
|
+
const page2 = await marketFetcher.getActiveMarkets({
|
|
71
|
+
limit: 8,
|
|
72
|
+
page: 2,
|
|
73
|
+
sortBy: 'ending_soon',
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
See [examples/project-integration/src/active-markets.ts](./examples/project-integration/src/active-markets.ts) for more examples.
|
|
78
|
+
|
|
79
|
+
### Authentication
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { ethers } from 'ethers';
|
|
83
|
+
import { HttpClient, MessageSigner, Authenticator } from '@limitless-exchange/sdk';
|
|
84
|
+
|
|
85
|
+
// Create wallet from private key
|
|
86
|
+
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
|
|
87
|
+
|
|
88
|
+
// Initialize SDK components
|
|
89
|
+
const httpClient = new HttpClient({
|
|
90
|
+
baseURL: 'https://api.limitless.exchange',
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const signer = new MessageSigner(wallet);
|
|
94
|
+
const authenticator = new Authenticator(httpClient, signer);
|
|
95
|
+
|
|
96
|
+
// Authenticate
|
|
97
|
+
const result = await authenticator.authenticate({
|
|
98
|
+
client: 'eoa', // 'eoa', 'base', or 'etherspot'
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log('Session cookie:', result.sessionCookie);
|
|
102
|
+
console.log('Profile:', result.profile);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### ETHERSPOT Authentication (Smart Wallet)
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const result = await authenticator.authenticate({
|
|
109
|
+
client: 'etherspot',
|
|
110
|
+
smartWallet: '0x...', // Your smart wallet address
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Trading on NegRisk Markets
|
|
115
|
+
|
|
116
|
+
NegRisk markets are group markets with multiple related outcomes. Here's a quick example:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { OrderClient, MarketFetcher, MarketType, Side, OrderType } from '@limitless-exchange/sdk';
|
|
120
|
+
|
|
121
|
+
// Set the NegRisk contract address
|
|
122
|
+
process.env.NEGRISK_CONTRACT_ADDRESS = '0x5a38afc17F7E97ad8d6C547ddb837E40B4aEDfC6';
|
|
123
|
+
|
|
124
|
+
// 1. Fetch NegRisk group market
|
|
125
|
+
const marketFetcher = new MarketFetcher(httpClient);
|
|
126
|
+
const groupMarket = await marketFetcher.getMarket('largest-company-end-of-2025-1746118069282');
|
|
127
|
+
|
|
128
|
+
// 2. Select a submarket (e.g., Apple)
|
|
129
|
+
const appleMarket = groupMarket.markets[0];
|
|
130
|
+
const marketDetails = await marketFetcher.getMarket(appleMarket.slug);
|
|
131
|
+
|
|
132
|
+
// 3. Create order client for NegRisk
|
|
133
|
+
const orderClient = new OrderClient({
|
|
134
|
+
httpClient,
|
|
135
|
+
wallet,
|
|
136
|
+
userData: {
|
|
137
|
+
userId: (authResult.profile as any).id,
|
|
138
|
+
feeRateBps: (authResult.profile as any).rank?.feeRateBps || 300,
|
|
139
|
+
},
|
|
140
|
+
marketType: MarketType.NEGRISK, // Important: Use NEGRISK
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// 4. Place order on submarket (not group!)
|
|
144
|
+
const order = await orderClient.createOrder({
|
|
145
|
+
tokenId: marketDetails.tokens.yes,
|
|
146
|
+
price: 0.5,
|
|
147
|
+
size: 10,
|
|
148
|
+
side: Side.BUY,
|
|
149
|
+
orderType: OrderType.GTC,
|
|
150
|
+
marketSlug: appleMarket.slug, // Use submarket slug
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Important**: Always use the **submarket slug** for NegRisk orders, not the group market slug!
|
|
155
|
+
|
|
156
|
+
For more details, see the [NegRisk Trading Guide](./docs/orders/README.md#negrisk-markets).
|
|
157
|
+
|
|
158
|
+
### Error Handling & Retry
|
|
159
|
+
|
|
160
|
+
The SDK provides automatic retry logic for handling transient failures like rate limits and server errors:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { withRetry, retryOnErrors } from '@limitless-exchange/sdk';
|
|
164
|
+
|
|
165
|
+
// Option 1: Wrapper function approach
|
|
166
|
+
const result = await withRetry(async () => await orderClient.createOrder(orderData), {
|
|
167
|
+
statusCodes: [429, 500, 503], // Retry on rate limits and server errors
|
|
168
|
+
maxRetries: 3,
|
|
169
|
+
delays: [2, 5, 10], // Wait 2s, then 5s, then 10s
|
|
170
|
+
onRetry: (attempt, error, delay) => {
|
|
171
|
+
console.log(`Retry ${attempt + 1} after ${delay}s: ${error.message}`);
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Option 2: Decorator approach (requires experimentalDecorators: true)
|
|
176
|
+
class TradingService {
|
|
177
|
+
@retryOnErrors({
|
|
178
|
+
statusCodes: [429, 500, 503],
|
|
179
|
+
maxRetries: 3,
|
|
180
|
+
exponentialBase: 2, // Exponential backoff: 1s, 2s, 4s
|
|
181
|
+
maxDelay: 30,
|
|
182
|
+
})
|
|
183
|
+
async placeOrder(orderData: any) {
|
|
184
|
+
return await this.orderClient.createOrder(orderData);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Key Features**:
|
|
190
|
+
|
|
191
|
+
- Automatic retry on configurable status codes (429, 500, 502, 503, 504)
|
|
192
|
+
- Fixed delays or exponential backoff strategies
|
|
193
|
+
- Callback hooks for monitoring retry attempts
|
|
194
|
+
- Three approaches: decorator, wrapper function, or global client wrapper
|
|
195
|
+
|
|
196
|
+
For detailed documentation, see the [Error Handling & Retry Guide](./docs/api/README.md).
|
|
197
|
+
|
|
198
|
+
## API Documentation
|
|
199
|
+
|
|
200
|
+
### Authentication
|
|
201
|
+
|
|
202
|
+
#### `MessageSigner`
|
|
203
|
+
|
|
204
|
+
Handles message signing for authentication.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
const signer = new MessageSigner(wallet);
|
|
208
|
+
|
|
209
|
+
// Create authentication headers
|
|
210
|
+
const headers = await signer.createAuthHeaders(signingMessage);
|
|
211
|
+
|
|
212
|
+
// Sign EIP-712 typed data
|
|
213
|
+
const signature = await signer.signTypedData(domain, types, value);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### `Authenticator`
|
|
217
|
+
|
|
218
|
+
Manages the authentication flow.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
const authenticator = new Authenticator(httpClient, signer);
|
|
222
|
+
|
|
223
|
+
// Get signing message
|
|
224
|
+
const message = await authenticator.getSigningMessage();
|
|
225
|
+
|
|
226
|
+
// Authenticate
|
|
227
|
+
const result = await authenticator.authenticate({ client: 'eoa' });
|
|
228
|
+
|
|
229
|
+
// Verify authentication
|
|
230
|
+
const address = await authenticator.verifyAuth(sessionCookie);
|
|
231
|
+
|
|
232
|
+
// Logout
|
|
233
|
+
await authenticator.logout(sessionCookie);
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
#### `HttpClient`
|
|
237
|
+
|
|
238
|
+
HTTP client with cookie management.
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
const httpClient = new HttpClient({
|
|
242
|
+
baseURL: 'https://api.limitless.exchange',
|
|
243
|
+
timeout: 30000,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Set session cookie for authenticated requests
|
|
247
|
+
httpClient.setSessionCookie(sessionCookie);
|
|
248
|
+
|
|
249
|
+
// Make requests
|
|
250
|
+
const data = await httpClient.get('/endpoint');
|
|
251
|
+
await httpClient.post('/endpoint', { data });
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Documentation
|
|
255
|
+
|
|
256
|
+
For detailed documentation, see the [docs](./docs) directory:
|
|
257
|
+
|
|
258
|
+
- **[Complete Documentation](./docs/README.md)** - Full SDK documentation
|
|
259
|
+
- **[Authentication Guide](./docs/auth/README.md)** - Authentication and session management
|
|
260
|
+
- **[Trading & Orders](./docs/orders/README.md)** - Order creation, management, and NegRisk markets
|
|
261
|
+
- **[Market Data](./docs/markets/README.md)** - Market discovery and orderbook access
|
|
262
|
+
- **[Portfolio & Positions](./docs/portfolio/README.md)** - Position tracking and balances
|
|
263
|
+
- **[WebSocket Streaming](./docs/websocket/README.md)** - Real-time data updates
|
|
264
|
+
- **[Error Handling & Retry](./docs/api/README.md)** - API error handling and retry mechanisms
|
|
265
|
+
- **[Logging](./docs/logging/LOGGING.md)** - Logging configuration
|
|
266
|
+
|
|
267
|
+
## Code Examples
|
|
268
|
+
|
|
269
|
+
Production-ready code samples are available in [docs/code-samples](./docs/code-samples):
|
|
270
|
+
|
|
271
|
+
### Authentication Examples
|
|
272
|
+
|
|
273
|
+
- `basic-auth.ts` - Simple EOA authentication
|
|
274
|
+
- `smart-wallet.ts` - Etherspot smart wallet integration
|
|
275
|
+
- `with-logging.ts` - Authentication with custom logging
|
|
276
|
+
- `auth-retry.ts` - Authentication with retry logic
|
|
277
|
+
- `error-handling.ts` - Comprehensive error handling
|
|
278
|
+
|
|
279
|
+
### Trading Examples
|
|
280
|
+
|
|
281
|
+
**CLOB Markets:**
|
|
282
|
+
|
|
283
|
+
- `clob-fok-order.ts` - Fill-or-Kill market orders
|
|
284
|
+
- `clob-gtc-order.ts` - Good-Til-Cancelled limit orders
|
|
285
|
+
|
|
286
|
+
**NegRisk Markets:**
|
|
287
|
+
|
|
288
|
+
- `negrisk-fok-order.ts` - FOK orders on group markets
|
|
289
|
+
- `negrisk-gtc-trading-example.ts` - Complete NegRisk trading workflow
|
|
290
|
+
|
|
291
|
+
### Market Data Examples
|
|
292
|
+
|
|
293
|
+
- `get-active-markets.ts` - Fetching active markets with sorting and pagination
|
|
294
|
+
- `orderbook.ts` - Fetching and analyzing orderbooks
|
|
295
|
+
- `positions.ts` - Portfolio and position tracking
|
|
296
|
+
- `trading.ts` - Complete trading workflow
|
|
297
|
+
|
|
298
|
+
### Real-Time Examples
|
|
299
|
+
|
|
300
|
+
- `websocket-trading.ts` - Real-time order monitoring
|
|
301
|
+
- `websocket-orderbook.ts` - Live orderbook streaming
|
|
302
|
+
|
|
303
|
+
## Development
|
|
304
|
+
|
|
305
|
+
### Build
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
pnpm install
|
|
309
|
+
pnpm build
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Test
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
pnpm test
|
|
316
|
+
pnpm test:coverage
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Lint
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
pnpm lint
|
|
323
|
+
pnpm format
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Project Structure
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
src/
|
|
330
|
+
├── types/ # TypeScript type definitions
|
|
331
|
+
│ ├── markets.ts # Market and active markets types
|
|
332
|
+
│ ├── orders.ts # Order types
|
|
333
|
+
│ ├── auth.ts # Authentication types
|
|
334
|
+
│ └── ...
|
|
335
|
+
├── auth/ # Authentication modules
|
|
336
|
+
│ ├── signer.ts # Message signing
|
|
337
|
+
│ └── authenticator.ts
|
|
338
|
+
├── markets/ # Market data modules
|
|
339
|
+
│ ├── fetcher.ts # Market and orderbook fetching
|
|
340
|
+
│ └── index.ts
|
|
341
|
+
├── orders/ # Order management
|
|
342
|
+
│ └── client.ts # Order creation and management
|
|
343
|
+
├── portfolio/ # Portfolio and positions
|
|
344
|
+
│ └── fetcher.ts
|
|
345
|
+
├── websocket/ # Real-time data streaming
|
|
346
|
+
│ └── client.ts
|
|
347
|
+
├── api/ # HTTP client and API utilities
|
|
348
|
+
│ ├── http.ts # HTTP client
|
|
349
|
+
│ └── errors.ts # API error handling
|
|
350
|
+
└── utils/ # Shared utilities and constants
|
|
351
|
+
|
|
352
|
+
tests/
|
|
353
|
+
├── auth/ # Authentication tests
|
|
354
|
+
└── markets/ # Market fetcher tests
|
|
355
|
+
└── fetcher.test.ts //etc.
|
|
356
|
+
|
|
357
|
+
docs/
|
|
358
|
+
├── code-samples/ # Production-ready examples
|
|
359
|
+
│ ├── get-active-markets.ts
|
|
360
|
+
│ ├── clob-fok-order.ts
|
|
361
|
+
│ └── ...
|
|
362
|
+
└── */ # Documentation guides
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## License
|
|
367
|
+
|
|
368
|
+
MIT - See [LICENSE](./LICENSE) file for details
|