pmxt 1.7.0__py3-none-any.whl → 2.0.0b0__py3-none-any.whl

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.
@@ -38544,6 +38544,302 @@ var require_utils4 = __commonJS({
38544
38544
  }
38545
38545
  });
38546
38546
 
38547
+ // dist/errors.js
38548
+ var require_errors = __commonJS({
38549
+ "dist/errors.js"(exports2) {
38550
+ "use strict";
38551
+ Object.defineProperty(exports2, "__esModule", { value: true });
38552
+ exports2.ExchangeNotAvailable = exports2.NetworkError = exports2.ValidationError = exports2.InsufficientFunds = exports2.InvalidOrder = exports2.RateLimitExceeded = exports2.MarketNotFound = exports2.OrderNotFound = exports2.NotFound = exports2.PermissionDenied = exports2.AuthenticationError = exports2.BadRequest = exports2.BaseError = void 0;
38553
+ var BaseError2 = class extends Error {
38554
+ constructor(message, status, code, retryable = false, exchange) {
38555
+ super(message);
38556
+ this.name = this.constructor.name;
38557
+ this.status = status;
38558
+ this.code = code;
38559
+ this.retryable = retryable;
38560
+ this.exchange = exchange;
38561
+ if (Error.captureStackTrace) {
38562
+ Error.captureStackTrace(this, this.constructor);
38563
+ }
38564
+ }
38565
+ };
38566
+ exports2.BaseError = BaseError2;
38567
+ var BadRequest = class extends BaseError2 {
38568
+ constructor(message, exchange) {
38569
+ super(message, 400, "BAD_REQUEST", false, exchange);
38570
+ }
38571
+ };
38572
+ exports2.BadRequest = BadRequest;
38573
+ var AuthenticationError = class extends BaseError2 {
38574
+ constructor(message, exchange) {
38575
+ super(message, 401, "AUTHENTICATION_ERROR", false, exchange);
38576
+ }
38577
+ };
38578
+ exports2.AuthenticationError = AuthenticationError;
38579
+ var PermissionDenied = class extends BaseError2 {
38580
+ constructor(message, exchange) {
38581
+ super(message, 403, "PERMISSION_DENIED", false, exchange);
38582
+ }
38583
+ };
38584
+ exports2.PermissionDenied = PermissionDenied;
38585
+ var NotFound = class extends BaseError2 {
38586
+ constructor(message, exchange) {
38587
+ super(message, 404, "NOT_FOUND", false, exchange);
38588
+ }
38589
+ };
38590
+ exports2.NotFound = NotFound;
38591
+ var OrderNotFound = class extends BaseError2 {
38592
+ constructor(orderId, exchange) {
38593
+ super(`Order not found: ${orderId}`, 404, "ORDER_NOT_FOUND", false, exchange);
38594
+ }
38595
+ };
38596
+ exports2.OrderNotFound = OrderNotFound;
38597
+ var MarketNotFound = class extends BaseError2 {
38598
+ constructor(marketId, exchange) {
38599
+ super(`Market not found: ${marketId}`, 404, "MARKET_NOT_FOUND", false, exchange);
38600
+ }
38601
+ };
38602
+ exports2.MarketNotFound = MarketNotFound;
38603
+ var RateLimitExceeded = class extends BaseError2 {
38604
+ constructor(message, retryAfter, exchange) {
38605
+ super(message, 429, "RATE_LIMIT_EXCEEDED", true, exchange);
38606
+ this.retryAfter = retryAfter;
38607
+ }
38608
+ };
38609
+ exports2.RateLimitExceeded = RateLimitExceeded;
38610
+ var InvalidOrder = class extends BaseError2 {
38611
+ constructor(message, exchange) {
38612
+ super(message, 400, "INVALID_ORDER", false, exchange);
38613
+ }
38614
+ };
38615
+ exports2.InvalidOrder = InvalidOrder;
38616
+ var InsufficientFunds = class extends BaseError2 {
38617
+ constructor(message, exchange) {
38618
+ super(message, 400, "INSUFFICIENT_FUNDS", false, exchange);
38619
+ }
38620
+ };
38621
+ exports2.InsufficientFunds = InsufficientFunds;
38622
+ var ValidationError = class extends BaseError2 {
38623
+ constructor(message, field, exchange) {
38624
+ super(message, 400, "VALIDATION_ERROR", false, exchange);
38625
+ this.field = field;
38626
+ }
38627
+ };
38628
+ exports2.ValidationError = ValidationError;
38629
+ var NetworkError = class extends BaseError2 {
38630
+ constructor(message, exchange) {
38631
+ super(message, 503, "NETWORK_ERROR", true, exchange);
38632
+ }
38633
+ };
38634
+ exports2.NetworkError = NetworkError;
38635
+ var ExchangeNotAvailable = class extends BaseError2 {
38636
+ constructor(message, exchange) {
38637
+ super(message, 503, "EXCHANGE_NOT_AVAILABLE", true, exchange);
38638
+ }
38639
+ };
38640
+ exports2.ExchangeNotAvailable = ExchangeNotAvailable;
38641
+ }
38642
+ });
38643
+
38644
+ // dist/utils/error-mapper.js
38645
+ var require_error_mapper = __commonJS({
38646
+ "dist/utils/error-mapper.js"(exports2) {
38647
+ "use strict";
38648
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
38649
+ return mod && mod.__esModule ? mod : { "default": mod };
38650
+ };
38651
+ Object.defineProperty(exports2, "__esModule", { value: true });
38652
+ exports2.ErrorMapper = void 0;
38653
+ var axios_1 = __importDefault(require_axios());
38654
+ var errors_1 = require_errors();
38655
+ var ErrorMapper = class {
38656
+ constructor(exchangeName) {
38657
+ this.exchangeName = exchangeName;
38658
+ }
38659
+ /**
38660
+ * Main entry point for error mapping
38661
+ */
38662
+ mapError(error) {
38663
+ if (error instanceof errors_1.BaseError) {
38664
+ if (!error.exchange && this.exchangeName) {
38665
+ return new error.constructor(error.message, this.exchangeName);
38666
+ }
38667
+ return error;
38668
+ }
38669
+ if (axios_1.default.isAxiosError(error)) {
38670
+ return this.mapAxiosError(error);
38671
+ }
38672
+ if (error.code === "ECONNREFUSED" || error.code === "ENOTFOUND" || error.code === "ETIMEDOUT") {
38673
+ return new errors_1.NetworkError(`Network error: ${error.message}`, this.exchangeName);
38674
+ }
38675
+ const message = this.extractErrorMessage(error);
38676
+ return new errors_1.BadRequest(message, this.exchangeName);
38677
+ }
38678
+ /**
38679
+ * Maps axios HTTP errors to appropriate error classes
38680
+ */
38681
+ mapAxiosError(error) {
38682
+ const status = error.response?.status;
38683
+ const message = this.extractErrorMessage(error);
38684
+ const data = error.response?.data;
38685
+ if (!status) {
38686
+ if (error.code === "ECONNABORTED" || error.code === "ETIMEDOUT") {
38687
+ return new errors_1.NetworkError(`Request timeout: ${message}`, this.exchangeName);
38688
+ }
38689
+ return new errors_1.ExchangeNotAvailable(`Exchange unreachable: ${message}`, this.exchangeName);
38690
+ }
38691
+ switch (status) {
38692
+ case 400:
38693
+ return this.mapBadRequestError(message, data);
38694
+ case 401:
38695
+ return new errors_1.AuthenticationError(message, this.exchangeName);
38696
+ case 403:
38697
+ return new errors_1.PermissionDenied(message, this.exchangeName);
38698
+ case 404:
38699
+ return this.mapNotFoundError(message, data);
38700
+ case 429:
38701
+ return this.mapRateLimitError(message, error.response);
38702
+ case 500:
38703
+ case 502:
38704
+ case 503:
38705
+ case 504:
38706
+ return new errors_1.ExchangeNotAvailable(`Exchange error (${status}): ${message}`, this.exchangeName);
38707
+ default:
38708
+ return new errors_1.BadRequest(`HTTP ${status}: ${message}`, this.exchangeName);
38709
+ }
38710
+ }
38711
+ /**
38712
+ * Maps 400 errors to specific bad request subtypes
38713
+ */
38714
+ mapBadRequestError(message, data) {
38715
+ const lowerMessage = message.toLowerCase();
38716
+ if (lowerMessage.includes("insufficient") || lowerMessage.includes("balance") || lowerMessage.includes("not enough")) {
38717
+ return new errors_1.InsufficientFunds(message, this.exchangeName);
38718
+ }
38719
+ if (lowerMessage.includes("invalid order") || lowerMessage.includes("tick size") || lowerMessage.includes("price must be") || lowerMessage.includes("size must be") || lowerMessage.includes("amount must be")) {
38720
+ return new errors_1.InvalidOrder(message, this.exchangeName);
38721
+ }
38722
+ if (lowerMessage.includes("validation") || lowerMessage.includes("invalid parameter")) {
38723
+ return new errors_1.ValidationError(message, void 0, this.exchangeName);
38724
+ }
38725
+ return new errors_1.BadRequest(message, this.exchangeName);
38726
+ }
38727
+ /**
38728
+ * Maps 404 errors to specific not found subtypes
38729
+ */
38730
+ mapNotFoundError(message, data) {
38731
+ const lowerMessage = message.toLowerCase();
38732
+ if (lowerMessage.includes("order")) {
38733
+ const orderIdMatch = message.match(/order[:\s]+([a-zA-Z0-9-]+)/i);
38734
+ const orderId = orderIdMatch ? orderIdMatch[1] : "unknown";
38735
+ return new errors_1.OrderNotFound(orderId, this.exchangeName);
38736
+ }
38737
+ if (lowerMessage.includes("market")) {
38738
+ const marketIdMatch = message.match(/market[:\s]+([a-zA-Z0-9-]+)/i);
38739
+ const marketId = marketIdMatch ? marketIdMatch[1] : "unknown";
38740
+ return new errors_1.MarketNotFound(marketId, this.exchangeName);
38741
+ }
38742
+ return new errors_1.NotFound(message, this.exchangeName);
38743
+ }
38744
+ /**
38745
+ * Maps rate limit errors
38746
+ */
38747
+ mapRateLimitError(message, response) {
38748
+ const retryAfter = response?.headers?.["retry-after"];
38749
+ const retryAfterSeconds = retryAfter ? parseInt(retryAfter, 10) : void 0;
38750
+ return new errors_1.RateLimitExceeded(message, retryAfterSeconds, this.exchangeName);
38751
+ }
38752
+ /**
38753
+ * Extracts error message from various error formats
38754
+ */
38755
+ extractErrorMessage(error) {
38756
+ if (axios_1.default.isAxiosError(error) && error.response?.data) {
38757
+ const data = error.response.data;
38758
+ if (typeof data === "string") {
38759
+ return data;
38760
+ }
38761
+ if (data.error) {
38762
+ if (typeof data.error === "string") {
38763
+ return data.error;
38764
+ }
38765
+ if (data.error.message) {
38766
+ return data.error.message;
38767
+ }
38768
+ }
38769
+ if (data.message) {
38770
+ return data.message;
38771
+ }
38772
+ if (data.errorMsg) {
38773
+ return data.errorMsg;
38774
+ }
38775
+ return JSON.stringify(data);
38776
+ }
38777
+ if (error instanceof Error) {
38778
+ return error.message;
38779
+ }
38780
+ if (typeof error === "string") {
38781
+ return error;
38782
+ }
38783
+ return String(error);
38784
+ }
38785
+ };
38786
+ exports2.ErrorMapper = ErrorMapper;
38787
+ }
38788
+ });
38789
+
38790
+ // dist/exchanges/polymarket/errors.js
38791
+ var require_errors2 = __commonJS({
38792
+ "dist/exchanges/polymarket/errors.js"(exports2) {
38793
+ "use strict";
38794
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
38795
+ return mod && mod.__esModule ? mod : { "default": mod };
38796
+ };
38797
+ Object.defineProperty(exports2, "__esModule", { value: true });
38798
+ exports2.polymarketErrorMapper = exports2.PolymarketErrorMapper = void 0;
38799
+ var axios_1 = __importDefault(require_axios());
38800
+ var error_mapper_1 = require_error_mapper();
38801
+ var errors_1 = require_errors();
38802
+ var PolymarketErrorMapper = class extends error_mapper_1.ErrorMapper {
38803
+ constructor() {
38804
+ super("Polymarket");
38805
+ }
38806
+ /**
38807
+ * Override to handle Polymarket-specific error patterns
38808
+ */
38809
+ extractErrorMessage(error) {
38810
+ if (axios_1.default.isAxiosError(error) && error.response?.data) {
38811
+ const data = error.response.data;
38812
+ if (data.errorMsg) {
38813
+ return data.errorMsg;
38814
+ }
38815
+ if (data.error?.message) {
38816
+ return data.error.message;
38817
+ }
38818
+ if (data.message) {
38819
+ return data.message;
38820
+ }
38821
+ }
38822
+ return super.extractErrorMessage(error);
38823
+ }
38824
+ /**
38825
+ * Override to detect Polymarket-specific error patterns
38826
+ */
38827
+ mapBadRequestError(message, data) {
38828
+ const lowerMessage = message.toLowerCase();
38829
+ if (lowerMessage.includes("api key") || lowerMessage.includes("proxy") || lowerMessage.includes("signature type")) {
38830
+ return new errors_1.AuthenticationError(message, this.exchangeName);
38831
+ }
38832
+ if (lowerMessage.includes("tick size")) {
38833
+ return new errors_1.InvalidOrder(message, this.exchangeName);
38834
+ }
38835
+ return super.mapBadRequestError(message, data);
38836
+ }
38837
+ };
38838
+ exports2.PolymarketErrorMapper = PolymarketErrorMapper;
38839
+ exports2.polymarketErrorMapper = new PolymarketErrorMapper();
38840
+ }
38841
+ });
38842
+
38547
38843
  // dist/exchanges/polymarket/fetchMarkets.js
38548
38844
  var require_fetchMarkets = __commonJS({
38549
38845
  "dist/exchanges/polymarket/fetchMarkets.js"(exports2) {
@@ -38555,6 +38851,7 @@ var require_fetchMarkets = __commonJS({
38555
38851
  exports2.fetchMarkets = fetchMarkets;
38556
38852
  var axios_1 = __importDefault(require_axios());
38557
38853
  var utils_1 = require_utils4();
38854
+ var errors_1 = require_errors2();
38558
38855
  async function fetchMarkets(params) {
38559
38856
  const limit = params?.limit || 200;
38560
38857
  const offset = params?.offset || 0;
@@ -38599,8 +38896,7 @@ var require_fetchMarkets = __commonJS({
38599
38896
  }
38600
38897
  return unifiedMarkets.slice(0, limit);
38601
38898
  } catch (error) {
38602
- console.error("Error fetching Polymarket data:", error);
38603
- return [];
38899
+ throw errors_1.polymarketErrorMapper.mapError(error);
38604
38900
  }
38605
38901
  }
38606
38902
  }
@@ -38613,6 +38909,7 @@ var require_searchMarkets = __commonJS({
38613
38909
  Object.defineProperty(exports2, "__esModule", { value: true });
38614
38910
  exports2.searchMarkets = searchMarkets;
38615
38911
  var fetchMarkets_1 = require_fetchMarkets();
38912
+ var errors_1 = require_errors2();
38616
38913
  async function searchMarkets(query, params) {
38617
38914
  const searchLimit = 5e3;
38618
38915
  try {
@@ -38634,8 +38931,7 @@ var require_searchMarkets = __commonJS({
38634
38931
  const limit = params?.limit || 20;
38635
38932
  return filtered.slice(0, limit);
38636
38933
  } catch (error) {
38637
- console.error("Error searching Polymarket data:", error);
38638
- return [];
38934
+ throw errors_1.polymarketErrorMapper.mapError(error);
38639
38935
  }
38640
38936
  }
38641
38937
  }
@@ -38722,6 +39018,7 @@ var require_getMarketsBySlug = __commonJS({
38722
39018
  exports2.getMarketsBySlug = getMarketsBySlug;
38723
39019
  var axios_1 = __importDefault(require_axios());
38724
39020
  var utils_1 = require_utils4();
39021
+ var errors_1 = require_errors2();
38725
39022
  async function getMarketsBySlug(slug) {
38726
39023
  try {
38727
39024
  const response = await axios_1.default.get(utils_1.GAMMA_API_URL, {
@@ -38743,8 +39040,7 @@ var require_getMarketsBySlug = __commonJS({
38743
39040
  }
38744
39041
  return unifiedMarkets;
38745
39042
  } catch (error) {
38746
- console.error(`Error fetching Polymarket slug ${slug}:`, error);
38747
- return [];
39043
+ throw errors_1.polymarketErrorMapper.mapError(error);
38748
39044
  }
38749
39045
  }
38750
39046
  }
@@ -38757,14 +39053,15 @@ var require_validation = __commonJS({
38757
39053
  Object.defineProperty(exports2, "__esModule", { value: true });
38758
39054
  exports2.validateOutcomeId = validateOutcomeId;
38759
39055
  exports2.validateIdFormat = validateIdFormat;
39056
+ var errors_1 = require_errors();
38760
39057
  function validateOutcomeId(id, context) {
38761
39058
  if (id.length < 10 && /^\d+$/.test(id)) {
38762
- throw new Error(`Invalid ID for ${context}: "${id}". This appears to be a market ID (deprecated: market.id, use: market.marketId). Please use outcome ID (preferred: outcome.outcomeId, deprecated: outcome.id).`);
39059
+ throw new errors_1.ValidationError(`Invalid ID for ${context}: "${id}". This appears to be a market ID (deprecated: market.id, use: market.marketId). Please use outcome ID (preferred: outcome.outcomeId, deprecated: outcome.id).`, "id");
38763
39060
  }
38764
39061
  }
38765
39062
  function validateIdFormat(id, context) {
38766
39063
  if (!id || id.trim().length === 0) {
38767
- throw new Error(`Invalid ID for ${context}: ID cannot be empty`);
39064
+ throw new errors_1.ValidationError(`Invalid ID for ${context}: ID cannot be empty`, "id");
38768
39065
  }
38769
39066
  }
38770
39067
  }
@@ -38782,6 +39079,7 @@ var require_fetchOHLCV = __commonJS({
38782
39079
  var axios_1 = __importDefault(require_axios());
38783
39080
  var utils_1 = require_utils4();
38784
39081
  var validation_1 = require_validation();
39082
+ var errors_1 = require_errors2();
38785
39083
  async function fetchOHLCV(id, params) {
38786
39084
  (0, validation_1.validateIdFormat)(id, "OHLCV");
38787
39085
  (0, validation_1.validateOutcomeId)(id, "OHLCV");
@@ -38846,12 +39144,7 @@ var require_fetchOHLCV = __commonJS({
38846
39144
  }
38847
39145
  return candles;
38848
39146
  } catch (error) {
38849
- if (axios_1.default.isAxiosError(error) && error.response) {
38850
- const apiError = error.response.data?.error || error.response.data?.message || "Unknown API Error";
38851
- throw new Error(`Polymarket History API Error (${error.response.status}): ${apiError}. Used ID: ${id}`);
38852
- }
38853
- console.error(`Unexpected error fetching Polymarket history for ${id}:`, error);
38854
- throw error;
39147
+ throw errors_1.polymarketErrorMapper.mapError(error);
38855
39148
  }
38856
39149
  }
38857
39150
  }
@@ -38869,6 +39162,7 @@ var require_fetchOrderBook = __commonJS({
38869
39162
  var axios_1 = __importDefault(require_axios());
38870
39163
  var utils_1 = require_utils4();
38871
39164
  var validation_1 = require_validation();
39165
+ var errors_1 = require_errors2();
38872
39166
  async function fetchOrderBook(id) {
38873
39167
  (0, validation_1.validateIdFormat)(id, "OrderBook");
38874
39168
  (0, validation_1.validateOutcomeId)(id, "OrderBook");
@@ -38891,8 +39185,7 @@ var require_fetchOrderBook = __commonJS({
38891
39185
  timestamp: data.timestamp ? new Date(data.timestamp).getTime() : Date.now()
38892
39186
  };
38893
39187
  } catch (error) {
38894
- console.error(`Error fetching Polymarket orderbook for ${id}:`, error);
38895
- return { bids: [], asks: [] };
39188
+ throw errors_1.polymarketErrorMapper.mapError(error);
38896
39189
  }
38897
39190
  }
38898
39191
  }
@@ -38910,6 +39203,7 @@ var require_fetchTrades = __commonJS({
38910
39203
  var axios_1 = __importDefault(require_axios());
38911
39204
  var utils_1 = require_utils4();
38912
39205
  var validation_1 = require_validation();
39206
+ var errors_1 = require_errors2();
38913
39207
  async function fetchTrades(id, params) {
38914
39208
  (0, validation_1.validateIdFormat)(id, "Trades");
38915
39209
  (0, validation_1.validateOutcomeId)(id, "Trades");
@@ -38941,13 +39235,7 @@ var require_fetchTrades = __commonJS({
38941
39235
  }
38942
39236
  return mappedTrades;
38943
39237
  } catch (error) {
38944
- if (axios_1.default.isAxiosError(error)) {
38945
- const apiError = error.response?.data?.error || error.response?.data?.message || error.message;
38946
- console.error(`[Polymarket] fetchTrades failed for ID ${id}: ${apiError}`);
38947
- throw new Error(`Polymarket Trades API Error: ${apiError}`);
38948
- }
38949
- console.error(`Unexpected error fetching Polymarket trades for ${id}:`, error);
38950
- throw error;
39238
+ throw errors_1.polymarketErrorMapper.mapError(error);
38951
39239
  }
38952
39240
  }
38953
39241
  }
@@ -83544,6 +83832,7 @@ var require_auth = __commonJS({
83544
83832
  var clob_client_1 = (init_dist2(), __toCommonJS(dist_exports));
83545
83833
  var ethers_1 = require_lib36();
83546
83834
  var axios_1 = __importDefault(require_axios());
83835
+ var errors_1 = require_errors2();
83547
83836
  var POLYMARKET_HOST = "https://clob.polymarket.com";
83548
83837
  var POLYGON_CHAIN_ID = 137;
83549
83838
  var PolymarketAuth = class {
@@ -83584,9 +83873,7 @@ var require_auth = __commonJS({
83584
83873
  creds = await l1Client.createApiKey();
83585
83874
  console.log("[PolymarketAuth] createApiKey returned:", JSON.stringify(creds, null, 2));
83586
83875
  } catch (createError) {
83587
- const apiError = createError?.response?.data?.error || createError?.message || createError;
83588
- console.error("[PolymarketAuth] Failed to both derive and create API key. Create error:", apiError);
83589
- throw new Error(`Authentication failed: Could not create or derive API key. Latest error: ${apiError}`);
83876
+ throw errors_1.polymarketErrorMapper.mapError(createError);
83590
83877
  }
83591
83878
  }
83592
83879
  if (!creds || !creds.key || !creds.secret || !creds.passphrase) {
@@ -89039,7 +89326,7 @@ var require_align = __commonJS({
89039
89326
  });
89040
89327
 
89041
89328
  // ../node_modules/logform/errors.js
89042
- var require_errors = __commonJS({
89329
+ var require_errors3 = __commonJS({
89043
89330
  "../node_modules/logform/errors.js"(exports2, module2) {
89044
89331
  "use strict";
89045
89332
  var format = require_format();
@@ -90551,7 +90838,7 @@ var require_logform = __commonJS({
90551
90838
  return require_align();
90552
90839
  });
90553
90840
  exposeFormat("errors", function() {
90554
- return require_errors();
90841
+ return require_errors3();
90555
90842
  });
90556
90843
  exposeFormat("cli", function() {
90557
90844
  return require_cli2();
@@ -90822,7 +91109,7 @@ var require_destroy = __commonJS({
90822
91109
  });
90823
91110
 
90824
91111
  // ../node_modules/readable-stream/errors.js
90825
- var require_errors2 = __commonJS({
91112
+ var require_errors4 = __commonJS({
90826
91113
  "../node_modules/readable-stream/errors.js"(exports2, module2) {
90827
91114
  "use strict";
90828
91115
  var codes = {};
@@ -90925,7 +91212,7 @@ var require_errors2 = __commonJS({
90925
91212
  var require_state2 = __commonJS({
90926
91213
  "../node_modules/readable-stream/lib/internal/streams/state.js"(exports2, module2) {
90927
91214
  "use strict";
90928
- var ERR_INVALID_OPT_VALUE = require_errors2().codes.ERR_INVALID_OPT_VALUE;
91215
+ var ERR_INVALID_OPT_VALUE = require_errors4().codes.ERR_INVALID_OPT_VALUE;
90929
91216
  function highWaterMarkFrom(options, isDuplex, duplexKey) {
90930
91217
  return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
90931
91218
  }
@@ -91488,7 +91775,7 @@ var require_string_decoder = __commonJS({
91488
91775
  var require_end_of_stream = __commonJS({
91489
91776
  "../node_modules/readable-stream/lib/internal/streams/end-of-stream.js"(exports2, module2) {
91490
91777
  "use strict";
91491
- var ERR_STREAM_PREMATURE_CLOSE = require_errors2().codes.ERR_STREAM_PREMATURE_CLOSE;
91778
+ var ERR_STREAM_PREMATURE_CLOSE = require_errors4().codes.ERR_STREAM_PREMATURE_CLOSE;
91492
91779
  function once(callback) {
91493
91780
  var called = false;
91494
91781
  return function() {
@@ -91833,7 +92120,7 @@ var require_from = __commonJS({
91833
92120
  }
91834
92121
  return (hint === "string" ? String : Number)(input);
91835
92122
  }
91836
- var ERR_INVALID_ARG_TYPE = require_errors2().codes.ERR_INVALID_ARG_TYPE;
92123
+ var ERR_INVALID_ARG_TYPE = require_errors4().codes.ERR_INVALID_ARG_TYPE;
91837
92124
  function from(Readable2, iterable, opts) {
91838
92125
  var iterator2;
91839
92126
  if (iterable && typeof iterable.next === "function") {
@@ -91910,7 +92197,7 @@ var require_stream_readable = __commonJS({
91910
92197
  var destroyImpl = require_destroy();
91911
92198
  var _require = require_state2();
91912
92199
  var getHighWaterMark = _require.getHighWaterMark;
91913
- var _require$codes = require_errors2().codes;
92200
+ var _require$codes = require_errors4().codes;
91914
92201
  var ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE;
91915
92202
  var ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF;
91916
92203
  var ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED;
@@ -92734,7 +93021,7 @@ var require_stream_writable = __commonJS({
92734
93021
  var destroyImpl = require_destroy();
92735
93022
  var _require = require_state2();
92736
93023
  var getHighWaterMark = _require.getHighWaterMark;
92737
- var _require$codes = require_errors2().codes;
93024
+ var _require$codes = require_errors4().codes;
92738
93025
  var ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE;
92739
93026
  var ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED;
92740
93027
  var ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK;
@@ -94007,7 +94294,7 @@ var require_stream_transform = __commonJS({
94007
94294
  "../node_modules/readable-stream/lib/_stream_transform.js"(exports2, module2) {
94008
94295
  "use strict";
94009
94296
  module2.exports = Transform;
94010
- var _require$codes = require_errors2().codes;
94297
+ var _require$codes = require_errors4().codes;
94011
94298
  var ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED;
94012
94299
  var ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK;
94013
94300
  var ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING;
@@ -94133,7 +94420,7 @@ var require_pipeline = __commonJS({
94133
94420
  callback.apply(void 0, arguments);
94134
94421
  };
94135
94422
  }
94136
- var _require$codes = require_errors2().codes;
94423
+ var _require$codes = require_errors4().codes;
94137
94424
  var ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS;
94138
94425
  var ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
94139
94426
  function noop2(err) {
@@ -105236,6 +105523,8 @@ var require_polymarket = __commonJS({
105236
105523
  var auth_1 = require_auth();
105237
105524
  var clob_client_1 = (init_dist2(), __toCommonJS(dist_exports));
105238
105525
  var websocket_1 = require_websocket3();
105526
+ var errors_1 = require_errors2();
105527
+ var errors_2 = require_errors();
105239
105528
  var PolymarketExchange = class extends BaseExchange_1.PredictionMarketExchange {
105240
105529
  constructor(options) {
105241
105530
  let credentials;
@@ -105287,30 +105576,30 @@ var require_polymarket = __commonJS({
105287
105576
  */
105288
105577
  ensureAuth() {
105289
105578
  if (!this.auth) {
105290
- throw new Error('Trading operations require authentication. Initialize PolymarketExchange with credentials: new PolymarketExchange({ privateKey: "0x..." })');
105579
+ throw new errors_2.AuthenticationError('Trading operations require authentication. Initialize PolymarketExchange with credentials: new PolymarketExchange({ privateKey: "0x..." })', "Polymarket");
105291
105580
  }
105292
105581
  return this.auth;
105293
105582
  }
105294
105583
  async createOrder(params) {
105295
- const auth = this.ensureAuth();
105296
- const client = await auth.getClobClient();
105297
- const side = params.side.toUpperCase() === "BUY" ? clob_client_1.Side.BUY : clob_client_1.Side.SELL;
105298
- if (params.type === "limit" && !params.price) {
105299
- throw new Error("Price is required for limit orders");
105300
- }
105301
- const price = params.price || (side === clob_client_1.Side.BUY ? 0.99 : 0.01);
105302
- let tickSize;
105303
- if (params.tickSize) {
105304
- tickSize = params.tickSize.toString();
105305
- } else {
105306
- try {
105307
- const orderBook = await this.fetchOrderBook(params.outcomeId);
105308
- tickSize = this.inferTickSize(orderBook);
105309
- } catch (error) {
105310
- tickSize = "0.01";
105311
- }
105312
- }
105313
105584
  try {
105585
+ const auth = this.ensureAuth();
105586
+ const client = await auth.getClobClient();
105587
+ const side = params.side.toUpperCase() === "BUY" ? clob_client_1.Side.BUY : clob_client_1.Side.SELL;
105588
+ if (params.type === "limit" && !params.price) {
105589
+ throw new Error("Price is required for limit orders");
105590
+ }
105591
+ const price = params.price || (side === clob_client_1.Side.BUY ? 0.99 : 0.01);
105592
+ let tickSize;
105593
+ if (params.tickSize) {
105594
+ tickSize = params.tickSize.toString();
105595
+ } else {
105596
+ try {
105597
+ const orderBook = await this.fetchOrderBook(params.outcomeId);
105598
+ tickSize = this.inferTickSize(orderBook);
105599
+ } catch (error) {
105600
+ tickSize = "0.01";
105601
+ }
105602
+ }
105314
105603
  const orderArgs = {
105315
105604
  tokenID: params.outcomeId,
105316
105605
  price,
@@ -105341,7 +105630,7 @@ var require_polymarket = __commonJS({
105341
105630
  timestamp: Date.now()
105342
105631
  };
105343
105632
  } catch (error) {
105344
- throw error;
105633
+ throw errors_1.polymarketErrorMapper.mapError(error);
105345
105634
  }
105346
105635
  }
105347
105636
  /**
@@ -105377,9 +105666,9 @@ var require_polymarket = __commonJS({
105377
105666
  return "0.0001";
105378
105667
  }
105379
105668
  async cancelOrder(orderId) {
105380
- const auth = this.ensureAuth();
105381
- const client = await auth.getClobClient();
105382
105669
  try {
105670
+ const auth = this.ensureAuth();
105671
+ const client = await auth.getClobClient();
105383
105672
  await client.cancelOrder({ orderID: orderId });
105384
105673
  return {
105385
105674
  id: orderId,
@@ -105394,13 +105683,13 @@ var require_polymarket = __commonJS({
105394
105683
  timestamp: Date.now()
105395
105684
  };
105396
105685
  } catch (error) {
105397
- throw error;
105686
+ throw errors_1.polymarketErrorMapper.mapError(error);
105398
105687
  }
105399
105688
  }
105400
105689
  async fetchOrder(orderId) {
105401
- const auth = this.ensureAuth();
105402
- const client = await auth.getClobClient();
105403
105690
  try {
105691
+ const auth = this.ensureAuth();
105692
+ const client = await auth.getClobClient();
105404
105693
  const order = await client.getOrder(orderId);
105405
105694
  if (!order || !order.id) {
105406
105695
  const errorMsg = order?.error || "Order not found (Invalid ID)";
@@ -105420,13 +105709,13 @@ var require_polymarket = __commonJS({
105420
105709
  timestamp: order.created_at * 1e3
105421
105710
  };
105422
105711
  } catch (error) {
105423
- throw error;
105712
+ throw errors_1.polymarketErrorMapper.mapError(error);
105424
105713
  }
105425
105714
  }
105426
105715
  async fetchOpenOrders(marketId) {
105427
- const auth = this.ensureAuth();
105428
- const client = await auth.getClobClient();
105429
105716
  try {
105717
+ const auth = this.ensureAuth();
105718
+ const client = await auth.getClobClient();
105430
105719
  const orders = await client.getOpenOrders({
105431
105720
  market: marketId
105432
105721
  });
@@ -105444,19 +105733,22 @@ var require_polymarket = __commonJS({
105444
105733
  timestamp: o.created_at * 1e3
105445
105734
  }));
105446
105735
  } catch (error) {
105447
- console.error("Error fetching Polymarket open orders:", error);
105448
- return [];
105736
+ throw errors_1.polymarketErrorMapper.mapError(error);
105449
105737
  }
105450
105738
  }
105451
105739
  async fetchPositions() {
105452
- const auth = this.ensureAuth();
105453
- const address = await auth.getEffectiveFunderAddress();
105454
- return (0, fetchPositions_1.fetchPositions)(address);
105740
+ try {
105741
+ const auth = this.ensureAuth();
105742
+ const address = await auth.getEffectiveFunderAddress();
105743
+ return (0, fetchPositions_1.fetchPositions)(address);
105744
+ } catch (error) {
105745
+ throw errors_1.polymarketErrorMapper.mapError(error);
105746
+ }
105455
105747
  }
105456
105748
  async fetchBalance() {
105457
- const auth = this.ensureAuth();
105458
- const client = await auth.getClobClient();
105459
105749
  try {
105750
+ const auth = this.ensureAuth();
105751
+ const client = await auth.getClobClient();
105460
105752
  const USDC_DECIMALS = 6;
105461
105753
  let total = 0;
105462
105754
  try {
@@ -105503,7 +105795,7 @@ var require_polymarket = __commonJS({
105503
105795
  locked
105504
105796
  }];
105505
105797
  } catch (error) {
105506
- throw error;
105798
+ throw errors_1.polymarketErrorMapper.mapError(error);
105507
105799
  }
105508
105800
  }
105509
105801
  async watchOrderBook(id, limit) {
@@ -105597,6 +105889,59 @@ var require_utils10 = __commonJS({
105597
105889
  }
105598
105890
  });
105599
105891
 
105892
+ // dist/exchanges/limitless/errors.js
105893
+ var require_errors5 = __commonJS({
105894
+ "dist/exchanges/limitless/errors.js"(exports2) {
105895
+ "use strict";
105896
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
105897
+ return mod && mod.__esModule ? mod : { "default": mod };
105898
+ };
105899
+ Object.defineProperty(exports2, "__esModule", { value: true });
105900
+ exports2.limitlessErrorMapper = exports2.LimitlessErrorMapper = void 0;
105901
+ var axios_1 = __importDefault(require_axios());
105902
+ var error_mapper_1 = require_error_mapper();
105903
+ var errors_1 = require_errors();
105904
+ var LimitlessErrorMapper = class extends error_mapper_1.ErrorMapper {
105905
+ constructor() {
105906
+ super("Limitless");
105907
+ }
105908
+ /**
105909
+ * Override to handle Limitless-specific error patterns
105910
+ */
105911
+ extractErrorMessage(error) {
105912
+ if (axios_1.default.isAxiosError(error) && error.response?.data) {
105913
+ const data = error.response.data;
105914
+ if (data.errorMsg) {
105915
+ return data.errorMsg;
105916
+ }
105917
+ if (data.error?.message) {
105918
+ return data.error.message;
105919
+ }
105920
+ if (data.message) {
105921
+ return data.message;
105922
+ }
105923
+ }
105924
+ return super.extractErrorMessage(error);
105925
+ }
105926
+ /**
105927
+ * Override to detect Limitless-specific error patterns
105928
+ */
105929
+ mapBadRequestError(message, data) {
105930
+ const lowerMessage = message.toLowerCase();
105931
+ if (lowerMessage.includes("api key") || lowerMessage.includes("proxy") || lowerMessage.includes("signature type")) {
105932
+ return new errors_1.AuthenticationError(message, this.exchangeName);
105933
+ }
105934
+ if (lowerMessage.includes("tick size")) {
105935
+ return new errors_1.InvalidOrder(message, this.exchangeName);
105936
+ }
105937
+ return super.mapBadRequestError(message, data);
105938
+ }
105939
+ };
105940
+ exports2.LimitlessErrorMapper = LimitlessErrorMapper;
105941
+ exports2.limitlessErrorMapper = new LimitlessErrorMapper();
105942
+ }
105943
+ });
105944
+
105600
105945
  // dist/exchanges/limitless/fetchMarkets.js
105601
105946
  var require_fetchMarkets2 = __commonJS({
105602
105947
  "dist/exchanges/limitless/fetchMarkets.js"(exports2) {
@@ -105608,6 +105953,7 @@ var require_fetchMarkets2 = __commonJS({
105608
105953
  exports2.fetchMarkets = fetchMarkets;
105609
105954
  var axios_1 = __importDefault(require_axios());
105610
105955
  var utils_1 = require_utils10();
105956
+ var errors_1 = require_errors5();
105611
105957
  async function fetchMarkets(params) {
105612
105958
  const limit = params?.limit || 200;
105613
105959
  const offset = params?.offset || 0;
@@ -105632,8 +105978,7 @@ var require_fetchMarkets2 = __commonJS({
105632
105978
  }
105633
105979
  return unifiedMarkets.slice(offset, offset + limit);
105634
105980
  } catch (error) {
105635
- console.error("Error fetching Limitless markets:", error.message);
105636
- return [];
105981
+ throw errors_1.limitlessErrorMapper.mapError(error);
105637
105982
  }
105638
105983
  }
105639
105984
  }
@@ -105650,6 +105995,7 @@ var require_searchMarkets2 = __commonJS({
105650
105995
  exports2.searchMarkets = searchMarkets;
105651
105996
  var axios_1 = __importDefault(require_axios());
105652
105997
  var utils_1 = require_utils10();
105998
+ var errors_1 = require_errors5();
105653
105999
  async function searchMarkets(query, params) {
105654
106000
  try {
105655
106001
  const response = await axios_1.default.get(`${utils_1.LIMITLESS_API_URL}/markets/search`, {
@@ -105675,8 +106021,7 @@ var require_searchMarkets2 = __commonJS({
105675
106021
  }
105676
106022
  return allMarkets.filter((m) => m !== null && m.outcomes.length > 0).slice(0, params?.limit || 20);
105677
106023
  } catch (error) {
105678
- console.error("Error searching Limitless data:", error.message);
105679
- return [];
106024
+ throw errors_1.limitlessErrorMapper.mapError(error);
105680
106025
  }
105681
106026
  }
105682
106027
  }
@@ -105774,6 +106119,7 @@ var require_fetchOHLCV2 = __commonJS({
105774
106119
  var axios_1 = __importDefault(require_axios());
105775
106120
  var utils_1 = require_utils10();
105776
106121
  var validation_1 = require_validation();
106122
+ var errors_1 = require_errors5();
105777
106123
  async function fetchOHLCV(id, params) {
105778
106124
  (0, validation_1.validateIdFormat)(id, "OHLCV");
105779
106125
  try {
@@ -105808,8 +106154,7 @@ var require_fetchOHLCV2 = __commonJS({
105808
106154
  }
105809
106155
  return candles;
105810
106156
  } catch (error) {
105811
- console.error(`Error fetching Limitless history for ${id}:`, error.message);
105812
- return [];
106157
+ throw errors_1.limitlessErrorMapper.mapError(error);
105813
106158
  }
105814
106159
  }
105815
106160
  }
@@ -105861,8 +106206,13 @@ var require_fetchTrades2 = __commonJS({
105861
106206
  "use strict";
105862
106207
  Object.defineProperty(exports2, "__esModule", { value: true });
105863
106208
  exports2.fetchTrades = fetchTrades;
106209
+ var errors_1 = require_errors5();
105864
106210
  async function fetchTrades(id, params) {
105865
- throw new Error("Limitless fetchTrades not implemented: No public market trades API available.");
106211
+ try {
106212
+ throw new Error("Limitless fetchTrades not implemented: No public market trades API available.");
106213
+ } catch (error) {
106214
+ throw errors_1.limitlessErrorMapper.mapError(error);
106215
+ }
105866
106216
  }
105867
106217
  }
105868
106218
  });
@@ -105912,6 +106262,7 @@ var require_auth2 = __commonJS({
105912
106262
  exports2.LimitlessAuth = void 0;
105913
106263
  var clob_client_1 = (init_dist2(), __toCommonJS(dist_exports));
105914
106264
  var ethers_1 = require_lib36();
106265
+ var errors_1 = require_errors5();
105915
106266
  var LIMITLESS_HOST = "https://api.limitless.exchange";
105916
106267
  var BASE_CHAIN_ID = 8453;
105917
106268
  var LimitlessAuth = class {
@@ -105946,8 +106297,7 @@ var require_auth2 = __commonJS({
105946
106297
  try {
105947
106298
  creds = await l1Client.createApiKey();
105948
106299
  } catch (createError) {
105949
- console.error("Failed to both derive and create API key:", createError?.message || createError);
105950
- throw new Error("Authentication failed: Could not create or derive API key.");
106300
+ throw errors_1.limitlessErrorMapper.mapError(createError);
105951
106301
  }
105952
106302
  }
105953
106303
  if (!creds) {
@@ -106221,6 +106571,8 @@ var require_limitless = __commonJS({
106221
106571
  var auth_1 = require_auth2();
106222
106572
  var client_1 = require_client();
106223
106573
  var websocket_1 = require_websocket4();
106574
+ var errors_1 = require_errors5();
106575
+ var errors_2 = require_errors();
106224
106576
  var LimitlessExchange = class extends BaseExchange_1.PredictionMarketExchange {
106225
106577
  constructor(options) {
106226
106578
  let credentials;
@@ -106281,7 +106633,7 @@ var require_limitless = __commonJS({
106281
106633
  */
106282
106634
  ensureAuth() {
106283
106635
  if (!this.auth) {
106284
- throw new Error('Trading operations require authentication. Initialize LimitlessExchange with credentials: new LimitlessExchange({ privateKey: "0x..." })');
106636
+ throw new errors_2.AuthenticationError('Trading operations require authentication. Initialize LimitlessExchange with credentials: new LimitlessExchange({ privateKey: "0x..." })', "Limitless");
106285
106637
  }
106286
106638
  return this.auth;
106287
106639
  }
@@ -106316,8 +106668,7 @@ var require_limitless = __commonJS({
106316
106668
  timestamp: Date.now()
106317
106669
  };
106318
106670
  } catch (error) {
106319
- console.error("Limitless createOrder failed:", error.response?.data || error.message);
106320
- throw error;
106671
+ throw errors_1.limitlessErrorMapper.mapError(error);
106321
106672
  }
106322
106673
  }
106323
106674
  async cancelOrder(orderId) {
@@ -106337,8 +106688,7 @@ var require_limitless = __commonJS({
106337
106688
  timestamp: Date.now()
106338
106689
  };
106339
106690
  } catch (error) {
106340
- console.error("Limitless cancelOrder failed:", error.response?.data || error.message);
106341
- throw error;
106691
+ throw errors_1.limitlessErrorMapper.mapError(error);
106342
106692
  }
106343
106693
  }
106344
106694
  async fetchOrder(orderId) {
@@ -106369,8 +106719,7 @@ var require_limitless = __commonJS({
106369
106719
  // API doesn't always return TS in summary
106370
106720
  }));
106371
106721
  } catch (error) {
106372
- console.error("Error fetching Limitless open orders:", error.message);
106373
- return [];
106722
+ throw errors_1.limitlessErrorMapper.mapError(error);
106374
106723
  }
106375
106724
  }
106376
106725
  async fetchPositions() {
@@ -106396,8 +106745,7 @@ var require_limitless = __commonJS({
106396
106745
  locked: 0
106397
106746
  }];
106398
106747
  } catch (error) {
106399
- console.warn("fetchBalance failed via CLOB client", error.message);
106400
- return [{ currency: "USDC", total: 0, available: 0, locked: 0 }];
106748
+ throw errors_1.limitlessErrorMapper.mapError(error);
106401
106749
  }
106402
106750
  }
106403
106751
  async watchOrderBook(id, limit) {
@@ -106516,6 +106864,57 @@ var require_utils11 = __commonJS({
106516
106864
  }
106517
106865
  });
106518
106866
 
106867
+ // dist/exchanges/kalshi/errors.js
106868
+ var require_errors6 = __commonJS({
106869
+ "dist/exchanges/kalshi/errors.js"(exports2) {
106870
+ "use strict";
106871
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
106872
+ return mod && mod.__esModule ? mod : { "default": mod };
106873
+ };
106874
+ Object.defineProperty(exports2, "__esModule", { value: true });
106875
+ exports2.kalshiErrorMapper = exports2.KalshiErrorMapper = void 0;
106876
+ var axios_1 = __importDefault(require_axios());
106877
+ var error_mapper_1 = require_error_mapper();
106878
+ var errors_1 = require_errors();
106879
+ var KalshiErrorMapper = class extends error_mapper_1.ErrorMapper {
106880
+ constructor() {
106881
+ super("Kalshi");
106882
+ }
106883
+ /**
106884
+ * Override to handle Kalshi-specific error patterns
106885
+ */
106886
+ extractErrorMessage(error) {
106887
+ if (axios_1.default.isAxiosError(error) && error.response?.data) {
106888
+ const data = error.response.data;
106889
+ if (data.error?.message) {
106890
+ const status = error.response.status;
106891
+ return `[${status}] ${data.error.message}`;
106892
+ }
106893
+ if (data.message) {
106894
+ return data.message;
106895
+ }
106896
+ if (data.error && typeof data.error === "string") {
106897
+ return data.error;
106898
+ }
106899
+ }
106900
+ return super.extractErrorMessage(error);
106901
+ }
106902
+ /**
106903
+ * Override to detect Kalshi-specific error patterns
106904
+ */
106905
+ mapBadRequestError(message, data) {
106906
+ const lowerMessage = message.toLowerCase();
106907
+ if (lowerMessage.includes("balance")) {
106908
+ return new errors_1.InsufficientFunds(message, this.exchangeName);
106909
+ }
106910
+ return super.mapBadRequestError(message, data);
106911
+ }
106912
+ };
106913
+ exports2.KalshiErrorMapper = KalshiErrorMapper;
106914
+ exports2.kalshiErrorMapper = new KalshiErrorMapper();
106915
+ }
106916
+ });
106917
+
106519
106918
  // dist/exchanges/kalshi/fetchMarkets.js
106520
106919
  var require_fetchMarkets3 = __commonJS({
106521
106920
  "dist/exchanges/kalshi/fetchMarkets.js"(exports2) {
@@ -106528,6 +106927,7 @@ var require_fetchMarkets3 = __commonJS({
106528
106927
  exports2.fetchMarkets = fetchMarkets;
106529
106928
  var axios_1 = __importDefault(require_axios());
106530
106929
  var utils_1 = require_utils11();
106930
+ var errors_1 = require_errors6();
106531
106931
  async function fetchActiveEvents(targetMarketCount) {
106532
106932
  let allEvents = [];
106533
106933
  let totalMarketCount = 0;
@@ -106564,8 +106964,7 @@ var require_fetchMarkets3 = __commonJS({
106564
106964
  break;
106565
106965
  }
106566
106966
  } catch (e) {
106567
- console.error(`Error fetching Kalshi page ${page}:`, e);
106568
- break;
106967
+ throw errors_1.kalshiErrorMapper.mapError(e);
106569
106968
  }
106570
106969
  } while (cursor && page < MAX_PAGES);
106571
106970
  return allEvents;
@@ -106582,8 +106981,7 @@ var require_fetchMarkets3 = __commonJS({
106582
106981
  }
106583
106982
  return map;
106584
106983
  } catch (e) {
106585
- console.error("Error fetching Kalshi series:", e);
106586
- return /* @__PURE__ */ new Map();
106984
+ throw errors_1.kalshiErrorMapper.mapError(e);
106587
106985
  }
106588
106986
  }
106589
106987
  var cachedEvents = null;
@@ -106644,8 +107042,7 @@ var require_fetchMarkets3 = __commonJS({
106644
107042
  }
106645
107043
  return allMarkets.slice(offset, offset + limit);
106646
107044
  } catch (error) {
106647
- console.error("Error fetching Kalshi data:", error);
106648
- return [];
107045
+ throw errors_1.kalshiErrorMapper.mapError(error);
106649
107046
  }
106650
107047
  }
106651
107048
  }
@@ -106658,6 +107055,7 @@ var require_searchMarkets3 = __commonJS({
106658
107055
  Object.defineProperty(exports2, "__esModule", { value: true });
106659
107056
  exports2.searchMarkets = searchMarkets;
106660
107057
  var fetchMarkets_1 = require_fetchMarkets3();
107058
+ var errors_1 = require_errors6();
106661
107059
  async function searchMarkets(query, params) {
106662
107060
  const searchLimit = 5e3;
106663
107061
  try {
@@ -106676,8 +107074,7 @@ var require_searchMarkets3 = __commonJS({
106676
107074
  const limit = params?.limit || 20;
106677
107075
  return filtered.slice(0, limit);
106678
107076
  } catch (error) {
106679
- console.error("Error searching Kalshi data:", error);
106680
- return [];
107077
+ throw errors_1.kalshiErrorMapper.mapError(error);
106681
107078
  }
106682
107079
  }
106683
107080
  }
@@ -106694,6 +107091,7 @@ var require_searchEvents3 = __commonJS({
106694
107091
  exports2.searchEvents = searchEvents;
106695
107092
  var axios_1 = __importDefault(require_axios());
106696
107093
  var utils_1 = require_utils11();
107094
+ var errors_1 = require_errors6();
106697
107095
  async function searchEvents(query, params) {
106698
107096
  try {
106699
107097
  const queryParams = {
@@ -106738,8 +107136,7 @@ var require_searchEvents3 = __commonJS({
106738
107136
  const limit = params?.limit || 20;
106739
107137
  return unifiedEvents.slice(0, limit);
106740
107138
  } catch (error) {
106741
- console.error("Error searching Kalshi events:", error);
106742
- return [];
107139
+ throw errors_1.kalshiErrorMapper.mapError(error);
106743
107140
  }
106744
107141
  }
106745
107142
  }
@@ -106815,6 +107212,7 @@ var require_fetchOHLCV3 = __commonJS({
106815
107212
  var axios_1 = __importDefault(require_axios());
106816
107213
  var utils_1 = require_utils11();
106817
107214
  var validation_1 = require_validation();
107215
+ var errors_1 = require_errors6();
106818
107216
  async function fetchOHLCV(id, params) {
106819
107217
  (0, validation_1.validateIdFormat)(id, "OHLCV");
106820
107218
  try {
@@ -106881,12 +107279,7 @@ var require_fetchOHLCV3 = __commonJS({
106881
107279
  }
106882
107280
  return mappedCandles;
106883
107281
  } catch (error) {
106884
- if (axios_1.default.isAxiosError(error) && error.response) {
106885
- const apiError = error.response.data?.error || error.response.data?.message || "Unknown API Error";
106886
- throw new Error(`Kalshi History API Error (${error.response.status}): ${apiError}. Used Ticker: ${id}`);
106887
- }
106888
- console.error(`Unexpected error fetching Kalshi history for ${id}:`, error);
106889
- throw error;
107282
+ throw errors_1.kalshiErrorMapper.mapError(error);
106890
107283
  }
106891
107284
  }
106892
107285
  }
@@ -106903,6 +107296,7 @@ var require_fetchOrderBook3 = __commonJS({
106903
107296
  exports2.fetchOrderBook = fetchOrderBook;
106904
107297
  var axios_1 = __importDefault(require_axios());
106905
107298
  var validation_1 = require_validation();
107299
+ var errors_1 = require_errors6();
106906
107300
  async function fetchOrderBook(id) {
106907
107301
  (0, validation_1.validateIdFormat)(id, "OrderBook");
106908
107302
  try {
@@ -106938,8 +107332,7 @@ var require_fetchOrderBook3 = __commonJS({
106938
107332
  asks.sort((a, b) => a.price - b.price);
106939
107333
  return { bids, asks, timestamp: Date.now() };
106940
107334
  } catch (error) {
106941
- console.error(`Error fetching Kalshi orderbook for ${id}:`, error);
106942
- return { bids: [], asks: [] };
107335
+ throw errors_1.kalshiErrorMapper.mapError(error);
106943
107336
  }
106944
107337
  }
106945
107338
  }
@@ -106955,6 +107348,7 @@ var require_fetchTrades3 = __commonJS({
106955
107348
  Object.defineProperty(exports2, "__esModule", { value: true });
106956
107349
  exports2.fetchTrades = fetchTrades;
106957
107350
  var axios_1 = __importDefault(require_axios());
107351
+ var errors_1 = require_errors6();
106958
107352
  async function fetchTrades(id, params) {
106959
107353
  try {
106960
107354
  const ticker = id.replace(/-NO$/, "");
@@ -106974,8 +107368,7 @@ var require_fetchTrades3 = __commonJS({
106974
107368
  side: t.taker_side === "yes" ? "buy" : "sell"
106975
107369
  }));
106976
107370
  } catch (error) {
106977
- console.error(`Error fetching Kalshi trades for ${id}:`, error);
106978
- return [];
107371
+ throw errors_1.kalshiErrorMapper.mapError(error);
106979
107372
  }
106980
107373
  }
106981
107374
  }
@@ -107025,6 +107418,7 @@ var require_auth3 = __commonJS({
107025
107418
  Object.defineProperty(exports2, "__esModule", { value: true });
107026
107419
  exports2.KalshiAuth = void 0;
107027
107420
  var crypto2 = __importStar(require("crypto"));
107421
+ var errors_1 = require_errors6();
107028
107422
  var KalshiAuth = class {
107029
107423
  constructor(credentials) {
107030
107424
  this.credentials = credentials;
@@ -107072,8 +107466,7 @@ var require_auth3 = __commonJS({
107072
107466
  }, "base64");
107073
107467
  return signature;
107074
107468
  } catch (error) {
107075
- console.error("Error signing Kalshi request:", error);
107076
- throw new Error(`Failed to sign Kalshi request: ${error.message}`);
107469
+ throw errors_1.kalshiErrorMapper.mapError(error);
107077
107470
  }
107078
107471
  }
107079
107472
  };
@@ -107426,6 +107819,8 @@ var require_kalshi = __commonJS({
107426
107819
  var fetchTrades_1 = require_fetchTrades3();
107427
107820
  var auth_1 = require_auth3();
107428
107821
  var websocket_1 = require_websocket5();
107822
+ var errors_1 = require_errors6();
107823
+ var errors_2 = require_errors();
107429
107824
  var KalshiExchange = class extends BaseExchange_1.PredictionMarketExchange {
107430
107825
  constructor(options) {
107431
107826
  let credentials;
@@ -107453,7 +107848,7 @@ var require_kalshi = __commonJS({
107453
107848
  // ----------------------------------------------------------------------------
107454
107849
  ensureAuth() {
107455
107850
  if (!this.auth) {
107456
- throw new Error("Trading operations require authentication. Initialize KalshiExchange with credentials (apiKey and privateKey).");
107851
+ throw new errors_2.AuthenticationError("Trading operations require authentication. Initialize KalshiExchange with credentials (apiKey and privateKey).", "Kalshi");
107457
107852
  }
107458
107853
  return this.auth;
107459
107854
  }
@@ -107485,11 +107880,11 @@ var require_kalshi = __commonJS({
107485
107880
  // User Data Methods
107486
107881
  // ----------------------------------------------------------------------------
107487
107882
  async fetchBalance() {
107488
- const auth = this.ensureAuth();
107489
- const path = "/trade-api/v2/portfolio/balance";
107490
- const baseUrl = this.getBaseUrl();
107491
- const headers = auth.getHeaders("GET", path);
107492
107883
  try {
107884
+ const auth = this.ensureAuth();
107885
+ const path = "/trade-api/v2/portfolio/balance";
107886
+ const baseUrl = this.getBaseUrl();
107887
+ const headers = auth.getHeaders("GET", path);
107493
107888
  const response = await axios_1.default.get(`${baseUrl}${path}`, { headers });
107494
107889
  const balanceCents = response.data.balance;
107495
107890
  const portfolioValueCents = response.data.portfolio_value;
@@ -107506,37 +107901,37 @@ var require_kalshi = __commonJS({
107506
107901
  // Value locked in positions
107507
107902
  }];
107508
107903
  } catch (error) {
107509
- throw error;
107904
+ throw errors_1.kalshiErrorMapper.mapError(error);
107510
107905
  }
107511
107906
  }
107512
107907
  // ----------------------------------------------------------------------------
107513
107908
  // Trading Methods
107514
107909
  // ----------------------------------------------------------------------------
107515
107910
  async createOrder(params) {
107516
- const auth = this.ensureAuth();
107517
- const path = "/trade-api/v2/portfolio/orders";
107518
- const baseUrl = this.getBaseUrl();
107519
- const headers = auth.getHeaders("POST", path);
107520
- const isYesSide = params.side === "buy";
107521
- const kalshiOrder = {
107522
- ticker: params.marketId,
107523
- // Kalshi uses ticker for market identification
107524
- client_order_id: `pmxt-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
107525
- side: isYesSide ? "yes" : "no",
107526
- action: params.side === "buy" ? "buy" : "sell",
107527
- count: params.amount,
107528
- // Number of contracts
107529
- type: params.type === "limit" ? "limit" : "market"
107530
- };
107531
- if (params.price) {
107532
- const priceInCents = Math.round(params.price * 100);
107533
- if (isYesSide) {
107534
- kalshiOrder.yes_price = priceInCents;
107535
- } else {
107536
- kalshiOrder.no_price = priceInCents;
107537
- }
107538
- }
107539
107911
  try {
107912
+ const auth = this.ensureAuth();
107913
+ const path = "/trade-api/v2/portfolio/orders";
107914
+ const baseUrl = this.getBaseUrl();
107915
+ const headers = auth.getHeaders("POST", path);
107916
+ const isYesSide = params.side === "buy";
107917
+ const kalshiOrder = {
107918
+ ticker: params.marketId,
107919
+ // Kalshi uses ticker for market identification
107920
+ client_order_id: `pmxt-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
107921
+ side: isYesSide ? "yes" : "no",
107922
+ action: params.side === "buy" ? "buy" : "sell",
107923
+ count: params.amount,
107924
+ // Number of contracts
107925
+ type: params.type === "limit" ? "limit" : "market"
107926
+ };
107927
+ if (params.price) {
107928
+ const priceInCents = Math.round(params.price * 100);
107929
+ if (isYesSide) {
107930
+ kalshiOrder.yes_price = priceInCents;
107931
+ } else {
107932
+ kalshiOrder.no_price = priceInCents;
107933
+ }
107934
+ }
107540
107935
  const response = await axios_1.default.post(`${baseUrl}${path}`, kalshiOrder, { headers });
107541
107936
  const order = response.data.order;
107542
107937
  return {
@@ -107553,15 +107948,15 @@ var require_kalshi = __commonJS({
107553
107948
  timestamp: new Date(order.created_time).getTime()
107554
107949
  };
107555
107950
  } catch (error) {
107556
- throw new Error(`${error.response?.data?.error?.message || error.message} (Status: ${error.response?.status} - ${JSON.stringify(error.response?.data || {})})`);
107951
+ throw errors_1.kalshiErrorMapper.mapError(error);
107557
107952
  }
107558
107953
  }
107559
107954
  async cancelOrder(orderId) {
107560
- const auth = this.ensureAuth();
107561
- const path = `/trade-api/v2/portfolio/orders/${orderId}`;
107562
- const baseUrl = this.getBaseUrl();
107563
- const headers = auth.getHeaders("DELETE", path);
107564
107955
  try {
107956
+ const auth = this.ensureAuth();
107957
+ const path = `/trade-api/v2/portfolio/orders/${orderId}`;
107958
+ const baseUrl = this.getBaseUrl();
107959
+ const headers = auth.getHeaders("DELETE", path);
107565
107960
  const response = await axios_1.default.delete(`${baseUrl}${path}`, { headers });
107566
107961
  const order = response.data.order;
107567
107962
  return {
@@ -107577,15 +107972,15 @@ var require_kalshi = __commonJS({
107577
107972
  timestamp: new Date(order.created_time).getTime()
107578
107973
  };
107579
107974
  } catch (error) {
107580
- throw error;
107975
+ throw errors_1.kalshiErrorMapper.mapError(error);
107581
107976
  }
107582
107977
  }
107583
107978
  async fetchOrder(orderId) {
107584
- const auth = this.ensureAuth();
107585
- const path = `/trade-api/v2/portfolio/orders/${orderId}`;
107586
- const baseUrl = this.getBaseUrl();
107587
- const headers = auth.getHeaders("GET", path);
107588
107979
  try {
107980
+ const auth = this.ensureAuth();
107981
+ const path = `/trade-api/v2/portfolio/orders/${orderId}`;
107982
+ const baseUrl = this.getBaseUrl();
107983
+ const headers = auth.getHeaders("GET", path);
107589
107984
  const response = await axios_1.default.get(`${baseUrl}${path}`, { headers });
107590
107985
  const order = response.data.order;
107591
107986
  return {
@@ -107602,19 +107997,19 @@ var require_kalshi = __commonJS({
107602
107997
  timestamp: new Date(order.created_time).getTime()
107603
107998
  };
107604
107999
  } catch (error) {
107605
- throw error;
108000
+ throw errors_1.kalshiErrorMapper.mapError(error);
107606
108001
  }
107607
108002
  }
107608
108003
  async fetchOpenOrders(marketId) {
107609
- const auth = this.ensureAuth();
107610
- const basePath = "/trade-api/v2/portfolio/orders";
107611
- let queryParams = "?status=resting";
107612
- if (marketId) {
107613
- queryParams += `&ticker=${marketId}`;
107614
- }
107615
- const baseUrl = this.getBaseUrl();
107616
- const headers = auth.getHeaders("GET", basePath);
107617
108004
  try {
108005
+ const auth = this.ensureAuth();
108006
+ const basePath = "/trade-api/v2/portfolio/orders";
108007
+ let queryParams = "?status=resting";
108008
+ if (marketId) {
108009
+ queryParams += `&ticker=${marketId}`;
108010
+ }
108011
+ const baseUrl = this.getBaseUrl();
108012
+ const headers = auth.getHeaders("GET", basePath);
107618
108013
  const response = await axios_1.default.get(`${baseUrl}${basePath}${queryParams}`, { headers });
107619
108014
  const orders = response.data.orders || [];
107620
108015
  return orders.map((order) => ({
@@ -107631,15 +108026,15 @@ var require_kalshi = __commonJS({
107631
108026
  timestamp: new Date(order.created_time).getTime()
107632
108027
  }));
107633
108028
  } catch (error) {
107634
- return [];
108029
+ throw errors_1.kalshiErrorMapper.mapError(error);
107635
108030
  }
107636
108031
  }
107637
108032
  async fetchPositions() {
107638
- const auth = this.ensureAuth();
107639
- const path = "/trade-api/v2/portfolio/positions";
107640
- const baseUrl = this.getBaseUrl();
107641
- const headers = auth.getHeaders("GET", path);
107642
108033
  try {
108034
+ const auth = this.ensureAuth();
108035
+ const path = "/trade-api/v2/portfolio/positions";
108036
+ const baseUrl = this.getBaseUrl();
108037
+ const headers = auth.getHeaders("GET", path);
107643
108038
  const response = await axios_1.default.get(`${baseUrl}${path}`, { headers });
107644
108039
  const positions = response.data.market_positions || [];
107645
108040
  return positions.map((pos) => {
@@ -107659,7 +108054,7 @@ var require_kalshi = __commonJS({
107659
108054
  };
107660
108055
  });
107661
108056
  } catch (error) {
107662
- return [];
108057
+ throw errors_1.kalshiErrorMapper.mapError(error);
107663
108058
  }
107664
108059
  }
107665
108060
  // Helper to map Kalshi order status to unified status
@@ -107718,6 +108113,7 @@ var require_app = __commonJS({
107718
108113
  var polymarket_1 = require_polymarket();
107719
108114
  var limitless_1 = require_limitless();
107720
108115
  var kalshi_1 = require_kalshi();
108116
+ var errors_1 = require_errors();
107721
108117
  var defaultExchanges = {
107722
108118
  polymarket: null,
107723
108119
  limitless: null,
@@ -107768,6 +108164,27 @@ var require_app = __commonJS({
107768
108164
  if (error.stack) {
107769
108165
  console.error(error.stack);
107770
108166
  }
108167
+ if (error instanceof errors_1.BaseError) {
108168
+ const errorResponse = {
108169
+ success: false,
108170
+ error: {
108171
+ message: error.message,
108172
+ code: error.code,
108173
+ retryable: error.retryable
108174
+ }
108175
+ };
108176
+ if (error.exchange) {
108177
+ errorResponse.error.exchange = error.exchange;
108178
+ }
108179
+ if ("retryAfter" in error && error.retryAfter !== void 0) {
108180
+ errorResponse.error.retryAfter = error.retryAfter;
108181
+ }
108182
+ if (process.env.NODE_ENV === "development") {
108183
+ errorResponse.error.stack = error.stack;
108184
+ }
108185
+ res.status(error.status).json(errorResponse);
108186
+ return;
108187
+ }
107771
108188
  res.status(error.status || 500).json({
107772
108189
  success: false,
107773
108190
  error: {