pmxtjs 2.51.1 → 2.51.3
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/README.md +14 -5
- package/dist/esm/generated/src/apis/DefaultApi.d.ts +6 -0
- package/dist/esm/generated/src/apis/DefaultApi.js +6 -0
- package/dist/esm/generated/src/models/CreateOrderParams.d.ts +20 -0
- package/dist/esm/generated/src/models/CreateOrderParams.js +11 -0
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +3 -2
- package/dist/esm/pmxt/client.d.ts +61 -12
- package/dist/esm/pmxt/client.js +126 -21
- package/dist/esm/pmxt/escrow.js +109 -10
- package/dist/esm/pmxt/hosted-typed-data.d.ts +1 -1
- package/dist/esm/pmxt/hosted-typed-data.js +14 -0
- package/dist/esm/pmxt/models.d.ts +17 -0
- package/dist/esm/pmxt/server-manager.js +5 -3
- package/dist/generated/src/apis/DefaultApi.d.ts +6 -0
- package/dist/generated/src/apis/DefaultApi.js +6 -0
- package/dist/generated/src/models/CreateOrderParams.d.ts +20 -0
- package/dist/generated/src/models/CreateOrderParams.js +12 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/dist/pmxt/client.d.ts +61 -12
- package/dist/pmxt/client.js +126 -20
- package/dist/pmxt/escrow.js +109 -10
- package/dist/pmxt/hosted-typed-data.d.ts +1 -1
- package/dist/pmxt/hosted-typed-data.js +14 -0
- package/dist/pmxt/models.d.ts +17 -0
- package/dist/pmxt/server-manager.js +5 -3
- package/generated/docs/ArbitrageOpportunity.md +0 -29
- package/generated/docs/Balance.md +0 -25
- package/generated/docs/BaseRequest.md +0 -21
- package/generated/docs/BaseResponse.md +0 -22
- package/generated/docs/BuildOrder200Response.md +0 -23
- package/generated/docs/BuildOrderRequest.md +0 -22
- package/generated/docs/BuiltOrder.md +0 -26
- package/generated/docs/BuiltOrderTx.md +0 -24
- package/generated/docs/CancelOrderRequest.md +0 -22
- package/generated/docs/CloseRequest.md +0 -22
- package/generated/docs/CompareMarketPrices200Response.md +0 -23
- package/generated/docs/CompareMarketPricesRequest.md +0 -22
- package/generated/docs/CreateOrder200Response.md +0 -23
- package/generated/docs/CreateOrderParams.md +2 -30
- package/generated/docs/CreateOrderRequest.md +0 -22
- package/generated/docs/DataFeedsApi.md +0 -329
- package/generated/docs/DefaultApi.md +3 -1438
- package/generated/docs/ErrorDetail.md +0 -25
- package/generated/docs/ErrorResponse.md +0 -22
- package/generated/docs/EventFetchParams.md +0 -35
- package/generated/docs/EventFilterCriteria.md +0 -26
- package/generated/docs/EventFilterCriteriaTotalVolume.md +0 -22
- package/generated/docs/EventMatchResult.md +0 -22
- package/generated/docs/ExchangeCredentials.md +0 -29
- package/generated/docs/ExchangeCredentialsSignatureType.md +0 -20
- package/generated/docs/ExchangeOptions.md +0 -27
- package/generated/docs/ExecutionPriceResult.md +0 -23
- package/generated/docs/FeedFetchHistoricalPrices200Response.md +0 -22
- package/generated/docs/FeedFetchOHLCV200Response.md +0 -22
- package/generated/docs/FeedFetchOracleHistory200Response.md +0 -22
- package/generated/docs/FeedFetchOracleRound200Response.md +0 -22
- package/generated/docs/FeedFetchOrderBook200Response.md +0 -22
- package/generated/docs/FeedFetchOrderBook200ResponseData.md +0 -25
- package/generated/docs/FeedFetchTicker200Response.md +0 -22
- package/generated/docs/FeedFetchTickers200Response.md +0 -22
- package/generated/docs/FeedList200Response.md +0 -22
- package/generated/docs/FeedLoadMarkets200Response.md +0 -22
- package/generated/docs/FeedMarket.md +0 -27
- package/generated/docs/FeedOracleRound.md +0 -28
- package/generated/docs/FeedTicker.md +0 -42
- package/generated/docs/FetchArbitrage200Response.md +0 -23
- package/generated/docs/FetchArbitrageParams.md +0 -24
- package/generated/docs/FetchBalance200Response.md +0 -23
- package/generated/docs/FetchEvent200Response.md +0 -23
- package/generated/docs/FetchEventMatches200Response.md +0 -23
- package/generated/docs/FetchEventMatchesParams.md +0 -29
- package/generated/docs/FetchEvents200Response.md +0 -23
- package/generated/docs/FetchEventsPaginated200Response.md +0 -23
- package/generated/docs/FetchMarket200Response.md +0 -23
- package/generated/docs/FetchMarketMatches200Response.md +0 -23
- package/generated/docs/FetchMarketMatchesParams.md +0 -32
- package/generated/docs/FetchMarkets200Response.md +0 -23
- package/generated/docs/FetchMarketsPaginated200Response.md +0 -23
- package/generated/docs/FetchMatchedMarkets200Response.md +0 -23
- package/generated/docs/FetchMatchedMarketsParams.md +0 -24
- package/generated/docs/FetchMyTrades200Response.md +0 -23
- package/generated/docs/FetchOHLCV200Response.md +0 -23
- package/generated/docs/FetchOpenOrders200Response.md +0 -23
- package/generated/docs/FetchOrderBook200Response.md +0 -23
- package/generated/docs/FetchOrderBookParams.md +0 -24
- package/generated/docs/FetchOrderBooks200Response.md +0 -23
- package/generated/docs/FetchOrderBooksRequest.md +0 -22
- package/generated/docs/FetchPositions200Response.md +0 -23
- package/generated/docs/FetchSeries200Response.md +0 -23
- package/generated/docs/FetchTrades200Response.md +0 -23
- package/generated/docs/FilterEventsRequest.md +0 -22
- package/generated/docs/FilterEventsRequestArgsInner.md +0 -26
- package/generated/docs/FilterMarketsRequest.md +0 -22
- package/generated/docs/FilterMarketsRequestArgsInner.md +0 -31
- package/generated/docs/GetExecutionPrice200Response.md +0 -23
- package/generated/docs/GetExecutionPriceDetailed200Response.md +0 -23
- package/generated/docs/GetExecutionPriceDetailedRequest.md +0 -22
- package/generated/docs/GetExecutionPriceRequest.md +0 -22
- package/generated/docs/GetExecutionPriceRequestArgsInner.md +0 -27
- package/generated/docs/HealthCheck200Response.md +0 -22
- package/generated/docs/HistoryFilterParams.md +0 -24
- package/generated/docs/LoadMarkets200Response.md +0 -23
- package/generated/docs/LoadMarketsRequest.md +0 -22
- package/generated/docs/MarketFilterCriteria.md +0 -31
- package/generated/docs/MarketFilterCriteriaLiquidity.md +0 -22
- package/generated/docs/MarketFilterCriteriaOpenInterest.md +0 -22
- package/generated/docs/MarketFilterCriteriaPrice.md +0 -23
- package/generated/docs/MarketFilterCriteriaResolutionDate.md +0 -22
- package/generated/docs/MarketFilterCriteriaVolume.md +0 -22
- package/generated/docs/MarketFilterCriteriaVolume24h.md +0 -22
- package/generated/docs/MarketFilterParams.md +0 -34
- package/generated/docs/MarketOutcome.md +0 -26
- package/generated/docs/MatchResult.md +0 -27
- package/generated/docs/MatchedMarketPair.md +0 -30
- package/generated/docs/MyTradesParams.md +0 -26
- package/generated/docs/OHLCVParams.md +0 -24
- package/generated/docs/Order.md +0 -37
- package/generated/docs/OrderBook.md +0 -27
- package/generated/docs/OrderHistoryParams.md +0 -25
- package/generated/docs/OrderLevel.md +0 -23
- package/generated/docs/PaginatedEventsResult.md +0 -23
- package/generated/docs/PaginatedMarketsResult.md +0 -23
- package/generated/docs/Position.md +0 -32
- package/generated/docs/PriceCandle.md +0 -26
- package/generated/docs/PriceComparison.md +0 -27
- package/generated/docs/SubmitOrderRequest.md +0 -22
- package/generated/docs/Trade.md +0 -26
- package/generated/docs/TradesParams.md +0 -23
- package/generated/docs/UnifiedEvent.md +0 -33
- package/generated/docs/UnifiedMarket.md +0 -44
- package/generated/docs/UnifiedSeries.md +0 -31
- package/generated/docs/UserTrade.md +0 -32
- package/generated/package.json +1 -1
- package/generated/src/apis/DefaultApi.ts +6 -0
- package/generated/src/models/CreateOrderParams.ts +25 -0
- package/index.ts +3 -2
- package/package.json +2 -2
- package/pmxt/client.ts +153 -28
- package/pmxt/escrow.ts +131 -11
- package/pmxt/hosted-typed-data.ts +17 -1
- package/pmxt/models.ts +20 -0
- package/pmxt/server-manager.ts +5 -3
package/dist/pmxt/client.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* OpenAPI client, matching the Python API exactly.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Mock = exports.Rain = exports.Suibets = exports.SuiBets = exports.Hyperliquid = exports.GeminiTitan = exports.PolymarketUS = exports.Smarkets = exports.Metaculus = exports.Opinion = exports.Baozi = exports.Probable = exports.Myriad = exports.KalshiDemo = exports.Limitless = exports.Kalshi = exports.Polymarket = exports.Exchange = void 0;
|
|
9
|
+
exports.Mock = exports.Hunch = exports.Rain = exports.Suibets = exports.SuiBets = exports.Hyperliquid = exports.GeminiTitan = exports.PolymarketUS = exports.Smarkets = exports.Metaculus = exports.Opinion = exports.Baozi = exports.Probable = exports.Myriad = exports.KalshiDemo = exports.Limitless = exports.Kalshi = exports.Polymarket = exports.Exchange = void 0;
|
|
10
10
|
const index_js_1 = require("../generated/src/index.js");
|
|
11
11
|
const models_js_1 = require("./models.js");
|
|
12
12
|
const server_manager_js_1 = require("./server-manager.js");
|
|
@@ -193,6 +193,7 @@ class Exchange {
|
|
|
193
193
|
_wsClient = null;
|
|
194
194
|
/** Sticky flag: true if the sidecar /ws endpoint is unavailable. */
|
|
195
195
|
_wsUnsupported = false;
|
|
196
|
+
_useSidecarLockBaseUrl;
|
|
196
197
|
constructor(exchangeName, options = {}) {
|
|
197
198
|
this.exchangeName = exchangeName.toLowerCase();
|
|
198
199
|
this.apiKey = options.apiKey;
|
|
@@ -210,6 +211,9 @@ class Exchange {
|
|
|
210
211
|
const baseUrl = resolved.baseUrl;
|
|
211
212
|
this.pmxtApiKey = resolved.pmxtApiKey;
|
|
212
213
|
this.isHosted = resolved.isHosted;
|
|
214
|
+
const hasBaseUrlOverride = Boolean(options.baseUrl ||
|
|
215
|
+
(typeof process !== "undefined" && process.env[constants_js_1.ENV.BASE_URL]));
|
|
216
|
+
this._useSidecarLockBaseUrl = !this.isHosted && !hasBaseUrlOverride;
|
|
213
217
|
// Hosted trading bridge: if the caller passed a privateKey but no
|
|
214
218
|
// explicit signer, lazily wrap it in an EthersSigner so that
|
|
215
219
|
// `pmxt.Polymarket(pmxtApiKey, privateKey)` just works without the
|
|
@@ -250,15 +254,17 @@ class Exchange {
|
|
|
250
254
|
if (autoStartServer) {
|
|
251
255
|
try {
|
|
252
256
|
await this.serverManager.ensureServerRunning();
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
257
|
+
if (this._useSidecarLockBaseUrl) {
|
|
258
|
+
// Get the actual port the server is running on
|
|
259
|
+
// (may differ from default if default port was busy)
|
|
260
|
+
const actualPort = this.serverManager.getRunningPort();
|
|
261
|
+
const newBaseUrl = `http://localhost:${actualPort}`;
|
|
262
|
+
// Update API client with actual base URL
|
|
263
|
+
this.config = new index_js_1.Configuration({
|
|
264
|
+
basePath: newBaseUrl,
|
|
265
|
+
});
|
|
266
|
+
this.api = new index_js_1.DefaultApi(this.config);
|
|
267
|
+
}
|
|
262
268
|
}
|
|
263
269
|
catch (error) {
|
|
264
270
|
const msg = `Failed to start PMXT server: ${error instanceof Error ? error.message : error}\n\n` +
|
|
@@ -332,12 +338,12 @@ class Exchange {
|
|
|
332
338
|
/**
|
|
333
339
|
* Resolve the current sidecar base URL.
|
|
334
340
|
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
341
|
+
* Hosted mode and explicit baseUrl clients keep the configured basePath.
|
|
342
|
+
* Default local clients re-read the lock-file port on every call so they
|
|
343
|
+
* pick up sidecar restarts that land on a different port.
|
|
338
344
|
*/
|
|
339
345
|
resolveBaseUrl() {
|
|
340
|
-
if (this.isHosted)
|
|
346
|
+
if (this.isHosted || !this._useSidecarLockBaseUrl)
|
|
341
347
|
return this.config.basePath;
|
|
342
348
|
const port = this.serverManager.getRunningPort();
|
|
343
349
|
return `http://localhost:${port}`;
|
|
@@ -1021,7 +1027,10 @@ class Exchange {
|
|
|
1021
1027
|
const route = hosted_routing_js_1.HOSTED_METHOD_ROUTES.get("fetchOrder");
|
|
1022
1028
|
const path = (0, hosted_routing_js_1.formatRoutePath)(route, { order_id: orderId });
|
|
1023
1029
|
const data = await (0, hosted_routing_js_1._tradingRequest)(this, { method: route.method, path });
|
|
1024
|
-
|
|
1030
|
+
const payload = data && typeof data === "object" && "order" in data
|
|
1031
|
+
? data.order
|
|
1032
|
+
: data;
|
|
1033
|
+
return (0, hosted_mappers_js_1.orderFromV0)(payload);
|
|
1025
1034
|
}
|
|
1026
1035
|
try {
|
|
1027
1036
|
const args = [];
|
|
@@ -1127,6 +1136,9 @@ class Exchange {
|
|
|
1127
1136
|
}
|
|
1128
1137
|
async fetchClosedOrders(params) {
|
|
1129
1138
|
await this.initPromise;
|
|
1139
|
+
if (this.isHosted) {
|
|
1140
|
+
throw new errors_js_1.NotSupported("fetchClosedOrders is not available in hosted trading mode.");
|
|
1141
|
+
}
|
|
1130
1142
|
try {
|
|
1131
1143
|
const args = [];
|
|
1132
1144
|
if (params !== undefined)
|
|
@@ -1155,6 +1167,9 @@ class Exchange {
|
|
|
1155
1167
|
}
|
|
1156
1168
|
async fetchAllOrders(params) {
|
|
1157
1169
|
await this.initPromise;
|
|
1170
|
+
if (this.isHosted) {
|
|
1171
|
+
throw new errors_js_1.NotSupported("fetchAllOrders is not available in hosted trading mode.");
|
|
1172
|
+
}
|
|
1158
1173
|
try {
|
|
1159
1174
|
const args = [];
|
|
1160
1175
|
if (params !== undefined)
|
|
@@ -1188,7 +1203,9 @@ class Exchange {
|
|
|
1188
1203
|
const route = hosted_routing_js_1.HOSTED_METHOD_ROUTES.get("fetchPositions");
|
|
1189
1204
|
const path = (0, hosted_routing_js_1.formatRoutePath)(route, { address: resolvedAddress });
|
|
1190
1205
|
const data = await (0, hosted_routing_js_1._tradingRequest)(this, { method: route.method, path });
|
|
1191
|
-
const list = Array.isArray(data)
|
|
1206
|
+
const list = Array.isArray(data)
|
|
1207
|
+
? data
|
|
1208
|
+
: (data && Array.isArray(data.positions) ? data.positions : []);
|
|
1192
1209
|
return list.map((p) => (0, hosted_mappers_js_1.positionFromV0)(p));
|
|
1193
1210
|
}
|
|
1194
1211
|
try {
|
|
@@ -1224,7 +1241,9 @@ class Exchange {
|
|
|
1224
1241
|
const route = hosted_routing_js_1.HOSTED_METHOD_ROUTES.get("fetchBalance");
|
|
1225
1242
|
const path = (0, hosted_routing_js_1.formatRoutePath)(route, { address: resolvedAddress });
|
|
1226
1243
|
const data = await (0, hosted_routing_js_1._tradingRequest)(this, { method: route.method, path });
|
|
1227
|
-
const list = Array.isArray(data)
|
|
1244
|
+
const list = Array.isArray(data)
|
|
1245
|
+
? data
|
|
1246
|
+
: (data && Array.isArray(data.balances) ? data.balances : []);
|
|
1228
1247
|
return list.map((b) => (0, hosted_mappers_js_1.balanceFromV0)(b));
|
|
1229
1248
|
}
|
|
1230
1249
|
try {
|
|
@@ -1791,7 +1810,13 @@ class Exchange {
|
|
|
1791
1810
|
}
|
|
1792
1811
|
throw this.wsTransportUnavailableError("watchAllOrderBooks");
|
|
1793
1812
|
}
|
|
1794
|
-
/**
|
|
1813
|
+
/**
|
|
1814
|
+
* Stream all orderbook updates across venues.
|
|
1815
|
+
*
|
|
1816
|
+
* @deprecated Use {@link watchAllOrderBooks} instead.
|
|
1817
|
+
* @param venues - Optional venue filter
|
|
1818
|
+
* @returns Next event with source, symbol, and orderbook
|
|
1819
|
+
*/
|
|
1795
1820
|
async firehose(venues) {
|
|
1796
1821
|
return this.watchAllOrderBooks(venues);
|
|
1797
1822
|
}
|
|
@@ -1916,8 +1941,11 @@ class Exchange {
|
|
|
1916
1941
|
* const order = await exchange.submitOrder(built);
|
|
1917
1942
|
*
|
|
1918
1943
|
* // Using outcome shorthand:
|
|
1944
|
+
* const yes = market.yes;
|
|
1945
|
+
* if (!yes) throw new Error("Market has no YES outcome");
|
|
1946
|
+
*
|
|
1919
1947
|
* const built2 = await exchange.buildOrder({
|
|
1920
|
-
* outcome:
|
|
1948
|
+
* outcome: yes,
|
|
1921
1949
|
* side: "buy",
|
|
1922
1950
|
* type: "market",
|
|
1923
1951
|
* amount: 10
|
|
@@ -2210,8 +2238,9 @@ class Exchange {
|
|
|
2210
2238
|
const venue = this.exchangeName;
|
|
2211
2239
|
if (venue === "polymarket")
|
|
2212
2240
|
return "cancel_polymarket";
|
|
2213
|
-
if (venue === "limitless")
|
|
2241
|
+
if (venue === "limitless") {
|
|
2214
2242
|
return isPull ? "cancel_limitless_base_pull" : "cancel_limitless_polygon";
|
|
2243
|
+
}
|
|
2215
2244
|
return isPull ? "cancel_opinion_bsc_pull" : "cancel_opinion_polygon";
|
|
2216
2245
|
}
|
|
2217
2246
|
/**
|
|
@@ -2787,6 +2816,71 @@ class Limitless extends Exchange {
|
|
|
2787
2816
|
constructor(options = {}) {
|
|
2788
2817
|
super("limitless", options);
|
|
2789
2818
|
}
|
|
2819
|
+
/**
|
|
2820
|
+
* Watch real-time AMM price updates via WebSocket.
|
|
2821
|
+
*
|
|
2822
|
+
* @param marketAddress - Limitless market contract address
|
|
2823
|
+
* @param callback - Optional callback invoked with the returned update
|
|
2824
|
+
* @returns Next price update
|
|
2825
|
+
*/
|
|
2826
|
+
async watchPrices(marketAddress, callback) {
|
|
2827
|
+
await this.initPromise;
|
|
2828
|
+
try {
|
|
2829
|
+
const json = await this.sidecarPostRequest("watchPrices", [marketAddress]);
|
|
2830
|
+
const data = this.handleResponse(json);
|
|
2831
|
+
callback?.(data);
|
|
2832
|
+
return data;
|
|
2833
|
+
}
|
|
2834
|
+
catch (error) {
|
|
2835
|
+
if (error instanceof errors_js_1.PmxtError)
|
|
2836
|
+
throw error;
|
|
2837
|
+
throw new errors_js_1.PmxtError(`Failed to watch prices: ${error}`);
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
/**
|
|
2841
|
+
* Watch real-time Limitless user position updates.
|
|
2842
|
+
*
|
|
2843
|
+
* Requires API key authentication.
|
|
2844
|
+
*
|
|
2845
|
+
* @param callback - Optional callback invoked with the returned positions
|
|
2846
|
+
* @returns Next position update payload
|
|
2847
|
+
*/
|
|
2848
|
+
async watchUserPositions(callback) {
|
|
2849
|
+
await this.initPromise;
|
|
2850
|
+
try {
|
|
2851
|
+
const json = await this.sidecarPostRequest("watchUserPositions", []);
|
|
2852
|
+
const data = this.handleResponse(json).map(convertPosition);
|
|
2853
|
+
callback?.(data);
|
|
2854
|
+
return data;
|
|
2855
|
+
}
|
|
2856
|
+
catch (error) {
|
|
2857
|
+
if (error instanceof errors_js_1.PmxtError)
|
|
2858
|
+
throw error;
|
|
2859
|
+
throw new errors_js_1.PmxtError(`Failed to watch user positions: ${error}`);
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
/**
|
|
2863
|
+
* Watch real-time Limitless user transaction updates.
|
|
2864
|
+
*
|
|
2865
|
+
* Requires API key authentication.
|
|
2866
|
+
*
|
|
2867
|
+
* @param callback - Optional callback invoked with the returned update
|
|
2868
|
+
* @returns Next transaction update
|
|
2869
|
+
*/
|
|
2870
|
+
async watchUserTransactions(callback) {
|
|
2871
|
+
await this.initPromise;
|
|
2872
|
+
try {
|
|
2873
|
+
const json = await this.sidecarPostRequest("watchUserTransactions", []);
|
|
2874
|
+
const data = this.handleResponse(json);
|
|
2875
|
+
callback?.(data);
|
|
2876
|
+
return data;
|
|
2877
|
+
}
|
|
2878
|
+
catch (error) {
|
|
2879
|
+
if (error instanceof errors_js_1.PmxtError)
|
|
2880
|
+
throw error;
|
|
2881
|
+
throw new errors_js_1.PmxtError(`Failed to watch user transactions: ${error}`);
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2790
2884
|
}
|
|
2791
2885
|
exports.Limitless = Limitless;
|
|
2792
2886
|
/**
|
|
@@ -3053,6 +3147,18 @@ class Rain extends Exchange {
|
|
|
3053
3147
|
}
|
|
3054
3148
|
}
|
|
3055
3149
|
exports.Rain = Rain;
|
|
3150
|
+
/**
|
|
3151
|
+
* Hunch exchange client.
|
|
3152
|
+
*
|
|
3153
|
+
* Hunch is a crypto-native prediction market. Reads are unauthenticated;
|
|
3154
|
+
* trading requires an EVM private key.
|
|
3155
|
+
*/
|
|
3156
|
+
class Hunch extends Exchange {
|
|
3157
|
+
constructor(options = {}) {
|
|
3158
|
+
super("hunch", options);
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
exports.Hunch = Hunch;
|
|
3056
3162
|
/**
|
|
3057
3163
|
* Mock exchange client.
|
|
3058
3164
|
*
|
package/dist/pmxt/escrow.js
CHANGED
|
@@ -12,6 +12,80 @@
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.Escrow = void 0;
|
|
14
14
|
const hosted_routing_1 = require("./hosted-routing");
|
|
15
|
+
const errors_1 = require("./errors");
|
|
16
|
+
const APPROVAL_TOKENS = new Set(["usdc", "ctf"]);
|
|
17
|
+
const WITHDRAW_ACTIONS = new Set(["request", "claim", "cancel"]);
|
|
18
|
+
const USDC_SCALE = 1000000n;
|
|
19
|
+
function isDecimalTokenId(token) {
|
|
20
|
+
return /^[0-9]+$/.test(token);
|
|
21
|
+
}
|
|
22
|
+
function normalizeApprovalToken(token) {
|
|
23
|
+
if (typeof token !== "string") {
|
|
24
|
+
throw new errors_1.ValidationError("token must be 'usdc', 'ctf', or a decimal CTF token_id string", "token");
|
|
25
|
+
}
|
|
26
|
+
const candidate = token.trim();
|
|
27
|
+
const normalized = candidate.toLowerCase();
|
|
28
|
+
if (APPROVAL_TOKENS.has(normalized)) {
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
if (isDecimalTokenId(candidate)) {
|
|
32
|
+
return candidate;
|
|
33
|
+
}
|
|
34
|
+
throw new errors_1.ValidationError("token must be 'usdc', 'ctf', or a decimal CTF token_id string", "token");
|
|
35
|
+
}
|
|
36
|
+
function normalizeAmountWei(amountWei) {
|
|
37
|
+
if (amountWei === undefined) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
if (typeof amountWei !== "bigint") {
|
|
41
|
+
throw new errors_1.ValidationError("amount_wei must be a non-negative integer", "amount_wei");
|
|
42
|
+
}
|
|
43
|
+
if (amountWei < 0n) {
|
|
44
|
+
throw new errors_1.ValidationError("amount_wei must be non-negative", "amount_wei");
|
|
45
|
+
}
|
|
46
|
+
return amountWei.toString();
|
|
47
|
+
}
|
|
48
|
+
function validateUsdcDecimal(value, field) {
|
|
49
|
+
const match = /^([0-9]+)(?:\.([0-9]+))?$/.exec(value);
|
|
50
|
+
if (!match) {
|
|
51
|
+
throw new errors_1.ValidationError(`${field} must be a finite positive number`, field);
|
|
52
|
+
}
|
|
53
|
+
const fractional = match[2] ?? "";
|
|
54
|
+
if (fractional.length > 6) {
|
|
55
|
+
throw new errors_1.ValidationError(`${field} precision exceeds 6 decimals; max precision for USDC is 0.000001`, field);
|
|
56
|
+
}
|
|
57
|
+
const scaled = BigInt(match[1]) * USDC_SCALE + BigInt(fractional.padEnd(6, "0"));
|
|
58
|
+
if (scaled <= 0n) {
|
|
59
|
+
throw new errors_1.ValidationError(`${field} must be positive`, field);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function normalizeUsdcAmount(value, field = "amount") {
|
|
63
|
+
if (typeof value === "bigint") {
|
|
64
|
+
if (value <= 0n) {
|
|
65
|
+
throw new errors_1.ValidationError(`${field} must be positive`, field);
|
|
66
|
+
}
|
|
67
|
+
return value.toString();
|
|
68
|
+
}
|
|
69
|
+
if (typeof value === "number") {
|
|
70
|
+
if (!Number.isFinite(value)) {
|
|
71
|
+
throw new errors_1.ValidationError(`${field} must be a finite positive number`, field);
|
|
72
|
+
}
|
|
73
|
+
validateUsdcDecimal(String(value), field);
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
if (typeof value === "string") {
|
|
77
|
+
const trimmed = value.trim();
|
|
78
|
+
validateUsdcDecimal(trimmed, field);
|
|
79
|
+
return trimmed;
|
|
80
|
+
}
|
|
81
|
+
throw new errors_1.ValidationError(`${field} must be a finite positive number`, field);
|
|
82
|
+
}
|
|
83
|
+
function normalizeWithdrawAction(action) {
|
|
84
|
+
if (typeof action === "string" && WITHDRAW_ACTIONS.has(action)) {
|
|
85
|
+
return action;
|
|
86
|
+
}
|
|
87
|
+
throw new errors_1.ValidationError("action must be 'request', 'claim', or 'cancel'", "action");
|
|
88
|
+
}
|
|
15
89
|
class Escrow {
|
|
16
90
|
client;
|
|
17
91
|
constructor(client) {
|
|
@@ -22,13 +96,16 @@ class Escrow {
|
|
|
22
96
|
* `amountWei` is omitted, the server returns an unlimited approval.
|
|
23
97
|
*/
|
|
24
98
|
async approveTx(token, amountWei) {
|
|
99
|
+
const address = (0, hosted_routing_1.resolveWalletAddress)(this.client);
|
|
100
|
+
const approvalAmount = normalizeAmountWei(amountWei);
|
|
25
101
|
const route = hosted_routing_1.HOSTED_METHOD_ROUTES.get("escrowApproveTx");
|
|
26
102
|
return (0, hosted_routing_1._tradingRequest)(this.client, {
|
|
27
103
|
method: route.method,
|
|
28
104
|
path: route.path,
|
|
29
105
|
body: {
|
|
30
|
-
token,
|
|
31
|
-
|
|
106
|
+
token: normalizeApprovalToken(token),
|
|
107
|
+
user_address: address,
|
|
108
|
+
...(approvalAmount === undefined ? {} : { amount_wei: approvalAmount }),
|
|
32
109
|
},
|
|
33
110
|
});
|
|
34
111
|
}
|
|
@@ -37,12 +114,15 @@ class Escrow {
|
|
|
37
114
|
* grid). Accepts number, decimal string, or BigInt in micro-units.
|
|
38
115
|
*/
|
|
39
116
|
async depositTx(amount) {
|
|
117
|
+
const address = (0, hosted_routing_1.resolveWalletAddress)(this.client);
|
|
40
118
|
const route = hosted_routing_1.HOSTED_METHOD_ROUTES.get("escrowDepositTx");
|
|
41
119
|
return (0, hosted_routing_1._tradingRequest)(this.client, {
|
|
42
120
|
method: route.method,
|
|
43
121
|
path: route.path,
|
|
44
122
|
body: {
|
|
45
|
-
|
|
123
|
+
token: "usdc",
|
|
124
|
+
amount: normalizeUsdcAmount(amount),
|
|
125
|
+
user_address: address,
|
|
46
126
|
},
|
|
47
127
|
});
|
|
48
128
|
}
|
|
@@ -52,16 +132,31 @@ class Escrow {
|
|
|
52
132
|
* the timelock, `cancel` aborts a pending request.
|
|
53
133
|
*/
|
|
54
134
|
async withdrawTx(action, amount) {
|
|
135
|
+
const normalizedAction = normalizeWithdrawAction(action);
|
|
136
|
+
const address = (0, hosted_routing_1.resolveWalletAddress)(this.client);
|
|
55
137
|
const route = hosted_routing_1.HOSTED_METHOD_ROUTES.get("escrowWithdrawTx");
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
138
|
+
if (normalizedAction === "request") {
|
|
139
|
+
if (amount === undefined) {
|
|
140
|
+
throw new errors_1.ValidationError("amount is required when action='request'", "amount");
|
|
141
|
+
}
|
|
142
|
+
return (0, hosted_routing_1._tradingRequest)(this.client, {
|
|
143
|
+
method: route.method,
|
|
144
|
+
path: route.path,
|
|
145
|
+
body: {
|
|
146
|
+
action: normalizedAction,
|
|
147
|
+
token: "usdc",
|
|
148
|
+
amount: normalizeUsdcAmount(amount),
|
|
149
|
+
user_address: address,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (amount !== undefined) {
|
|
154
|
+
throw new errors_1.ValidationError(`amount must be omitted when action='${normalizedAction}'`, "amount");
|
|
155
|
+
}
|
|
61
156
|
return (0, hosted_routing_1._tradingRequest)(this.client, {
|
|
62
157
|
method: route.method,
|
|
63
158
|
path: route.path,
|
|
64
|
-
body: { action,
|
|
159
|
+
body: { action: normalizedAction, token: "usdc", user_address: address },
|
|
65
160
|
});
|
|
66
161
|
}
|
|
67
162
|
/**
|
|
@@ -70,12 +165,16 @@ class Escrow {
|
|
|
70
165
|
*/
|
|
71
166
|
async withdrawals(opts = {}) {
|
|
72
167
|
const address = (0, hosted_routing_1.resolveWalletAddress)(this.client, opts.address);
|
|
168
|
+
const include = (opts.include ?? "pending,events").trim();
|
|
169
|
+
if (!include) {
|
|
170
|
+
throw new errors_1.ValidationError("include must not be empty", "include");
|
|
171
|
+
}
|
|
73
172
|
const route = hosted_routing_1.HOSTED_METHOD_ROUTES.get("escrowWithdrawals");
|
|
74
173
|
const path = (0, hosted_routing_1.formatRoutePath)(route, { address });
|
|
75
174
|
return (0, hosted_routing_1._tradingRequest)(this.client, {
|
|
76
175
|
method: route.method,
|
|
77
176
|
path,
|
|
78
|
-
params: { include
|
|
177
|
+
params: { include },
|
|
79
178
|
});
|
|
80
179
|
}
|
|
81
180
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Layer 3 uses the optional `ethers` peer dependency for typed-data verification.
|
|
10
10
|
*/
|
|
11
11
|
import { TypedData } from "./signers";
|
|
12
|
-
export type HostedRoute = "polymarket_buy" | "polymarket_sell" | "limitless_buy" | "limitless_sell_polygon" | "limitless_sell_base_pull" | "opinion_buy" | "opinion_sell_polygon" | "opinion_sell_bsc_pull" | "cancel_polymarket" | "cancel_opinion_polygon" | "cancel_opinion_bsc_pull";
|
|
12
|
+
export type HostedRoute = "polymarket_buy" | "polymarket_sell" | "limitless_buy" | "limitless_sell_polygon" | "limitless_sell_base_pull" | "opinion_buy" | "opinion_sell_polygon" | "opinion_sell_bsc_pull" | "cancel_polymarket" | "cancel_opinion_polygon" | "cancel_opinion_bsc_pull" | "cancel_limitless_polygon" | "cancel_limitless_base_pull";
|
|
13
13
|
export declare const SECP256K1_HALF_N = 57896044618658097711785492504343953926418782139537452191302581570759080747168n;
|
|
14
14
|
/**
|
|
15
15
|
* Validate the structural shape of a typed-data payload before signing.
|
|
@@ -211,6 +211,20 @@ const SCHEMAS = {
|
|
|
211
211
|
messageKeys: messageKeysFromFields(CANCEL_PULL_FIELDS),
|
|
212
212
|
walletField: "user",
|
|
213
213
|
},
|
|
214
|
+
cancel_limitless_polygon: {
|
|
215
|
+
primaryType: "CancelOrder",
|
|
216
|
+
domain: PREFUNDED_DOMAIN,
|
|
217
|
+
fields: CANCEL_ORDER_FIELDS,
|
|
218
|
+
messageKeys: messageKeysFromFields(CANCEL_ORDER_FIELDS),
|
|
219
|
+
walletField: "user",
|
|
220
|
+
},
|
|
221
|
+
cancel_limitless_base_pull: {
|
|
222
|
+
primaryType: "CancelPull",
|
|
223
|
+
domain: LIMITLESS_VENUE_DOMAIN,
|
|
224
|
+
fields: CANCEL_PULL_FIELDS,
|
|
225
|
+
messageKeys: messageKeysFromFields(CANCEL_PULL_FIELDS),
|
|
226
|
+
walletField: "user",
|
|
227
|
+
},
|
|
214
228
|
};
|
|
215
229
|
// secp256k1 group order / 2, for canonical low-s check.
|
|
216
230
|
exports.SECP256K1_HALF_N = 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0n;
|
package/dist/pmxt/models.d.ts
CHANGED
|
@@ -400,6 +400,10 @@ export interface CreateOrderParams {
|
|
|
400
400
|
amount: number;
|
|
401
401
|
/** Limit price (required for limit orders, 0.0-1.0) */
|
|
402
402
|
price?: number;
|
|
403
|
+
/** Hosted mode: unit that amount is denominated in. Market buys use usdc; market sells and limit orders use shares. */
|
|
404
|
+
denom?: "usdc" | "shares";
|
|
405
|
+
/** Hosted mode: maximum slippage percentage for market orders. */
|
|
406
|
+
slippage_pct?: number;
|
|
403
407
|
/** Optional fee rate (e.g., 1000 for 0.1%) */
|
|
404
408
|
fee?: number;
|
|
405
409
|
/** Optional override for Limitless/Polymarket */
|
|
@@ -409,6 +413,19 @@ export interface CreateOrderParams {
|
|
|
409
413
|
/** Limitless delegated signing: profile ID to trade on behalf of */
|
|
410
414
|
onBehalfOf?: number;
|
|
411
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Public order input accepted by createOrder/buildOrder.
|
|
418
|
+
*
|
|
419
|
+
* Callers can either pass explicit marketId/outcomeId fields, or pass an
|
|
420
|
+
* outcome object returned by fetchMarkets and let the SDK infer those ids.
|
|
421
|
+
*/
|
|
422
|
+
export type CreateOrderInput = (CreateOrderParams & {
|
|
423
|
+
outcome?: never;
|
|
424
|
+
}) | (Omit<CreateOrderParams, 'marketId' | 'outcomeId'> & {
|
|
425
|
+
outcome: MarketOutcome;
|
|
426
|
+
marketId?: never;
|
|
427
|
+
outcomeId?: never;
|
|
428
|
+
});
|
|
412
429
|
/** Alias matching the core MarketFetchParams name. */
|
|
413
430
|
export type MarketFetchParams = MarketFilterParams;
|
|
414
431
|
/**
|
|
@@ -117,12 +117,14 @@ class ServerManager {
|
|
|
117
117
|
* Check if the server is running.
|
|
118
118
|
*/
|
|
119
119
|
async isServerRunning() {
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
const info = this.getServerInfo();
|
|
121
|
+
if (!info?.port) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
122
124
|
try {
|
|
123
125
|
// Use native fetch to check health on the actual running port
|
|
124
126
|
// This avoids issues where this.api is configured with the wrong port
|
|
125
|
-
const response = await fetch(`http://localhost:${port}/health`, {
|
|
127
|
+
const response = await fetch(`http://localhost:${info.port}/health`, {
|
|
126
128
|
signal: AbortSignal.timeout(5_000),
|
|
127
129
|
});
|
|
128
130
|
if (response.ok) {
|
|
@@ -16,35 +16,6 @@ Name | Type
|
|
|
16
16
|
`relation` | string
|
|
17
17
|
`confidence` | number
|
|
18
18
|
|
|
19
|
-
## Example
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import type { ArbitrageOpportunity } from 'pmxtjs'
|
|
23
|
-
|
|
24
|
-
// TODO: Update the object below with actual values
|
|
25
|
-
const example = {
|
|
26
|
-
"marketA": null,
|
|
27
|
-
"marketB": null,
|
|
28
|
-
"spread": null,
|
|
29
|
-
"buyVenue": null,
|
|
30
|
-
"sellVenue": null,
|
|
31
|
-
"buyPrice": null,
|
|
32
|
-
"sellPrice": null,
|
|
33
|
-
"relation": null,
|
|
34
|
-
"confidence": null,
|
|
35
|
-
} satisfies ArbitrageOpportunity
|
|
36
|
-
|
|
37
|
-
console.log(example)
|
|
38
|
-
|
|
39
|
-
// Convert the instance to a JSON string
|
|
40
|
-
const exampleJSON: string = JSON.stringify(example)
|
|
41
|
-
console.log(exampleJSON)
|
|
42
|
-
|
|
43
|
-
// Parse the JSON string back to an object
|
|
44
|
-
const exampleParsed = JSON.parse(exampleJSON) as ArbitrageOpportunity
|
|
45
|
-
console.log(exampleParsed)
|
|
46
|
-
```
|
|
47
|
-
|
|
48
19
|
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
|
|
49
20
|
|
|
50
21
|
|
|
@@ -12,31 +12,6 @@ Name | Type
|
|
|
12
12
|
`locked` | number
|
|
13
13
|
`venue` | string
|
|
14
14
|
|
|
15
|
-
## Example
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import type { Balance } from 'pmxtjs'
|
|
19
|
-
|
|
20
|
-
// TODO: Update the object below with actual values
|
|
21
|
-
const example = {
|
|
22
|
-
"currency": null,
|
|
23
|
-
"total": null,
|
|
24
|
-
"available": null,
|
|
25
|
-
"locked": null,
|
|
26
|
-
"venue": null,
|
|
27
|
-
} satisfies Balance
|
|
28
|
-
|
|
29
|
-
console.log(example)
|
|
30
|
-
|
|
31
|
-
// Convert the instance to a JSON string
|
|
32
|
-
const exampleJSON: string = JSON.stringify(example)
|
|
33
|
-
console.log(exampleJSON)
|
|
34
|
-
|
|
35
|
-
// Parse the JSON string back to an object
|
|
36
|
-
const exampleParsed = JSON.parse(exampleJSON) as Balance
|
|
37
|
-
console.log(exampleParsed)
|
|
38
|
-
```
|
|
39
|
-
|
|
40
15
|
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
|
|
41
16
|
|
|
42
17
|
|
|
@@ -9,27 +9,6 @@ Name | Type
|
|
|
9
9
|
------------ | -------------
|
|
10
10
|
`credentials` | [ExchangeCredentials](ExchangeCredentials.md)
|
|
11
11
|
|
|
12
|
-
## Example
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import type { BaseRequest } from 'pmxtjs'
|
|
16
|
-
|
|
17
|
-
// TODO: Update the object below with actual values
|
|
18
|
-
const example = {
|
|
19
|
-
"credentials": null,
|
|
20
|
-
} satisfies BaseRequest
|
|
21
|
-
|
|
22
|
-
console.log(example)
|
|
23
|
-
|
|
24
|
-
// Convert the instance to a JSON string
|
|
25
|
-
const exampleJSON: string = JSON.stringify(example)
|
|
26
|
-
console.log(exampleJSON)
|
|
27
|
-
|
|
28
|
-
// Parse the JSON string back to an object
|
|
29
|
-
const exampleParsed = JSON.parse(exampleJSON) as BaseRequest
|
|
30
|
-
console.log(exampleParsed)
|
|
31
|
-
```
|
|
32
|
-
|
|
33
12
|
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
|
|
34
13
|
|
|
35
14
|
|
|
@@ -9,28 +9,6 @@ Name | Type
|
|
|
9
9
|
`success` | boolean
|
|
10
10
|
`error` | [ErrorDetail](ErrorDetail.md)
|
|
11
11
|
|
|
12
|
-
## Example
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import type { BaseResponse } from 'pmxtjs'
|
|
16
|
-
|
|
17
|
-
// TODO: Update the object below with actual values
|
|
18
|
-
const example = {
|
|
19
|
-
"success": true,
|
|
20
|
-
"error": null,
|
|
21
|
-
} satisfies BaseResponse
|
|
22
|
-
|
|
23
|
-
console.log(example)
|
|
24
|
-
|
|
25
|
-
// Convert the instance to a JSON string
|
|
26
|
-
const exampleJSON: string = JSON.stringify(example)
|
|
27
|
-
console.log(exampleJSON)
|
|
28
|
-
|
|
29
|
-
// Parse the JSON string back to an object
|
|
30
|
-
const exampleParsed = JSON.parse(exampleJSON) as BaseResponse
|
|
31
|
-
console.log(exampleParsed)
|
|
32
|
-
```
|
|
33
|
-
|
|
34
12
|
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
|
|
35
13
|
|
|
36
14
|
|
|
@@ -10,29 +10,6 @@ Name | Type
|
|
|
10
10
|
`error` | [ErrorDetail](ErrorDetail.md)
|
|
11
11
|
`data` | [BuiltOrder](BuiltOrder.md)
|
|
12
12
|
|
|
13
|
-
## Example
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import type { BuildOrder200Response } from 'pmxtjs'
|
|
17
|
-
|
|
18
|
-
// TODO: Update the object below with actual values
|
|
19
|
-
const example = {
|
|
20
|
-
"success": true,
|
|
21
|
-
"error": null,
|
|
22
|
-
"data": null,
|
|
23
|
-
} satisfies BuildOrder200Response
|
|
24
|
-
|
|
25
|
-
console.log(example)
|
|
26
|
-
|
|
27
|
-
// Convert the instance to a JSON string
|
|
28
|
-
const exampleJSON: string = JSON.stringify(example)
|
|
29
|
-
console.log(exampleJSON)
|
|
30
|
-
|
|
31
|
-
// Parse the JSON string back to an object
|
|
32
|
-
const exampleParsed = JSON.parse(exampleJSON) as BuildOrder200Response
|
|
33
|
-
console.log(exampleParsed)
|
|
34
|
-
```
|
|
35
|
-
|
|
36
13
|
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
|
|
37
14
|
|
|
38
15
|
|