pmxtjs 2.50.10 → 2.50.12

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.
@@ -17,8 +17,8 @@ import { logger } from "./logger.js";
17
17
  // import names below are the conventional ones from the plan. Cross-module
18
18
  // "Cannot find module" errors during the parallel landing window resolve
19
19
  // once the matching files exist.
20
- import { HOSTED_TRADING_VENUES, _tradingRequest, HOSTED_METHOD_ROUTES, } from "./hosted-routing.js";
21
- import { orderFromV0, to6dec, } from "./hosted-mappers.js";
20
+ import { HOSTED_TRADING_VENUES, _tradingRequest, resolveWalletAddress, formatRoutePath, HOSTED_METHOD_ROUTES, } from "./hosted-routing.js";
21
+ import { orderFromV0, positionFromV0, balanceFromV0, userTradeFromV0, to6dec, } from "./hosted-mappers.js";
22
22
  import { validateTypedData, validateEconomics, verifySignature, } from "./hosted-typed-data.js";
23
23
  import { EthersSigner } from "./signers.js";
24
24
  import { Escrow } from "./escrow.js";
@@ -979,6 +979,12 @@ export class Exchange {
979
979
  }
980
980
  async fetchOrder(orderId) {
981
981
  await this.initPromise;
982
+ if (this.isHosted) {
983
+ const route = HOSTED_METHOD_ROUTES.get("fetchOrder");
984
+ const path = formatRoutePath(route, { order_id: orderId });
985
+ const data = await _tradingRequest(this, { method: route.method, path });
986
+ return orderFromV0(data);
987
+ }
982
988
  try {
983
989
  const args = [];
984
990
  args.push(orderId);
@@ -1034,6 +1040,14 @@ export class Exchange {
1034
1040
  }
1035
1041
  async fetchMyTrades(params) {
1036
1042
  await this.initPromise;
1043
+ if (this.isHosted) {
1044
+ const resolvedAddress = resolveWalletAddress(this, undefined);
1045
+ const route = HOSTED_METHOD_ROUTES.get("fetchMyTrades");
1046
+ const path = formatRoutePath(route, { address: resolvedAddress });
1047
+ const data = await _tradingRequest(this, { method: route.method, path });
1048
+ const list = Array.isArray(data) ? data : (data && Array.isArray(data.trades) ? data.trades : []);
1049
+ return list.map((t) => userTradeFromV0(t));
1050
+ }
1037
1051
  try {
1038
1052
  const args = [];
1039
1053
  if (params !== undefined)
@@ -1118,6 +1132,14 @@ export class Exchange {
1118
1132
  }
1119
1133
  async fetchPositions(address) {
1120
1134
  await this.initPromise;
1135
+ if (this.isHosted) {
1136
+ const resolvedAddress = resolveWalletAddress(this, address);
1137
+ const route = HOSTED_METHOD_ROUTES.get("fetchPositions");
1138
+ const path = formatRoutePath(route, { address: resolvedAddress });
1139
+ const data = await _tradingRequest(this, { method: route.method, path });
1140
+ const list = Array.isArray(data) ? data : [];
1141
+ return list.map((p) => positionFromV0(p));
1142
+ }
1121
1143
  try {
1122
1144
  const args = [];
1123
1145
  if (address !== undefined)
@@ -1146,6 +1168,14 @@ export class Exchange {
1146
1168
  }
1147
1169
  async fetchBalance(address) {
1148
1170
  await this.initPromise;
1171
+ if (this.isHosted) {
1172
+ const resolvedAddress = resolveWalletAddress(this, address);
1173
+ const route = HOSTED_METHOD_ROUTES.get("fetchBalance");
1174
+ const path = formatRoutePath(route, { address: resolvedAddress });
1175
+ const data = await _tradingRequest(this, { method: route.method, path });
1176
+ const list = Array.isArray(data) ? data : [];
1177
+ return list.map((b) => balanceFromV0(b));
1178
+ }
1149
1179
  try {
1150
1180
  const args = [];
1151
1181
  if (address !== undefined)
@@ -328,15 +328,27 @@ export class Router extends Exchange {
328
328
  const data = this.handleResponse(json);
329
329
  if (!data)
330
330
  return [];
331
- return data.map((r) => ({
332
- market: convertMarket(r.market || {}),
333
- relation: r.relation || 'identity',
334
- confidence: r.confidence || 0,
335
- reasoning: r.reasoning,
336
- bestBid: r.bestBid,
337
- bestAsk: r.bestAsk,
338
- venue: r.venue || '',
339
- }));
331
+ return data.map((r) => {
332
+ const marketPayload = r.market || {};
333
+ const market = convertMarket(marketPayload);
334
+ // Hosted /api/router response carries the live bid/ask on the
335
+ // nested market (and the venue via market.sourceExchange). The
336
+ // top-level bestBid/bestAsk/venue fields are legacy and often
337
+ // null on the wire, so prefer the market fields and fall back
338
+ // to the top-level only when needed.
339
+ const bestBid = r.bestBid ?? market.bestBid ?? marketPayload.bestBid ?? null;
340
+ const bestAsk = r.bestAsk ?? market.bestAsk ?? marketPayload.bestAsk ?? null;
341
+ const venue = r.venue || market.sourceExchange || marketPayload.sourceExchange || '';
342
+ return {
343
+ market,
344
+ relation: r.relation || 'identity',
345
+ confidence: r.confidence || 0,
346
+ reasoning: r.reasoning,
347
+ bestBid,
348
+ bestAsk,
349
+ venue,
350
+ };
351
+ });
340
352
  }
341
353
  catch (error) {
342
354
  if (error instanceof Error)
@@ -360,15 +372,22 @@ export class Router extends Exchange {
360
372
  const data = this.handleResponse(json);
361
373
  if (!data)
362
374
  return [];
363
- return data.map((r) => ({
364
- market: convertMarket(r.market || {}),
365
- relation: r.relation || 'identity',
366
- confidence: r.confidence || 0,
367
- reasoning: r.reasoning,
368
- bestBid: r.bestBid,
369
- bestAsk: r.bestAsk,
370
- venue: r.venue || '',
371
- }));
375
+ return data.map((r) => {
376
+ const marketPayload = r.market || {};
377
+ const market = convertMarket(marketPayload);
378
+ const bestBid = r.bestBid ?? market.bestBid ?? marketPayload.bestBid ?? null;
379
+ const bestAsk = r.bestAsk ?? market.bestAsk ?? marketPayload.bestAsk ?? null;
380
+ const venue = r.venue || market.sourceExchange || marketPayload.sourceExchange || '';
381
+ return {
382
+ market,
383
+ relation: r.relation || 'identity',
384
+ confidence: r.confidence || 0,
385
+ reasoning: r.reasoning,
386
+ bestBid,
387
+ bestAsk,
388
+ venue,
389
+ };
390
+ });
372
391
  }
373
392
  catch (error) {
374
393
  if (error instanceof Error)
@@ -982,6 +982,12 @@ class Exchange {
982
982
  }
983
983
  async fetchOrder(orderId) {
984
984
  await this.initPromise;
985
+ if (this.isHosted) {
986
+ const route = hosted_routing_js_1.HOSTED_METHOD_ROUTES.get("fetchOrder");
987
+ const path = (0, hosted_routing_js_1.formatRoutePath)(route, { order_id: orderId });
988
+ const data = await (0, hosted_routing_js_1._tradingRequest)(this, { method: route.method, path });
989
+ return (0, hosted_mappers_js_1.orderFromV0)(data);
990
+ }
985
991
  try {
986
992
  const args = [];
987
993
  args.push(orderId);
@@ -1037,6 +1043,14 @@ class Exchange {
1037
1043
  }
1038
1044
  async fetchMyTrades(params) {
1039
1045
  await this.initPromise;
1046
+ if (this.isHosted) {
1047
+ const resolvedAddress = (0, hosted_routing_js_1.resolveWalletAddress)(this, undefined);
1048
+ const route = hosted_routing_js_1.HOSTED_METHOD_ROUTES.get("fetchMyTrades");
1049
+ const path = (0, hosted_routing_js_1.formatRoutePath)(route, { address: resolvedAddress });
1050
+ const data = await (0, hosted_routing_js_1._tradingRequest)(this, { method: route.method, path });
1051
+ const list = Array.isArray(data) ? data : (data && Array.isArray(data.trades) ? data.trades : []);
1052
+ return list.map((t) => (0, hosted_mappers_js_1.userTradeFromV0)(t));
1053
+ }
1040
1054
  try {
1041
1055
  const args = [];
1042
1056
  if (params !== undefined)
@@ -1121,6 +1135,14 @@ class Exchange {
1121
1135
  }
1122
1136
  async fetchPositions(address) {
1123
1137
  await this.initPromise;
1138
+ if (this.isHosted) {
1139
+ const resolvedAddress = (0, hosted_routing_js_1.resolveWalletAddress)(this, address);
1140
+ const route = hosted_routing_js_1.HOSTED_METHOD_ROUTES.get("fetchPositions");
1141
+ const path = (0, hosted_routing_js_1.formatRoutePath)(route, { address: resolvedAddress });
1142
+ const data = await (0, hosted_routing_js_1._tradingRequest)(this, { method: route.method, path });
1143
+ const list = Array.isArray(data) ? data : [];
1144
+ return list.map((p) => (0, hosted_mappers_js_1.positionFromV0)(p));
1145
+ }
1124
1146
  try {
1125
1147
  const args = [];
1126
1148
  if (address !== undefined)
@@ -1149,6 +1171,14 @@ class Exchange {
1149
1171
  }
1150
1172
  async fetchBalance(address) {
1151
1173
  await this.initPromise;
1174
+ if (this.isHosted) {
1175
+ const resolvedAddress = (0, hosted_routing_js_1.resolveWalletAddress)(this, address);
1176
+ const route = hosted_routing_js_1.HOSTED_METHOD_ROUTES.get("fetchBalance");
1177
+ const path = (0, hosted_routing_js_1.formatRoutePath)(route, { address: resolvedAddress });
1178
+ const data = await (0, hosted_routing_js_1._tradingRequest)(this, { method: route.method, path });
1179
+ const list = Array.isArray(data) ? data : [];
1180
+ return list.map((b) => (0, hosted_mappers_js_1.balanceFromV0)(b));
1181
+ }
1152
1182
  try {
1153
1183
  const args = [];
1154
1184
  if (address !== undefined)
@@ -364,15 +364,27 @@ class Router extends client_js_1.Exchange {
364
364
  const data = this.handleResponse(json);
365
365
  if (!data)
366
366
  return [];
367
- return data.map((r) => ({
368
- market: convertMarket(r.market || {}),
369
- relation: r.relation || 'identity',
370
- confidence: r.confidence || 0,
371
- reasoning: r.reasoning,
372
- bestBid: r.bestBid,
373
- bestAsk: r.bestAsk,
374
- venue: r.venue || '',
375
- }));
367
+ return data.map((r) => {
368
+ const marketPayload = r.market || {};
369
+ const market = convertMarket(marketPayload);
370
+ // Hosted /api/router response carries the live bid/ask on the
371
+ // nested market (and the venue via market.sourceExchange). The
372
+ // top-level bestBid/bestAsk/venue fields are legacy and often
373
+ // null on the wire, so prefer the market fields and fall back
374
+ // to the top-level only when needed.
375
+ const bestBid = r.bestBid ?? market.bestBid ?? marketPayload.bestBid ?? null;
376
+ const bestAsk = r.bestAsk ?? market.bestAsk ?? marketPayload.bestAsk ?? null;
377
+ const venue = r.venue || market.sourceExchange || marketPayload.sourceExchange || '';
378
+ return {
379
+ market,
380
+ relation: r.relation || 'identity',
381
+ confidence: r.confidence || 0,
382
+ reasoning: r.reasoning,
383
+ bestBid,
384
+ bestAsk,
385
+ venue,
386
+ };
387
+ });
376
388
  }
377
389
  catch (error) {
378
390
  if (error instanceof Error)
@@ -396,15 +408,22 @@ class Router extends client_js_1.Exchange {
396
408
  const data = this.handleResponse(json);
397
409
  if (!data)
398
410
  return [];
399
- return data.map((r) => ({
400
- market: convertMarket(r.market || {}),
401
- relation: r.relation || 'identity',
402
- confidence: r.confidence || 0,
403
- reasoning: r.reasoning,
404
- bestBid: r.bestBid,
405
- bestAsk: r.bestAsk,
406
- venue: r.venue || '',
407
- }));
411
+ return data.map((r) => {
412
+ const marketPayload = r.market || {};
413
+ const market = convertMarket(marketPayload);
414
+ const bestBid = r.bestBid ?? market.bestBid ?? marketPayload.bestBid ?? null;
415
+ const bestAsk = r.bestAsk ?? market.bestAsk ?? marketPayload.bestAsk ?? null;
416
+ const venue = r.venue || market.sourceExchange || marketPayload.sourceExchange || '';
417
+ return {
418
+ market,
419
+ relation: r.relation || 'identity',
420
+ confidence: r.confidence || 0,
421
+ reasoning: r.reasoning,
422
+ bestBid,
423
+ bestAsk,
424
+ venue,
425
+ };
426
+ });
408
427
  }
409
428
  catch (error) {
410
429
  if (error instanceof Error)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.50.10",
3
+ "version": "2.50.12",
4
4
  "description": "OpenAPI client for pmxtjs",
5
5
  "author": "OpenAPI-Generator",
6
6
  "repository": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.50.10",
3
+ "version": "2.50.12",
4
4
  "description": "Unified prediction market data API - The ccxt for prediction markets",
5
5
  "author": "PMXT Contributors",
6
6
  "repository": {
@@ -43,7 +43,7 @@
43
43
  "unified"
44
44
  ],
45
45
  "dependencies": {
46
- "pmxt-core": "2.50.10",
46
+ "pmxt-core": "2.50.12",
47
47
  "ws": "^8.18.0"
48
48
  },
49
49
  "peerDependencies": {
package/pmxt/client.ts CHANGED
@@ -1188,6 +1188,12 @@ export abstract class Exchange {
1188
1188
 
1189
1189
  async fetchOrder(orderId: string): Promise<Order> {
1190
1190
  await this.initPromise;
1191
+ if (this.isHosted) {
1192
+ const route = HOSTED_METHOD_ROUTES.get("fetchOrder")!;
1193
+ const path = formatRoutePath(route, { order_id: orderId });
1194
+ const data = await _tradingRequest(this, { method: route.method, path });
1195
+ return orderFromV0(data as Record<string, unknown>);
1196
+ }
1191
1197
  try {
1192
1198
  const args: any[] = [];
1193
1199
  args.push(orderId);
@@ -1240,6 +1246,14 @@ export abstract class Exchange {
1240
1246
 
1241
1247
  async fetchMyTrades(params?: MyTradesParams): Promise<UserTrade[]> {
1242
1248
  await this.initPromise;
1249
+ if (this.isHosted) {
1250
+ const resolvedAddress = resolveWalletAddress(this, undefined);
1251
+ const route = HOSTED_METHOD_ROUTES.get("fetchMyTrades")!;
1252
+ const path = formatRoutePath(route, { address: resolvedAddress });
1253
+ const data = await _tradingRequest(this, { method: route.method, path });
1254
+ const list = Array.isArray(data) ? data : (data && Array.isArray((data as any).trades) ? (data as any).trades : []);
1255
+ return list.map((t: unknown) => userTradeFromV0(t as Record<string, unknown>));
1256
+ }
1243
1257
  try {
1244
1258
  const args: any[] = [];
1245
1259
  if (params !== undefined) args.push(params);
@@ -1318,6 +1332,14 @@ export abstract class Exchange {
1318
1332
 
1319
1333
  async fetchPositions(address?: string): Promise<Position[]> {
1320
1334
  await this.initPromise;
1335
+ if (this.isHosted) {
1336
+ const resolvedAddress = resolveWalletAddress(this, address);
1337
+ const route = HOSTED_METHOD_ROUTES.get("fetchPositions")!;
1338
+ const path = formatRoutePath(route, { address: resolvedAddress });
1339
+ const data = await _tradingRequest(this, { method: route.method, path });
1340
+ const list = Array.isArray(data) ? data : [];
1341
+ return list.map((p) => positionFromV0(p as Record<string, unknown>));
1342
+ }
1321
1343
  try {
1322
1344
  const args: any[] = [];
1323
1345
  if (address !== undefined) args.push(address);
@@ -1344,6 +1366,14 @@ export abstract class Exchange {
1344
1366
 
1345
1367
  async fetchBalance(address?: string): Promise<Balance[]> {
1346
1368
  await this.initPromise;
1369
+ if (this.isHosted) {
1370
+ const resolvedAddress = resolveWalletAddress(this, address);
1371
+ const route = HOSTED_METHOD_ROUTES.get("fetchBalance")!;
1372
+ const path = formatRoutePath(route, { address: resolvedAddress });
1373
+ const data = await _tradingRequest(this, { method: route.method, path });
1374
+ const list = Array.isArray(data) ? data : [];
1375
+ return list.map((b) => balanceFromV0(b as Record<string, unknown>));
1376
+ }
1347
1377
  try {
1348
1378
  const args: any[] = [];
1349
1379
  if (address !== undefined) args.push(address);
package/pmxt/router.ts CHANGED
@@ -491,15 +491,30 @@ export class Router extends Exchange {
491
491
  const json = await response.json();
492
492
  const data = this.handleResponse(json);
493
493
  if (!data) return [];
494
- return (data as any[]).map((r) => ({
495
- market: convertMarket(r.market || {}),
496
- relation: r.relation || 'identity',
497
- confidence: r.confidence || 0,
498
- reasoning: r.reasoning,
499
- bestBid: r.bestBid,
500
- bestAsk: r.bestAsk,
501
- venue: r.venue || '',
502
- }));
494
+ return (data as any[]).map((r) => {
495
+ const marketPayload = r.market || {};
496
+ const market = convertMarket(marketPayload);
497
+ // Hosted /api/router response carries the live bid/ask on the
498
+ // nested market (and the venue via market.sourceExchange). The
499
+ // top-level bestBid/bestAsk/venue fields are legacy and often
500
+ // null on the wire, so prefer the market fields and fall back
501
+ // to the top-level only when needed.
502
+ const bestBid =
503
+ r.bestBid ?? (market as any).bestBid ?? marketPayload.bestBid ?? null;
504
+ const bestAsk =
505
+ r.bestAsk ?? (market as any).bestAsk ?? marketPayload.bestAsk ?? null;
506
+ const venue =
507
+ r.venue || (market as any).sourceExchange || marketPayload.sourceExchange || '';
508
+ return {
509
+ market,
510
+ relation: r.relation || 'identity',
511
+ confidence: r.confidence || 0,
512
+ reasoning: r.reasoning,
513
+ bestBid,
514
+ bestAsk,
515
+ venue,
516
+ };
517
+ });
503
518
  } catch (error) {
504
519
  if (error instanceof Error) throw error;
505
520
  throw new Error(`Failed to compareMarketPrices: ${error}`);
@@ -540,15 +555,25 @@ export class Router extends Exchange {
540
555
  const json = await this.sidecarReadRequest('fetchHedges', query, [query]);
541
556
  const data = this.handleResponse(json);
542
557
  if (!data) return [];
543
- return (data as any[]).map((r) => ({
544
- market: convertMarket(r.market || {}),
545
- relation: r.relation || 'identity',
546
- confidence: r.confidence || 0,
547
- reasoning: r.reasoning,
548
- bestBid: r.bestBid,
549
- bestAsk: r.bestAsk,
550
- venue: r.venue || '',
551
- }));
558
+ return (data as any[]).map((r) => {
559
+ const marketPayload = r.market || {};
560
+ const market = convertMarket(marketPayload);
561
+ const bestBid =
562
+ r.bestBid ?? (market as any).bestBid ?? marketPayload.bestBid ?? null;
563
+ const bestAsk =
564
+ r.bestAsk ?? (market as any).bestAsk ?? marketPayload.bestAsk ?? null;
565
+ const venue =
566
+ r.venue || (market as any).sourceExchange || marketPayload.sourceExchange || '';
567
+ return {
568
+ market,
569
+ relation: r.relation || 'identity',
570
+ confidence: r.confidence || 0,
571
+ reasoning: r.reasoning,
572
+ bestBid,
573
+ bestAsk,
574
+ venue,
575
+ };
576
+ });
552
577
  } catch (error) {
553
578
  if (error instanceof Error) throw error;
554
579
  throw new Error(`Failed to fetchHedges: ${error}`);