@alango/dr-manhattan 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.
- package/LICENSE +21 -0
- package/README.md +365 -0
- package/dist/index.d.ts +696 -0
- package/dist/index.js +2537 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import WebSocket from 'ws';
|
|
3
|
+
import pino from 'pino';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Order-related types for prediction market trading.
|
|
7
|
+
*/
|
|
8
|
+
/** Order side - buy or sell */
|
|
9
|
+
declare const OrderSide: {
|
|
10
|
+
readonly BUY: "buy";
|
|
11
|
+
readonly SELL: "sell";
|
|
12
|
+
};
|
|
13
|
+
type OrderSide = (typeof OrderSide)[keyof typeof OrderSide];
|
|
14
|
+
/** Order status */
|
|
15
|
+
declare const OrderStatus: {
|
|
16
|
+
readonly PENDING: "pending";
|
|
17
|
+
readonly OPEN: "open";
|
|
18
|
+
readonly FILLED: "filled";
|
|
19
|
+
readonly PARTIALLY_FILLED: "partially_filled";
|
|
20
|
+
readonly CANCELLED: "cancelled";
|
|
21
|
+
readonly REJECTED: "rejected";
|
|
22
|
+
};
|
|
23
|
+
type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus];
|
|
24
|
+
/** Order representation */
|
|
25
|
+
interface Order {
|
|
26
|
+
/** Unique order identifier */
|
|
27
|
+
id: string;
|
|
28
|
+
/** Market identifier */
|
|
29
|
+
marketId: string;
|
|
30
|
+
/** Outcome being traded */
|
|
31
|
+
outcome: string;
|
|
32
|
+
/** Buy or sell */
|
|
33
|
+
side: OrderSide;
|
|
34
|
+
/** Price per share (0-1) */
|
|
35
|
+
price: number;
|
|
36
|
+
/** Total order size */
|
|
37
|
+
size: number;
|
|
38
|
+
/** Amount filled */
|
|
39
|
+
filled: number;
|
|
40
|
+
/** Current status */
|
|
41
|
+
status: OrderStatus;
|
|
42
|
+
/** Creation timestamp */
|
|
43
|
+
createdAt: Date;
|
|
44
|
+
/** Last update timestamp */
|
|
45
|
+
updatedAt?: Date;
|
|
46
|
+
}
|
|
47
|
+
/** Helper functions for Order */
|
|
48
|
+
declare const OrderUtils: {
|
|
49
|
+
/** Get remaining unfilled amount */
|
|
50
|
+
readonly remaining: (order: Order) => number;
|
|
51
|
+
/** Check if order is still active */
|
|
52
|
+
readonly isActive: (order: Order) => boolean;
|
|
53
|
+
/** Check if order is completely filled */
|
|
54
|
+
readonly isFilled: (order: Order) => boolean;
|
|
55
|
+
/** Get fill percentage (0-1) */
|
|
56
|
+
readonly fillPercentage: (order: Order) => number;
|
|
57
|
+
};
|
|
58
|
+
/** Parameters for creating a new order */
|
|
59
|
+
interface CreateOrderParams {
|
|
60
|
+
marketId: string;
|
|
61
|
+
outcome: string;
|
|
62
|
+
side: OrderSide;
|
|
63
|
+
price: number;
|
|
64
|
+
size: number;
|
|
65
|
+
/** Token ID (required for some exchanges) */
|
|
66
|
+
tokenId?: string;
|
|
67
|
+
/** Additional exchange-specific parameters */
|
|
68
|
+
params?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Market-related types for prediction markets.
|
|
73
|
+
*/
|
|
74
|
+
/** Represents a tradeable outcome with its token ID */
|
|
75
|
+
interface OutcomeToken {
|
|
76
|
+
/** Outcome name (e.g., "Yes", "No") */
|
|
77
|
+
outcome: string;
|
|
78
|
+
/** Token ID for trading */
|
|
79
|
+
tokenId: string;
|
|
80
|
+
}
|
|
81
|
+
/** Represents a prediction market */
|
|
82
|
+
interface Market {
|
|
83
|
+
/** Unique market identifier */
|
|
84
|
+
id: string;
|
|
85
|
+
/** Market question */
|
|
86
|
+
question: string;
|
|
87
|
+
/** List of possible outcomes */
|
|
88
|
+
outcomes: string[];
|
|
89
|
+
/** Market close/resolution time */
|
|
90
|
+
closeTime?: Date;
|
|
91
|
+
/** Total trading volume */
|
|
92
|
+
volume: number;
|
|
93
|
+
/** Available liquidity */
|
|
94
|
+
liquidity: number;
|
|
95
|
+
/** Current prices for each outcome (0-1) */
|
|
96
|
+
prices: Record<string, number>;
|
|
97
|
+
/** Minimum price increment */
|
|
98
|
+
tickSize: number;
|
|
99
|
+
/** Resolution criteria description */
|
|
100
|
+
description: string;
|
|
101
|
+
/** Additional exchange-specific metadata */
|
|
102
|
+
metadata: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
/** Helper functions for Market */
|
|
105
|
+
declare const MarketUtils: {
|
|
106
|
+
/** Check if market is binary (Yes/No) */
|
|
107
|
+
readonly isBinary: (market: Market) => boolean;
|
|
108
|
+
/** Check if market is still open for trading */
|
|
109
|
+
readonly isOpen: (market: Market) => boolean;
|
|
110
|
+
/** Get bid-ask spread for binary markets */
|
|
111
|
+
readonly spread: (market: Market) => number | null;
|
|
112
|
+
/** Get token IDs from market metadata */
|
|
113
|
+
readonly getTokenIds: (market: Market) => string[];
|
|
114
|
+
/** Create OutcomeToken array from market */
|
|
115
|
+
readonly getOutcomeTokens: (market: Market) => OutcomeToken[];
|
|
116
|
+
};
|
|
117
|
+
/** Parameters for fetching markets */
|
|
118
|
+
interface FetchMarketsParams {
|
|
119
|
+
/** Maximum number of markets to return */
|
|
120
|
+
limit?: number;
|
|
121
|
+
/** Offset for pagination */
|
|
122
|
+
offset?: number;
|
|
123
|
+
/** Only return active markets */
|
|
124
|
+
active?: boolean;
|
|
125
|
+
/** Include closed markets */
|
|
126
|
+
closed?: boolean;
|
|
127
|
+
/** Additional exchange-specific filters */
|
|
128
|
+
[key: string]: unknown;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Position-related types for tracking holdings.
|
|
133
|
+
*/
|
|
134
|
+
/** Represents a position in a prediction market */
|
|
135
|
+
interface Position {
|
|
136
|
+
/** Market identifier */
|
|
137
|
+
marketId: string;
|
|
138
|
+
/** Outcome held */
|
|
139
|
+
outcome: string;
|
|
140
|
+
/** Position size (number of shares) */
|
|
141
|
+
size: number;
|
|
142
|
+
/** Average entry price */
|
|
143
|
+
averagePrice: number;
|
|
144
|
+
/** Current market price */
|
|
145
|
+
currentPrice: number;
|
|
146
|
+
}
|
|
147
|
+
/** Helper functions for Position */
|
|
148
|
+
declare const PositionUtils: {
|
|
149
|
+
/** Get total cost basis */
|
|
150
|
+
readonly costBasis: (position: Position) => number;
|
|
151
|
+
/** Get current market value */
|
|
152
|
+
readonly currentValue: (position: Position) => number;
|
|
153
|
+
/** Get unrealized profit/loss */
|
|
154
|
+
readonly unrealizedPnl: (position: Position) => number;
|
|
155
|
+
/** Get unrealized P&L as percentage */
|
|
156
|
+
readonly unrealizedPnlPercent: (position: Position) => number;
|
|
157
|
+
};
|
|
158
|
+
/** Aggregated position info for delta calculations */
|
|
159
|
+
interface DeltaInfo {
|
|
160
|
+
/** Net delta (positive = long bias) */
|
|
161
|
+
delta: number;
|
|
162
|
+
/** Outcome with maximum position */
|
|
163
|
+
maxOutcome: string | null;
|
|
164
|
+
/** Maximum position size */
|
|
165
|
+
maxPosition: number;
|
|
166
|
+
}
|
|
167
|
+
/** Calculate delta from positions map */
|
|
168
|
+
declare function calculateDelta(positions: Record<string, number>): DeltaInfo;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Orderbook-related types for market data.
|
|
172
|
+
*/
|
|
173
|
+
/** Price level: [price, size] */
|
|
174
|
+
type PriceLevel = [price: number, size: number];
|
|
175
|
+
/** Normalized orderbook data structure */
|
|
176
|
+
interface Orderbook {
|
|
177
|
+
/** Bids sorted descending by price */
|
|
178
|
+
bids: PriceLevel[];
|
|
179
|
+
/** Asks sorted ascending by price */
|
|
180
|
+
asks: PriceLevel[];
|
|
181
|
+
/** Timestamp (ms since epoch) */
|
|
182
|
+
timestamp: number;
|
|
183
|
+
/** Asset/token ID */
|
|
184
|
+
assetId: string;
|
|
185
|
+
/** Market ID */
|
|
186
|
+
marketId: string;
|
|
187
|
+
}
|
|
188
|
+
/** Helper functions for Orderbook */
|
|
189
|
+
declare const OrderbookUtils: {
|
|
190
|
+
/** Get best bid price */
|
|
191
|
+
readonly bestBid: (orderbook: Orderbook) => number | null;
|
|
192
|
+
/** Get best ask price */
|
|
193
|
+
readonly bestAsk: (orderbook: Orderbook) => number | null;
|
|
194
|
+
/** Get mid price */
|
|
195
|
+
readonly midPrice: (orderbook: Orderbook) => number | null;
|
|
196
|
+
/** Get bid-ask spread */
|
|
197
|
+
readonly spread: (orderbook: Orderbook) => number | null;
|
|
198
|
+
/** Create orderbook from REST API response */
|
|
199
|
+
readonly fromRestResponse: (data: {
|
|
200
|
+
bids?: Array<{
|
|
201
|
+
price: string;
|
|
202
|
+
size: string;
|
|
203
|
+
}>;
|
|
204
|
+
asks?: Array<{
|
|
205
|
+
price: string;
|
|
206
|
+
size: string;
|
|
207
|
+
}>;
|
|
208
|
+
}, tokenId?: string) => Orderbook;
|
|
209
|
+
};
|
|
210
|
+
/** Manages multiple orderbooks efficiently */
|
|
211
|
+
declare class OrderbookManager {
|
|
212
|
+
private orderbooks;
|
|
213
|
+
/** Update orderbook for a token */
|
|
214
|
+
update(tokenId: string, orderbook: Orderbook): void;
|
|
215
|
+
/** Get orderbook for a token */
|
|
216
|
+
get(tokenId: string): Orderbook | undefined;
|
|
217
|
+
/** Get best bid and ask for a token */
|
|
218
|
+
getBestBidAsk(tokenId: string): [bid: number | null, ask: number | null];
|
|
219
|
+
/** Check if we have data for a token */
|
|
220
|
+
hasData(tokenId: string): boolean;
|
|
221
|
+
/** Check if we have data for all tokens */
|
|
222
|
+
hasAllData(tokenIds: string[]): boolean;
|
|
223
|
+
/** Clear all orderbooks */
|
|
224
|
+
clear(): void;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
type MarketDirection = 'up' | 'down';
|
|
228
|
+
type CryptoMarketType = 'up_down' | 'strike_price';
|
|
229
|
+
interface CryptoHourlyMarket {
|
|
230
|
+
tokenSymbol: string;
|
|
231
|
+
expiryTime: Date;
|
|
232
|
+
strikePrice: number | null;
|
|
233
|
+
direction?: MarketDirection;
|
|
234
|
+
marketType?: CryptoMarketType;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
interface PublicTrade {
|
|
238
|
+
proxyWallet: string;
|
|
239
|
+
side: string;
|
|
240
|
+
asset: string;
|
|
241
|
+
conditionId: string;
|
|
242
|
+
size: number;
|
|
243
|
+
price: number;
|
|
244
|
+
timestamp: Date;
|
|
245
|
+
title?: string;
|
|
246
|
+
slug?: string;
|
|
247
|
+
icon?: string;
|
|
248
|
+
eventSlug?: string;
|
|
249
|
+
outcome?: string;
|
|
250
|
+
outcomeIndex?: number;
|
|
251
|
+
name?: string;
|
|
252
|
+
pseudonym?: string;
|
|
253
|
+
bio?: string;
|
|
254
|
+
profileImage?: string;
|
|
255
|
+
profileImageOptimized?: string;
|
|
256
|
+
transactionHash?: string;
|
|
257
|
+
}
|
|
258
|
+
interface PricePoint {
|
|
259
|
+
timestamp: Date;
|
|
260
|
+
price: number;
|
|
261
|
+
raw: Record<string, unknown>;
|
|
262
|
+
}
|
|
263
|
+
interface Tag {
|
|
264
|
+
id: string;
|
|
265
|
+
label?: string;
|
|
266
|
+
slug?: string;
|
|
267
|
+
forceShow?: boolean;
|
|
268
|
+
forceHide?: boolean;
|
|
269
|
+
isCarousel?: boolean;
|
|
270
|
+
publishedAt?: string;
|
|
271
|
+
createdAt?: string;
|
|
272
|
+
updatedAt?: string;
|
|
273
|
+
raw: Record<string, unknown>;
|
|
274
|
+
}
|
|
275
|
+
type PriceHistoryInterval = '1m' | '1h' | '6h' | '1d' | '1w' | 'max';
|
|
276
|
+
|
|
277
|
+
declare class DrManhattanError extends Error {
|
|
278
|
+
constructor(message: string);
|
|
279
|
+
}
|
|
280
|
+
declare class ExchangeError extends DrManhattanError {
|
|
281
|
+
constructor(message: string);
|
|
282
|
+
}
|
|
283
|
+
declare class NetworkError extends DrManhattanError {
|
|
284
|
+
constructor(message: string);
|
|
285
|
+
}
|
|
286
|
+
declare class RateLimitError extends DrManhattanError {
|
|
287
|
+
retryAfter: number | undefined;
|
|
288
|
+
constructor(message: string, retryAfter?: number);
|
|
289
|
+
}
|
|
290
|
+
declare class AuthenticationError extends DrManhattanError {
|
|
291
|
+
constructor(message: string);
|
|
292
|
+
}
|
|
293
|
+
declare class InsufficientFunds extends DrManhattanError {
|
|
294
|
+
constructor(message: string);
|
|
295
|
+
}
|
|
296
|
+
declare class InvalidOrder extends DrManhattanError {
|
|
297
|
+
constructor(message: string);
|
|
298
|
+
}
|
|
299
|
+
declare class MarketNotFound extends DrManhattanError {
|
|
300
|
+
constructor(message: string);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
interface ExchangeConfig {
|
|
304
|
+
apiKey?: string;
|
|
305
|
+
apiSecret?: string;
|
|
306
|
+
privateKey?: string;
|
|
307
|
+
funder?: string;
|
|
308
|
+
timeout?: number;
|
|
309
|
+
verbose?: boolean;
|
|
310
|
+
rateLimit?: number;
|
|
311
|
+
maxRetries?: number;
|
|
312
|
+
retryDelay?: number;
|
|
313
|
+
retryBackoff?: number;
|
|
314
|
+
}
|
|
315
|
+
interface ExchangeCapabilities {
|
|
316
|
+
fetchMarkets: boolean;
|
|
317
|
+
fetchMarket: boolean;
|
|
318
|
+
createOrder: boolean;
|
|
319
|
+
cancelOrder: boolean;
|
|
320
|
+
fetchOrder: boolean;
|
|
321
|
+
fetchOpenOrders: boolean;
|
|
322
|
+
fetchPositions: boolean;
|
|
323
|
+
fetchBalance: boolean;
|
|
324
|
+
websocket: boolean;
|
|
325
|
+
}
|
|
326
|
+
declare abstract class Exchange {
|
|
327
|
+
protected config: ExchangeConfig;
|
|
328
|
+
protected requestTimes: number[];
|
|
329
|
+
protected lastRequestTime: number;
|
|
330
|
+
abstract readonly id: string;
|
|
331
|
+
abstract readonly name: string;
|
|
332
|
+
constructor(config?: ExchangeConfig);
|
|
333
|
+
get verbose(): boolean;
|
|
334
|
+
get timeout(): number;
|
|
335
|
+
abstract fetchMarkets(params?: FetchMarketsParams): Promise<Market[]>;
|
|
336
|
+
abstract fetchMarket(marketId: string): Promise<Market>;
|
|
337
|
+
abstract createOrder(params: CreateOrderParams): Promise<Order>;
|
|
338
|
+
abstract cancelOrder(orderId: string, marketId?: string): Promise<Order>;
|
|
339
|
+
abstract fetchOrder(orderId: string, marketId?: string): Promise<Order>;
|
|
340
|
+
abstract fetchOpenOrders(marketId?: string): Promise<Order[]>;
|
|
341
|
+
abstract fetchPositions(marketId?: string): Promise<Position[]>;
|
|
342
|
+
abstract fetchBalance(): Promise<Record<string, number>>;
|
|
343
|
+
describe(): {
|
|
344
|
+
id: string;
|
|
345
|
+
name: string;
|
|
346
|
+
has: ExchangeCapabilities;
|
|
347
|
+
};
|
|
348
|
+
protected checkRateLimit(): void;
|
|
349
|
+
protected withRetry<T>(fn: () => Promise<T>): Promise<T>;
|
|
350
|
+
protected sleep(ms: number): Promise<void>;
|
|
351
|
+
protected parseDateTime(timestamp: unknown): Date | undefined;
|
|
352
|
+
findTradeableMarket(options?: {
|
|
353
|
+
binary?: boolean;
|
|
354
|
+
limit?: number;
|
|
355
|
+
minLiquidity?: number;
|
|
356
|
+
}): Promise<Market | null>;
|
|
357
|
+
calculateSpread(market: Market): number | null;
|
|
358
|
+
calculateImpliedProbability(price: number): number;
|
|
359
|
+
calculateExpectedValue(market: Market, outcome: string, price: number): number;
|
|
360
|
+
getOptimalOrderSize(market: Market, maxPositionSize: number): number;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
declare const WebSocketState: {
|
|
364
|
+
readonly DISCONNECTED: "disconnected";
|
|
365
|
+
readonly CONNECTING: "connecting";
|
|
366
|
+
readonly CONNECTED: "connected";
|
|
367
|
+
readonly RECONNECTING: "reconnecting";
|
|
368
|
+
readonly CLOSED: "closed";
|
|
369
|
+
};
|
|
370
|
+
type WebSocketState = (typeof WebSocketState)[keyof typeof WebSocketState];
|
|
371
|
+
interface WebSocketConfig {
|
|
372
|
+
verbose?: boolean;
|
|
373
|
+
autoReconnect?: boolean;
|
|
374
|
+
maxReconnectAttempts?: number;
|
|
375
|
+
reconnectDelay?: number;
|
|
376
|
+
pingInterval?: number;
|
|
377
|
+
pingTimeout?: number;
|
|
378
|
+
}
|
|
379
|
+
interface OrderbookUpdate {
|
|
380
|
+
marketId: string;
|
|
381
|
+
bids: [number, number][];
|
|
382
|
+
asks: [number, number][];
|
|
383
|
+
timestamp: number;
|
|
384
|
+
}
|
|
385
|
+
type OrderbookCallback = (marketId: string, orderbook: OrderbookUpdate) => void | Promise<void>;
|
|
386
|
+
declare abstract class OrderBookWebSocket extends EventEmitter {
|
|
387
|
+
protected config: WebSocketConfig;
|
|
388
|
+
protected ws: WebSocket | null;
|
|
389
|
+
protected state: WebSocketState;
|
|
390
|
+
protected reconnectAttempts: number;
|
|
391
|
+
protected subscriptions: Map<string, OrderbookCallback>;
|
|
392
|
+
protected pingTimer: ReturnType<typeof setInterval> | null;
|
|
393
|
+
protected lastMessageTime: number;
|
|
394
|
+
abstract readonly wsUrl: string;
|
|
395
|
+
constructor(config?: WebSocketConfig);
|
|
396
|
+
get isConnected(): boolean;
|
|
397
|
+
protected abstract authenticate(): Promise<void>;
|
|
398
|
+
protected abstract subscribeOrderbook(marketId: string): Promise<void>;
|
|
399
|
+
protected abstract unsubscribeOrderbook(marketId: string): Promise<void>;
|
|
400
|
+
protected abstract parseOrderbookMessage(message: Record<string, unknown>): OrderbookUpdate | null;
|
|
401
|
+
connect(): Promise<void>;
|
|
402
|
+
disconnect(): Promise<void>;
|
|
403
|
+
watchOrderbook(marketId: string, callback: OrderbookCallback): Promise<void>;
|
|
404
|
+
unwatchOrderbook(marketId: string): Promise<void>;
|
|
405
|
+
protected handleMessage(data: WebSocket.RawData): void;
|
|
406
|
+
protected handleError(error: Error): void;
|
|
407
|
+
protected handleClose(): void;
|
|
408
|
+
protected reconnect(): Promise<void>;
|
|
409
|
+
protected startPingTimer(): void;
|
|
410
|
+
protected stopPingTimer(): void;
|
|
411
|
+
protected sleep(ms: number): Promise<void>;
|
|
412
|
+
protected send(data: unknown): void;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
declare const StrategyState: {
|
|
416
|
+
readonly STOPPED: "stopped";
|
|
417
|
+
readonly RUNNING: "running";
|
|
418
|
+
readonly PAUSED: "paused";
|
|
419
|
+
};
|
|
420
|
+
type StrategyState = (typeof StrategyState)[keyof typeof StrategyState];
|
|
421
|
+
interface StrategyConfig {
|
|
422
|
+
tickInterval?: number;
|
|
423
|
+
maxPositionSize?: number;
|
|
424
|
+
spreadBps?: number;
|
|
425
|
+
verbose?: boolean;
|
|
426
|
+
}
|
|
427
|
+
declare abstract class Strategy extends EventEmitter {
|
|
428
|
+
protected exchange: Exchange;
|
|
429
|
+
protected marketId: string;
|
|
430
|
+
protected market: Market | null;
|
|
431
|
+
protected state: StrategyState;
|
|
432
|
+
protected config: StrategyConfig;
|
|
433
|
+
protected tickTimer: ReturnType<typeof setInterval> | null;
|
|
434
|
+
protected positions: Position[];
|
|
435
|
+
protected openOrders: Order[];
|
|
436
|
+
constructor(exchange: Exchange, marketId: string, config?: StrategyConfig);
|
|
437
|
+
abstract onTick(): Promise<void>;
|
|
438
|
+
start(): Promise<void>;
|
|
439
|
+
stop(): Promise<void>;
|
|
440
|
+
pause(): void;
|
|
441
|
+
resume(): void;
|
|
442
|
+
protected refreshState(): Promise<void>;
|
|
443
|
+
protected cancelAllOrders(): Promise<void>;
|
|
444
|
+
protected getPosition(outcome: string): Position | undefined;
|
|
445
|
+
protected getNetPosition(): number;
|
|
446
|
+
protected placeOrder(outcome: string, side: OrderSide, price: number, size: number, tokenId?: string): Promise<Order | null>;
|
|
447
|
+
protected log(message: string): void;
|
|
448
|
+
get isRunning(): boolean;
|
|
449
|
+
get currentState(): StrategyState;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
interface PolymarketConfig extends ExchangeConfig {
|
|
453
|
+
chainId?: number;
|
|
454
|
+
signatureType?: number;
|
|
455
|
+
}
|
|
456
|
+
declare class Polymarket extends Exchange {
|
|
457
|
+
readonly id = "polymarket";
|
|
458
|
+
readonly name = "Polymarket";
|
|
459
|
+
private clobClient;
|
|
460
|
+
private wallet;
|
|
461
|
+
private address;
|
|
462
|
+
constructor(config?: PolymarketConfig);
|
|
463
|
+
describe(): {
|
|
464
|
+
has: {
|
|
465
|
+
websocket: boolean;
|
|
466
|
+
fetchMarkets: boolean;
|
|
467
|
+
fetchMarket: boolean;
|
|
468
|
+
createOrder: boolean;
|
|
469
|
+
cancelOrder: boolean;
|
|
470
|
+
fetchOrder: boolean;
|
|
471
|
+
fetchOpenOrders: boolean;
|
|
472
|
+
fetchPositions: boolean;
|
|
473
|
+
fetchBalance: boolean;
|
|
474
|
+
};
|
|
475
|
+
id: string;
|
|
476
|
+
name: string;
|
|
477
|
+
};
|
|
478
|
+
private initializeClobClient;
|
|
479
|
+
fetchMarkets(params?: FetchMarketsParams): Promise<Market[]>;
|
|
480
|
+
fetchMarket(marketId: string): Promise<Market>;
|
|
481
|
+
fetchMarketsBySlug(slugOrUrl: string): Promise<Market[]>;
|
|
482
|
+
createOrder(params: CreateOrderParams): Promise<Order>;
|
|
483
|
+
cancelOrder(orderId: string, marketId?: string): Promise<Order>;
|
|
484
|
+
fetchOrder(orderId: string, _marketId?: string): Promise<Order>;
|
|
485
|
+
fetchOpenOrders(marketId?: string): Promise<Order[]>;
|
|
486
|
+
fetchPositions(_marketId?: string): Promise<Position[]>;
|
|
487
|
+
fetchBalance(): Promise<Record<string, number>>;
|
|
488
|
+
getOrderbook(tokenId: string): Promise<{
|
|
489
|
+
bids: Array<{
|
|
490
|
+
price: string;
|
|
491
|
+
size: string;
|
|
492
|
+
}>;
|
|
493
|
+
asks: Array<{
|
|
494
|
+
price: string;
|
|
495
|
+
size: string;
|
|
496
|
+
}>;
|
|
497
|
+
}>;
|
|
498
|
+
private parseMarketIdentifier;
|
|
499
|
+
private parseSamplingMarket;
|
|
500
|
+
private parseGammaMarket;
|
|
501
|
+
private parseOrder;
|
|
502
|
+
private parseOrderStatus;
|
|
503
|
+
private isMarketOpen;
|
|
504
|
+
get walletAddress(): string | null;
|
|
505
|
+
fetchTokenIds(conditionId: string): Promise<string[]>;
|
|
506
|
+
fetchPositionsForMarket(market: Market): Promise<Position[]>;
|
|
507
|
+
fetchPriceHistory(marketOrId: Market | string, options?: {
|
|
508
|
+
outcome?: number | string;
|
|
509
|
+
interval?: PriceHistoryInterval;
|
|
510
|
+
fidelity?: number;
|
|
511
|
+
}): Promise<PricePoint[]>;
|
|
512
|
+
searchMarkets(options?: {
|
|
513
|
+
limit?: number;
|
|
514
|
+
offset?: number;
|
|
515
|
+
order?: string;
|
|
516
|
+
ascending?: boolean;
|
|
517
|
+
closed?: boolean;
|
|
518
|
+
tagId?: string;
|
|
519
|
+
query?: string;
|
|
520
|
+
binary?: boolean;
|
|
521
|
+
minLiquidity?: number;
|
|
522
|
+
}): Promise<Market[]>;
|
|
523
|
+
fetchPublicTrades(options?: {
|
|
524
|
+
market?: Market | string;
|
|
525
|
+
limit?: number;
|
|
526
|
+
offset?: number;
|
|
527
|
+
side?: 'BUY' | 'SELL';
|
|
528
|
+
user?: string;
|
|
529
|
+
}): Promise<PublicTrade[]>;
|
|
530
|
+
getTagBySlug(slug: string): Promise<Tag>;
|
|
531
|
+
findCryptoHourlyMarket(options?: {
|
|
532
|
+
tokenSymbol?: string;
|
|
533
|
+
minLiquidity?: number;
|
|
534
|
+
limit?: number;
|
|
535
|
+
isActive?: boolean;
|
|
536
|
+
isExpired?: boolean;
|
|
537
|
+
}): Promise<{
|
|
538
|
+
market: Market;
|
|
539
|
+
crypto: CryptoHourlyMarket;
|
|
540
|
+
} | null>;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
interface PolymarketWsConfig extends WebSocketConfig {
|
|
544
|
+
apiKey?: string;
|
|
545
|
+
}
|
|
546
|
+
declare class PolymarketWebSocket extends OrderBookWebSocket {
|
|
547
|
+
readonly wsUrl = "wss://ws-subscriptions-clob.polymarket.com/ws/market";
|
|
548
|
+
private apiKey?;
|
|
549
|
+
private assetSubscriptions;
|
|
550
|
+
constructor(config?: PolymarketWsConfig);
|
|
551
|
+
protected authenticate(): Promise<void>;
|
|
552
|
+
protected subscribeOrderbook(marketId: string): Promise<void>;
|
|
553
|
+
protected unsubscribeOrderbook(marketId: string): Promise<void>;
|
|
554
|
+
protected parseOrderbookMessage(message: Record<string, unknown>): OrderbookUpdate | null;
|
|
555
|
+
watchOrderbookWithAsset(marketId: string, assetId: string, callback: (marketId: string, orderbook: OrderbookUpdate) => void | Promise<void>): Promise<void>;
|
|
556
|
+
private findMarketIdByAsset;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
interface OpinionConfig extends ExchangeConfig {
|
|
560
|
+
apiKey?: string;
|
|
561
|
+
multiSigAddr?: string;
|
|
562
|
+
chainId?: number;
|
|
563
|
+
host?: string;
|
|
564
|
+
}
|
|
565
|
+
declare class Opinion extends Exchange {
|
|
566
|
+
readonly id = "opinion";
|
|
567
|
+
readonly name = "Opinion";
|
|
568
|
+
private readonly apiKey;
|
|
569
|
+
private readonly multiSigAddr;
|
|
570
|
+
private readonly chainId;
|
|
571
|
+
private readonly host;
|
|
572
|
+
private wallet;
|
|
573
|
+
constructor(config?: OpinionConfig);
|
|
574
|
+
private request;
|
|
575
|
+
private ensureAuth;
|
|
576
|
+
private parseMarket;
|
|
577
|
+
private parseOrder;
|
|
578
|
+
private parsePosition;
|
|
579
|
+
fetchMarkets(params?: FetchMarketsParams): Promise<Market[]>;
|
|
580
|
+
fetchMarket(marketId: string): Promise<Market>;
|
|
581
|
+
getOrderbook(tokenId: string): Promise<{
|
|
582
|
+
bids: Array<{
|
|
583
|
+
price: string;
|
|
584
|
+
size: string;
|
|
585
|
+
}>;
|
|
586
|
+
asks: Array<{
|
|
587
|
+
price: string;
|
|
588
|
+
size: string;
|
|
589
|
+
}>;
|
|
590
|
+
}>;
|
|
591
|
+
createOrder(params: CreateOrderParams): Promise<Order>;
|
|
592
|
+
cancelOrder(orderId: string, marketId?: string): Promise<Order>;
|
|
593
|
+
fetchOrder(orderId: string, _marketId?: string): Promise<Order>;
|
|
594
|
+
fetchOpenOrders(marketId?: string): Promise<Order[]>;
|
|
595
|
+
fetchPositions(marketId?: string): Promise<Position[]>;
|
|
596
|
+
fetchBalance(): Promise<Record<string, number>>;
|
|
597
|
+
describe(): {
|
|
598
|
+
id: string;
|
|
599
|
+
name: string;
|
|
600
|
+
has: {
|
|
601
|
+
fetchMarkets: boolean;
|
|
602
|
+
fetchMarket: boolean;
|
|
603
|
+
createOrder: boolean;
|
|
604
|
+
cancelOrder: boolean;
|
|
605
|
+
fetchOrder: boolean;
|
|
606
|
+
fetchOpenOrders: boolean;
|
|
607
|
+
fetchPositions: boolean;
|
|
608
|
+
fetchBalance: boolean;
|
|
609
|
+
websocket: boolean;
|
|
610
|
+
};
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
interface LimitlessConfig extends ExchangeConfig {
|
|
615
|
+
host?: string;
|
|
616
|
+
chainId?: number;
|
|
617
|
+
}
|
|
618
|
+
declare class Limitless extends Exchange {
|
|
619
|
+
readonly id = "limitless";
|
|
620
|
+
readonly name = "Limitless";
|
|
621
|
+
private readonly host;
|
|
622
|
+
private readonly chainId;
|
|
623
|
+
private wallet;
|
|
624
|
+
private address;
|
|
625
|
+
private authenticated;
|
|
626
|
+
private ownerId;
|
|
627
|
+
private sessionCookie;
|
|
628
|
+
private tokenToSlug;
|
|
629
|
+
private noTokens;
|
|
630
|
+
constructor(config?: LimitlessConfig);
|
|
631
|
+
private authenticate;
|
|
632
|
+
private ensureAuth;
|
|
633
|
+
private request;
|
|
634
|
+
private parseMarket;
|
|
635
|
+
private parseOrder;
|
|
636
|
+
private parseOrderStatus;
|
|
637
|
+
private parsePortfolioPositions;
|
|
638
|
+
fetchMarkets(params?: FetchMarketsParams): Promise<Market[]>;
|
|
639
|
+
fetchMarket(marketId: string): Promise<Market>;
|
|
640
|
+
getOrderbook(marketSlugOrTokenId: string): Promise<{
|
|
641
|
+
bids: Array<{
|
|
642
|
+
price: string;
|
|
643
|
+
size: string;
|
|
644
|
+
}>;
|
|
645
|
+
asks: Array<{
|
|
646
|
+
price: string;
|
|
647
|
+
size: string;
|
|
648
|
+
}>;
|
|
649
|
+
}>;
|
|
650
|
+
createOrder(params: CreateOrderParams): Promise<Order>;
|
|
651
|
+
private buildSignedOrder;
|
|
652
|
+
private signOrderEip712;
|
|
653
|
+
cancelOrder(orderId: string, marketId?: string): Promise<Order>;
|
|
654
|
+
fetchOrder(orderId: string, _marketId?: string): Promise<Order>;
|
|
655
|
+
fetchOpenOrders(marketId?: string): Promise<Order[]>;
|
|
656
|
+
fetchPositions(marketId?: string): Promise<Position[]>;
|
|
657
|
+
fetchBalance(): Promise<Record<string, number>>;
|
|
658
|
+
describe(): {
|
|
659
|
+
id: string;
|
|
660
|
+
name: string;
|
|
661
|
+
has: {
|
|
662
|
+
fetchMarkets: boolean;
|
|
663
|
+
fetchMarket: boolean;
|
|
664
|
+
createOrder: boolean;
|
|
665
|
+
cancelOrder: boolean;
|
|
666
|
+
fetchOrder: boolean;
|
|
667
|
+
fetchOpenOrders: boolean;
|
|
668
|
+
fetchPositions: boolean;
|
|
669
|
+
fetchBalance: boolean;
|
|
670
|
+
websocket: boolean;
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
declare function listExchanges(): string[];
|
|
676
|
+
declare function createExchange(exchangeId: string, config?: ExchangeConfig): Exchange;
|
|
677
|
+
|
|
678
|
+
declare const logger: pino.Logger<never, boolean>;
|
|
679
|
+
declare function createLogger(name: string): pino.Logger<never, boolean>;
|
|
680
|
+
declare const Colors: {
|
|
681
|
+
readonly bold: (text: string) => string;
|
|
682
|
+
readonly red: (text: string) => string;
|
|
683
|
+
readonly green: (text: string) => string;
|
|
684
|
+
readonly yellow: (text: string) => string;
|
|
685
|
+
readonly blue: (text: string) => string;
|
|
686
|
+
readonly magenta: (text: string) => string;
|
|
687
|
+
readonly cyan: (text: string) => string;
|
|
688
|
+
readonly gray: (text: string) => string;
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
declare function roundToTickSize(price: number, tickSize: number): number;
|
|
692
|
+
declare function clampPrice(price: number, min?: number, max?: number): number;
|
|
693
|
+
declare function formatPrice(price: number, decimals?: number): string;
|
|
694
|
+
declare function formatUsd(amount: number): string;
|
|
695
|
+
|
|
696
|
+
export { AuthenticationError, Colors, type CreateOrderParams, type DeltaInfo, DrManhattanError, Exchange, type ExchangeCapabilities, type ExchangeConfig, ExchangeError, type FetchMarketsParams, InsufficientFunds, InvalidOrder, Limitless, type Market, MarketNotFound, MarketUtils, NetworkError, Opinion, type Order, OrderBookWebSocket, OrderSide, OrderStatus, OrderUtils, type Orderbook, type OrderbookCallback, OrderbookManager, type OrderbookUpdate, OrderbookUtils, type OutcomeToken, Polymarket, PolymarketWebSocket, type Position, PositionUtils, type PriceLevel, RateLimitError, Strategy, type StrategyConfig, StrategyState, type WebSocketConfig, WebSocketState, calculateDelta, clampPrice, createExchange, createLogger, formatPrice, formatUsd, listExchanges, logger, roundToTickSize };
|