pmxtjs 0.3.0 → 0.4.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 (50) hide show
  1. package/API_REFERENCE.md +448 -51
  2. package/dist/BaseExchange.d.ts +38 -3
  3. package/dist/BaseExchange.js +43 -1
  4. package/dist/exchanges/Kalshi.js +10 -2
  5. package/dist/exchanges/Polymarket.js +12 -4
  6. package/dist/exchanges/kalshi/auth.d.ts +23 -0
  7. package/dist/exchanges/kalshi/auth.js +99 -0
  8. package/dist/exchanges/kalshi/fetchMarkets.d.ts +3 -0
  9. package/dist/exchanges/kalshi/fetchMarkets.js +84 -0
  10. package/dist/exchanges/kalshi/fetchOHLCV.d.ts +3 -0
  11. package/dist/exchanges/kalshi/fetchOHLCV.js +78 -0
  12. package/dist/exchanges/kalshi/fetchOrderBook.d.ts +2 -0
  13. package/dist/exchanges/kalshi/fetchOrderBook.js +32 -0
  14. package/dist/exchanges/kalshi/fetchTrades.d.ts +3 -0
  15. package/dist/exchanges/kalshi/fetchTrades.js +31 -0
  16. package/dist/exchanges/kalshi/getMarketsBySlug.d.ts +7 -0
  17. package/dist/exchanges/kalshi/getMarketsBySlug.js +46 -0
  18. package/dist/exchanges/kalshi/index.d.ts +21 -0
  19. package/dist/exchanges/kalshi/index.js +273 -0
  20. package/dist/exchanges/kalshi/kalshi.test.d.ts +1 -0
  21. package/dist/exchanges/kalshi/kalshi.test.js +309 -0
  22. package/dist/exchanges/kalshi/searchMarkets.d.ts +3 -0
  23. package/dist/exchanges/kalshi/searchMarkets.js +28 -0
  24. package/dist/exchanges/kalshi/utils.d.ts +4 -0
  25. package/dist/exchanges/kalshi/utils.js +70 -0
  26. package/dist/exchanges/polymarket/auth.d.ts +32 -0
  27. package/dist/exchanges/polymarket/auth.js +98 -0
  28. package/dist/exchanges/polymarket/fetchMarkets.d.ts +3 -0
  29. package/dist/exchanges/polymarket/fetchMarkets.js +75 -0
  30. package/dist/exchanges/polymarket/fetchOHLCV.d.ts +7 -0
  31. package/dist/exchanges/polymarket/fetchOHLCV.js +73 -0
  32. package/dist/exchanges/polymarket/fetchOrderBook.d.ts +6 -0
  33. package/dist/exchanges/polymarket/fetchOrderBook.js +38 -0
  34. package/dist/exchanges/polymarket/fetchPositions.d.ts +2 -0
  35. package/dist/exchanges/polymarket/fetchPositions.js +27 -0
  36. package/dist/exchanges/polymarket/fetchTrades.d.ts +11 -0
  37. package/dist/exchanges/polymarket/fetchTrades.js +59 -0
  38. package/dist/exchanges/polymarket/getMarketsBySlug.d.ts +7 -0
  39. package/dist/exchanges/polymarket/getMarketsBySlug.js +39 -0
  40. package/dist/exchanges/polymarket/index.d.ts +23 -0
  41. package/dist/exchanges/polymarket/index.js +216 -0
  42. package/dist/exchanges/polymarket/searchMarkets.d.ts +3 -0
  43. package/dist/exchanges/polymarket/searchMarkets.js +35 -0
  44. package/dist/exchanges/polymarket/utils.d.ts +7 -0
  45. package/dist/exchanges/polymarket/utils.js +95 -0
  46. package/dist/index.d.ts +4 -4
  47. package/dist/index.js +8 -8
  48. package/dist/types.d.ts +38 -0
  49. package/package.json +5 -1
  50. package/readme.md +44 -24
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolymarketExchange = void 0;
4
+ const BaseExchange_1 = require("../../BaseExchange");
5
+ const fetchMarkets_1 = require("./fetchMarkets");
6
+ const searchMarkets_1 = require("./searchMarkets");
7
+ const getMarketsBySlug_1 = require("./getMarketsBySlug");
8
+ const fetchOHLCV_1 = require("./fetchOHLCV");
9
+ const fetchOrderBook_1 = require("./fetchOrderBook");
10
+ const fetchTrades_1 = require("./fetchTrades");
11
+ const fetchPositions_1 = require("./fetchPositions");
12
+ const auth_1 = require("./auth");
13
+ const clob_client_1 = require("@polymarket/clob-client");
14
+ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
15
+ constructor(credentials) {
16
+ super(credentials);
17
+ // Initialize auth if credentials are provided
18
+ if (credentials?.privateKey) {
19
+ this.auth = new auth_1.PolymarketAuth(credentials);
20
+ }
21
+ }
22
+ get name() {
23
+ return 'Polymarket';
24
+ }
25
+ async fetchMarkets(params) {
26
+ return (0, fetchMarkets_1.fetchMarkets)(params);
27
+ }
28
+ async searchMarkets(query, params) {
29
+ return (0, searchMarkets_1.searchMarkets)(query, params);
30
+ }
31
+ async getMarketsBySlug(slug) {
32
+ return (0, getMarketsBySlug_1.getMarketsBySlug)(slug);
33
+ }
34
+ async fetchOHLCV(id, params) {
35
+ return (0, fetchOHLCV_1.fetchOHLCV)(id, params);
36
+ }
37
+ async fetchOrderBook(id) {
38
+ return (0, fetchOrderBook_1.fetchOrderBook)(id);
39
+ }
40
+ async fetchTrades(id, params) {
41
+ return (0, fetchTrades_1.fetchTrades)(id, params);
42
+ }
43
+ // ----------------------------------------------------------------------------
44
+ // Trading Methods
45
+ // ----------------------------------------------------------------------------
46
+ /**
47
+ * Ensure authentication is initialized before trading operations.
48
+ */
49
+ ensureAuth() {
50
+ if (!this.auth) {
51
+ throw new Error('Trading operations require authentication. ' +
52
+ 'Initialize PolymarketExchange with credentials: new PolymarketExchange({ privateKey: "0x..." })');
53
+ }
54
+ return this.auth;
55
+ }
56
+ async createOrder(params) {
57
+ const auth = this.ensureAuth();
58
+ const client = await auth.getClobClient();
59
+ // Map side to Polymarket enum
60
+ const side = params.side.toUpperCase() === 'BUY' ? clob_client_1.Side.BUY : clob_client_1.Side.SELL;
61
+ // For limit orders, price is required
62
+ if (params.type === 'limit' && !params.price) {
63
+ throw new Error('Price is required for limit orders');
64
+ }
65
+ // For market orders, use max slippage: 0.99 for BUY (willing to pay up to 99%), 0.01 for SELL (willing to accept down to 1%)
66
+ const price = params.price || (side === clob_client_1.Side.BUY ? 0.99 : 0.01);
67
+ try {
68
+ // We use createAndPostOrder which handles signing and posting
69
+ const response = await client.createAndPostOrder({
70
+ tokenID: params.outcomeId,
71
+ price: price,
72
+ side: side,
73
+ size: params.amount,
74
+ feeRateBps: 0,
75
+ }, {
76
+ tickSize: "0.01"
77
+ });
78
+ if (!response || !response.success) {
79
+ throw new Error(response?.errorMsg || 'Order placement failed');
80
+ }
81
+ return {
82
+ id: response.orderID,
83
+ marketId: params.marketId,
84
+ outcomeId: params.outcomeId,
85
+ side: params.side,
86
+ type: params.type,
87
+ price: price,
88
+ amount: params.amount,
89
+ status: 'open',
90
+ filled: 0,
91
+ remaining: params.amount,
92
+ timestamp: Date.now()
93
+ };
94
+ }
95
+ catch (error) {
96
+ console.error("Polymarket createOrder error:", error);
97
+ throw error;
98
+ }
99
+ }
100
+ async cancelOrder(orderId) {
101
+ const auth = this.ensureAuth();
102
+ const client = await auth.getClobClient();
103
+ try {
104
+ await client.cancelOrder({ orderID: orderId });
105
+ return {
106
+ id: orderId,
107
+ marketId: 'unknown',
108
+ outcomeId: 'unknown',
109
+ side: 'buy',
110
+ type: 'limit',
111
+ amount: 0,
112
+ status: 'cancelled',
113
+ filled: 0,
114
+ remaining: 0,
115
+ timestamp: Date.now()
116
+ };
117
+ }
118
+ catch (error) {
119
+ console.error("Polymarket cancelOrder error:", error);
120
+ throw error;
121
+ }
122
+ }
123
+ async fetchOrder(orderId) {
124
+ const auth = this.ensureAuth();
125
+ const client = await auth.getClobClient();
126
+ try {
127
+ const order = await client.getOrder(orderId);
128
+ return {
129
+ id: order.id,
130
+ marketId: order.market || 'unknown',
131
+ outcomeId: order.asset_id,
132
+ side: order.side.toLowerCase(),
133
+ type: order.order_type === 'GTC' ? 'limit' : 'market',
134
+ price: parseFloat(order.price),
135
+ amount: parseFloat(order.original_size),
136
+ status: order.status, // Needs precise mapping
137
+ filled: parseFloat(order.size_matched),
138
+ remaining: parseFloat(order.original_size) - parseFloat(order.size_matched),
139
+ timestamp: order.created_at * 1000
140
+ };
141
+ }
142
+ catch (error) {
143
+ console.error("Polymarket fetchOrder error:", error);
144
+ throw error;
145
+ }
146
+ }
147
+ async fetchOpenOrders(marketId) {
148
+ const auth = this.ensureAuth();
149
+ const client = await auth.getClobClient();
150
+ try {
151
+ const orders = await client.getOpenOrders({
152
+ market: marketId
153
+ });
154
+ return orders.map((o) => ({
155
+ id: o.id,
156
+ marketId: o.market || 'unknown',
157
+ outcomeId: o.asset_id,
158
+ side: o.side.toLowerCase(),
159
+ type: 'limit',
160
+ price: parseFloat(o.price),
161
+ amount: parseFloat(o.original_size),
162
+ status: 'open',
163
+ filled: parseFloat(o.size_matched),
164
+ remaining: parseFloat(o.size_left || (parseFloat(o.original_size) - parseFloat(o.size_matched))),
165
+ timestamp: o.created_at * 1000
166
+ }));
167
+ }
168
+ catch (error) {
169
+ console.error("Polymarket fetchOpenOrders error:", error);
170
+ return [];
171
+ }
172
+ }
173
+ async fetchPositions() {
174
+ const auth = this.ensureAuth();
175
+ const address = auth.getAddress();
176
+ return (0, fetchPositions_1.fetchPositions)(address);
177
+ }
178
+ async fetchBalance() {
179
+ const auth = this.ensureAuth();
180
+ const client = await auth.getClobClient();
181
+ try {
182
+ // 1. Fetch raw collateral balance (USDC)
183
+ // Polymarket relies strictly on USDC (Polygon) which has 6 decimals.
184
+ const USDC_DECIMALS = 6;
185
+ const balRes = await client.getBalanceAllowance({
186
+ asset_type: clob_client_1.AssetType.COLLATERAL
187
+ });
188
+ const rawBalance = parseFloat(balRes.balance);
189
+ const total = rawBalance / Math.pow(10, USDC_DECIMALS);
190
+ // 2. Fetch open orders to calculate locked funds
191
+ // We only care about BUY orders for USDC balance locking
192
+ const openOrders = await client.getOpenOrders({});
193
+ let locked = 0;
194
+ if (openOrders && Array.isArray(openOrders)) {
195
+ for (const order of openOrders) {
196
+ if (order.side === clob_client_1.Side.BUY) {
197
+ const remainingSize = parseFloat(order.original_size) - parseFloat(order.size_matched);
198
+ const price = parseFloat(order.price);
199
+ locked += remainingSize * price;
200
+ }
201
+ }
202
+ }
203
+ return [{
204
+ currency: 'USDC',
205
+ total: total,
206
+ available: total - locked, // Available for new trades
207
+ locked: locked
208
+ }];
209
+ }
210
+ catch (error) {
211
+ console.error("Polymarket fetchBalance error:", error);
212
+ throw error;
213
+ }
214
+ }
215
+ }
216
+ exports.PolymarketExchange = PolymarketExchange;
@@ -0,0 +1,3 @@
1
+ import { MarketFilterParams } from '../../BaseExchange';
2
+ import { UnifiedMarket } from '../../types';
3
+ export declare function searchMarkets(query: string, params?: MarketFilterParams): Promise<UnifiedMarket[]>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.searchMarkets = searchMarkets;
4
+ const fetchMarkets_1 = require("./fetchMarkets");
5
+ async function searchMarkets(query, params) {
6
+ // Polymarket Gamma API doesn't support native search
7
+ // Fetch all active markets and filter client-side
8
+ const searchLimit = 100000; // Fetch all markets for comprehensive search
9
+ try {
10
+ // Fetch markets with a higher limit
11
+ const markets = await (0, fetchMarkets_1.fetchMarkets)({
12
+ ...params,
13
+ limit: searchLimit
14
+ });
15
+ // Client-side text filtering
16
+ const lowerQuery = query.toLowerCase();
17
+ const searchIn = params?.searchIn || 'title'; // Default to title-only search
18
+ const filtered = markets.filter(market => {
19
+ const titleMatch = (market.title || '').toLowerCase().includes(lowerQuery);
20
+ const descMatch = (market.description || '').toLowerCase().includes(lowerQuery);
21
+ if (searchIn === 'title')
22
+ return titleMatch;
23
+ if (searchIn === 'description')
24
+ return descMatch;
25
+ return titleMatch || descMatch; // 'both'
26
+ });
27
+ // Apply limit to filtered results
28
+ const limit = params?.limit || 20;
29
+ return filtered.slice(0, limit);
30
+ }
31
+ catch (error) {
32
+ console.error("Error searching Polymarket data:", error);
33
+ return [];
34
+ }
35
+ }
@@ -0,0 +1,7 @@
1
+ import { UnifiedMarket, CandleInterval } from '../../types';
2
+ export declare const GAMMA_API_URL = "https://gamma-api.polymarket.com/events";
3
+ export declare const CLOB_API_URL = "https://clob.polymarket.com";
4
+ export declare function mapMarketToUnified(event: any, market: any, options?: {
5
+ useQuestionAsCandidateFallback?: boolean;
6
+ }): UnifiedMarket | null;
7
+ export declare function mapIntervalToFidelity(interval: CandleInterval): number;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLOB_API_URL = exports.GAMMA_API_URL = void 0;
4
+ exports.mapMarketToUnified = mapMarketToUnified;
5
+ exports.mapIntervalToFidelity = mapIntervalToFidelity;
6
+ exports.GAMMA_API_URL = 'https://gamma-api.polymarket.com/events';
7
+ exports.CLOB_API_URL = 'https://clob.polymarket.com';
8
+ function mapMarketToUnified(event, market, options = {}) {
9
+ if (!market)
10
+ return null;
11
+ const outcomes = [];
12
+ // Polymarket Gamma often returns 'outcomes' and 'outcomePrices' as stringified JSON keys.
13
+ let outcomeLabels = [];
14
+ let outcomePrices = [];
15
+ try {
16
+ outcomeLabels = typeof market.outcomes === 'string' ? JSON.parse(market.outcomes) : (market.outcomes || []);
17
+ outcomePrices = typeof market.outcomePrices === 'string' ? JSON.parse(market.outcomePrices) : (market.outcomePrices || []);
18
+ }
19
+ catch (e) {
20
+ console.warn(`Error parsing outcomes for market ${market.id}:`, e);
21
+ }
22
+ // Extract CLOB token IDs for granular operations
23
+ let clobTokenIds = [];
24
+ try {
25
+ clobTokenIds = typeof market.clobTokenIds === 'string' ? JSON.parse(market.clobTokenIds) : (market.clobTokenIds || []);
26
+ }
27
+ catch (e) {
28
+ // console.warn(`Error parsing clobTokenIds for market ${market.id}`, e);
29
+ }
30
+ // Extract candidate/option name from market question for better outcome labels
31
+ let candidateName = null;
32
+ if (market.groupItemTitle) {
33
+ candidateName = market.groupItemTitle;
34
+ }
35
+ else if (market.question && options.useQuestionAsCandidateFallback) {
36
+ // Fallback or sometimes question is the candidate name in nested structures
37
+ // Only used if explicitly requested (e.g. for getMarketsBySlug)
38
+ candidateName = market.question;
39
+ }
40
+ if (outcomeLabels.length > 0) {
41
+ outcomeLabels.forEach((label, index) => {
42
+ const rawPrice = outcomePrices[index] || "0";
43
+ // For Yes/No markets with specific candidates, use the candidate name
44
+ let outcomeLabel = label;
45
+ if (candidateName && label.toLowerCase() === 'yes') {
46
+ outcomeLabel = candidateName;
47
+ }
48
+ else if (candidateName && label.toLowerCase() === 'no') {
49
+ outcomeLabel = `Not ${candidateName}`;
50
+ }
51
+ // 24h Price Change
52
+ // Polymarket API provides 'oneDayPriceChange' on the market object
53
+ let priceChange = 0;
54
+ if (index === 0 || label.toLowerCase() === 'yes' || (candidateName && label === candidateName)) {
55
+ priceChange = Number(market.oneDayPriceChange || 0);
56
+ }
57
+ outcomes.push({
58
+ id: clobTokenIds[index] || String(index), // Use CLOB Token ID as the primary ID
59
+ label: outcomeLabel,
60
+ price: parseFloat(rawPrice) || 0,
61
+ priceChange24h: priceChange,
62
+ metadata: {
63
+ // clobTokenId is now the main ID, but keeping it in metadata for backward compat if needed
64
+ clobTokenId: clobTokenIds[index]
65
+ }
66
+ });
67
+ });
68
+ }
69
+ return {
70
+ id: market.id,
71
+ title: market.question ? `${event.title} - ${market.question}` : event.title,
72
+ description: market.description || event.description,
73
+ outcomes: outcomes,
74
+ resolutionDate: market.endDate ? new Date(market.endDate) : (market.end_date_iso ? new Date(market.end_date_iso) : new Date()),
75
+ volume24h: Number(market.volume24hr || market.volume_24h || 0),
76
+ volume: Number(market.volume || 0),
77
+ liquidity: Number(market.liquidity || market.rewards?.liquidity || 0),
78
+ openInterest: Number(market.openInterest || market.open_interest || 0),
79
+ url: `https://polymarket.com/event/${event.slug}`,
80
+ image: event.image || market.image || `https://polymarket.com/api/og?slug=${event.slug}`,
81
+ category: event.category || event.tags?.[0]?.label,
82
+ tags: event.tags?.map((t) => t.label) || []
83
+ };
84
+ }
85
+ function mapIntervalToFidelity(interval) {
86
+ const mapping = {
87
+ '1m': 1,
88
+ '5m': 5,
89
+ '15m': 15,
90
+ '1h': 60,
91
+ '6h': 360,
92
+ '1d': 1440
93
+ };
94
+ return mapping[interval];
95
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export * from './BaseExchange';
2
2
  export * from './types';
3
- export * from './exchanges/Polymarket';
4
- export * from './exchanges/Kalshi';
5
- import { PolymarketExchange } from './exchanges/Polymarket';
6
- import { KalshiExchange } from './exchanges/Kalshi';
3
+ export * from './exchanges/polymarket';
4
+ export * from './exchanges/kalshi';
5
+ import { PolymarketExchange } from './exchanges/polymarket';
6
+ import { KalshiExchange } from './exchanges/kalshi';
7
7
  declare const pmxt: {
8
8
  polymarket: typeof PolymarketExchange;
9
9
  kalshi: typeof KalshiExchange;
package/dist/index.js CHANGED
@@ -16,14 +16,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./BaseExchange"), exports);
18
18
  __exportStar(require("./types"), exports);
19
- __exportStar(require("./exchanges/Polymarket"), exports);
20
- __exportStar(require("./exchanges/Kalshi"), exports);
21
- const Polymarket_1 = require("./exchanges/Polymarket");
22
- const Kalshi_1 = require("./exchanges/Kalshi");
19
+ __exportStar(require("./exchanges/polymarket"), exports);
20
+ __exportStar(require("./exchanges/kalshi"), exports);
21
+ const polymarket_1 = require("./exchanges/polymarket");
22
+ const kalshi_1 = require("./exchanges/kalshi");
23
23
  const pmxt = {
24
- polymarket: Polymarket_1.PolymarketExchange,
25
- kalshi: Kalshi_1.KalshiExchange,
26
- Polymarket: Polymarket_1.PolymarketExchange,
27
- Kalshi: Kalshi_1.KalshiExchange
24
+ polymarket: polymarket_1.PolymarketExchange,
25
+ kalshi: kalshi_1.KalshiExchange,
26
+ Polymarket: polymarket_1.PolymarketExchange,
27
+ Kalshi: kalshi_1.KalshiExchange
28
28
  };
29
29
  exports.default = pmxt;
package/dist/types.d.ts CHANGED
@@ -45,3 +45,41 @@ export interface Trade {
45
45
  amount: number;
46
46
  side: 'buy' | 'sell' | 'unknown';
47
47
  }
48
+ export interface Order {
49
+ id: string;
50
+ marketId: string;
51
+ outcomeId: string;
52
+ side: 'buy' | 'sell';
53
+ type: 'market' | 'limit';
54
+ price?: number;
55
+ amount: number;
56
+ status: 'pending' | 'open' | 'filled' | 'cancelled' | 'rejected';
57
+ filled: number;
58
+ remaining: number;
59
+ timestamp: number;
60
+ fee?: number;
61
+ }
62
+ export interface Position {
63
+ marketId: string;
64
+ outcomeId: string;
65
+ outcomeLabel: string;
66
+ size: number;
67
+ entryPrice: number;
68
+ currentPrice: number;
69
+ unrealizedPnL: number;
70
+ realizedPnL?: number;
71
+ }
72
+ export interface Balance {
73
+ currency: string;
74
+ total: number;
75
+ available: number;
76
+ locked: number;
77
+ }
78
+ export interface CreateOrderParams {
79
+ marketId: string;
80
+ outcomeId: string;
81
+ side: 'buy' | 'sell';
82
+ type: 'market' | 'limit';
83
+ amount: number;
84
+ price?: number;
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "pmxt is a unified prediction market data API. The ccxt for prediction markets.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,13 +21,17 @@
21
21
  "license": "MIT",
22
22
  "type": "commonjs",
23
23
  "dependencies": {
24
+ "@polymarket/clob-client": "^5.2.0",
24
25
  "axios": "^1.7.9",
26
+ "dotenv": "^17.2.3",
27
+ "ethers": "^5.8.0",
25
28
  "jest": "^30.2.0",
26
29
  "tsx": "^4.21.0"
27
30
  },
28
31
  "devDependencies": {
29
32
  "@types/jest": "^30.0.0",
30
33
  "@types/node": "^25.0.3",
34
+ "identity-obj-proxy": "^3.0.0",
31
35
  "ts-jest": "^29.4.6",
32
36
  "typescript": "^5.9.3"
33
37
  }
package/readme.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <table>
9
9
  <tr>
10
10
  <td rowspan="3">
11
- <a href="https://www.producthunt.com/products/qoery-python-sdk?embed=true&amp;utm_source=badge-featured&amp;utm_medium=badge&amp;utm_campaign=badge-qoery-python-sdk" target="_blank" rel="noopener noreferrer"><img alt="Qoery Python SDK - 50% cheaper crypto data. Now in Python. | Product Hunt" width="250" height="54" src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=1056631&amp;theme=light&amp;t=1767263265752"></a>
11
+ <a href="https://www.producthunt.com/products/ccxt-for-prediction-markets?embed=true&amp;utm_source=badge-featured&amp;utm_medium=badge&amp;utm_campaign=badge-ccxt-for-prediction-markets" target="_blank" rel="noopener noreferrer"><img alt="CCXT for Prediction Markets - A unified API for prediction market data across exchanges. | Product Hunt" width="250" height="54" src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=1060549&amp;theme=light&amp;t=1768206672608"></a>
12
12
  </td>
13
13
  <td>
14
14
  <img src="https://img.shields.io/github/watchers/qoery-com/pmxt?style=social" alt="GitHub watchers">
@@ -54,33 +54,19 @@ Different prediction market platforms have different APIs, data formats, and con
54
54
 
55
55
  ## Quick Example
56
56
 
57
- Search for markets across Polymarket and Kalshi using the same API:
57
+ Get the current price for any market in seconds:
58
58
 
59
59
  ```typescript
60
60
  import pmxt from 'pmxtjs';
61
61
 
62
- const query = process.argv[2] || 'Who will Trump nominate as Fed Chair?';
63
- console.log(`Searching for "${query}"...\n`);
62
+ async function main() {
63
+ const poly = new pmxt.polymarket();
64
+ const [market] = await poly.searchMarkets('Trump');
64
65
 
65
- // Polymarket
66
- const polymarket = new pmxt.polymarket();
67
- const polyResults = await polymarket.searchMarkets(query, { sort: 'volume' });
66
+ console.log(`${market.title} - ${market.outcomes[0].label}: ${marketoutcomes[0].price * 100}%`);
67
+ }
68
68
 
69
- console.log(`--- Polymarket Found ${polyResults.length} ---`);
70
- polyResults.slice(0, 10).forEach(m => {
71
- const label = m.outcomes[0]?.label || 'Unknown';
72
- console.log(`[${m.id}] ${m.title} - ${label} (Vol24h: $${m.volume24h.toLocaleString()})`);
73
- });
74
-
75
- // Kalshi
76
- const kalshi = new pmxt.kalshi();
77
- const kalshiResults = await kalshi.searchMarkets(query);
78
-
79
- console.log(`\n--- Kalshi Found ${kalshiResults.length} ---`);
80
- kalshiResults.slice(0, 10).forEach(m => {
81
- const label = m.outcomes[0]?.label || 'Unknown';
82
- console.log(`[${m.id}] ${m.title} - ${label} (Vol24h: $${m.volume24h.toLocaleString()})`);
83
- });
69
+ main();
84
70
  ```
85
71
 
86
72
  ## Installation
@@ -94,13 +80,47 @@ npm install pmxtjs
94
80
  - Polymarket
95
81
  - Kalshi
96
82
 
83
+ ## Trading
84
+ pmxt supports trading functionality (placing and cancelling orders).
85
+
86
+ ### Setup
87
+ To trade, you must provide your private credentials.
88
+
89
+ - **Polymarket**: Requires your Polygon Private Key. [View Setup Guide](docs/SETUP_POLYMARKET.md)
90
+ - **Kalshi**: Requires API Key & Private Key (Coming Soon).
91
+
92
+ ### Trading Example
93
+
94
+ ```typescript
95
+ import pmxt from 'pmxtjs';
96
+
97
+ const exchange = new pmxt.Polymarket({
98
+ privateKey: process.env.POLYMARKET_PRIVATE_KEY
99
+ });
100
+
101
+ // Check Balance
102
+ const balance = await exchange.fetchBalance();
103
+ console.log('Balance:', balance);
104
+
105
+ // Place an Order
106
+ const order = await exchange.createOrder({
107
+ marketId: 'market-123',
108
+ outcomeId: 'token-id-456',
109
+ side: 'buy',
110
+ type: 'limit',
111
+ price: 0.50,
112
+ amount: 100
113
+ });
114
+ console.log('Order:', order);
115
+ ```
116
+
97
117
  ## Documentation
98
118
 
99
- See the [API Reference](pmxt/API_REFERENCE.md) for detailed documentation and more examples.
119
+ See the [API Reference](API_REFERENCE.md) for detailed documentation and more examples.
100
120
 
101
121
  ## Examples
102
122
 
103
- Check out the [examples](pmxt/examples/) directory for more use cases:
123
+ Check out the [examples](examples/) directory for more use cases:
104
124
  - Market search
105
125
  - Order book data
106
126
  - Historical prices