@catalyst-team/poly-sdk 0.4.3 → 0.4.6
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/src/clients/bridge-client.d.ts +131 -1
- package/dist/src/clients/bridge-client.d.ts.map +1 -1
- package/dist/src/clients/bridge-client.js +143 -0
- package/dist/src/clients/bridge-client.js.map +1 -1
- package/dist/src/core/order-status.d.ts +159 -0
- package/dist/src/core/order-status.d.ts.map +1 -0
- package/dist/src/core/order-status.js +254 -0
- package/dist/src/core/order-status.js.map +1 -0
- package/dist/src/core/types.d.ts +124 -0
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +120 -0
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/index.d.ts +6 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/services/ctf-detector.d.ts +215 -0
- package/dist/src/services/ctf-detector.d.ts.map +1 -0
- package/dist/src/services/ctf-detector.js +420 -0
- package/dist/src/services/ctf-detector.js.map +1 -0
- package/dist/src/services/ctf-manager.d.ts +202 -0
- package/dist/src/services/ctf-manager.d.ts.map +1 -0
- package/dist/src/services/ctf-manager.js +542 -0
- package/dist/src/services/ctf-manager.js.map +1 -0
- package/dist/src/services/order-manager.d.ts +440 -0
- package/dist/src/services/order-manager.d.ts.map +1 -0
- package/dist/src/services/order-manager.js +853 -0
- package/dist/src/services/order-manager.js.map +1 -0
- package/dist/src/services/order-manager.test.d.ts +10 -0
- package/dist/src/services/order-manager.test.d.ts.map +1 -0
- package/dist/src/services/order-manager.test.js +751 -0
- package/dist/src/services/order-manager.test.js.map +1 -0
- package/dist/src/services/trading-service.d.ts +89 -1
- package/dist/src/services/trading-service.d.ts.map +1 -1
- package/dist/src/services/trading-service.js +227 -1
- package/dist/src/services/trading-service.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OrderManager - Unified Order Creation and Monitoring
|
|
3
|
+
*
|
|
4
|
+
* Core Design Philosophy:
|
|
5
|
+
* - Unifies order creation + lifecycle monitoring in one component
|
|
6
|
+
* - Encapsulates all Polymarket-specific details (USDC.e, tick size, tokenId, CTF, Polygon)
|
|
7
|
+
* - Provides complete lifecycle events (CLOB match → tx submit → on-chain confirm)
|
|
8
|
+
* - Auto-validates orders before submission (market state, balance, precision)
|
|
9
|
+
* - Auto-watches orders after creation
|
|
10
|
+
*
|
|
11
|
+
* ============================================================================
|
|
12
|
+
* ORDER TYPES AND LIFECYCLE
|
|
13
|
+
* ============================================================================
|
|
14
|
+
*
|
|
15
|
+
* Polymarket supports 4 order types, each with different lifecycle patterns:
|
|
16
|
+
*
|
|
17
|
+
* ┌─────────────────────────────────────────────────────────────────────────┐
|
|
18
|
+
* │ LIMIT ORDERS (createOrder) │
|
|
19
|
+
* ├─────────────────────────────────────────────────────────────────────────┤
|
|
20
|
+
* │ │
|
|
21
|
+
* │ GTC (Good Till Cancelled) - Default limit order │
|
|
22
|
+
* │ ─────────────────────────────────────────────────────────────────────── │
|
|
23
|
+
* │ Lifecycle: PENDING → OPEN → PARTIALLY_FILLED* → FILLED or CANCELLED │
|
|
24
|
+
* │ Duration: seconds → minutes → hours → days (until filled/cancelled) │
|
|
25
|
+
* │ │
|
|
26
|
+
* │ ┌─────────┐ placed ┌──────┐ partial ┌──────────────────┐ │
|
|
27
|
+
* │ │ PENDING │ ───────────→ │ OPEN │ ──────────→ │ PARTIALLY_FILLED │ │
|
|
28
|
+
* │ └─────────┘ └──────┘ └──────────────────┘ │
|
|
29
|
+
* │ │ │ │ │
|
|
30
|
+
* │ │ reject │ cancel │ fill/cancel│
|
|
31
|
+
* │ ↓ ↓ ↓ │
|
|
32
|
+
* │ ┌──────────┐ ┌───────────┐ ┌────────┐ │
|
|
33
|
+
* │ │ REJECTED │ │ CANCELLED │ │ FILLED │ │
|
|
34
|
+
* │ └──────────┘ └───────────┘ └────────┘ │
|
|
35
|
+
* │ │
|
|
36
|
+
* │ GTD (Good Till Date) - Limit order with expiration │
|
|
37
|
+
* │ ───────────────────────────────────────────────────────────────────── │
|
|
38
|
+
* │ Lifecycle: Same as GTC, but auto-expires at specified time │
|
|
39
|
+
* │ Duration: seconds → specified expiration time │
|
|
40
|
+
* │ Additional terminal state: EXPIRED (when expiration time reached) │
|
|
41
|
+
* │ │
|
|
42
|
+
* ├─────────────────────────────────────────────────────────────────────────┤
|
|
43
|
+
* │ MARKET ORDERS (createMarketOrder) │
|
|
44
|
+
* ├─────────────────────────────────────────────────────────────────────────┤
|
|
45
|
+
* │ │
|
|
46
|
+
* │ FOK (Fill Or Kill) - Must fill completely or cancel immediately │
|
|
47
|
+
* │ ───────────────────────────────────────────────────────────────────────│
|
|
48
|
+
* │ Lifecycle: PENDING → FILLED (success) or PENDING → CANCELLED (fail) │
|
|
49
|
+
* │ Duration: milliseconds (instant execution) │
|
|
50
|
+
* │ Key: NO partial fills - all or nothing │
|
|
51
|
+
* │ │
|
|
52
|
+
* │ ┌─────────┐ full fill ┌────────┐ │
|
|
53
|
+
* │ │ PENDING │ ─────────────→ │ FILLED │ │
|
|
54
|
+
* │ └─────────┘ └────────┘ │
|
|
55
|
+
* │ │ │
|
|
56
|
+
* │ │ cannot fill completely │
|
|
57
|
+
* │ ↓ │
|
|
58
|
+
* │ ┌───────────┐ │
|
|
59
|
+
* │ │ CANCELLED │ (filledSize = 0) │
|
|
60
|
+
* │ └───────────┘ │
|
|
61
|
+
* │ │
|
|
62
|
+
* │ FAK (Fill And Kill) - Fill what's available, cancel the rest │
|
|
63
|
+
* │ ───────────────────────────────────────────────────────────────────────│
|
|
64
|
+
* │ Lifecycle: PENDING → FILLED or PENDING → CANCELLED (with partial fill)│
|
|
65
|
+
* │ Duration: milliseconds (instant execution) │
|
|
66
|
+
* │ Key: May have partial fills, remainder is cancelled immediately │
|
|
67
|
+
* │ │
|
|
68
|
+
* │ ┌─────────┐ full fill ┌────────┐ │
|
|
69
|
+
* │ │ PENDING │ ─────────────→ │ FILLED │ │
|
|
70
|
+
* │ └─────────┘ └────────┘ │
|
|
71
|
+
* │ │ │
|
|
72
|
+
* │ │ partial fill + cancel rest │
|
|
73
|
+
* │ ↓ │
|
|
74
|
+
* │ ┌───────────┐ │
|
|
75
|
+
* │ │ CANCELLED │ (filledSize > 0, cancelledSize > 0) │
|
|
76
|
+
* │ └───────────┘ │
|
|
77
|
+
* │ │
|
|
78
|
+
* └─────────────────────────────────────────────────────────────────────────┘
|
|
79
|
+
*
|
|
80
|
+
* ============================================================================
|
|
81
|
+
* WHY ORDERMANAGER SUPPORTS ALL ORDER TYPES
|
|
82
|
+
* ============================================================================
|
|
83
|
+
*
|
|
84
|
+
* The key insight is that despite different lifecycles, all order types share
|
|
85
|
+
* the same underlying status model and event stream:
|
|
86
|
+
*
|
|
87
|
+
* 1. UNIFIED STATUS MODEL
|
|
88
|
+
* All orders use the same OrderStatus enum: PENDING, OPEN, PARTIALLY_FILLED,
|
|
89
|
+
* FILLED, CANCELLED, EXPIRED. The difference is which transitions are valid
|
|
90
|
+
* and how quickly they occur.
|
|
91
|
+
*
|
|
92
|
+
* 2. SAME WEBSOCKET/POLLING EVENTS
|
|
93
|
+
* RealtimeServiceV2's `clob_user` topic emits the same USER_ORDER and
|
|
94
|
+
* USER_TRADE events for all order types. The eventType field indicates:
|
|
95
|
+
* - PLACEMENT: Order entered the system
|
|
96
|
+
* - UPDATE: Order was modified (fill, partial fill)
|
|
97
|
+
* - CANCELLATION: Order was cancelled
|
|
98
|
+
*
|
|
99
|
+
* 3. STATUS TRANSITION VALIDATION
|
|
100
|
+
* The isValidStatusTransition() function handles all valid paths:
|
|
101
|
+
* - GTC/GTD: PENDING → OPEN → PARTIALLY_FILLED → FILLED/CANCELLED
|
|
102
|
+
* - FOK: PENDING → FILLED or PENDING → CANCELLED (no PARTIALLY_FILLED)
|
|
103
|
+
* - FAK: PENDING → FILLED or PENDING → CANCELLED (filledSize may be > 0)
|
|
104
|
+
*
|
|
105
|
+
* 4. TERMINAL STATE HANDLING
|
|
106
|
+
* All order types eventually reach a terminal state (FILLED, CANCELLED,
|
|
107
|
+
* EXPIRED). OrderManager auto-unwatches orders when they reach terminal
|
|
108
|
+
* states, regardless of order type.
|
|
109
|
+
*
|
|
110
|
+
* 5. FILL EVENT DETECTION
|
|
111
|
+
* Whether fills come rapidly (FOK/FAK) or slowly (GTC/GTD), the same
|
|
112
|
+
* fill detection logic works: compare filledSize changes and emit
|
|
113
|
+
* order_partially_filled or order_filled events.
|
|
114
|
+
*
|
|
115
|
+
* Key differences in behavior:
|
|
116
|
+
* ┌─────────────┬─────────────────────────────────────────────────────────┐
|
|
117
|
+
* │ Order Type │ Behavior │
|
|
118
|
+
* ├─────────────┼─────────────────────────────────────────────────────────┤
|
|
119
|
+
* │ GTC/GTD │ May emit many events over long time (hours/days) │
|
|
120
|
+
* │ │ watchOrder() monitors until filled/cancelled/expired │
|
|
121
|
+
* ├─────────────┼─────────────────────────────────────────────────────────┤
|
|
122
|
+
* │ FOK/FAK │ Emit 1-2 events almost instantly (milliseconds) │
|
|
123
|
+
* │ │ watchOrder() monitors briefly, auto-unwatches quickly │
|
|
124
|
+
* └─────────────┴─────────────────────────────────────────────────────────┘
|
|
125
|
+
*
|
|
126
|
+
* ============================================================================
|
|
127
|
+
* PLATFORM-SPECIFIC IMPLEMENTATION
|
|
128
|
+
* ============================================================================
|
|
129
|
+
*
|
|
130
|
+
* This is a Polymarket-specific implementation. The design allows future extraction
|
|
131
|
+
* to interfaces if supporting multiple prediction markets, but for now we focus on
|
|
132
|
+
* clean encapsulation with Polymarket details in private methods.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const orderMgr = new OrderManager({
|
|
137
|
+
* privateKey: '0x...',
|
|
138
|
+
* rateLimiter,
|
|
139
|
+
* cache,
|
|
140
|
+
* });
|
|
141
|
+
*
|
|
142
|
+
* await orderMgr.start();
|
|
143
|
+
*
|
|
144
|
+
* // Listen to complete lifecycle
|
|
145
|
+
* orderMgr.on('order_opened', (order) => {
|
|
146
|
+
* console.log('Order live in orderbook');
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* orderMgr.on('order_filled', (event) => {
|
|
150
|
+
* console.log(`Filled: ${event.fill.size} @ ${event.fill.price}`);
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* orderMgr.on('transaction_confirmed', (event) => {
|
|
154
|
+
* console.log(`On-chain settled: ${event.transactionHash}`);
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* // Create limit order (GTC by default)
|
|
158
|
+
* const limitResult = await orderMgr.createOrder({
|
|
159
|
+
* tokenId: '0x...',
|
|
160
|
+
* side: 'BUY',
|
|
161
|
+
* price: 0.52,
|
|
162
|
+
* size: 100,
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* // Create market order (FOK - fill completely or cancel)
|
|
166
|
+
* const fokResult = await orderMgr.createMarketOrder({
|
|
167
|
+
* tokenId: '0x...',
|
|
168
|
+
* side: 'BUY',
|
|
169
|
+
* amount: 50, // $50 USDC
|
|
170
|
+
* orderType: 'FOK',
|
|
171
|
+
* });
|
|
172
|
+
*
|
|
173
|
+
* // Create market order (FAK - fill what's available)
|
|
174
|
+
* const fakResult = await orderMgr.createMarketOrder({
|
|
175
|
+
* tokenId: '0x...',
|
|
176
|
+
* side: 'BUY',
|
|
177
|
+
* amount: 50,
|
|
178
|
+
* orderType: 'FAK',
|
|
179
|
+
* });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
import { EventEmitter } from 'events';
|
|
183
|
+
import { type LimitOrderParams, type MarketOrderParams, type Order, type OrderResult } from './trading-service.js';
|
|
184
|
+
import { RateLimiter } from '../core/rate-limiter.js';
|
|
185
|
+
import type { UnifiedCache } from '../core/unified-cache.js';
|
|
186
|
+
import { OrderStatus } from '../core/types.js';
|
|
187
|
+
export interface OrderManagerConfig {
|
|
188
|
+
/** Private key for signing transactions */
|
|
189
|
+
privateKey: string;
|
|
190
|
+
/** Rate limiter for API calls */
|
|
191
|
+
rateLimiter: RateLimiter;
|
|
192
|
+
/** Cache for market metadata */
|
|
193
|
+
cache: UnifiedCache;
|
|
194
|
+
/** Chain ID (default: 137 Polygon mainnet) */
|
|
195
|
+
chainId?: number;
|
|
196
|
+
/** Detection mode for order status tracking */
|
|
197
|
+
mode?: 'websocket' | 'polling' | 'hybrid';
|
|
198
|
+
/** Polling interval in ms (default: 5000) */
|
|
199
|
+
pollingInterval?: number;
|
|
200
|
+
/** RPC URL for Polygon provider (for settlement tracking) */
|
|
201
|
+
polygonRpcUrl?: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Optional metadata for order tracking
|
|
205
|
+
* Can be used by strategies to attach context
|
|
206
|
+
*/
|
|
207
|
+
export interface OrderMetadata {
|
|
208
|
+
strategyId?: string;
|
|
209
|
+
marketSlug?: string;
|
|
210
|
+
notes?: string;
|
|
211
|
+
[key: string]: unknown;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Order status change event
|
|
215
|
+
* Emitted whenever an order transitions between states
|
|
216
|
+
*/
|
|
217
|
+
export interface OrderStatusChangeEvent {
|
|
218
|
+
orderId: string;
|
|
219
|
+
from: OrderStatus;
|
|
220
|
+
to: OrderStatus;
|
|
221
|
+
order: Order;
|
|
222
|
+
timestamp: number;
|
|
223
|
+
reason?: string;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Fill event
|
|
227
|
+
* Emitted when an order receives a fill (partial or complete)
|
|
228
|
+
*/
|
|
229
|
+
export interface FillEvent {
|
|
230
|
+
orderId: string;
|
|
231
|
+
order: Order;
|
|
232
|
+
fill: {
|
|
233
|
+
tradeId: string;
|
|
234
|
+
size: number;
|
|
235
|
+
price: number;
|
|
236
|
+
fee: number;
|
|
237
|
+
timestamp: number;
|
|
238
|
+
transactionHash?: string;
|
|
239
|
+
};
|
|
240
|
+
cumulativeFilled: number;
|
|
241
|
+
remainingSize: number;
|
|
242
|
+
isCompleteFill: boolean;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Transaction submitted event (Polymarket-specific)
|
|
246
|
+
* Emitted when a trade has a transaction hash
|
|
247
|
+
*/
|
|
248
|
+
export interface TransactionEvent {
|
|
249
|
+
orderId: string;
|
|
250
|
+
tradeId: string;
|
|
251
|
+
transactionHash: string;
|
|
252
|
+
timestamp: number;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* On-chain settlement event (Polymarket-specific)
|
|
256
|
+
* Emitted when transaction is confirmed on Polygon
|
|
257
|
+
*/
|
|
258
|
+
export interface SettlementEvent {
|
|
259
|
+
orderId: string;
|
|
260
|
+
tradeId: string;
|
|
261
|
+
transactionHash: string;
|
|
262
|
+
blockNumber: number;
|
|
263
|
+
gasUsed: string;
|
|
264
|
+
timestamp: number;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Cancellation event
|
|
268
|
+
*/
|
|
269
|
+
export interface CancelEvent {
|
|
270
|
+
orderId: string;
|
|
271
|
+
order: Order;
|
|
272
|
+
filledSize: number;
|
|
273
|
+
cancelledSize: number;
|
|
274
|
+
reason: 'user' | 'system';
|
|
275
|
+
timestamp: number;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Expiration event (for GTD orders)
|
|
279
|
+
*/
|
|
280
|
+
export interface ExpireEvent {
|
|
281
|
+
orderId: string;
|
|
282
|
+
order: Order;
|
|
283
|
+
filledSize: number;
|
|
284
|
+
expiredSize: number;
|
|
285
|
+
expirationTime: number;
|
|
286
|
+
timestamp: number;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Rejection event (order failed validation)
|
|
290
|
+
*/
|
|
291
|
+
export interface RejectEvent {
|
|
292
|
+
orderId?: string;
|
|
293
|
+
params: LimitOrderParams;
|
|
294
|
+
reason: string;
|
|
295
|
+
timestamp: number;
|
|
296
|
+
}
|
|
297
|
+
export declare class OrderManager extends EventEmitter {
|
|
298
|
+
private tradingService;
|
|
299
|
+
private realtimeService;
|
|
300
|
+
private polygonProvider;
|
|
301
|
+
private config;
|
|
302
|
+
private initialized;
|
|
303
|
+
private watchedOrders;
|
|
304
|
+
private processedEvents;
|
|
305
|
+
private mode;
|
|
306
|
+
private marketCache;
|
|
307
|
+
constructor(config: OrderManagerConfig);
|
|
308
|
+
/**
|
|
309
|
+
* Initialize OrderManager
|
|
310
|
+
* - Initializes TradingService
|
|
311
|
+
* - Optionally initializes RealtimeService (for WebSocket mode)
|
|
312
|
+
* - Optionally initializes Polygon provider (for settlement tracking)
|
|
313
|
+
*/
|
|
314
|
+
start(): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* Stop OrderManager
|
|
317
|
+
* - Unwatch all orders
|
|
318
|
+
* - Disconnect WebSocket (if connected)
|
|
319
|
+
*/
|
|
320
|
+
stop(): void;
|
|
321
|
+
/**
|
|
322
|
+
* Create and submit a limit order
|
|
323
|
+
*
|
|
324
|
+
* Auto-validates (Polymarket-specific):
|
|
325
|
+
* - Market state (active, not closed)
|
|
326
|
+
* - USDC.e balance
|
|
327
|
+
* - Tick size (0.01)
|
|
328
|
+
* - Minimum size (5 shares)
|
|
329
|
+
* - Minimum value ($1)
|
|
330
|
+
*
|
|
331
|
+
* Auto-watches: Starts monitoring immediately after creation
|
|
332
|
+
*
|
|
333
|
+
* @param params Order parameters
|
|
334
|
+
* @param metadata Optional metadata for tracking
|
|
335
|
+
* @returns Order result with orderId or error
|
|
336
|
+
*/
|
|
337
|
+
createOrder(params: LimitOrderParams, metadata?: OrderMetadata): Promise<OrderResult>;
|
|
338
|
+
/**
|
|
339
|
+
* Create and submit a market order (FOK or FAK)
|
|
340
|
+
*
|
|
341
|
+
* Market order lifecycle:
|
|
342
|
+
* - FOK (Fill Or Kill): Must fill completely or cancels immediately
|
|
343
|
+
* PENDING → FILLED (success) or PENDING → CANCELLED (failed to fill)
|
|
344
|
+
* - FAK (Fill And Kill): Fills what it can, cancels the rest
|
|
345
|
+
* PENDING → PARTIALLY_FILLED + CANCELLED (partial) or PENDING → FILLED (complete)
|
|
346
|
+
*
|
|
347
|
+
* Auto-validates (Polymarket-specific):
|
|
348
|
+
* - Minimum value ($1)
|
|
349
|
+
*
|
|
350
|
+
* Auto-watches: Starts monitoring immediately after creation
|
|
351
|
+
* Note: Market orders typically complete very quickly (within seconds)
|
|
352
|
+
*
|
|
353
|
+
* @param params Market order parameters
|
|
354
|
+
* @param metadata Optional metadata for tracking
|
|
355
|
+
* @returns Order result with orderId or error
|
|
356
|
+
*/
|
|
357
|
+
createMarketOrder(params: MarketOrderParams, metadata?: OrderMetadata): Promise<OrderResult>;
|
|
358
|
+
/**
|
|
359
|
+
* Cancel an order
|
|
360
|
+
* Auto-unwatches after cancellation
|
|
361
|
+
*/
|
|
362
|
+
cancelOrder(orderId: string): Promise<OrderResult>;
|
|
363
|
+
/**
|
|
364
|
+
* Get order details
|
|
365
|
+
* Fetches from TradingService (CLOB API)
|
|
366
|
+
*/
|
|
367
|
+
getOrder(orderId: string): Promise<Order | null>;
|
|
368
|
+
/**
|
|
369
|
+
* Create multiple orders in batch
|
|
370
|
+
* Auto-watches all successfully created orders
|
|
371
|
+
*/
|
|
372
|
+
createBatchOrders(orders: LimitOrderParams[], metadata?: OrderMetadata): Promise<OrderResult>;
|
|
373
|
+
/**
|
|
374
|
+
* Manually watch an order
|
|
375
|
+
* Used for monitoring externally-created orders
|
|
376
|
+
*
|
|
377
|
+
* @param orderId Order ID to watch
|
|
378
|
+
* @param metadata Optional metadata
|
|
379
|
+
*/
|
|
380
|
+
watchOrder(orderId: string, metadata?: OrderMetadata): void;
|
|
381
|
+
/**
|
|
382
|
+
* Stop watching an order
|
|
383
|
+
*/
|
|
384
|
+
unwatchOrder(orderId: string): void;
|
|
385
|
+
/**
|
|
386
|
+
* Get all watched orders
|
|
387
|
+
*/
|
|
388
|
+
getWatchedOrders(): Order[];
|
|
389
|
+
/**
|
|
390
|
+
* Get watched order by ID
|
|
391
|
+
*/
|
|
392
|
+
getWatchedOrder(orderId: string): Order | undefined;
|
|
393
|
+
/**
|
|
394
|
+
* Validate order parameters before submission
|
|
395
|
+
* All checks here are Polymarket-specific
|
|
396
|
+
*/
|
|
397
|
+
private validateOrder;
|
|
398
|
+
/**
|
|
399
|
+
* Validate market order parameters before submission
|
|
400
|
+
* Market orders have simpler validation than limit orders
|
|
401
|
+
*/
|
|
402
|
+
private validateMarketOrder;
|
|
403
|
+
/**
|
|
404
|
+
* Ensure WebSocket connection is established
|
|
405
|
+
* Lazy initialization of RealtimeService
|
|
406
|
+
*/
|
|
407
|
+
private ensureWebSocketConnected;
|
|
408
|
+
/**
|
|
409
|
+
* Handle USER_ORDER WebSocket event (Polymarket-specific)
|
|
410
|
+
* Triggered on: PLACEMENT, UPDATE, CANCELLATION
|
|
411
|
+
*/
|
|
412
|
+
private handleUserOrder;
|
|
413
|
+
/**
|
|
414
|
+
* Handle USER_TRADE WebSocket event (Polymarket-specific)
|
|
415
|
+
* Triggered when: MATCHED, MINED, CONFIRMED
|
|
416
|
+
*/
|
|
417
|
+
private handleUserTrade;
|
|
418
|
+
/**
|
|
419
|
+
* Start polling for order status
|
|
420
|
+
* Fallback mechanism when WebSocket is unavailable
|
|
421
|
+
*/
|
|
422
|
+
private startPolling;
|
|
423
|
+
/**
|
|
424
|
+
* Update watched order from polling result
|
|
425
|
+
* Detects both status changes and fill changes
|
|
426
|
+
*/
|
|
427
|
+
private updateWatchedOrder;
|
|
428
|
+
/**
|
|
429
|
+
* Emit status change event with appropriate specific events
|
|
430
|
+
* @param fillAlreadyEmitted - Set to true if fill event was already emitted (to prevent duplicates)
|
|
431
|
+
*/
|
|
432
|
+
private emitStatusChange;
|
|
433
|
+
/**
|
|
434
|
+
* Track transaction settlement on Polygon blockchain
|
|
435
|
+
* Waits for on-chain confirmation and emits transaction_confirmed event
|
|
436
|
+
*/
|
|
437
|
+
private trackSettlement;
|
|
438
|
+
private ensureInitialized;
|
|
439
|
+
}
|
|
440
|
+
//# sourceMappingURL=order-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-manager.d.ts","sourceRoot":"","sources":["../../../src/services/order-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoLG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAkB,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnI,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,WAAW,EAAE,WAAW,CAAC;IACzB,gCAAgC;IAChC,KAAK,EAAE,YAAY,CAAC;IACpB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC1C,6CAA6C;IAC7C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAiBD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACp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