@catalyst-team/poly-sdk 0.2.1 → 0.3.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.
Files changed (97) hide show
  1. package/README.md +545 -812
  2. package/README.zh-CN.md +645 -342
  3. package/dist/__tests__/integration/arbitrage-service.integration.test.d.ts +12 -0
  4. package/dist/__tests__/integration/arbitrage-service.integration.test.d.ts.map +1 -0
  5. package/dist/__tests__/integration/arbitrage-service.integration.test.js +267 -0
  6. package/dist/__tests__/integration/arbitrage-service.integration.test.js.map +1 -0
  7. package/dist/__tests__/integration/data-api.integration.test.js +6 -3
  8. package/dist/__tests__/integration/data-api.integration.test.js.map +1 -1
  9. package/dist/__tests__/integration/market-service.integration.test.d.ts +10 -0
  10. package/dist/__tests__/integration/market-service.integration.test.d.ts.map +1 -0
  11. package/dist/__tests__/integration/market-service.integration.test.js +173 -0
  12. package/dist/__tests__/integration/market-service.integration.test.js.map +1 -0
  13. package/dist/__tests__/integration/realtime-service-v2.integration.test.d.ts +10 -0
  14. package/dist/__tests__/integration/realtime-service-v2.integration.test.d.ts.map +1 -0
  15. package/dist/__tests__/integration/realtime-service-v2.integration.test.js +307 -0
  16. package/dist/__tests__/integration/realtime-service-v2.integration.test.js.map +1 -0
  17. package/dist/__tests__/integration/trading-service.integration.test.d.ts +10 -0
  18. package/dist/__tests__/integration/trading-service.integration.test.d.ts.map +1 -0
  19. package/dist/__tests__/integration/trading-service.integration.test.js +58 -0
  20. package/dist/__tests__/integration/trading-service.integration.test.js.map +1 -0
  21. package/dist/clients/clob-api.d.ts +73 -0
  22. package/dist/clients/clob-api.d.ts.map +1 -1
  23. package/dist/clients/clob-api.js +60 -0
  24. package/dist/clients/clob-api.js.map +1 -1
  25. package/dist/clients/data-api.d.ts +319 -14
  26. package/dist/clients/data-api.d.ts.map +1 -1
  27. package/dist/clients/data-api.js +342 -15
  28. package/dist/clients/data-api.js.map +1 -1
  29. package/dist/clients/subgraph.d.ts +196 -0
  30. package/dist/clients/subgraph.d.ts.map +1 -0
  31. package/dist/clients/subgraph.js +332 -0
  32. package/dist/clients/subgraph.js.map +1 -0
  33. package/dist/clients/websocket-manager.d.ts +3 -0
  34. package/dist/clients/websocket-manager.d.ts.map +1 -1
  35. package/dist/clients/websocket-manager.js +10 -3
  36. package/dist/clients/websocket-manager.js.map +1 -1
  37. package/dist/core/cache.d.ts +1 -0
  38. package/dist/core/cache.d.ts.map +1 -1
  39. package/dist/core/cache.js +1 -0
  40. package/dist/core/cache.js.map +1 -1
  41. package/dist/core/errors.d.ts +2 -1
  42. package/dist/core/errors.d.ts.map +1 -1
  43. package/dist/core/errors.js +2 -0
  44. package/dist/core/errors.js.map +1 -1
  45. package/dist/core/rate-limiter.d.ts +2 -1
  46. package/dist/core/rate-limiter.d.ts.map +1 -1
  47. package/dist/core/rate-limiter.js +5 -0
  48. package/dist/core/rate-limiter.js.map +1 -1
  49. package/dist/core/types.d.ts +100 -12
  50. package/dist/core/types.d.ts.map +1 -1
  51. package/dist/core/types.js.map +1 -1
  52. package/dist/core/types.test.d.ts +7 -0
  53. package/dist/core/types.test.d.ts.map +1 -0
  54. package/dist/core/types.test.js +122 -0
  55. package/dist/core/types.test.js.map +1 -0
  56. package/dist/index.d.ts +76 -18
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +125 -132
  59. package/dist/index.js.map +1 -1
  60. package/dist/services/arbitrage-service.d.ts +3 -2
  61. package/dist/services/arbitrage-service.d.ts.map +1 -1
  62. package/dist/services/arbitrage-service.js +58 -40
  63. package/dist/services/arbitrage-service.js.map +1 -1
  64. package/dist/services/market-service.d.ts +108 -8
  65. package/dist/services/market-service.d.ts.map +1 -1
  66. package/dist/services/market-service.js +352 -36
  67. package/dist/services/market-service.js.map +1 -1
  68. package/dist/services/onchain-service.d.ts +309 -0
  69. package/dist/services/onchain-service.d.ts.map +1 -0
  70. package/dist/services/onchain-service.js +417 -0
  71. package/dist/services/onchain-service.js.map +1 -0
  72. package/dist/services/realtime-service-v2.d.ts +361 -0
  73. package/dist/services/realtime-service-v2.d.ts.map +1 -0
  74. package/dist/services/realtime-service-v2.js +840 -0
  75. package/dist/services/realtime-service-v2.js.map +1 -0
  76. package/dist/services/realtime-service.d.ts +17 -17
  77. package/dist/services/realtime-service.d.ts.map +1 -1
  78. package/dist/services/realtime-service.js +91 -59
  79. package/dist/services/realtime-service.js.map +1 -1
  80. package/dist/services/smart-money-service.d.ts +196 -0
  81. package/dist/services/smart-money-service.d.ts.map +1 -0
  82. package/dist/services/smart-money-service.js +358 -0
  83. package/dist/services/smart-money-service.js.map +1 -0
  84. package/dist/services/trading-service.d.ts +156 -0
  85. package/dist/services/trading-service.d.ts.map +1 -0
  86. package/dist/services/trading-service.js +356 -0
  87. package/dist/services/trading-service.js.map +1 -0
  88. package/dist/services/wallet-service.d.ts +183 -2
  89. package/dist/services/wallet-service.d.ts.map +1 -1
  90. package/dist/services/wallet-service.js +458 -1
  91. package/dist/services/wallet-service.js.map +1 -1
  92. package/dist/utils/price-utils.test.d.ts +5 -0
  93. package/dist/utils/price-utils.test.d.ts.map +1 -0
  94. package/dist/utils/price-utils.test.js +192 -0
  95. package/dist/utils/price-utils.test.js.map +1 -0
  96. package/package.json +4 -3
  97. package/README.en.md +0 -502
@@ -0,0 +1,358 @@
1
+ /**
2
+ * SmartMoneyService
3
+ *
4
+ * 聪明钱监控和自动跟单服务
5
+ *
6
+ * 核心功能:
7
+ * 1. 监听指定地址的交易 - subscribeSmartMoneyTrades()
8
+ * 2. 自动跟单 - startAutoCopyTrading()
9
+ * 3. 聪明钱信息获取 - getSmartMoneyList(), getSmartMoneyInfo()
10
+ *
11
+ * ============================================================================
12
+ * 设计决策
13
+ * ============================================================================
14
+ *
15
+ * ## 监控方式
16
+ * 使用 Activity WebSocket,延迟 < 100ms,实测验证有效。
17
+ *
18
+ * ## 下单方式
19
+ * | 方式 | 使用场景 | 特点 |
20
+ * |------|---------|------|
21
+ * | FOK | 小额跟单 | 全部成交或取消 |
22
+ * | FAK | 大额跟单 | 部分成交也接受 |
23
+ *
24
+ * ## 重要限制
25
+ * ⚠️ Activity WebSocket 不会广播用户自己的交易!
26
+ * 验证跟单结果请使用 TradingService.getTrades()
27
+ */
28
+ // ============================================================================
29
+ // SmartMoneyService
30
+ // ============================================================================
31
+ export class SmartMoneyService {
32
+ walletService;
33
+ realtimeService;
34
+ tradingService;
35
+ config;
36
+ smartMoneyCache = new Map();
37
+ smartMoneySet = new Set();
38
+ cacheTimestamp = 0;
39
+ activeSubscription = null;
40
+ tradeHandlers = new Set();
41
+ constructor(walletService, realtimeService, tradingService, config = {}) {
42
+ this.walletService = walletService;
43
+ this.realtimeService = realtimeService;
44
+ this.tradingService = tradingService;
45
+ this.config = {
46
+ minPnl: config.minPnl ?? 1000,
47
+ cacheTtl: config.cacheTtl ?? 300000,
48
+ };
49
+ }
50
+ // ============================================================================
51
+ // Smart Money Info
52
+ // ============================================================================
53
+ /**
54
+ * Get list of Smart Money wallets from leaderboard
55
+ */
56
+ async getSmartMoneyList(limit = 100) {
57
+ if (this.isCacheValid()) {
58
+ return Array.from(this.smartMoneyCache.values());
59
+ }
60
+ const leaderboardPage = await this.walletService.getLeaderboard(0, limit);
61
+ const entries = leaderboardPage.entries;
62
+ const smartMoneyList = [];
63
+ for (let i = 0; i < entries.length; i++) {
64
+ const trader = entries[i];
65
+ if (trader.pnl < this.config.minPnl)
66
+ continue;
67
+ const wallet = {
68
+ address: trader.address.toLowerCase(),
69
+ name: trader.userName,
70
+ pnl: trader.pnl,
71
+ volume: trader.volume,
72
+ score: Math.min(100, Math.round((trader.pnl / 100000) * 50 + (trader.volume / 1000000) * 50)),
73
+ rank: trader.rank ?? i + 1,
74
+ };
75
+ smartMoneyList.push(wallet);
76
+ this.smartMoneyCache.set(wallet.address, wallet);
77
+ this.smartMoneySet.add(wallet.address);
78
+ }
79
+ this.cacheTimestamp = Date.now();
80
+ return smartMoneyList;
81
+ }
82
+ /**
83
+ * Check if an address is Smart Money
84
+ */
85
+ async isSmartMoney(address) {
86
+ const normalized = address.toLowerCase();
87
+ if (this.isCacheValid()) {
88
+ return this.smartMoneySet.has(normalized);
89
+ }
90
+ await this.getSmartMoneyList();
91
+ return this.smartMoneySet.has(normalized);
92
+ }
93
+ /**
94
+ * Get Smart Money info for an address
95
+ */
96
+ async getSmartMoneyInfo(address) {
97
+ const normalized = address.toLowerCase();
98
+ if (this.isCacheValid() && this.smartMoneyCache.has(normalized)) {
99
+ return this.smartMoneyCache.get(normalized);
100
+ }
101
+ await this.getSmartMoneyList();
102
+ return this.smartMoneyCache.get(normalized) || null;
103
+ }
104
+ // ============================================================================
105
+ // Trade Subscription - 监听交易
106
+ // ============================================================================
107
+ /**
108
+ * Subscribe to trades from specific addresses
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const sub = smartMoneyService.subscribeSmartMoneyTrades(
113
+ * (trade) => {
114
+ * console.log(`${trade.traderName} ${trade.side} ${trade.size} @ ${trade.price}`);
115
+ * },
116
+ * { filterAddresses: ['0x1234...', '0x5678...'] }
117
+ * );
118
+ *
119
+ * // Stop listening
120
+ * sub.unsubscribe();
121
+ * ```
122
+ */
123
+ subscribeSmartMoneyTrades(onTrade, options = {}) {
124
+ this.tradeHandlers.add(onTrade);
125
+ // Ensure cache is populated
126
+ this.getSmartMoneyList().catch(() => { });
127
+ // Start subscription if not active
128
+ if (!this.activeSubscription) {
129
+ this.activeSubscription = this.realtimeService.subscribeAllActivity({
130
+ onTrade: (activityTrade) => {
131
+ this.handleActivityTrade(activityTrade, options);
132
+ },
133
+ onError: (error) => {
134
+ console.error('[SmartMoneyService] Subscription error:', error);
135
+ },
136
+ });
137
+ }
138
+ return {
139
+ id: `smart_money_${Date.now()}`,
140
+ unsubscribe: () => {
141
+ this.tradeHandlers.delete(onTrade);
142
+ if (this.tradeHandlers.size === 0 && this.activeSubscription) {
143
+ this.activeSubscription.unsubscribe();
144
+ this.activeSubscription = null;
145
+ }
146
+ },
147
+ };
148
+ }
149
+ async handleActivityTrade(trade, options) {
150
+ const rawAddress = trade.trader?.address;
151
+ if (!rawAddress)
152
+ return;
153
+ const traderAddress = rawAddress.toLowerCase();
154
+ // Address filter
155
+ if (options.filterAddresses && options.filterAddresses.length > 0) {
156
+ const normalized = options.filterAddresses.map(a => a.toLowerCase());
157
+ if (!normalized.includes(traderAddress))
158
+ return;
159
+ }
160
+ // Size filter
161
+ if (options.minSize && trade.size < options.minSize)
162
+ return;
163
+ // Smart Money filter
164
+ const isSmartMoney = this.smartMoneySet.has(traderAddress);
165
+ if (options.smartMoneyOnly && !isSmartMoney)
166
+ return;
167
+ const smartMoneyTrade = {
168
+ traderAddress,
169
+ traderName: trade.trader?.name,
170
+ conditionId: trade.conditionId,
171
+ marketSlug: trade.marketSlug,
172
+ side: trade.side,
173
+ size: trade.size,
174
+ price: trade.price,
175
+ tokenId: trade.asset,
176
+ outcome: trade.outcome,
177
+ txHash: trade.transactionHash,
178
+ timestamp: trade.timestamp,
179
+ isSmartMoney,
180
+ smartMoneyInfo: this.smartMoneyCache.get(traderAddress),
181
+ };
182
+ for (const handler of this.tradeHandlers) {
183
+ try {
184
+ handler(smartMoneyTrade);
185
+ }
186
+ catch (error) {
187
+ console.error('[SmartMoneyService] Handler error:', error);
188
+ }
189
+ }
190
+ }
191
+ // ============================================================================
192
+ // Auto Copy Trading - 自动跟单
193
+ // ============================================================================
194
+ /**
195
+ * Start auto copy trading - 自动跟单
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const sub = await smartMoneyService.startAutoCopyTrading({
200
+ * targetAddresses: ['0x1234...'],
201
+ * // 或者跟踪排行榜前N名
202
+ * topN: 10,
203
+ *
204
+ * sizeScale: 0.1, // 10%
205
+ * maxSizePerTrade: 50, // $50
206
+ * maxSlippage: 0.03, // 3%
207
+ * orderType: 'FOK',
208
+ *
209
+ * dryRun: true, // 测试模式
210
+ *
211
+ * onTrade: (trade, result) => console.log(result),
212
+ * });
213
+ *
214
+ * // 停止
215
+ * sub.stop();
216
+ * ```
217
+ */
218
+ async startAutoCopyTrading(options) {
219
+ const startTime = Date.now();
220
+ // Build target list
221
+ let targetAddresses = [];
222
+ if (options.targetAddresses?.length) {
223
+ targetAddresses = options.targetAddresses.map(a => a.toLowerCase());
224
+ }
225
+ if (options.topN && options.topN > 0) {
226
+ const smartMoneyList = await this.getSmartMoneyList(options.topN);
227
+ const topAddresses = smartMoneyList.map(w => w.address);
228
+ targetAddresses = [...new Set([...targetAddresses, ...topAddresses])];
229
+ }
230
+ if (targetAddresses.length === 0) {
231
+ throw new Error('No target addresses. Use targetAddresses or topN.');
232
+ }
233
+ // Stats
234
+ const stats = {
235
+ startTime,
236
+ tradesDetected: 0,
237
+ tradesExecuted: 0,
238
+ tradesSkipped: 0,
239
+ tradesFailed: 0,
240
+ totalUsdcSpent: 0,
241
+ };
242
+ // Config
243
+ const sizeScale = options.sizeScale ?? 0.1;
244
+ const maxSizePerTrade = options.maxSizePerTrade ?? 50;
245
+ const maxSlippage = options.maxSlippage ?? 0.03;
246
+ const orderType = options.orderType ?? 'FOK';
247
+ const minTradeSize = options.minTradeSize ?? 10;
248
+ const sideFilter = options.sideFilter;
249
+ const delay = options.delay ?? 0;
250
+ const dryRun = options.dryRun ?? false;
251
+ // Subscribe
252
+ const subscription = this.subscribeSmartMoneyTrades(async (trade) => {
253
+ stats.tradesDetected++;
254
+ try {
255
+ // Check target
256
+ if (!targetAddresses.includes(trade.traderAddress.toLowerCase())) {
257
+ return;
258
+ }
259
+ // Filters
260
+ const tradeValue = trade.size * trade.price;
261
+ if (tradeValue < minTradeSize) {
262
+ stats.tradesSkipped++;
263
+ return;
264
+ }
265
+ if (sideFilter && trade.side !== sideFilter) {
266
+ stats.tradesSkipped++;
267
+ return;
268
+ }
269
+ // Calculate size
270
+ let copySize = trade.size * sizeScale;
271
+ let copyValue = copySize * trade.price;
272
+ // Enforce max size
273
+ if (copyValue > maxSizePerTrade) {
274
+ copySize = maxSizePerTrade / trade.price;
275
+ copyValue = maxSizePerTrade;
276
+ }
277
+ // Polymarket minimum order is $1
278
+ const MIN_ORDER_SIZE = 1;
279
+ if (copyValue < MIN_ORDER_SIZE) {
280
+ stats.tradesSkipped++;
281
+ return;
282
+ }
283
+ // Delay
284
+ if (delay > 0) {
285
+ await new Promise(resolve => setTimeout(resolve, delay));
286
+ }
287
+ // Token
288
+ const tokenId = trade.tokenId;
289
+ if (!tokenId) {
290
+ stats.tradesSkipped++;
291
+ return;
292
+ }
293
+ // Price with slippage
294
+ const slippagePrice = trade.side === 'BUY'
295
+ ? trade.price * (1 + maxSlippage)
296
+ : trade.price * (1 - maxSlippage);
297
+ const usdcAmount = copyValue; // Already calculated above
298
+ // Execute
299
+ let result;
300
+ if (dryRun) {
301
+ result = { success: true, orderId: `dry_run_${Date.now()}` };
302
+ console.log('[DRY RUN]', {
303
+ trader: trade.traderAddress.slice(0, 10),
304
+ side: trade.side,
305
+ market: trade.marketSlug,
306
+ copy: { size: copySize.toFixed(2), usdc: usdcAmount.toFixed(2) },
307
+ });
308
+ }
309
+ else {
310
+ result = await this.tradingService.createMarketOrder({
311
+ tokenId,
312
+ side: trade.side,
313
+ amount: usdcAmount,
314
+ price: slippagePrice,
315
+ orderType,
316
+ });
317
+ }
318
+ if (result.success) {
319
+ stats.tradesExecuted++;
320
+ stats.totalUsdcSpent += usdcAmount;
321
+ }
322
+ else {
323
+ stats.tradesFailed++;
324
+ }
325
+ options.onTrade?.(trade, result);
326
+ }
327
+ catch (error) {
328
+ stats.tradesFailed++;
329
+ options.onError?.(error instanceof Error ? error : new Error(String(error)));
330
+ }
331
+ }, { filterAddresses: targetAddresses, minSize: minTradeSize });
332
+ return {
333
+ id: subscription.id,
334
+ targetAddresses,
335
+ startTime,
336
+ isActive: true,
337
+ stats,
338
+ stop: () => subscription.unsubscribe(),
339
+ getStats: () => ({ ...stats }),
340
+ };
341
+ }
342
+ // ============================================================================
343
+ // Utilities
344
+ // ============================================================================
345
+ isCacheValid() {
346
+ return Date.now() - this.cacheTimestamp < this.config.cacheTtl && this.smartMoneyCache.size > 0;
347
+ }
348
+ disconnect() {
349
+ if (this.activeSubscription) {
350
+ this.activeSubscription.unsubscribe();
351
+ this.activeSubscription = null;
352
+ }
353
+ this.tradeHandlers.clear();
354
+ this.smartMoneyCache.clear();
355
+ this.smartMoneySet.clear();
356
+ }
357
+ }
358
+ //# sourceMappingURL=smart-money-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-money-service.js","sourceRoot":"","sources":["../../src/services/smart-money-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AA6GH,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,MAAM,OAAO,iBAAiB;IACpB,aAAa,CAAgB;IAC7B,eAAe,CAAoB;IACnC,cAAc,CAAiB;IAC/B,MAAM,CAAoC;IAE1C,eAAe,GAAkC,IAAI,GAAG,EAAE,CAAC;IAC3D,aAAa,GAAgB,IAAI,GAAG,EAAE,CAAC;IACvC,cAAc,GAAW,CAAC,CAAC;IAE3B,kBAAkB,GAAuC,IAAI,CAAC;IAC9D,aAAa,GAA0C,IAAI,GAAG,EAAE,CAAC;IAEzE,YACE,aAA4B,EAC5B,eAAkC,EAClC,cAA8B,EAC9B,SAAkC,EAAE;QAEpC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QAErC,IAAI,CAAC,MAAM,GAAG;YACZ,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI;YAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM;SACpC,CAAC;IACJ,CAAC;IAED,+EAA+E;IAC/E,mBAAmB;IACnB,+EAA+E;IAE/E;;OAEG;IACH,KAAK,CAAC,iBAAiB,CAAC,QAAgB,GAAG;QACzC,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC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,kBAAkB,CAAC,WAAW,EAAE,CAAC;YACtC,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * TradingService
3
+ *
4
+ * Trading service using official @polymarket/clob-client.
5
+ *
6
+ * Provides:
7
+ * - Order creation (limit, market)
8
+ * - Order management (cancel, query)
9
+ * - Rewards tracking
10
+ * - Balance management
11
+ *
12
+ * Note: Market data methods have been moved to MarketService.
13
+ */
14
+ import { ClobClient, type TickSize } from '@polymarket/clob-client';
15
+ import { Wallet } from 'ethers';
16
+ import { RateLimiter } from '../core/rate-limiter.js';
17
+ import type { UnifiedCache } from '../core/unified-cache.js';
18
+ import type { Side } from '../core/types.js';
19
+ export declare const POLYGON_MAINNET = 137;
20
+ export declare const POLYGON_AMOY = 80002;
21
+ export type { Side, OrderType } from '../core/types.js';
22
+ export interface ApiCredentials {
23
+ key: string;
24
+ secret: string;
25
+ passphrase: string;
26
+ }
27
+ export interface TradingServiceConfig {
28
+ /** Private key for signing */
29
+ privateKey: string;
30
+ /** Chain ID (default: Polygon mainnet 137) */
31
+ chainId?: number;
32
+ /** Pre-generated API credentials (optional) */
33
+ credentials?: ApiCredentials;
34
+ }
35
+ export interface LimitOrderParams {
36
+ tokenId: string;
37
+ side: Side;
38
+ price: number;
39
+ size: number;
40
+ orderType?: 'GTC' | 'GTD';
41
+ expiration?: number;
42
+ }
43
+ export interface MarketOrderParams {
44
+ tokenId: string;
45
+ side: Side;
46
+ amount: number;
47
+ price?: number;
48
+ orderType?: 'FOK' | 'FAK';
49
+ }
50
+ export interface Order {
51
+ id: string;
52
+ status: string;
53
+ tokenId: string;
54
+ side: Side;
55
+ price: number;
56
+ originalSize: number;
57
+ filledSize: number;
58
+ remainingSize: number;
59
+ associateTrades: string[];
60
+ createdAt: number;
61
+ }
62
+ export interface OrderResult {
63
+ success: boolean;
64
+ orderId?: string;
65
+ orderIds?: string[];
66
+ errorMsg?: string;
67
+ transactionHashes?: string[];
68
+ }
69
+ export interface TradeInfo {
70
+ id: string;
71
+ tokenId: string;
72
+ side: Side;
73
+ price: number;
74
+ size: number;
75
+ fee: number;
76
+ timestamp: number;
77
+ }
78
+ export interface UserEarning {
79
+ date: string;
80
+ conditionId: string;
81
+ assetAddress: string;
82
+ makerAddress: string;
83
+ earnings: number;
84
+ assetRate: number;
85
+ }
86
+ export interface MarketReward {
87
+ conditionId: string;
88
+ question: string;
89
+ marketSlug: string;
90
+ eventSlug: string;
91
+ rewardsMaxSpread: number;
92
+ rewardsMinSize: number;
93
+ tokens: Array<{
94
+ tokenId: string;
95
+ outcome: string;
96
+ price: number;
97
+ }>;
98
+ rewardsConfig: Array<{
99
+ assetAddress: string;
100
+ startDate: string;
101
+ endDate: string;
102
+ ratePerDay: number;
103
+ totalRewards: number;
104
+ }>;
105
+ }
106
+ export declare class TradingService {
107
+ private rateLimiter;
108
+ private cache;
109
+ private config;
110
+ private clobClient;
111
+ private wallet;
112
+ private chainId;
113
+ private credentials;
114
+ private initialized;
115
+ private tickSizeCache;
116
+ private negRiskCache;
117
+ constructor(rateLimiter: RateLimiter, cache: UnifiedCache, config: TradingServiceConfig);
118
+ initialize(): Promise<void>;
119
+ private ensureInitialized;
120
+ /**
121
+ * Get tick size for a token
122
+ */
123
+ getTickSize(tokenId: string): Promise<TickSize>;
124
+ /**
125
+ * Check if token is neg risk
126
+ */
127
+ isNegRisk(tokenId: string): Promise<boolean>;
128
+ /**
129
+ * Create and post a limit order
130
+ */
131
+ createLimitOrder(params: LimitOrderParams): Promise<OrderResult>;
132
+ /**
133
+ * Create and post a market order
134
+ */
135
+ createMarketOrder(params: MarketOrderParams): Promise<OrderResult>;
136
+ cancelOrder(orderId: string): Promise<OrderResult>;
137
+ cancelOrders(orderIds: string[]): Promise<OrderResult>;
138
+ cancelAllOrders(): Promise<OrderResult>;
139
+ getOpenOrders(marketId?: string): Promise<Order[]>;
140
+ getTrades(marketId?: string): Promise<TradeInfo[]>;
141
+ isOrderScoring(orderId: string): Promise<boolean>;
142
+ areOrdersScoring(orderIds: string[]): Promise<Record<string, boolean>>;
143
+ getEarningsForDay(date: string): Promise<UserEarning[]>;
144
+ getCurrentRewards(): Promise<MarketReward[]>;
145
+ getBalanceAllowance(assetType: 'COLLATERAL' | 'CONDITIONAL', tokenId?: string): Promise<{
146
+ balance: string;
147
+ allowance: string;
148
+ }>;
149
+ updateBalanceAllowance(assetType: 'COLLATERAL' | 'CONDITIONAL', tokenId?: string): Promise<void>;
150
+ getAddress(): string;
151
+ getWallet(): Wallet;
152
+ getCredentials(): ApiCredentials | null;
153
+ isInitialized(): boolean;
154
+ getClobClient(): ClobClient | null;
155
+ }
156
+ //# sourceMappingURL=trading-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trading-service.d.ts","sourceRoot":"","sources":["../../src/services/trading-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,UAAU,EAMV,KAAK,QAAQ,EACd,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAW,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,KAAK,EAAE,IAAI,EAAa,MAAM,kBAAkB,CAAC;AAGxD,eAAO,MAAM,eAAe,MAAM,CAAC;AACnC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAWlC,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MA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