pmxt-core 2.13.2 → 2.15.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 (39) hide show
  1. package/dist/exchanges/kalshi/api.d.ts +7 -1
  2. package/dist/exchanges/kalshi/api.js +11 -2
  3. package/dist/exchanges/kalshi/config.d.ts +103 -0
  4. package/dist/exchanges/kalshi/config.js +144 -0
  5. package/dist/exchanges/kalshi/fetchEvents.d.ts +2 -2
  6. package/dist/exchanges/kalshi/fetchEvents.js +19 -16
  7. package/dist/exchanges/kalshi/fetchMarkets.d.ts +2 -2
  8. package/dist/exchanges/kalshi/fetchMarkets.js +36 -25
  9. package/dist/exchanges/kalshi/fetchOHLCV.d.ts +2 -2
  10. package/dist/exchanges/kalshi/fetchOHLCV.js +20 -17
  11. package/dist/exchanges/kalshi/fetchOrderBook.d.ts +2 -0
  12. package/dist/exchanges/kalshi/fetchOrderBook.js +60 -0
  13. package/dist/exchanges/kalshi/fetchTrades.d.ts +3 -0
  14. package/dist/exchanges/kalshi/fetchTrades.js +32 -0
  15. package/dist/exchanges/kalshi/index.d.ts +8 -3
  16. package/dist/exchanges/kalshi/index.js +82 -70
  17. package/dist/exchanges/kalshi/kalshi.test.js +294 -292
  18. package/dist/exchanges/kalshi/utils.d.ts +1 -3
  19. package/dist/exchanges/kalshi/utils.js +14 -16
  20. package/dist/exchanges/kalshi/websocket.d.ts +4 -3
  21. package/dist/exchanges/kalshi/websocket.js +87 -61
  22. package/dist/exchanges/kalshi-demo/index.d.ts +10 -0
  23. package/dist/exchanges/kalshi-demo/index.js +23 -0
  24. package/dist/exchanges/limitless/api.d.ts +1 -1
  25. package/dist/exchanges/limitless/api.js +1 -1
  26. package/dist/exchanges/myriad/api.d.ts +1 -1
  27. package/dist/exchanges/myriad/api.js +1 -1
  28. package/dist/exchanges/polymarket/api-clob.d.ts +1 -1
  29. package/dist/exchanges/polymarket/api-clob.js +1 -1
  30. package/dist/exchanges/polymarket/api-data.d.ts +1 -1
  31. package/dist/exchanges/polymarket/api-data.js +1 -1
  32. package/dist/exchanges/polymarket/api-gamma.d.ts +1 -1
  33. package/dist/exchanges/polymarket/api-gamma.js +1 -1
  34. package/dist/exchanges/probable/api.d.ts +1 -1
  35. package/dist/exchanges/probable/api.js +1 -1
  36. package/dist/index.d.ts +4 -0
  37. package/dist/index.js +5 -1
  38. package/dist/server/app.js +56 -48
  39. package/package.json +3 -3
@@ -9,6 +9,7 @@ const cors_1 = __importDefault(require("cors"));
9
9
  const polymarket_1 = require("../exchanges/polymarket");
10
10
  const limitless_1 = require("../exchanges/limitless");
11
11
  const kalshi_1 = require("../exchanges/kalshi");
12
+ const kalshi_demo_1 = require("../exchanges/kalshi-demo");
12
13
  const probable_1 = require("../exchanges/probable");
13
14
  const baozi_1 = require("../exchanges/baozi");
14
15
  const myriad_1 = require("../exchanges/myriad");
@@ -18,44 +19,34 @@ const defaultExchanges = {
18
19
  polymarket: null,
19
20
  limitless: null,
20
21
  kalshi: null,
22
+ "kalshi-demo": null,
21
23
  probable: null,
22
24
  baozi: null,
23
- myriad: null
25
+ myriad: null,
24
26
  };
25
27
  async function startServer(port, accessToken) {
26
28
  const app = (0, express_1.default)();
27
29
  app.use((0, cors_1.default)());
28
30
  app.use(express_1.default.json());
29
31
  // Health check (public)
30
- app.get('/health', (req, res) => {
31
- res.json({ status: 'ok', timestamp: Date.now() });
32
+ app.get("/health", (req, res) => {
33
+ res.json({ status: "ok", timestamp: Date.now() });
32
34
  });
33
35
  // Auth Middleware
34
36
  app.use((req, res, next) => {
35
- const token = req.headers['x-pmxt-access-token'];
37
+ const token = req.headers["x-pmxt-access-token"];
36
38
  if (!token || token !== accessToken) {
37
- res.status(401).json({ success: false, error: 'Unauthorized: Invalid or missing access token' });
39
+ res.status(401).json({
40
+ success: false,
41
+ error: "Unauthorized: Invalid or missing access token",
42
+ });
38
43
  return;
39
44
  }
40
45
  next();
41
46
  });
42
- // Capability map endpoint: GET /api/:exchange/has
43
- app.get('/api/:exchange/has', (req, res, next) => {
44
- try {
45
- const exchangeName = req.params.exchange.toLowerCase();
46
- if (!defaultExchanges[exchangeName]) {
47
- defaultExchanges[exchangeName] = createExchange(exchangeName);
48
- }
49
- const exchange = defaultExchanges[exchangeName];
50
- res.json({ success: true, data: exchange.has });
51
- }
52
- catch (error) {
53
- next(error);
54
- }
55
- });
56
47
  // API endpoint: POST /api/:exchange/:method
57
48
  // Body: { args: any[], credentials?: ExchangeCredentials }
58
- app.post('/api/:exchange/:method', async (req, res, next) => {
49
+ app.post("/api/:exchange/:method", async (req, res, next) => {
59
50
  try {
60
51
  const exchangeName = req.params.exchange.toLowerCase();
61
52
  const methodName = req.params.method;
@@ -74,18 +65,20 @@ async function startServer(port, accessToken) {
74
65
  }
75
66
  exchange = defaultExchanges[exchangeName];
76
67
  }
77
- // Set verbose flag if present in request
78
- if (req.body.verbose === true) {
68
+ // Apply verbose logging if requested via header
69
+ if (req.headers["x-pmxt-verbose"] === "true") {
79
70
  exchange.verbose = true;
80
71
  }
81
72
  else {
82
73
  // Reset to false for singleton instances to avoid leaking state between requests
83
- // For new instances it defaults to false anyway
84
74
  exchange.verbose = false;
85
75
  }
86
76
  // 2. Validate Method
87
- if (typeof exchange[methodName] !== 'function') {
88
- res.status(404).json({ success: false, error: `Method '${methodName}' not found on ${exchangeName}` });
77
+ if (typeof exchange[methodName] !== "function") {
78
+ res.status(404).json({
79
+ success: false,
80
+ error: `Method '${methodName}' not found on ${exchangeName}`,
81
+ });
89
82
  return;
90
83
  }
91
84
  // 3. Execute with direct argument spreading
@@ -98,7 +91,7 @@ async function startServer(port, accessToken) {
98
91
  });
99
92
  // Error handler
100
93
  app.use((error, req, res, next) => {
101
- console.error('API Error:', error);
94
+ console.error("API Error:", error);
102
95
  if (error.stack) {
103
96
  console.error(error.stack);
104
97
  }
@@ -109,72 +102,87 @@ async function startServer(port, accessToken) {
109
102
  error: {
110
103
  message: error.message,
111
104
  code: error.code,
112
- retryable: error.retryable
113
- }
105
+ retryable: error.retryable,
106
+ },
114
107
  };
115
108
  // Add exchange context if available
116
109
  if (error.exchange) {
117
110
  errorResponse.error.exchange = error.exchange;
118
111
  }
119
112
  // Add retryAfter for rate limit errors
120
- if ('retryAfter' in error && error.retryAfter !== undefined) {
113
+ if ("retryAfter" in error && error.retryAfter !== undefined) {
121
114
  errorResponse.error.retryAfter = error.retryAfter;
122
115
  }
123
116
  // Add stack trace in development
124
- if (process.env.NODE_ENV === 'development') {
117
+ if (process.env.NODE_ENV === "development") {
125
118
  errorResponse.error.stack = error.stack;
126
119
  }
127
- res.status(error.status).json(errorResponse);
120
+ res.status(error.status || 500).json(errorResponse);
128
121
  return;
129
122
  }
130
123
  // Handle generic errors
131
124
  res.status(error.status || 500).json({
132
125
  success: false,
133
126
  error: {
134
- message: error.message || 'Internal server error',
135
- stack: process.env.NODE_ENV === 'development' ? error.stack : undefined
136
- }
127
+ message: error.message || "Internal server error",
128
+ stack: process.env.NODE_ENV === "development" ? error.stack : undefined,
129
+ },
137
130
  });
138
131
  });
139
- return app.listen(port, '127.0.0.1');
132
+ return app.listen(port, "127.0.0.1");
140
133
  }
141
134
  function createExchange(name, credentials) {
142
135
  switch (name) {
143
- case 'polymarket':
136
+ case "polymarket":
144
137
  return new polymarket_1.PolymarketExchange({
145
- privateKey: credentials?.privateKey || process.env.POLYMARKET_PK || process.env.POLYMARKET_PRIVATE_KEY,
138
+ privateKey: credentials?.privateKey ||
139
+ process.env.POLYMARKET_PK ||
140
+ process.env.POLYMARKET_PRIVATE_KEY,
146
141
  apiKey: credentials?.apiKey || process.env.POLYMARKET_API_KEY,
147
142
  apiSecret: credentials?.apiSecret || process.env.POLYMARKET_API_SECRET,
148
143
  passphrase: credentials?.passphrase || process.env.POLYMARKET_PASSPHRASE,
149
144
  funderAddress: credentials?.funderAddress,
150
- signatureType: credentials?.signatureType
145
+ signatureType: credentials?.signatureType,
151
146
  });
152
- case 'limitless':
147
+ case "limitless":
153
148
  return new limitless_1.LimitlessExchange({
154
- privateKey: credentials?.privateKey || process.env.LIMITLESS_PK || process.env.LIMITLESS_PRIVATE_KEY,
149
+ privateKey: credentials?.privateKey ||
150
+ process.env.LIMITLESS_PK ||
151
+ process.env.LIMITLESS_PRIVATE_KEY,
155
152
  apiKey: credentials?.apiKey || process.env.LIMITLESS_API_KEY,
156
153
  apiSecret: credentials?.apiSecret || process.env.LIMITLESS_API_SECRET,
157
- passphrase: credentials?.passphrase || process.env.LIMITLESS_PASSPHRASE
154
+ passphrase: credentials?.passphrase || process.env.LIMITLESS_PASSPHRASE,
158
155
  });
159
- case 'kalshi':
156
+ case "kalshi":
160
157
  return new kalshi_1.KalshiExchange({
161
- apiKey: credentials?.apiKey || process.env.KALSHI_API_KEY,
162
- privateKey: credentials?.privateKey || process.env.KALSHI_PRIVATE_KEY
158
+ credentials: {
159
+ apiKey: credentials?.apiKey || process.env.KALSHI_API_KEY,
160
+ privateKey: credentials?.privateKey || process.env.KALSHI_PRIVATE_KEY,
161
+ },
162
+ });
163
+ case "kalshi-demo":
164
+ return new kalshi_demo_1.KalshiDemoExchange({
165
+ credentials: {
166
+ apiKey: credentials?.apiKey || process.env.KALSHI_API_KEY,
167
+ privateKey: credentials?.privateKey || process.env.KALSHI_PRIVATE_KEY,
168
+ },
163
169
  });
164
- case 'probable':
170
+ case "probable":
165
171
  return new probable_1.ProbableExchange({
166
172
  apiKey: credentials?.apiKey || process.env.PROBABLE_API_KEY,
167
173
  apiSecret: credentials?.apiSecret || process.env.PROBABLE_API_SECRET,
168
174
  passphrase: credentials?.passphrase || process.env.PROBABLE_PASSPHRASE,
169
175
  privateKey: credentials?.privateKey || process.env.PROBABLE_PRIVATE_KEY,
170
176
  });
171
- case 'baozi':
177
+ case "baozi":
172
178
  return new baozi_1.BaoziExchange({
173
179
  privateKey: credentials?.privateKey || process.env.BAOZI_PRIVATE_KEY,
174
180
  });
175
- case 'myriad':
181
+ case "myriad":
176
182
  return new myriad_1.MyriadExchange({
177
- apiKey: credentials?.apiKey || process.env.MYRIAD_API_KEY || process.env.MYRIAD_PROD,
183
+ apiKey: credentials?.apiKey ||
184
+ process.env.MYRIAD_API_KEY ||
185
+ process.env.MYRIAD_PROD,
178
186
  privateKey: credentials?.privateKey || process.env.MYRIAD_WALLET_ADDRESS,
179
187
  });
180
188
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxt-core",
3
- "version": "2.13.2",
3
+ "version": "2.15.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.13.2,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.13.2,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.15.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.15.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",