@catalyst-team/poly-sdk 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/.env +0 -0
- package/README.md +803 -0
- package/dist/__tests__/clob-api.test.d.ts +5 -0
- package/dist/__tests__/clob-api.test.d.ts.map +1 -0
- package/dist/__tests__/clob-api.test.js +240 -0
- package/dist/__tests__/clob-api.test.js.map +1 -0
- package/dist/__tests__/integration/bridge-client.integration.test.d.ts +11 -0
- package/dist/__tests__/integration/bridge-client.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/bridge-client.integration.test.js +260 -0
- package/dist/__tests__/integration/bridge-client.integration.test.js.map +1 -0
- package/dist/__tests__/integration/clob-api.integration.test.d.ts +13 -0
- package/dist/__tests__/integration/clob-api.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/clob-api.integration.test.js +170 -0
- package/dist/__tests__/integration/clob-api.integration.test.js.map +1 -0
- package/dist/__tests__/integration/ctf-client.integration.test.d.ts +17 -0
- package/dist/__tests__/integration/ctf-client.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/ctf-client.integration.test.js +234 -0
- package/dist/__tests__/integration/ctf-client.integration.test.js.map +1 -0
- package/dist/__tests__/integration/data-api.integration.test.d.ts +9 -0
- package/dist/__tests__/integration/data-api.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/data-api.integration.test.js +161 -0
- package/dist/__tests__/integration/data-api.integration.test.js.map +1 -0
- package/dist/__tests__/integration/gamma-api.integration.test.d.ts +9 -0
- package/dist/__tests__/integration/gamma-api.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/gamma-api.integration.test.js +170 -0
- package/dist/__tests__/integration/gamma-api.integration.test.js.map +1 -0
- package/dist/__tests__/test-utils.d.ts +92 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -0
- package/dist/__tests__/test-utils.js +143 -0
- package/dist/__tests__/test-utils.js.map +1 -0
- package/dist/clients/bridge-client.d.ts +388 -0
- package/dist/clients/bridge-client.d.ts.map +1 -0
- package/dist/clients/bridge-client.js +587 -0
- package/dist/clients/bridge-client.js.map +1 -0
- package/dist/clients/clob-api.d.ts +318 -0
- package/dist/clients/clob-api.d.ts.map +1 -0
- package/dist/clients/clob-api.js +388 -0
- package/dist/clients/clob-api.js.map +1 -0
- package/dist/clients/ctf-client.d.ts +473 -0
- package/dist/clients/ctf-client.d.ts.map +1 -0
- package/dist/clients/ctf-client.js +915 -0
- package/dist/clients/ctf-client.js.map +1 -0
- package/dist/clients/data-api.d.ts +134 -0
- package/dist/clients/data-api.d.ts.map +1 -0
- package/dist/clients/data-api.js +265 -0
- package/dist/clients/data-api.js.map +1 -0
- package/dist/clients/gamma-api.d.ts +401 -0
- package/dist/clients/gamma-api.d.ts.map +1 -0
- package/dist/clients/gamma-api.js +352 -0
- package/dist/clients/gamma-api.js.map +1 -0
- package/dist/clients/trading-client.d.ts +252 -0
- package/dist/clients/trading-client.d.ts.map +1 -0
- package/dist/clients/trading-client.js +543 -0
- package/dist/clients/trading-client.js.map +1 -0
- package/dist/clients/websocket-manager.d.ts +100 -0
- package/dist/clients/websocket-manager.d.ts.map +1 -0
- package/dist/clients/websocket-manager.js +193 -0
- package/dist/clients/websocket-manager.js.map +1 -0
- package/dist/core/cache-adapter-bridge.d.ts +36 -0
- package/dist/core/cache-adapter-bridge.d.ts.map +1 -0
- package/dist/core/cache-adapter-bridge.js +81 -0
- package/dist/core/cache-adapter-bridge.js.map +1 -0
- package/dist/core/cache.d.ts +40 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +71 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/errors.d.ts +38 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +84 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/rate-limiter.d.ts +31 -0
- package/dist/core/rate-limiter.d.ts.map +1 -0
- package/dist/core/rate-limiter.js +70 -0
- package/dist/core/rate-limiter.js.map +1 -0
- package/dist/core/types.d.ts +314 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +19 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/unified-cache.d.ts +63 -0
- package/dist/core/unified-cache.d.ts.map +1 -0
- package/dist/core/unified-cache.js +114 -0
- package/dist/core/unified-cache.js.map +1 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +258 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/errors.d.ts +33 -0
- package/dist/mcp/errors.d.ts.map +1 -0
- package/dist/mcp/errors.js +86 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +62 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +173 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +17 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +155 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/guide.d.ts +12 -0
- package/dist/mcp/tools/guide.d.ts.map +1 -0
- package/dist/mcp/tools/guide.js +801 -0
- package/dist/mcp/tools/guide.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +11 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +27 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/market.d.ts +11 -0
- package/dist/mcp/tools/market.d.ts.map +1 -0
- package/dist/mcp/tools/market.js +314 -0
- package/dist/mcp/tools/market.js.map +1 -0
- package/dist/mcp/tools/order.d.ts +10 -0
- package/dist/mcp/tools/order.d.ts.map +1 -0
- package/dist/mcp/tools/order.js +258 -0
- package/dist/mcp/tools/order.js.map +1 -0
- package/dist/mcp/tools/trade.d.ts +38 -0
- package/dist/mcp/tools/trade.d.ts.map +1 -0
- package/dist/mcp/tools/trade.js +314 -0
- package/dist/mcp/tools/trade.js.map +1 -0
- package/dist/mcp/tools/trader.d.ts +11 -0
- package/dist/mcp/tools/trader.d.ts.map +1 -0
- package/dist/mcp/tools/trader.js +277 -0
- package/dist/mcp/tools/trader.js.map +1 -0
- package/dist/mcp/tools/wallet.d.ts +274 -0
- package/dist/mcp/tools/wallet.d.ts.map +1 -0
- package/dist/mcp/tools/wallet.js +579 -0
- package/dist/mcp/tools/wallet.js.map +1 -0
- package/dist/mcp/types.d.ts +413 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +5 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/services/authorization-service.d.ts +97 -0
- package/dist/services/authorization-service.d.ts.map +1 -0
- package/dist/services/authorization-service.js +279 -0
- package/dist/services/authorization-service.js.map +1 -0
- package/dist/services/market-service.d.ts +108 -0
- package/dist/services/market-service.d.ts.map +1 -0
- package/dist/services/market-service.js +458 -0
- package/dist/services/market-service.js.map +1 -0
- package/dist/services/realtime-service.d.ts +82 -0
- package/dist/services/realtime-service.d.ts.map +1 -0
- package/dist/services/realtime-service.js +150 -0
- package/dist/services/realtime-service.js.map +1 -0
- package/dist/services/swap-service.d.ts +217 -0
- package/dist/services/swap-service.d.ts.map +1 -0
- package/dist/services/swap-service.js +695 -0
- package/dist/services/swap-service.js.map +1 -0
- package/dist/services/wallet-service.d.ts +94 -0
- package/dist/services/wallet-service.d.ts.map +1 -0
- package/dist/services/wallet-service.js +173 -0
- package/dist/services/wallet-service.js.map +1 -0
- package/dist/utils/price-utils.d.ts +153 -0
- package/dist/utils/price-utils.d.ts.map +1 -0
- package/dist/utils/price-utils.js +236 -0
- package/dist/utils/price-utils.js.map +1 -0
- package/docs/00-design.md +760 -0
- package/docs/01-mcp.md +2041 -0
- package/docs/02-API.md +1148 -0
- package/docs/e2e/01-trader-tools.md +159 -0
- package/docs/e2e/02-market-tools.md +180 -0
- package/docs/e2e/03-order-tools.md +166 -0
- package/docs/e2e/04-wallet-tools.md +224 -0
- package/docs/e2e/05-trading-tools.md +327 -0
- package/docs/e2e/06-integration-scenarios.md +481 -0
- package/docs/e2e/coordinator.md +376 -0
- package/examples/01-basic-usage.ts +68 -0
- package/examples/02-smart-money.ts +95 -0
- package/examples/03-market-analysis.ts +108 -0
- package/examples/04-kline-aggregation.ts +158 -0
- package/examples/05-follow-wallet-strategy.ts +156 -0
- package/examples/06-services-demo.ts +124 -0
- package/examples/07-realtime-websocket.ts +117 -0
- package/examples/08-trading-orders.ts +278 -0
- package/examples/09-rewards-tracking.ts +187 -0
- package/examples/10-ctf-operations.ts +336 -0
- package/examples/11-live-arbitrage-scan.ts +221 -0
- package/examples/12-trending-arb-monitor.ts +406 -0
- package/examples/README.md +179 -0
- package/package.json +62 -0
- package/scripts/README.md +163 -0
- package/scripts/approvals/approve-erc1155.ts +129 -0
- package/scripts/approvals/approve-neg-risk-erc1155.ts +149 -0
- package/scripts/approvals/approve-neg-risk.ts +102 -0
- package/scripts/approvals/check-all-allowances.ts +150 -0
- package/scripts/approvals/check-allowance.ts +129 -0
- package/scripts/approvals/check-ctf-approval.ts +158 -0
- package/scripts/datas/001-report.md +486 -0
- package/scripts/datas/clone-modal-screenshot.png +0 -0
- package/scripts/deposit/deposit-native-usdc.ts +179 -0
- package/scripts/deposit/deposit-usdc.ts +155 -0
- package/scripts/deposit/swap-usdc-to-usdce.ts +375 -0
- package/scripts/research/research-markets.ts +166 -0
- package/scripts/trading/check-orders.ts +50 -0
- package/scripts/trading/sell-nvidia-positions.ts +206 -0
- package/scripts/trading/test-order.ts +172 -0
- package/scripts/truth.md +440 -0
- package/scripts/verify/test-approve-trading.ts +98 -0
- package/scripts/verify/test-provider-fix.ts +43 -0
- package/scripts/verify/test-search-mcp.ts +113 -0
- package/scripts/verify/verify-all-apis.ts +160 -0
- package/scripts/wallet/check-wallet-balances.ts +75 -0
- package/scripts/wallet/test-wallet-operations.ts +191 -0
- package/scripts/wallet/verify-wallet-tools.ts +124 -0
- package/src/__tests__/clob-api.test.ts +301 -0
- package/src/__tests__/integration/bridge-client.integration.test.ts +314 -0
- package/src/__tests__/integration/clob-api.integration.test.ts +218 -0
- package/src/__tests__/integration/ctf-client.integration.test.ts +331 -0
- package/src/__tests__/integration/data-api.integration.test.ts +194 -0
- package/src/__tests__/integration/gamma-api.integration.test.ts +206 -0
- package/src/__tests__/test-utils.ts +170 -0
- package/src/clients/bridge-client.ts +841 -0
- package/src/clients/clob-api.ts +629 -0
- package/src/clients/ctf-client.ts +1216 -0
- package/src/clients/data-api.ts +469 -0
- package/src/clients/gamma-api.ts +597 -0
- package/src/clients/trading-client.ts +749 -0
- package/src/clients/websocket-manager.ts +267 -0
- package/src/core/cache-adapter-bridge.ts +94 -0
- package/src/core/cache.ts +85 -0
- package/src/core/errors.ts +117 -0
- package/src/core/rate-limiter.ts +74 -0
- package/src/core/types.ts +360 -0
- package/src/core/unified-cache.ts +153 -0
- package/src/index.ts +455 -0
- package/src/mcp/README.md +380 -0
- package/src/mcp/errors.ts +124 -0
- package/src/mcp/index.ts +309 -0
- package/src/mcp/server.ts +183 -0
- package/src/mcp/tools/guide.ts +821 -0
- package/src/mcp/tools/index.ts +73 -0
- package/src/mcp/tools/market.ts +363 -0
- package/src/mcp/tools/order.ts +326 -0
- package/src/mcp/tools/trade.ts +417 -0
- package/src/mcp/tools/trader.ts +322 -0
- package/src/mcp/tools/wallet.ts +683 -0
- package/src/mcp/types.ts +472 -0
- package/src/services/authorization-service.ts +357 -0
- package/src/services/market-service.ts +544 -0
- package/src/services/realtime-service.ts +196 -0
- package/src/services/swap-service.ts +896 -0
- package/src/services/wallet-service.ts +259 -0
- package/src/utils/price-utils.ts +307 -0
- package/tsconfig.json +8 -0
- package/vitest.config.ts +19 -0
- package/vitest.integration.config.ts +18 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLOB API Client for Polymarket
|
|
3
|
+
*
|
|
4
|
+
* The Central Limit Order Book (CLOB) API provides access to Polymarket's
|
|
5
|
+
* trading infrastructure. This client handles market information retrieval
|
|
6
|
+
* and orderbook data.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* - Base URL: https://clob.polymarket.com
|
|
10
|
+
* - Rate limits are automatically handled by the RateLimiter
|
|
11
|
+
* - Market data is cached to reduce API calls
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { ClobApiClient, RateLimiter, Cache } from '@prediction-router/poly-sdk';
|
|
16
|
+
*
|
|
17
|
+
* const client = new ClobApiClient(new RateLimiter(), new Cache());
|
|
18
|
+
*
|
|
19
|
+
* // Get market info
|
|
20
|
+
* const market = await client.getMarket('0x123...');
|
|
21
|
+
* console.log(market.question);
|
|
22
|
+
*
|
|
23
|
+
* // Get orderbook
|
|
24
|
+
* const orderbook = await client.getOrderbook(market.tokens[0].tokenId);
|
|
25
|
+
* console.log('Best bid:', orderbook.bids[0]);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @see {@link https://docs.polymarket.com/#clob-api CLOB API Documentation}
|
|
29
|
+
*
|
|
30
|
+
* @module clients/clob-api
|
|
31
|
+
*/
|
|
32
|
+
import { RateLimiter } from '../core/rate-limiter.js';
|
|
33
|
+
import type { UnifiedCache } from '../core/unified-cache.js';
|
|
34
|
+
import type { ProcessedOrderbook } from '../core/types.js';
|
|
35
|
+
/**
|
|
36
|
+
* Market information from the CLOB API
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* A market represents a binary prediction market with YES/NO outcomes.
|
|
40
|
+
* Each outcome has its own ERC-1155 token that can be traded.
|
|
41
|
+
*/
|
|
42
|
+
export interface ClobMarket {
|
|
43
|
+
conditionId: string;
|
|
44
|
+
questionId?: string;
|
|
45
|
+
marketSlug: string;
|
|
46
|
+
question: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
image?: string;
|
|
49
|
+
icon?: string;
|
|
50
|
+
tokens: ClobToken[];
|
|
51
|
+
tags?: string[];
|
|
52
|
+
active: boolean;
|
|
53
|
+
closed: boolean;
|
|
54
|
+
archived?: boolean;
|
|
55
|
+
acceptingOrders: boolean;
|
|
56
|
+
acceptingOrderTimestamp?: string;
|
|
57
|
+
enableOrderBook?: boolean;
|
|
58
|
+
minimumOrderSize?: number;
|
|
59
|
+
minimumTickSize?: number;
|
|
60
|
+
makerBaseFee?: number;
|
|
61
|
+
takerBaseFee?: number;
|
|
62
|
+
endDateIso?: string | null;
|
|
63
|
+
gameStartTime?: string | null;
|
|
64
|
+
secondsDelay?: number;
|
|
65
|
+
negRisk?: boolean;
|
|
66
|
+
negRiskMarketId?: string;
|
|
67
|
+
negRiskRequestId?: string;
|
|
68
|
+
rewards?: {
|
|
69
|
+
rates?: unknown;
|
|
70
|
+
minSize?: number;
|
|
71
|
+
maxSpread?: number;
|
|
72
|
+
};
|
|
73
|
+
fpmm?: string;
|
|
74
|
+
notificationsEnabled?: boolean;
|
|
75
|
+
is5050Outcome?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Token information for a market outcome
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* Each outcome (YES/NO) has its own ERC-1155 token with a unique ID.
|
|
82
|
+
* The tokenId is used for trading and querying orderbooks.
|
|
83
|
+
*/
|
|
84
|
+
export interface ClobToken {
|
|
85
|
+
/**
|
|
86
|
+
* ERC-1155 token ID for this outcome
|
|
87
|
+
* @example "21742633143463906290569050155826241533067272736897614950488156847949938836455"
|
|
88
|
+
*/
|
|
89
|
+
tokenId: string;
|
|
90
|
+
/**
|
|
91
|
+
* Outcome name (typically "Yes" or "No")
|
|
92
|
+
*/
|
|
93
|
+
outcome: string;
|
|
94
|
+
/**
|
|
95
|
+
* Current mid-market price (0-1)
|
|
96
|
+
* @example 0.65 for 65% probability
|
|
97
|
+
*/
|
|
98
|
+
price: number;
|
|
99
|
+
/**
|
|
100
|
+
* Whether this token is the winning outcome (after resolution)
|
|
101
|
+
*/
|
|
102
|
+
winner?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Single price level in an orderbook
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* Represents one row in the order book with a price and total size at that price.
|
|
109
|
+
*/
|
|
110
|
+
export interface OrderbookLevel {
|
|
111
|
+
/**
|
|
112
|
+
* Price level (0.001 to 0.999)
|
|
113
|
+
* @example 0.55
|
|
114
|
+
*/
|
|
115
|
+
price: number;
|
|
116
|
+
/**
|
|
117
|
+
* Total size available at this price (in shares)
|
|
118
|
+
* @example 1500.5
|
|
119
|
+
*/
|
|
120
|
+
size: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Complete orderbook for a token
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* The orderbook contains all open orders for a specific outcome token.
|
|
127
|
+
* - Bids are sorted descending (highest bid first)
|
|
128
|
+
* - Asks are sorted ascending (lowest ask first)
|
|
129
|
+
*/
|
|
130
|
+
export interface Orderbook {
|
|
131
|
+
/**
|
|
132
|
+
* Buy orders, sorted by price descending (best bid first)
|
|
133
|
+
*/
|
|
134
|
+
bids: OrderbookLevel[];
|
|
135
|
+
/**
|
|
136
|
+
* Sell orders, sorted by price ascending (best ask first)
|
|
137
|
+
*/
|
|
138
|
+
asks: OrderbookLevel[];
|
|
139
|
+
/**
|
|
140
|
+
* Timestamp when the orderbook was fetched (Unix ms)
|
|
141
|
+
*/
|
|
142
|
+
timestamp: number;
|
|
143
|
+
market?: string;
|
|
144
|
+
assetId?: string;
|
|
145
|
+
hash?: string;
|
|
146
|
+
minOrderSize?: string;
|
|
147
|
+
tickSize?: string;
|
|
148
|
+
negRisk?: boolean;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* CLOB API client for interacting with Polymarket's orderbook
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* This client provides read-only access to market data and orderbooks.
|
|
155
|
+
* For trading operations, use {@link TradingClient} instead.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const client = new ClobApiClient(rateLimiter, cache);
|
|
160
|
+
*
|
|
161
|
+
* // Get market details
|
|
162
|
+
* const market = await client.getMarket('0x123...');
|
|
163
|
+
*
|
|
164
|
+
* // Get processed orderbook with analytics
|
|
165
|
+
* const processed = await client.getProcessedOrderbook('0x123...');
|
|
166
|
+
* console.log('Long arb profit:', processed.summary.longArbProfit);
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare class ClobApiClient {
|
|
170
|
+
private rateLimiter;
|
|
171
|
+
private cache;
|
|
172
|
+
private config?;
|
|
173
|
+
/**
|
|
174
|
+
* Creates a new CLOB API client
|
|
175
|
+
*
|
|
176
|
+
* @param rateLimiter - Rate limiter instance for API throttling
|
|
177
|
+
* @param cache - Cache instance for storing market data (supports both legacy Cache and CacheAdapter)
|
|
178
|
+
* @param config - Optional configuration for trading capabilities
|
|
179
|
+
* @param config.chainId - Polygon chain ID (137 for mainnet, 80002 for Amoy testnet)
|
|
180
|
+
* @param config.signer - Ethers signer for authenticated requests
|
|
181
|
+
* @param config.creds - API credentials for L2 authentication
|
|
182
|
+
*/
|
|
183
|
+
constructor(rateLimiter: RateLimiter, cache: UnifiedCache, config?: {
|
|
184
|
+
/** Polygon chain ID (137 = mainnet, 80002 = Amoy testnet) */
|
|
185
|
+
chainId?: number;
|
|
186
|
+
/** Ethers signer for authenticated requests */
|
|
187
|
+
signer?: unknown;
|
|
188
|
+
/** API credentials for L2 authentication */
|
|
189
|
+
creds?: {
|
|
190
|
+
key: string;
|
|
191
|
+
secret: string;
|
|
192
|
+
passphrase: string;
|
|
193
|
+
};
|
|
194
|
+
} | undefined);
|
|
195
|
+
/**
|
|
196
|
+
* Get the signer if configured
|
|
197
|
+
* @returns The signer or undefined if not configured
|
|
198
|
+
*/
|
|
199
|
+
get signer(): unknown;
|
|
200
|
+
/**
|
|
201
|
+
* Get market information by condition ID
|
|
202
|
+
*
|
|
203
|
+
* @param conditionId - The unique condition identifier for the market
|
|
204
|
+
* @returns Market information including tokens and status
|
|
205
|
+
*
|
|
206
|
+
* @throws {@link PolymarketError} If the market is not found or API fails
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const market = await client.getMarket('0x82ace55...');
|
|
211
|
+
* console.log(market.question); // "Will BTC reach $100k?"
|
|
212
|
+
* console.log(market.tokens[0].tokenId); // YES token ID
|
|
213
|
+
* console.log(market.tokens[1].tokenId); // NO token ID
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
getMarket(conditionId: string): Promise<ClobMarket>;
|
|
217
|
+
/**
|
|
218
|
+
* Get raw orderbook for a specific token
|
|
219
|
+
*
|
|
220
|
+
* @param tokenId - The ERC-1155 token ID (either YES or NO token)
|
|
221
|
+
* @returns Orderbook with sorted bids and asks
|
|
222
|
+
*
|
|
223
|
+
* @remarks
|
|
224
|
+
* - Bids are sorted descending (highest bid first)
|
|
225
|
+
* - Asks are sorted ascending (lowest ask first)
|
|
226
|
+
* - This returns the raw orderbook for ONE outcome token
|
|
227
|
+
* - For complete market analysis, use {@link getProcessedOrderbook}
|
|
228
|
+
*
|
|
229
|
+
* @throws {@link PolymarketError} If the token is not found or API fails
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const orderbook = await client.getOrderbook('21742633...');
|
|
234
|
+
*
|
|
235
|
+
* console.log('Best bid:', orderbook.bids[0]?.price); // e.g., 0.55
|
|
236
|
+
* console.log('Best ask:', orderbook.asks[0]?.price); // e.g., 0.57
|
|
237
|
+
* console.log('Spread:', orderbook.asks[0]?.price - orderbook.bids[0]?.price);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
getOrderbook(tokenId: string): Promise<Orderbook>;
|
|
241
|
+
/**
|
|
242
|
+
* Get processed orderbook with complete market analysis
|
|
243
|
+
*
|
|
244
|
+
* @param conditionId - The unique condition identifier for the market
|
|
245
|
+
* @returns Processed orderbook with both YES/NO books and arbitrage analysis
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* This method fetches both YES and NO orderbooks and calculates:
|
|
249
|
+
* - Effective prices (accounting for order book mirroring)
|
|
250
|
+
* - Arbitrage opportunities (long and short)
|
|
251
|
+
* - Depth and liquidity metrics
|
|
252
|
+
*
|
|
253
|
+
* **Important**: Polymarket orderbooks have a mirroring property:
|
|
254
|
+
* - Buying YES @ P = Selling NO @ (1-P)
|
|
255
|
+
* - The same order appears in both books
|
|
256
|
+
*
|
|
257
|
+
* Therefore, correct arbitrage calculation must use "effective prices":
|
|
258
|
+
* - effectiveBuyYes = min(YES.ask, 1 - NO.bid)
|
|
259
|
+
* - effectiveBuyNo = min(NO.ask, 1 - YES.bid)
|
|
260
|
+
*
|
|
261
|
+
* @throws {@link PolymarketError} If market not found or missing tokens
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const processed = await client.getProcessedOrderbook('0x82ace55...');
|
|
266
|
+
*
|
|
267
|
+
* // Check for arbitrage
|
|
268
|
+
* if (processed.summary.longArbProfit > 0.003) {
|
|
269
|
+
* console.log('Long arb opportunity!');
|
|
270
|
+
* console.log('Buy YES @', processed.summary.effectivePrices.effectiveBuyYes);
|
|
271
|
+
* console.log('Buy NO @', processed.summary.effectivePrices.effectiveBuyNo);
|
|
272
|
+
* console.log('Profit:', processed.summary.longArbProfit * 100, '%');
|
|
273
|
+
* }
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
getProcessedOrderbook(conditionId: string): Promise<ProcessedOrderbook>;
|
|
277
|
+
/**
|
|
278
|
+
* Process orderbooks and calculate analytics
|
|
279
|
+
*
|
|
280
|
+
* 关键概念:Polymarket 订单簿的镜像特性
|
|
281
|
+
*
|
|
282
|
+
* 买 YES @ P = 卖 NO @ (1-P)
|
|
283
|
+
* 因此同一订单会在 YES 和 NO 订单簿中同时出现
|
|
284
|
+
*
|
|
285
|
+
* 正确的套利计算必须使用"有效价格":
|
|
286
|
+
* - effectiveBuyYes = min(YES.ask, 1 - NO.bid)
|
|
287
|
+
* - effectiveBuyNo = min(NO.ask, 1 - YES.bid)
|
|
288
|
+
* - effectiveSellYes = max(YES.bid, 1 - NO.ask)
|
|
289
|
+
* - effectiveSellNo = max(NO.bid, 1 - YES.ask)
|
|
290
|
+
*
|
|
291
|
+
* 详细文档见: docs/01-polymarket-orderbook-arbitrage.md
|
|
292
|
+
*/
|
|
293
|
+
private processOrderbooks;
|
|
294
|
+
/**
|
|
295
|
+
* Check if this client has trading capabilities
|
|
296
|
+
*
|
|
297
|
+
* @returns True if a signer or API credentials are configured
|
|
298
|
+
*
|
|
299
|
+
* @remarks
|
|
300
|
+
* Trading requires either:
|
|
301
|
+
* - A signer (for L1 authentication)
|
|
302
|
+
* - API credentials (for L2 authentication)
|
|
303
|
+
*
|
|
304
|
+
* For actual trading, use the {@link TradingClient} instead.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* if (client.hasTradingCapabilities()) {
|
|
309
|
+
* console.log('Client can execute trades');
|
|
310
|
+
* } else {
|
|
311
|
+
* console.log('Read-only mode - use TradingClient for trading');
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
hasTradingCapabilities(): boolean;
|
|
316
|
+
private normalizeMarket;
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=clob-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clob-api.d.ts","sourceRoot":"","sources":["../../src/clients/clob-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,WAAW,EAAW,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;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