@0xmonaco/types 1.0.73 → 1.0.74-develop.367860f

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 (60) hide show
  1. package/dist/api/index.d.ts +0 -7
  2. package/dist/applications/index.d.ts +14 -15
  3. package/dist/applications/index.js +2 -2
  4. package/dist/applications/requests.d.ts +70 -15
  5. package/dist/applications/requests.js +2 -3
  6. package/dist/applications/responses.d.ts +35 -39
  7. package/dist/applications/responses.js +1 -1
  8. package/dist/buildercodes/index.d.ts +3 -4
  9. package/dist/buildercodes/responses.d.ts +12 -6
  10. package/dist/buildercodes/responses.js +26 -7
  11. package/dist/copy-trading/index.d.ts +7 -7
  12. package/dist/delegated-agents/index.d.ts +15 -5
  13. package/dist/fees/responses.js +2 -2
  14. package/dist/managed-markets/index.d.ts +21 -2
  15. package/dist/margin-accounts/index.d.ts +185 -21
  16. package/dist/market/index.d.ts +76 -6
  17. package/dist/pitpass/index.d.ts +31 -11
  18. package/dist/pitpass/index.js +1 -1
  19. package/dist/pitpass/responses.d.ts +67 -0
  20. package/dist/pitpass/responses.js +92 -8
  21. package/dist/portfolio/index.d.ts +36 -14
  22. package/dist/positions/index.d.ts +81 -14
  23. package/dist/profile/index.d.ts +114 -44
  24. package/dist/sdk/index.d.ts +12 -4
  25. package/dist/trading/index.d.ts +1 -1
  26. package/dist/trading/orders.d.ts +6 -32
  27. package/dist/trading/responses.d.ts +9 -14
  28. package/dist/validation/applications.d.ts +51 -0
  29. package/dist/validation/applications.js +45 -0
  30. package/dist/validation/index.d.ts +2 -0
  31. package/dist/validation/index.js +2 -0
  32. package/dist/validation/managed-markets.d.ts +17 -0
  33. package/dist/validation/managed-markets.js +17 -0
  34. package/dist/validation/margin-accounts.d.ts +44 -3
  35. package/dist/validation/margin-accounts.js +57 -6
  36. package/dist/validation/market.d.ts +45 -0
  37. package/dist/validation/market.js +43 -0
  38. package/dist/validation/positions.d.ts +5 -3
  39. package/dist/validation/positions.js +12 -5
  40. package/dist/validation/profile.d.ts +19 -2
  41. package/dist/validation/profile.js +36 -4
  42. package/dist/validation/trading.d.ts +2 -2
  43. package/dist/validation/vault.d.ts +14 -0
  44. package/dist/validation/vault.js +14 -0
  45. package/dist/websocket/base.d.ts +56 -6
  46. package/dist/websocket/client.d.ts +8 -3
  47. package/dist/websocket/events/index.d.ts +1 -0
  48. package/dist/websocket/events/index.js +1 -0
  49. package/dist/websocket/events/liquidation-events.d.ts +3 -3
  50. package/dist/websocket/events/market-stats-events.d.ts +33 -3
  51. package/dist/websocket/events/market-stats-events.js +3 -2
  52. package/dist/websocket/events/orders-events.d.ts +36 -3
  53. package/dist/websocket/events/position-events.d.ts +33 -15
  54. package/dist/websocket/events/position-valuation-events.d.ts +60 -0
  55. package/dist/websocket/events/position-valuation-events.js +15 -0
  56. package/dist/wire/operations.d.ts +1 -1
  57. package/dist/wire/operations.js +7 -0
  58. package/dist/wire/schema.d.ts +1595 -352
  59. package/dist/withdrawals/index.d.ts +27 -6
  60. package/package.json +2 -2
@@ -48,8 +48,13 @@ export declare const SetSelfTradePreventionDefaultSchema: z.ZodObject<{
48
48
  * All fields are optional — an empty object or undefined is valid.
49
49
  */
50
50
  export declare const GetUserMovementsSchema: z.ZodObject<{
51
- page: z.ZodOptional<z.ZodNumber>;
51
+ page: z.ZodOptional<z.ZodNever>;
52
52
  pageSize: z.ZodOptional<z.ZodNumber>;
53
+ pageToken: z.ZodOptional<z.ZodString>;
54
+ orderBy: z.ZodOptional<z.ZodEnum<{
55
+ ASC: "ASC";
56
+ DESC: "DESC";
57
+ }>>;
53
58
  entryType: z.ZodOptional<z.ZodEnum<{
54
59
  CREDIT: "CREDIT";
55
60
  DEBIT: "DEBIT";
@@ -81,9 +86,21 @@ export declare const GetUserTradesSchema: z.ZodObject<{
81
86
  tradingPairId: z.ZodOptional<z.ZodUUID>;
82
87
  pageToken: z.ZodOptional<z.ZodString>;
83
88
  }, z.core.$strip>;
89
+ /**
90
+ * Get User Balances validation schema
91
+ *
92
+ * Validates parameters for the cursor-paged balances listing. All fields are
93
+ * optional — an empty object or undefined is valid.
94
+ */
95
+ export declare const GetUserBalancesSchema: z.ZodObject<{
96
+ page: z.ZodOptional<z.ZodNever>;
97
+ pageSize: z.ZodOptional<z.ZodNumber>;
98
+ pageToken: z.ZodOptional<z.ZodString>;
99
+ }, z.core.$strip>;
84
100
  export declare const ListFundingPaymentsSchema: z.ZodObject<{
85
- page: z.ZodOptional<z.ZodNumber>;
101
+ page: z.ZodOptional<z.ZodNever>;
86
102
  pageSize: z.ZodOptional<z.ZodNumber>;
103
+ pageToken: z.ZodOptional<z.ZodString>;
87
104
  tradingPairId: z.ZodOptional<z.ZodUUID>;
88
105
  positionId: z.ZodOptional<z.ZodUUID>;
89
106
  marginAccountId: z.ZodOptional<z.ZodUUID>;
@@ -33,8 +33,16 @@ export const SetSelfTradePreventionDefaultSchema = z.object({
33
33
  * All fields are optional — an empty object or undefined is valid.
34
34
  */
35
35
  export const GetUserMovementsSchema = z.object({
36
- page: z.number().int("Page must be an integer").min(1, "Page must be at least 1").optional(),
37
- pageSize: z.number().int("Page size must be an integer").min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
36
+ /**
37
+ * Rejected, not ignored. A non-strict object would let a JS or `any` caller
38
+ * keep passing `page`, and the request would come back as the first cursor
39
+ * page every time — the same silent duplicate-page failure the REST 400
40
+ * guard exists to prevent (0XM-2788).
41
+ */
42
+ page: z.never().optional(),
43
+ pageSize: z.number().int("Page size must be an integer").min(1, "Page size must be at least 1").max(1000, "Page size cannot exceed 1000").optional(),
44
+ pageToken: z.string().optional(),
45
+ orderBy: z.enum(["ASC", "DESC"]).optional(),
38
46
  entryType: LedgerEntryTypeSchema.optional(),
39
47
  transactionType: TransactionTypeSchema.optional(),
40
48
  assetId: UUIDSchema.optional(),
@@ -57,9 +65,33 @@ export const GetUserTradesSchema = z.object({
57
65
  tradingPairId: UUIDSchema.optional(),
58
66
  pageToken: z.string().optional(),
59
67
  });
68
+ /**
69
+ * Get User Balances validation schema
70
+ *
71
+ * Validates parameters for the cursor-paged balances listing. All fields are
72
+ * optional — an empty object or undefined is valid.
73
+ */
74
+ export const GetUserBalancesSchema = z.object({
75
+ /**
76
+ * Rejected, not ignored. Without a schema at all a JS or `any` caller's
77
+ * `page` was silently dropped while building the query string, so the call
78
+ * resolved with the FIRST cursor page on every request — the quiet
79
+ * duplicate-page failure the REST 400 guard exists to prevent (0XM-2821).
80
+ */
81
+ page: z.never().optional(),
82
+ pageSize: z.number().int("Page size must be an integer").min(1, "Page size must be at least 1").max(1000, "Page size cannot exceed 1000").optional(),
83
+ pageToken: z.string().optional(),
84
+ });
60
85
  export const ListFundingPaymentsSchema = z.object({
61
- page: z.number().int("Page must be an integer").min(1, "Page must be at least 1").optional(),
62
- pageSize: z.number().int("Page size must be an integer").min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
86
+ /**
87
+ * Rejected, not ignored. A non-strict object would let a JS or `any` caller
88
+ * keep passing `page`, and the request would come back as the first cursor
89
+ * page every time — the same silent duplicate-page failure the REST 400
90
+ * guard exists to prevent (0XM-2788).
91
+ */
92
+ page: z.never().optional(),
93
+ pageSize: z.number().int("Page size must be an integer").min(1, "Page size must be at least 1").max(1000, "Page size cannot exceed 1000").optional(),
94
+ pageToken: z.string().optional(),
63
95
  tradingPairId: UUIDSchema.optional(),
64
96
  positionId: UUIDSchema.optional(),
65
97
  marginAccountId: UUIDSchema.optional(),
@@ -375,11 +375,11 @@ export declare const ConditionalOrderTriggerSourceSchema: z.ZodEnum<{
375
375
  export declare const ConditionalOrderStateSchema: z.ZodEnum<{
376
376
  CANCELLED: "CANCELLED";
377
377
  EXPIRED: "EXPIRED";
378
- FAILED: "FAILED";
379
378
  PENDING_PARENT: "PENDING_PARENT";
380
379
  ACTIVE: "ACTIVE";
381
380
  TRIGGERING: "TRIGGERING";
382
381
  TRIGGERED: "TRIGGERED";
382
+ FAILED: "FAILED";
383
383
  }>;
384
384
  export declare const ClosePositionSideSchema: z.ZodEnum<{
385
385
  LONG: "LONG";
@@ -395,11 +395,11 @@ export declare const ListConditionalOrdersSchema: z.ZodObject<{
395
395
  state: z.ZodOptional<z.ZodEnum<{
396
396
  CANCELLED: "CANCELLED";
397
397
  EXPIRED: "EXPIRED";
398
- FAILED: "FAILED";
399
398
  PENDING_PARENT: "PENDING_PARENT";
400
399
  ACTIVE: "ACTIVE";
401
400
  TRIGGERING: "TRIGGERING";
402
401
  TRIGGERED: "TRIGGERED";
402
+ FAILED: "FAILED";
403
403
  }>>;
404
404
  pageSize: z.ZodOptional<z.ZodNumber>;
405
405
  pageToken: z.ZodOptional<z.ZodString>;
@@ -75,3 +75,17 @@ export declare const WithdrawSchema: z.ZodObject<{
75
75
  export declare const GetBalanceSchema: z.ZodObject<{
76
76
  assetId: z.ZodUUID;
77
77
  }, z.core.$strip>;
78
+ /**
79
+ * Pending-withdrawals listing validation schema.
80
+ *
81
+ * Cursor paged (0XM-2821). `page` is REJECTED rather than omitted: the client
82
+ * forwards the params field by field, which would drop a stray `page` before it
83
+ * reached the wire, so a JavaScript or `any` caller looping on `{ page: n }`
84
+ * would be handed the FIRST cursor page on every call and would never advance —
85
+ * the exact failure the REST 400 exists to surface.
86
+ */
87
+ export declare const ListPendingWithdrawalsSchema: z.ZodObject<{
88
+ page: z.ZodOptional<z.ZodNever>;
89
+ pageSize: z.ZodOptional<z.ZodNumber>;
90
+ pageToken: z.ZodOptional<z.ZodString>;
91
+ }, z.core.$strip>;
@@ -86,3 +86,17 @@ export const WithdrawSchema = z.object({
86
86
  export const GetBalanceSchema = z.object({
87
87
  assetId: UUIDSchema,
88
88
  });
89
+ /**
90
+ * Pending-withdrawals listing validation schema.
91
+ *
92
+ * Cursor paged (0XM-2821). `page` is REJECTED rather than omitted: the client
93
+ * forwards the params field by field, which would drop a stray `page` before it
94
+ * reached the wire, so a JavaScript or `any` caller looping on `{ page: n }`
95
+ * would be handed the FIRST cursor page on every call and would never advance —
96
+ * the exact failure the REST 400 exists to surface.
97
+ */
98
+ export const ListPendingWithdrawalsSchema = z.object({
99
+ page: z.never().optional(),
100
+ pageSize: z.number().int("Page size must be an integer").min(1, "Page size must be at least 1").max(1000, "Page size cannot exceed 1000").optional(),
101
+ pageToken: z.string().optional(),
102
+ });
@@ -7,8 +7,40 @@
7
7
  * WebSocket connection status
8
8
  */
9
9
  export type WebSocketStatus = "connected" | "connecting" | "disconnected" | "reconnecting";
10
- /** Handler invoked whenever the WebSocket connection status changes. */
11
- export type StatusHandler = (status: WebSocketStatus) => void;
10
+ /**
11
+ * Connection-attempt context delivered with every status change.
12
+ *
13
+ * `"reconnecting"` with `hasConnected: false` means the client has never
14
+ * reached the server and is still trying (the first connect failed);
15
+ * `hasConnected: true` means a working connection was lost.
16
+ */
17
+ export interface WebSocketStatusInfo {
18
+ /**
19
+ * The retry this status refers to. `0` for `"connecting"` and
20
+ * `"connected"`; `1`, `2`, … for `"reconnecting"` (the retry just
21
+ * scheduled); for `"disconnected"`, the number of retries scheduled in the
22
+ * outage before it, counting one still in backoff when `disconnect()` is
23
+ * called (`0` after a clean close of a working connection).
24
+ */
25
+ attempt: number;
26
+ /**
27
+ * Whether this client has reached the server at least once since it was
28
+ * created or since the last `disconnect()`.
29
+ */
30
+ hasConnected: boolean;
31
+ /**
32
+ * Set only on `"reconnecting"`: the delay, in milliseconds, before the
33
+ * scheduled retry opens its connection.
34
+ */
35
+ nextRetryDelayMs?: number;
36
+ }
37
+ /**
38
+ * Handler invoked whenever the WebSocket connection status changes.
39
+ *
40
+ * Inside the handler, `getStatus()` returns the status being reported. A
41
+ * handler that takes only `status` remains valid.
42
+ */
43
+ export type StatusHandler = (status: WebSocketStatus, info: WebSocketStatusInfo) => void;
12
44
  /**
13
45
  * Why the connection was re-established. Delivered by
14
46
  * {@link MonacoWebSocketConfig.onResync} after the socket reopens and sends its
@@ -129,9 +161,11 @@ export interface MonacoWebSocketConfig {
129
161
  /** Enable auto-reconnect on disconnect (default: true) */
130
162
  autoReconnect?: boolean;
131
163
  /**
132
- * Maximum reconnection attempts (default: unlimited). Retry delay is
133
- * full-jitter exponential backoff capped at 30s, so unlimited retries are
134
- * capped-rate, not a tight loop.
164
+ * Maximum reconnection attempts per outage (default: unlimited). Retry
165
+ * delay is full-jitter exponential backoff capped at 30s, so unlimited
166
+ * retries are capped-rate, not a tight loop. Once the attempts run out the
167
+ * client reports `"disconnected"`; a later `connect()` starts a fresh
168
+ * budget.
135
169
  */
136
170
  maxReconnectAttempts?: number;
137
171
  /** Base delay for the exponential backoff in milliseconds (default: 1000) */
@@ -141,7 +175,23 @@ export interface MonacoWebSocketConfig {
141
175
  * retried, in milliseconds (default: 10000)
142
176
  */
143
177
  connectionTimeoutMs?: number;
144
- /** Callback for connection status changes */
178
+ /**
179
+ * Called on every connection status change, with the attempt context in
180
+ * {@link WebSocketStatusInfo}:
181
+ *
182
+ * - `"connecting"` — a connection is opening outside a retry cycle: the
183
+ * first connect, a `connect()` after a terminal `"disconnected"`, or a
184
+ * fresh session's reconnect after terminal authentication loss.
185
+ * - `"connected"` — the connection opened.
186
+ * - `"reconnecting"` — a retry is scheduled, once per retry. It holds until
187
+ * a retry connects or the retries run out; retries do not report
188
+ * `"connecting"`.
189
+ * - `"disconnected"` — terminal: a clean close, retries exhausted, terminal
190
+ * authentication loss, or `disconnect()`.
191
+ *
192
+ * An error thrown by this callback, or a rejection of the promise an async
193
+ * callback returns, is logged and does not affect the connection.
194
+ */
145
195
  onStatusChange?: StatusHandler;
146
196
  /**
147
197
  * Called after every automatic reconnect sends authentication/subscription
@@ -52,7 +52,7 @@ import type { Interval } from "../market";
52
52
  import type { TradingMode } from "../trading";
53
53
  import type { WebSocketStatus } from "./base";
54
54
  import type { OrderbookQuotationMode } from "./clients/orderbook-client";
55
- import type { AccountEvent, AccountEventData, ConditionalOrderEvent, ConditionalOrderEventData, CopyEvent, CopyRelationshipEventData, InstrumentEvent, InstrumentEventData, LiquidationEvent, LiquidationEventData, MarketStatsAllEvent, MarketStatsData, MarketStatsEvent, MarketStatsSummary, OHLCVEvent, OHLCVPriceType, OrderbookEvent, OrderEvent, PositionEvent, PositionEventData, TradeEvent, TwapOrderEvent, TwapOrderEventData, UserBalanceEvent, UserBalanceEventData, UserMovementEvent } from "./events";
55
+ import type { AccountEvent, AccountEventData, ConditionalOrderEvent, ConditionalOrderEventData, CopyEvent, CopyRelationshipEventData, InstrumentEvent, InstrumentEventData, LiquidationEvent, LiquidationEventData, MarketStatsAllEvent, MarketStatsData, MarketStatsEvent, MarketStatsSummary, OHLCVEvent, OHLCVPriceType, OrderbookEvent, OrderEvent, PositionEvent, PositionEventData, PositionValuationEvent, TradeEvent, TwapOrderEvent, TwapOrderEventData, UserBalanceEvent, UserBalanceEventData, UserMovementEvent } from "./events";
56
56
  import type { OrderSnapshotItem, SnapshotHandler } from "./snapshots";
57
57
  export type MessageHandler<T> = (data: T) => void;
58
58
  export interface MonacoWebSocket {
@@ -84,8 +84,13 @@ export interface MonacoWebSocket {
84
84
  conditionalOrders: (handler: MessageHandler<ConditionalOrderEvent>, tradingPairId?: string, onSnapshot?: SnapshotHandler<ConditionalOrderEventData>) => () => void;
85
85
  /** Subscribe to TWAP parent-order lifecycle events (requires authentication) */
86
86
  twapOrders: (handler: MessageHandler<TwapOrderEvent>, tradingPairId?: string, onSnapshot?: SnapshotHandler<TwapOrderEventData>) => () => void;
87
- /** Subscribe to position state updates (requires authentication); omit `tradingPairId` for all pairs. `onSnapshot` receives every open position */
88
- positions: (handler: MessageHandler<PositionEvent>, tradingPairId?: string, onSnapshot?: SnapshotHandler<PositionEventData>) => () => void;
87
+ /**
88
+ * Subscribe to position state updates (requires authentication); omit `tradingPairId` for all pairs. `onSnapshot` receives every open position.
89
+ *
90
+ * `handler` receives lifecycle `position_update` frames only. `onValuation`, when given, receives the periodic `position_valuation`
91
+ * frames carried on the same channel; without it they are ignored. Apply a valuation only to a position already held as `OPEN`.
92
+ */
93
+ positions: (handler: MessageHandler<PositionEvent>, tradingPairId?: string, onSnapshot?: SnapshotHandler<PositionEventData>, onValuation?: MessageHandler<PositionValuationEvent>) => () => void;
89
94
  /** Subscribe to liquidation alerts (requires authentication); omit `tradingPairId` for all pairs */
90
95
  liquidations: (handler: MessageHandler<LiquidationEvent>, tradingPairId?: string, onSnapshot?: SnapshotHandler<LiquidationEventData>) => () => void;
91
96
  /** Subscribe to account-level margin health updates for the authenticated user (requires authentication) */
@@ -10,5 +10,6 @@ export * from "./ohlcv-events";
10
10
  export * from "./orderbook-events";
11
11
  export * from "./orders-events";
12
12
  export * from "./position-events";
13
+ export * from "./position-valuation-events";
13
14
  export * from "./trade-events";
14
15
  export * from "./twap-order-events";
@@ -10,5 +10,6 @@ export * from "./ohlcv-events";
10
10
  export * from "./orderbook-events";
11
11
  export * from "./orders-events";
12
12
  export * from "./position-events";
13
+ export * from "./position-valuation-events";
13
14
  export * from "./trade-events";
14
15
  export * from "./twap-order-events";
@@ -12,7 +12,7 @@
12
12
  /**
13
13
  * Liquidation alert event data.
14
14
  *
15
- * `status` and `accountState` are free-form strings on the wire (they mirror
15
+ * `status` and `riskBucketState` are free-form strings on the wire (they mirror
16
16
  * server-side enums that carry no wire-level rename), so they are typed as
17
17
  * `string` rather than a closed union to avoid dropping a risk-critical alert
18
18
  * on an unexpected value.
@@ -28,8 +28,8 @@ export interface LiquidationEventData {
28
28
  tradingPairId?: string;
29
29
  /** Liquidation record status (e.g. "UNRESOLVED", free-form) */
30
30
  status: string;
31
- /** Margin-account risk state at alert time (e.g. "PENDING", free-form) */
32
- accountState: string;
31
+ /** The liquidated risk bucket's state at alert time (e.g. "PENDING_LIQUIDATION", free-form) */
32
+ riskBucketState: string;
33
33
  /** Position liquidation price, when known (decimal string) */
34
34
  liquidationPrice?: string;
35
35
  /** Mark price at alert time, when known (decimal string) */
@@ -13,8 +13,9 @@
13
13
  *
14
14
  * Perp-only fields (index/mark price, open interest, funding) are optional and
15
15
  * omitted on the wire for spot markets, which have no positions or funding.
16
- * All numeric quantities are decimal strings except `fundingTimestamp`, which
17
- * is a millisecond epoch number.
16
+ * All numeric quantities are decimal strings except `fundingTimestamp` and
17
+ * `lastFundingTime` (millisecond epoch numbers) and `fundingIntervalSeconds`
18
+ * (whole seconds).
18
19
  */
19
20
  /**
20
21
  * Market tradability label, derived from the oracle market status. Spot markets
@@ -23,6 +24,10 @@
23
24
  export type MarketStatus = "TRADABLE" | "POST_ONLY" | "HALTED" | "NOT_READY" | "UNKNOWN";
24
25
  /**
25
26
  * Full per-market statistics for the `market_stats:<tradingPairId>` channel.
27
+ *
28
+ * `marketStatus` is typed `MarketStatus | (string & {})` for the same reason as
29
+ * on {@link MarketStatsSummary}: an unrecognized status is passed through
30
+ * rather than dropping the frame. Match it with a `default` branch.
26
31
  */
27
32
  export interface MarketStatsData {
28
33
  /** Market symbol, e.g. "BTC/USDC" */
@@ -41,8 +46,19 @@ export interface MarketStatsData {
41
46
  bestAskPrice?: string;
42
47
  /** Open interest (decimal string). Perp-only; omitted for spot. */
43
48
  openInterest?: string;
44
- /** Open interest limit (decimal string). Perp-only; omitted for spot. */
49
+ /**
50
+ * The market's gross open-interest cap, in quote (USD) notional (decimal
51
+ * string). `openInterest` is in base units: multiply it by `markPrice` to
52
+ * compare. Perp-only; omitted for spot.
53
+ */
45
54
  openInterestLimit?: string;
55
+ /**
56
+ * What is left of `openInterestLimit` at the mark, in quote (USD) notional,
57
+ * never below zero (decimal string). At zero, orders that open exposure are
58
+ * refused until open interest or the mark falls. Perp-only; omitted for spot
59
+ * and when there is no mark.
60
+ */
61
+ openInterestHeadroom?: string;
46
62
  /** Last trade price (decimal string) */
47
63
  lastTradePrice?: string;
48
64
  /** 24h base-token volume (decimal string) */
@@ -71,6 +87,20 @@ export interface MarketStatsData {
71
87
  fundingClampSmall?: string;
72
88
  /** Live funding cap, upper bound (decimal string). Perp-only; omitted for spot. */
73
89
  fundingClampBig?: string;
90
+ /**
91
+ * Tradability label, the same value the all-markets summary carries for this
92
+ * market. Perp markets report any {@link MarketStatus}; spot markets report
93
+ * `TRADABLE` or `HALTED`. Always present on frames from current servers.
94
+ */
95
+ marketStatus?: MarketStatus | (string & {});
96
+ /** Funding settlement interval in whole seconds. Perp-only; omitted for spot. */
97
+ fundingIntervalSeconds?: number;
98
+ /**
99
+ * When the latest funding window settled, as a millisecond epoch number
100
+ * (REST `getFundingState` returns the same instant as an RFC 3339 string).
101
+ * Perp-only; omitted for spot and for a market that has not settled yet.
102
+ */
103
+ lastFundingTime?: number;
74
104
  }
75
105
  /**
76
106
  * Per-market statistics event on the `market_stats:<tradingPairId>` channel.
@@ -13,6 +13,7 @@
13
13
  *
14
14
  * Perp-only fields (index/mark price, open interest, funding) are optional and
15
15
  * omitted on the wire for spot markets, which have no positions or funding.
16
- * All numeric quantities are decimal strings except `fundingTimestamp`, which
17
- * is a millisecond epoch number.
16
+ * All numeric quantities are decimal strings except `fundingTimestamp` and
17
+ * `lastFundingTime` (millisecond epoch numbers) and `fundingIntervalSeconds`
18
+ * (whole seconds).
18
19
  */
@@ -179,6 +179,12 @@ export interface CommonOrderEventData {
179
179
  * Wire: `parent_order_id`.
180
180
  */
181
181
  parentOrderId?: string;
182
+ /**
183
+ * The margin account the order trades on: the default margin account or one
184
+ * of your sub-accounts, so an owner can route events per account. Omitted for
185
+ * a spot order and by servers predating the field. Wire: `margin_account_id`.
186
+ */
187
+ marginAccountId?: string;
182
188
  /**
183
189
  * The margin position this order is bound to: the same id REST `getOrder`
184
190
  * returns as `positionId`. A margin order placed while its margin account
@@ -221,6 +227,21 @@ export interface OrderPlacedEvent extends OrderEvent {
221
227
  * spot. Wire: `reduce_only`.
222
228
  */
223
229
  reduceOnly?: boolean;
230
+ /**
231
+ * The fill an edit carried over from the original order (decimal string).
232
+ * Sent only when the order is a replacement of a partly filled order; its
233
+ * `quantity` is then the order's total and its `status` is
234
+ * `PARTIALLY_FILLED`, as REST reports the edited order. Omitted on any
235
+ * other `OrderPlaced`. Wire: `filled_quantity`.
236
+ */
237
+ filledQuantity?: string;
238
+ /** `filledQuantity` in RAW (integer, base-unit) precision. Wire: `filled_quantity_raw`. */
239
+ filledQuantityRaw?: string;
240
+ /**
241
+ * Average fill price of the carried fill (decimal string). Sent with
242
+ * `filledQuantity`, omitted otherwise. Wire: `average_fill_price`.
243
+ */
244
+ averageFillPrice?: string;
224
245
  };
225
246
  }
226
247
  /**
@@ -305,7 +326,11 @@ export interface OrderMatchedEvent extends OrderEvent {
305
326
  tradesCount: number;
306
327
  /** Remaining quantity to be filled. */
307
328
  remainingQuantity: string;
308
- /** Average fill price across all trades. `null` when there is none. */
329
+ /**
330
+ * The order's cumulative average fill price, across every fill — those an
331
+ * edit carried over from the original order included, matching REST.
332
+ * `null` when there is none. This match's own price is `executionPrice`.
333
+ */
309
334
  averageFillPrice: string | null;
310
335
  /** Order status. */
311
336
  status: OrderStatus | (string & {});
@@ -339,7 +364,11 @@ export interface OrderPartiallyFilledEvent extends OrderEvent {
339
364
  tradesCount?: number;
340
365
  /** Remaining quantity (present for both taker and maker) */
341
366
  remainingQuantity?: string;
342
- /** Average fill price (taker orders only) */
367
+ /**
368
+ * The order's cumulative average fill price, on both roles: the average
369
+ * across every fill of the order (an edit's carried fills included), as
370
+ * REST reports it — not this trade's price, which is `executionPrice`.
371
+ */
343
372
  averageFillPrice?: string;
344
373
  /** Order status (taker orders only) */
345
374
  status?: OrderStatus | (string & {});
@@ -433,7 +462,11 @@ export interface OrderFilledEvent extends OrderEvent {
433
462
  tradesCount?: number;
434
463
  /** Remaining quantity (present for both, should be 0 for filled orders) */
435
464
  remainingQuantity?: string;
436
- /** Average fill price (taker orders only) */
465
+ /**
466
+ * The order's cumulative average fill price, on both roles: the average
467
+ * across every fill of the order (an edit's carried fills included), as
468
+ * REST reports it — not this trade's price, which is `executionPrice`.
469
+ */
437
470
  averageFillPrice?: string;
438
471
  /** Order status (taker orders only) */
439
472
  status?: OrderStatus | (string & {});
@@ -42,7 +42,14 @@ export interface PositionEventData {
42
42
  side: PositionEventSide | (string & {});
43
43
  /** Position lifecycle status (SCREAMING_SNAKE_CASE on the wire, e.g. "OPEN") */
44
44
  status: PositionEventStatus | (string & {});
45
- /** Absolute position size (decimal string) */
45
+ /**
46
+ * Absolute position size (decimal string). Open frames carry current size;
47
+ * terminal frames normally carry lifetime reduced quantity — the sum of
48
+ * every reducing execution, not only the exposure before the final close.
49
+ * After restart, incomplete legacy size history carries the known partial
50
+ * quantity and leaves the frame unranked. Detect closure from `status`,
51
+ * never from `size === "0"`.
52
+ */
46
53
  size: string;
47
54
  /** Average entry price (decimal string) */
48
55
  entryPrice: string;
@@ -134,6 +141,21 @@ export interface PositionEventData {
134
141
  * that window, and the frame is the fresher one.
135
142
  */
136
143
  updatedAt: string;
144
+ /**
145
+ * When the position OPENED (ISO 8601): the fill that took its exposure from
146
+ * zero to non-zero. It never changes for the life of `positionId`, so time
147
+ * held is now minus `openedAt` while open, and `updatedAt` minus `openedAt`
148
+ * on a terminal frame. A flip closes the position and opens a new one with
149
+ * a new `positionId` and its own `openedAt`.
150
+ *
151
+ * Absent when the server does not know it — never filled with the time the
152
+ * frame was sent. A REST read of the same position reports the same
153
+ * instant, normally to within one matching-engine step; after a server
154
+ * restart it can move by the server's own clock drift. Clamp a computed time
155
+ * held at zero. Not versioned: take it from the newest payload (frame or
156
+ * REST read) rather than skipping it on an equal `version`.
157
+ */
158
+ openedAt?: string;
137
159
  /**
138
160
  * Opaque, non-negative producer-owned row version for this position
139
161
  * (0XM-2673). Compare only within the same `positionId`; higher is newer.
@@ -144,14 +166,10 @@ export interface PositionEventData {
144
166
  * an unranked frame is not comparable with a snapshot row even when their
145
167
  * state matches.
146
168
  * Absent means UNRANKED, never "oldest", and it does NOT tell you whether
147
- * anything was persisted. Four cases reach it: the frame came from a
148
- * producer that predates this field; the emit path wrote no row;
149
- * the path DID write the row but re-reads live risk state after sequencing
150
- * (`funding`), so the mutation did advance the persisted version; or the
151
- * frame is a different projection of the row
152
- * than persistence stores (terminal frames report `size` 0 and
153
- * `LIQUIDATED`, while the stored row keeps its size and records `CLOSED`).
154
- * In the last two, a REST read or a fresh snapshot ranks the mutation.
169
+ * anything was persisted. Current cases are a producer predating this field,
170
+ * an emit path whose command wrote no position row, or a terminal frame
171
+ * rebuilt after restart from legacy reduction history that lacks the size or
172
+ * margin fields needed to reconstruct complete lifetime values.
155
173
  * Fall back to a full field comparison rather than ranking it lowest.
156
174
  *
157
175
  * The merge rule is PER FIELD GROUP, never per frame. On a higher version
@@ -172,15 +190,15 @@ export interface PositionEventData {
172
190
  * mutation — up to the one-hour funding interval.
173
191
  *
174
192
  * A frame is ranked only when it is a faithful projection of the row
175
- * persisted at that sequence: fills that leave a position OPEN, direct
176
- * isolated-position margin adds/reductions, and copy-position margin adds.
193
+ * persisted at that sequence: fills, non-zero funding settlements, terminal
194
+ * closes/liquidations/ADL, direct isolated-position margin adds/reductions,
195
+ * and copy-position margin adds. Funding carries state captured inside its
196
+ * sequencer command; terminal frames retain lifetime reduced quantity and
197
+ * exact CLOSED/LIQUIDATED classification.
177
198
  * The copy add refreshes the isolated child and its copy-cross siblings at
178
199
  * the same version. Cross-risk-bucket ALLOCATE/RELEASE and copy follow/stop
179
200
  * refreshes use `margin_added`/`margin_reduced` but are UNRANKED because
180
- * those commands write no position rows. Funding re-reads live state after
181
- * sequencing and is also unranked. TERMINAL frames are unranked because
182
- * they report `size` 0 and `LIQUIDATED` while the stored row keeps its size
183
- * and records `CLOSED`. Wallet IN/OUT and plain isolated allocation emit no
201
+ * those commands write no position rows. Wallet IN/OUT and plain isolated allocation emit no
184
202
  * position frame. Transfer frames use captured post-command state and are
185
203
  * released only after durable acknowledgement.
186
204
  */
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Position Valuation WebSocket Event Types
3
+ *
4
+ * Periodic mark-derived valuation of one OPEN position, delivered on the same
5
+ * authenticated `positions` / `positions:<tradingPairId>` channel as lifecycle
6
+ * `position_update` frames, with `eventType: "position_valuation"`.
7
+ *
8
+ * Valuation data only: it carries no size, side, status or version, and never
9
+ * creates, reopens, closes or resizes a position. Apply it only to a position
10
+ * you already hold as `OPEN` whose `updatedAt` is earlier than the frame's
11
+ * `valuedAt`, and ignore it otherwise: valuations are spread over each
12
+ * interval, so one can arrive after a newer `position_update` (a fill, a close,
13
+ * a funding settlement) for the same position. `@0xmonaco/core` delivers these to the `onValuation` callback of
14
+ * `positions(...)`, never to its lifecycle handler.
15
+ */
16
+ /**
17
+ * The five mark-derived figures of one open position, from the same
18
+ * derivation as a lifecycle frame's figures for that position.
19
+ */
20
+ export interface PositionValuationEventData {
21
+ /** Position identifier (UUID) */
22
+ positionId: string;
23
+ /** Margin account that owns the position (UUID) */
24
+ marginAccountId: string;
25
+ /** Trading pair identifier (UUID) */
26
+ tradingPairId: string;
27
+ /** Current mark price (decimal string) */
28
+ markPrice: string;
29
+ /** Unrealized PnL at the mark price (decimal string) */
30
+ unrealizedPnl: string;
31
+ /**
32
+ * Liquidation price (decimal string), or `null` when the server cannot
33
+ * derive one for this position (for example an isolated risk bucket shared
34
+ * by several positions, or one whose collateral basis is not positive).
35
+ */
36
+ liquidationPrice: string | null;
37
+ /** Initial margin this position requires at the mark price (decimal string) */
38
+ initialMarginRequired: string;
39
+ /** Maintenance margin this position requires at the mark price (decimal string) */
40
+ maintenanceMarginRequired: string;
41
+ /**
42
+ * When the server read the position (RFC 3339). Not the oracle publish time
43
+ * and not the position's last mutation (`updatedAt` on lifecycle frames),
44
+ * but on the same server clock as `updatedAt`: a valuation whose `valuedAt`
45
+ * is not later than the held position's `updatedAt` was read before that
46
+ * state and is stale.
47
+ */
48
+ valuedAt: string;
49
+ }
50
+ /**
51
+ * Periodic valuation frame for one open position.
52
+ */
53
+ export interface PositionValuationEvent {
54
+ /** Event type identifier */
55
+ eventType: "position_valuation";
56
+ /** User ID (UUID) */
57
+ userId: string;
58
+ /** Valuation data */
59
+ data: PositionValuationEventData;
60
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Position Valuation WebSocket Event Types
3
+ *
4
+ * Periodic mark-derived valuation of one OPEN position, delivered on the same
5
+ * authenticated `positions` / `positions:<tradingPairId>` channel as lifecycle
6
+ * `position_update` frames, with `eventType: "position_valuation"`.
7
+ *
8
+ * Valuation data only: it carries no size, side, status or version, and never
9
+ * creates, reopens, closes or resizes a position. Apply it only to a position
10
+ * you already hold as `OPEN` whose `updatedAt` is earlier than the frame's
11
+ * `valuedAt`, and ignore it otherwise: valuations are spread over each
12
+ * interval, so one can arrive after a newer `position_update` (a fill, a close,
13
+ * a funding settlement) for the same position. `@0xmonaco/core` delivers these to the `onValuation` callback of
14
+ * `positions(...)`, never to its lifecycle handler.
15
+ */
@@ -10,6 +10,6 @@
10
10
  * hand-written SDK surface. CI regenerates it and fails on a diff, identical to
11
11
  * the `schema.ts` wire-types tripwire (MON-1476), so it can never go stale.
12
12
  */
13
- export declare const OPERATION_IDS: readonly ["add_follow_position_margin", "attach_position_tp_sl", "batch_cancel_all", "batch_cancel_all_by_pair", "batch_cancel_orders", "batch_close_all_positions", "batch_create_orders", "batch_replace_orders", "cancel_conditional_order", "cancel_order", "cancel_twap_order", "check_trader_code_availability", "claim_buildercode_rewards", "claim_managed_market_lease", "clear_trader_code", "close_all_copy_positions", "close_follow_positions", "close_position", "create_challenge", "create_delegated_session", "create_order", "create_sub_account_limit", "create_twap_order", "delete_sub_account_limit", "get_application_config", "get_application_stats", "get_available_collateral", "get_buildercode_payout_summary", "get_buildercode_rewards_balance", "get_buildercodes_config", "get_candles", "get_conditional_order", "get_faucet_info", "get_follow", "get_funding_state", "get_index_price", "get_lead_trader", "get_margin_account_movements", "get_margin_account_summary", "get_mark_price", "get_market_metadata", "get_market_stats", "get_my_fee_tier", "get_my_lead_trader", "get_my_referral_downline", "get_my_referral_position", "get_my_trader_code", "get_open_interest", "get_order_by_id", "get_orderbook_snapshot", "get_orders", "get_parent_margin_account_movements", "get_parent_margin_account_summary", "get_perp_market_config", "get_perp_market_summary", "get_portfolio_assets", "get_portfolio_chart", "get_portfolio_margin", "get_portfolio_performance", "get_portfolio_realized_pnl", "get_portfolio_stats", "get_portfolio_summary", "get_position", "get_position_pnl_history", "get_position_risk", "get_pulse", "get_rewards_balance", "get_screener", "get_self_trade_prevention_default", "get_sub_account_limits", "get_sweeper_chains", "get_trade_by_id", "get_trader_code_info", "get_trades", "get_trading_pair_by_id", "get_twap_order", "get_twap_order_tca", "get_user_balance_by_asset", "get_user_balances", "get_user_movements", "get_user_profile", "get_user_trades", "get_withdrawal", "health_check", "initiate_withdrawal", "list_all_funding_history", "list_application_balances", "list_application_movements", "list_application_orders", "list_application_users", "list_builder_fee_changes", "list_buildercode_payouts", "list_conditional_orders", "list_delegated_agent_owners", "list_delegated_agents", "list_follow_leader_positions", "list_funding_history", "list_funding_payments", "list_lead_trader_closed_trades", "list_lead_trader_open_positions", "list_lead_traders", "list_managed_market_assignments", "list_margin_accounts", "list_my_followers", "list_my_follows", "list_pending_withdrawals", "list_position_history", "list_positions", "list_sub_accounts_with_balances", "list_trading_pairs", "list_twap_orders", "mint_tokens", "preview_follow", "refresh_managed_market_quotes", "refresh_session", "register_deposit_address", "replace_order", "revoke_delegated_agent", "revoke_session", "set_builder_fee", "set_self_trade_prevention_default", "set_trader_code", "simulate_fees", "simulate_order_risk", "simulate_parent_margin_order_risk", "simulate_risk_bucket_order_risk", "stop_follow", "submit_whitelist", "transfer_collateral_from_margin_account", "transfer_collateral_from_parent_margin_account", "transfer_collateral_to_margin_account", "transfer_collateral_to_parent_margin_account", "transfer_collateral_to_risk_bucket", "transfer_rewards", "update_sub_account_limit", "upsert_delegated_agent", "upsert_follow", "upsert_lead_trader", "verify_signature"];
13
+ export declare const OPERATION_IDS: readonly ["add_follow_position_margin", "attach_position_tp_sl", "batch_cancel_all", "batch_cancel_all_by_pair", "batch_cancel_orders", "batch_close_all_positions", "batch_create_orders", "batch_replace_orders", "cancel_conditional_order", "cancel_order", "cancel_twap_order", "check_trader_code_availability", "claim_buildercode_rewards", "claim_managed_market_lease", "clear_trader_code", "close_all_copy_positions", "close_follow_positions", "close_position", "close_sub_account", "create_challenge", "create_delegated_session", "create_order", "create_sub_account", "create_sub_account_limit", "create_twap_order", "delete_sub_account_limit", "get_application_config", "get_application_stats", "get_available_collateral", "get_buildercode_payout_summary", "get_buildercode_rewards_balance", "get_buildercodes_config", "get_candles", "get_conditional_order", "get_faucet_info", "get_follow", "get_funding_state", "get_index_price", "get_lead_trader", "get_margin_account_movements", "get_margin_account_pnl", "get_margin_account_summary", "get_mark_price", "get_market_metadata", "get_market_stats", "get_my_fee_tier", "get_my_lead_trader", "get_my_referral_downline", "get_my_referral_position", "get_my_referral_tree", "get_my_trader_code", "get_open_interest", "get_order_by_id", "get_orderbook_snapshot", "get_orders", "get_parent_margin_account_movements", "get_parent_margin_account_summary", "get_perp_market_config", "get_perp_market_summary", "get_portfolio_assets", "get_portfolio_chart", "get_portfolio_margin", "get_portfolio_performance", "get_portfolio_realized_pnl", "get_portfolio_stats", "get_portfolio_summary", "get_position", "get_position_pnl_history", "get_position_risk", "get_pulse", "get_rewards_balance", "get_screener", "get_self_trade_prevention_default", "get_sub_account_limits", "get_sweeper_chains", "get_trade_by_id", "get_trader_code_info", "get_trades", "get_trading_pair_by_id", "get_twap_order", "get_twap_order_tca", "get_user_balance_by_asset", "get_user_balances", "get_user_movements", "get_user_profile", "get_user_trades", "get_withdrawal", "health_check", "initiate_withdrawal", "list_all_funding_history", "list_application_balances", "list_application_movements", "list_application_orders", "list_application_users", "list_builder_fee_changes", "list_buildercode_payouts", "list_conditional_orders", "list_delegated_agent_owners", "list_delegated_agents", "list_follow_leader_positions", "list_funding_history", "list_funding_payments", "list_lead_trader_closed_trades", "list_lead_trader_open_positions", "list_lead_traders", "list_managed_market_assignments", "list_margin_accounts", "list_my_followers", "list_my_follows", "list_pending_withdrawals", "list_position_history", "list_positions", "list_sub_accounts_with_balances", "list_trading_pairs", "list_twap_orders", "mint_tokens", "preview_follow", "refresh_managed_market_quotes", "refresh_session", "register_deposit_address", "replace_order", "revoke_delegated_agent", "revoke_session", "set_builder_fee", "set_self_trade_prevention_default", "set_trader_code", "simulate_fees", "simulate_order_risk", "simulate_parent_margin_order_risk", "simulate_risk_bucket_order_risk", "stop_follow", "submit_whitelist", "transfer_collateral", "transfer_collateral_from_margin_account", "transfer_collateral_from_parent_margin_account", "transfer_collateral_from_sub_account", "transfer_collateral_to_margin_account", "transfer_collateral_to_parent_margin_account", "transfer_collateral_to_risk_bucket", "transfer_collateral_to_sub_account", "transfer_rewards", "update_sub_account_limit", "upsert_delegated_agent", "upsert_follow", "upsert_lead_trader", "verify_signature"];
14
14
  /** Union of every OpenAPI operationId in the spec. */
15
15
  export type OperationId = (typeof OPERATION_IDS)[number];