@0xmonaco/types 1.0.58 → 1.0.60

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.
@@ -47,7 +47,6 @@ const RiskBucketRequestSchema = z.object({
47
47
  tradingPairId: UUIDSchema,
48
48
  strategyKey: z.string().trim().min(1, "Strategy key cannot be empty").optional(),
49
49
  });
50
- const SelectedCrossTradingPairIdsSchema = z.array(UUIDSchema).min(1, "selectedTradingPairIds is required for CROSS risk buckets");
51
50
  const IsolatedRiskBucketRequestSchema = RiskBucketRequestSchema.extend({
52
51
  marginMode: z.literal("ISOLATED").optional(),
53
52
  selectedTradingPairIds: z.never().optional(),
@@ -56,11 +55,16 @@ const IsolatedRiskBucketRequestSchema = RiskBucketRequestSchema.extend({
56
55
  // stays strict-rejected (no per-position margin to commit to).
57
56
  applyToPositionMargin: z.boolean().optional(),
58
57
  });
59
- // Simulation still declares the scope it wants previewed: a preview of a
60
- // bucket that may not exist yet has nothing recorded to read from.
61
- const CrossRiskBucketScopeSchema = z.object({
58
+ // A cross preview names no pairs. Cross scope is derived from trading, so a
59
+ // preview has nothing to declare; `selectedTradingPairIds` used to be REQUIRED
60
+ // here (non-empty, containing `tradingPairId`, covering every open cross
61
+ // position) while the server never priced anything from it. The server now
62
+ // ignores it and this schema rejects it, so the caller learns it does nothing
63
+ // rather than believing it took effect. `tradingPairId` stays required: it is
64
+ // the pair being previewed, not a scope declaration.
65
+ const CrossRiskBucketSimulateRequestSchema = z.object({
62
66
  marginMode: z.literal("CROSS"),
63
- selectedTradingPairIds: SelectedCrossTradingPairIdsSchema,
67
+ selectedTradingPairIds: z.never().optional(),
64
68
  strategyKey: z.never().optional(),
65
69
  });
66
70
  // A cross transfer-in names no pairs. Cross scope is derived from trading, so
@@ -83,7 +87,8 @@ export const TransferCollateralToParentMarginAccountSchema = z.object({
83
87
  });
84
88
  // Named ahead of the union: a union of two strict members collapses every
85
89
  // mismatch into a single "Invalid input" on `request`, which would hide the one
86
- // mistake this schema most needs to name.
90
+ // mistake this schema most needs to name — in EVERY mode, since the isolated
91
+ // member is strict too and the server names the field there as well.
87
92
  const CrossTransferNamesNoPairsSchema = z
88
93
  .object({
89
94
  marginMode: z.enum(["ISOLATED", "CROSS"]).optional(),
@@ -91,13 +96,16 @@ const CrossTransferNamesNoPairsSchema = z
91
96
  })
92
97
  .loose()
93
98
  .superRefine((request, ctx) => {
94
- if (request.marginMode === "CROSS" && request.selectedTradingPairIds !== undefined) {
95
- ctx.addIssue({
96
- code: "custom",
97
- path: ["selectedTradingPairIds"],
98
- message: "selectedTradingPairIds is not accepted on a CROSS transfer: cross scope is derived from trading, so a funding call has nothing to declare",
99
- });
99
+ if (request.selectedTradingPairIds === undefined) {
100
+ return;
100
101
  }
102
+ ctx.addIssue({
103
+ code: "custom",
104
+ path: ["selectedTradingPairIds"],
105
+ message: request.marginMode === "CROSS"
106
+ ? "selectedTradingPairIds is not accepted on a CROSS transfer: cross scope is derived from trading, so a funding call has nothing to declare"
107
+ : "selectedTradingPairIds is not supported for ISOLATED risk buckets",
108
+ });
101
109
  });
102
110
  export const TransferCollateralToRiskBucketSchema = z.object({
103
111
  request: CrossTransferNamesNoPairsSchema.pipe(z.union([
@@ -148,14 +156,33 @@ const SimulateOrderRiskRequestSchema = BaseSimulateOrderRiskRequestSchema.strict
148
156
  const SimulateIsolatedRiskBucketOrderRiskRequestSchema = BaseSimulateOrderRiskRequestSchema.merge(IsolatedRiskBucketRequestSchema)
149
157
  .strict()
150
158
  .superRefine(validateOneWaySimulationFields);
151
- const SimulateCrossRiskBucketOrderRiskRequestSchema = BaseSimulateOrderRiskRequestSchema.merge(CrossRiskBucketScopeSchema)
159
+ const SimulateCrossRiskBucketOrderRiskRequestSchema = BaseSimulateOrderRiskRequestSchema.merge(CrossRiskBucketSimulateRequestSchema)
152
160
  .strict()
153
- .superRefine(validateOneWaySimulationFields)
154
- .refine((data) => data.selectedTradingPairIds.includes(data.tradingPairId), {
155
- message: "tradingPairId must be included in selectedTradingPairIds for CROSS risk buckets",
156
- path: ["selectedTradingPairIds"],
157
- });
158
- const SimulateRiskBucketOrderRiskRequestSchema = z.union([SimulateIsolatedRiskBucketOrderRiskRequestSchema, SimulateCrossRiskBucketOrderRiskRequestSchema]);
161
+ .superRefine(validateOneWaySimulationFields);
162
+ // Named ahead of the union for the same reason `CrossTransferNamesNoPairsSchema`
163
+ // is: a union of two strict members collapses every mismatch into a single
164
+ // "Invalid input" on `request`, which would hide the one mistake this schema
165
+ // most needs to name — in every mode, with the server's own wording for
166
+ // ISOLATED (where the field never applied).
167
+ const CrossSimulateNamesNoPairsSchema = z
168
+ .object({
169
+ marginMode: z.enum(["ISOLATED", "CROSS"]).optional(),
170
+ selectedTradingPairIds: z.unknown().optional(),
171
+ })
172
+ .loose()
173
+ .superRefine((request, ctx) => {
174
+ if (request.selectedTradingPairIds === undefined) {
175
+ return;
176
+ }
177
+ ctx.addIssue({
178
+ code: "custom",
179
+ path: ["selectedTradingPairIds"],
180
+ message: request.marginMode === "CROSS"
181
+ ? "selectedTradingPairIds is not accepted on a CROSS preview: cross scope is derived from trading, so a preview has nothing to declare"
182
+ : "selectedTradingPairIds is not supported for ISOLATED risk buckets",
183
+ });
184
+ });
185
+ const SimulateRiskBucketOrderRiskRequestSchema = CrossSimulateNamesNoPairsSchema.pipe(z.union([SimulateIsolatedRiskBucketOrderRiskRequestSchema, SimulateCrossRiskBucketOrderRiskRequestSchema]));
159
186
  export const SimulateOrderRiskSchema = z
160
187
  .object({
161
188
  marginAccountId: UUIDSchema,
@@ -8,6 +8,7 @@
8
8
  * Detected broadcast lag closes the connection with 1013 and requires resync.
9
9
  * A lost terminal position update need not have a later replacement.
10
10
  */
11
+ import type { MarginMode } from "../../margin-accounts";
11
12
  /**
12
13
  * Position side. The server emits `LONG` or `SHORT` for an open position.
13
14
  */
@@ -55,6 +56,50 @@ export interface PositionEventData {
55
56
  isolatedMargin: string;
56
57
  /** Effective leverage (decimal string) */
57
58
  leverage: string;
59
+ /**
60
+ * Risk bucket that scopes this position's margin (UUID) — the same
61
+ * `riskBucketId` REST returns (0XM-2668). Omitted only for a legacy
62
+ * unbucketed position, and on a terminal frame whose close came back through
63
+ * the durable log rather than in-band.
64
+ */
65
+ riskBucketId?: string;
66
+ /**
67
+ * Margin mode of `riskBucketId`: `CROSS` or `ISOLATED`, the same `marginMode`
68
+ * REST returns (0XM-2668). Omitted for a position with no risk bucket, since
69
+ * there is then no mode to report.
70
+ *
71
+ * Do NOT infer it from `riskBucketId` in either direction. The two are
72
+ * resolved from different sources — the bucket id from the position, the mode
73
+ * from the risk engine when it holds the position and from the bucket row
74
+ * otherwise — so an id can arrive with no mode: a terminal row whose bucket
75
+ * record is unavailable, a read taken while the engine is unreachable, or a
76
+ * producer older than this field. Treat a missing mode as unknown and leave
77
+ * the position's mode unchanged; defaulting it to `CROSS` mis-renders an
78
+ * isolated position's backing.
79
+ *
80
+ * VERSIONED: a position's mode changes only on a real mutation, never on an
81
+ * oracle tick. See `version`.
82
+ */
83
+ marginMode?: MarginMode | (string & {});
84
+ /**
85
+ * Maintenance margin this position requires at `markPrice` (decimal string),
86
+ * the same `maintenanceMarginRequired` REST returns (0XM-2668). `"0"` when
87
+ * the position has no open exposure, so a terminal frame reports zero rather
88
+ * than omitting it.
89
+ *
90
+ * UNVERSIONED: re-derived from the oracle mark on every frame. See `version`
91
+ * for the whole unversioned group.
92
+ */
93
+ maintenanceMarginRequired?: string;
94
+ /**
95
+ * Initial margin this position requires at `markPrice` (decimal string),
96
+ * honoring both its effective leverage and the market initial-margin floor —
97
+ * the same `initialMarginRequired` REST returns (0XM-2668). `"0"` when the
98
+ * position has no open exposure.
99
+ *
100
+ * UNVERSIONED, for the same reason as `maintenanceMarginRequired`.
101
+ */
102
+ initialMarginRequired?: string;
58
103
  /** Trade that caused the update, when driven by a fill (UUID). Omitted otherwise. */
59
104
  tradeId?: string;
60
105
  /** Order that caused the update, when driven by an order (UUID). Omitted otherwise. */
@@ -65,8 +110,77 @@ export interface PositionEventData {
65
110
  * `margin_reduced`, `margin_collateral_transfer`.
66
111
  */
67
112
  reason: string;
68
- /** Timestamp when the position state was updated (ISO 8601) */
113
+ /**
114
+ * When the position was last MUTATED (ISO 8601) — a fill, collateral
115
+ * transfer, funding settlement or close.
116
+ *
117
+ * Read from the producer's own record of the mutation, never stamped while
118
+ * the frame is serialized (0XM-2668), so two frames for a position nothing
119
+ * has changed repeat one timestamp and a valuation-only oracle reprice does
120
+ * not move it. Do not use it as a reconciliation key — that is `version`'s
121
+ * job; this is display metadata.
122
+ *
123
+ * It matches a REST read of the same OPEN position exactly. Two cases come
124
+ * from the server's persistence clock instead and differ by the persistence
125
+ * lag: a TERMINAL row (this frame carries the engine's close instant, a
126
+ * terminal REST read carries the stored one), and any position read after a
127
+ * matching-engine restart. Accurate to that lag, not to the microsecond.
128
+ *
129
+ * A third case is not lag-bounded: while the server's matching engine is
130
+ * unreachable, a REST read of an OPEN position falls back to that row's
131
+ * lifecycle timestamps and can report the position's opening instant until
132
+ * funding settles. This frame is unaffected — it is built from engine state
133
+ * — so a REST value OLDER than a frame you already hold is expected during
134
+ * that window, and the frame is the fresher one.
135
+ */
69
136
  updatedAt: string;
137
+ /**
138
+ * Opaque, non-negative producer-owned row version for this position
139
+ * (0XM-2673). Compare only within the same `positionId`; higher is newer.
140
+ *
141
+ * Carried on RANKED live frames and on the subscribe-time `positions`
142
+ * snapshot, so a client can rank the two against each other on
143
+ * `positionId + version`. Not every live frame is ranked — see below — so
144
+ * an unranked frame is not comparable with a snapshot row even when their
145
+ * state matches.
146
+ * 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, `margin_added`/`margin_reduced`), so the mutation did advance
151
+ * the persisted version; or the 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.
155
+ * Fall back to a full field comparison rather than ranking it lowest.
156
+ *
157
+ * The merge rule is PER FIELD GROUP, never per frame. On a higher version
158
+ * apply everything. On an EQUAL version skip the versioned fields as an
159
+ * idempotent redelivery — EXCEPT `isolatedMargin`, which the subscribe-time
160
+ * snapshot overlays from an independent live matching-engine read rather
161
+ * than from the versioned row, so it can reflect a later command than the
162
+ * version names and must be taken from the newer payload or you retain
163
+ * stale backing. Also still take `markPrice`, `unrealizedPnl`,
164
+ * `liquidationPrice`, `leverage`, `maintenanceMarginRequired` and
165
+ * `initialMarginRequired` from the newer frame: those six are re-derived
166
+ * per frame rather than served from the versioned row, carry no version,
167
+ * and the version does not advance for them. Five move with the oracle
168
+ * mark; `leverage` does not — it is opening notional over posted margin —
169
+ * but the live surfaces derive it while a persisted read serves the row's
170
+ * stored column, so it can still disagree at an unchanged version. Discarding an equal-version frame wholesale
171
+ * freezes displayed unrealized PnL until the position's next real
172
+ * mutation — up to the one-hour funding interval.
173
+ *
174
+ * A frame is ranked only when it is a faithful projection of the row
175
+ * persisted at that sequence: in practice the FILLS THAT LEAVE A POSITION
176
+ * OPEN. Unranked are (a) frames that re-read live risk state after their
177
+ * command was sequenced, since a later command can overtake that read —
178
+ * the `funding` and `margin_added`/`margin_reduced` frames — and (b)
179
+ * TERMINAL frames, which report `size` 0 and `LIQUIDATED` while the stored
180
+ * row keeps its size and records `CLOSED`. Those mutations still advance
181
+ * the persisted version, so REST and a fresh snapshot rank them.
182
+ */
183
+ version?: number;
70
184
  }
71
185
  /**
72
186
  * Position event emitted when a user's position state changes.
@@ -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 ["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", "clear_trader_code", "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_candles", "get_conditional_order", "get_faucet_info", "get_funding_state", "get_index_price", "get_margin_account_movements", "get_margin_account_summary", "get_mark_price", "get_market_metadata", "get_market_stats", "get_my_fee_tier", "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_conditional_orders", "list_delegated_agent_owners", "list_delegated_agents", "list_funding_history", "list_funding_payments", "list_margin_accounts", "list_pending_withdrawals", "list_position_history", "list_positions", "list_sub_accounts_with_balances", "list_trading_pairs", "list_twap_orders", "mint_tokens", "refresh_session", "register_deposit_address", "replace_order", "revoke_delegated_agent", "revoke_session", "set_self_trade_prevention_default", "set_trader_code", "simulate_fees", "simulate_order_risk", "simulate_parent_margin_order_risk", "simulate_risk_bucket_order_risk", "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", "verify_signature"];
13
+ export declare const OPERATION_IDS: readonly ["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_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_funding_state", "get_index_price", "get_margin_account_movements", "get_margin_account_summary", "get_mark_price", "get_market_metadata", "get_market_stats", "get_my_fee_tier", "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_buildercode_payouts", "list_conditional_orders", "list_delegated_agent_owners", "list_delegated_agents", "list_funding_history", "list_funding_payments", "list_managed_market_assignments", "list_margin_accounts", "list_pending_withdrawals", "list_position_history", "list_positions", "list_sub_accounts_with_balances", "list_trading_pairs", "list_twap_orders", "mint_tokens", "refresh_managed_market_quotes", "refresh_session", "register_deposit_address", "replace_order", "revoke_delegated_agent", "revoke_session", "set_self_trade_prevention_default", "set_trader_code", "simulate_fees", "simulate_order_risk", "simulate_parent_margin_order_risk", "simulate_risk_bucket_order_risk", "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", "verify_signature"];
14
14
  /** Union of every OpenAPI operationId in the spec. */
15
15
  export type OperationId = (typeof OPERATION_IDS)[number];
@@ -22,6 +22,8 @@ export const OPERATION_IDS = [
22
22
  "cancel_order",
23
23
  "cancel_twap_order",
24
24
  "check_trader_code_availability",
25
+ "claim_buildercode_rewards",
26
+ "claim_managed_market_lease",
25
27
  "clear_trader_code",
26
28
  "close_position",
27
29
  "create_challenge",
@@ -33,6 +35,9 @@ export const OPERATION_IDS = [
33
35
  "get_application_config",
34
36
  "get_application_stats",
35
37
  "get_available_collateral",
38
+ "get_buildercode_payout_summary",
39
+ "get_buildercode_rewards_balance",
40
+ "get_buildercodes_config",
36
41
  "get_candles",
37
42
  "get_conditional_order",
38
43
  "get_faucet_info",
@@ -88,11 +93,13 @@ export const OPERATION_IDS = [
88
93
  "list_application_movements",
89
94
  "list_application_orders",
90
95
  "list_application_users",
96
+ "list_buildercode_payouts",
91
97
  "list_conditional_orders",
92
98
  "list_delegated_agent_owners",
93
99
  "list_delegated_agents",
94
100
  "list_funding_history",
95
101
  "list_funding_payments",
102
+ "list_managed_market_assignments",
96
103
  "list_margin_accounts",
97
104
  "list_pending_withdrawals",
98
105
  "list_position_history",
@@ -101,6 +108,7 @@ export const OPERATION_IDS = [
101
108
  "list_trading_pairs",
102
109
  "list_twap_orders",
103
110
  "mint_tokens",
111
+ "refresh_managed_market_quotes",
104
112
  "refresh_session",
105
113
  "register_deposit_address",
106
114
  "replace_order",