pmxt-core 2.0.8 → 2.0.9

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.
@@ -1,24 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchEvents = fetchEvents;
7
- const axios_1 = __importDefault(require("axios"));
8
4
  const utils_1 = require("./utils");
9
5
  const errors_1 = require("./errors");
10
6
  async function fetchEvents(params) {
11
7
  const searchLimit = 100000; // Fetch all events for comprehensive search
12
8
  try {
13
- // Fetch events from Gamma API
14
- const response = await axios_1.default.get(utils_1.GAMMA_API_URL, {
15
- params: {
16
- active: 'true',
17
- closed: 'false',
18
- limit: searchLimit
19
- }
9
+ // Fetch events from Gamma API using parallel pagination
10
+ const events = await (0, utils_1.paginateParallel)(utils_1.GAMMA_API_URL, {
11
+ active: 'true',
12
+ closed: 'false',
13
+ limit: searchLimit
20
14
  });
21
- const events = response.data || [];
22
15
  // Client-side text filtering
23
16
  const lowerQuery = (params?.query || '').toLowerCase();
24
17
  const searchIn = params?.searchIn || 'title';
@@ -95,11 +95,8 @@ async function fetchMarketsDefault(params) {
95
95
  queryParams.ascending = 'false';
96
96
  }
97
97
  try {
98
- // Fetch active events from Gamma
99
- const response = await axios_1.default.get(utils_1.GAMMA_API_URL, {
100
- params: queryParams
101
- });
102
- const events = response.data;
98
+ // Fetch active events from Gamma using parallel pagination
99
+ const events = await (0, utils_1.paginateParallel)(utils_1.GAMMA_API_URL, queryParams);
103
100
  const unifiedMarkets = [];
104
101
  for (const event of events) {
105
102
  // Each event is a container (e.g. "US Election").
@@ -6,3 +6,8 @@ export declare function mapMarketToUnified(event: any, market: any, options?: {
6
6
  useQuestionAsCandidateFallback?: boolean;
7
7
  }): UnifiedMarket | null;
8
8
  export declare function mapIntervalToFidelity(interval: CandleInterval): number;
9
+ /**
10
+ * Fetch all results from Gamma API using parallel pagination for best DX.
11
+ * Polymarket Gamma API has a hard limit of 500 results per request.
12
+ */
13
+ export declare function paginateParallel(url: string, params: any, maxResults?: number): Promise<any[]>;
@@ -1,8 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.DATA_API_URL = exports.CLOB_API_URL = exports.GAMMA_API_URL = void 0;
4
37
  exports.mapMarketToUnified = mapMarketToUnified;
5
38
  exports.mapIntervalToFidelity = mapIntervalToFidelity;
39
+ exports.paginateParallel = paginateParallel;
6
40
  const market_utils_1 = require("../../utils/market-utils");
7
41
  exports.GAMMA_API_URL = 'https://gamma-api.polymarket.com/events';
8
42
  exports.CLOB_API_URL = 'https://clob.polymarket.com';
@@ -99,3 +133,41 @@ function mapIntervalToFidelity(interval) {
99
133
  };
100
134
  return mapping[interval];
101
135
  }
136
+ /**
137
+ * Fetch all results from Gamma API using parallel pagination for best DX.
138
+ * Polymarket Gamma API has a hard limit of 500 results per request.
139
+ */
140
+ async function paginateParallel(url, params, maxResults = 10000) {
141
+ const PAGE_SIZE = 500;
142
+ const initialLimit = Math.min(params.limit || PAGE_SIZE, PAGE_SIZE);
143
+ // 1. Fetch the first page to see if we even need more
144
+ const firstPageResponse = await Promise.resolve().then(() => __importStar(require('axios'))).then(axios => axios.default.get(url, {
145
+ params: { ...params, limit: initialLimit, offset: 0 }
146
+ }));
147
+ const firstPage = firstPageResponse.data || [];
148
+ // If the first page isn't full, or we specifically asked for a small amount, we're done
149
+ if (firstPage.length < initialLimit || (params.limit && params.limit <= PAGE_SIZE)) {
150
+ return firstPage;
151
+ }
152
+ // 2. Determine how many more pages to fetch
153
+ const targetLimit = params.limit || maxResults;
154
+ const numPages = Math.ceil(targetLimit / PAGE_SIZE);
155
+ const offsets = [];
156
+ for (let i = 1; i < numPages; i++) {
157
+ offsets.push(i * PAGE_SIZE);
158
+ }
159
+ // 3. Fetch remaining pages in parallel
160
+ const axios = (await Promise.resolve().then(() => __importStar(require('axios')))).default;
161
+ const remainingPages = await Promise.all(offsets.map(async (offset) => {
162
+ try {
163
+ const res = await axios.get(url, {
164
+ params: { ...params, limit: PAGE_SIZE, offset }
165
+ });
166
+ return res.data || [];
167
+ }
168
+ catch (e) {
169
+ return []; // Swallow individual page errors to be robust
170
+ }
171
+ }));
172
+ return [firstPage, ...remainingPages].flat();
173
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxt-core",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
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.0.8,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.0.8,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.0.9,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.0.9,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"