pmxt-core 2.7.0 → 2.8.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.
@@ -123,9 +123,20 @@ export declare abstract class PredictionMarketExchange {
123
123
  protected credentials?: ExchangeCredentials;
124
124
  verbose: boolean;
125
125
  http: AxiosInstance;
126
+ markets: Record<string, UnifiedMarket>;
127
+ marketsBySlug: Record<string, UnifiedMarket>;
128
+ loadedMarkets: boolean;
126
129
  readonly has: ExchangeHas;
127
130
  constructor(credentials?: ExchangeCredentials);
128
131
  abstract get name(): string;
132
+ /**
133
+ * Load and cache markets from the exchange.
134
+ * This method populates `this.markets` and `this.marketsBySlug`.
135
+ *
136
+ * @param reload - Force a reload of markets from the API even if already loaded
137
+ * @returns Dictionary of markets indexed by marketId
138
+ */
139
+ loadMarkets(reload?: boolean): Promise<Record<string, UnifiedMarket>>;
129
140
  /**
130
141
  * Fetch markets with optional filtering, search, or slug lookup.
131
142
  * This is the primary method for retrieving markets.
@@ -14,6 +14,10 @@ class PredictionMarketExchange {
14
14
  credentials;
15
15
  verbose = false;
16
16
  http;
17
+ // Market Cache
18
+ markets = {};
19
+ marketsBySlug = {};
20
+ loadedMarkets = false;
17
21
  has = {
18
22
  fetchMarkets: false,
19
23
  fetchEvents: false,
@@ -63,6 +67,32 @@ class PredictionMarketExchange {
63
67
  return Promise.reject(error);
64
68
  });
65
69
  }
70
+ /**
71
+ * Load and cache markets from the exchange.
72
+ * This method populates `this.markets` and `this.marketsBySlug`.
73
+ *
74
+ * @param reload - Force a reload of markets from the API even if already loaded
75
+ * @returns Dictionary of markets indexed by marketId
76
+ */
77
+ async loadMarkets(reload = false) {
78
+ if (this.loadedMarkets && !reload) {
79
+ return this.markets;
80
+ }
81
+ // Fetch all markets (implementation dependent, usually fetches active markets)
82
+ const markets = await this.fetchMarkets();
83
+ // Reset caches
84
+ this.markets = {};
85
+ this.marketsBySlug = {};
86
+ for (const market of markets) {
87
+ this.markets[market.marketId] = market;
88
+ // Some exchanges provide slugs, if so cache them
89
+ if (market.slug) {
90
+ this.marketsBySlug[market.slug] = market;
91
+ }
92
+ }
93
+ this.loadedMarkets = true;
94
+ return this.markets;
95
+ }
66
96
  /**
67
97
  * Fetch markets with optional filtering, search, or slug lookup.
68
98
  * This is the primary method for retrieving markets.
@@ -142,6 +172,15 @@ class PredictionMarketExchange {
142
172
  * market = exchange.fetch_market(market_id='663583')
143
173
  */
144
174
  async fetchMarket(params) {
175
+ // Try to fetch from cache first if we have loaded markets and have an ID/slug
176
+ if (this.loadedMarkets) {
177
+ if (params?.marketId && this.markets[params.marketId]) {
178
+ return this.markets[params.marketId];
179
+ }
180
+ if (params?.slug && this.marketsBySlug[params.slug]) {
181
+ return this.marketsBySlug[params.slug];
182
+ }
183
+ }
145
184
  const markets = await this.fetchMarkets(params);
146
185
  if (markets.length === 0) {
147
186
  const identifier = params?.marketId || params?.outcomeId || params?.slug || params?.eventId || params?.query || 'unknown';
@@ -151,7 +151,7 @@ async function fetchMarketsBySlug(eventTicker, http) {
151
151
  }
152
152
  async function searchMarkets(query, params, http) {
153
153
  // We must fetch ALL markets to search them locally since we don't have server-side search
154
- const searchLimit = 10000;
154
+ const searchLimit = 250000;
155
155
  const markets = await fetchMarketsDefault({ ...params, limit: searchLimit }, http);
156
156
  const lowerQuery = query.toLowerCase();
157
157
  const searchIn = params?.searchIn || 'title'; // Default to title-only search
@@ -164,11 +164,11 @@ async function searchMarkets(query, params, http) {
164
164
  return descMatch;
165
165
  return titleMatch || descMatch; // 'both'
166
166
  });
167
- const limit = params?.limit || 10000;
167
+ const limit = params?.limit || 250000;
168
168
  return filtered.slice(0, limit);
169
169
  }
170
170
  async function fetchMarketsDefault(params, http) {
171
- const limit = params?.limit || 10000;
171
+ const limit = params?.limit || 250000;
172
172
  const offset = params?.offset || 0;
173
173
  const now = Date.now();
174
174
  const status = params?.status || 'active'; // Default to 'active'
@@ -97,7 +97,7 @@ async function searchMarkets(query, params, http) {
97
97
  const response = await http.get(`${utils_1.LIMITLESS_API_URL}/markets/search`, {
98
98
  params: {
99
99
  query: query,
100
- limit: params?.limit || 10000,
100
+ limit: params?.limit || 250000,
101
101
  page: params?.page || 1,
102
102
  similarityThreshold: params?.similarityThreshold || 0.5
103
103
  }
@@ -121,10 +121,10 @@ async function searchMarkets(query, params, http) {
121
121
  }
122
122
  return allMarkets
123
123
  .filter((m) => m !== null && m.outcomes.length > 0)
124
- .slice(0, params?.limit || 10000);
124
+ .slice(0, params?.limit || 250000);
125
125
  }
126
126
  async function fetchMarketsDefault(marketFetcher, params) {
127
- const limit = params?.limit || 10000;
127
+ const limit = params?.limit || 250000;
128
128
  const offset = params?.offset || 0;
129
129
  // Map sort parameter to SDK's sortBy
130
130
  let sortBy = 'lp_rewards';
@@ -97,7 +97,7 @@ async function fetchMarketsBySlug(slug, http) {
97
97
  return unifiedMarkets;
98
98
  }
99
99
  async function searchMarkets(query, params, http) {
100
- const limit = params?.limit || 10000;
100
+ const limit = params?.limit || 250000;
101
101
  // Use parallel pagination to fetch all matching events
102
102
  // Each event can contain multiple markets, so we need a larger pool
103
103
  const queryParams = {
@@ -138,7 +138,7 @@ async function searchMarkets(query, params, http) {
138
138
  return unifiedMarkets.slice(0, limit);
139
139
  }
140
140
  async function fetchMarketsDefault(params, http) {
141
- const limit = params?.limit || 10000; // Higher default for better coverage
141
+ const limit = params?.limit || 250000; // Higher default for better coverage
142
142
  const offset = params?.offset || 0;
143
143
  // Map generic sort params to Polymarket Gamma API params
144
144
  let queryParams = {
package/dist/types.d.ts CHANGED
@@ -24,6 +24,7 @@ export interface UnifiedMarket {
24
24
  marketId: string;
25
25
  title: string;
26
26
  description: string;
27
+ slug?: string;
27
28
  outcomes: MarketOutcome[];
28
29
  resolutionDate: Date;
29
30
  volume24h: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxt-core",
3
- "version": "2.7.0",
3
+ "version": "2.8.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",
@@ -29,8 +29,8 @@
29
29
  "test": "jest -c jest.config.js",
30
30
  "server": "tsx watch src/server/index.ts",
31
31
  "server:prod": "node dist/server/index.js",
32
- "generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.7.0,library=urllib3",
33
- "generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.7.0,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
32
+ "generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.8.0,library=urllib3",
33
+ "generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.8.0,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
34
34
  "extract:jsdoc": "node ../scripts/extract-jsdoc.js",
35
35
  "generate:docs": "npm run extract:jsdoc && node ../scripts/generate-api-docs.js",
36
36
  "generate:sdk:all": "npm run generate:sdk:python && npm run generate:sdk:typescript && npm run generate:docs"