pmxtjs 2.48.6 → 2.49.1

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.
Files changed (129) hide show
  1. package/README.md +72 -10
  2. package/dist/esm/generated/src/models/Balance.d.ts +6 -0
  3. package/dist/esm/generated/src/models/Balance.js +2 -0
  4. package/dist/esm/generated/src/models/BuiltOrder.d.ts +6 -0
  5. package/dist/esm/generated/src/models/BuiltOrder.js +2 -0
  6. package/dist/esm/generated/src/models/ErrorDetail.d.ts +58 -2
  7. package/dist/esm/generated/src/models/ErrorDetail.js +37 -0
  8. package/dist/esm/generated/src/models/ExchangeOptions.d.ts +70 -0
  9. package/dist/esm/generated/src/models/ExchangeOptions.js +53 -0
  10. package/dist/esm/generated/src/models/MatchedMarketPair.d.ts +1 -1
  11. package/dist/esm/generated/src/models/Order.d.ts +18 -0
  12. package/dist/esm/generated/src/models/Order.js +6 -0
  13. package/dist/esm/generated/src/models/OrderLevel.d.ts +6 -0
  14. package/dist/esm/generated/src/models/OrderLevel.js +2 -0
  15. package/dist/esm/generated/src/models/Position.d.ts +33 -9
  16. package/dist/esm/generated/src/models/Position.js +12 -12
  17. package/dist/esm/generated/src/models/UnifiedSeries.d.ts +4 -4
  18. package/dist/esm/generated/src/models/UserTrade.d.ts +18 -0
  19. package/dist/esm/generated/src/models/UserTrade.js +6 -0
  20. package/dist/esm/generated/src/models/index.d.ts +1 -0
  21. package/dist/esm/generated/src/models/index.js +1 -0
  22. package/dist/esm/index.d.ts +2 -0
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/pmxt/client.d.ts +106 -5
  25. package/dist/esm/pmxt/client.js +400 -6
  26. package/dist/esm/pmxt/constants.d.ts +11 -0
  27. package/dist/esm/pmxt/constants.js +13 -0
  28. package/dist/esm/pmxt/errors.d.ts +3 -0
  29. package/dist/esm/pmxt/errors.js +9 -0
  30. package/dist/esm/pmxt/escrow.d.ts +39 -0
  31. package/dist/esm/pmxt/escrow.js +78 -0
  32. package/dist/esm/pmxt/feed-client.d.ts +3 -0
  33. package/dist/esm/pmxt/feed-client.js +11 -2
  34. package/dist/esm/pmxt/hosted-errors.d.ts +84 -0
  35. package/dist/esm/pmxt/hosted-errors.js +186 -0
  36. package/dist/esm/pmxt/hosted-mappers.d.ts +45 -0
  37. package/dist/esm/pmxt/hosted-mappers.js +291 -0
  38. package/dist/esm/pmxt/hosted-routing.d.ts +69 -0
  39. package/dist/esm/pmxt/hosted-routing.js +119 -0
  40. package/dist/esm/pmxt/hosted-typed-data.d.ts +36 -0
  41. package/dist/esm/pmxt/hosted-typed-data.js +580 -0
  42. package/dist/esm/pmxt/models.d.ts +46 -8
  43. package/dist/esm/pmxt/server-manager.d.ts +4 -0
  44. package/dist/esm/pmxt/server-manager.js +6 -0
  45. package/dist/esm/pmxt/signers.d.ts +57 -0
  46. package/dist/esm/pmxt/signers.js +50 -0
  47. package/dist/esm/pmxt/ws-client.js +2 -1
  48. package/dist/generated/src/models/Balance.d.ts +6 -0
  49. package/dist/generated/src/models/Balance.js +2 -0
  50. package/dist/generated/src/models/BuiltOrder.d.ts +6 -0
  51. package/dist/generated/src/models/BuiltOrder.js +2 -0
  52. package/dist/generated/src/models/ErrorDetail.d.ts +58 -2
  53. package/dist/generated/src/models/ErrorDetail.js +38 -0
  54. package/dist/generated/src/models/ExchangeOptions.d.ts +70 -0
  55. package/dist/generated/src/models/ExchangeOptions.js +60 -0
  56. package/dist/generated/src/models/MatchedMarketPair.d.ts +1 -1
  57. package/dist/generated/src/models/Order.d.ts +18 -0
  58. package/dist/generated/src/models/Order.js +6 -0
  59. package/dist/generated/src/models/OrderLevel.d.ts +6 -0
  60. package/dist/generated/src/models/OrderLevel.js +2 -0
  61. package/dist/generated/src/models/Position.d.ts +33 -9
  62. package/dist/generated/src/models/Position.js +12 -12
  63. package/dist/generated/src/models/UnifiedSeries.d.ts +4 -4
  64. package/dist/generated/src/models/UserTrade.d.ts +18 -0
  65. package/dist/generated/src/models/UserTrade.js +6 -0
  66. package/dist/generated/src/models/index.d.ts +1 -0
  67. package/dist/generated/src/models/index.js +1 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +1 -0
  70. package/dist/pmxt/client.d.ts +106 -5
  71. package/dist/pmxt/client.js +399 -5
  72. package/dist/pmxt/constants.d.ts +11 -0
  73. package/dist/pmxt/constants.js +14 -1
  74. package/dist/pmxt/errors.d.ts +3 -0
  75. package/dist/pmxt/errors.js +11 -1
  76. package/dist/pmxt/escrow.d.ts +39 -0
  77. package/dist/pmxt/escrow.js +82 -0
  78. package/dist/pmxt/feed-client.d.ts +3 -0
  79. package/dist/pmxt/feed-client.js +11 -2
  80. package/dist/pmxt/hosted-errors.d.ts +84 -0
  81. package/dist/pmxt/hosted-errors.js +201 -0
  82. package/dist/pmxt/hosted-mappers.d.ts +45 -0
  83. package/dist/pmxt/hosted-mappers.js +302 -0
  84. package/dist/pmxt/hosted-routing.d.ts +69 -0
  85. package/dist/pmxt/hosted-routing.js +126 -0
  86. package/dist/pmxt/hosted-typed-data.d.ts +36 -0
  87. package/dist/pmxt/hosted-typed-data.js +619 -0
  88. package/dist/pmxt/models.d.ts +46 -8
  89. package/dist/pmxt/server-manager.d.ts +4 -0
  90. package/dist/pmxt/server-manager.js +6 -0
  91. package/dist/pmxt/signers.d.ts +57 -0
  92. package/dist/pmxt/signers.js +55 -0
  93. package/dist/pmxt/ws-client.js +2 -1
  94. package/generated/.openapi-generator/FILES +2 -0
  95. package/generated/docs/Balance.md +2 -0
  96. package/generated/docs/BuiltOrder.md +2 -0
  97. package/generated/docs/ErrorDetail.md +9 -0
  98. package/generated/docs/ExchangeOptions.md +47 -0
  99. package/generated/docs/Order.md +6 -0
  100. package/generated/docs/OrderLevel.md +2 -0
  101. package/generated/docs/Position.md +9 -0
  102. package/generated/docs/UserTrade.md +6 -0
  103. package/generated/package.json +1 -1
  104. package/generated/src/models/Balance.ts +8 -0
  105. package/generated/src/models/BuiltOrder.ts +8 -0
  106. package/generated/src/models/ErrorDetail.ts +67 -2
  107. package/generated/src/models/ExchangeOptions.ts +115 -0
  108. package/generated/src/models/MatchedMarketPair.ts +1 -1
  109. package/generated/src/models/Order.ts +24 -0
  110. package/generated/src/models/OrderLevel.ts +8 -0
  111. package/generated/src/models/Position.ts +45 -17
  112. package/generated/src/models/UnifiedSeries.ts +4 -4
  113. package/generated/src/models/UserTrade.ts +24 -0
  114. package/generated/src/models/index.ts +1 -0
  115. package/index.ts +1 -0
  116. package/package.json +11 -2
  117. package/pmxt/client.ts +495 -9
  118. package/pmxt/constants.ts +15 -0
  119. package/pmxt/errors.ts +11 -0
  120. package/pmxt/escrow.ts +93 -0
  121. package/pmxt/feed-client.ts +14 -2
  122. package/pmxt/hosted-errors.ts +216 -0
  123. package/pmxt/hosted-mappers.ts +312 -0
  124. package/pmxt/hosted-routing.ts +165 -0
  125. package/pmxt/hosted-typed-data.ts +767 -0
  126. package/pmxt/models.ts +65 -8
  127. package/pmxt/server-manager.ts +7 -0
  128. package/pmxt/signers.ts +86 -0
  129. package/pmxt/ws-client.ts +2 -1
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Hosted-mode escrow namespace.
3
+ *
4
+ * Exposes the `/v0/escrow/*` endpoints of the pmxt hosted trading API as a
5
+ * small ergonomic helper class. Each method returns the raw upstream JSON
6
+ * payload as `unknown` — typed mappers can be layered on later without
7
+ * breaking the wire shape.
8
+ *
9
+ * Mirrors `sdks/python/pmxt/escrow.py`.
10
+ */
11
+ import { _tradingRequest, formatRoutePath, HOSTED_METHOD_ROUTES, resolveWalletAddress, } from "./hosted-routing.js";
12
+ export class Escrow {
13
+ client;
14
+ constructor(client) {
15
+ this.client = client;
16
+ }
17
+ /**
18
+ * Build an unsigned approve transaction for a given ERC-20 `token`. When
19
+ * `amountWei` is omitted, the server returns an unlimited approval.
20
+ */
21
+ async approveTx(token, amountWei) {
22
+ const route = HOSTED_METHOD_ROUTES.get("escrowApproveTx");
23
+ return _tradingRequest(this.client, {
24
+ method: route.method,
25
+ path: route.path,
26
+ body: {
27
+ token,
28
+ amount_wei: amountWei === undefined ? null : amountWei.toString(),
29
+ },
30
+ });
31
+ }
32
+ /**
33
+ * Build an unsigned deposit transaction for `amount` (USDC, 6-decimal
34
+ * grid). Accepts number, decimal string, or BigInt in micro-units.
35
+ */
36
+ async depositTx(amount) {
37
+ const route = HOSTED_METHOD_ROUTES.get("escrowDepositTx");
38
+ return _tradingRequest(this.client, {
39
+ method: route.method,
40
+ path: route.path,
41
+ body: {
42
+ amount: typeof amount === "bigint" ? amount.toString() : amount,
43
+ },
44
+ });
45
+ }
46
+ /**
47
+ * Build an unsigned withdraw transaction. `action` selects the stage of
48
+ * the withdrawal lifecycle: `request` initiates, `claim` finalizes after
49
+ * the timelock, `cancel` aborts a pending request.
50
+ */
51
+ async withdrawTx(action, amount) {
52
+ const route = HOSTED_METHOD_ROUTES.get("escrowWithdrawTx");
53
+ const normalizedAmount = amount === undefined
54
+ ? null
55
+ : typeof amount === "bigint"
56
+ ? amount.toString()
57
+ : amount;
58
+ return _tradingRequest(this.client, {
59
+ method: route.method,
60
+ path: route.path,
61
+ body: { action, amount: normalizedAmount },
62
+ });
63
+ }
64
+ /**
65
+ * List the user's withdrawal records. `include` is forwarded verbatim and
66
+ * defaults to `"pending,events"` to match the Python SDK.
67
+ */
68
+ async withdrawals(opts = {}) {
69
+ const address = resolveWalletAddress(this.client, opts.address);
70
+ const route = HOSTED_METHOD_ROUTES.get("escrowWithdrawals");
71
+ const path = formatRoutePath(route, { address });
72
+ return _tradingRequest(this.client, {
73
+ method: route.method,
74
+ path,
75
+ params: { include: opts.include ?? "pending,events" },
76
+ });
77
+ }
78
+ }
@@ -59,6 +59,7 @@ export declare class FeedClient {
59
59
  private readonly baseUrl;
60
60
  private readonly headers;
61
61
  constructor(feedName: string, options?: FeedClientOptions);
62
+ listFeeds(): Promise<string[]>;
62
63
  loadMarkets(): Promise<Record<string, Market>>;
63
64
  fetchTicker(symbol: string): Promise<Ticker>;
64
65
  fetchTickers(symbols?: string[]): Promise<Tickers>;
@@ -72,4 +73,6 @@ export declare class FeedClient {
72
73
  order?: 'asc' | 'desc';
73
74
  }): Promise<Ticker[]>;
74
75
  private get;
76
+ private getRoot;
77
+ private request;
75
78
  }
@@ -22,6 +22,9 @@ export class FeedClient {
22
22
  ...(resolved.pmxtApiKey ? { 'Authorization': `Bearer ${resolved.pmxtApiKey}` } : {}),
23
23
  };
24
24
  }
25
+ async listFeeds() {
26
+ return this.getRoot();
27
+ }
25
28
  async loadMarkets() {
26
29
  return this.get('loadMarkets', {});
27
30
  }
@@ -50,12 +53,18 @@ export class FeedClient {
50
53
  return this.get('fetchHistoricalPrices', { symbol, ...opts });
51
54
  }
52
55
  async get(method, params) {
56
+ return this.request(`${this.baseUrl}/api/feeds/${this.feedName}/${method}`, params);
57
+ }
58
+ async getRoot(params = {}) {
59
+ return this.request(`${this.baseUrl}/api/feeds/`, params);
60
+ }
61
+ async request(url, params) {
53
62
  const qs = Object.entries(params)
54
63
  .filter(([, v]) => v !== undefined && v !== null)
55
64
  .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
56
65
  .join('&');
57
- const url = `${this.baseUrl}/api/feeds/${this.feedName}/${method}${qs ? '?' + qs : ''}`;
58
- const response = await fetch(url, {
66
+ const requestUrl = `${url}${qs ? '?' + qs : ''}`;
67
+ const response = await fetch(requestUrl, {
59
68
  headers: this.headers,
60
69
  signal: AbortSignal.timeout(30_000),
61
70
  });
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Hosted trading error hierarchy and upstream response mapping.
3
+ *
4
+ * Mirrors the Python implementation in `pmxt/_hosted_errors.py`. TypeScript
5
+ * does not support multiple inheritance, so each hosted error class extends
6
+ * the semantically-closest legacy parent (e.g. `InsufficientEscrowBalance`
7
+ * extends `InsufficientFunds`) so existing `instanceof` checks continue to
8
+ * match. The `static isHostedError = true` flag and the {@link isHostedError}
9
+ * helper provide a structural alternative for callers that want to detect
10
+ * hosted-mode failures regardless of the concrete subclass.
11
+ */
12
+ import { AuthenticationError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, NotFoundError, PmxtError, ValidationError } from "./errors.js";
13
+ export declare class HostedTradingError extends PmxtError {
14
+ static readonly isHostedError = true;
15
+ readonly status: number;
16
+ readonly detail: string;
17
+ constructor(status: number, detail: string);
18
+ }
19
+ export declare class InsufficientEscrowBalance extends InsufficientFunds {
20
+ static readonly isHostedError = true;
21
+ readonly status: number;
22
+ readonly detail: string;
23
+ constructor(status: number, detail: string);
24
+ }
25
+ export declare class OrderSizeTooSmall extends InvalidOrder {
26
+ static readonly isHostedError = true;
27
+ readonly status: number;
28
+ readonly detail: string;
29
+ constructor(status: number, detail: string);
30
+ }
31
+ export declare class InvalidApiKey extends AuthenticationError {
32
+ static readonly isHostedError = true;
33
+ readonly status: number;
34
+ readonly detail: string;
35
+ constructor(status: number, detail: string);
36
+ }
37
+ export declare class OutcomeNotFound extends NotFoundError {
38
+ static readonly isHostedError = true;
39
+ readonly status: number;
40
+ readonly detail: string;
41
+ constructor(status: number, detail: string);
42
+ }
43
+ export declare class CatalogUnavailable extends ExchangeNotAvailable {
44
+ static readonly isHostedError = true;
45
+ readonly status: number;
46
+ readonly detail: string;
47
+ constructor(status: number, detail: string);
48
+ }
49
+ export declare class BuiltOrderExpired extends InvalidOrder {
50
+ static readonly isHostedError = true;
51
+ readonly status: number;
52
+ readonly detail: string;
53
+ constructor(status: number, detail: string);
54
+ }
55
+ export declare class InvalidSignature extends AuthenticationError {
56
+ static readonly isHostedError = true;
57
+ readonly status: number;
58
+ readonly detail: string;
59
+ constructor(status: number, detail: string);
60
+ }
61
+ export declare class NoLiquidity extends InvalidOrder {
62
+ static readonly isHostedError = true;
63
+ readonly status: number;
64
+ readonly detail: string;
65
+ constructor(status: number, detail: string);
66
+ }
67
+ /**
68
+ * Local validation failure. Not a hosted-mode upstream error, so does NOT
69
+ * carry the `isHostedError` flag.
70
+ */
71
+ export declare class MissingWalletAddress extends ValidationError {
72
+ constructor(message: string);
73
+ }
74
+ /**
75
+ * Returns true if `e` is a hosted trading error — either an instance of
76
+ * {@link HostedTradingError} or any subclass that carries the
77
+ * `static isHostedError = true` marker.
78
+ */
79
+ export declare function isHostedError(e: unknown): boolean;
80
+ /**
81
+ * Read an upstream `Response` and throw the matching hosted trading error.
82
+ * Always throws — return type is `never`.
83
+ */
84
+ export declare function raiseFromResponse(response: Response): Promise<never>;
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Hosted trading error hierarchy and upstream response mapping.
3
+ *
4
+ * Mirrors the Python implementation in `pmxt/_hosted_errors.py`. TypeScript
5
+ * does not support multiple inheritance, so each hosted error class extends
6
+ * the semantically-closest legacy parent (e.g. `InsufficientEscrowBalance`
7
+ * extends `InsufficientFunds`) so existing `instanceof` checks continue to
8
+ * match. The `static isHostedError = true` flag and the {@link isHostedError}
9
+ * helper provide a structural alternative for callers that want to detect
10
+ * hosted-mode failures regardless of the concrete subclass.
11
+ */
12
+ import { AuthenticationError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, NotFoundError, PmxtError, ValidationError, } from "./errors.js";
13
+ export class HostedTradingError extends PmxtError {
14
+ static isHostedError = true;
15
+ status;
16
+ detail;
17
+ constructor(status, detail) {
18
+ super(detail);
19
+ this.status = status;
20
+ this.detail = detail;
21
+ this.name = this.constructor.name;
22
+ }
23
+ }
24
+ export class InsufficientEscrowBalance extends InsufficientFunds {
25
+ static isHostedError = true;
26
+ status;
27
+ detail;
28
+ constructor(status, detail) {
29
+ super(detail);
30
+ this.status = status;
31
+ this.detail = detail;
32
+ this.name = this.constructor.name;
33
+ }
34
+ }
35
+ export class OrderSizeTooSmall extends InvalidOrder {
36
+ static isHostedError = true;
37
+ status;
38
+ detail;
39
+ constructor(status, detail) {
40
+ super(detail);
41
+ this.status = status;
42
+ this.detail = detail;
43
+ this.name = this.constructor.name;
44
+ }
45
+ }
46
+ export class InvalidApiKey extends AuthenticationError {
47
+ static isHostedError = true;
48
+ status;
49
+ detail;
50
+ constructor(status, detail) {
51
+ super(detail);
52
+ this.status = status;
53
+ this.detail = detail;
54
+ this.name = this.constructor.name;
55
+ }
56
+ }
57
+ export class OutcomeNotFound extends NotFoundError {
58
+ static isHostedError = true;
59
+ status;
60
+ detail;
61
+ constructor(status, detail) {
62
+ super(detail);
63
+ this.status = status;
64
+ this.detail = detail;
65
+ this.name = this.constructor.name;
66
+ }
67
+ }
68
+ export class CatalogUnavailable extends ExchangeNotAvailable {
69
+ static isHostedError = true;
70
+ status;
71
+ detail;
72
+ constructor(status, detail) {
73
+ super(detail);
74
+ this.status = status;
75
+ this.detail = detail;
76
+ this.name = this.constructor.name;
77
+ }
78
+ }
79
+ export class BuiltOrderExpired extends InvalidOrder {
80
+ static isHostedError = true;
81
+ status;
82
+ detail;
83
+ constructor(status, detail) {
84
+ super(detail);
85
+ this.status = status;
86
+ this.detail = detail;
87
+ this.name = this.constructor.name;
88
+ }
89
+ }
90
+ export class InvalidSignature extends AuthenticationError {
91
+ static isHostedError = true;
92
+ status;
93
+ detail;
94
+ constructor(status, detail) {
95
+ super(detail);
96
+ this.status = status;
97
+ this.detail = detail;
98
+ this.name = this.constructor.name;
99
+ }
100
+ }
101
+ export class NoLiquidity extends InvalidOrder {
102
+ static isHostedError = true;
103
+ status;
104
+ detail;
105
+ constructor(status, detail) {
106
+ super(detail);
107
+ this.status = status;
108
+ this.detail = detail;
109
+ this.name = this.constructor.name;
110
+ }
111
+ }
112
+ /**
113
+ * Local validation failure. Not a hosted-mode upstream error, so does NOT
114
+ * carry the `isHostedError` flag.
115
+ */
116
+ export class MissingWalletAddress extends ValidationError {
117
+ constructor(message) {
118
+ super(message);
119
+ this.name = this.constructor.name;
120
+ }
121
+ }
122
+ /**
123
+ * Returns true if `e` is a hosted trading error — either an instance of
124
+ * {@link HostedTradingError} or any subclass that carries the
125
+ * `static isHostedError = true` marker.
126
+ */
127
+ export function isHostedError(e) {
128
+ if (e instanceof HostedTradingError)
129
+ return true;
130
+ const ctor = e?.constructor;
131
+ return ctor != null && ctor.isHostedError === true;
132
+ }
133
+ /**
134
+ * Read an upstream `Response` and throw the matching hosted trading error.
135
+ * Always throws — return type is `never`.
136
+ */
137
+ export async function raiseFromResponse(response) {
138
+ const status = response.status;
139
+ let detail = "";
140
+ try {
141
+ const body = await response.json();
142
+ if (body != null && typeof body === "object") {
143
+ const record = body;
144
+ const candidate = (typeof record.detail === "string" ? record.detail : undefined) ||
145
+ (typeof record.message === "string" ? record.message : undefined) ||
146
+ (typeof record.error === "string" ? record.error : undefined);
147
+ detail = candidate || JSON.stringify(body);
148
+ }
149
+ else {
150
+ detail = typeof body === "string" ? body : JSON.stringify(body);
151
+ }
152
+ }
153
+ catch {
154
+ try {
155
+ detail = await response.text();
156
+ }
157
+ catch {
158
+ detail = `HTTP ${status}`;
159
+ }
160
+ }
161
+ if (status === 401) {
162
+ throw new InvalidApiKey(status, detail);
163
+ }
164
+ if (detail.startsWith("Insufficient escrow balance")) {
165
+ throw new InsufficientEscrowBalance(status, detail);
166
+ }
167
+ if (detail.includes("below the minimum")) {
168
+ throw new OrderSizeTooSmall(status, detail);
169
+ }
170
+ if (detail.includes("catalog: no outcome")) {
171
+ throw new OutcomeNotFound(status, detail);
172
+ }
173
+ if (detail.startsWith("catalog:")) {
174
+ throw new CatalogUnavailable(status, detail);
175
+ }
176
+ if (detail.includes("built_order_id expired") || detail.includes("cancel_id expired")) {
177
+ throw new BuiltOrderExpired(status, detail);
178
+ }
179
+ if (detail.includes("Invalid signature")) {
180
+ throw new InvalidSignature(status, detail);
181
+ }
182
+ if (detail.includes("book has no resting asks") || detail.includes("book has no resting bids")) {
183
+ throw new NoLiquidity(status, detail);
184
+ }
185
+ throw new HostedTradingError(status, detail);
186
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Hosted trading v0 response mappers.
3
+ *
4
+ * The hosted trading API exposes explicit `/v0/*` JSON shapes. These helpers
5
+ * translate those wire dictionaries to the SDK TypeScript interfaces.
6
+ *
7
+ * Mirrors `sdks/python/pmxt/_hosted_mappers.py`.
8
+ */
9
+ import { Balance, Order, Position, UserTrade } from "./models.js";
10
+ /**
11
+ * Convert a decimal amount to integer micro-units (6-decimal grid).
12
+ *
13
+ * Rejects amounts whose fractional part has more than 6 digits. Pure integer
14
+ * math via BigInt — no float rounding involved.
15
+ */
16
+ export declare function to6dec(amount: number | string | bigint): bigint;
17
+ /** Map an `OrderV0` JSON object to {@link Order}. */
18
+ export declare function orderFromV0(payload: Record<string, unknown>): Order;
19
+ /** Map an {@link Order} back to an `OrderV0` JSON object. */
20
+ export declare function orderToV0(order: Order): Record<string, unknown>;
21
+ /** Map a `UserTradeV0` JSON object to {@link UserTrade}. */
22
+ export declare function userTradeFromV0(payload: Record<string, unknown>): UserTrade;
23
+ /** Map a {@link UserTrade} back to a `UserTradeV0` JSON object. */
24
+ export declare function userTradeToV0(trade: UserTrade): Record<string, unknown>;
25
+ /**
26
+ * Map a `PositionV0` JSON object to {@link Position}.
27
+ *
28
+ * Optional fields (`outcomeLabel`, `entryPrice`, `currentPrice`,
29
+ * `unrealizedPnL`, `realizedPnL`) surface as `undefined` when missing —
30
+ * **never** a fake `0` or `""`. This keeps the SDK honest about which data
31
+ * the server actually provided.
32
+ */
33
+ export declare function positionFromV0(payload: Record<string, unknown>): Position;
34
+ /** Map a {@link Position} back to a `PositionV0` JSON object. */
35
+ export declare function positionToV0(position: Position): Record<string, unknown>;
36
+ /**
37
+ * Map a `BalanceV0` JSON object to {@link Balance}.
38
+ *
39
+ * Hosted-mode semantic: PreFundedEscrow doesn't reserve funds for resting
40
+ * orders, so `available = total` and `locked = 0`. Concurrent limit orders
41
+ * may fail at fill time if cumulative cost exceeds the escrow balance.
42
+ */
43
+ export declare function balanceFromV0(payload: Record<string, unknown>): Balance;
44
+ /** Map a {@link Balance} back to a `BalanceV0` JSON object. */
45
+ export declare function balanceToV0(balance: Balance): Record<string, unknown>;