pmxt 1.5.2__tar.gz → 1.5.5__tar.gz

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 (78) hide show
  1. {pmxt-1.5.2 → pmxt-1.5.5}/PKG-INFO +1 -1
  2. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/__init__.py +1 -1
  3. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/api_client.py +1 -1
  4. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/configuration.py +1 -1
  5. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt/__init__.py +1 -1
  6. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt/_server/server/bundled.js +350 -218
  7. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt.egg-info/PKG-INFO +1 -1
  8. {pmxt-1.5.2 → pmxt-1.5.5}/pyproject.toml +1 -1
  9. {pmxt-1.5.2 → pmxt-1.5.5}/README.md +0 -0
  10. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/api/__init__.py +0 -0
  11. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/api/default_api.py +0 -0
  12. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/api_response.py +0 -0
  13. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/exceptions.py +0 -0
  14. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/__init__.py +0 -0
  15. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/balance.py +0 -0
  16. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/base_request.py +0 -0
  17. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/base_response.py +0 -0
  18. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/cancel_order_request.py +0 -0
  19. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/create_order200_response.py +0 -0
  20. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/create_order_params.py +0 -0
  21. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/create_order_request.py +0 -0
  22. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/error_detail.py +0 -0
  23. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/error_response.py +0 -0
  24. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/exchange_credentials.py +0 -0
  25. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/execution_price_result.py +0 -0
  26. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_balance200_response.py +0 -0
  27. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_markets200_response.py +0 -0
  28. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_markets_request.py +0 -0
  29. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_ohlcv200_response.py +0 -0
  30. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_ohlcv_request.py +0 -0
  31. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_ohlcv_request_args_inner.py +0 -0
  32. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_open_orders200_response.py +0 -0
  33. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_open_orders_request.py +0 -0
  34. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_order_book200_response.py +0 -0
  35. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_order_book_request.py +0 -0
  36. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_positions200_response.py +0 -0
  37. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_positions_request.py +0 -0
  38. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_trades200_response.py +0 -0
  39. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/fetch_trades_request.py +0 -0
  40. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/get_execution_price200_response.py +0 -0
  41. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/get_execution_price_detailed200_response.py +0 -0
  42. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/get_execution_price_request.py +0 -0
  43. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/get_execution_price_request_args_inner.py +0 -0
  44. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/get_markets_by_slug_request.py +0 -0
  45. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/health_check200_response.py +0 -0
  46. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/history_filter_params.py +0 -0
  47. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/market_filter_params.py +0 -0
  48. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/market_outcome.py +0 -0
  49. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/order.py +0 -0
  50. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/order_book.py +0 -0
  51. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/order_level.py +0 -0
  52. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/position.py +0 -0
  53. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/price_candle.py +0 -0
  54. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/search_events200_response.py +0 -0
  55. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/search_events_request.py +0 -0
  56. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/search_markets_request.py +0 -0
  57. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/search_markets_request_args_inner.py +0 -0
  58. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/trade.py +0 -0
  59. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/unified_event.py +0 -0
  60. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/unified_market.py +0 -0
  61. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/watch_order_book_request.py +0 -0
  62. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/watch_order_book_request_args_inner.py +0 -0
  63. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/models/watch_trades_request.py +0 -0
  64. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/py.typed +0 -0
  65. {pmxt-1.5.2 → pmxt-1.5.5}/generated/pmxt_internal/rest.py +0 -0
  66. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt/_server/__init__.py +0 -0
  67. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt/_server/bin/pmxt-ensure-server +0 -0
  68. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt/_server/bin/pmxt-ensure-server.js +0 -0
  69. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt/client.py +0 -0
  70. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt/models.py +0 -0
  71. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt/server_manager.py +0 -0
  72. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt.egg-info/SOURCES.txt +0 -0
  73. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt.egg-info/dependency_links.txt +0 -0
  74. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt.egg-info/requires.txt +0 -0
  75. {pmxt-1.5.2 → pmxt-1.5.5}/pmxt.egg-info/top_level.txt +0 -0
  76. {pmxt-1.5.2 → pmxt-1.5.5}/setup.cfg +0 -0
  77. {pmxt-1.5.2 → pmxt-1.5.5}/tests/test_integration.py +0 -0
  78. {pmxt-1.5.2 → pmxt-1.5.5}/tests/test_server_manager.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pmxt
3
- Version: 1.5.2
3
+ Version: 1.5.5
4
4
  Summary: Unified prediction market data API - The ccxt for prediction markets
5
5
  Author: PMXT Contributors
6
6
  License: MIT
@@ -14,7 +14,7 @@
14
14
  """ # noqa: E501
15
15
 
16
16
 
17
- __version__ = "1.5.2"
17
+ __version__ = "1.5.5"
18
18
 
19
19
  # Define package exports
20
20
  __all__ = [
@@ -91,7 +91,7 @@ class ApiClient:
91
91
  self.default_headers[header_name] = header_value
92
92
  self.cookie = cookie
93
93
  # Set default User-Agent.
94
- self.user_agent = 'OpenAPI-Generator/1.5.2/python'
94
+ self.user_agent = 'OpenAPI-Generator/1.5.5/python'
95
95
  self.client_side_validation = configuration.client_side_validation
96
96
 
97
97
  def __enter__(self):
@@ -506,7 +506,7 @@ class Configuration:
506
506
  "OS: {env}\n"\
507
507
  "Python Version: {pyversion}\n"\
508
508
  "Version of the API: 0.4.4\n"\
509
- "SDK Package Version: 1.5.2".\
509
+ "SDK Package Version: 1.5.5".\
510
510
  format(env=sys.platform, pyversion=sys.version)
511
511
 
512
512
  def get_host_settings(self) -> List[HostSetting]:
@@ -33,7 +33,7 @@ from .models import (
33
33
  CreateOrderParams,
34
34
  )
35
35
 
36
- __version__ = "1.5.2"
36
+ __version__ = "1.5.5"
37
37
  __all__ = [
38
38
  # Exchanges
39
39
  "Polymarket",
@@ -38127,12 +38127,13 @@ var require_utils4 = __commonJS({
38127
38127
  "dist/exchanges/polymarket/utils.js"(exports2) {
38128
38128
  "use strict";
38129
38129
  Object.defineProperty(exports2, "__esModule", { value: true });
38130
- exports2.CLOB_API_URL = exports2.GAMMA_API_URL = void 0;
38130
+ exports2.DATA_API_URL = exports2.CLOB_API_URL = exports2.GAMMA_API_URL = void 0;
38131
38131
  exports2.mapMarketToUnified = mapMarketToUnified;
38132
38132
  exports2.mapIntervalToFidelity = mapIntervalToFidelity;
38133
38133
  var market_utils_1 = require_market_utils();
38134
38134
  exports2.GAMMA_API_URL = "https://gamma-api.polymarket.com/events";
38135
38135
  exports2.CLOB_API_URL = "https://clob.polymarket.com";
38136
+ exports2.DATA_API_URL = "https://data-api.polymarket.com";
38136
38137
  function mapMarketToUnified(event, market, options = {}) {
38137
38138
  if (!market)
38138
38139
  return null;
@@ -38284,7 +38285,7 @@ var require_searchMarkets = __commonJS({
38284
38285
  exports2.searchMarkets = searchMarkets;
38285
38286
  var fetchMarkets_1 = require_fetchMarkets();
38286
38287
  async function searchMarkets(query, params) {
38287
- const searchLimit = 1e5;
38288
+ const searchLimit = 5e3;
38288
38289
  try {
38289
38290
  const markets = await (0, fetchMarkets_1.fetchMarkets)({
38290
38291
  ...params,
@@ -38562,7 +38563,8 @@ var require_fetchTrades = __commonJS({
38562
38563
  }
38563
38564
  try {
38564
38565
  const queryParams = {
38565
- market: id
38566
+ asset_id: id
38567
+ // Uses asset_id for Token ID on Data API
38566
38568
  };
38567
38569
  if (params.start) {
38568
38570
  queryParams.after = Math.floor(params.start.getTime() / 1e3);
@@ -38570,7 +38572,7 @@ var require_fetchTrades = __commonJS({
38570
38572
  if (params.end) {
38571
38573
  queryParams.before = Math.floor(params.end.getTime() / 1e3);
38572
38574
  }
38573
- const response = await axios_1.default.get(`${utils_1.CLOB_API_URL}/trades`, {
38575
+ const response = await axios_1.default.get(`${utils_1.DATA_API_URL}/trades`, {
38574
38576
  params: queryParams
38575
38577
  });
38576
38578
  const trades = response.data || [];
@@ -38583,13 +38585,14 @@ var require_fetchTrades = __commonJS({
38583
38585
  side: trade.side === "BUY" ? "buy" : trade.side === "SELL" ? "sell" : "unknown"
38584
38586
  }));
38585
38587
  if (params.limit && mappedTrades.length > params.limit) {
38586
- return mappedTrades.slice(-params.limit);
38588
+ return mappedTrades.slice(0, params.limit);
38587
38589
  }
38588
38590
  return mappedTrades;
38589
38591
  } catch (error) {
38590
- if (axios_1.default.isAxiosError(error) && error.response) {
38591
- const apiError = error.response.data?.error || error.response.data?.message || "Unknown API Error";
38592
- throw new Error(`Polymarket Trades API Error (${error.response.status}): ${apiError}. Used ID: ${id}`);
38592
+ if (axios_1.default.isAxiosError(error)) {
38593
+ const apiError = error.response?.data?.error || error.response?.data?.message || error.message;
38594
+ console.error(`[Polymarket] fetchTrades failed for ID ${id}: ${apiError}`);
38595
+ throw new Error(`Polymarket Trades API Error: ${apiError}`);
38593
38596
  }
38594
38597
  console.error(`Unexpected error fetching Polymarket trades for ${id}:`, error);
38595
38598
  throw error;
@@ -38608,25 +38611,31 @@ var require_fetchPositions = __commonJS({
38608
38611
  Object.defineProperty(exports2, "__esModule", { value: true });
38609
38612
  exports2.fetchPositions = fetchPositions;
38610
38613
  var axios_1 = __importDefault(require_axios());
38611
- var DATA_API_URL = "https://data-api.polymarket.com";
38614
+ var utils_1 = require_utils4();
38612
38615
  async function fetchPositions(userAddress) {
38613
- const response = await axios_1.default.get(`${DATA_API_URL}/positions`, {
38614
- params: {
38615
- user: userAddress,
38616
- limit: 100
38617
- }
38618
- });
38619
- const data = Array.isArray(response.data) ? response.data : [];
38620
- return data.map((p) => ({
38621
- marketId: p.conditionId,
38622
- outcomeId: p.asset,
38623
- outcomeLabel: p.outcome || "Unknown",
38624
- size: parseFloat(p.size),
38625
- entryPrice: parseFloat(p.avgPrice),
38626
- currentPrice: parseFloat(p.curPrice || "0"),
38627
- unrealizedPnL: parseFloat(p.cashPnl || "0"),
38628
- realizedPnL: parseFloat(p.realizedPnl || "0")
38629
- }));
38616
+ try {
38617
+ const response = await axios_1.default.get(`${utils_1.DATA_API_URL}/positions`, {
38618
+ params: {
38619
+ user: userAddress,
38620
+ limit: 100
38621
+ }
38622
+ });
38623
+ const data = Array.isArray(response.data) ? response.data : [];
38624
+ return data.map((p) => ({
38625
+ marketId: p.conditionId,
38626
+ outcomeId: p.asset,
38627
+ outcomeLabel: p.outcome || "Unknown",
38628
+ size: parseFloat(p.size),
38629
+ entryPrice: parseFloat(p.avgPrice),
38630
+ currentPrice: parseFloat(p.curPrice || "0"),
38631
+ unrealizedPnL: parseFloat(p.cashPnl || "0"),
38632
+ realizedPnL: parseFloat(p.realizedPnl || "0")
38633
+ }));
38634
+ } catch (error) {
38635
+ const apiError = error.response?.data?.error || error.response?.data?.message || error.message;
38636
+ console.error(`[Polymarket] fetchPositions failed for ${userAddress}: ${apiError}`);
38637
+ throw new Error(`Polymarket Positions API Error: ${apiError}`);
38638
+ }
38630
38639
  }
38631
38640
  }
38632
38641
  });
@@ -104861,7 +104870,7 @@ var require_polymarket = __commonJS({
104861
104870
  tickSize
104862
104871
  });
104863
104872
  if (!response || !response.success) {
104864
- throw new Error(response?.errorMsg || "Order placement failed");
104873
+ throw new Error(`${response?.errorMsg || "Order placement failed"} (Response: ${JSON.stringify(response)})`);
104865
104874
  }
104866
104875
  return {
104867
104876
  id: response.orderID,
@@ -104938,16 +104947,19 @@ var require_polymarket = __commonJS({
104938
104947
  const client = await auth.getClobClient();
104939
104948
  try {
104940
104949
  const order = await client.getOrder(orderId);
104950
+ if (!order || !order.id) {
104951
+ const errorMsg = order?.error || "Order not found (Invalid ID)";
104952
+ throw new Error(errorMsg);
104953
+ }
104941
104954
  return {
104942
104955
  id: order.id,
104943
104956
  marketId: order.market || "unknown",
104944
104957
  outcomeId: order.asset_id,
104945
- side: order.side.toLowerCase(),
104958
+ side: (order.side || "").toLowerCase(),
104946
104959
  type: order.order_type === "GTC" ? "limit" : "market",
104947
104960
  price: parseFloat(order.price),
104948
104961
  amount: parseFloat(order.original_size),
104949
- status: order.status,
104950
- // Needs precise mapping
104962
+ status: typeof order.status === "string" ? order.status.toLowerCase() : order.status,
104951
104963
  filled: parseFloat(order.size_matched),
104952
104964
  remaining: parseFloat(order.original_size) - parseFloat(order.size_matched),
104953
104965
  timestamp: order.created_at * 1e3
@@ -105130,7 +105142,7 @@ var require_fetchMarkets2 = __commonJS({
105130
105142
  const unifiedMarkets = [];
105131
105143
  for (const market of markets) {
105132
105144
  const unifiedMarket = (0, utils_1.mapMarketToUnified)(market);
105133
- if (unifiedMarket) {
105145
+ if (unifiedMarket && unifiedMarket.outcomes.length > 0) {
105134
105146
  unifiedMarkets.push(unifiedMarket);
105135
105147
  }
105136
105148
  }
@@ -105167,8 +105179,22 @@ var require_searchMarkets2 = __commonJS({
105167
105179
  limit: params?.limit || 20
105168
105180
  }
105169
105181
  });
105170
- const markets = response.data?.markets || [];
105171
- return markets.map((m) => (0, utils_1.mapMarketToUnified)(m)).filter((m) => m !== null).slice(0, params?.limit || 20);
105182
+ const rawResults = response.data?.markets || [];
105183
+ const allMarkets = [];
105184
+ for (const res of rawResults) {
105185
+ if (res.markets && Array.isArray(res.markets)) {
105186
+ for (const child of res.markets) {
105187
+ const mapped = (0, utils_1.mapMarketToUnified)(child);
105188
+ if (mapped)
105189
+ allMarkets.push(mapped);
105190
+ }
105191
+ } else {
105192
+ const mapped = (0, utils_1.mapMarketToUnified)(res);
105193
+ if (mapped)
105194
+ allMarkets.push(mapped);
105195
+ }
105196
+ }
105197
+ return allMarkets.filter((m) => m !== null && m.outcomes.length > 0).slice(0, params?.limit || 20);
105172
105198
  } catch (error) {
105173
105199
  console.error("Error searching Limitless data:", error.message);
105174
105200
  return [];
@@ -105350,55 +105376,10 @@ var require_fetchOrderBook2 = __commonJS({
105350
105376
  var require_fetchTrades2 = __commonJS({
105351
105377
  "dist/exchanges/limitless/fetchTrades.js"(exports2) {
105352
105378
  "use strict";
105353
- var __importDefault = exports2 && exports2.__importDefault || function(mod) {
105354
- return mod && mod.__esModule ? mod : { "default": mod };
105355
- };
105356
105379
  Object.defineProperty(exports2, "__esModule", { value: true });
105357
105380
  exports2.fetchTrades = fetchTrades;
105358
- var axios_1 = __importDefault(require_axios());
105359
- var utils_1 = require_utils10();
105360
105381
  async function fetchTrades(id, params) {
105361
- try {
105362
- const url2 = `${utils_1.LIMITLESS_API_URL}/portfolio/trades`;
105363
- const requestParams = {
105364
- limit: params.limit || 100
105365
- };
105366
- if (params.start) {
105367
- requestParams.after = Math.floor(params.start.getTime() / 1e3);
105368
- }
105369
- if (params.end) {
105370
- requestParams.before = Math.floor(params.end.getTime() / 1e3);
105371
- }
105372
- const response = await axios_1.default.get(url2, {
105373
- params: requestParams
105374
- });
105375
- const tradesData = response.data?.data || response.data || [];
105376
- let trades = tradesData.map((trade) => {
105377
- const price = parseFloat(trade.price);
105378
- const timestamp = Number(trade.timestamp);
105379
- let side = "unknown";
105380
- const rawSide = trade.side?.toLowerCase();
105381
- if (rawSide === "buy")
105382
- side = "buy";
105383
- else if (rawSide === "sell")
105384
- side = "sell";
105385
- return {
105386
- id: trade.id || `${timestamp}-${price}`,
105387
- timestamp: timestamp * 1e3,
105388
- price,
105389
- amount: parseFloat(trade.size || trade.amount || 0),
105390
- side
105391
- };
105392
- });
105393
- trades.sort((a, b) => b.timestamp - a.timestamp);
105394
- if (params.limit) {
105395
- trades = trades.slice(0, params.limit);
105396
- }
105397
- return trades;
105398
- } catch (error) {
105399
- console.error(`Error fetching Limitless trades for ${id}:`, error.message);
105400
- return [];
105401
- }
105382
+ throw new Error("Limitless fetchTrades not implemented: No public market trades API available.");
105402
105383
  }
105403
105384
  }
105404
105385
  });
@@ -105524,6 +105505,176 @@ var require_auth2 = __commonJS({
105524
105505
  }
105525
105506
  });
105526
105507
 
105508
+ // dist/exchanges/limitless/client.js
105509
+ var require_client = __commonJS({
105510
+ "dist/exchanges/limitless/client.js"(exports2) {
105511
+ "use strict";
105512
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
105513
+ return mod && mod.__esModule ? mod : { "default": mod };
105514
+ };
105515
+ Object.defineProperty(exports2, "__esModule", { value: true });
105516
+ exports2.LimitlessClient = void 0;
105517
+ var axios_1 = __importDefault(require_axios());
105518
+ var ethers_1 = require_lib36();
105519
+ var LIMITLESS_API_URL = "https://api.limitless.exchange";
105520
+ var BASE_CHAIN_ID = 8453;
105521
+ var ORDER_TYPES = {
105522
+ Order: [
105523
+ { name: "salt", type: "uint256" },
105524
+ { name: "maker", type: "address" },
105525
+ { name: "signer", type: "address" },
105526
+ { name: "taker", type: "address" },
105527
+ { name: "tokenId", type: "uint256" },
105528
+ { name: "makerAmount", type: "uint256" },
105529
+ { name: "takerAmount", type: "uint256" },
105530
+ { name: "expiration", type: "uint256" },
105531
+ { name: "nonce", type: "uint256" },
105532
+ { name: "feeRateBps", type: "uint256" },
105533
+ { name: "side", type: "uint8" },
105534
+ { name: "signatureType", type: "uint8" }
105535
+ ]
105536
+ };
105537
+ var LimitlessClient = class {
105538
+ constructor(privateKey) {
105539
+ this.marketCache = {};
105540
+ this.signer = new ethers_1.Wallet(privateKey);
105541
+ this.api = axios_1.default.create({
105542
+ baseURL: LIMITLESS_API_URL,
105543
+ headers: {
105544
+ "Content-Type": "application/json",
105545
+ "Accept": "application/json"
105546
+ }
105547
+ });
105548
+ }
105549
+ async ensureAuth() {
105550
+ if (this.sessionCookie && this.userId)
105551
+ return;
105552
+ const msgRes = await this.api.get("/auth/signing-message");
105553
+ const message = msgRes.data;
105554
+ const hexMessage = ethers_1.utils.hexlify(ethers_1.utils.toUtf8Bytes(message));
105555
+ const signature = await this.signer.signMessage(message);
105556
+ const loginRes = await this.api.post("/auth/login", {
105557
+ client: "eoa"
105558
+ }, {
105559
+ headers: {
105560
+ "x-account": this.signer.address,
105561
+ "x-signing-message": hexMessage,
105562
+ "x-signature": signature
105563
+ }
105564
+ });
105565
+ const setCookie = loginRes.headers["set-cookie"];
105566
+ if (setCookie) {
105567
+ const sessionMatch = setCookie.find((c) => c.startsWith("limitless_session="));
105568
+ if (sessionMatch) {
105569
+ this.sessionCookie = sessionMatch.split(";")[0];
105570
+ }
105571
+ }
105572
+ if (!this.sessionCookie) {
105573
+ throw new Error("Failed to retrieve session cookie from login response");
105574
+ }
105575
+ this.userId = loginRes.data.id;
105576
+ this.userData = loginRes.data;
105577
+ this.api.defaults.headers.common["Cookie"] = this.sessionCookie;
105578
+ }
105579
+ async getMarket(slug) {
105580
+ if (this.marketCache[slug])
105581
+ return this.marketCache[slug];
105582
+ const res = await this.api.get(`/markets/${slug}`);
105583
+ const market = res.data;
105584
+ if (!market)
105585
+ throw new Error(`Market not found: ${slug}`);
105586
+ this.marketCache[slug] = market;
105587
+ return market;
105588
+ }
105589
+ async createOrder(params) {
105590
+ await this.ensureAuth();
105591
+ const market = await this.getMarket(params.marketSlug);
105592
+ const venue = market.venue;
105593
+ if (!venue || !venue.exchange) {
105594
+ throw new Error(`Market ${params.marketSlug} has no venue exchange address`);
105595
+ }
105596
+ const SCALING_FACTOR = 1e6;
105597
+ let makerAmount;
105598
+ let takerAmount;
105599
+ const price = params.price;
105600
+ const amount = params.amount;
105601
+ if (params.side === "BUY") {
105602
+ const totalCost = price * amount;
105603
+ makerAmount = Math.round(totalCost * SCALING_FACTOR);
105604
+ takerAmount = Math.round(amount * SCALING_FACTOR);
105605
+ } else {
105606
+ const totalProceeds = price * amount;
105607
+ makerAmount = Math.round(amount * SCALING_FACTOR);
105608
+ takerAmount = Math.round(totalProceeds * SCALING_FACTOR);
105609
+ }
105610
+ const domain = {
105611
+ name: "Limitless CTF Exchange",
105612
+ version: "1",
105613
+ chainId: BASE_CHAIN_ID,
105614
+ // 8453
105615
+ verifyingContract: venue.exchange
105616
+ };
105617
+ const sideInt = params.side === "BUY" ? 0 : 1;
105618
+ const feeRateBps = this.userData?.rank?.feeRateBps ?? 0;
105619
+ const orderData = {
105620
+ salt: Date.now() + 864e5,
105621
+ // 24h expiry
105622
+ maker: this.signer.address,
105623
+ signer: this.signer.address,
105624
+ taker: "0x0000000000000000000000000000000000000000",
105625
+ tokenId: params.outcomeId,
105626
+ // Keep as string for now if big
105627
+ makerAmount,
105628
+ takerAmount,
105629
+ expiration: "0",
105630
+ nonce: 0,
105631
+ feeRateBps,
105632
+ side: sideInt,
105633
+ signatureType: 0
105634
+ // EOA
105635
+ };
105636
+ const signature = await this.signer._signTypedData(domain, ORDER_TYPES, orderData);
105637
+ const payload = {
105638
+ order: {
105639
+ ...orderData,
105640
+ price: params.price,
105641
+ // Send float as per API
105642
+ signature
105643
+ },
105644
+ ownerId: this.userId,
105645
+ orderType: "GTC",
105646
+ // Force Limit Orders for now
105647
+ marketSlug: params.marketSlug
105648
+ };
105649
+ const res = await this.api.post("/orders", payload);
105650
+ return res.data;
105651
+ }
105652
+ async cancelOrder(orderId) {
105653
+ await this.ensureAuth();
105654
+ const res = await this.api.delete(`/orders/${orderId}`, {
105655
+ data: {}
105656
+ });
105657
+ return res.data;
105658
+ }
105659
+ async cancelAllOrders(marketSlug) {
105660
+ await this.ensureAuth();
105661
+ const res = await this.api.delete(`/orders/all/${marketSlug}`);
105662
+ return res.data;
105663
+ }
105664
+ async getOrders(marketSlug, statuses) {
105665
+ await this.ensureAuth();
105666
+ const params = {};
105667
+ if (statuses && statuses.length > 0) {
105668
+ params.statuses = statuses;
105669
+ }
105670
+ const res = await this.api.get(`/markets/${marketSlug}/user-orders`, { params });
105671
+ return res.data.orders || [];
105672
+ }
105673
+ };
105674
+ exports2.LimitlessClient = LimitlessClient;
105675
+ }
105676
+ });
105677
+
105527
105678
  // dist/exchanges/limitless/websocket.js
105528
105679
  var require_websocket4 = __commonJS({
105529
105680
  "dist/exchanges/limitless/websocket.js"(exports2) {
@@ -105562,7 +105713,7 @@ var require_limitless = __commonJS({
105562
105713
  var fetchTrades_1 = require_fetchTrades2();
105563
105714
  var fetchPositions_1 = require_fetchPositions2();
105564
105715
  var auth_1 = require_auth2();
105565
- var clob_client_1 = (init_dist2(), __toCommonJS(dist_exports));
105716
+ var client_1 = require_client();
105566
105717
  var websocket_1 = require_websocket4();
105567
105718
  var LimitlessExchange = class extends BaseExchange_1.PredictionMarketExchange {
105568
105719
  constructor(options) {
@@ -105580,6 +105731,7 @@ var require_limitless = __commonJS({
105580
105731
  this.wsConfig = wsConfig;
105581
105732
  if (credentials?.privateKey) {
105582
105733
  this.auth = new auth_1.LimitlessAuth(credentials);
105734
+ this.client = new client_1.LimitlessClient(credentials.privateKey);
105583
105735
  }
105584
105736
  }
105585
105737
  get name() {
@@ -105609,6 +105761,12 @@ var require_limitless = __commonJS({
105609
105761
  // ----------------------------------------------------------------------------
105610
105762
  // Trading Methods
105611
105763
  // ----------------------------------------------------------------------------
105764
+ ensureClient() {
105765
+ if (!this.client) {
105766
+ throw new Error('Trading operations require authentication. Initialize LimitlessExchange with credentials: new LimitlessExchange({ privateKey: "0x..." })');
105767
+ }
105768
+ return this.client;
105769
+ }
105612
105770
  /**
105613
105771
  * Ensure authentication is initialized before trading operations.
105614
105772
  */
@@ -105619,44 +105777,29 @@ var require_limitless = __commonJS({
105619
105777
  return this.auth;
105620
105778
  }
105621
105779
  async createOrder(params) {
105622
- const auth = this.ensureAuth();
105623
- const client = await auth.getClobClient();
105624
- const side = params.side.toUpperCase() === "BUY" ? clob_client_1.Side.BUY : clob_client_1.Side.SELL;
105625
- if (params.type === "limit" && !params.price) {
105626
- throw new Error("Price is required for limit orders");
105627
- }
105628
- const price = params.price || (side === clob_client_1.Side.BUY ? 0.99 : 0.01);
105629
- let tickSize;
105630
- if (params.tickSize) {
105631
- tickSize = params.tickSize.toString();
105632
- } else {
105633
- try {
105634
- const orderBook = await this.fetchOrderBook(params.outcomeId);
105635
- tickSize = this.inferTickSize(orderBook);
105636
- } catch (error) {
105637
- tickSize = "0.001";
105638
- }
105639
- }
105780
+ const client = this.ensureClient();
105640
105781
  try {
105641
- const response = await client.createAndPostOrder({
105642
- tokenID: params.outcomeId,
105643
- price,
105782
+ const side = params.side.toUpperCase();
105783
+ const marketSlug = params.marketId;
105784
+ if (!params.price) {
105785
+ throw new Error("Limit orders require a price");
105786
+ }
105787
+ const response = await client.createOrder({
105788
+ marketSlug,
105789
+ outcomeId: params.outcomeId,
105644
105790
  side,
105645
- size: params.amount,
105646
- feeRateBps: 0
105647
- }, {
105648
- tickSize
105791
+ price: params.price,
105792
+ amount: params.amount,
105793
+ type: params.type
105649
105794
  });
105650
- if (!response || !response.success) {
105651
- throw new Error(response?.errorMsg || "Order placement failed");
105652
- }
105653
105795
  return {
105654
- id: response.orderID,
105796
+ id: response.id || "unknown",
105797
+ // Adjust based on actual response
105655
105798
  marketId: params.marketId,
105656
105799
  outcomeId: params.outcomeId,
105657
105800
  side: params.side,
105658
105801
  type: params.type,
105659
- price,
105802
+ price: params.price,
105660
105803
  amount: params.amount,
105661
105804
  status: "open",
105662
105805
  filled: 0,
@@ -105664,46 +105807,14 @@ var require_limitless = __commonJS({
105664
105807
  timestamp: Date.now()
105665
105808
  };
105666
105809
  } catch (error) {
105810
+ console.error("Limitless createOrder failed:", error.response?.data || error.message);
105667
105811
  throw error;
105668
105812
  }
105669
105813
  }
105670
- /**
105671
- * Infer the tick size from order book price levels.
105672
- * Analyzes the decimal precision of existing orders to determine the market's tick size.
105673
- */
105674
- inferTickSize(orderBook) {
105675
- const allPrices = [
105676
- ...orderBook.bids.map((b) => b.price),
105677
- ...orderBook.asks.map((a) => a.price)
105678
- ];
105679
- if (allPrices.length === 0) {
105680
- return "0.001";
105681
- }
105682
- let minIncrement = 1;
105683
- for (const price of allPrices) {
105684
- const priceStr = price.toString();
105685
- const decimalPart = priceStr.split(".")[1];
105686
- if (decimalPart) {
105687
- const decimals = decimalPart.length;
105688
- const increment = Math.pow(10, -decimals);
105689
- if (increment < minIncrement) {
105690
- minIncrement = increment;
105691
- }
105692
- }
105693
- }
105694
- if (minIncrement >= 0.1)
105695
- return "0.1";
105696
- if (minIncrement >= 0.01)
105697
- return "0.01";
105698
- if (minIncrement >= 1e-3)
105699
- return "0.001";
105700
- return "0.0001";
105701
- }
105702
105814
  async cancelOrder(orderId) {
105703
- const auth = this.ensureAuth();
105704
- const client = await auth.getClobClient();
105815
+ const client = this.ensureClient();
105705
105816
  try {
105706
- await client.cancelOrder({ orderID: orderId });
105817
+ await client.cancelOrder(orderId);
105707
105818
  return {
105708
105819
  id: orderId,
105709
105820
  marketId: "unknown",
@@ -105717,51 +105828,36 @@ var require_limitless = __commonJS({
105717
105828
  timestamp: Date.now()
105718
105829
  };
105719
105830
  } catch (error) {
105831
+ console.error("Limitless cancelOrder failed:", error.response?.data || error.message);
105720
105832
  throw error;
105721
105833
  }
105722
105834
  }
105723
105835
  async fetchOrder(orderId) {
105724
- const auth = this.ensureAuth();
105725
- const client = await auth.getClobClient();
105726
- try {
105727
- const order = await client.getOrder(orderId);
105728
- return {
105729
- id: order.id,
105730
- marketId: order.market || "unknown",
105731
- outcomeId: order.asset_id,
105732
- side: order.side.toLowerCase(),
105733
- type: order.order_type === "GTC" ? "limit" : "market",
105734
- price: parseFloat(order.price),
105735
- amount: parseFloat(order.original_size),
105736
- status: order.status,
105737
- // Needs precise mapping
105738
- filled: parseFloat(order.size_matched),
105739
- remaining: parseFloat(order.original_size) - parseFloat(order.size_matched),
105740
- timestamp: order.created_at * 1e3
105741
- };
105742
- } catch (error) {
105743
- throw error;
105744
- }
105836
+ throw new Error("Limitless: fetchOrder(id) is not supported directly. Use fetchOpenOrders(marketSlug).");
105745
105837
  }
105746
105838
  async fetchOpenOrders(marketId) {
105747
- const auth = this.ensureAuth();
105748
- const client = await auth.getClobClient();
105839
+ const client = this.ensureClient();
105749
105840
  try {
105750
- const orders = await client.getOpenOrders({
105751
- market: marketId
105752
- });
105841
+ if (!marketId) {
105842
+ console.warn("Limitless: fetchOpenOrders requires marketId (slug) to be efficient. Returning [].");
105843
+ return [];
105844
+ }
105845
+ const orders = await client.getOrders(marketId, ["LIVE"]);
105753
105846
  return orders.map((o) => ({
105754
105847
  id: o.id,
105755
- marketId: o.market || "unknown",
105756
- outcomeId: o.asset_id,
105848
+ marketId,
105849
+ outcomeId: "unknown",
105850
+ // API might not return this in the simplified list, need to check response
105757
105851
  side: o.side.toLowerCase(),
105758
105852
  type: "limit",
105759
105853
  price: parseFloat(o.price),
105760
- amount: parseFloat(o.original_size),
105854
+ amount: parseFloat(o.quantity),
105761
105855
  status: "open",
105762
- filled: parseFloat(o.size_matched),
105763
- remaining: parseFloat(o.size_left || parseFloat(o.original_size) - parseFloat(o.size_matched)),
105764
- timestamp: o.created_at * 1e3
105856
+ filled: 0,
105857
+ // Need to check if API returns filled amount in this view
105858
+ remaining: parseFloat(o.quantity),
105859
+ timestamp: Date.now()
105860
+ // API doesn't always return TS in summary
105765
105861
  }));
105766
105862
  } catch (error) {
105767
105863
  console.error("Error fetching Limitless open orders:", error.message);
@@ -105779,30 +105875,20 @@ var require_limitless = __commonJS({
105779
105875
  try {
105780
105876
  const USDC_DECIMALS = 6;
105781
105877
  const balRes = await client.getBalanceAllowance({
105782
- asset_type: clob_client_1.AssetType.COLLATERAL
105878
+ asset_type: "COLLATERAL"
105783
105879
  });
105784
105880
  const rawBalance = parseFloat(balRes.balance);
105785
105881
  const total = rawBalance / Math.pow(10, USDC_DECIMALS);
105786
- const openOrders = await client.getOpenOrders({});
105787
- let locked = 0;
105788
- if (openOrders && Array.isArray(openOrders)) {
105789
- for (const order of openOrders) {
105790
- if (order.side === clob_client_1.Side.BUY) {
105791
- const remainingSize = parseFloat(order.original_size) - parseFloat(order.size_matched);
105792
- const price = parseFloat(order.price);
105793
- locked += remainingSize * price;
105794
- }
105795
- }
105796
- }
105797
105882
  return [{
105798
105883
  currency: "USDC",
105799
105884
  total,
105800
- available: total - locked,
105801
- // Available for new trades
105802
- locked
105885
+ available: total,
105886
+ // Approximate
105887
+ locked: 0
105803
105888
  }];
105804
105889
  } catch (error) {
105805
- throw error;
105890
+ console.warn("fetchBalance failed via CLOB client", error.message);
105891
+ return [{ currency: "USDC", total: 0, available: 0, locked: 0 }];
105806
105892
  }
105807
105893
  }
105808
105894
  async watchOrderBook(id, limit) {
@@ -106061,9 +106147,9 @@ var require_searchMarkets3 = __commonJS({
106061
106147
  exports2.searchMarkets = searchMarkets;
106062
106148
  var fetchMarkets_1 = require_fetchMarkets3();
106063
106149
  async function searchMarkets(query, params) {
106064
- const fetchLimit = 1e5;
106150
+ const searchLimit = 5e3;
106065
106151
  try {
106066
- const markets = await (0, fetchMarkets_1.fetchMarkets)({ ...params, limit: fetchLimit });
106152
+ const markets = await (0, fetchMarkets_1.fetchMarkets)({ ...params, limit: searchLimit });
106067
106153
  const lowerQuery = query.toLowerCase();
106068
106154
  const searchIn = params?.searchIn || "title";
106069
106155
  const filtered = markets.filter((market) => {
@@ -106494,10 +106580,12 @@ var require_websocket5 = __commonJS({
106494
106580
  this.orderBookResolvers = /* @__PURE__ */ new Map();
106495
106581
  this.tradeResolvers = /* @__PURE__ */ new Map();
106496
106582
  this.orderBooks = /* @__PURE__ */ new Map();
106497
- this.subscribedTickers = /* @__PURE__ */ new Set();
106583
+ this.subscribedOrderBookTickers = /* @__PURE__ */ new Set();
106584
+ this.subscribedTradeTickers = /* @__PURE__ */ new Set();
106498
106585
  this.messageIdCounter = 1;
106499
106586
  this.isConnecting = false;
106500
106587
  this.isConnected = false;
106588
+ this.isTerminated = false;
106501
106589
  this.auth = auth;
106502
106590
  this.config = {
106503
106591
  wsUrl: config.wsUrl || "wss://api.elections.kalshi.com/trade-api/ws/v2",
@@ -106505,11 +106593,17 @@ var require_websocket5 = __commonJS({
106505
106593
  };
106506
106594
  }
106507
106595
  async connect() {
106508
- if (this.isConnected || this.isConnecting) {
106596
+ if (this.isConnected) {
106597
+ return;
106598
+ }
106599
+ if (this.isTerminated) {
106509
106600
  return;
106510
106601
  }
106602
+ if (this.connectionPromise) {
106603
+ return this.connectionPromise;
106604
+ }
106511
106605
  this.isConnecting = true;
106512
- return new Promise((resolve, reject) => {
106606
+ this.connectionPromise = new Promise((resolve, reject) => {
106513
106607
  try {
106514
106608
  const url2 = new URL(this.config.wsUrl);
106515
106609
  const path = url2.pathname;
@@ -106519,9 +106613,13 @@ var require_websocket5 = __commonJS({
106519
106613
  this.ws.on("open", () => {
106520
106614
  this.isConnected = true;
106521
106615
  this.isConnecting = false;
106616
+ this.connectionPromise = void 0;
106522
106617
  console.log("Kalshi WebSocket connected");
106523
- if (this.subscribedTickers.size > 0) {
106524
- this.subscribeToOrderbook(Array.from(this.subscribedTickers));
106618
+ if (this.subscribedOrderBookTickers.size > 0) {
106619
+ this.subscribeToOrderbook(Array.from(this.subscribedOrderBookTickers));
106620
+ }
106621
+ if (this.subscribedTradeTickers.size > 0) {
106622
+ this.subscribeToTrades(Array.from(this.subscribedTradeTickers));
106525
106623
  }
106526
106624
  resolve();
106527
106625
  });
@@ -106536,21 +106634,30 @@ var require_websocket5 = __commonJS({
106536
106634
  this.ws.on("error", (error) => {
106537
106635
  console.error("Kalshi WebSocket error:", error);
106538
106636
  this.isConnecting = false;
106637
+ this.connectionPromise = void 0;
106539
106638
  reject(error);
106540
106639
  });
106541
106640
  this.ws.on("close", () => {
106542
- console.log("Kalshi WebSocket closed");
106641
+ if (!this.isTerminated) {
106642
+ console.log("Kalshi WebSocket closed");
106643
+ this.scheduleReconnect();
106644
+ }
106543
106645
  this.isConnected = false;
106544
106646
  this.isConnecting = false;
106545
- this.scheduleReconnect();
106647
+ this.connectionPromise = void 0;
106546
106648
  });
106547
106649
  } catch (error) {
106548
106650
  this.isConnecting = false;
106651
+ this.connectionPromise = void 0;
106549
106652
  reject(error);
106550
106653
  }
106551
106654
  });
106655
+ return this.connectionPromise;
106552
106656
  }
106553
106657
  scheduleReconnect() {
106658
+ if (this.isTerminated) {
106659
+ return;
106660
+ }
106554
106661
  if (this.reconnectTimer) {
106555
106662
  clearTimeout(this.reconnectTimer);
106556
106663
  }
@@ -106721,9 +106828,9 @@ var require_websocket5 = __commonJS({
106721
106828
  if (!this.isConnected) {
106722
106829
  await this.connect();
106723
106830
  }
106724
- if (!this.subscribedTickers.has(ticker)) {
106725
- this.subscribedTickers.add(ticker);
106726
- this.subscribeToOrderbook([ticker]);
106831
+ if (!this.subscribedOrderBookTickers.has(ticker)) {
106832
+ this.subscribedOrderBookTickers.add(ticker);
106833
+ this.subscribeToOrderbook(Array.from(this.subscribedOrderBookTickers));
106727
106834
  }
106728
106835
  return new Promise((resolve, reject) => {
106729
106836
  if (!this.orderBookResolvers.has(ticker)) {
@@ -106736,9 +106843,9 @@ var require_websocket5 = __commonJS({
106736
106843
  if (!this.isConnected) {
106737
106844
  await this.connect();
106738
106845
  }
106739
- if (!this.subscribedTickers.has(ticker)) {
106740
- this.subscribedTickers.add(ticker);
106741
- this.subscribeToTrades([ticker]);
106846
+ if (!this.subscribedTradeTickers.has(ticker)) {
106847
+ this.subscribedTradeTickers.add(ticker);
106848
+ this.subscribeToTrades(Array.from(this.subscribedTradeTickers));
106742
106849
  }
106743
106850
  return new Promise((resolve, reject) => {
106744
106851
  if (!this.tradeResolvers.has(ticker)) {
@@ -106748,12 +106855,32 @@ var require_websocket5 = __commonJS({
106748
106855
  });
106749
106856
  }
106750
106857
  async close() {
106858
+ this.isTerminated = true;
106751
106859
  if (this.reconnectTimer) {
106752
106860
  clearTimeout(this.reconnectTimer);
106861
+ this.reconnectTimer = void 0;
106753
106862
  }
106863
+ this.orderBookResolvers.forEach((resolvers, ticker) => {
106864
+ resolvers.forEach((r) => r.reject(new Error(`WebSocket closed for ${ticker}`)));
106865
+ });
106866
+ this.orderBookResolvers.clear();
106867
+ this.tradeResolvers.forEach((resolvers, ticker) => {
106868
+ resolvers.forEach((r) => r.reject(new Error(`WebSocket closed for ${ticker}`)));
106869
+ });
106870
+ this.tradeResolvers.clear();
106754
106871
  if (this.ws) {
106755
- this.ws.close();
106872
+ const ws = this.ws;
106756
106873
  this.ws = void 0;
106874
+ if (ws.readyState !== ws_1.default.CLOSED && ws.readyState !== ws_1.default.CLOSING) {
106875
+ return new Promise((resolve) => {
106876
+ ws.once("close", () => {
106877
+ this.isConnected = false;
106878
+ this.isConnecting = false;
106879
+ resolve();
106880
+ });
106881
+ ws.close();
106882
+ });
106883
+ }
106757
106884
  }
106758
106885
  this.isConnected = false;
106759
106886
  this.isConnecting = false;
@@ -106802,6 +106929,9 @@ var require_kalshi = __commonJS({
106802
106929
  get name() {
106803
106930
  return "Kalshi";
106804
106931
  }
106932
+ getBaseUrl() {
106933
+ return "https://api.elections.kalshi.com";
106934
+ }
106805
106935
  // ----------------------------------------------------------------------------
106806
106936
  // Helpers
106807
106937
  // ----------------------------------------------------------------------------
@@ -106841,7 +106971,7 @@ var require_kalshi = __commonJS({
106841
106971
  async fetchBalance() {
106842
106972
  const auth = this.ensureAuth();
106843
106973
  const path = "/trade-api/v2/portfolio/balance";
106844
- const baseUrl = "https://trading-api.kalshi.com";
106974
+ const baseUrl = this.getBaseUrl();
106845
106975
  const headers = auth.getHeaders("GET", path);
106846
106976
  try {
106847
106977
  const response = await axios_1.default.get(`${baseUrl}${path}`, { headers });
@@ -106869,7 +106999,7 @@ var require_kalshi = __commonJS({
106869
106999
  async createOrder(params) {
106870
107000
  const auth = this.ensureAuth();
106871
107001
  const path = "/trade-api/v2/portfolio/orders";
106872
- const baseUrl = "https://trading-api.kalshi.com";
107002
+ const baseUrl = this.getBaseUrl();
106873
107003
  const headers = auth.getHeaders("POST", path);
106874
107004
  const isYesSide = params.side === "buy";
106875
107005
  const kalshiOrder = {
@@ -106907,13 +107037,13 @@ var require_kalshi = __commonJS({
106907
107037
  timestamp: new Date(order.created_time).getTime()
106908
107038
  };
106909
107039
  } catch (error) {
106910
- throw error;
107040
+ throw new Error(`${error.response?.data?.error?.message || error.message} (Status: ${error.response?.status} - ${JSON.stringify(error.response?.data || {})})`);
106911
107041
  }
106912
107042
  }
106913
107043
  async cancelOrder(orderId) {
106914
107044
  const auth = this.ensureAuth();
106915
107045
  const path = `/trade-api/v2/portfolio/orders/${orderId}`;
106916
- const baseUrl = "https://trading-api.kalshi.com";
107046
+ const baseUrl = this.getBaseUrl();
106917
107047
  const headers = auth.getHeaders("DELETE", path);
106918
107048
  try {
106919
107049
  const response = await axios_1.default.delete(`${baseUrl}${path}`, { headers });
@@ -106937,7 +107067,7 @@ var require_kalshi = __commonJS({
106937
107067
  async fetchOrder(orderId) {
106938
107068
  const auth = this.ensureAuth();
106939
107069
  const path = `/trade-api/v2/portfolio/orders/${orderId}`;
106940
- const baseUrl = "https://trading-api.kalshi.com";
107070
+ const baseUrl = this.getBaseUrl();
106941
107071
  const headers = auth.getHeaders("GET", path);
106942
107072
  try {
106943
107073
  const response = await axios_1.default.get(`${baseUrl}${path}`, { headers });
@@ -106966,7 +107096,7 @@ var require_kalshi = __commonJS({
106966
107096
  if (marketId) {
106967
107097
  queryParams += `&ticker=${marketId}`;
106968
107098
  }
106969
- const baseUrl = "https://trading-api.kalshi.com";
107099
+ const baseUrl = this.getBaseUrl();
106970
107100
  const headers = auth.getHeaders("GET", basePath);
106971
107101
  try {
106972
107102
  const response = await axios_1.default.get(`${baseUrl}${basePath}${queryParams}`, { headers });
@@ -106991,7 +107121,7 @@ var require_kalshi = __commonJS({
106991
107121
  async fetchPositions() {
106992
107122
  const auth = this.ensureAuth();
106993
107123
  const path = "/trade-api/v2/portfolio/positions";
106994
- const baseUrl = "https://trading-api.kalshi.com";
107124
+ const baseUrl = this.getBaseUrl();
106995
107125
  const headers = auth.getHeaders("GET", path);
106996
107126
  try {
106997
107127
  const response = await axios_1.default.get(`${baseUrl}${path}`, { headers });
@@ -107036,14 +107166,16 @@ var require_kalshi = __commonJS({
107036
107166
  if (!this.ws) {
107037
107167
  this.ws = new websocket_1.KalshiWebSocket(auth, this.wsConfig);
107038
107168
  }
107039
- return this.ws.watchOrderBook(id);
107169
+ const marketTicker = id.replace(/-NO$/, "");
107170
+ return this.ws.watchOrderBook(marketTicker);
107040
107171
  }
107041
107172
  async watchTrades(id, since, limit) {
107042
107173
  const auth = this.ensureAuth();
107043
107174
  if (!this.ws) {
107044
107175
  this.ws = new websocket_1.KalshiWebSocket(auth, this.wsConfig);
107045
107176
  }
107046
- return this.ws.watchTrades(id);
107177
+ const marketTicker = id.replace(/-NO$/, "");
107178
+ return this.ws.watchTrades(marketTicker);
107047
107179
  }
107048
107180
  async close() {
107049
107181
  if (this.ws) {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pmxt
3
- Version: 1.5.2
3
+ Version: 1.5.5
4
4
  Summary: Unified prediction market data API - The ccxt for prediction markets
5
5
  Author: PMXT Contributors
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pmxt"
7
- version = "1.5.2"
7
+ version = "1.5.5"
8
8
  description = "Unified prediction market data API - The ccxt for prediction markets"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes