pmxtjs 2.20.2 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +17 -0
- package/dist/esm/index.js +4 -1
- package/dist/esm/pmxt/client.js +181 -69
- package/dist/esm/pmxt/errors.d.ts +55 -0
- package/dist/esm/pmxt/errors.js +132 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +7 -1
- package/dist/pmxt/client.js +181 -69
- package/dist/pmxt/errors.d.ts +55 -0
- package/dist/pmxt/errors.js +150 -0
- package/generated/package.json +1 -1
- package/index.ts +4 -1
- package/package.json +3 -3
- package/pmxt/client.ts +154 -69
- package/pmxt/errors.ts +163 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Typed error classes for pmxt.
|
|
4
|
+
*
|
|
5
|
+
* These mirror the error hierarchy in the core TypeScript library,
|
|
6
|
+
* enabling users to catch specific error types.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ExchangeNotAvailable = exports.NetworkError = exports.ValidationError = exports.InsufficientFunds = exports.InvalidOrder = exports.RateLimitExceeded = exports.EventNotFound = exports.MarketNotFound = exports.OrderNotFound = exports.NotFoundError = exports.PermissionDenied = exports.AuthenticationError = exports.BadRequest = exports.PmxtError = void 0;
|
|
10
|
+
exports.fromServerError = fromServerError;
|
|
11
|
+
class PmxtError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
retryable;
|
|
14
|
+
exchange;
|
|
15
|
+
constructor(message, code = "UNKNOWN_ERROR", retryable = false, exchange) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = this.constructor.name;
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.retryable = retryable;
|
|
20
|
+
this.exchange = exchange;
|
|
21
|
+
if (Error.captureStackTrace) {
|
|
22
|
+
Error.captureStackTrace(this, this.constructor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.PmxtError = PmxtError;
|
|
27
|
+
// 4xx Client Errors
|
|
28
|
+
class BadRequest extends PmxtError {
|
|
29
|
+
constructor(message, exchange) {
|
|
30
|
+
super(message, "BAD_REQUEST", false, exchange);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.BadRequest = BadRequest;
|
|
34
|
+
class AuthenticationError extends PmxtError {
|
|
35
|
+
constructor(message, exchange) {
|
|
36
|
+
super(message, "AUTHENTICATION_ERROR", false, exchange);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.AuthenticationError = AuthenticationError;
|
|
40
|
+
class PermissionDenied extends PmxtError {
|
|
41
|
+
constructor(message, exchange) {
|
|
42
|
+
super(message, "PERMISSION_DENIED", false, exchange);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.PermissionDenied = PermissionDenied;
|
|
46
|
+
class NotFoundError extends PmxtError {
|
|
47
|
+
constructor(message, exchange) {
|
|
48
|
+
super(message, "NOT_FOUND", false, exchange);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.NotFoundError = NotFoundError;
|
|
52
|
+
class OrderNotFound extends NotFoundError {
|
|
53
|
+
constructor(orderId, exchange) {
|
|
54
|
+
super(`Order not found: ${orderId}`, exchange);
|
|
55
|
+
this.code = "ORDER_NOT_FOUND";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.OrderNotFound = OrderNotFound;
|
|
59
|
+
class MarketNotFound extends NotFoundError {
|
|
60
|
+
constructor(marketId, exchange) {
|
|
61
|
+
super(`Market not found: ${marketId}`, exchange);
|
|
62
|
+
this.code = "MARKET_NOT_FOUND";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MarketNotFound = MarketNotFound;
|
|
66
|
+
class EventNotFound extends NotFoundError {
|
|
67
|
+
constructor(identifier, exchange) {
|
|
68
|
+
super(`Event not found: ${identifier}`, exchange);
|
|
69
|
+
this.code = "EVENT_NOT_FOUND";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.EventNotFound = EventNotFound;
|
|
73
|
+
class RateLimitExceeded extends PmxtError {
|
|
74
|
+
retryAfter;
|
|
75
|
+
constructor(message, retryAfter, exchange) {
|
|
76
|
+
super(message, "RATE_LIMIT_EXCEEDED", true, exchange);
|
|
77
|
+
this.retryAfter = retryAfter;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.RateLimitExceeded = RateLimitExceeded;
|
|
81
|
+
class InvalidOrder extends PmxtError {
|
|
82
|
+
constructor(message, exchange) {
|
|
83
|
+
super(message, "INVALID_ORDER", false, exchange);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.InvalidOrder = InvalidOrder;
|
|
87
|
+
class InsufficientFunds extends PmxtError {
|
|
88
|
+
constructor(message, exchange) {
|
|
89
|
+
super(message, "INSUFFICIENT_FUNDS", false, exchange);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.InsufficientFunds = InsufficientFunds;
|
|
93
|
+
class ValidationError extends PmxtError {
|
|
94
|
+
field;
|
|
95
|
+
constructor(message, field, exchange) {
|
|
96
|
+
super(message, "VALIDATION_ERROR", false, exchange);
|
|
97
|
+
this.field = field;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.ValidationError = ValidationError;
|
|
101
|
+
// 5xx Server/Network Errors
|
|
102
|
+
class NetworkError extends PmxtError {
|
|
103
|
+
constructor(message, exchange) {
|
|
104
|
+
super(message, "NETWORK_ERROR", true, exchange);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.NetworkError = NetworkError;
|
|
108
|
+
class ExchangeNotAvailable extends PmxtError {
|
|
109
|
+
constructor(message, exchange) {
|
|
110
|
+
super(message, "EXCHANGE_NOT_AVAILABLE", true, exchange);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.ExchangeNotAvailable = ExchangeNotAvailable;
|
|
114
|
+
// Error code to class mapping
|
|
115
|
+
const ERROR_CODE_MAP = {
|
|
116
|
+
BAD_REQUEST: BadRequest,
|
|
117
|
+
AUTHENTICATION_ERROR: AuthenticationError,
|
|
118
|
+
PERMISSION_DENIED: PermissionDenied,
|
|
119
|
+
NOT_FOUND: NotFoundError,
|
|
120
|
+
ORDER_NOT_FOUND: OrderNotFound,
|
|
121
|
+
MARKET_NOT_FOUND: MarketNotFound,
|
|
122
|
+
EVENT_NOT_FOUND: EventNotFound,
|
|
123
|
+
RATE_LIMIT_EXCEEDED: RateLimitExceeded,
|
|
124
|
+
INVALID_ORDER: InvalidOrder,
|
|
125
|
+
INSUFFICIENT_FUNDS: InsufficientFunds,
|
|
126
|
+
VALIDATION_ERROR: ValidationError,
|
|
127
|
+
NETWORK_ERROR: NetworkError,
|
|
128
|
+
EXCHANGE_NOT_AVAILABLE: ExchangeNotAvailable,
|
|
129
|
+
};
|
|
130
|
+
/** Convert a server error response object into a typed PmxtError. */
|
|
131
|
+
function fromServerError(errorData) {
|
|
132
|
+
if (typeof errorData === "string") {
|
|
133
|
+
return new PmxtError(errorData);
|
|
134
|
+
}
|
|
135
|
+
const message = errorData.message || "Unknown error";
|
|
136
|
+
const code = errorData.code || "UNKNOWN_ERROR";
|
|
137
|
+
const retryable = errorData.retryable || false;
|
|
138
|
+
const exchange = errorData.exchange;
|
|
139
|
+
const ErrorClass = ERROR_CODE_MAP[code];
|
|
140
|
+
if (ErrorClass === RateLimitExceeded) {
|
|
141
|
+
return new RateLimitExceeded(message, errorData.retryAfter, exchange);
|
|
142
|
+
}
|
|
143
|
+
if (ErrorClass === ValidationError) {
|
|
144
|
+
return new ValidationError(message, errorData.field, exchange);
|
|
145
|
+
}
|
|
146
|
+
if (ErrorClass) {
|
|
147
|
+
return new ErrorClass(message, exchange);
|
|
148
|
+
}
|
|
149
|
+
return new PmxtError(message, code, retryable, exchange);
|
|
150
|
+
}
|
package/generated/package.json
CHANGED
package/index.ts
CHANGED
|
@@ -22,11 +22,13 @@
|
|
|
22
22
|
import { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi } from "./pmxt/client.js";
|
|
23
23
|
import { ServerManager } from "./pmxt/server-manager.js";
|
|
24
24
|
import * as models from "./pmxt/models.js";
|
|
25
|
+
import * as errors from "./pmxt/errors.js";
|
|
25
26
|
|
|
26
27
|
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, PolymarketOptions } from "./pmxt/client.js";
|
|
27
28
|
export { ServerManager } from "./pmxt/server-manager.js";
|
|
28
29
|
export { MarketList } from "./pmxt/models.js";
|
|
29
30
|
export type * from "./pmxt/models.js";
|
|
31
|
+
export * from "./pmxt/errors.js";
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
const defaultManager = new ServerManager();
|
|
@@ -51,7 +53,8 @@ const pmxt = {
|
|
|
51
53
|
ServerManager,
|
|
52
54
|
stopServer,
|
|
53
55
|
restartServer,
|
|
54
|
-
...models
|
|
56
|
+
...models,
|
|
57
|
+
...errors
|
|
55
58
|
};
|
|
56
59
|
|
|
57
60
|
export default pmxt;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmxtjs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.0",
|
|
4
4
|
"description": "Unified prediction market data API - The ccxt for prediction markets",
|
|
5
5
|
"author": "PMXT Contributors",
|
|
6
6
|
"repository": {
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"unified"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"pmxt-core": "2.
|
|
46
|
+
"pmxt-core": "2.21.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/jest": "^30.0.0",
|
|
50
50
|
"@types/node": "^20.0.0",
|
|
51
|
-
"jest": "^30.
|
|
51
|
+
"jest": "^30.3.0",
|
|
52
52
|
"ts-jest": "^29.4.6",
|
|
53
53
|
"typescript": "^5.0.0"
|
|
54
54
|
}
|