Skip to content

Commit 75a43b2

Browse files
authored
fix: align SDK parity type gaps (#958)
1 parent 518fe8b commit 75a43b2

7 files changed

Lines changed: 71 additions & 11 deletions

File tree

sdks/python/pmxt/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
PaginatedEventsResult,
5757
Order,
5858
BuiltOrder,
59+
CreateOrderParams,
60+
TxPayload,
5961
Position,
6062
Balance,
6163
MarketFilterCriteria,
@@ -82,6 +84,7 @@
8284
PriceComparison,
8385
ArbitrageOpportunity,
8486
SubscribedAddressSnapshot,
87+
SubscriptionOption,
8588
ExecutionPriceResult,
8689
MatchRelation,
8790
ClusterSortOption,
@@ -229,6 +232,8 @@ def restart_server() -> None:
229232
"PaginatedEventsResult",
230233
"Order",
231234
"BuiltOrder",
235+
"CreateOrderParams",
236+
"TxPayload",
232237
"ExecutionPriceResult",
233238
"Position",
234239
"Balance",
@@ -241,6 +246,7 @@ def restart_server() -> None:
241246
"PriceComparison",
242247
"ArbitrageOpportunity",
243248
"SubscribedAddressSnapshot",
249+
"SubscriptionOption",
244250
"MatchRelation",
245251
"ClusterSortOption",
246252
"MatchedClusterSort",

sdks/python/pmxt/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
TradesParams,
5353
FetchOrderBookParams,
5454
SubscribedAddressSnapshot,
55+
SubscriptionOption,
5556
FirehoseEvent,
5657
MatchResult,
5758
EventMatchResult,
@@ -2268,6 +2269,7 @@ def fetch_trades(
22682269
since: Optional[int] = None,
22692270
start: Optional[Union[str, int]] = None,
22702271
end: Optional[Union[str, int]] = None,
2272+
resolution: Optional[str] = None,
22712273
**kwargs
22722274
) -> List[Trade]:
22732275
"""
@@ -2281,6 +2283,7 @@ def fetch_trades(
22812283
since: Return trades since this timestamp (Unix milliseconds)
22822284
start: Start of time range (ISO 8601 string or epoch seconds/ms)
22832285
end: End of time range (ISO 8601 string or epoch seconds/ms)
2286+
resolution: Optional trade resolution/status filter forwarded to the venue
22842287
**kwargs: Additional parameters
22852288
22862289
Returns:
@@ -2302,6 +2305,8 @@ def fetch_trades(
23022305
params_dict["start"] = start
23032306
if end is not None:
23042307
params_dict["end"] = end
2308+
if resolution is not None:
2309+
params_dict["resolution"] = resolution
23052310

23062311
# Add any extra keyword arguments
23072312
for key, value in kwargs.items():
@@ -2663,7 +2668,7 @@ def watch_trades(
26632668
def watch_address(
26642669
self,
26652670
address: str,
2666-
types: Optional[List[str]] = None,
2671+
types: Optional[List[SubscriptionOption]] = None,
26672672
) -> SubscribedAddressSnapshot:
26682673
"""
26692674
Watch real-time updates of a public wallet via WebSocket.

sdks/python/pmxt/feed_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from dataclasses import dataclass, field
1616
from typing import List, Optional, Dict, Any, Tuple
1717

18+
from .errors import PmxtError
19+
1820

1921
@dataclass(frozen=True)
2022
class Ticker:
@@ -190,10 +192,10 @@ def _request(self, url: str, params: Optional[Dict[str, Any]] = None) -> Any:
190192
except urllib.error.HTTPError as e:
191193
body = json.loads(e.read()) if e.fp else {}
192194
msg = body.get("error", e.reason)
193-
raise RuntimeError(f"Feed API error ({e.code}): {msg}") from e
195+
raise PmxtError(f"Feed API error ({e.code}): {msg}") from e
194196

195197
if not body.get("success"):
196-
raise RuntimeError(f"Feed API error: {body.get('error', 'unknown')}")
198+
raise PmxtError(f"Feed API error: {body.get('error', 'unknown')}")
197199
return body["data"]
198200

199201
@staticmethod

sdks/python/pmxt/models.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
OrderSide = Literal["buy", "sell"]
1919
OrderType = Literal["market", "limit"]
2020
OutcomeType = Literal["yes", "no", "up", "down"]
21+
SubscriptionOption = Literal["trades", "positions", "balances"]
2122

2223

2324
@dataclass
@@ -501,7 +502,7 @@ class BuiltOrder:
501502
exchange: str
502503
"""The exchange name this order was built for."""
503504

504-
params: Dict[str, Any]
505+
params: "CreateOrderParams"
505506
"""The original params used to build this order."""
506507

507508
raw: Any
@@ -510,10 +511,28 @@ class BuiltOrder:
510511
signed_order: Optional[Dict[str, Any]] = None
511512
"""For CLOB exchanges (Polymarket): the EIP-712 signed order."""
512513

513-
tx: Optional[Dict[str, Any]] = None
514+
tx: Optional["TxPayload"] = None
514515
"""For on-chain AMM exchanges: the EVM transaction payload."""
515516

516517

518+
class CreateOrderParams(TypedDict, total=False):
519+
"""Parameters used to build or create an order."""
520+
market_id: str
521+
outcome_id: str
522+
side: OrderSide
523+
type: OrderType
524+
amount: float
525+
price: float
526+
fee: int
527+
528+
529+
class TxPayload(TypedDict):
530+
"""EVM transaction payload returned for on-chain AMM orders."""
531+
to: str
532+
data: str
533+
value: str
534+
chainId: int
535+
517536
@dataclass
518537
class Position:
519538
"""A current position in a market.
@@ -767,6 +786,7 @@ class TradesParams(TypedDict, total=False):
767786
until: int
768787
limit: int
769788
cursor: str
789+
resolution: str
770790

771791

772792
class HistoryFilterParams(TypedDict, total=False):
@@ -934,12 +954,12 @@ class MatchedMarketCluster:
934954
confidence: float
935955
"""Cluster confidence score."""
936956

957+
volume_24h: float
958+
"""Total 24-hour volume across markets in the cluster."""
959+
937960
category: Optional[str] = None
938961
"""Canonical category selected by the hosted API."""
939962

940-
volume_24h: Optional[float] = None
941-
"""Total 24-hour volume across markets in the cluster."""
942-
943963
raw_matches: Optional[List[Dict[str, Any]]] = None
944964
"""Pairwise match edges used to build the cluster when requested."""
945965

@@ -963,12 +983,12 @@ class MatchedEventCluster:
963983
confidence: float
964984
"""Cluster confidence score."""
965985

986+
volume_24h: float
987+
"""Total 24-hour volume across events in the cluster."""
988+
966989
category: Optional[str] = None
967990
"""Canonical category selected by the hosted API."""
968991

969-
volume_24h: Optional[float] = None
970-
"""Total 24-hour volume across events in the cluster."""
971-
972992
raw_matches: Optional[List[Dict[str, Any]]] = None
973993
"""Pairwise match edges used to build the cluster when requested."""
974994

sdks/typescript/pmxt/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,9 @@ export abstract class Exchange {
11351135
return this._hostedSubmitOrder(built);
11361136
}
11371137
await this.initPromise;
1138+
if (this.isHosted) {
1139+
throw new PmxtError("submitOrder is not available in hosted mode. Use createOrder instead.");
1140+
}
11381141
try {
11391142
const args: any[] = [];
11401143
args.push(built);

sdks/typescript/pmxt/router.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ export class Router extends Exchange {
224224
marketId?: string;
225225
slug?: string;
226226
url?: string;
227+
query?: string;
228+
category?: string;
227229
relation?: MatchRelation;
228230
minConfidence?: number;
229231
limit?: number;
@@ -234,6 +236,8 @@ export class Router extends Exchange {
234236
marketId?: string;
235237
slug?: string;
236238
url?: string;
239+
query?: string;
240+
category?: string;
237241
relation?: MatchRelation;
238242
minConfidence?: number;
239243
limit?: number;
@@ -246,6 +250,8 @@ export class Router extends Exchange {
246250
if (marketId) query.marketId = marketId;
247251
if (params.slug ?? params.market?.slug) query.slug = params.slug ?? params.market?.slug;
248252
if (params.url) query.url = params.url;
253+
if (params.query) query.query = params.query;
254+
if (params.category) query.category = params.category;
249255
if (params.relation) query.relation = params.relation;
250256
if (params.minConfidence !== undefined) query.minConfidence = params.minConfidence;
251257
if (params.limit !== undefined) query.limit = params.limit;
@@ -274,6 +280,8 @@ export class Router extends Exchange {
274280
marketId?: string;
275281
slug?: string;
276282
url?: string;
283+
query?: string;
284+
category?: string;
277285
relation?: MatchRelation;
278286
minConfidence?: number;
279287
limit?: number;
@@ -284,6 +292,8 @@ export class Router extends Exchange {
284292
marketId?: string;
285293
slug?: string;
286294
url?: string;
295+
query?: string;
296+
category?: string;
287297
relation?: MatchRelation;
288298
minConfidence?: number;
289299
limit?: number;
@@ -303,6 +313,8 @@ export class Router extends Exchange {
303313
event?: UnifiedEvent;
304314
eventId?: string;
305315
slug?: string;
316+
query?: string;
317+
category?: string;
306318
relation?: MatchRelation;
307319
minConfidence?: number;
308320
limit?: number;
@@ -312,6 +324,8 @@ export class Router extends Exchange {
312324
event?: UnifiedEvent;
313325
eventId?: string;
314326
slug?: string;
327+
query?: string;
328+
category?: string;
315329
relation?: MatchRelation;
316330
minConfidence?: number;
317331
limit?: number;
@@ -323,6 +337,8 @@ export class Router extends Exchange {
323337
const eventId = params.eventId ?? (!params.event?.slug ? params.event?.id : undefined);
324338
if (eventId) query.eventId = eventId;
325339
if (params.slug ?? params.event?.slug) query.slug = params.slug ?? params.event?.slug;
340+
if (params.query) query.query = params.query;
341+
if (params.category) query.category = params.category;
326342
if (params.relation) query.relation = params.relation;
327343
if (params.minConfidence !== undefined) query.minConfidence = params.minConfidence;
328344
if (params.limit !== undefined) query.limit = params.limit;

sdks/typescript/scripts/generate-client-methods.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,18 @@ function generateMethod(name, params, config, sf) {
424424
const argsCode = buildArgsLines(params, sf);
425425
const returnCode = buildReturnLines(config);
426426
const { returnTs } = config;
427+
const localOnlyGuard = name === 'submitOrder'
428+
? [
429+
` if (this.isHosted) {`,
430+
` throw new PmxtError("submitOrder is not available in hosted mode. Use createOrder instead.");`,
431+
` }`,
432+
]
433+
: [];
427434

428435
return [
429436
` async ${name}(${sig}): Promise<${returnTs}> {`,
430437
` await this.initPromise;`,
438+
...localOnlyGuard,
431439
` try {`,
432440
` ${argsCode}`,
433441
` const response = await this.fetchWithRetry(\`\${this.resolveBaseUrl()}/api/\${this.exchangeName}/${name}\`, {`,

0 commit comments

Comments
 (0)