propheseer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,857 @@
1
+ import { EventEmitter } from 'events';
2
+
3
+ /**
4
+ * Rate limit information extracted from API response headers.
5
+ */
6
+ interface RateLimitInfo {
7
+ /** User's plan (free, pro, business, etc.) */
8
+ plan: string;
9
+ /** Billing type: 'subscription' or 'credits' */
10
+ billingType: 'subscription' | 'credits';
11
+ /** Daily request limit (subscription billing) */
12
+ limitDay?: number;
13
+ /** Remaining daily requests (subscription billing) */
14
+ remainingDay?: number;
15
+ /** Per-minute request limit (subscription billing) */
16
+ limitMinute?: number;
17
+ /** Remaining per-minute requests (subscription billing) */
18
+ remainingMinute?: number;
19
+ /** Credit balance in cents (credit billing) */
20
+ creditBalanceCents?: number;
21
+ /** Formatted credit balance (credit billing) */
22
+ creditBalance?: string;
23
+ /** Cost of the request in cents (credit billing) */
24
+ requestCostCents?: number;
25
+ /** Formatted request cost (credit billing) */
26
+ requestCost?: string;
27
+ }
28
+ /**
29
+ * Wrapper for API responses that includes rate limit info.
30
+ */
31
+ interface APIResponse<T> {
32
+ /** The response data */
33
+ data: T;
34
+ /** Rate limit information from response headers */
35
+ rateLimit: RateLimitInfo | null;
36
+ /** The raw Response object */
37
+ response: Response;
38
+ }
39
+ /**
40
+ * Pagination metadata returned by paginated endpoints.
41
+ */
42
+ interface PaginationMeta {
43
+ /** Total number of items matching the query */
44
+ total: number;
45
+ /** Maximum items per page */
46
+ limit: number;
47
+ /** Current offset */
48
+ offset: number;
49
+ /** Source metadata (varies by endpoint) */
50
+ sources?: Record<string, unknown>;
51
+ }
52
+
53
+ interface ClientOptions {
54
+ /** API key for authentication. Falls back to PROPHESEER_API_KEY env var. */
55
+ apiKey?: string;
56
+ /** Base URL for the API (default: https://api.propheseer.com) */
57
+ baseURL?: string;
58
+ /** Request timeout in milliseconds (default: 30000) */
59
+ timeout?: number;
60
+ /** Maximum number of retries on retryable errors (default: 2) */
61
+ maxRetries?: number;
62
+ }
63
+ interface RequestConfig {
64
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
65
+ path: string;
66
+ query?: Record<string, string | number | boolean | undefined>;
67
+ body?: unknown;
68
+ /** Whether this request requires authentication (default: true) */
69
+ auth?: boolean;
70
+ }
71
+ /**
72
+ * Base HTTP client with retry logic, rate limit parsing, and error mapping.
73
+ */
74
+ declare class BaseClient {
75
+ readonly apiKey: string | undefined;
76
+ readonly baseURL: string;
77
+ readonly timeout: number;
78
+ readonly maxRetries: number;
79
+ constructor(options?: ClientOptions);
80
+ /**
81
+ * Make an authenticated API request with retry and error handling.
82
+ */
83
+ request<T>(config: RequestConfig): Promise<{
84
+ data: T;
85
+ rateLimit: RateLimitInfo | null;
86
+ response: Response;
87
+ }>;
88
+ private buildURL;
89
+ private getRetryDelay;
90
+ }
91
+
92
+ /** Prediction market data sources */
93
+ type MarketSource = 'polymarket' | 'kalshi' | 'gemini';
94
+ /** Market status */
95
+ type MarketStatus = 'open' | 'closed' | 'settled';
96
+ /** Market category */
97
+ type MarketCategory = 'politics' | 'sports' | 'finance' | 'entertainment' | 'science' | 'other';
98
+ /**
99
+ * An outcome within a prediction market.
100
+ */
101
+ interface Outcome {
102
+ /** Outcome name (e.g. "Yes", "No", "Donald Trump") */
103
+ name: string;
104
+ /** Probability as a decimal between 0 and 1 */
105
+ probability: number;
106
+ /** 24-hour trading volume (null if unavailable) */
107
+ volume24h: number | null;
108
+ }
109
+ /**
110
+ * A normalized prediction market from any supported platform.
111
+ */
112
+ interface Market {
113
+ /** Unique market ID (prefixed: pm_, ks_, gm_) */
114
+ id: string;
115
+ /** Source platform */
116
+ source: MarketSource;
117
+ /** Original ID on the source platform */
118
+ sourceId: string;
119
+ /** The market question */
120
+ question: string;
121
+ /** Market description (may be null) */
122
+ description: string | null;
123
+ /** Normalized category */
124
+ category: MarketCategory;
125
+ /** Market status */
126
+ status: MarketStatus;
127
+ /** Available outcomes with probabilities */
128
+ outcomes: Outcome[];
129
+ /** Expected resolution date (ISO 8601, may be null) */
130
+ resolutionDate: string | null;
131
+ /** When the market was created (ISO 8601) */
132
+ createdAt: string;
133
+ /** When the market was last updated (ISO 8601) */
134
+ updatedAt: string;
135
+ /** URL to the market on its source platform */
136
+ url: string;
137
+ /** Market image URL (may be null) */
138
+ imageUrl: string | null;
139
+ /** Tags from the source platform */
140
+ tags: string[];
141
+ }
142
+ /**
143
+ * Parameters for listing markets.
144
+ */
145
+ interface MarketListParams {
146
+ /** Filter by source platform */
147
+ source?: MarketSource | 'all';
148
+ /** Filter by category */
149
+ category?: MarketCategory;
150
+ /** Filter by status */
151
+ status?: MarketStatus;
152
+ /** Search query string */
153
+ q?: string;
154
+ /** Maximum results per page (default: 50, max: 200) */
155
+ limit?: number;
156
+ /** Offset for pagination (default: 0) */
157
+ offset?: number;
158
+ }
159
+
160
+ /**
161
+ * A page of results from a paginated API endpoint.
162
+ */
163
+ declare class Page<T> {
164
+ /** Items on this page */
165
+ readonly data: T[];
166
+ /** Pagination metadata */
167
+ readonly meta: PaginationMeta;
168
+ /** Rate limit information */
169
+ readonly rateLimit: RateLimitInfo | null;
170
+ constructor(data: T[], meta: PaginationMeta, rateLimit: RateLimitInfo | null);
171
+ /** Whether there are more pages available */
172
+ hasMore(): boolean;
173
+ /** The offset for the next page, or null if no more pages */
174
+ nextOffset(): number | null;
175
+ }
176
+ /**
177
+ * Options for auto-pagination.
178
+ */
179
+ interface AutoPaginateOptions {
180
+ /** Maximum total items to yield (default: unlimited) */
181
+ maxItems?: number;
182
+ }
183
+ /**
184
+ * Creates an async generator that automatically paginates through all results.
185
+ *
186
+ * @param fetchPage - Function that fetches a page given an offset
187
+ * @param options - Auto-pagination options
188
+ * @returns AsyncGenerator yielding individual items
189
+ */
190
+ declare function autoPaginate<T>(fetchPage: (offset: number) => Promise<Page<T>>, options?: AutoPaginateOptions): AsyncGenerator<T, void, undefined>;
191
+
192
+ declare class Markets {
193
+ private client;
194
+ constructor(client: BaseClient);
195
+ /**
196
+ * List markets with optional filters.
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * const page = await client.markets.list({ source: 'polymarket', limit: 10 });
201
+ * console.log(page.data); // Market[]
202
+ * console.log(page.meta.total); // total matching markets
203
+ * ```
204
+ */
205
+ list(params?: MarketListParams): Promise<Page<Market>>;
206
+ /**
207
+ * Get a single market by ID.
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * const { data: market } = await client.markets.get('pm_12345');
212
+ * ```
213
+ */
214
+ get(id: string): Promise<APIResponse<Market>>;
215
+ /**
216
+ * Auto-paginate through all markets matching the query.
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * for await (const market of client.markets.listAutoPaginate({ source: 'kalshi' })) {
221
+ * console.log(market.question);
222
+ * }
223
+ * ```
224
+ */
225
+ listAutoPaginate(params?: Omit<MarketListParams, 'offset'>, options?: AutoPaginateOptions): AsyncGenerator<Market, void, undefined>;
226
+ }
227
+
228
+ /**
229
+ * A market category with its subcategories.
230
+ */
231
+ interface Category {
232
+ /** Category identifier */
233
+ id: string;
234
+ /** Display name */
235
+ name: string;
236
+ /** List of subcategory identifiers */
237
+ subcategories: string[];
238
+ }
239
+
240
+ declare class Categories {
241
+ private client;
242
+ constructor(client: BaseClient);
243
+ /**
244
+ * List all available market categories.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * const { data: categories } = await client.categories.list();
249
+ * ```
250
+ */
251
+ list(): Promise<APIResponse<Category[]>>;
252
+ }
253
+
254
+ /**
255
+ * A market involved in an arbitrage opportunity.
256
+ */
257
+ interface ArbitrageMarket {
258
+ /** Source platform */
259
+ source: MarketSource;
260
+ /** Yes price (probability) */
261
+ yesPrice: number;
262
+ /** URL to the market */
263
+ url: string;
264
+ }
265
+ /**
266
+ * An arbitrage opportunity across platforms.
267
+ */
268
+ interface ArbitrageOpportunity {
269
+ /** The market question */
270
+ question: string;
271
+ /** Price spread between platforms (decimal) */
272
+ spread: number;
273
+ /** Potential return percentage (e.g. "5.2%") */
274
+ potentialReturn: string;
275
+ /** Markets involved in the opportunity */
276
+ markets: ArbitrageMarket[];
277
+ }
278
+ /**
279
+ * Parameters for finding arbitrage opportunities.
280
+ */
281
+ interface ArbitrageFindParams {
282
+ /** Minimum spread to include (default: 0.03) */
283
+ minSpread?: number;
284
+ /** Filter by category */
285
+ category?: MarketCategory;
286
+ }
287
+
288
+ declare class Arbitrage {
289
+ private client;
290
+ constructor(client: BaseClient);
291
+ /**
292
+ * Find arbitrage opportunities across platforms.
293
+ * Requires Pro plan or higher.
294
+ *
295
+ * @example
296
+ * ```ts
297
+ * const { data: opportunities } = await client.arbitrage.find({ minSpread: 0.05 });
298
+ * for (const opp of opportunities) {
299
+ * console.log(`${opp.question}: ${opp.potentialReturn}`);
300
+ * }
301
+ * ```
302
+ */
303
+ find(params?: ArbitrageFindParams): Promise<APIResponse<ArbitrageOpportunity[]>>;
304
+ }
305
+
306
+ /** Reasons a trade was flagged as unusual */
307
+ type DetectionReason = 'potential_insider' | 'high_amount' | 'new_wallet' | 'near_resolution';
308
+ /** Trade side */
309
+ type TradeSide = 'BUY' | 'SELL';
310
+ /**
311
+ * Market information associated with an unusual trade.
312
+ */
313
+ interface UnusualTradeMarket {
314
+ /** Market ID */
315
+ id: string;
316
+ /** Market question */
317
+ question: string;
318
+ /** Source platform */
319
+ source: MarketSource;
320
+ /** Market end date (may be undefined) */
321
+ endDate?: string;
322
+ /** URL to the market */
323
+ url?: string;
324
+ /** Tags from the platform */
325
+ tags: string[];
326
+ /** Market image URL */
327
+ imageUrl?: string | null;
328
+ }
329
+ /**
330
+ * Details of the flagged trade.
331
+ */
332
+ interface TradeDetails {
333
+ /** Trader's wallet address */
334
+ walletAddress: string;
335
+ /** Buy or sell */
336
+ side: TradeSide;
337
+ /** Trade size (contracts) */
338
+ size: number;
339
+ /** Trade price */
340
+ price: number;
341
+ /** USDC value of the trade */
342
+ usdcValue: number;
343
+ /** When the trade occurred (ISO 8601) */
344
+ timestamp: string;
345
+ /** On-chain transaction hash */
346
+ transactionHash: string;
347
+ }
348
+ /**
349
+ * Why the trade was flagged.
350
+ */
351
+ interface DetectionInfo {
352
+ /** Detection reason */
353
+ reason: DetectionReason;
354
+ /** Anomaly score (0-100) */
355
+ anomalyScore: number;
356
+ /** Market context for the detection */
357
+ context: {
358
+ /** Average trade size in this market */
359
+ marketAvgSize: number;
360
+ /** Standard deviation of trade sizes */
361
+ marketStdDev: number;
362
+ };
363
+ }
364
+ /**
365
+ * An unusual trade detected by the system.
366
+ */
367
+ interface UnusualTrade {
368
+ /** Trade ID */
369
+ id: string;
370
+ /** Associated market */
371
+ market: UnusualTradeMarket;
372
+ /** Trade details */
373
+ trade: TradeDetails;
374
+ /** Detection information */
375
+ detection: DetectionInfo;
376
+ /** When the trade was detected (ISO 8601) */
377
+ detectedAt: string;
378
+ }
379
+ /**
380
+ * Parameters for listing unusual trades.
381
+ */
382
+ interface UnusualTradeListParams {
383
+ /** Maximum results per page (default: 50, max: 100) */
384
+ limit?: number;
385
+ /** Offset for pagination */
386
+ offset?: number;
387
+ /** Filter by market ID */
388
+ marketId?: string;
389
+ /** Filter by detection reason */
390
+ reason?: DetectionReason;
391
+ /** Minimum anomaly score */
392
+ minScore?: number;
393
+ /** Only trades since this date (ISO 8601) */
394
+ since?: string;
395
+ /** Filter by trade side */
396
+ side?: TradeSide;
397
+ /** Filter by source platform */
398
+ source?: MarketSource;
399
+ /** Categories to exclude (comma-separated) */
400
+ excludeCategories?: string;
401
+ }
402
+
403
+ declare class UnusualTrades {
404
+ private client;
405
+ constructor(client: BaseClient);
406
+ /**
407
+ * List unusual trades detected by the system.
408
+ * Requires Pro plan or higher.
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * const page = await client.unusualTrades.list({ reason: 'high_amount', limit: 10 });
413
+ * for (const trade of page.data) {
414
+ * console.log(`${trade.market.question}: $${trade.trade.usdcValue}`);
415
+ * }
416
+ * ```
417
+ */
418
+ list(params?: UnusualTradeListParams): Promise<Page<UnusualTrade>>;
419
+ /**
420
+ * Auto-paginate through all unusual trades matching the query.
421
+ *
422
+ * @example
423
+ * ```ts
424
+ * for await (const trade of client.unusualTrades.listAutoPaginate({ since: '2025-01-01' })) {
425
+ * console.log(trade.detection.reason);
426
+ * }
427
+ * ```
428
+ */
429
+ listAutoPaginate(params?: Omit<UnusualTradeListParams, 'offset'>, options?: AutoPaginateOptions): AsyncGenerator<UnusualTrade, void, undefined>;
430
+ }
431
+
432
+ /**
433
+ * A historical market snapshot.
434
+ */
435
+ interface MarketHistoryEntry {
436
+ /** Market ID */
437
+ marketId: string;
438
+ /** Snapshot date (YYYY-MM-DD) */
439
+ snapshotDate: string;
440
+ /** Snapshot data (market state at that time) */
441
+ [key: string]: unknown;
442
+ }
443
+ /**
444
+ * Parameters for listing market history.
445
+ */
446
+ interface HistoryListParams {
447
+ /** Filter by specific market ID */
448
+ marketId?: string;
449
+ /** Filter by source platform */
450
+ source?: MarketSource;
451
+ /** Filter by category */
452
+ category?: MarketCategory;
453
+ /** Number of days of history (default: 30) */
454
+ days?: number;
455
+ /** Maximum results (default: 1000) */
456
+ limit?: number;
457
+ }
458
+ /**
459
+ * A date with available snapshot data.
460
+ */
461
+ interface SnapshotDate {
462
+ /** Date string (YYYY-MM-DD) */
463
+ date: string;
464
+ /** Number of markets captured */
465
+ count: number;
466
+ }
467
+
468
+ declare class History {
469
+ private client;
470
+ constructor(client: BaseClient);
471
+ /**
472
+ * List historical market snapshots.
473
+ * Requires Business plan or higher.
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * const { data: history } = await client.history.list({ marketId: 'pm_12345', days: 7 });
478
+ * ```
479
+ */
480
+ list(params?: HistoryListParams): Promise<APIResponse<MarketHistoryEntry[]>>;
481
+ /**
482
+ * List available snapshot dates.
483
+ * Requires Business plan or higher.
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * const { data: dates } = await client.history.dates();
488
+ * console.log(dates); // [{ date: '2025-02-01', count: 150 }, ...]
489
+ * ```
490
+ */
491
+ dates(): Promise<APIResponse<SnapshotDate[]>>;
492
+ }
493
+
494
+ /**
495
+ * API key usage statistics.
496
+ */
497
+ interface KeyUsage {
498
+ /** Requests made today */
499
+ daily: number;
500
+ /** Requests made this minute */
501
+ minute: number;
502
+ /** Total requests ever */
503
+ total: number;
504
+ }
505
+ /**
506
+ * Daily usage history entry.
507
+ */
508
+ interface UsageHistoryEntry {
509
+ /** Date (YYYY-MM-DD) */
510
+ date: string;
511
+ /** Number of requests */
512
+ count: number;
513
+ }
514
+ /**
515
+ * Plan rate limits.
516
+ */
517
+ interface PlanLimits {
518
+ /** Maximum requests per day */
519
+ requestsPerDay: number;
520
+ /** Maximum requests per minute */
521
+ requestsPerMinute: number;
522
+ }
523
+ /**
524
+ * Information about the current API key.
525
+ */
526
+ interface KeyInfo {
527
+ /** Key ID */
528
+ id: string;
529
+ /** Key name */
530
+ name: string;
531
+ /** Plan name */
532
+ plan: string;
533
+ /** Rate limits for the plan */
534
+ limits: PlanLimits;
535
+ /** Current usage */
536
+ usage: KeyUsage;
537
+ /** Daily usage history */
538
+ history: UsageHistoryEntry[];
539
+ /** When the key was created (ISO 8601) */
540
+ createdAt: string;
541
+ /** When the key was last used (ISO 8601, may be null) */
542
+ lastUsedAt: string | null;
543
+ }
544
+
545
+ declare class Keys {
546
+ private client;
547
+ constructor(client: BaseClient);
548
+ /**
549
+ * Get information about the current API key, including usage statistics.
550
+ *
551
+ * @example
552
+ * ```ts
553
+ * const { data: keyInfo } = await client.keys.me();
554
+ * console.log(`Plan: ${keyInfo.plan}`);
555
+ * console.log(`Daily usage: ${keyInfo.usage.daily}/${keyInfo.limits.requestsPerDay}`);
556
+ * ```
557
+ */
558
+ me(): Promise<APIResponse<KeyInfo>>;
559
+ }
560
+
561
+ /**
562
+ * A simplified market item for the ticker.
563
+ */
564
+ interface TickerItem {
565
+ /** Market ID */
566
+ id: string;
567
+ /** Market question */
568
+ question: string;
569
+ /** Primary outcome probability */
570
+ probability: number;
571
+ /** Source platform */
572
+ source: MarketSource;
573
+ }
574
+ /**
575
+ * Parameters for listing ticker items.
576
+ */
577
+ interface TickerListParams {
578
+ /** Maximum items (default: 12, max: 20) */
579
+ limit?: number;
580
+ }
581
+
582
+ declare class Ticker {
583
+ private client;
584
+ constructor(client: BaseClient);
585
+ /**
586
+ * List ticker items (public, no auth required).
587
+ *
588
+ * @example
589
+ * ```ts
590
+ * const { data: items } = await client.ticker.list({ limit: 10 });
591
+ * for (const item of items) {
592
+ * console.log(`${item.question}: ${(item.probability * 100).toFixed(0)}%`);
593
+ * }
594
+ * ```
595
+ */
596
+ list(params?: TickerListParams): Promise<APIResponse<TickerItem[]>>;
597
+ }
598
+
599
+ /**
600
+ * Propheseer SDK client for the prediction markets API.
601
+ *
602
+ * @example
603
+ * ```ts
604
+ * import Propheseer from 'propheseer';
605
+ *
606
+ * const client = new Propheseer({ apiKey: 'pk_test_...' });
607
+ *
608
+ * // List markets
609
+ * const page = await client.markets.list({ source: 'polymarket' });
610
+ * console.log(page.data);
611
+ *
612
+ * // Find arbitrage (Pro+)
613
+ * const { data: opportunities } = await client.arbitrage.find();
614
+ *
615
+ * // Check your usage
616
+ * const { data: keyInfo } = await client.keys.me();
617
+ * ```
618
+ */
619
+ declare class Propheseer extends BaseClient {
620
+ /** List and search prediction markets */
621
+ readonly markets: Markets;
622
+ /** List market categories */
623
+ readonly categories: Categories;
624
+ /** Find cross-platform arbitrage opportunities (Pro+) */
625
+ readonly arbitrage: Arbitrage;
626
+ /** Detect unusual trading activity (Pro+) */
627
+ readonly unusualTrades: UnusualTrades;
628
+ /** Access historical market snapshots (Business+) */
629
+ readonly history: History;
630
+ /** Get API key info and usage statistics */
631
+ readonly keys: Keys;
632
+ /** Public market ticker (no auth required) */
633
+ readonly ticker: Ticker;
634
+ constructor(options?: ClientOptions);
635
+ }
636
+
637
+ /**
638
+ * WebSocket message types received from the server.
639
+ */
640
+ interface WSConnectedMessage {
641
+ type: 'connected';
642
+ sessionId: string;
643
+ plan: string;
644
+ limits: {
645
+ maxSubscriptions: number;
646
+ messagesPerMinute: number;
647
+ maxConnections: number;
648
+ monthlyDataMB: number;
649
+ };
650
+ }
651
+ interface WSMarketUpdateMessage {
652
+ type: 'market_update';
653
+ market: Record<string, unknown>;
654
+ timestamp: string;
655
+ }
656
+ interface WSMarketSnapshotMessage {
657
+ type: 'market_snapshot';
658
+ market: Record<string, unknown>;
659
+ timestamp: string;
660
+ }
661
+ interface WSSubscribedMessage {
662
+ type: 'subscribed';
663
+ markets: string[];
664
+ alreadySubscribed: string[];
665
+ notFound: string[];
666
+ subscriptionCount: number;
667
+ }
668
+ interface WSUnsubscribedMessage {
669
+ type: 'unsubscribed';
670
+ markets: string[];
671
+ notSubscribed: string[];
672
+ subscriptionCount: number;
673
+ }
674
+ interface WSSubscriptionsMessage {
675
+ type: 'subscriptions';
676
+ markets: string[];
677
+ count: number;
678
+ }
679
+ interface WSPongMessage {
680
+ type: 'pong';
681
+ timestamp: string;
682
+ }
683
+ interface WSErrorMessage {
684
+ type: 'error';
685
+ code: string;
686
+ message: string;
687
+ }
688
+ type WSMessage = WSConnectedMessage | WSMarketUpdateMessage | WSMarketSnapshotMessage | WSSubscribedMessage | WSUnsubscribedMessage | WSSubscriptionsMessage | WSPongMessage | WSErrorMessage;
689
+ interface PropheseerWebSocketOptions {
690
+ /** API key for authentication */
691
+ apiKey?: string;
692
+ /** Base WebSocket URL (default: wss://api.propheseer.com) */
693
+ baseURL?: string;
694
+ /** Whether to automatically reconnect on disconnect (default: true) */
695
+ reconnect?: boolean;
696
+ /** Maximum reconnection attempts (default: 5) */
697
+ maxReconnectAttempts?: number;
698
+ /** Ping interval in ms to keep connection alive (default: 25000) */
699
+ pingInterval?: number;
700
+ }
701
+ interface PropheseerWebSocketEvents {
702
+ connected: (message: WSConnectedMessage) => void;
703
+ market_update: (message: WSMarketUpdateMessage) => void;
704
+ market_snapshot: (message: WSMarketSnapshotMessage) => void;
705
+ subscribed: (message: WSSubscribedMessage) => void;
706
+ unsubscribed: (message: WSUnsubscribedMessage) => void;
707
+ error: (error: WSErrorMessage | Error) => void;
708
+ disconnect: (code: number, reason: string) => void;
709
+ reconnect: (attempt: number) => void;
710
+ }
711
+ /**
712
+ * WebSocket client for real-time market updates.
713
+ *
714
+ * @example
715
+ * ```ts
716
+ * const ws = new PropheseerWebSocket({ apiKey: 'pk_test_...' });
717
+ *
718
+ * ws.on('connected', (msg) => {
719
+ * console.log('Connected:', msg.sessionId);
720
+ * ws.subscribe(['pm_12345', 'ks_67890']);
721
+ * });
722
+ *
723
+ * ws.on('market_update', (msg) => {
724
+ * console.log('Update:', msg.market);
725
+ * });
726
+ *
727
+ * await ws.connect();
728
+ * ```
729
+ */
730
+ declare class PropheseerWebSocket extends EventEmitter {
731
+ private apiKey;
732
+ private baseURL;
733
+ private reconnectEnabled;
734
+ private maxReconnectAttempts;
735
+ private pingIntervalMs;
736
+ private ws;
737
+ private pingTimer;
738
+ private reconnectAttempts;
739
+ private subscribedMarkets;
740
+ private closed;
741
+ constructor(options?: PropheseerWebSocketOptions);
742
+ /**
743
+ * Connect to the WebSocket server.
744
+ */
745
+ connect(): Promise<void>;
746
+ /**
747
+ * Subscribe to real-time updates for specific market IDs.
748
+ */
749
+ subscribe(marketIds: string[]): void;
750
+ /**
751
+ * Unsubscribe from market updates.
752
+ */
753
+ unsubscribe(marketIds: string[]): void;
754
+ /**
755
+ * Request the current list of subscribed markets.
756
+ */
757
+ listSubscriptions(): void;
758
+ /**
759
+ * Close the WebSocket connection.
760
+ */
761
+ close(): void;
762
+ private handleMessage;
763
+ private send;
764
+ private getReadyState;
765
+ private startPing;
766
+ private stopPing;
767
+ private attemptReconnect;
768
+ private getWebSocketConstructor;
769
+ }
770
+
771
+ declare const VERSION = "0.1.0";
772
+
773
+ /**
774
+ * Base error class for all Propheseer SDK errors.
775
+ */
776
+ declare class PropheseerError extends Error {
777
+ /** HTTP status code (if applicable) */
778
+ readonly status: number | undefined;
779
+ /** Error code from the API */
780
+ readonly code: string | undefined;
781
+ /** Response headers */
782
+ readonly headers: Headers | undefined;
783
+ constructor(message: string, options?: {
784
+ status?: number;
785
+ code?: string;
786
+ headers?: Headers;
787
+ });
788
+ }
789
+ /**
790
+ * Thrown when the API key is missing or invalid (HTTP 401).
791
+ */
792
+ declare class AuthenticationError extends PropheseerError {
793
+ constructor(message: string, headers?: Headers);
794
+ }
795
+ /**
796
+ * Thrown when the user has insufficient credits (HTTP 402).
797
+ */
798
+ declare class InsufficientCreditsError extends PropheseerError {
799
+ /** Current balance in cents */
800
+ readonly balanceCents: number | undefined;
801
+ /** Required amount in cents */
802
+ readonly requiredCents: number | undefined;
803
+ constructor(message: string, options?: {
804
+ balanceCents?: number;
805
+ requiredCents?: number;
806
+ headers?: Headers;
807
+ });
808
+ }
809
+ /**
810
+ * Thrown when the user lacks permission for the requested resource (HTTP 403).
811
+ */
812
+ declare class PermissionDeniedError extends PropheseerError {
813
+ /** Plan required to access the resource */
814
+ readonly requiredPlan: string | undefined;
815
+ constructor(message: string, options?: {
816
+ code?: string;
817
+ requiredPlan?: string;
818
+ headers?: Headers;
819
+ });
820
+ }
821
+ /**
822
+ * Thrown when the requested resource is not found (HTTP 404).
823
+ */
824
+ declare class NotFoundError extends PropheseerError {
825
+ constructor(message: string, headers?: Headers);
826
+ }
827
+ /**
828
+ * Thrown when rate limits are exceeded (HTTP 429).
829
+ */
830
+ declare class RateLimitError extends PropheseerError {
831
+ /** Seconds to wait before retrying */
832
+ readonly retryAfter: number | undefined;
833
+ constructor(message: string, options?: {
834
+ retryAfter?: number;
835
+ headers?: Headers;
836
+ });
837
+ }
838
+ /**
839
+ * Thrown when the API returns a server error (HTTP 5xx).
840
+ */
841
+ declare class InternalServerError extends PropheseerError {
842
+ constructor(message: string, options?: {
843
+ status?: number;
844
+ headers?: Headers;
845
+ });
846
+ }
847
+ /**
848
+ * Thrown when a network or connection error occurs.
849
+ */
850
+ declare class APIConnectionError extends PropheseerError {
851
+ readonly cause: Error | undefined;
852
+ constructor(message: string, options?: {
853
+ cause?: Error;
854
+ });
855
+ }
856
+
857
+ export { APIConnectionError, type APIResponse, type ArbitrageFindParams, type ArbitrageMarket, type ArbitrageOpportunity, AuthenticationError, type AutoPaginateOptions, type Category, type ClientOptions, type DetectionInfo, type DetectionReason, type HistoryListParams, InsufficientCreditsError, InternalServerError, type KeyInfo, type KeyUsage, type Market, type MarketCategory, type MarketHistoryEntry, type MarketListParams, type MarketSource, type MarketStatus, NotFoundError, type Outcome, Page, type PaginationMeta, PermissionDeniedError, type PlanLimits, Propheseer, PropheseerError, PropheseerWebSocket, type PropheseerWebSocketEvents, type PropheseerWebSocketOptions, RateLimitError, type RateLimitInfo, type SnapshotDate, type TickerItem, type TickerListParams, type TradeDetails, type TradeSide, type UnusualTrade, type UnusualTradeListParams, type UnusualTradeMarket, type UsageHistoryEntry, VERSION, type WSConnectedMessage, type WSErrorMessage, type WSMarketSnapshotMessage, type WSMarketUpdateMessage, type WSMessage, type WSSubscribedMessage, type WSUnsubscribedMessage, autoPaginate, Propheseer as default };