@catalyst-team/poly-sdk 0.4.5 → 0.4.7
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/README.md +18 -9
- package/README.zh-CN.md +18 -9
- 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/clients/data-api.d.ts +25 -0
- package/dist/src/clients/data-api.d.ts.map +1 -1
- package/dist/src/clients/data-api.js +57 -0
- package/dist/src/clients/data-api.js.map +1 -1
- package/dist/src/core/types.d.ts +55 -0
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +7 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/realtime/index.d.ts +18 -0
- package/dist/src/realtime/index.d.ts.map +1 -0
- package/dist/src/realtime/index.js +14 -0
- package/dist/src/realtime/index.js.map +1 -0
- package/dist/src/realtime/realtime-data-client.d.ts +274 -0
- package/dist/src/realtime/realtime-data-client.d.ts.map +1 -0
- package/dist/src/realtime/realtime-data-client.js +771 -0
- package/dist/src/realtime/realtime-data-client.js.map +1 -0
- package/dist/src/realtime/types.d.ts +485 -0
- package/dist/src/realtime/types.d.ts.map +1 -0
- package/dist/src/realtime/types.js +36 -0
- package/dist/src/realtime/types.js.map +1 -0
- package/dist/src/services/arbitrage-service.d.ts.map +1 -1
- package/dist/src/services/arbitrage-service.js +2 -1
- package/dist/src/services/arbitrage-service.js.map +1 -1
- package/dist/src/services/dip-arb-service.d.ts.map +1 -1
- package/dist/src/services/dip-arb-service.js +3 -19
- package/dist/src/services/dip-arb-service.js.map +1 -1
- package/dist/src/services/market-service.d.ts +93 -11
- package/dist/src/services/market-service.d.ts.map +1 -1
- package/dist/src/services/market-service.js +189 -22
- package/dist/src/services/market-service.js.map +1 -1
- package/dist/src/services/order-handle.test.d.ts +15 -0
- package/dist/src/services/order-handle.test.d.ts.map +1 -0
- package/dist/src/services/order-handle.test.js +333 -0
- package/dist/src/services/order-handle.test.js.map +1 -0
- package/dist/src/services/order-manager.d.ts +325 -10
- package/dist/src/services/order-manager.d.ts.map +1 -1
- package/dist/src/services/order-manager.js +633 -32
- package/dist/src/services/order-manager.js.map +1 -1
- package/dist/src/services/order-manager.test.d.ts +2 -0
- package/dist/src/services/order-manager.test.d.ts.map +1 -1
- package/dist/src/services/order-manager.test.js +274 -0
- package/dist/src/services/order-manager.test.js.map +1 -1
- package/dist/src/services/realtime-service-v2.d.ts +122 -6
- package/dist/src/services/realtime-service-v2.d.ts.map +1 -1
- package/dist/src/services/realtime-service-v2.js +475 -70
- package/dist/src/services/realtime-service-v2.js.map +1 -1
- package/dist/src/services/trading-service.d.ts +129 -1
- package/dist/src/services/trading-service.d.ts.map +1 -1
- package/dist/src/services/trading-service.js +198 -5
- package/dist/src/services/trading-service.js.map +1 -1
- package/package.json +1 -2
- package/dist/src/services/ctf-detector.d.ts +0 -215
- package/dist/src/services/ctf-detector.d.ts.map +0 -1
- package/dist/src/services/ctf-detector.js +0 -420
- package/dist/src/services/ctf-detector.js.map +0 -1
|
@@ -8,7 +8,125 @@
|
|
|
8
8
|
* - Auto-validates orders before submission (market state, balance, precision)
|
|
9
9
|
* - Auto-watches orders after creation
|
|
10
10
|
*
|
|
11
|
-
*
|
|
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
|
+
*
|
|
12
130
|
* This is a Polymarket-specific implementation. The design allows future extraction
|
|
13
131
|
* to interfaces if supporting multiple prediction markets, but for now we focus on
|
|
14
132
|
* clean encapsulation with Polymarket details in private methods.
|
|
@@ -36,20 +154,36 @@
|
|
|
36
154
|
* console.log(`On-chain settled: ${event.transactionHash}`);
|
|
37
155
|
* });
|
|
38
156
|
*
|
|
39
|
-
* // Create order (
|
|
40
|
-
* const
|
|
157
|
+
* // Create limit order (GTC by default)
|
|
158
|
+
* const limitResult = await orderMgr.createOrder({
|
|
41
159
|
* tokenId: '0x...',
|
|
42
160
|
* side: 'BUY',
|
|
43
161
|
* price: 0.52,
|
|
44
162
|
* size: 100,
|
|
45
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
|
+
* });
|
|
46
180
|
* ```
|
|
47
181
|
*/
|
|
48
182
|
import { EventEmitter } from 'events';
|
|
49
|
-
import { type LimitOrderParams, type Order, type OrderResult } from './trading-service.js';
|
|
183
|
+
import { type LimitOrderParams, type MarketOrderParams, type Order, type OrderResult } from './trading-service.js';
|
|
50
184
|
import { RateLimiter } from '../core/rate-limiter.js';
|
|
51
185
|
import type { UnifiedCache } from '../core/unified-cache.js';
|
|
52
|
-
import { OrderStatus } from '../core/types.js';
|
|
186
|
+
import { OrderStatus, type Side } from '../core/types.js';
|
|
53
187
|
export interface OrderManagerConfig {
|
|
54
188
|
/** Private key for signing transactions */
|
|
55
189
|
privateKey: string;
|
|
@@ -160,6 +294,101 @@ export interface RejectEvent {
|
|
|
160
294
|
reason: string;
|
|
161
295
|
timestamp: number;
|
|
162
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Status of an order as seen through the OrderHandle.
|
|
299
|
+
* Maps to OrderStatus enum values but as a string union for ergonomic usage.
|
|
300
|
+
*/
|
|
301
|
+
export type OrderHandleStatus = 'created' | 'open' | 'partially_filled' | 'filled' | 'cancelled' | 'rejected' | 'expired';
|
|
302
|
+
/**
|
|
303
|
+
* Terminal result returned when awaiting an OrderHandle.
|
|
304
|
+
*/
|
|
305
|
+
export interface OrderFinalResult {
|
|
306
|
+
status: 'filled' | 'cancelled' | 'rejected' | 'expired';
|
|
307
|
+
order: Order | null;
|
|
308
|
+
fills: FillEvent[];
|
|
309
|
+
reason?: string;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Fluent, chainable handle for an order's lifecycle.
|
|
313
|
+
*
|
|
314
|
+
* Implements PromiseLike so callers can `await` for terminal state.
|
|
315
|
+
* Provides chainable lifecycle callbacks and cancel() for control.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const handle = orderManager.placeOrder({ tokenId, side: 'BUY', price: 0.52, size: 100 });
|
|
320
|
+
*
|
|
321
|
+
* handle
|
|
322
|
+
* .onAccepted((order) => console.log('Live:', order.id))
|
|
323
|
+
* .onPartialFill((fill) => console.log('Partial:', fill.fill.size))
|
|
324
|
+
* .onFilled((fill) => console.log('Done!'));
|
|
325
|
+
*
|
|
326
|
+
* const result = await handle;
|
|
327
|
+
* console.log(result.status, result.fills.length);
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
export interface OrderHandle extends PromiseLike<OrderFinalResult> {
|
|
331
|
+
/** Called when the order is accepted and open in the orderbook */
|
|
332
|
+
onAccepted(handler: (order: Order) => void): this;
|
|
333
|
+
/** Called on each partial fill */
|
|
334
|
+
onPartialFill(handler: (fill: FillEvent) => void): this;
|
|
335
|
+
/** Called when the order is fully filled */
|
|
336
|
+
onFilled(handler: (fill: FillEvent) => void): this;
|
|
337
|
+
/** Called if the order is rejected (validation/API failure) */
|
|
338
|
+
onRejected(handler: (reason: string) => void): this;
|
|
339
|
+
/** Called if the order is cancelled */
|
|
340
|
+
onCancelled(handler: (order: Order) => void): this;
|
|
341
|
+
/** Called if the order expires (GTD) */
|
|
342
|
+
onExpired(handler: (order: Order) => void): this;
|
|
343
|
+
/** Cancel the order. Returns true if cancellation succeeded. */
|
|
344
|
+
cancel(): Promise<boolean>;
|
|
345
|
+
/** The order ID (available after API acceptance, undefined before) */
|
|
346
|
+
readonly orderId: string | undefined;
|
|
347
|
+
/** Current status of the order */
|
|
348
|
+
readonly status: OrderHandleStatus;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Internal implementation of OrderHandle.
|
|
352
|
+
*
|
|
353
|
+
* Lifecycle:
|
|
354
|
+
* 1. Constructor receives orderManager ref and an executor function
|
|
355
|
+
* 2. Status starts at 'created'
|
|
356
|
+
* 3. Executor is invoked immediately (fire-and-forget)
|
|
357
|
+
* 4. On success: stores orderId, subscribes to OrderManager events
|
|
358
|
+
* 5. On rejection: transitions to 'rejected', resolves promise
|
|
359
|
+
* 6. On terminal events: resolves promise, removes listeners
|
|
360
|
+
*/
|
|
361
|
+
export declare class OrderHandleImpl implements OrderHandle {
|
|
362
|
+
private orderManager;
|
|
363
|
+
private executor;
|
|
364
|
+
private _orderId;
|
|
365
|
+
private _status;
|
|
366
|
+
private _fills;
|
|
367
|
+
private _order;
|
|
368
|
+
private _reason;
|
|
369
|
+
private _resolve;
|
|
370
|
+
private _promise;
|
|
371
|
+
private _handlers;
|
|
372
|
+
private _eventCleanup;
|
|
373
|
+
constructor(orderManager: OrderManager, executor: () => Promise<OrderResult>);
|
|
374
|
+
then<TResult1 = OrderFinalResult, TResult2 = never>(onfulfilled?: ((value: OrderFinalResult) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
375
|
+
onAccepted(handler: (order: Order) => void): this;
|
|
376
|
+
onPartialFill(handler: (fill: FillEvent) => void): this;
|
|
377
|
+
onFilled(handler: (fill: FillEvent) => void): this;
|
|
378
|
+
onRejected(handler: (reason: string) => void): this;
|
|
379
|
+
onCancelled(handler: (order: Order) => void): this;
|
|
380
|
+
onExpired(handler: (order: Order) => void): this;
|
|
381
|
+
cancel(): Promise<boolean>;
|
|
382
|
+
get orderId(): string | undefined;
|
|
383
|
+
get status(): OrderHandleStatus;
|
|
384
|
+
private execute;
|
|
385
|
+
private subscribeToEvents;
|
|
386
|
+
private resolveTerminal;
|
|
387
|
+
private cleanup;
|
|
388
|
+
private isTerminal;
|
|
389
|
+
private addHandler;
|
|
390
|
+
private invokeHandlers;
|
|
391
|
+
}
|
|
163
392
|
export declare class OrderManager extends EventEmitter {
|
|
164
393
|
private tradingService;
|
|
165
394
|
private realtimeService;
|
|
@@ -201,11 +430,36 @@ export declare class OrderManager extends EventEmitter {
|
|
|
201
430
|
* @returns Order result with orderId or error
|
|
202
431
|
*/
|
|
203
432
|
createOrder(params: LimitOrderParams, metadata?: OrderMetadata): Promise<OrderResult>;
|
|
433
|
+
/**
|
|
434
|
+
* Create and submit a market order (FOK or FAK)
|
|
435
|
+
*
|
|
436
|
+
* Market order lifecycle:
|
|
437
|
+
* - FOK (Fill Or Kill): Must fill completely or cancels immediately
|
|
438
|
+
* PENDING → FILLED (success) or PENDING → CANCELLED (failed to fill)
|
|
439
|
+
* - FAK (Fill And Kill): Fills what it can, cancels the rest
|
|
440
|
+
* PENDING → PARTIALLY_FILLED + CANCELLED (partial) or PENDING → FILLED (complete)
|
|
441
|
+
*
|
|
442
|
+
* Auto-validates (Polymarket-specific):
|
|
443
|
+
* - Minimum value ($1)
|
|
444
|
+
*
|
|
445
|
+
* Auto-watches: Starts monitoring immediately after creation
|
|
446
|
+
* Note: Market orders typically complete very quickly (within seconds)
|
|
447
|
+
*
|
|
448
|
+
* @param params Market order parameters
|
|
449
|
+
* @param metadata Optional metadata for tracking
|
|
450
|
+
* @returns Order result with orderId or error
|
|
451
|
+
*/
|
|
452
|
+
createMarketOrder(params: MarketOrderParams, metadata?: OrderMetadata): Promise<OrderResult>;
|
|
204
453
|
/**
|
|
205
454
|
* Cancel an order
|
|
206
455
|
* Auto-unwatches after cancellation
|
|
207
456
|
*/
|
|
208
457
|
cancelOrder(orderId: string): Promise<OrderResult>;
|
|
458
|
+
/**
|
|
459
|
+
* Cancel all open orders for this wallet.
|
|
460
|
+
* Useful for cleanup on strategy shutdown.
|
|
461
|
+
*/
|
|
462
|
+
cancelAllOrders(): Promise<OrderResult>;
|
|
209
463
|
/**
|
|
210
464
|
* Get order details
|
|
211
465
|
* Fetches from TradingService (CLOB API)
|
|
@@ -217,13 +471,65 @@ export declare class OrderManager extends EventEmitter {
|
|
|
217
471
|
*/
|
|
218
472
|
createBatchOrders(orders: LimitOrderParams[], metadata?: OrderMetadata): Promise<OrderResult>;
|
|
219
473
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
474
|
+
* Place a limit order and return a fluent OrderHandle.
|
|
475
|
+
*
|
|
476
|
+
* The handle is PromiseLike - await it for the terminal result.
|
|
477
|
+
* Chain lifecycle callbacks for real-time updates.
|
|
478
|
+
*
|
|
479
|
+
* @param params Limit order parameters
|
|
480
|
+
* @param metadata Optional metadata for tracking
|
|
481
|
+
* @returns OrderHandle - chainable, awaitable order lifecycle
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```typescript
|
|
485
|
+
* const handle = orderManager.placeOrder({
|
|
486
|
+
* tokenId: '0x...',
|
|
487
|
+
* side: 'BUY',
|
|
488
|
+
* price: 0.52,
|
|
489
|
+
* size: 100,
|
|
490
|
+
* });
|
|
222
491
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
492
|
+
* handle
|
|
493
|
+
* .onAccepted((order) => console.log('Live:', order.id))
|
|
494
|
+
* .onFilled((fill) => console.log('Done!'));
|
|
495
|
+
*
|
|
496
|
+
* const result = await handle;
|
|
497
|
+
* ```
|
|
225
498
|
*/
|
|
226
|
-
|
|
499
|
+
placeOrder(params: LimitOrderParams, metadata?: OrderMetadata): OrderHandle;
|
|
500
|
+
/**
|
|
501
|
+
* Place a market order (FOK/FAK) and return a fluent OrderHandle.
|
|
502
|
+
*
|
|
503
|
+
* @param params Market order parameters
|
|
504
|
+
* @param metadata Optional metadata for tracking
|
|
505
|
+
* @returns OrderHandle - chainable, awaitable order lifecycle
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```typescript
|
|
509
|
+
* const result = await orderManager.placeMarketOrder({
|
|
510
|
+
* tokenId: '0x...',
|
|
511
|
+
* side: 'BUY',
|
|
512
|
+
* amount: 50,
|
|
513
|
+
* orderType: 'FOK',
|
|
514
|
+
* });
|
|
515
|
+
* console.log(result.status); // 'filled' or 'cancelled'
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
placeMarketOrder(params: MarketOrderParams, metadata?: OrderMetadata): OrderHandle;
|
|
519
|
+
/**
|
|
520
|
+
* Watch an order by ID
|
|
521
|
+
*
|
|
522
|
+
* @param orderId - Order ID to watch
|
|
523
|
+
* @param metadata - Optional metadata for strategy context
|
|
524
|
+
* @param initialOrderInfo - Optional initial order info (tokenId, side, price, size)
|
|
525
|
+
* to avoid relying on polling for accurate token type
|
|
526
|
+
*/
|
|
527
|
+
watchOrder(orderId: string, metadata?: OrderMetadata, initialOrderInfo?: {
|
|
528
|
+
tokenId?: string;
|
|
529
|
+
side?: Side;
|
|
530
|
+
price?: number;
|
|
531
|
+
size?: number;
|
|
532
|
+
}): void;
|
|
227
533
|
/**
|
|
228
534
|
* Stop watching an order
|
|
229
535
|
*/
|
|
@@ -241,6 +547,11 @@ export declare class OrderManager extends EventEmitter {
|
|
|
241
547
|
* All checks here are Polymarket-specific
|
|
242
548
|
*/
|
|
243
549
|
private validateOrder;
|
|
550
|
+
/**
|
|
551
|
+
* Validate market order parameters before submission
|
|
552
|
+
* Market orders have simpler validation than limit orders
|
|
553
|
+
*/
|
|
554
|
+
private validateMarketOrder;
|
|
244
555
|
/**
|
|
245
556
|
* Ensure WebSocket connection is established
|
|
246
557
|
* Lazy initialization of RealtimeService
|
|
@@ -254,6 +565,10 @@ export declare class OrderManager extends EventEmitter {
|
|
|
254
565
|
/**
|
|
255
566
|
* Handle USER_TRADE WebSocket event (Polymarket-specific)
|
|
256
567
|
* Triggered when: MATCHED, MINED, CONFIRMED
|
|
568
|
+
*
|
|
569
|
+
* Order lookup priority:
|
|
570
|
+
* 1. takerOrderId - if we placed a market order (FOK/FAK) or taker limit order
|
|
571
|
+
* 2. makerOrders[].orderId - if our limit order was matched as maker
|
|
257
572
|
*/
|
|
258
573
|
private handleUserTrade;
|
|
259
574
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-manager.d.ts","sourceRoot":"","sources":["../../../src/services/order-manager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"order-manager.d.ts","sourceRoot":"","sources":["../../../src/services/order-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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