Skip to content

Commit 72f418c

Browse files
committed
feat: consolidate API into unified fetchMarkets and fetchEvents (v1.7.0)
- Add fetchMarkets() with query/slug parameters (replaces searchMarkets/getMarketsBySlug) - Add fetchEvents() with query parameter (replaces searchEvents) - Deprecate old methods with console warnings (removal in v2.0) - Update all examples and tests to use new API - Update API references, changelog, and migration guide
1 parent a7ad578 commit 72f418c

47 files changed

Lines changed: 479 additions & 266 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MIGRATION.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
11
# Migration Guide
22

3-
## Feb 3, 2026 - v1.5.8: Unified Filtering
3+
## Feb 3, 2026 - v1.7.0: CCXT-Style Unified API
4+
5+
### Change
6+
Consolidated `searchMarkets()`, `getMarketsBySlug()`, and `searchEvents()` into unified `fetchMarkets()` and `fetchEvents()` methods that accept optional parameters, following CCXT conventions.
7+
8+
### What's Deprecated
9+
The following methods are now deprecated and will be removed in v2.0:
10+
- `searchMarkets(query, params)` → Use `fetchMarkets({ query, ...params })`
11+
- `getMarketsBySlug(slug)` → Use `fetchMarkets({ slug })`
12+
- `searchEvents(query, params)` → Use `fetchEvents({ query, ...params })`
13+
14+
Deprecation warnings will appear in the console when using the old methods.
15+
16+
### How to Migrate
17+
18+
**TypeScript:**
19+
```typescript
20+
// OLD (deprecated)
21+
const markets = await exchange.searchMarkets('Trump', { limit: 10 });
22+
const bySlug = await exchange.getMarketsBySlug('fed-chair-2025');
23+
const events = await exchange.searchEvents('Election', { limit: 5 });
24+
25+
// NEW (CCXT-style)
26+
const markets = await exchange.fetchMarkets({ query: 'Trump', limit: 10 });
27+
const bySlug = await exchange.fetchMarkets({ slug: 'fed-chair-2025' });
28+
const events = await exchange.fetchEvents({ query: 'Election', limit: 5 });
29+
```
30+
31+
**Python:**
32+
```python
33+
# OLD (deprecated)
34+
markets = await exchange.search_markets('Trump', limit=10)
35+
by_slug = await exchange.get_markets_by_slug('fed-chair-2025')
36+
events = await exchange.search_events('Election', limit=5)
37+
38+
# NEW (CCXT-style)
39+
markets = await exchange.fetch_markets(query='Trump', limit=10)
40+
by_slug = await exchange.fetch_markets(slug='fed-chair-2025')
41+
events = await exchange.fetch_events(query='Election', limit=5)
42+
```
43+
44+
### Benefits
45+
- **Unified interface**: Single method for all market fetching operations
46+
- **CCXT compatibility**: Familiar API for CCXT users
47+
- **Cleaner code**: No need to remember different method names for different operations
48+
- **Backward compatible**: Old methods still work (with warnings) until v2.0
49+
50+
---
51+
52+
## Feb 3, 2026 - v1.6.0: Unified Filtering
453

554
### Change
655
Introduced dedicated `filter_markets()` and `filter_events()` methods to replace manual list filtering and unify searching.

changelog.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.7.0] - 2026-02-03
6+
7+
### Added
8+
- **Unified API Consolidation**: Consolidated `searchMarkets()`, `getMarketsBySlug()`, and `searchEvents()` into new CCXT-style `fetchMarkets()` and `fetchEvents()` methods.
9+
- New methods accept a unified `params` object (TS) or keyword arguments (Python).
10+
- Supports `query` and `slug` as standard parameters.
11+
- **Improved CCXT Compatibility**: Aligned the API structure more closely with the CCXT standard for easier cross-platform migration.
12+
13+
### Deprecated
14+
- `searchMarkets(query, params)`: Use `fetchMarkets({ query, ...params })` instead.
15+
- `getMarketsBySlug(slug)`: Use `fetchMarkets({ slug })` instead.
16+
- `searchEvents(query, params)`: Use `fetchEvents({ query, ...params })` instead.
17+
- These methods will be removed in v2.0. Deprecation warnings have been added.
18+
19+
### Improved
20+
- **BaseExchange Architecture**: Moved search routing logic into the `BaseExchange` class to reduce duplication across exchange implementations.
21+
- **Example Modernization**: All core and SDK examples updated to use the new unified API patterns.
22+
- **Test Coverage**: Added compliance tests for the new `fetchMarkets` and `fetchEvents` implementations.
23+
524
## [1.6.0] - 2026-02-03
625

726
### Added

core/API_REFERENCE.md

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,53 @@ const poly = new pmxt.default.Polymarket();
4040
## Core Methods
4141

4242
### `fetchMarkets(params?)`
43-
Get active markets from an exchange.
43+
Get active markets from an exchange. This is the unified method for all market fetching operations.
44+
45+
**Parameters**:
46+
- `limit`: Number of results (default: 20)
47+
- `offset`: Pagination offset
48+
- `sort`: 'volume' | 'liquidity' | 'newest'
49+
- `query`: Search text (replaces `searchMarkets`)
50+
- `slug`: Market slug or ticker (replaces `getMarketsBySlug`)
4451

4552
```typescript
53+
// 1. Fetch recent markets
4654
const markets = await polymarket.fetchMarkets({
4755
limit: 20,
48-
offset: 0,
49-
sort: 'volume' // 'volume' | 'liquidity' | 'newest'
56+
sort: 'volume'
5057
});
51-
```
5258

53-
### `searchMarkets(query, params?)`
54-
Search markets by keyword. By default, searches only in titles.
59+
// 2. Search by text (replaces searchMarkets)
60+
const results = await kalshi.fetchMarkets({
61+
query: 'Fed rates',
62+
limit: 10
63+
});
5564

56-
```typescript
57-
const results = await kalshi.searchMarkets('Fed rates', {
58-
limit: 10,
59-
searchIn: 'title' // 'title' (default) | 'description' | 'both'
65+
// 3. Fetch by slug/ticker (replaces getMarketsBySlug)
66+
const market = await polymarket.fetchMarkets({
67+
slug: 'who-will-trump-nominate-as-fed-chair'
6068
});
6169
```
6270

63-
### `getMarketsBySlug(slug)`
64-
Fetch markets by URL slug/ticker.
71+
### `fetchEvents(params?)`
72+
Get events (groups of related markets). Unified method for event fetching.
6573

66-
```typescript
67-
// Polymarket: use URL slug
68-
const polyMarkets = await polymarket.getMarketsBySlug('who-will-trump-nominate-as-fed-chair');
74+
**Parameters**:
75+
- `query`: Search text
76+
- `limit`: Number of results
77+
- `offset`: Pagination offset
6978

70-
// Kalshi: use market ticker (auto-uppercased)
71-
const kalshiMarkets = await kalshi.getMarketsBySlug('KXFEDCHAIRNOM-29');
79+
```typescript
80+
// Search for events
81+
const events = await polymarket.fetchEvents({
82+
query: 'Fed Chair',
83+
limit: 5
84+
});
7285
```
7386

74-
#### Universal Slug/Ticker Reference
87+
---
88+
7589

76-
| Platform | Example Market URL | What to extract (Slug/Ticker) | Logic |
77-
|---|---|---|---|
78-
| **Kalshi** | `kalshi.com/markets/kxfedchairnom/.../kxfedchairnom-29` | `KXFEDCHAIRNOM-29` | The **last** path segment of the URL. |
79-
| **Polymarket** | `polymarket.com/event/who-will-trump-nominate-as-fed-chair` | `who-will-trump-nominate-as-fed-chair` | The slug immediately after `/event/`. |
8090

8191
---
8292

@@ -90,7 +100,7 @@ Get historical price candles.
90100
- **Kalshi**: `outcome.outcomeId` is the Market Ticker
91101

92102
```typescript
93-
const markets = await polymarket.searchMarkets('Trump');
103+
const markets = await polymarket.fetchMarkets({ query: 'Trump' });
94104
const outcomeId = markets[0].outcomes[0].outcomeId; // Get the outcome ID
95105

96106
const candles = await polymarket.fetchOHLCV(outcomeId, {
@@ -228,7 +238,7 @@ interface ExecutionPriceResult {
228238

229239
```typescript
230240
// 1. Search for markets
231-
const markets = await polymarket.searchMarkets('Fed Chair');
241+
const markets = await polymarket.fetchMarkets({ query: 'Fed Chair' });
232242
const market = markets[0];
233243

234244
// 2. Get outcome details
@@ -493,7 +503,7 @@ const [balance] = await exchange.fetchBalance();
493503
console.log(`Available: $${balance.available}`);
494504

495505
// 2. Search for a market
496-
const markets = await exchange.searchMarkets('Trump');
506+
const markets = await exchange.fetchMarkets({ query: 'Trump' });
497507
const market = markets[0];
498508
const outcome = market.outcomes[0];
499509

core/examples/filtering-example.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ async function main() {
1616
// Example 1: Simple text search
1717
// ----------------------------------------------------------------------------
1818
console.log('Example 1: Simple text search');
19-
const allMarkets = await api.searchMarkets('Trump');
19+
const allMarkets = await api.fetchMarkets({ query: 'Trump' });
2020
const filtered1 = api.filterMarkets(allMarkets, 'Fed Chair');
2121
console.log(`Found ${filtered1.length} markets matching "Fed Chair"\n`);
2222

2323
// ----------------------------------------------------------------------------
2424
// Example 2: Multi-field text search
2525
// ----------------------------------------------------------------------------
2626
console.log('Example 2: Multi-field text search');
27-
const events = await api.searchEvents('Election');
27+
const events = await api.fetchEvents({ query: 'Election' });
2828
const filtered2 = api.filterMarkets(events[0]?.markets || [], {
2929
text: 'Trump',
3030
searchIn: ['title', 'description', 'tags']
@@ -112,7 +112,7 @@ async function main() {
112112
// Example 9: Event filtering
113113
// ----------------------------------------------------------------------------
114114
console.log('Example 9: Event filtering');
115-
const allEvents = await api.searchEvents('2024');
115+
const allEvents = await api.fetchEvents({ query: '2024' });
116116
const filtered9 = api.filterEvents(allEvents, {
117117
text: 'Trump',
118118
category: 'Politics',
@@ -125,7 +125,7 @@ async function main() {
125125
// Example 10: Combining global search with filtering
126126
// ----------------------------------------------------------------------------
127127
console.log('Example 10: Global search + filtering');
128-
const markets = await api.searchMarkets('Election');
128+
const markets = await api.fetchMarkets({ query: 'Election' });
129129
const undervalued = api.filterMarkets(markets, {
130130
price: { outcome: 'yes', max: 0.3 },
131131
volume24h: { min: 5000 },

core/examples/market-data/get_event_prices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import pmxt from '../../src';
22

33
const main = async () => {
44
const api = new pmxt.Polymarket();
5-
const markets = await api.getMarketsBySlug('who-will-trump-nominate-as-fed-chair');
5+
const markets = await api.fetchMarkets({ slug: 'who-will-trump-nominate-as-fed-chair' });
66
const warsh = markets.find(m => m.outcomes[0]?.label === 'Kevin Warsh');
77

88
console.log(warsh?.outcomes[0].price);

core/examples/market-data/historical_prices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import pmxt from '../../src';
22

33
const main = async () => {
44
const api = new pmxt.Polymarket();
5-
const markets = await api.getMarketsBySlug('who-will-trump-nominate-as-fed-chair');
5+
const markets = await api.fetchMarkets({ slug: 'who-will-trump-nominate-as-fed-chair' });
66
const warsh = markets.find(m => m.outcomes[0]?.label === 'Kevin Warsh');
77

88
const history = await api.fetchOHLCV(warsh!.outcomes[0].metadata.clobTokenId, {

core/examples/market-data/orderbook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import pmxt from '../../src';
22

33
const main = async () => {
44
const api = new pmxt.Kalshi();
5-
const markets = await api.getMarketsBySlug('KXFEDCHAIRNOM-29');
5+
const markets = await api.fetchMarkets({ slug: 'KXFEDCHAIRNOM-29' });
66
const warsh = markets.find(m => m.outcomes[0]?.label === 'Kevin Warsh');
77

88
const book = await api.fetchOrderBook(warsh!.id);

core/examples/market-data/recent_trades.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import pmxt from '../../src';
33
const main = async () => {
44
// Kalshi
55
const kalshi = new pmxt.Kalshi();
6-
const kMarkets = await kalshi.getMarketsBySlug('KXFEDCHAIRNOM-29');
6+
const kMarkets = await kalshi.fetchMarkets({ slug: 'KXFEDCHAIRNOM-29' });
77
const kWarsh = kMarkets.find(m => m.outcomes[0]?.label === 'Kevin Warsh');
88
const kTrades = await kalshi.fetchTrades(kWarsh!.id, { limit: 10 });
99
console.log('Kalshi:', kTrades);
1010

1111
// Polymarket
1212
const poly = new pmxt.Polymarket();
13-
const pMarkets = await poly.getMarketsBySlug('who-will-trump-nominate-as-fed-chair');
13+
const pMarkets = await poly.fetchMarkets({ slug: 'who-will-trump-nominate-as-fed-chair' });
1414
const pWarsh = pMarkets.find(m => m.outcomes[0]?.label === 'Kevin Warsh');
1515
const pTrades = await poly.fetchTrades(pWarsh!.outcomes[0].metadata.clobTokenId, { limit: 10 });
1616
console.log('Polymarket:', pTrades);

core/examples/market-data/search_events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const main = async () => {
44
const poly = new pmxt.Polymarket();
55
// const kalshi = new pmxt.Kalshi();
66

7-
const events = await poly.searchEvents('Fed Chair');
7+
const events = await poly.fetchEvents({ query: 'Fed Chair' });
88

99
events.forEach(event => {
1010
console.log(`Event: ${event.title}`);

core/examples/market-data/search_markets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const main = async () => {
44
const poly = new pmxt.Polymarket();
55
const kalshi = new pmxt.Kalshi();
66

7-
console.log('Polymarket:', await poly.searchMarkets('Fed'));
8-
console.log('Kalshi:', await kalshi.searchMarkets('Fed'));
7+
console.log('Polymarket:', await poly.fetchMarkets({ query: 'Fed' }));
8+
console.log('Kalshi:', await kalshi.fetchMarkets({ query: 'Fed' }));
99
};
1010

1111
main();

0 commit comments

Comments
 (0)