polyedge 0.0.0-stage → 1.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,1094 @@
1
+ import { EventEmitter } from 'node:events';
2
+
3
+ /**
4
+ * PolyEdge API Data Models
5
+ * Aligned with PolyEdge OpenAPI 3.1.0 specification.
6
+ */
7
+ type Side = "BUY" | "SELL";
8
+ type TokenIndex = 0 | 1;
9
+ /**
10
+ * Data model for ActiveSessionInfo
11
+ */
12
+ interface ActiveSessionInfo {
13
+ /** Masked API credential used to authenticate the stream connection */
14
+ api_key?: string;
15
+ /** Remote IP address of the connected client */
16
+ client_ip?: string;
17
+ /** In-memory unique connection ID (prefixed with conn_) */
18
+ conn_id?: string;
19
+ /** ISO 8601 timestamp when the SSE connection was established */
20
+ connected_at?: string;
21
+ /** Total active connection uptime in seconds */
22
+ duration_seconds?: number;
23
+ /** Total number of live matched order events delivered over this connection */
24
+ pushed_tx_count?: number;
25
+ /** Unique persistent stream identifier (UUID) */
26
+ stream_id?: string;
27
+ /** HTTP User-Agent identifier of the client library or application */
28
+ user_agent?: string;
29
+ }
30
+ /**
31
+ * Data model for CreateAPIKeyRequest
32
+ */
33
+ interface CreateAPIKeyRequest {
34
+ key?: string;
35
+ name?: string;
36
+ }
37
+ /**
38
+ * Data model for DeleteKeyResponse
39
+ */
40
+ interface DeleteKeyResponse {
41
+ id?: string;
42
+ }
43
+ /**
44
+ * Data model for DeleteStreamResponse
45
+ */
46
+ interface DeleteStreamResponse {
47
+ id?: string;
48
+ }
49
+ /**
50
+ * Data model for DepositItem
51
+ */
52
+ interface DepositItem {
53
+ /** Trader's Ethereum wallet address */
54
+ address?: string;
55
+ /** Total number of deposits within the 60-day window */
56
+ deposit_count?: number;
57
+ /** Earliest deposit timestamp in 60-day window (RFC3339 UTC) */
58
+ first_deposit_at?: string;
59
+ /** First executed trade timestamp (RFC3339 UTC) */
60
+ first_trade_at?: string;
61
+ /** Most recent deposit timestamp (RFC3339 UTC) */
62
+ last_deposit_at?: string;
63
+ /** Most recent executed trade timestamp (RFC3339 UTC) */
64
+ last_trade_at?: string;
65
+ /** Current pUSD wallet balance in micro-USD (6 decimals) */
66
+ pusd_balance?: number;
67
+ /** Net cumulative pUSD cashflow generated from trading activities (6 decimals) */
68
+ pusd_trade_balance?: number;
69
+ /** Up to 10 latest on-chain deposit transactions (newest first) */
70
+ recent_deposits?: RecentDeposit[];
71
+ /** Cumulative 60-day deposit amount in micro-USD (6 decimals) */
72
+ total_deposit?: string;
73
+ }
74
+ /**
75
+ * Data model for DepositQueryResult
76
+ */
77
+ interface DepositQueryResult {
78
+ items?: DepositItem[];
79
+ total?: number;
80
+ updated_at?: string;
81
+ }
82
+ /**
83
+ * Data model for ErrorResponse
84
+ */
85
+ interface ErrorResponse {
86
+ error?: string;
87
+ message?: string;
88
+ }
89
+ /**
90
+ * Data model for HistoryMarket
91
+ */
92
+ interface HistoryMarket {
93
+ /** Market thumbnail image URL */
94
+ icon?: string;
95
+ /** Unique numeric prediction market identifier */
96
+ id?: number;
97
+ /** Raw JSON array of outcome display names, e.g. ["Yes", "No"] */
98
+ outcomes?: [string, string];
99
+ /** Full title question describing the market condition */
100
+ question?: string;
101
+ /** Timestamp when market officially settled (RFC 3339 UTC), or null if active */
102
+ resolved_at?: string;
103
+ /** Resolution outcome (-2: unresolved, -1: void/invalid, 0-100: payout percentage for Outcome 0, e.g. 100 = Outcome 0 won, 0 = Outcome 1 won, 50 = 50/50 split) */
104
+ result?: number;
105
+ /** URL slug of the recurring sports league or tournament series */
106
+ series_slug?: string;
107
+ /** URL-friendly slug identifying the market on Polymarket */
108
+ slug?: string;
109
+ }
110
+ /**
111
+ * Data model for HourlyStat
112
+ */
113
+ interface HourlyStat {
114
+ /** Aggregate capital cost basis in micro-USD (6 decimals) */
115
+ cost_basis?: number;
116
+ /** Total trading fees incurred in micro-USD (6 decimals) */
117
+ fee?: number;
118
+ /** 1-hour UTC bucket timestamp (ISO 8601) */
119
+ hour?: string;
120
+ /** Maker trading volume in micro-USD (6 decimals) */
121
+ maker_volume?: number;
122
+ /** Number of distinct prediction markets active or settled in this hour */
123
+ market_count?: number;
124
+ /** Realized net PnL in micro-USD (6 decimals) */
125
+ pnl?: number;
126
+ /** Taker trading volume in micro-USD (6 decimals) */
127
+ taker_volume?: number;
128
+ /** Number of profitable markets settled in this hour */
129
+ win_count?: number;
130
+ }
131
+ /**
132
+ * Data model for LeaderboardResponse
133
+ */
134
+ interface LeaderboardResponse {
135
+ /** Total count of matching traders for pagination */
136
+ total_count?: number;
137
+ /** Ranked array of trader performance summaries */
138
+ traders?: TraderSummary[];
139
+ }
140
+ /**
141
+ * Data model for LiveOrder
142
+ */
143
+ interface LiveOrder {
144
+ /** Execution and relayer fee paid in micro-USDC */
145
+ fee?: string;
146
+ /** Underlying signed off-chain CLOB limit order metadata */
147
+ order?: OrderInfo;
148
+ /** Market outcome label (e.g. "Yes", "No", "Up", "Down") */
149
+ outcome?: string;
150
+ /** Filled outcome shares amount represented as a 10^6 fixed-point decimal string */
151
+ shares?: string;
152
+ /** Order execution direction: "BUY" or "SELL" */
153
+ side?: Side;
154
+ /** 0-based index matching market.token_ids and market.outcomes */
155
+ token_ids_index?: 0 | 1;
156
+ /** Filled USDC notional amount in micro-USDC (10^6 scale) decimal string */
157
+ usdc?: string;
158
+ /** Trader account identity (wallet address and optional display pseudonym) */
159
+ user?: MonitorTrader;
160
+ }
161
+ /**
162
+ * Data model for LiveTransaction
163
+ */
164
+ interface LiveTransaction {
165
+ /** List of matched maker limit orders filled in this transaction */
166
+ makers?: LiveOrder[];
167
+ /** Associated Polymarket prediction market condition and metadata */
168
+ market?: Market;
169
+ /** Taker order execution details that initiated the match against the CLOB */
170
+ taker?: LiveOrder;
171
+ /** ISO 8601 UTC timestamp (millisecond precision) indicating when the pending transaction was detected in the mempool */
172
+ timestamp?: string;
173
+ /** Canonical Ethereum/Polygon on-chain transaction hash confirming the match execution */
174
+ tx_hash?: string;
175
+ }
176
+ /**
177
+ * Data model for Market
178
+ */
179
+ interface Market {
180
+ /** 32-byte hexadecimal condition ID from Gnosis Conditional Tokens */
181
+ condition_id?: string;
182
+ /** URL slug of the parent event containing this market */
183
+ event_slug?: string;
184
+ /** Sub-category item title within a grouped multi-market event */
185
+ group_item_title?: string;
186
+ /** Polymarket numeric prediction market identifier (e.g. 3688221) */
187
+ id?: number;
188
+ /** True if market operates under multi-outcome negative risk adapter */
189
+ neg_risk?: boolean;
190
+ /** Array of market outcome labels: [Outcome 1, Outcome 2] (e.g. ["Yes", "No"]) */
191
+ outcomes?: [string, string];
192
+ /** Full question describing the prediction market condition */
193
+ question?: string;
194
+ /** URL slug of the recurring sports league or tournament series */
195
+ series_slug?: string;
196
+ /** URL-friendly slug identifying the market on Polymarket */
197
+ slug?: string;
198
+ /** Sports market classification (e.g. moneyline, spread, over/under) */
199
+ sports_market_type?: string;
200
+ /** ISO 8601 UTC timestamp when trading began */
201
+ start_date?: string;
202
+ /** Canonical categorical tags for content filtering */
203
+ tags_slug?: string[];
204
+ /** ERC-1155 token IDs: [Token 1, Token 2] */
205
+ token_ids?: [string, string];
206
+ }
207
+ /**
208
+ * Data model for MarketDetailResponse
209
+ */
210
+ interface MarketDetailResponse {
211
+ /** Complete standardized market metadata matching exporter format */
212
+ market?: MarketMetadata;
213
+ /** Ranked list of top 20 profitable traders in this market */
214
+ top_earners?: MarketEarner[];
215
+ /** Total protocol and liquidity fees collected in micro-USD (6 decimals) */
216
+ total_fees?: number;
217
+ /** Total positive realized PnL distributed to winners in micro-USD (6 decimals) */
218
+ total_pnl_distributed?: number;
219
+ /** Total count of distinct wallet addresses that traded this market */
220
+ total_traders?: number;
221
+ /** Cumulative trading volume across all participants in micro-USD (6 decimals) */
222
+ total_volume?: number;
223
+ /** Total number of distinct traders with positive realized PnL */
224
+ total_winners?: number;
225
+ }
226
+ /**
227
+ * Data model for MarketEarner
228
+ */
229
+ interface MarketEarner {
230
+ /** Executed fill orders for this earner (included when include_orders=true) */
231
+ orders?: UserOrder[];
232
+ /** Realized net profit and loss in micro-USD (6 decimals, e.g. 1000000 = 1 USD) */
233
+ pnl?: number;
234
+ /** Public identity dossier of the earner */
235
+ profile?: TraderIdentity;
236
+ /** Rank position among top earners in this market (1-based) */
237
+ rank?: number;
238
+ /** Return on investment percentage (e.g. 25.5 for 25.5%) */
239
+ roi?: number;
240
+ /** Total traded volume in micro-USD (6 decimals) */
241
+ volume?: number;
242
+ }
243
+ /**
244
+ * Data model for MarketMetadata
245
+ */
246
+ interface MarketMetadata {
247
+ /** 0x-prefixed 66-character CTF condition identifier */
248
+ condition_id?: string;
249
+ /** Timestamp when market was indexed in database (RFC 3339 UTC) */
250
+ created_at?: string;
251
+ /** Extended details and market resolution criteria */
252
+ description?: string;
253
+ /** Estimated resolution date or scheduled closing time (RFC 3339 UTC) */
254
+ end_date?: string;
255
+ /** URL slug of the parent event containing this market */
256
+ event_slug?: string;
257
+ /** Detailed fee schedule JSON specification */
258
+ fee_schedule?: Record<string, any>;
259
+ /** Fee model classification (e.g. "dynamic", "fixed") */
260
+ fee_type?: string;
261
+ /** Whether trading fees are activated on this market */
262
+ fees_enabled?: boolean;
263
+ /** Threshold for numerical interval outcomes if applicable */
264
+ group_item_threshold?: number;
265
+ /** Sub-category item title within a grouped multi-market event */
266
+ group_item_title?: string;
267
+ /** Market thumbnail image URL */
268
+ icon?: string;
269
+ /** Unique numeric prediction market identifier */
270
+ id?: number;
271
+ /** True if market operates under multi-outcome negative risk adapter */
272
+ neg_risk?: boolean;
273
+ /** Raw JSON array of outcome display names, e.g. ["Yes", "No"] */
274
+ outcomes?: [string, string];
275
+ /** Full title question describing the market condition */
276
+ question?: string;
277
+ /** Source URL or oracle specification for resolution */
278
+ resolution_source?: string;
279
+ /** Timestamp when the market officially settled (RFC 3339 UTC), or null if active */
280
+ resolved_at?: string;
281
+ /** Resolution outcome (-2: unresolved, -1: void/invalid, 0-100: payout percentage for Outcome 0, e.g. 100 = Outcome 0 won, 0 = Outcome 1 won, 50 = 50/50 split) */
282
+ result?: number;
283
+ /** URL slug of the recurring sports league or tournament series */
284
+ series_slug?: string;
285
+ /** URL-friendly slug identifying the market on Polymarket */
286
+ slug?: string;
287
+ /** Sports market classification type if applicable */
288
+ sports_market_type?: string;
289
+ /** Timestamp when trading began (RFC 3339 UTC) */
290
+ start_date?: string;
291
+ /** Raw JSON array of topic tag URL slugs */
292
+ tags_slug?: string[];
293
+ /** Array of 2 ERC-1155 token IDs corresponding to outcomes */
294
+ token_ids?: [string, string];
295
+ }
296
+ /**
297
+ * Data model for MarketSettlementDetail
298
+ */
299
+ interface MarketSettlementDetail {
300
+ /** ISO 8601 UTC timestamp of the trader's last trade in this market */
301
+ last_trade_at?: string;
302
+ /** Concise standardized market metadata */
303
+ market?: HistoryMarket;
304
+ /** Detailed order fill events (present only when include_orders=true) */
305
+ orders?: UserOrder[];
306
+ /** Realized net PnL in micro-USD (6 decimals) */
307
+ pnl?: number;
308
+ /** Return on investment percentage in this market */
309
+ roi?: number;
310
+ /** Total traded volume in this market in micro-USD (6 decimals) */
311
+ volume?: number;
312
+ }
313
+ /**
314
+ * Data model for MonitorTrader
315
+ */
316
+ interface MonitorTrader {
317
+ /** Canonical 42-character hexadecimal Ethereum/Polygon wallet address */
318
+ address?: string;
319
+ /** Polymarket public username */
320
+ name?: string;
321
+ }
322
+ /**
323
+ * Data model for OrderInfo
324
+ */
325
+ interface OrderInfo {
326
+ /** Cryptographic EIP-712 order hash identifying the unique off-chain order */
327
+ order_hash?: string;
328
+ /** Original clob order shares capacity in 10^6 scale */
329
+ shares?: string;
330
+ /** Signature scheme encoding (0: Direct EOA, 1: Magic / Proxy Wallet, 2: Gnosis Safe, 3: Deposit Wallet (ERC-1271)) */
331
+ signature_type?: number;
332
+ /** Unix epoch seconds when the order was signed */
333
+ timestamp?: string;
334
+ /** Original clob order notional value in micro-USDC (10^6 scale) */
335
+ usdc?: string;
336
+ }
337
+ /**
338
+ * Data model for QuoteSubscriptionRequest
339
+ */
340
+ interface QuoteSubscriptionRequest {
341
+ billing_cycle?: string;
342
+ promo_code?: string;
343
+ tier?: string;
344
+ }
345
+ /**
346
+ * Data model for QuoteSubscriptionResponse
347
+ */
348
+ interface QuoteSubscriptionResponse {
349
+ amount_to_pay?: number;
350
+ billing_cycle?: string;
351
+ can_afford?: boolean;
352
+ current_balance?: number;
353
+ current_billing_cycle?: string;
354
+ current_license?: string;
355
+ current_tier?: string;
356
+ discount_amount?: number;
357
+ duration_days?: number;
358
+ is_active?: boolean;
359
+ license?: string;
360
+ message?: string;
361
+ original_price?: number;
362
+ prorated_credit?: number;
363
+ tier?: string;
364
+ }
365
+ /**
366
+ * Data model for RecentDeposit
367
+ */
368
+ interface RecentDeposit {
369
+ /** Deposited collateral amount in micro-USD (6 decimals, e.g. 100000000 for 100 USDC) */
370
+ amount?: number;
371
+ /** Source funding address (0x...) */
372
+ from?: string;
373
+ /** Deposit execution timestamp in RFC3339 UTC format */
374
+ time?: string;
375
+ /** On-chain transaction hash (0x...) */
376
+ tx_hash?: string;
377
+ }
378
+ /**
379
+ * Data model for SubscribeRequest
380
+ */
381
+ interface SubscribeRequest {
382
+ billing_cycle?: string;
383
+ idempotency_key?: string;
384
+ promo_code?: string;
385
+ tier?: string;
386
+ }
387
+ /**
388
+ * Data model for SubscribeResponse
389
+ */
390
+ interface SubscribeResponse {
391
+ subscription?: UserSubscription;
392
+ user?: UserProfile;
393
+ }
394
+ /**
395
+ * Data model for TagStat
396
+ */
397
+ interface TagStat {
398
+ /** Passive maker volume in micro-USD (6 decimals) */
399
+ maker_volume?: number;
400
+ /** Number of markets traded in this tag */
401
+ markets_count?: number;
402
+ /** Realized net PnL in micro-USD (6 decimals) */
403
+ pnl?: number;
404
+ /** Return on investment percentage for this tag */
405
+ roi?: number;
406
+ /** Category tag URL slug (e.g. "crypto", "politics", "sports") */
407
+ slug?: string;
408
+ /** Aggressive taker volume in micro-USD (6 decimals) */
409
+ taker_volume?: number;
410
+ /** Aggregated trading volume in micro-USD (6 decimals) */
411
+ volume?: number;
412
+ /** Win rate percentage for this tag (0.0 to 100.0) */
413
+ win_rate?: number;
414
+ /** Number of profitable markets in this tag */
415
+ wins_count?: number;
416
+ }
417
+ /**
418
+ * Data model for Tier
419
+ */
420
+ interface Tier {
421
+ /** Whether the tier is permitted to access REST API endpoints */
422
+ allow_rest_api?: boolean;
423
+ /** Whether the tier is permitted to access real-time stream endpoints */
424
+ allow_stream?: boolean;
425
+ /** Whether this tier supports a trial subscription */
426
+ allow_trial?: boolean;
427
+ /** Record creation timestamp */
428
+ created_at?: string;
429
+ /** Unique tier identifier (e.g. "free", "starter", "individual", "builder") */
430
+ id?: string;
431
+ /** Relative tier rank for upgrade comparison (0=free, 1=starter, etc.) */
432
+ level?: number;
433
+ /** License type: "personal" or "builder" */
434
+ license?: string;
435
+ /** Maximum API queries allowed per 24-hour UTC window (0 = unlimited) */
436
+ max_daily_requests?: number;
437
+ /** Maximum aggregated streaming seconds allowed per 24-hour UTC window */
438
+ max_daily_stream_seconds?: number;
439
+ /** Maximum wallet addresses that can be filtered per stream */
440
+ max_filter_addrs?: number;
441
+ /** Maximum market series allowed across active streams (0 = disabled) */
442
+ max_filter_series?: number;
443
+ /** Maximum market tags allowed across active streams (0 = disabled) */
444
+ max_filter_tags?: number;
445
+ /** Maximum concurrent API keys allowed per account */
446
+ max_keys?: number;
447
+ /** Maximum unfiltered streams allowed */
448
+ max_naked_streams?: number;
449
+ /** Maximum API queries allowed per second */
450
+ max_qps?: number;
451
+ /** Maximum concurrent active SSE connections per account */
452
+ max_sessions?: number;
453
+ /** Maximum persistent stream IDs the user can create */
454
+ max_streams?: number;
455
+ /** Monthly credit quota allocated to this tier */
456
+ monthly_credits?: number;
457
+ /** Display title of the tier */
458
+ name?: string;
459
+ /** 6 decimals, micro-USD (e.g. 99_000_000 = 99 USD) */
460
+ price_monthly?: number;
461
+ /** 6 decimals, micro-USD (e.g. 237_000_000 = 237 USD) */
462
+ price_quarterly?: number;
463
+ /** 6 decimals, micro-USD for trial (e.g. 10_000_000 = 10 USD) */
464
+ price_trial?: number;
465
+ /** 6 decimals, micro-USD (e.g. 499_000_000 = 499 USD) */
466
+ price_yearly?: number;
467
+ /** Duration in days for trial subscription (e.g. 5) */
468
+ trial_duration_days?: number;
469
+ /** Last modification timestamp */
470
+ updated_at?: string;
471
+ }
472
+ /**
473
+ * Data model for TraderHistoryResponse
474
+ */
475
+ interface TraderHistoryResponse {
476
+ /** Paginated list of market settlement details */
477
+ history?: MarketSettlementDetail[];
478
+ /** Total count of matching market positions for pagination */
479
+ total_count?: number;
480
+ }
481
+ /**
482
+ * Data model for TraderHourlyStatsResponse
483
+ */
484
+ interface TraderHourlyStatsResponse {
485
+ /** Chronological array of 1-hour performance metrics */
486
+ stats?: HourlyStat[];
487
+ }
488
+ /**
489
+ * Data model for TraderIdentity
490
+ */
491
+ interface TraderIdentity {
492
+ /** Checksummed 0x-prefixed EVM wallet address */
493
+ address?: string;
494
+ /** Custom display name or Polymarket profile username */
495
+ name?: string;
496
+ /** ISO 8601 UTC timestamp of Polymarket profile creation */
497
+ profile_created_at?: string;
498
+ /** Public avatar image URL */
499
+ profile_image?: string;
500
+ /** Linked X (formerly Twitter) social handle */
501
+ x_username?: string;
502
+ }
503
+ /**
504
+ * Data model for TraderProfileResponse
505
+ */
506
+ interface TraderProfileResponse {
507
+ /** ISO 8601 UTC timestamp of trader's most recent trade across the platform */
508
+ last_trade_at?: string;
509
+ /** Public identity dossier of the trader */
510
+ profile?: TraderIdentity;
511
+ /** Trader's pUSD balance in micro-pUSD (6 decimals, e.g. 1000000 = 1 pUSD) */
512
+ pusd_balance?: number;
513
+ /** Polymarket Taker Rebate tier level (0-6: 0=Tier 0, 1=Bronze, 2=Silver, 3=Gold, 4=Platinum, 5=Diamond, 6=Obsidian) */
514
+ taker_tier?: number;
515
+ /** Descriptive taker rebate tier name ("Tier 0", "Bronze", "Silver", "Gold", "Platinum", "Diamond", "Obsidian", or "" if unsynced) */
516
+ taker_tier_name?: string;
517
+ /** Performance breakdown across top 5 categories in last 30 days */
518
+ top_tags?: TagStat[];
519
+ /** Rolling 30-day taker Weighted Volume (wV) in USD, calculated by Trade Size * (1 - Entry Price) * Category Weight * Bonuses */
520
+ weighted_volume?: number;
521
+ }
522
+ /**
523
+ * Data model for TraderSummary
524
+ */
525
+ interface TraderSummary {
526
+ /** ISO 8601 UTC timestamp of trader's most recent trade across the platform */
527
+ last_trade_at?: string;
528
+ /** Number of distinct prediction markets traded in timeframe */
529
+ markets_count?: number;
530
+ /** Public identity dossier of the trader */
531
+ profile?: TraderIdentity;
532
+ /** Leaderboard ranking position (1-based) */
533
+ rank?: number;
534
+ /** Return on investment percentage over timeframe (e.g. 25.5 for 25.5%) */
535
+ roi?: number;
536
+ /** Realized net profit and loss in micro-USD (6 decimals, e.g. 1000000 = 1 USD) */
537
+ total_pnl?: number;
538
+ /** Aggregated trading volume in micro-USD (6 decimals) */
539
+ total_volume?: number;
540
+ /** Percentage of profitable closed positions (0.0 to 100.0) */
541
+ win_rate?: number;
542
+ /** Number of profitable settled markets in timeframe */
543
+ wins_count?: number;
544
+ }
545
+ /**
546
+ * Data model for UpdateSubscriptionRequest
547
+ */
548
+ interface UpdateSubscriptionRequest {
549
+ addresses?: string[];
550
+ series?: string[];
551
+ tags?: string[];
552
+ }
553
+ /**
554
+ * Data model for UserAPIKey
555
+ */
556
+ interface UserAPIKey {
557
+ created_at?: string;
558
+ key?: string;
559
+ name?: string;
560
+ status?: number;
561
+ }
562
+ /**
563
+ * Data model for UserActiveSessionsResponse
564
+ */
565
+ interface UserActiveSessionsResponse {
566
+ /** Array of active connected client session metadata */
567
+ data?: ActiveSessionInfo[];
568
+ /** Total concurrent active sessions currently running across all user streams */
569
+ total_count?: number;
570
+ }
571
+ /**
572
+ * Data model for UserCreateStreamRequest
573
+ */
574
+ interface UserCreateStreamRequest {
575
+ addresses?: string[];
576
+ name?: string;
577
+ series?: string[];
578
+ tags?: string[];
579
+ }
580
+ /**
581
+ * Data model for UserDisconnectSessionResponse
582
+ */
583
+ interface UserDisconnectSessionResponse {
584
+ conn_id?: string;
585
+ message?: string;
586
+ status?: string;
587
+ }
588
+ /**
589
+ * Data model for UserKeysResponse
590
+ */
591
+ interface UserKeysResponse {
592
+ data?: UserAPIKey[];
593
+ total_count?: number;
594
+ }
595
+ /**
596
+ * Data model for UserLedgerEntry
597
+ */
598
+ interface UserLedgerEntry {
599
+ amount?: number;
600
+ balance_after?: number;
601
+ created_at?: string;
602
+ reference_id?: string;
603
+ type?: string;
604
+ }
605
+ /**
606
+ * Data model for UserLedgerResponse
607
+ */
608
+ interface UserLedgerResponse {
609
+ data?: UserLedgerEntry[];
610
+ total_count?: number;
611
+ }
612
+ /**
613
+ * Data model for UserOrder
614
+ */
615
+ interface UserOrder {
616
+ /** Protocol trading fee deducted in micro-USD (6 decimals) */
617
+ fee?: number;
618
+ /** True if executed against resting book liquidity as a taker */
619
+ is_taker?: boolean;
620
+ /** Prediction outcome label (e.g. "Yes", "No") */
621
+ outcome?: string;
622
+ /** Filled outcome token shares (6 decimals) */
623
+ shares?: number;
624
+ /** Order execution side: "BUY" or "SELL" */
625
+ side?: Side;
626
+ /** ISO 8601 UTC timestamp of order fill execution */
627
+ time?: string;
628
+ /** Total collateral USDC transferred (6 decimals micro-USD) */
629
+ usdc?: number;
630
+ }
631
+ /**
632
+ * Data model for UserOrdersResponse
633
+ */
634
+ interface UserOrdersResponse {
635
+ /** Chronological list of compacted order fill events */
636
+ orders?: UserOrder[];
637
+ }
638
+ /**
639
+ * Data model for UserProfile
640
+ */
641
+ interface UserProfile {
642
+ billing_cycle?: string;
643
+ created_at?: string;
644
+ deposit_address?: string;
645
+ deposit_balance?: number;
646
+ email?: string;
647
+ is_expired?: boolean;
648
+ status?: number;
649
+ telegram_id?: number;
650
+ tier?: string;
651
+ tier_expires_at?: string;
652
+ updated_at?: string;
653
+ }
654
+ /**
655
+ * Data model for UserSessionHistoryResponse
656
+ */
657
+ interface UserSessionHistoryResponse {
658
+ /** Array of historical stream session records */
659
+ data?: UserSessionRecord[];
660
+ /** Total count of historical session records */
661
+ total_count?: number;
662
+ }
663
+ /**
664
+ * Data model for UserSessionRecord
665
+ */
666
+ interface UserSessionRecord {
667
+ /** Masked API credential used to authenticate the stream connection */
668
+ api_key?: string;
669
+ /** Remote IP address of the connected client */
670
+ client_ip?: string;
671
+ /** Diagnostic termination reason (e.g. client_closed, admin_force_disconnect, quota_exceeded) */
672
+ close_reason?: string;
673
+ /** ISO 8601 timestamp when the SSE connection was established */
674
+ connected_at?: string;
675
+ /** ISO 8601 timestamp when the connection was closed, or null if currently active */
676
+ disconnected_at?: string;
677
+ /** Total connection duration in seconds */
678
+ duration_seconds?: number;
679
+ /** Total number of live matched order events delivered over this connection */
680
+ pushed_tx_count?: number;
681
+ /** Target stream unique identifier (UUID) */
682
+ stream_id?: string;
683
+ /** HTTP User-Agent identifier of the client library or application */
684
+ user_agent?: string;
685
+ }
686
+ /**
687
+ * Data model for UserStreamResponse
688
+ */
689
+ interface UserStreamResponse {
690
+ active_sessions?: number;
691
+ addresses?: string[];
692
+ created_at?: string;
693
+ enabled?: boolean;
694
+ id?: string;
695
+ name?: string;
696
+ series?: string[];
697
+ tags?: string[];
698
+ updated_at?: string;
699
+ }
700
+ /**
701
+ * Data model for UserStreamsResponse
702
+ */
703
+ interface UserStreamsResponse {
704
+ data?: UserStreamResponse[];
705
+ total_count?: number;
706
+ }
707
+ /**
708
+ * Data model for UserSubscription
709
+ */
710
+ interface UserSubscription {
711
+ amount_paid?: number;
712
+ billing_cycle?: string;
713
+ created_at?: string;
714
+ discount_amount?: number;
715
+ duration_days?: number;
716
+ expires_at?: string;
717
+ original_price?: number;
718
+ plan_tier?: string;
719
+ promo_code?: string;
720
+ prorated_credit?: number;
721
+ starts_at?: string;
722
+ status?: string;
723
+ }
724
+ /**
725
+ * Data model for UserTelemetryResponse
726
+ */
727
+ interface UserTelemetryResponse {
728
+ date?: string;
729
+ endpoints?: Record<string, any>;
730
+ total_requests?: number;
731
+ }
732
+ /**
733
+ * Data model for UserUpdateKeyRequest
734
+ */
735
+ interface UserUpdateKeyRequest {
736
+ name?: string;
737
+ /** 1: Active, 0: Disabled */
738
+ status?: number;
739
+ }
740
+ /**
741
+ * Data model for UserUpdateStreamMetadataRequest
742
+ */
743
+ interface UserUpdateStreamMetadataRequest {
744
+ enabled?: boolean;
745
+ name?: string;
746
+ }
747
+ /**
748
+ * Data model for ValidatePromoCodeRequest
749
+ */
750
+ interface ValidatePromoCodeRequest {
751
+ billing_cycle?: string;
752
+ code?: string;
753
+ tier?: string;
754
+ }
755
+ /**
756
+ * Data model for ValidatePromoCodeResponse
757
+ */
758
+ interface ValidatePromoCodeResponse {
759
+ amount_to_pay?: number;
760
+ code?: string;
761
+ discount_amount?: number;
762
+ message?: string;
763
+ original_price?: number;
764
+ prorated_credit?: number;
765
+ valid?: boolean;
766
+ }
767
+
768
+ interface StreamOptions {
769
+ apiKey: string;
770
+ streamBaseUrl?: string;
771
+ heartbeatTimeoutMs?: number;
772
+ initialBackoffMs?: number;
773
+ maxBackoffMs?: number;
774
+ }
775
+ interface StreamEvents {
776
+ tx: (tx: LiveTransaction, eventId: string) => void;
777
+ heartbeat: () => void;
778
+ error: (err: Error) => void;
779
+ reconnect: (attempt: number, delayMs: number) => void;
780
+ close: (reason: string) => void;
781
+ }
782
+ declare class PolyEdgeStream extends EventEmitter {
783
+ private readonly streamId;
784
+ private readonly apiKey;
785
+ private readonly streamBaseUrl;
786
+ private readonly heartbeatTimeoutMs;
787
+ private readonly initialBackoffMs;
788
+ private readonly maxBackoffMs;
789
+ private lastEventId;
790
+ private abortController;
791
+ private watchdogTimer;
792
+ private reconnectTimer;
793
+ private reconnectAttempts;
794
+ private isDestroyed;
795
+ private isConnecting;
796
+ private asyncQueue;
797
+ private asyncResolvers;
798
+ constructor(streamId: string, options: StreamOptions);
799
+ getLastEventId(): string | null;
800
+ connect(): void;
801
+ private parseBlock;
802
+ private startWatchdog;
803
+ private resetWatchdog;
804
+ private clearWatchdog;
805
+ private clearTimers;
806
+ private scheduleReconnect;
807
+ private pushAsync;
808
+ [Symbol.asyncIterator](): AsyncGenerator<LiveTransaction, void, undefined>;
809
+ destroy(reason?: string): void;
810
+ }
811
+
812
+ interface PolyEdgeClientOptions {
813
+ /** API Key token for authentication */
814
+ apiKey: string;
815
+ /** Base URL for REST analytics & account gateway (default: https://api.polyedge.dev) */
816
+ apiBaseUrl?: string;
817
+ /** Base URL for SSE real-time streaming gateway (default: https://stream.polyedge.dev) */
818
+ streamBaseUrl?: string;
819
+ }
820
+ /** Base requester helper shared by services */
821
+ type Requester = <T>(baseUrl: string, endpoint: string, options?: RequestInit) => Promise<T>;
822
+ /** Streams Service: APIs for streams operations */
823
+ declare class StreamsService {
824
+ private readonly request;
825
+ private readonly apiBaseUrl;
826
+ private readonly streamBaseUrl;
827
+ private readonly apiKey;
828
+ constructor(request: Requester, apiBaseUrl: string, streamBaseUrl: string, apiKey: string);
829
+ /**
830
+ * Connect to real-time Server-Sent Events (SSE) order execution stream
831
+ * @param streamId Target stream ID
832
+ */
833
+ connect(streamId: string, options?: Partial<StreamOptions>): PolyEdgeStream;
834
+ /**
835
+ * List User Streams
836
+ * Returns custom and managed real-time trade streams configured by the user.
837
+ * @returns Models.UserStreamsResponse
838
+ */
839
+ list(): Promise<UserStreamsResponse>;
840
+ /**
841
+ * Create Filtered Order Stream
842
+ * Provisions a new custom real-time stream with optional address, tag, or series filters.
843
+ * @param req Request payload
844
+ * @returns Models.UserStreamResponse
845
+ */
846
+ create(req: UserCreateStreamRequest): Promise<UserStreamResponse>;
847
+ /**
848
+ * Get Stream Metadata
849
+ * Fetches metadata, active sessions count, and filter configuration for a specific stream.
850
+ * @param id Stream unique ID
851
+ * @returns Models.UserStreamResponse
852
+ */
853
+ get(id: string): Promise<UserStreamResponse>;
854
+ /**
855
+ * Delete Stream
856
+ * Permanently removes a stream and gracefully disconnects all connected listener sessions.
857
+ * @param id Stream unique ID
858
+ * @returns Models.DeleteStreamResponse
859
+ */
860
+ delete(id: string): Promise<DeleteStreamResponse>;
861
+ /**
862
+ * Update Stream Metadata
863
+ * Updates operational attributes of the stream, such as nickname or enabled/disabled status.
864
+ * @param id Stream unique ID
865
+ * @param req Request payload
866
+ * @returns Models.UserStreamResponse
867
+ */
868
+ updateMetadata(id: string, req: UserUpdateStreamMetadataRequest): Promise<UserStreamResponse>;
869
+ /**
870
+ * Update Stream Filter Subscription
871
+ * Dynamically mutates monitored wallet addresses, market tags, or series slugs without disconnecting SSE clients.
872
+ * @param id Stream unique ID
873
+ * @param req Request payload
874
+ * @returns Models.UserStreamResponse
875
+ */
876
+ updateSubscription(id: string, req: UpdateSubscriptionRequest): Promise<UserStreamResponse>;
877
+ /**
878
+ * List All User Active Sessions
879
+ * Returns all currently connected active SSE listeners for this account.
880
+ * @returns Models.UserActiveSessionsResponse
881
+ */
882
+ getActiveSessions(): Promise<UserActiveSessionsResponse>;
883
+ /**
884
+ * Disconnect User Stream Connection
885
+ * Terminates an active SSE stream connection owned by this account, identified by its conn_id from getActiveSessions.
886
+ * @param id Connection ID (conn_...)
887
+ * @returns Models.UserDisconnectSessionResponse
888
+ */
889
+ disconnectSession(id: string): Promise<UserDisconnectSessionResponse>;
890
+ /**
891
+ * List User Stream Session History
892
+ * Returns historical SSE connection logs including duration and pushed transactions count.
893
+ * @param params.limit Max records to return
894
+ * @param params.offset Pagination offset
895
+ * @returns Models.UserSessionHistoryResponse
896
+ */
897
+ getSessionHistory(params?: {
898
+ limit?: number;
899
+ offset?: number;
900
+ }): Promise<UserSessionHistoryResponse>;
901
+ }
902
+ /** Analytics Service: APIs for analytics operations */
903
+ declare class AnalyticsService {
904
+ private readonly request;
905
+ private readonly apiBaseUrl;
906
+ private readonly streamBaseUrl;
907
+ private readonly apiKey;
908
+ constructor(request: Requester, apiBaseUrl: string, streamBaseUrl: string, apiKey: string);
909
+ /**
910
+ * 60-Day Trader Deposit Analytics
911
+ * Returns 60-day aggregated deposit summary and individual transaction breakdown for top traders.
912
+ * @param params.limit Max records to return
913
+ * @param params.offset Pagination offset
914
+ * @returns Models.DepositQueryResult
915
+ */
916
+ getDeposits(params?: {
917
+ limit?: number;
918
+ offset?: number;
919
+ }): Promise<DepositQueryResult>;
920
+ /**
921
+ * Top Traders PnL Leaderboard
922
+ * Queries ranked traders across timeframes with PnL, volume, win rate, and performance metrics.
923
+ * @param params.limit Max traders to return
924
+ * @param params.offset Pagination offset
925
+ * @returns Models.LeaderboardResponse
926
+ */
927
+ getLeaderboard(params?: {
928
+ limit?: number;
929
+ offset?: number;
930
+ }): Promise<LeaderboardResponse>;
931
+ /**
932
+ * Get Prediction Market Detail
933
+ * Fetches standardized market metadata matching on-chain condition IDs and NegRisk parameters.
934
+ * @param id Market numeric ID or condition ID
935
+ * @returns Models.MarketDetailResponse
936
+ */
937
+ getMarket(id: string): Promise<MarketDetailResponse>;
938
+ /**
939
+ * Get Trader Intelligence Profile
940
+ * Fetches trader identity dossier, pUSD balance, total PnL, win rates, and ranking metrics.
941
+ * @param address Trader Polygon/Ethereum wallet address
942
+ * @returns Models.TraderProfileResponse
943
+ */
944
+ getTrader(address: string): Promise<TraderProfileResponse>;
945
+ /**
946
+ * Get Hourly PnL Equity Curve
947
+ * Provides 1-hour bucketed historical equity curves and trade metrics for a specific trader.
948
+ * @param address Trader Polygon/Ethereum wallet address
949
+ * @returns Models.TraderHourlyStatsResponse
950
+ */
951
+ getTraderHourlyStats(address: string): Promise<TraderHourlyStatsResponse>;
952
+ /**
953
+ * Get Trader Market Participation History
954
+ * Queries resolved and active prediction markets traded by the specified wallet address.
955
+ * @param address Trader Polygon/Ethereum wallet address
956
+ * @param params.limit Max markets to return
957
+ * @param params.offset Pagination offset
958
+ * @returns Models.TraderHistoryResponse
959
+ */
960
+ getTraderMarkets(address: string, params?: {
961
+ limit?: number;
962
+ offset?: number;
963
+ }): Promise<TraderHistoryResponse>;
964
+ /**
965
+ * Get Trader Orders in Market
966
+ * Retrieves granular fill events, side, price, and token outcomes for a trader in a given market.
967
+ * @param address Trader wallet address
968
+ * @param id Market numeric ID
969
+ * @param params.limit Max orders to return
970
+ * @param params.offset Pagination offset
971
+ * @returns Models.UserOrdersResponse
972
+ */
973
+ getTraderMarketOrders(address: string, id: string, params?: {
974
+ limit?: number;
975
+ offset?: number;
976
+ }): Promise<UserOrdersResponse>;
977
+ }
978
+ /** Account Service: APIs for account operations */
979
+ declare class AccountService {
980
+ private readonly request;
981
+ private readonly apiBaseUrl;
982
+ private readonly streamBaseUrl;
983
+ private readonly apiKey;
984
+ constructor(request: Requester, apiBaseUrl: string, streamBaseUrl: string, apiKey: string);
985
+ /**
986
+ * Get Current Profile
987
+ * Retrieves the authenticated user profile, tier subscription status, and available USDC balance.
988
+ * @returns Models.UserProfile
989
+ */
990
+ getProfile(): Promise<UserProfile>;
991
+ /**
992
+ * List API Keys
993
+ * Lists all active and revoked API keys issued to the authenticated account.
994
+ * @returns Models.UserKeysResponse
995
+ */
996
+ listKeys(): Promise<UserKeysResponse>;
997
+ /**
998
+ * Create API Key
999
+ * Generates a new authenticated API key token with optional memo label.
1000
+ * @param req Request payload
1001
+ * @returns Models.UserAPIKey
1002
+ */
1003
+ createKey(req: CreateAPIKeyRequest): Promise<UserAPIKey>;
1004
+ /**
1005
+ * Update API Key
1006
+ * Modifies label memo or operational status of an existing API key.
1007
+ * @param key API key string
1008
+ * @param req Request payload
1009
+ * @returns Models.UserAPIKey
1010
+ */
1011
+ updateKey(key: string, req: UserUpdateKeyRequest): Promise<UserAPIKey>;
1012
+ /**
1013
+ * Revoke API Key
1014
+ * Permanently revokes and deactivates an API key token.
1015
+ * @param key API key string
1016
+ * @returns Models.DeleteKeyResponse
1017
+ */
1018
+ deleteKey(key: string): Promise<DeleteKeyResponse>;
1019
+ /**
1020
+ * List User Balance Ledger
1021
+ * Lists chronological ledger entries (subscription billing charges, deposits, withdrawals).
1022
+ * @param params.limit Max entries to return
1023
+ * @param params.offset Pagination offset
1024
+ * @returns Models.UserLedgerResponse
1025
+ */
1026
+ getLedger(params?: {
1027
+ limit?: number;
1028
+ offset?: number;
1029
+ }): Promise<UserLedgerResponse>;
1030
+ /**
1031
+ * Get Account Telemetry & Limits
1032
+ * Provides live usage statistics, quota limits, and remaining streaming bandwidth.
1033
+ * @returns Models.UserTelemetryResponse
1034
+ */
1035
+ getTelemetry(): Promise<UserTelemetryResponse>;
1036
+ }
1037
+ /** Subscription Service: APIs for subscription operations */
1038
+ declare class SubscriptionService {
1039
+ private readonly request;
1040
+ private readonly apiBaseUrl;
1041
+ private readonly streamBaseUrl;
1042
+ private readonly apiKey;
1043
+ constructor(request: Requester, apiBaseUrl: string, streamBaseUrl: string, apiKey: string);
1044
+ /**
1045
+ * List Public Tiers Catalog
1046
+ * Returns plan tiers (Free, Starter, Pro, Growth, Whale) with limits and pricing details.
1047
+ * @returns Models.Tier[]
1048
+ */
1049
+ listTiers(): Promise<Tier[]>;
1050
+ /**
1051
+ * Get Subscription Quote
1052
+ * Calculates prorated billing amounts for subscribing to or upgrading a tier plan.
1053
+ * @param req Request payload
1054
+ * @returns Models.QuoteSubscriptionResponse
1055
+ */
1056
+ getQuote(req: QuoteSubscriptionRequest): Promise<QuoteSubscriptionResponse>;
1057
+ /**
1058
+ * Purchase / Upgrade Tier Subscription
1059
+ * Executes purchase, renewal, or upgrade of an active subscription tier plan.
1060
+ * @param req Request payload
1061
+ * @returns Models.SubscribeResponse
1062
+ */
1063
+ subscribe(req: SubscribeRequest): Promise<SubscribeResponse>;
1064
+ /**
1065
+ * Validate Promo Code
1066
+ * Verifies validity, discount percentage, and applicable plans for a promotion coupon code.
1067
+ * @param req Request payload
1068
+ * @returns Models.ValidatePromoCodeResponse
1069
+ */
1070
+ validatePromoCode(req: ValidatePromoCodeRequest): Promise<ValidatePromoCodeResponse>;
1071
+ }
1072
+ /**
1073
+ * PolyEdge API Client
1074
+ * Provides namespaced access to Streams, Analytics, Account, and Subscription services.
1075
+ */
1076
+ declare class PolyEdgeClient {
1077
+ private readonly apiKey;
1078
+ private readonly apiBaseUrl;
1079
+ private readonly streamBaseUrl;
1080
+ /** Streams Service: Real-time SSE trade streaming & filters */
1081
+ readonly streams: StreamsService;
1082
+ /** Analytics Service: Leaderboard, trader intelligence, markets */
1083
+ readonly analytics: AnalyticsService;
1084
+ /** Account Service: Profile, keys, ledger, telemetry */
1085
+ readonly account: AccountService;
1086
+ /** Subscription Service: Plan tiers, quotes, checkout */
1087
+ readonly subscription: SubscriptionService;
1088
+ constructor(options: PolyEdgeClientOptions);
1089
+ private request;
1090
+ /** Direct helper to create SSE order stream */
1091
+ stream(streamId: string, options?: Partial<StreamOptions>): PolyEdgeStream;
1092
+ }
1093
+
1094
+ export { AccountService, type ActiveSessionInfo, AnalyticsService, type CreateAPIKeyRequest, type DeleteKeyResponse, type DeleteStreamResponse, type DepositItem, type DepositQueryResult, type ErrorResponse, type HistoryMarket, type HourlyStat, type LeaderboardResponse, type LiveOrder, type LiveTransaction, type Market, type MarketDetailResponse, type MarketEarner, type MarketMetadata, type MarketSettlementDetail, type MonitorTrader, type OrderInfo, PolyEdgeClient, type PolyEdgeClientOptions, PolyEdgeStream, type QuoteSubscriptionRequest, type QuoteSubscriptionResponse, type RecentDeposit, type Requester, type Side, type StreamEvents, type StreamOptions, StreamsService, type SubscribeRequest, type SubscribeResponse, SubscriptionService, type TagStat, type Tier, type TokenIndex, type TraderHistoryResponse, type TraderHourlyStatsResponse, type TraderIdentity, type TraderProfileResponse, type TraderSummary, type UpdateSubscriptionRequest, type UserAPIKey, type UserActiveSessionsResponse, type UserCreateStreamRequest, type UserDisconnectSessionResponse, type UserKeysResponse, type UserLedgerEntry, type UserLedgerResponse, type UserOrder, type UserOrdersResponse, type UserProfile, type UserSessionHistoryResponse, type UserSessionRecord, type UserStreamResponse, type UserStreamsResponse, type UserSubscription, type UserTelemetryResponse, type UserUpdateKeyRequest, type UserUpdateStreamMetadataRequest, type ValidatePromoCodeRequest, type ValidatePromoCodeResponse };