pmxt-core 2.10.0 → 2.11.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.
@@ -140,6 +140,11 @@ export declare abstract class PredictionMarketExchange {
140
140
  protected credentials?: ExchangeCredentials;
141
141
  verbose: boolean;
142
142
  http: AxiosInstance;
143
+ enableRateLimit: boolean;
144
+ private _rateLimit;
145
+ private _throttler;
146
+ get rateLimit(): number;
147
+ set rateLimit(value: number);
143
148
  markets: Record<string, UnifiedMarket>;
144
149
  marketsBySlug: Record<string, UnifiedMarket>;
145
150
  loadedMarkets: boolean;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PredictionMarketExchange = void 0;
7
7
  const math_1 = require("./utils/math");
8
8
  const errors_1 = require("./errors");
9
+ const throttler_1 = require("./utils/throttler");
9
10
  const axios_1 = __importDefault(require("axios"));
10
11
  // ----------------------------------------------------------------------------
11
12
  // Base Exchange Class
@@ -14,6 +15,20 @@ class PredictionMarketExchange {
14
15
  credentials;
15
16
  verbose = false;
16
17
  http;
18
+ enableRateLimit = true;
19
+ _rateLimit = 1000;
20
+ _throttler;
21
+ get rateLimit() {
22
+ return this._rateLimit;
23
+ }
24
+ set rateLimit(value) {
25
+ this._rateLimit = value;
26
+ this._throttler = new throttler_1.Throttler({
27
+ refillRate: 1 / value,
28
+ capacity: 1,
29
+ delay: 1,
30
+ });
31
+ }
17
32
  // Market Cache
18
33
  markets = {};
19
34
  marketsBySlug = {};
@@ -39,6 +54,18 @@ class PredictionMarketExchange {
39
54
  constructor(credentials) {
40
55
  this.credentials = credentials;
41
56
  this.http = axios_1.default.create();
57
+ this._throttler = new throttler_1.Throttler({
58
+ refillRate: 1 / this._rateLimit,
59
+ capacity: 1,
60
+ delay: 1,
61
+ });
62
+ // Rate Limit Interceptor
63
+ this.http.interceptors.request.use(async (config) => {
64
+ if (this.enableRateLimit) {
65
+ await this._throttler.throttle();
66
+ }
67
+ return config;
68
+ });
42
69
  // Request Interceptor
43
70
  this.http.interceptors.request.use((config) => {
44
71
  if (this.verbose) {
@@ -43,6 +43,7 @@ class BaoziExchange extends BaseExchange_1.PredictionMarketExchange {
43
43
  credentials = options;
44
44
  }
45
45
  super(credentials);
46
+ this.rateLimit = 500;
46
47
  rpcUrl = rpcUrl
47
48
  || process.env.BAOZI_RPC_URL
48
49
  || process.env.HELIUS_RPC_URL
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/kalshi/Kalshi.yaml
3
- * Generated at: 2026-02-19T11:56:56.608Z
3
+ * Generated at: 2026-02-22T07:47:40.083Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const kalshiApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.kalshiApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/kalshi/Kalshi.yaml
6
- * Generated at: 2026-02-19T11:56:56.608Z
6
+ * Generated at: 2026-02-22T07:47:40.083Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.kalshiApiSpec = {
@@ -44,6 +44,7 @@ class KalshiExchange extends BaseExchange_1.PredictionMarketExchange {
44
44
  credentials = options;
45
45
  }
46
46
  super(credentials);
47
+ this.rateLimit = 100;
47
48
  this.wsConfig = wsConfig;
48
49
  if (credentials?.apiKey && credentials?.privateKey) {
49
50
  this.auth = new auth_1.KalshiAuth(credentials);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/limitless/Limitless.yaml
3
- * Generated at: 2026-02-19T11:56:56.657Z
3
+ * Generated at: 2026-02-22T07:47:40.130Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const limitlessApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.limitlessApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/limitless/Limitless.yaml
6
- * Generated at: 2026-02-19T11:56:56.657Z
6
+ * Generated at: 2026-02-22T07:47:40.130Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.limitlessApiSpec = {
@@ -53,6 +53,7 @@ class LimitlessExchange extends BaseExchange_1.PredictionMarketExchange {
53
53
  credentials = options;
54
54
  }
55
55
  super(credentials);
56
+ this.rateLimit = 200;
56
57
  this.wsConfig = wsConfig;
57
58
  // Initialize auth if API key or private key are provided
58
59
  // API key is now the primary authentication method
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/myriad/myriad.yaml
3
- * Generated at: 2026-02-19T11:56:56.675Z
3
+ * Generated at: 2026-02-22T07:47:40.144Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const myriadApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.myriadApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/myriad/myriad.yaml
6
- * Generated at: 2026-02-19T11:56:56.675Z
6
+ * Generated at: 2026-02-22T07:47:40.144Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.myriadApiSpec = {
@@ -33,6 +33,7 @@ class MyriadExchange extends BaseExchange_1.PredictionMarketExchange {
33
33
  ws;
34
34
  constructor(credentials) {
35
35
  super(credentials);
36
+ this.rateLimit = 500;
36
37
  if (credentials?.apiKey) {
37
38
  this.auth = new auth_1.MyriadAuth(credentials);
38
39
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketClobAPI.yaml
3
- * Generated at: 2026-02-19T11:56:56.616Z
3
+ * Generated at: 2026-02-22T07:47:40.090Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketClobSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketClobSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketClobAPI.yaml
6
- * Generated at: 2026-02-19T11:56:56.616Z
6
+ * Generated at: 2026-02-22T07:47:40.090Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketClobSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/Polymarket_Data_API.yaml
3
- * Generated at: 2026-02-19T11:56:56.634Z
3
+ * Generated at: 2026-02-22T07:47:40.108Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketDataSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketDataSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/Polymarket_Data_API.yaml
6
- * Generated at: 2026-02-19T11:56:56.634Z
6
+ * Generated at: 2026-02-22T07:47:40.108Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketDataSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketGammaAPI.yaml
3
- * Generated at: 2026-02-19T11:56:56.631Z
3
+ * Generated at: 2026-02-22T07:47:40.103Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketGammaSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketGammaSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketGammaAPI.yaml
6
- * Generated at: 2026-02-19T11:56:56.631Z
6
+ * Generated at: 2026-02-22T07:47:40.103Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketGammaSpec = {
@@ -52,6 +52,7 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
52
52
  credentials = options;
53
53
  }
54
54
  super(credentials);
55
+ this.rateLimit = 200;
55
56
  this.wsConfig = wsConfig;
56
57
  // Initialize auth if credentials are provided
57
58
  if (credentials?.privateKey) {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/probable/probable.yaml
3
- * Generated at: 2026-02-19T11:56:56.667Z
3
+ * Generated at: 2026-02-22T07:47:40.137Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const probableApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.probableApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/probable/probable.yaml
6
- * Generated at: 2026-02-19T11:56:56.667Z
6
+ * Generated at: 2026-02-22T07:47:40.137Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.probableApiSpec = {
@@ -53,6 +53,7 @@ class ProbableExchange extends BaseExchange_1.PredictionMarketExchange {
53
53
  wsConfig;
54
54
  constructor(credentials, wsConfig) {
55
55
  super(credentials);
56
+ this.rateLimit = 500;
56
57
  this.wsConfig = wsConfig;
57
58
  if (credentials?.privateKey && credentials?.apiKey && credentials?.apiSecret && credentials?.passphrase) {
58
59
  this.auth = new auth_1.ProbableAuth(credentials);
@@ -0,0 +1,17 @@
1
+ export declare class Throttler {
2
+ private tokens;
3
+ private queue;
4
+ private running;
5
+ private lastTimestamp;
6
+ private refillRate;
7
+ private capacity;
8
+ private delay;
9
+ constructor(config: {
10
+ refillRate: number;
11
+ capacity: number;
12
+ delay: number;
13
+ });
14
+ throttle(cost?: number): Promise<void>;
15
+ private loop;
16
+ private sleep;
17
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Throttler = void 0;
4
+ class Throttler {
5
+ tokens = 0;
6
+ queue = [];
7
+ running = false;
8
+ lastTimestamp = 0;
9
+ refillRate;
10
+ capacity;
11
+ delay;
12
+ constructor(config) {
13
+ this.refillRate = config.refillRate;
14
+ this.capacity = config.capacity;
15
+ this.delay = config.delay;
16
+ }
17
+ async throttle(cost = 1) {
18
+ return new Promise((resolve) => {
19
+ this.queue.push({ resolve, cost });
20
+ if (!this.running) {
21
+ this.running = true;
22
+ this.loop();
23
+ }
24
+ });
25
+ }
26
+ async loop() {
27
+ while (this.queue.length > 0) {
28
+ const now = Date.now();
29
+ if (this.lastTimestamp > 0) {
30
+ const elapsed = now - this.lastTimestamp;
31
+ this.tokens = Math.min(this.tokens + elapsed * this.refillRate, this.capacity);
32
+ }
33
+ this.lastTimestamp = now;
34
+ const head = this.queue[0];
35
+ if (this.tokens >= 0) {
36
+ this.tokens -= head.cost;
37
+ head.resolve();
38
+ this.queue.shift();
39
+ }
40
+ else {
41
+ await this.sleep(this.delay);
42
+ }
43
+ }
44
+ this.running = false;
45
+ }
46
+ sleep(ms) {
47
+ return new Promise((resolve) => setTimeout(resolve, ms));
48
+ }
49
+ }
50
+ exports.Throttler = Throttler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxt-core",
3
- "version": "2.10.0",
3
+ "version": "2.11.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.10.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.10.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.11.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.11.0,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
34
34
  "fetch:openapi": "node scripts/fetch-openapi-specs.js",
35
35
  "extract:jsdoc": "node ../scripts/extract-jsdoc.js",
36
36
  "generate:docs": "npm run extract:jsdoc && node ../scripts/generate-api-docs.js",