pmxtjs 2.33.4 → 2.34.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/generated/src/apis/DefaultApi.d.ts +72 -7
- package/dist/esm/generated/src/apis/DefaultApi.js +107 -6
- package/dist/esm/generated/src/models/ArbitrageOpportunity.d.ts +23 -0
- package/dist/esm/generated/src/models/ArbitrageOpportunity.js +14 -0
- package/dist/esm/generated/src/models/CompareMarketPricesRequest.d.ts +3 -3
- package/dist/esm/generated/src/models/CompareMarketPricesRequest.js +3 -3
- package/dist/esm/generated/src/models/FetchArbitrageParams.d.ts +17 -0
- package/dist/esm/generated/src/models/FetchArbitrageParams.js +12 -0
- package/dist/esm/generated/src/models/FetchEventMatchesParams.d.ts +7 -0
- package/dist/esm/generated/src/models/FetchEventMatchesParams.js +3 -0
- package/dist/esm/generated/src/models/FetchMarketMatches200Response.d.ts +46 -0
- package/dist/esm/generated/src/models/{FetchMatches200Response.js → FetchMarketMatches200Response.js} +8 -8
- package/dist/esm/generated/src/models/FetchMarketMatchesParams.d.ts +86 -0
- package/dist/esm/generated/src/models/{FetchMatchesParams.js → FetchMarketMatchesParams.js} +12 -9
- package/dist/esm/generated/src/models/UnifiedEvent.d.ts +6 -0
- package/dist/esm/generated/src/models/UnifiedEvent.js +2 -0
- package/dist/esm/generated/src/models/UnifiedMarket.d.ts +6 -0
- package/dist/esm/generated/src/models/UnifiedMarket.js +2 -0
- package/dist/esm/generated/src/models/index.d.ts +2 -2
- package/dist/esm/generated/src/models/index.js +2 -2
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/pmxt/client.js +2 -0
- package/dist/esm/pmxt/models.d.ts +66 -0
- package/dist/esm/pmxt/router.d.ts +133 -0
- package/dist/esm/pmxt/router.js +338 -0
- package/dist/generated/src/apis/DefaultApi.d.ts +72 -7
- package/dist/generated/src/apis/DefaultApi.js +108 -7
- package/dist/generated/src/models/ArbitrageOpportunity.d.ts +23 -0
- package/dist/generated/src/models/ArbitrageOpportunity.js +15 -0
- package/dist/generated/src/models/CompareMarketPricesRequest.d.ts +3 -3
- package/dist/generated/src/models/CompareMarketPricesRequest.js +3 -3
- package/dist/generated/src/models/FetchArbitrageParams.d.ts +17 -0
- package/dist/generated/src/models/FetchArbitrageParams.js +13 -0
- package/dist/generated/src/models/FetchEventMatchesParams.d.ts +7 -0
- package/dist/generated/src/models/FetchEventMatchesParams.js +3 -0
- package/dist/generated/src/models/FetchMarketMatches200Response.d.ts +46 -0
- package/dist/generated/src/models/{FetchMatches200Response.js → FetchMarketMatches200Response.js} +13 -13
- package/dist/generated/src/models/FetchMarketMatchesParams.d.ts +86 -0
- package/dist/generated/src/models/{FetchMatchesParams.js → FetchMarketMatchesParams.js} +18 -15
- package/dist/generated/src/models/UnifiedEvent.d.ts +6 -0
- package/dist/generated/src/models/UnifiedEvent.js +2 -0
- package/dist/generated/src/models/UnifiedMarket.d.ts +6 -0
- package/dist/generated/src/models/UnifiedMarket.js +2 -0
- package/dist/generated/src/models/index.d.ts +2 -2
- package/dist/generated/src/models/index.js +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/pmxt/client.js +2 -0
- package/dist/pmxt/models.d.ts +66 -0
- package/dist/pmxt/router.d.ts +133 -0
- package/dist/pmxt/router.js +375 -0
- package/generated/.openapi-generator/FILES +4 -4
- package/generated/docs/ArbitrageOpportunity.md +4 -0
- package/generated/docs/CompareMarketPricesRequest.md +1 -1
- package/generated/docs/DefaultApi.md +112 -10
- package/generated/docs/FetchArbitrageParams.md +2 -0
- package/generated/docs/FetchEventMatchesParams.md +2 -0
- package/generated/docs/{FetchMatches200Response.md → FetchMarketMatches200Response.md} +4 -4
- package/generated/docs/{FetchMatchesParams.md → FetchMarketMatchesParams.md} +6 -4
- package/generated/docs/UnifiedEvent.md +2 -0
- package/generated/docs/UnifiedMarket.md +2 -0
- package/generated/package.json +1 -1
- package/generated/src/apis/DefaultApi.ts +159 -10
- package/generated/src/models/ArbitrageOpportunity.ts +30 -0
- package/generated/src/models/CompareMarketPricesRequest.ts +11 -11
- package/generated/src/models/FetchArbitrageParams.ts +22 -0
- package/generated/src/models/FetchEventMatchesParams.ts +16 -0
- package/generated/src/models/{FetchMatches200Response.ts → FetchMarketMatches200Response.ts} +13 -13
- package/generated/src/models/{FetchMatchesParams.ts → FetchMarketMatchesParams.ts} +36 -20
- package/generated/src/models/UnifiedEvent.ts +8 -0
- package/generated/src/models/UnifiedMarket.ts +8 -0
- package/generated/src/models/index.ts +2 -2
- package/index.ts +3 -0
- package/package.json +2 -2
- package/pmxt/client.ts +2 -0
- package/pmxt/models.ts +97 -0
- package/pmxt/router.ts +385 -0
- package/dist/esm/generated/src/models/FetchMatches200Response.d.ts +0 -46
- package/dist/esm/generated/src/models/FetchMatchesParams.d.ts +0 -79
- package/dist/generated/src/models/FetchMatches200Response.d.ts +0 -46
- package/dist/generated/src/models/FetchMatchesParams.d.ts +0 -79
package/dist/pmxt/models.d.ts
CHANGED
|
@@ -62,6 +62,8 @@ export interface UnifiedMarket {
|
|
|
62
62
|
status?: string;
|
|
63
63
|
/** On-chain contract / condition identifier where applicable (Polymarket conditionId, etc.). */
|
|
64
64
|
contractAddress?: string;
|
|
65
|
+
/** The exchange/venue this market originates from (e.g. 'polymarket', 'kalshi'). Populated by the Router. */
|
|
66
|
+
sourceExchange?: string;
|
|
65
67
|
/** ID of the parent event this market belongs to */
|
|
66
68
|
eventId?: string;
|
|
67
69
|
/** Convenience access to the Yes outcome for binary markets. */
|
|
@@ -375,6 +377,8 @@ export interface UnifiedEvent {
|
|
|
375
377
|
category?: string;
|
|
376
378
|
/** Event tags */
|
|
377
379
|
tags?: string[];
|
|
380
|
+
/** The exchange/venue this event originates from (e.g. 'polymarket', 'kalshi'). Populated by the Router. */
|
|
381
|
+
sourceExchange?: string;
|
|
378
382
|
}
|
|
379
383
|
/**
|
|
380
384
|
* Advanced criteria for filtering markets.
|
|
@@ -483,3 +487,65 @@ export interface SubscribedAddressSnapshot {
|
|
|
483
487
|
/** Unix timestamp (ms) of this snapshot */
|
|
484
488
|
timestamp: number;
|
|
485
489
|
}
|
|
490
|
+
/** Set-theoretic relation between two markets' resolution conditions. */
|
|
491
|
+
export type MatchRelation = 'identity' | 'subset' | 'superset' | 'overlap' | 'disjoint';
|
|
492
|
+
/** A cross-venue market match with relation classification. */
|
|
493
|
+
export interface MatchResult {
|
|
494
|
+
/** The matched market on another venue. */
|
|
495
|
+
market: UnifiedMarket;
|
|
496
|
+
/** Set-theoretic relation between the source and matched market. */
|
|
497
|
+
relation: MatchRelation;
|
|
498
|
+
/** Confidence score (0.0 to 1.0). */
|
|
499
|
+
confidence: number;
|
|
500
|
+
/** Human-readable explanation of the match. */
|
|
501
|
+
reasoning?: string;
|
|
502
|
+
/** Best bid price on the matched venue (when includePrices=true). */
|
|
503
|
+
bestBid?: number;
|
|
504
|
+
/** Best ask price on the matched venue (when includePrices=true). */
|
|
505
|
+
bestAsk?: number;
|
|
506
|
+
}
|
|
507
|
+
/** A cross-venue event match with constituent market matches. */
|
|
508
|
+
export interface EventMatchResult {
|
|
509
|
+
/** The matched event on another venue. */
|
|
510
|
+
event: UnifiedEvent;
|
|
511
|
+
/** Cross-venue market matches within this event. */
|
|
512
|
+
marketMatches: MatchResult[];
|
|
513
|
+
}
|
|
514
|
+
/** Side-by-side price comparison for a matched market. */
|
|
515
|
+
export interface PriceComparison {
|
|
516
|
+
/** The matched market. */
|
|
517
|
+
market: UnifiedMarket;
|
|
518
|
+
/** Relation type (typically 'identity' for price comparisons). */
|
|
519
|
+
relation: MatchRelation;
|
|
520
|
+
/** Confidence score (0.0 to 1.0). */
|
|
521
|
+
confidence: number;
|
|
522
|
+
/** Human-readable explanation. */
|
|
523
|
+
reasoning?: string;
|
|
524
|
+
/** Best bid price on this venue. */
|
|
525
|
+
bestBid?: number;
|
|
526
|
+
/** Best ask price on this venue. */
|
|
527
|
+
bestAsk?: number;
|
|
528
|
+
/** The venue name (e.g. 'kalshi', 'polymarket'). */
|
|
529
|
+
venue: string;
|
|
530
|
+
}
|
|
531
|
+
/** A cross-venue arbitrage opportunity. */
|
|
532
|
+
export interface ArbitrageOpportunity {
|
|
533
|
+
/** Market on the buy side. */
|
|
534
|
+
marketA: UnifiedMarket;
|
|
535
|
+
/** Market on the sell side. */
|
|
536
|
+
marketB: UnifiedMarket;
|
|
537
|
+
/** Price spread (sellPrice - buyPrice). */
|
|
538
|
+
spread: number;
|
|
539
|
+
/** Venue to buy on. */
|
|
540
|
+
buyVenue: string;
|
|
541
|
+
/** Venue to sell on. */
|
|
542
|
+
sellVenue: string;
|
|
543
|
+
/** Price to buy at. */
|
|
544
|
+
buyPrice: number;
|
|
545
|
+
/** Price to sell at. */
|
|
546
|
+
sellPrice: number;
|
|
547
|
+
/** The set-theoretic relation between the two markets (e.g. identity, subset). */
|
|
548
|
+
relation?: MatchRelation;
|
|
549
|
+
/** Match confidence score (0.0 to 1.0). */
|
|
550
|
+
confidence?: number;
|
|
551
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Router — cross-venue intelligence layer.
|
|
3
|
+
*
|
|
4
|
+
* Search, match, compare prices, find hedges, and detect arbitrage across
|
|
5
|
+
* every venue PMXT supports. Only requires a PMXT API key.
|
|
6
|
+
*/
|
|
7
|
+
import { Exchange } from "./client.js";
|
|
8
|
+
import { MatchResult, MatchRelation, EventMatchResult, PriceComparison, ArbitrageOpportunity, UnifiedMarket, UnifiedEvent } from "./models.js";
|
|
9
|
+
/** Options for creating a Router. */
|
|
10
|
+
export interface RouterOptions {
|
|
11
|
+
/** PMXT API key (required for hosted mode). */
|
|
12
|
+
pmxtApiKey?: string;
|
|
13
|
+
/** Override the base URL (defaults to hosted API). */
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
/** Start local sidecar (default: false). */
|
|
16
|
+
autoStartServer?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Cross-venue intelligence layer.
|
|
20
|
+
*
|
|
21
|
+
* Search markets and events across every venue, find semantically
|
|
22
|
+
* equivalent markets on other platforms, compare prices, discover
|
|
23
|
+
* hedges, and scan for arbitrage — all from a single PMXT API key.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import pmxt from "pmxtjs";
|
|
28
|
+
*
|
|
29
|
+
* const router = new pmxt.Router({ pmxtApiKey: "pmxt_live_..." });
|
|
30
|
+
* const markets = await router.fetchMarkets({ query: "election" });
|
|
31
|
+
* const matches = await router.fetchMarketMatches({ market: markets[0] });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class Router extends Exchange {
|
|
35
|
+
constructor(options?: RouterOptions);
|
|
36
|
+
/**
|
|
37
|
+
* Find markets on other venues that correspond to a given market.
|
|
38
|
+
*
|
|
39
|
+
* @param params.market - A UnifiedMarket object (extracts marketId automatically).
|
|
40
|
+
* @param params.marketId - PMXT market ID.
|
|
41
|
+
* @param params.slug - Market slug (alternative to marketId).
|
|
42
|
+
* @param params.url - Market URL on the source venue.
|
|
43
|
+
* @param params.relation - Filter to a specific relation type.
|
|
44
|
+
* @param params.minConfidence - Minimum confidence threshold (0–1).
|
|
45
|
+
* @param params.limit - Maximum number of matches to return.
|
|
46
|
+
* @param params.includePrices - Attach live bestBid/bestAsk to each match.
|
|
47
|
+
*/
|
|
48
|
+
fetchMarketMatches(params?: {
|
|
49
|
+
market?: UnifiedMarket;
|
|
50
|
+
marketId?: string;
|
|
51
|
+
slug?: string;
|
|
52
|
+
url?: string;
|
|
53
|
+
relation?: MatchRelation;
|
|
54
|
+
minConfidence?: number;
|
|
55
|
+
limit?: number;
|
|
56
|
+
includePrices?: boolean;
|
|
57
|
+
}): Promise<MatchResult[]>;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Use {@link fetchMarketMatches} instead.
|
|
60
|
+
*/
|
|
61
|
+
fetchMatches(params?: {
|
|
62
|
+
market?: UnifiedMarket;
|
|
63
|
+
marketId?: string;
|
|
64
|
+
slug?: string;
|
|
65
|
+
url?: string;
|
|
66
|
+
relation?: MatchRelation;
|
|
67
|
+
minConfidence?: number;
|
|
68
|
+
limit?: number;
|
|
69
|
+
includePrices?: boolean;
|
|
70
|
+
}): Promise<MatchResult[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Match an entire event across venues.
|
|
73
|
+
*
|
|
74
|
+
* @param params.event - A UnifiedEvent object (extracts id automatically).
|
|
75
|
+
* @param params.eventId - PMXT event ID.
|
|
76
|
+
* @param params.slug - Event slug.
|
|
77
|
+
* @param params.relation - Filter market matches to a specific relation type.
|
|
78
|
+
* @param params.minConfidence - Minimum confidence threshold (0–1).
|
|
79
|
+
* @param params.limit - Maximum number of event matches to return.
|
|
80
|
+
* @param params.includePrices - Attach live prices to each market match.
|
|
81
|
+
*/
|
|
82
|
+
fetchEventMatches(params?: {
|
|
83
|
+
event?: UnifiedEvent;
|
|
84
|
+
eventId?: string;
|
|
85
|
+
slug?: string;
|
|
86
|
+
relation?: MatchRelation;
|
|
87
|
+
minConfidence?: number;
|
|
88
|
+
limit?: number;
|
|
89
|
+
includePrices?: boolean;
|
|
90
|
+
}): Promise<EventMatchResult[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Compare prices for the same market across venues.
|
|
93
|
+
*
|
|
94
|
+
* @param params.market - A UnifiedMarket object (extracts marketId automatically).
|
|
95
|
+
* @param params.marketId - PMXT market ID.
|
|
96
|
+
* @param params.slug - Market slug.
|
|
97
|
+
* @param params.url - Market URL.
|
|
98
|
+
*/
|
|
99
|
+
compareMarketPrices(params?: {
|
|
100
|
+
market?: UnifiedMarket;
|
|
101
|
+
marketId?: string;
|
|
102
|
+
slug?: string;
|
|
103
|
+
url?: string;
|
|
104
|
+
}): Promise<PriceComparison[]>;
|
|
105
|
+
/**
|
|
106
|
+
* Find markets that partially hedge a position.
|
|
107
|
+
*
|
|
108
|
+
* @param params.market - A UnifiedMarket object (extracts marketId automatically).
|
|
109
|
+
* @param params.marketId - PMXT market ID.
|
|
110
|
+
* @param params.slug - Market slug.
|
|
111
|
+
* @param params.url - Market URL.
|
|
112
|
+
*/
|
|
113
|
+
fetchHedges(params?: {
|
|
114
|
+
market?: UnifiedMarket;
|
|
115
|
+
marketId?: string;
|
|
116
|
+
slug?: string;
|
|
117
|
+
url?: string;
|
|
118
|
+
}): Promise<PriceComparison[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Scan for cross-venue arbitrage opportunities.
|
|
121
|
+
*
|
|
122
|
+
* @param params.minSpread - Only return pairs with spread >= this value.
|
|
123
|
+
* @param params.category - Filter source markets by category.
|
|
124
|
+
* @param params.limit - Max source markets to scan (default: 50).
|
|
125
|
+
* @param params.relations - Relation types to include (default: ['identity']).
|
|
126
|
+
*/
|
|
127
|
+
fetchArbitrage(params?: {
|
|
128
|
+
minSpread?: number;
|
|
129
|
+
category?: string;
|
|
130
|
+
limit?: number;
|
|
131
|
+
relations?: MatchRelation[];
|
|
132
|
+
}): Promise<ArbitrageOpportunity[]>;
|
|
133
|
+
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Router — cross-venue intelligence layer.
|
|
4
|
+
*
|
|
5
|
+
* Search, match, compare prices, find hedges, and detect arbitrage across
|
|
6
|
+
* every venue PMXT supports. Only requires a PMXT API key.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.Router = void 0;
|
|
43
|
+
const client_js_1 = require("./client.js");
|
|
44
|
+
function convertMarket(raw) {
|
|
45
|
+
const outcomes = (raw.outcomes || []).map((o) => ({
|
|
46
|
+
outcomeId: o.outcomeId,
|
|
47
|
+
marketId: o.marketId,
|
|
48
|
+
label: o.label,
|
|
49
|
+
price: o.price,
|
|
50
|
+
priceChange24h: o.priceChange24h,
|
|
51
|
+
metadata: o.metadata,
|
|
52
|
+
}));
|
|
53
|
+
const convertOutcome = (o) => o ? ({
|
|
54
|
+
outcomeId: o.outcomeId,
|
|
55
|
+
marketId: o.marketId,
|
|
56
|
+
label: o.label,
|
|
57
|
+
price: o.price,
|
|
58
|
+
priceChange24h: o.priceChange24h,
|
|
59
|
+
metadata: o.metadata,
|
|
60
|
+
}) : undefined;
|
|
61
|
+
return {
|
|
62
|
+
marketId: raw.marketId,
|
|
63
|
+
title: raw.title,
|
|
64
|
+
slug: raw.slug,
|
|
65
|
+
outcomes,
|
|
66
|
+
volume24h: raw.volume24h || 0,
|
|
67
|
+
liquidity: raw.liquidity || 0,
|
|
68
|
+
url: raw.url,
|
|
69
|
+
description: raw.description,
|
|
70
|
+
resolutionDate: raw.resolutionDate ? new Date(raw.resolutionDate) : undefined,
|
|
71
|
+
volume: raw.volume,
|
|
72
|
+
openInterest: raw.openInterest,
|
|
73
|
+
image: raw.image,
|
|
74
|
+
category: raw.category,
|
|
75
|
+
tags: raw.tags,
|
|
76
|
+
tickSize: raw.tickSize,
|
|
77
|
+
status: raw.status,
|
|
78
|
+
contractAddress: raw.contractAddress,
|
|
79
|
+
sourceExchange: raw.sourceExchange,
|
|
80
|
+
eventId: raw.eventId,
|
|
81
|
+
yes: convertOutcome(raw.yes),
|
|
82
|
+
no: convertOutcome(raw.no),
|
|
83
|
+
up: convertOutcome(raw.up),
|
|
84
|
+
down: convertOutcome(raw.down),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function convertEvent(raw) {
|
|
88
|
+
return {
|
|
89
|
+
id: raw.id,
|
|
90
|
+
title: raw.title,
|
|
91
|
+
description: raw.description,
|
|
92
|
+
slug: raw.slug,
|
|
93
|
+
markets: (raw.markets || []).map(convertMarket),
|
|
94
|
+
volume24h: raw.volume24h,
|
|
95
|
+
volume: raw.volume,
|
|
96
|
+
url: raw.url,
|
|
97
|
+
image: raw.image,
|
|
98
|
+
category: raw.category,
|
|
99
|
+
tags: raw.tags,
|
|
100
|
+
sourceExchange: raw.sourceExchange,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function parseMatchResult(raw) {
|
|
104
|
+
const marketData = raw.market || {};
|
|
105
|
+
return {
|
|
106
|
+
market: convertMarket(marketData),
|
|
107
|
+
relation: raw.relation || 'identity',
|
|
108
|
+
confidence: raw.confidence || 0,
|
|
109
|
+
reasoning: raw.reasoning,
|
|
110
|
+
bestBid: raw.bestBid ?? marketData.bestBid,
|
|
111
|
+
bestAsk: raw.bestAsk ?? marketData.bestAsk,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Cross-venue intelligence layer.
|
|
116
|
+
*
|
|
117
|
+
* Search markets and events across every venue, find semantically
|
|
118
|
+
* equivalent markets on other platforms, compare prices, discover
|
|
119
|
+
* hedges, and scan for arbitrage — all from a single PMXT API key.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import pmxt from "pmxtjs";
|
|
124
|
+
*
|
|
125
|
+
* const router = new pmxt.Router({ pmxtApiKey: "pmxt_live_..." });
|
|
126
|
+
* const markets = await router.fetchMarkets({ query: "election" });
|
|
127
|
+
* const matches = await router.fetchMarketMatches({ market: markets[0] });
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
class Router extends client_js_1.Exchange {
|
|
131
|
+
constructor(options = {}) {
|
|
132
|
+
super("router", options);
|
|
133
|
+
}
|
|
134
|
+
// ------------------------------------------------------------------
|
|
135
|
+
// Matching
|
|
136
|
+
// ------------------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Find markets on other venues that correspond to a given market.
|
|
139
|
+
*
|
|
140
|
+
* @param params.market - A UnifiedMarket object (extracts marketId automatically).
|
|
141
|
+
* @param params.marketId - PMXT market ID.
|
|
142
|
+
* @param params.slug - Market slug (alternative to marketId).
|
|
143
|
+
* @param params.url - Market URL on the source venue.
|
|
144
|
+
* @param params.relation - Filter to a specific relation type.
|
|
145
|
+
* @param params.minConfidence - Minimum confidence threshold (0–1).
|
|
146
|
+
* @param params.limit - Maximum number of matches to return.
|
|
147
|
+
* @param params.includePrices - Attach live bestBid/bestAsk to each match.
|
|
148
|
+
*/
|
|
149
|
+
async fetchMarketMatches(params = {}) {
|
|
150
|
+
await this.initPromise;
|
|
151
|
+
const query = {};
|
|
152
|
+
const marketId = params.marketId ?? params.market?.marketId;
|
|
153
|
+
if (marketId)
|
|
154
|
+
query.marketId = marketId;
|
|
155
|
+
if (params.slug)
|
|
156
|
+
query.slug = params.slug;
|
|
157
|
+
if (params.url)
|
|
158
|
+
query.url = params.url;
|
|
159
|
+
if (params.relation)
|
|
160
|
+
query.relation = params.relation;
|
|
161
|
+
if (params.minConfidence !== undefined)
|
|
162
|
+
query.minConfidence = params.minConfidence;
|
|
163
|
+
if (params.limit !== undefined)
|
|
164
|
+
query.limit = params.limit;
|
|
165
|
+
if (params.includePrices)
|
|
166
|
+
query.includePrices = true;
|
|
167
|
+
try {
|
|
168
|
+
const json = await this.sidecarReadRequest('fetchMatches', query, [query]);
|
|
169
|
+
const data = this.handleResponse(json);
|
|
170
|
+
if (!data)
|
|
171
|
+
return [];
|
|
172
|
+
return data.map(parseMatchResult);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (error instanceof Error)
|
|
176
|
+
throw error;
|
|
177
|
+
throw new Error(`Failed to fetchMarketMatches: ${error}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @deprecated Use {@link fetchMarketMatches} instead.
|
|
182
|
+
*/
|
|
183
|
+
async fetchMatches(params = {}) {
|
|
184
|
+
console.warn('[pmxt] fetchMatches is deprecated, use fetchMarketMatches instead');
|
|
185
|
+
return this.fetchMarketMatches(params);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Match an entire event across venues.
|
|
189
|
+
*
|
|
190
|
+
* @param params.event - A UnifiedEvent object (extracts id automatically).
|
|
191
|
+
* @param params.eventId - PMXT event ID.
|
|
192
|
+
* @param params.slug - Event slug.
|
|
193
|
+
* @param params.relation - Filter market matches to a specific relation type.
|
|
194
|
+
* @param params.minConfidence - Minimum confidence threshold (0–1).
|
|
195
|
+
* @param params.limit - Maximum number of event matches to return.
|
|
196
|
+
* @param params.includePrices - Attach live prices to each market match.
|
|
197
|
+
*/
|
|
198
|
+
async fetchEventMatches(params = {}) {
|
|
199
|
+
await this.initPromise;
|
|
200
|
+
const query = {};
|
|
201
|
+
const eventId = params.eventId ?? params.event?.id;
|
|
202
|
+
if (eventId)
|
|
203
|
+
query.eventId = eventId;
|
|
204
|
+
if (params.slug)
|
|
205
|
+
query.slug = params.slug;
|
|
206
|
+
if (params.relation)
|
|
207
|
+
query.relation = params.relation;
|
|
208
|
+
if (params.minConfidence !== undefined)
|
|
209
|
+
query.minConfidence = params.minConfidence;
|
|
210
|
+
if (params.limit !== undefined)
|
|
211
|
+
query.limit = params.limit;
|
|
212
|
+
if (params.includePrices)
|
|
213
|
+
query.includePrices = true;
|
|
214
|
+
try {
|
|
215
|
+
const json = await this.sidecarReadRequest('fetchEventMatches', query, [query]);
|
|
216
|
+
const data = this.handleResponse(json);
|
|
217
|
+
if (!data)
|
|
218
|
+
return [];
|
|
219
|
+
return data.map((entry) => ({
|
|
220
|
+
event: convertEvent(entry.event || {}),
|
|
221
|
+
marketMatches: (entry.marketMatches || []).map(parseMatchResult),
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
if (error instanceof Error)
|
|
226
|
+
throw error;
|
|
227
|
+
throw new Error(`Failed to fetchEventMatches: ${error}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// ------------------------------------------------------------------
|
|
231
|
+
// Price comparison
|
|
232
|
+
// ------------------------------------------------------------------
|
|
233
|
+
/**
|
|
234
|
+
* Compare prices for the same market across venues.
|
|
235
|
+
*
|
|
236
|
+
* @param params.market - A UnifiedMarket object (extracts marketId automatically).
|
|
237
|
+
* @param params.marketId - PMXT market ID.
|
|
238
|
+
* @param params.slug - Market slug.
|
|
239
|
+
* @param params.url - Market URL.
|
|
240
|
+
*/
|
|
241
|
+
async compareMarketPrices(params = {}) {
|
|
242
|
+
await this.initPromise;
|
|
243
|
+
const query = {};
|
|
244
|
+
const marketId = params.marketId ?? params.market?.marketId;
|
|
245
|
+
if (marketId)
|
|
246
|
+
query.marketId = marketId;
|
|
247
|
+
if (params.slug)
|
|
248
|
+
query.slug = params.slug;
|
|
249
|
+
if (params.url)
|
|
250
|
+
query.url = params.url;
|
|
251
|
+
try {
|
|
252
|
+
const url = `${this.config.basePath}/api/${this.exchangeName}/compareMarketPrices`;
|
|
253
|
+
const response = await fetch(url, {
|
|
254
|
+
method: 'POST',
|
|
255
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
256
|
+
body: JSON.stringify({ args: [query], credentials: this.getCredentials() }),
|
|
257
|
+
});
|
|
258
|
+
if (!response.ok) {
|
|
259
|
+
const body = await response.json().catch(() => ({}));
|
|
260
|
+
if (body.error && typeof body.error === 'object') {
|
|
261
|
+
const { fromServerError } = await Promise.resolve().then(() => __importStar(require('./errors.js')));
|
|
262
|
+
throw fromServerError(body.error);
|
|
263
|
+
}
|
|
264
|
+
throw new Error(body.error?.message || response.statusText);
|
|
265
|
+
}
|
|
266
|
+
const json = await response.json();
|
|
267
|
+
const data = this.handleResponse(json);
|
|
268
|
+
if (!data)
|
|
269
|
+
return [];
|
|
270
|
+
return data.map((r) => ({
|
|
271
|
+
market: convertMarket(r.market || {}),
|
|
272
|
+
relation: r.relation || 'identity',
|
|
273
|
+
confidence: r.confidence || 0,
|
|
274
|
+
reasoning: r.reasoning,
|
|
275
|
+
bestBid: r.bestBid,
|
|
276
|
+
bestAsk: r.bestAsk,
|
|
277
|
+
venue: r.venue || '',
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
if (error instanceof Error)
|
|
282
|
+
throw error;
|
|
283
|
+
throw new Error(`Failed to compareMarketPrices: ${error}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
// ------------------------------------------------------------------
|
|
287
|
+
// Hedging
|
|
288
|
+
// ------------------------------------------------------------------
|
|
289
|
+
/**
|
|
290
|
+
* Find markets that partially hedge a position.
|
|
291
|
+
*
|
|
292
|
+
* @param params.market - A UnifiedMarket object (extracts marketId automatically).
|
|
293
|
+
* @param params.marketId - PMXT market ID.
|
|
294
|
+
* @param params.slug - Market slug.
|
|
295
|
+
* @param params.url - Market URL.
|
|
296
|
+
*/
|
|
297
|
+
async fetchHedges(params = {}) {
|
|
298
|
+
await this.initPromise;
|
|
299
|
+
const query = {};
|
|
300
|
+
const marketId = params.marketId ?? params.market?.marketId;
|
|
301
|
+
if (marketId)
|
|
302
|
+
query.marketId = marketId;
|
|
303
|
+
if (params.slug)
|
|
304
|
+
query.slug = params.slug;
|
|
305
|
+
if (params.url)
|
|
306
|
+
query.url = params.url;
|
|
307
|
+
try {
|
|
308
|
+
const json = await this.sidecarReadRequest('fetchHedges', query, [query]);
|
|
309
|
+
const data = this.handleResponse(json);
|
|
310
|
+
if (!data)
|
|
311
|
+
return [];
|
|
312
|
+
return data.map((r) => ({
|
|
313
|
+
market: convertMarket(r.market || {}),
|
|
314
|
+
relation: r.relation || 'identity',
|
|
315
|
+
confidence: r.confidence || 0,
|
|
316
|
+
reasoning: r.reasoning,
|
|
317
|
+
bestBid: r.bestBid,
|
|
318
|
+
bestAsk: r.bestAsk,
|
|
319
|
+
venue: r.venue || '',
|
|
320
|
+
}));
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
if (error instanceof Error)
|
|
324
|
+
throw error;
|
|
325
|
+
throw new Error(`Failed to fetchHedges: ${error}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// ------------------------------------------------------------------
|
|
329
|
+
// Arbitrage
|
|
330
|
+
// ------------------------------------------------------------------
|
|
331
|
+
/**
|
|
332
|
+
* Scan for cross-venue arbitrage opportunities.
|
|
333
|
+
*
|
|
334
|
+
* @param params.minSpread - Only return pairs with spread >= this value.
|
|
335
|
+
* @param params.category - Filter source markets by category.
|
|
336
|
+
* @param params.limit - Max source markets to scan (default: 50).
|
|
337
|
+
* @param params.relations - Relation types to include (default: ['identity']).
|
|
338
|
+
*/
|
|
339
|
+
async fetchArbitrage(params = {}) {
|
|
340
|
+
await this.initPromise;
|
|
341
|
+
const query = {};
|
|
342
|
+
if (params.minSpread !== undefined)
|
|
343
|
+
query.minSpread = params.minSpread;
|
|
344
|
+
if (params.category)
|
|
345
|
+
query.category = params.category;
|
|
346
|
+
if (params.limit !== undefined)
|
|
347
|
+
query.limit = params.limit;
|
|
348
|
+
if (params.relations && params.relations.length > 0) {
|
|
349
|
+
query.relations = params.relations.join(',');
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
const json = await this.sidecarReadRequest('fetchArbitrage', query, [query]);
|
|
353
|
+
const data = this.handleResponse(json);
|
|
354
|
+
if (!data)
|
|
355
|
+
return [];
|
|
356
|
+
return data.map((r) => ({
|
|
357
|
+
marketA: convertMarket(r.marketA || {}),
|
|
358
|
+
marketB: convertMarket(r.marketB || {}),
|
|
359
|
+
spread: r.spread || 0,
|
|
360
|
+
buyVenue: r.buyVenue || '',
|
|
361
|
+
sellVenue: r.sellVenue || '',
|
|
362
|
+
buyPrice: r.buyPrice || 0,
|
|
363
|
+
sellPrice: r.sellPrice || 0,
|
|
364
|
+
relation: r.relation,
|
|
365
|
+
confidence: r.confidence,
|
|
366
|
+
}));
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
if (error instanceof Error)
|
|
370
|
+
throw error;
|
|
371
|
+
throw new Error(`Failed to fetchArbitrage: ${error}`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
exports.Router = Router;
|
|
@@ -35,10 +35,10 @@ docs/FetchEventMatches200Response.md
|
|
|
35
35
|
docs/FetchEventMatchesParams.md
|
|
36
36
|
docs/FetchEvents200Response.md
|
|
37
37
|
docs/FetchMarket200Response.md
|
|
38
|
+
docs/FetchMarketMatches200Response.md
|
|
39
|
+
docs/FetchMarketMatchesParams.md
|
|
38
40
|
docs/FetchMarkets200Response.md
|
|
39
41
|
docs/FetchMarketsPaginated200Response.md
|
|
40
|
-
docs/FetchMatches200Response.md
|
|
41
|
-
docs/FetchMatchesParams.md
|
|
42
42
|
docs/FetchMyTrades200Response.md
|
|
43
43
|
docs/FetchOHLCV200Response.md
|
|
44
44
|
docs/FetchOpenOrders200Response.md
|
|
@@ -128,10 +128,10 @@ src/models/FetchEventMatches200Response.ts
|
|
|
128
128
|
src/models/FetchEventMatchesParams.ts
|
|
129
129
|
src/models/FetchEvents200Response.ts
|
|
130
130
|
src/models/FetchMarket200Response.ts
|
|
131
|
+
src/models/FetchMarketMatches200Response.ts
|
|
132
|
+
src/models/FetchMarketMatchesParams.ts
|
|
131
133
|
src/models/FetchMarkets200Response.ts
|
|
132
134
|
src/models/FetchMarketsPaginated200Response.ts
|
|
133
|
-
src/models/FetchMatches200Response.ts
|
|
134
|
-
src/models/FetchMatchesParams.ts
|
|
135
135
|
src/models/FetchMyTrades200Response.ts
|
|
136
136
|
src/models/FetchOHLCV200Response.ts
|
|
137
137
|
src/models/FetchOpenOrders200Response.ts
|
|
@@ -13,6 +13,8 @@ Name | Type
|
|
|
13
13
|
`sellVenue` | string
|
|
14
14
|
`buyPrice` | number
|
|
15
15
|
`sellPrice` | number
|
|
16
|
+
`relation` | string
|
|
17
|
+
`confidence` | number
|
|
16
18
|
|
|
17
19
|
## Example
|
|
18
20
|
|
|
@@ -28,6 +30,8 @@ const example = {
|
|
|
28
30
|
"sellVenue": null,
|
|
29
31
|
"buyPrice": null,
|
|
30
32
|
"sellPrice": null,
|
|
33
|
+
"relation": null,
|
|
34
|
+
"confidence": null,
|
|
31
35
|
} satisfies ArbitrageOpportunity
|
|
32
36
|
|
|
33
37
|
console.log(example)
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Name | Type
|
|
8
8
|
------------ | -------------
|
|
9
|
-
`args` | [Array<
|
|
9
|
+
`args` | [Array<FetchMarketMatchesParams>](FetchMarketMatchesParams.md)
|
|
10
10
|
`credentials` | [ExchangeCredentials](ExchangeCredentials.md)
|
|
11
11
|
|
|
12
12
|
## Example
|