@alango/dr-manhattan 0.1.3 → 0.1.4

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/dist/index.d.ts CHANGED
@@ -3,70 +3,14 @@ import WebSocket from 'ws';
3
3
  import pino from 'pino';
4
4
  import { Socket } from 'socket.io-client';
5
5
 
6
- /**
7
- * Order-related types for prediction market trading.
8
- */
9
- /** Order side - buy or sell */
10
- declare const OrderSide: {
11
- readonly BUY: "buy";
12
- readonly SELL: "sell";
13
- };
14
- type OrderSide = (typeof OrderSide)[keyof typeof OrderSide];
15
- /** Order status */
16
- declare const OrderStatus: {
17
- readonly PENDING: "pending";
18
- readonly OPEN: "open";
19
- readonly FILLED: "filled";
20
- readonly PARTIALLY_FILLED: "partially_filled";
21
- readonly CANCELLED: "cancelled";
22
- readonly REJECTED: "rejected";
23
- };
24
- type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus];
25
- /** Order representation */
26
- interface Order {
27
- /** Unique order identifier */
28
- id: string;
29
- /** Market identifier */
30
- marketId: string;
31
- /** Outcome being traded */
32
- outcome: string;
33
- /** Buy or sell */
34
- side: OrderSide;
35
- /** Price per share (0-1) */
36
- price: number;
37
- /** Total order size */
38
- size: number;
39
- /** Amount filled */
40
- filled: number;
41
- /** Current status */
42
- status: OrderStatus;
43
- /** Creation timestamp */
44
- createdAt: Date;
45
- /** Last update timestamp */
46
- updatedAt?: Date;
47
- }
48
- /** Helper functions for Order */
49
- declare const OrderUtils: {
50
- /** Get remaining unfilled amount */
51
- readonly remaining: (order: Order) => number;
52
- /** Check if order is still active */
53
- readonly isActive: (order: Order) => boolean;
54
- /** Check if order is completely filled */
55
- readonly isFilled: (order: Order) => boolean;
56
- /** Get fill percentage (0-1) */
57
- readonly fillPercentage: (order: Order) => number;
58
- };
59
- /** Parameters for creating a new order */
60
- interface CreateOrderParams {
61
- marketId: string;
62
- outcome: string;
63
- side: OrderSide;
64
- price: number;
65
- size: number;
66
- /** Token ID (required for some exchanges) */
67
- tokenId?: string;
68
- /** Additional exchange-specific parameters */
69
- params?: Record<string, unknown>;
6
+ type MarketDirection = 'up' | 'down';
7
+ type CryptoMarketType = 'up_down' | 'strike_price';
8
+ interface CryptoHourlyMarket {
9
+ tokenSymbol: string;
10
+ expiryTime: Date;
11
+ strikePrice: number | null;
12
+ direction?: MarketDirection;
13
+ marketType?: CryptoMarketType;
70
14
  }
71
15
 
72
16
  /**
@@ -130,43 +74,70 @@ interface FetchMarketsParams {
130
74
  }
131
75
 
132
76
  /**
133
- * Position-related types for tracking holdings.
77
+ * Order-related types for prediction market trading.
134
78
  */
135
- /** Represents a position in a prediction market */
136
- interface Position {
79
+ /** Order side - buy or sell */
80
+ declare const OrderSide: {
81
+ readonly BUY: "buy";
82
+ readonly SELL: "sell";
83
+ };
84
+ type OrderSide = (typeof OrderSide)[keyof typeof OrderSide];
85
+ /** Order status */
86
+ declare const OrderStatus: {
87
+ readonly PENDING: "pending";
88
+ readonly OPEN: "open";
89
+ readonly FILLED: "filled";
90
+ readonly PARTIALLY_FILLED: "partially_filled";
91
+ readonly CANCELLED: "cancelled";
92
+ readonly REJECTED: "rejected";
93
+ };
94
+ type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus];
95
+ /** Order representation */
96
+ interface Order {
97
+ /** Unique order identifier */
98
+ id: string;
137
99
  /** Market identifier */
138
100
  marketId: string;
139
- /** Outcome held */
101
+ /** Outcome being traded */
140
102
  outcome: string;
141
- /** Position size (number of shares) */
103
+ /** Buy or sell */
104
+ side: OrderSide;
105
+ /** Price per share (0-1) */
106
+ price: number;
107
+ /** Total order size */
142
108
  size: number;
143
- /** Average entry price */
144
- averagePrice: number;
145
- /** Current market price */
146
- currentPrice: number;
109
+ /** Amount filled */
110
+ filled: number;
111
+ /** Current status */
112
+ status: OrderStatus;
113
+ /** Creation timestamp */
114
+ createdAt: Date;
115
+ /** Last update timestamp */
116
+ updatedAt?: Date;
147
117
  }
148
- /** Helper functions for Position */
149
- declare const PositionUtils: {
150
- /** Get total cost basis */
151
- readonly costBasis: (position: Position) => number;
152
- /** Get current market value */
153
- readonly currentValue: (position: Position) => number;
154
- /** Get unrealized profit/loss */
155
- readonly unrealizedPnl: (position: Position) => number;
156
- /** Get unrealized P&L as percentage */
157
- readonly unrealizedPnlPercent: (position: Position) => number;
118
+ /** Helper functions for Order */
119
+ declare const OrderUtils: {
120
+ /** Get remaining unfilled amount */
121
+ readonly remaining: (order: Order) => number;
122
+ /** Check if order is still active */
123
+ readonly isActive: (order: Order) => boolean;
124
+ /** Check if order is completely filled */
125
+ readonly isFilled: (order: Order) => boolean;
126
+ /** Get fill percentage (0-1) */
127
+ readonly fillPercentage: (order: Order) => number;
158
128
  };
159
- /** Aggregated position info for delta calculations */
160
- interface DeltaInfo {
161
- /** Net delta (positive = long bias) */
162
- delta: number;
163
- /** Outcome with maximum position */
164
- maxOutcome: string | null;
165
- /** Maximum position size */
166
- maxPosition: number;
129
+ /** Parameters for creating a new order */
130
+ interface CreateOrderParams {
131
+ marketId: string;
132
+ outcome: string;
133
+ side: OrderSide;
134
+ price: number;
135
+ size: number;
136
+ /** Token ID (required for some exchanges) */
137
+ tokenId?: string;
138
+ /** Additional exchange-specific parameters */
139
+ params?: Record<string, unknown>;
167
140
  }
168
- /** Calculate delta from positions map */
169
- declare function calculateDelta(positions: Record<string, number>): DeltaInfo;
170
141
 
171
142
  /**
172
143
  * Orderbook-related types for market data.
@@ -225,15 +196,44 @@ declare class OrderbookManager {
225
196
  clear(): void;
226
197
  }
227
198
 
228
- type MarketDirection = 'up' | 'down';
229
- type CryptoMarketType = 'up_down' | 'strike_price';
230
- interface CryptoHourlyMarket {
231
- tokenSymbol: string;
232
- expiryTime: Date;
233
- strikePrice: number | null;
234
- direction?: MarketDirection;
235
- marketType?: CryptoMarketType;
199
+ /**
200
+ * Position-related types for tracking holdings.
201
+ */
202
+ /** Represents a position in a prediction market */
203
+ interface Position {
204
+ /** Market identifier */
205
+ marketId: string;
206
+ /** Outcome held */
207
+ outcome: string;
208
+ /** Position size (number of shares) */
209
+ size: number;
210
+ /** Average entry price */
211
+ averagePrice: number;
212
+ /** Current market price */
213
+ currentPrice: number;
214
+ }
215
+ /** Helper functions for Position */
216
+ declare const PositionUtils: {
217
+ /** Get total cost basis */
218
+ readonly costBasis: (position: Position) => number;
219
+ /** Get current market value */
220
+ readonly currentValue: (position: Position) => number;
221
+ /** Get unrealized profit/loss */
222
+ readonly unrealizedPnl: (position: Position) => number;
223
+ /** Get unrealized P&L as percentage */
224
+ readonly unrealizedPnlPercent: (position: Position) => number;
225
+ };
226
+ /** Aggregated position info for delta calculations */
227
+ interface DeltaInfo {
228
+ /** Net delta (positive = long bias) */
229
+ delta: number;
230
+ /** Outcome with maximum position */
231
+ maxOutcome: string | null;
232
+ /** Maximum position size */
233
+ maxPosition: number;
236
234
  }
235
+ /** Calculate delta from positions map */
236
+ declare function calculateDelta(positions: Record<string, number>): DeltaInfo;
237
237
 
238
238
  interface PublicTrade {
239
239
  proxyWallet: string;
@@ -275,32 +275,6 @@ interface Tag {
275
275
  }
276
276
  type PriceHistoryInterval = '1m' | '1h' | '6h' | '1d' | '1w' | 'max';
277
277
 
278
- declare class DrManhattanError extends Error {
279
- constructor(message: string);
280
- }
281
- declare class ExchangeError extends DrManhattanError {
282
- constructor(message: string);
283
- }
284
- declare class NetworkError extends DrManhattanError {
285
- constructor(message: string);
286
- }
287
- declare class RateLimitError extends DrManhattanError {
288
- retryAfter: number | undefined;
289
- constructor(message: string, retryAfter?: number);
290
- }
291
- declare class AuthenticationError extends DrManhattanError {
292
- constructor(message: string);
293
- }
294
- declare class InsufficientFunds extends DrManhattanError {
295
- constructor(message: string);
296
- }
297
- declare class InvalidOrder extends DrManhattanError {
298
- constructor(message: string);
299
- }
300
- declare class MarketNotFound extends DrManhattanError {
301
- constructor(message: string);
302
- }
303
-
304
278
  interface ExchangeConfig {
305
279
  apiKey?: string;
306
280
  apiSecret?: string;
@@ -361,27 +335,64 @@ declare abstract class Exchange {
361
335
  getOptimalOrderSize(market: Market, maxPositionSize: number): number;
362
336
  }
363
337
 
364
- declare const WebSocketState: {
365
- readonly DISCONNECTED: "disconnected";
366
- readonly CONNECTING: "connecting";
367
- readonly CONNECTED: "connected";
368
- readonly RECONNECTING: "reconnecting";
369
- readonly CLOSED: "closed";
338
+ declare const StrategyState: {
339
+ readonly STOPPED: "stopped";
340
+ readonly RUNNING: "running";
341
+ readonly PAUSED: "paused";
370
342
  };
371
- type WebSocketState = (typeof WebSocketState)[keyof typeof WebSocketState];
372
- interface WebSocketConfig {
343
+ type StrategyState = (typeof StrategyState)[keyof typeof StrategyState];
344
+ interface StrategyConfig {
345
+ tickInterval?: number;
346
+ maxPositionSize?: number;
347
+ spreadBps?: number;
373
348
  verbose?: boolean;
374
- autoReconnect?: boolean;
375
- maxReconnectAttempts?: number;
376
- reconnectDelay?: number;
377
- pingInterval?: number;
378
- pingTimeout?: number;
379
- }
380
- interface OrderbookUpdate {
381
- marketId: string;
382
- bids: [number, number][];
383
- asks: [number, number][];
384
- timestamp: number;
349
+ }
350
+ declare abstract class Strategy extends EventEmitter {
351
+ protected exchange: Exchange;
352
+ protected marketId: string;
353
+ protected market: Market | null;
354
+ protected state: StrategyState;
355
+ protected config: StrategyConfig;
356
+ protected tickTimer: ReturnType<typeof setInterval> | null;
357
+ protected positions: Position[];
358
+ protected openOrders: Order[];
359
+ constructor(exchange: Exchange, marketId: string, config?: StrategyConfig);
360
+ abstract onTick(): Promise<void>;
361
+ start(): Promise<void>;
362
+ stop(): Promise<void>;
363
+ pause(): void;
364
+ resume(): void;
365
+ protected refreshState(): Promise<void>;
366
+ protected cancelAllOrders(): Promise<void>;
367
+ protected getPosition(outcome: string): Position | undefined;
368
+ protected getNetPosition(): number;
369
+ protected placeOrder(outcome: string, side: OrderSide, price: number, size: number, tokenId?: string): Promise<Order | null>;
370
+ protected log(message: string): void;
371
+ get isRunning(): boolean;
372
+ get currentState(): StrategyState;
373
+ }
374
+
375
+ declare const WebSocketState: {
376
+ readonly DISCONNECTED: "disconnected";
377
+ readonly CONNECTING: "connecting";
378
+ readonly CONNECTED: "connected";
379
+ readonly RECONNECTING: "reconnecting";
380
+ readonly CLOSED: "closed";
381
+ };
382
+ type WebSocketState = (typeof WebSocketState)[keyof typeof WebSocketState];
383
+ interface WebSocketConfig {
384
+ verbose?: boolean;
385
+ autoReconnect?: boolean;
386
+ maxReconnectAttempts?: number;
387
+ reconnectDelay?: number;
388
+ pingInterval?: number;
389
+ pingTimeout?: number;
390
+ }
391
+ interface OrderbookUpdate {
392
+ marketId: string;
393
+ bids: [number, number][];
394
+ asks: [number, number][];
395
+ timestamp: number;
385
396
  }
386
397
  type OrderbookCallback = (marketId: string, orderbook: OrderbookUpdate) => void | Promise<void>;
387
398
  declare abstract class OrderBookWebSocket extends EventEmitter {
@@ -413,184 +424,62 @@ declare abstract class OrderBookWebSocket extends EventEmitter {
413
424
  protected send(data: unknown): void;
414
425
  }
415
426
 
416
- declare const StrategyState: {
417
- readonly STOPPED: "stopped";
418
- readonly RUNNING: "running";
419
- readonly PAUSED: "paused";
420
- };
421
- type StrategyState = (typeof StrategyState)[keyof typeof StrategyState];
422
- interface StrategyConfig {
423
- tickInterval?: number;
424
- maxPositionSize?: number;
425
- spreadBps?: number;
426
- verbose?: boolean;
427
+ declare class DrManhattanError extends Error {
428
+ constructor(message: string);
427
429
  }
428
- declare abstract class Strategy extends EventEmitter {
429
- protected exchange: Exchange;
430
- protected marketId: string;
431
- protected market: Market | null;
432
- protected state: StrategyState;
433
- protected config: StrategyConfig;
434
- protected tickTimer: ReturnType<typeof setInterval> | null;
435
- protected positions: Position[];
436
- protected openOrders: Order[];
437
- constructor(exchange: Exchange, marketId: string, config?: StrategyConfig);
438
- abstract onTick(): Promise<void>;
439
- start(): Promise<void>;
440
- stop(): Promise<void>;
441
- pause(): void;
442
- resume(): void;
443
- protected refreshState(): Promise<void>;
444
- protected cancelAllOrders(): Promise<void>;
445
- protected getPosition(outcome: string): Position | undefined;
446
- protected getNetPosition(): number;
447
- protected placeOrder(outcome: string, side: OrderSide, price: number, size: number, tokenId?: string): Promise<Order | null>;
448
- protected log(message: string): void;
449
- get isRunning(): boolean;
450
- get currentState(): StrategyState;
430
+ declare class ExchangeError extends DrManhattanError {
431
+ constructor(message: string);
451
432
  }
452
-
453
- interface PolymarketConfig extends ExchangeConfig {
454
- chainId?: number;
455
- signatureType?: number;
433
+ declare class NetworkError extends DrManhattanError {
434
+ constructor(message: string);
456
435
  }
457
- declare class Polymarket extends Exchange {
458
- readonly id = "polymarket";
459
- readonly name = "Polymarket";
460
- private clobClient;
461
- private wallet;
462
- private address;
463
- constructor(config?: PolymarketConfig);
464
- describe(): {
465
- has: {
466
- websocket: boolean;
467
- fetchMarkets: boolean;
468
- fetchMarket: boolean;
469
- createOrder: boolean;
470
- cancelOrder: boolean;
471
- fetchOrder: boolean;
472
- fetchOpenOrders: boolean;
473
- fetchPositions: boolean;
474
- fetchBalance: boolean;
475
- };
476
- id: string;
477
- name: string;
478
- };
479
- private initializeClobClient;
480
- fetchMarkets(params?: FetchMarketsParams): Promise<Market[]>;
481
- fetchMarket(marketId: string): Promise<Market>;
482
- fetchMarketsBySlug(slugOrUrl: string): Promise<Market[]>;
483
- createOrder(params: CreateOrderParams): Promise<Order>;
484
- cancelOrder(orderId: string, marketId?: string): Promise<Order>;
485
- fetchOrder(orderId: string, _marketId?: string): Promise<Order>;
486
- fetchOpenOrders(marketId?: string): Promise<Order[]>;
487
- fetchPositions(_marketId?: string): Promise<Position[]>;
488
- fetchBalance(): Promise<Record<string, number>>;
489
- getOrderbook(tokenId: string): Promise<{
490
- bids: Array<{
491
- price: string;
492
- size: string;
493
- }>;
494
- asks: Array<{
495
- price: string;
496
- size: string;
497
- }>;
498
- }>;
499
- private parseMarketIdentifier;
500
- private parseSamplingMarket;
501
- private parseGammaMarket;
502
- private parseOrder;
503
- private parseOrderStatus;
504
- private isMarketOpen;
505
- get walletAddress(): string | null;
506
- fetchTokenIds(conditionId: string): Promise<string[]>;
507
- fetchPositionsForMarket(market: Market): Promise<Position[]>;
508
- fetchPriceHistory(marketOrId: Market | string, options?: {
509
- outcome?: number | string;
510
- interval?: PriceHistoryInterval;
511
- fidelity?: number;
512
- }): Promise<PricePoint[]>;
513
- searchMarkets(options?: {
514
- limit?: number;
515
- offset?: number;
516
- order?: string;
517
- ascending?: boolean;
518
- closed?: boolean;
519
- tagId?: string;
520
- query?: string;
521
- binary?: boolean;
522
- minLiquidity?: number;
523
- }): Promise<Market[]>;
524
- fetchPublicTrades(options?: {
525
- market?: Market | string;
526
- limit?: number;
527
- offset?: number;
528
- side?: 'BUY' | 'SELL';
529
- user?: string;
530
- }): Promise<PublicTrade[]>;
531
- getTagBySlug(slug: string): Promise<Tag>;
532
- findCryptoHourlyMarket(options?: {
533
- tokenSymbol?: string;
534
- minLiquidity?: number;
535
- limit?: number;
536
- isActive?: boolean;
537
- isExpired?: boolean;
538
- }): Promise<{
539
- market: Market;
540
- crypto: CryptoHourlyMarket;
541
- } | null>;
436
+ declare class RateLimitError extends DrManhattanError {
437
+ retryAfter: number | undefined;
438
+ constructor(message: string, retryAfter?: number);
542
439
  }
543
-
544
- interface PolymarketWsConfig extends WebSocketConfig {
545
- apiKey?: string;
440
+ declare class AuthenticationError extends DrManhattanError {
441
+ constructor(message: string);
546
442
  }
547
- declare class PolymarketWebSocket extends OrderBookWebSocket {
548
- readonly wsUrl = "wss://ws-subscriptions-clob.polymarket.com/ws/market";
549
- private apiKey?;
550
- private assetSubscriptions;
551
- constructor(config?: PolymarketWsConfig);
552
- protected authenticate(): Promise<void>;
553
- protected subscribeOrderbook(marketId: string): Promise<void>;
554
- protected unsubscribeOrderbook(marketId: string): Promise<void>;
555
- protected parseOrderbookMessage(message: Record<string, unknown>): OrderbookUpdate | null;
556
- watchOrderbookWithAsset(marketId: string, assetId: string, callback: (marketId: string, orderbook: OrderbookUpdate) => void | Promise<void>): Promise<void>;
557
- private findMarketIdByAsset;
443
+ declare class InsufficientFunds extends DrManhattanError {
444
+ constructor(message: string);
445
+ }
446
+ declare class InvalidOrder extends DrManhattanError {
447
+ constructor(message: string);
448
+ }
449
+ declare class MarketNotFound extends DrManhattanError {
450
+ constructor(message: string);
558
451
  }
559
452
 
560
- interface OpinionConfig extends ExchangeConfig {
561
- apiKey?: string;
562
- multiSigAddr?: string;
563
- chainId?: number;
564
- host?: string;
453
+ interface KalshiConfig extends ExchangeConfig {
454
+ /** API key ID (the public key identifier) */
455
+ apiKeyId?: string;
456
+ /** Path to RSA private key PEM file */
457
+ privateKeyPath?: string;
458
+ /** RSA private key PEM content (alternative to path) */
459
+ privateKeyPem?: string;
460
+ /** Use demo environment */
461
+ demo?: boolean;
462
+ /** Custom API URL */
463
+ apiUrl?: string;
565
464
  }
566
- declare class Opinion extends Exchange {
567
- readonly id = "opinion";
568
- readonly name = "Opinion";
569
- private readonly apiKey;
570
- private readonly multiSigAddr;
571
- private readonly chainId;
572
- private readonly host;
573
- private wallet;
574
- constructor(config?: OpinionConfig);
575
- private request;
465
+ declare class Kalshi extends Exchange {
466
+ readonly id = "kalshi";
467
+ readonly name = "Kalshi";
468
+ private readonly apiUrl;
469
+ private readonly apiKeyId;
470
+ private auth;
471
+ constructor(config?: KalshiConfig);
472
+ private isAuthenticated;
576
473
  private ensureAuth;
474
+ private request;
577
475
  private parseMarket;
578
476
  private parseOrder;
579
477
  private parsePosition;
580
478
  fetchMarkets(params?: FetchMarketsParams): Promise<Market[]>;
581
479
  fetchMarket(marketId: string): Promise<Market>;
582
- getOrderbook(tokenId: string): Promise<{
583
- bids: Array<{
584
- price: string;
585
- size: string;
586
- }>;
587
- asks: Array<{
588
- price: string;
589
- size: string;
590
- }>;
591
- }>;
480
+ fetchOrderbook(ticker: string): Promise<Orderbook>;
592
481
  createOrder(params: CreateOrderParams): Promise<Order>;
593
- cancelOrder(orderId: string, marketId?: string): Promise<Order>;
482
+ cancelOrder(orderId: string, _marketId?: string): Promise<Order>;
594
483
  fetchOrder(orderId: string, _marketId?: string): Promise<Order>;
595
484
  fetchOpenOrders(marketId?: string): Promise<Order[]>;
596
485
  fetchPositions(marketId?: string): Promise<Position[]>;
@@ -740,36 +629,40 @@ declare class Limitless extends Exchange {
740
629
  };
741
630
  }
742
631
 
743
- interface KalshiConfig extends ExchangeConfig {
744
- /** API key ID (the public key identifier) */
745
- apiKeyId?: string;
746
- /** Path to RSA private key PEM file */
747
- privateKeyPath?: string;
748
- /** RSA private key PEM content (alternative to path) */
749
- privateKeyPem?: string;
750
- /** Use demo environment */
751
- demo?: boolean;
752
- /** Custom API URL */
753
- apiUrl?: string;
632
+ interface OpinionConfig extends ExchangeConfig {
633
+ apiKey?: string;
634
+ multiSigAddr?: string;
635
+ chainId?: number;
636
+ host?: string;
754
637
  }
755
- declare class Kalshi extends Exchange {
756
- readonly id = "kalshi";
757
- readonly name = "Kalshi";
758
- private readonly apiUrl;
759
- private readonly apiKeyId;
760
- private auth;
761
- constructor(config?: KalshiConfig);
762
- private isAuthenticated;
763
- private ensureAuth;
638
+ declare class Opinion extends Exchange {
639
+ readonly id = "opinion";
640
+ readonly name = "Opinion";
641
+ private readonly apiKey;
642
+ private readonly multiSigAddr;
643
+ private readonly chainId;
644
+ private readonly host;
645
+ private wallet;
646
+ constructor(config?: OpinionConfig);
764
647
  private request;
648
+ private ensureAuth;
765
649
  private parseMarket;
766
650
  private parseOrder;
767
651
  private parsePosition;
768
652
  fetchMarkets(params?: FetchMarketsParams): Promise<Market[]>;
769
653
  fetchMarket(marketId: string): Promise<Market>;
770
- fetchOrderbook(ticker: string): Promise<Orderbook>;
654
+ getOrderbook(tokenId: string): Promise<{
655
+ bids: Array<{
656
+ price: string;
657
+ size: string;
658
+ }>;
659
+ asks: Array<{
660
+ price: string;
661
+ size: string;
662
+ }>;
663
+ }>;
771
664
  createOrder(params: CreateOrderParams): Promise<Order>;
772
- cancelOrder(orderId: string, _marketId?: string): Promise<Order>;
665
+ cancelOrder(orderId: string, marketId?: string): Promise<Order>;
773
666
  fetchOrder(orderId: string, _marketId?: string): Promise<Order>;
774
667
  fetchOpenOrders(marketId?: string): Promise<Order[]>;
775
668
  fetchPositions(marketId?: string): Promise<Position[]>;
@@ -791,6 +684,113 @@ declare class Kalshi extends Exchange {
791
684
  };
792
685
  }
793
686
 
687
+ interface PolymarketConfig extends ExchangeConfig {
688
+ chainId?: number;
689
+ signatureType?: number;
690
+ }
691
+ declare class Polymarket extends Exchange {
692
+ readonly id = "polymarket";
693
+ readonly name = "Polymarket";
694
+ private clobClient;
695
+ private wallet;
696
+ private address;
697
+ constructor(config?: PolymarketConfig);
698
+ describe(): {
699
+ has: {
700
+ websocket: boolean;
701
+ fetchMarkets: boolean;
702
+ fetchMarket: boolean;
703
+ createOrder: boolean;
704
+ cancelOrder: boolean;
705
+ fetchOrder: boolean;
706
+ fetchOpenOrders: boolean;
707
+ fetchPositions: boolean;
708
+ fetchBalance: boolean;
709
+ };
710
+ id: string;
711
+ name: string;
712
+ };
713
+ private initializeClobClient;
714
+ fetchMarkets(params?: FetchMarketsParams): Promise<Market[]>;
715
+ fetchMarket(marketId: string): Promise<Market>;
716
+ fetchMarketsBySlug(slugOrUrl: string): Promise<Market[]>;
717
+ createOrder(params: CreateOrderParams): Promise<Order>;
718
+ cancelOrder(orderId: string, marketId?: string): Promise<Order>;
719
+ fetchOrder(orderId: string, _marketId?: string): Promise<Order>;
720
+ fetchOpenOrders(marketId?: string): Promise<Order[]>;
721
+ fetchPositions(_marketId?: string): Promise<Position[]>;
722
+ fetchBalance(): Promise<Record<string, number>>;
723
+ getOrderbook(tokenId: string): Promise<{
724
+ bids: Array<{
725
+ price: string;
726
+ size: string;
727
+ }>;
728
+ asks: Array<{
729
+ price: string;
730
+ size: string;
731
+ }>;
732
+ }>;
733
+ private parseMarketIdentifier;
734
+ private parseSamplingMarket;
735
+ private parseGammaMarket;
736
+ private parseOrder;
737
+ private parseOrderStatus;
738
+ private isMarketOpen;
739
+ get walletAddress(): string | null;
740
+ fetchTokenIds(conditionId: string): Promise<string[]>;
741
+ fetchPositionsForMarket(market: Market): Promise<Position[]>;
742
+ fetchPriceHistory(marketOrId: Market | string, options?: {
743
+ outcome?: number | string;
744
+ interval?: PriceHistoryInterval;
745
+ fidelity?: number;
746
+ }): Promise<PricePoint[]>;
747
+ searchMarkets(options?: {
748
+ limit?: number;
749
+ offset?: number;
750
+ order?: string;
751
+ ascending?: boolean;
752
+ closed?: boolean;
753
+ tagId?: string;
754
+ query?: string;
755
+ binary?: boolean;
756
+ minLiquidity?: number;
757
+ }): Promise<Market[]>;
758
+ fetchPublicTrades(options?: {
759
+ market?: Market | string;
760
+ limit?: number;
761
+ offset?: number;
762
+ side?: 'BUY' | 'SELL';
763
+ user?: string;
764
+ }): Promise<PublicTrade[]>;
765
+ getTagBySlug(slug: string): Promise<Tag>;
766
+ findCryptoHourlyMarket(options?: {
767
+ tokenSymbol?: string;
768
+ minLiquidity?: number;
769
+ limit?: number;
770
+ isActive?: boolean;
771
+ isExpired?: boolean;
772
+ }): Promise<{
773
+ market: Market;
774
+ crypto: CryptoHourlyMarket;
775
+ } | null>;
776
+ }
777
+
778
+ interface PolymarketWsConfig extends WebSocketConfig {
779
+ apiKey?: string;
780
+ }
781
+ declare class PolymarketWebSocket extends OrderBookWebSocket {
782
+ readonly wsUrl = "wss://ws-subscriptions-clob.polymarket.com/ws/market";
783
+ private apiKey?;
784
+ private assetSubscriptions;
785
+ constructor(config?: PolymarketWsConfig);
786
+ protected authenticate(): Promise<void>;
787
+ protected subscribeOrderbook(marketId: string): Promise<void>;
788
+ protected unsubscribeOrderbook(marketId: string): Promise<void>;
789
+ protected parseOrderbookMessage(message: Record<string, unknown>): OrderbookUpdate | null;
790
+ watchOrderbookWithAsset(marketId: string, assetId: string, callback: (marketId: string, orderbook: OrderbookUpdate) => void | Promise<void>): Promise<void>;
791
+ private findMarketIdByAsset;
792
+ }
793
+
794
794
  declare function listExchanges(): string[];
795
795
  declare function createExchange(exchangeId: string, config?: ExchangeConfig): Exchange;
796
796