pmxtjs 0.4.0 → 0.4.2

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.
package/API_REFERENCE.md CHANGED
@@ -249,7 +249,7 @@ Both Polymarket and Kalshi support authenticated trading operations. You must pr
249
249
 
250
250
  ### Polymarket Authentication
251
251
 
252
- Requires your **Polygon Private Key**. See [Setup Guide](docs/SETUP_POLYMARKET.md) for details.
252
+ Requires your **Polygon Private Key**. See [Setup Guide](https://github.com/qoery-com/pmxt/blob/main/docs/SETUP_POLYMARKET.md) for details.
253
253
 
254
254
  ```typescript
255
255
  import pmxt from 'pmxtjs';
@@ -18,7 +18,6 @@ async function fetchActiveEvents(targetMarketCount) {
18
18
  const BATCH_SIZE = 200; // Max limit per Kalshi API docs
19
19
  do {
20
20
  try {
21
- // console.log(`Fetching Kalshi page ${page + 1}...`);
22
21
  const queryParams = {
23
22
  limit: BATCH_SIZE,
24
23
  with_nested_markets: true,
@@ -51,15 +50,42 @@ async function fetchActiveEvents(targetMarketCount) {
51
50
  } while (cursor && page < MAX_PAGES);
52
51
  return allEvents;
53
52
  }
53
+ async function fetchSeriesMap() {
54
+ try {
55
+ const response = await axios_1.default.get(utils_1.KALSHI_SERIES_URL);
56
+ const seriesList = response.data.series || [];
57
+ const map = new Map();
58
+ for (const series of seriesList) {
59
+ if (series.tags && series.tags.length > 0) {
60
+ map.set(series.ticker, series.tags);
61
+ }
62
+ }
63
+ return map;
64
+ }
65
+ catch (e) {
66
+ console.error("Error fetching Kalshi series:", e);
67
+ return new Map();
68
+ }
69
+ }
54
70
  async function fetchMarkets(params) {
55
71
  const limit = params?.limit || 50;
56
72
  try {
57
73
  // Fetch active events with nested markets
58
- // For small limits, we can optimize by fetching fewer pages
59
- const allEvents = await fetchActiveEvents(limit);
74
+ // We also fetch Series metadata to get tags (tags are on Series, not Event)
75
+ const [allEvents, seriesMap] = await Promise.all([
76
+ fetchActiveEvents(limit),
77
+ fetchSeriesMap()
78
+ ]);
60
79
  // Extract ALL markets from all events
61
80
  const allMarkets = [];
62
81
  for (const event of allEvents) {
82
+ // Enrich event with tags from Series
83
+ if (event.series_ticker && seriesMap.has(event.series_ticker)) {
84
+ // If event has no tags or empty tags, use series tags
85
+ if (!event.tags || event.tags.length === 0) {
86
+ event.tags = seriesMap.get(event.series_ticker);
87
+ }
88
+ }
63
89
  const markets = event.markets || [];
64
90
  for (const market of markets) {
65
91
  const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market);
@@ -22,6 +22,22 @@ async function getMarketsBySlug(eventTicker) {
22
22
  const event = response.data.event;
23
23
  if (!event)
24
24
  return [];
25
+ // Enrichment: Fetch series tags if they exist
26
+ if (event.series_ticker) {
27
+ try {
28
+ const seriesUrl = `${utils_1.KALSHI_SERIES_URL}/${event.series_ticker}`;
29
+ const seriesResponse = await axios_1.default.get(seriesUrl);
30
+ const series = seriesResponse.data.series;
31
+ if (series && series.tags && series.tags.length > 0) {
32
+ if (!event.tags || event.tags.length === 0) {
33
+ event.tags = series.tags;
34
+ }
35
+ }
36
+ }
37
+ catch (e) {
38
+ // Ignore errors fetching series info - non-critical
39
+ }
40
+ }
25
41
  const unifiedMarkets = [];
26
42
  const markets = event.markets || [];
27
43
  for (const market of markets) {
@@ -1,4 +1,5 @@
1
1
  import { UnifiedMarket, CandleInterval } from '../../types';
2
2
  export declare const KALSHI_API_URL = "https://api.elections.kalshi.com/trade-api/v2/events";
3
+ export declare const KALSHI_SERIES_URL = "https://api.elections.kalshi.com/trade-api/v2/series";
3
4
  export declare function mapMarketToUnified(event: any, market: any): UnifiedMarket | null;
4
5
  export declare function mapIntervalToKalshi(interval: CandleInterval): number;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KALSHI_API_URL = void 0;
3
+ exports.KALSHI_SERIES_URL = exports.KALSHI_API_URL = void 0;
4
4
  exports.mapMarketToUnified = mapMarketToUnified;
5
5
  exports.mapIntervalToKalshi = mapIntervalToKalshi;
6
6
  exports.KALSHI_API_URL = "https://api.elections.kalshi.com/trade-api/v2/events";
7
+ exports.KALSHI_SERIES_URL = "https://api.elections.kalshi.com/trade-api/v2/series";
7
8
  function mapMarketToUnified(event, market) {
8
9
  if (!market)
9
10
  return null;
@@ -42,10 +43,24 @@ function mapMarketToUnified(event, market) {
42
43
  priceChange24h: -priceChange // Inverse change for No? simplified assumption
43
44
  }
44
45
  ];
46
+ // Combine category and tags into a unified tags array
47
+ const unifiedTags = [];
48
+ // Add category first (if it exists)
49
+ if (event.category) {
50
+ unifiedTags.push(event.category);
51
+ }
52
+ // Add tags (if they exist and avoid duplicates)
53
+ if (event.tags && Array.isArray(event.tags)) {
54
+ for (const tag of event.tags) {
55
+ if (!unifiedTags.includes(tag)) {
56
+ unifiedTags.push(tag);
57
+ }
58
+ }
59
+ }
45
60
  return {
46
61
  id: market.ticker,
47
62
  title: event.title,
48
- description: event.sub_title || market.subtitle || "",
63
+ description: market.rules_primary || market.rules_secondary || "",
49
64
  outcomes: outcomes,
50
65
  resolutionDate: new Date(market.expiration_time),
51
66
  volume24h: Number(market.volume_24h || market.volume || 0),
@@ -54,7 +69,7 @@ function mapMarketToUnified(event, market) {
54
69
  openInterest: Number(market.open_interest || 0),
55
70
  url: `https://kalshi.com/events/${event.event_ticker}`,
56
71
  category: event.category,
57
- tags: event.tags || []
72
+ tags: unifiedTags
58
73
  };
59
74
  }
60
75
  function mapIntervalToKalshi(interval) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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",
package/readme.md CHANGED
@@ -30,7 +30,9 @@
30
30
  <a href="https://github.com/qoery-com/pmxt/stargazers"><img src="https://img.shields.io/github/stars/qoery-com/pmxt?refresh=1" alt="GitHub stars"></a>
31
31
  </td>
32
32
  <td>
33
- <!-- Space for future badge -->
33
+ <a href="https://www.npmjs.com/package/pmxtjs">
34
+ <img src="https://img.shields.io/npm/v/pmxtjs.svg" alt="npm version">
35
+ </a>
34
36
  </td>
35
37
  </tr>
36
38
  </table>
@@ -87,7 +89,7 @@ pmxt supports trading functionality (placing and cancelling orders).
87
89
  To trade, you must provide your private credentials.
88
90
 
89
91
  - **Polymarket**: Requires your Polygon Private Key. [View Setup Guide](docs/SETUP_POLYMARKET.md)
90
- - **Kalshi**: Requires API Key & Private Key (Coming Soon).
92
+ - **Kalshi**: Requires API Key & Private Key.
91
93
 
92
94
  ### Trading Example
93
95