pmxtjs 2.50.11 → 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.
@@ -18,7 +18,7 @@ import { logger } from "./logger.js";
18
18
  // "Cannot find module" errors during the parallel landing window resolve
19
19
  // once the matching files exist.
20
20
  import { HOSTED_TRADING_VENUES, _tradingRequest, resolveWalletAddress, formatRoutePath, HOSTED_METHOD_ROUTES, } from "./hosted-routing.js";
21
- import { orderFromV0, positionFromV0, balanceFromV0, to6dec, } from "./hosted-mappers.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";
@@ -1040,6 +1040,14 @@ export class Exchange {
1040
1040
  }
1041
1041
  async fetchMyTrades(params) {
1042
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
+ }
1043
1051
  try {
1044
1052
  const args = [];
1045
1053
  if (params !== 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)
@@ -1043,6 +1043,14 @@ class Exchange {
1043
1043
  }
1044
1044
  async fetchMyTrades(params) {
1045
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
+ }
1046
1054
  try {
1047
1055
  const args = [];
1048
1056
  if (params !== 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.11",
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.11",
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.11",
46
+ "pmxt-core": "2.50.12",
47
47
  "ws": "^8.18.0"
48
48
  },
49
49
  "peerDependencies": {
package/pmxt/client.ts CHANGED
@@ -1246,6 +1246,14 @@ export abstract class Exchange {
1246
1246
 
1247
1247
  async fetchMyTrades(params?: MyTradesParams): Promise<UserTrade[]> {
1248
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
+ }
1249
1257
  try {
1250
1258
  const args: any[] = [];
1251
1259
  if (params !== undefined) args.push(params);
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}`);