@0xmonaco/types 1.0.56 → 1.0.58

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.
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { Address } from "viem";
7
7
  import type { BaseAPI } from "../api";
8
- import type { OrderSide, OrderStatus, OrderType, TimeInForce } from "../trading";
8
+ import type { OrderSide, OrderStatus, OrderType, SelfTradePreventionMode, TimeInForce } from "../trading";
9
9
  /**
10
10
  * Account movement/transaction information.
11
11
  * Represents transactions/movements returned in the profile's recent_movements array.
@@ -502,6 +502,17 @@ export interface UserProfile {
502
502
  /** Additional maker fee in basis points contributed by the application (if any) */
503
503
  applicationMakerFeeBps?: number;
504
504
  }
505
+ /**
506
+ * The wallet's self-trade-prevention default — the mode applied when an order
507
+ * from this wallet family would match the family's own resting order and the
508
+ * order itself names no override.
509
+ */
510
+ export interface SelfTradePreventionDefault {
511
+ /** The wallet's effective mode. */
512
+ mode: SelfTradePreventionMode;
513
+ /** True when this wallet has explicitly set a default; false when the platform default (`CANCEL_MAKER`) is in effect. */
514
+ isCustom: boolean;
515
+ }
505
516
  /**
506
517
  * Profile API interface.
507
518
  * Provides methods for fetching and managing user profile information.
@@ -612,4 +623,27 @@ export interface ProfileAPI extends BaseAPI {
612
623
  * @throws ValidationError If pagination params or a UUID filter are invalid; this may occur before any network request.
613
624
  */
614
625
  listFundingPayments(params?: ListFundingPaymentsParams): Promise<ListFundingPaymentsResponse>;
626
+ /**
627
+ * Get the wallet's self-trade-prevention default.
628
+ *
629
+ * Fetches the setting from the /api/v1/accounts/self-trade-prevention endpoint.
630
+ * Requires a valid access token to be set. The default is wallet-scoped: it
631
+ * covers every application and account sharing the wallet address.
632
+ *
633
+ * @returns Promise resolving to the effective mode plus whether it was explicitly set
634
+ */
635
+ getSelfTradePreventionDefault(): Promise<SelfTradePreventionDefault>;
636
+ /**
637
+ * Set the wallet's self-trade-prevention default.
638
+ *
639
+ * Sends a PUT to the /api/v1/accounts/self-trade-prevention endpoint. The
640
+ * write is sequenced through the matching engine; on success the wallet
641
+ * family's next order already resolves the new mode. Delegated-agent
642
+ * sessions cannot change it (403).
643
+ *
644
+ * @param mode - One of "CANCEL_MAKER", "CANCEL_TAKER", "CANCEL_BOTH", "SKIP"
645
+ * @returns Promise resolving to the setting now in force
646
+ * @throws ValidationError If mode is not a known token; this occurs before any network request.
647
+ */
648
+ setSelfTradePreventionDefault(mode: SelfTradePreventionMode): Promise<SelfTradePreventionDefault>;
615
649
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { BaseAPI } from "../api/index";
7
7
  import type { MarginMode } from "../margin-accounts";
8
- import type { Order, OrderSide, PositionSide, TimeInForce, TradingMode } from "./orders";
8
+ import type { Order, OrderSide, PositionSide, SelfTradePreventionMode, TimeInForce, TradingMode } from "./orders";
9
9
  import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, CancelTwapOrderResponse, ConditionalOrder, CreateOrderResponse, CreateTwapOrderOptions, CreateTwapOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, GetTwapOrderTcaResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, ListTwapOrdersParams, ListTwapOrdersResponse, ParentTpSlLegParams, ReplaceOrderResponse, TwapOrder } from "./responses";
10
10
  /**
11
11
  * Trading API interface.
@@ -45,6 +45,13 @@ export interface TradingAPI extends BaseAPI {
45
45
  * Echoed back as `postOnly` on order detail and list reads.
46
46
  */
47
47
  postOnly?: boolean;
48
+ /**
49
+ * Per-order self-trade-prevention override: CANCEL_MAKER, CANCEL_TAKER,
50
+ * CANCEL_BOTH, or SKIP. Omitted, your wallet's configured default
51
+ * applies, else the platform default CANCEL_MAKER. Echoed back as
52
+ * `selfTradePreventionMode` on order reads.
53
+ */
54
+ selfTradePreventionMode?: SelfTradePreventionMode;
48
55
  /**
49
56
  * Client-assigned correlation handle, echoed back on order reads and
50
57
  * order WebSocket events. At most 64 characters from [A-Za-z0-9._:-].
@@ -82,6 +89,13 @@ export interface TradingAPI extends BaseAPI {
82
89
  positionSide?: PositionSide;
83
90
  leverage?: string;
84
91
  reduceOnly?: boolean;
92
+ /**
93
+ * Per-order self-trade-prevention override: CANCEL_MAKER, CANCEL_TAKER,
94
+ * CANCEL_BOTH, or SKIP. Omitted, your wallet's configured default
95
+ * applies, else the platform default CANCEL_MAKER. Echoed back as
96
+ * `selfTradePreventionMode` on order reads.
97
+ */
98
+ selfTradePreventionMode?: SelfTradePreventionMode;
85
99
  /**
86
100
  * Client-assigned correlation handle, echoed back on order reads and
87
101
  * order WebSocket events. At most 64 characters from [A-Za-z0-9._:-].
@@ -149,6 +163,12 @@ export interface TradingAPI extends BaseAPI {
149
163
  quantity?: string;
150
164
  useMasterBalance?: boolean;
151
165
  postOnly?: boolean;
166
+ /**
167
+ * Re-states the self-trade-prevention override for the replacement:
168
+ * nothing is inherited from the original order. Omitted, your wallet's
169
+ * configured default applies, else the platform default CANCEL_MAKER.
170
+ */
171
+ selfTradePreventionMode?: SelfTradePreventionMode;
152
172
  /**
153
173
  * Client-assigned correlation handle, echoed back on order reads and
154
174
  * order WebSocket events. At most 64 characters from [A-Za-z0-9._:-].
@@ -238,6 +258,6 @@ export interface TradingAPI extends BaseAPI {
238
258
  */
239
259
  listTwapOrders(params?: ListTwapOrdersParams): Promise<ListTwapOrdersResponse>;
240
260
  }
241
- export type { ConditionalOrderConditionType, ConditionalOrderState, ConditionalOrderTriggerSource, Order, OrderRole, OrderSide, OrderStatus, OrderStatusFilter, OrderTerminalReason, OrderType, PositionSide, TimeInForce, TradingMode, TwapExecutionStyle, TwapOrderState, } from "./orders";
261
+ export type { ConditionalOrderConditionType, ConditionalOrderState, ConditionalOrderTriggerSource, ListedOrderType, Order, OrderRole, OrderSide, OrderStatus, OrderStatusFilter, OrderTerminalReason, OrderType, PositionSide, SelfTradePreventionMode, TimeInForce, TradingMode, TwapExecutionStyle, TwapOrderState, } from "./orders";
242
262
  export { ORDER_STATUS_VALUES } from "./orders";
243
263
  export type { BatchCancelError, BatchCancelOrdersResponse, BatchCancelResult, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchCreateResult, BatchError, BatchReplaceOrderParams, BatchReplaceOrdersResponse, BatchReplaceResult, CancelConditionalOrderResponse, CancelOrderResponse, CancelTwapOrderResponse, ConditionalOrder, CreateOrderResponse, CreateTwapOrderOptions, CreateTwapOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, GetTwapOrderTcaResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, ListTwapOrdersParams, ListTwapOrdersResponse, MatchResult, ParentTpSlLegParams, ReplaceOrderResponse, TwapOrder, UpdatedFields, } from "./responses";
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Types for trading operations and order management.
5
5
  */
6
+ import type { ConditionalOrder, TwapOrder } from "./responses";
6
7
  /**
7
8
  * Standard order structure used across all order-related responses.
8
9
  * This represents the complete order information as returned by the API.
@@ -13,6 +14,13 @@
13
14
  * Orders can transition to `CANCELLED`, `REJECTED`, or `EXPIRED` at various stages.
14
15
  * Fee fields are only populated after order fills occur.
15
16
  *
17
+ * The order listing returns every kind of order in one stream, so a row here
18
+ * may be a book order, a TWAP parent (`orderType: "TWAP"`) or a conditional
19
+ * order (`orderType: "CONDITIONAL"`). Switch on `orderType`: the kind-specific
20
+ * detail hangs off `twap` / `conditional`, and the fields above are populated
21
+ * for every kind — a parent's `quantity` is its total, `filledQuantity` what
22
+ * it has executed so far, and `status` its state expressed as an order status.
23
+ *
16
24
  * @example
17
25
  * To calculate remaining quantity:
18
26
  * ```typescript
@@ -26,8 +34,8 @@ export interface Order {
26
34
  tradingPairId: string;
27
35
  /** Order side (BUY or SELL) */
28
36
  side: OrderSide;
29
- /** Order type - see OrderType for all supported types */
30
- orderType: OrderType;
37
+ /** What kind of order this row is - see ListedOrderType */
38
+ orderType: ListedOrderType;
31
39
  /** Order status - see OrderStatus for lifecycle details */
32
40
  status: OrderStatus;
33
41
  /** Order price - null for market orders, required for limit orders */
@@ -70,6 +78,14 @@ export interface Order {
70
78
  reduceOnly?: boolean;
71
79
  /** Whether the order was placed post-only (maker-only). Absent for orders placed before the flag was persisted. */
72
80
  postOnly?: boolean;
81
+ /**
82
+ * The per-order self-trade-prevention override REQUESTED when this order was
83
+ * placed or replaced. Absent when the order carried no override — including
84
+ * every order placed before the field was accepted on write — even though a
85
+ * wallet or platform default still governed its matching: this echoes the
86
+ * request, not the resolved default.
87
+ */
88
+ selfTradePreventionMode?: SelfTradePreventionMode;
73
89
  /**
74
90
  * Client-assigned correlation handle as stored: the value supplied on create
75
91
  * or replace, with surrounding whitespace trimmed. Absent when the order
@@ -82,6 +98,18 @@ export interface Order {
82
98
  clientOrderId?: string;
83
99
  /** Position ID linked to the order, when available */
84
100
  positionId?: string;
101
+ /**
102
+ * The TWAP parent behind this row - its schedule, slice counters and
103
+ * progress - present only when `orderType` is `"TWAP"`. Identical to what
104
+ * `getTwapOrder` returns for the same id.
105
+ */
106
+ twap?: TwapOrder;
107
+ /**
108
+ * The conditional order behind this row - its trigger and the order it fires
109
+ * - present only when `orderType` is `"CONDITIONAL"`. Identical to what the
110
+ * conditional-order endpoints return for the same id.
111
+ */
112
+ conditional?: ConditionalOrder;
85
113
  /** Stable cause when status is CANCELLED */
86
114
  terminalReason?: OrderTerminalReason;
87
115
  /**
@@ -131,7 +159,7 @@ export interface Order {
131
159
  version?: number;
132
160
  }
133
161
  /** Stable terminal causes for accepted orders that end as CANCELLED. */
134
- export type OrderTerminalReason = "USER_REQUESTED" | "REPLACED" | "LIQUIDATION" | "INSUFFICIENT_MARGIN" | "REDUCE_ONLY_EXHAUSTED" | "POSITION_CLOSED" | "OCO_SIBLING_TRIGGERED" | "SYSTEM";
162
+ export type OrderTerminalReason = "USER_REQUESTED" | "REPLACED" | "LIQUIDATION" | "INSUFFICIENT_MARGIN" | "REDUCE_ONLY_EXHAUSTED" | "POSITION_CLOSED" | "OCO_SIBLING_TRIGGERED" | "SELF_TRADE_PREVENTION" | "SYSTEM";
135
163
  /**
136
164
  * Role of the creator or order
137
165
  */
@@ -154,6 +182,16 @@ export type PositionSide = "LONG" | "SHORT" | "NONE";
154
182
  * - TRAILING_STOP: Stop order that trails the market price
155
183
  */
156
184
  export type OrderType = "LIMIT" | "MARKET";
185
+ /**
186
+ * What kind of order a listed row is.
187
+ *
188
+ * Wider than {@link OrderType}, which is what you can place: the order listing
189
+ * serves book orders, TWAP parents and conditional orders as one stream, and
190
+ * `"TWAP"` / `"CONDITIONAL"` name the two kinds that are created through their
191
+ * own endpoints rather than `createOrder`. A row of either kind carries its
192
+ * detail on {@link Order.twap} or {@link Order.conditional}.
193
+ */
194
+ export type ListedOrderType = OrderType | "TWAP" | "CONDITIONAL";
157
195
  /**
158
196
  * Source-of-truth order status values used by runtime validation schemas.
159
197
  */
@@ -195,6 +233,24 @@ export type TradingMode = "SPOT" | "MARGIN";
195
233
  * `GTC` together with `expirationDate`.
196
234
  */
197
235
  export type TimeInForce = "GTC" | "IOC" | "FOK" | "GTD";
236
+ /**
237
+ * Per-order self-trade-prevention override: how the engine resolves the order
238
+ * matching against one of your own resting orders (whole wallet family,
239
+ * subaccounts included; the incoming order's mode governs the step).
240
+ * - CANCEL_MAKER: cancel each of your resting orders encountered and keep
241
+ * matching (the platform default when no override or wallet default is set)
242
+ * - CANCEL_TAKER: fill third-party liquidity up to the first self-touch, then
243
+ * cancel the incoming order's remainder (zero-fill CANCELLED possible)
244
+ * - CANCEL_BOTH: CANCEL_TAKER plus cancelling the encountered resting orders;
245
+ * an FOK order with your own order in the fill path is rejected with
246
+ * SELF_TRADE_NOT_ALLOWED
247
+ * - SKIP: trade around your resting orders; a remainder that would rest
248
+ * crossing one of your surviving orders is cancelled instead of resting
249
+ *
250
+ * STP cancellations carry `terminalReason: "SELF_TRADE_PREVENTION"` and
251
+ * `stpCounterpartyOrderId` on order reads and WebSocket events.
252
+ */
253
+ export type SelfTradePreventionMode = "CANCEL_MAKER" | "CANCEL_TAKER" | "CANCEL_BOTH" | "SKIP";
198
254
  /**
199
255
  * Conditional TP/SL condition type.
200
256
  */
@@ -4,7 +4,7 @@
4
4
  * Response types for trading operations.
5
5
  */
6
6
  import type { MarginMode } from "../margin-accounts";
7
- import type { ConditionalOrderConditionType, ConditionalOrderState, ConditionalOrderTriggerSource, Order, OrderSide, OrderStatus, OrderStatusFilter, OrderType, PositionSide, TimeInForce, TradingMode, TwapExecutionStyle, TwapOrderState } from "./orders";
7
+ import type { ConditionalOrderConditionType, ConditionalOrderState, ConditionalOrderTriggerSource, Order, OrderSide, OrderStatus, OrderStatusFilter, OrderType, PositionSide, SelfTradePreventionMode, TimeInForce, TradingMode, TwapExecutionStyle, TwapOrderState } from "./orders";
8
8
  /**
9
9
  * Match result information for order execution.
10
10
  * Contains detailed information about trades, fills, and execution quality.
@@ -375,6 +375,16 @@ export interface BatchCreateOrderParams {
375
375
  * detail and list reads.
376
376
  */
377
377
  postOnly?: boolean;
378
+ /**
379
+ * Per-order self-trade-prevention override. An unknown value fails only this
380
+ * item, with a structured `error.code` of
381
+ * `INVALID_SELF_TRADE_PREVENTION_MODE`; an FOK item under CANCEL_BOTH with
382
+ * your own order in the fill path fails with `SELF_TRADE_NOT_ALLOWED`.
383
+ * Omitted, your wallet's configured default applies, else the platform
384
+ * default CANCEL_MAKER. Echoed back as `selfTradePreventionMode` on order
385
+ * reads.
386
+ */
387
+ selfTradePreventionMode?: SelfTradePreventionMode;
378
388
  /**
379
389
  * Client-assigned correlation handle, echoed back on order reads and on
380
390
  * order WebSocket events. At most 64 characters from [A-Za-z0-9._:-].
@@ -405,6 +415,12 @@ export interface BatchReplaceOrderParams {
405
415
  * inherited from the original order — see `TradingAPI.replaceOrder`.
406
416
  */
407
417
  postOnly?: boolean;
418
+ /**
419
+ * Re-states the self-trade-prevention override for the replacement
420
+ * (optional). Nothing is inherited from the original order; an unknown value
421
+ * fails only this item with `INVALID_SELF_TRADE_PREVENTION_MODE`.
422
+ */
423
+ selfTradePreventionMode?: SelfTradePreventionMode;
408
424
  /**
409
425
  * Client-assigned correlation handle, echoed back on order reads and on
410
426
  * order WebSocket events. At most 64 characters from [A-Za-z0-9._:-].
@@ -28,6 +28,19 @@ export declare const TransactionTypeSchema: z.ZodEnum<{
28
28
  INTEREST: "INTEREST";
29
29
  REWARD: "REWARD";
30
30
  }>;
31
+ /**
32
+ * Set Self-Trade-Prevention Default validation schema
33
+ *
34
+ * Validates the body of PUT /api/v1/accounts/self-trade-prevention.
35
+ */
36
+ export declare const SetSelfTradePreventionDefaultSchema: z.ZodObject<{
37
+ mode: z.ZodEnum<{
38
+ CANCEL_MAKER: "CANCEL_MAKER";
39
+ CANCEL_TAKER: "CANCEL_TAKER";
40
+ CANCEL_BOTH: "CANCEL_BOTH";
41
+ SKIP: "SKIP";
42
+ }>;
43
+ }, z.core.$strip>;
31
44
  /**
32
45
  * Get User Movements validation schema
33
46
  *
@@ -5,7 +5,7 @@
5
5
  * Provides clear, actionable error messages for invalid parameters.
6
6
  */
7
7
  import { z } from "zod";
8
- import { UUIDSchema } from "./trading.js";
8
+ import { SelfTradePreventionModeSchema, UUIDSchema } from "./trading.js";
9
9
  /**
10
10
  * Ledger entry type validation
11
11
  */
@@ -18,6 +18,14 @@ export const LedgerEntryTypeSchema = z.enum(["CREDIT", "DEBIT", "LOCK", "UNLOCK"
18
18
  export const TransactionTypeSchema = z.enum(["DEPOSIT", "WITHDRAWAL", "TRADE", "FEE", "FUNDING", "LIQUIDATION", "INTEREST", "REWARD"], {
19
19
  message: 'Transaction type must be "DEPOSIT", "WITHDRAWAL", "TRADE", "FEE", "FUNDING", "LIQUIDATION", "INTEREST", or "REWARD"',
20
20
  });
21
+ /**
22
+ * Set Self-Trade-Prevention Default validation schema
23
+ *
24
+ * Validates the body of PUT /api/v1/accounts/self-trade-prevention.
25
+ */
26
+ export const SetSelfTradePreventionDefaultSchema = z.object({
27
+ mode: SelfTradePreventionModeSchema,
28
+ });
21
29
  /**
22
30
  * Get User Movements validation schema
23
31
  *
@@ -43,6 +43,15 @@ export declare const ConditionalTimeInForceSchema: z.ZodEnum<{
43
43
  GTC: "GTC";
44
44
  IOC: "IOC";
45
45
  }>;
46
+ /**
47
+ * Per-order self-trade-prevention override validation
48
+ */
49
+ export declare const SelfTradePreventionModeSchema: z.ZodEnum<{
50
+ CANCEL_MAKER: "CANCEL_MAKER";
51
+ CANCEL_TAKER: "CANCEL_TAKER";
52
+ CANCEL_BOTH: "CANCEL_BOTH";
53
+ SKIP: "SKIP";
54
+ }>;
46
55
  /**
47
56
  * Order type validation
48
57
  */
@@ -126,6 +135,12 @@ export declare const PlaceLimitOrderSchema: z.ZodObject<{
126
135
  leverage: z.ZodOptional<z.ZodString>;
127
136
  reduceOnly: z.ZodOptional<z.ZodBoolean>;
128
137
  postOnly: z.ZodOptional<z.ZodBoolean>;
138
+ selfTradePreventionMode: z.ZodOptional<z.ZodEnum<{
139
+ CANCEL_MAKER: "CANCEL_MAKER";
140
+ CANCEL_TAKER: "CANCEL_TAKER";
141
+ CANCEL_BOTH: "CANCEL_BOTH";
142
+ SKIP: "SKIP";
143
+ }>>;
129
144
  takeProfit: z.ZodOptional<z.ZodObject<{
130
145
  triggerPrice: z.ZodString;
131
146
  orderType: z.ZodEnum<{
@@ -192,6 +207,12 @@ export declare const PlaceMarketOrderSchema: z.ZodObject<{
192
207
  }>>;
193
208
  leverage: z.ZodOptional<z.ZodString>;
194
209
  reduceOnly: z.ZodOptional<z.ZodBoolean>;
210
+ selfTradePreventionMode: z.ZodOptional<z.ZodEnum<{
211
+ CANCEL_MAKER: "CANCEL_MAKER";
212
+ CANCEL_TAKER: "CANCEL_TAKER";
213
+ CANCEL_BOTH: "CANCEL_BOTH";
214
+ SKIP: "SKIP";
215
+ }>>;
195
216
  takeProfit: z.ZodOptional<z.ZodObject<{
196
217
  triggerPrice: z.ZodString;
197
218
  orderType: z.ZodEnum<{
@@ -248,6 +269,12 @@ export declare const ReplaceOrderSchema: z.ZodObject<{
248
269
  quantity: z.ZodOptional<z.ZodString>;
249
270
  useMasterBalance: z.ZodOptional<z.ZodBoolean>;
250
271
  postOnly: z.ZodOptional<z.ZodBoolean>;
272
+ selfTradePreventionMode: z.ZodOptional<z.ZodEnum<{
273
+ CANCEL_MAKER: "CANCEL_MAKER";
274
+ CANCEL_TAKER: "CANCEL_TAKER";
275
+ CANCEL_BOTH: "CANCEL_BOTH";
276
+ SKIP: "SKIP";
277
+ }>>;
251
278
  }, z.core.$strip>;
252
279
  }, z.core.$strip>;
253
280
  /**
@@ -300,11 +327,11 @@ export declare const ConditionalOrderTriggerSourceSchema: z.ZodEnum<{
300
327
  export declare const ConditionalOrderStateSchema: z.ZodEnum<{
301
328
  CANCELLED: "CANCELLED";
302
329
  EXPIRED: "EXPIRED";
330
+ FAILED: "FAILED";
303
331
  PENDING_PARENT: "PENDING_PARENT";
304
332
  ACTIVE: "ACTIVE";
305
333
  TRIGGERING: "TRIGGERING";
306
334
  TRIGGERED: "TRIGGERED";
307
- FAILED: "FAILED";
308
335
  }>;
309
336
  export declare const ClosePositionSideSchema: z.ZodEnum<{
310
337
  LONG: "LONG";
@@ -319,11 +346,11 @@ export declare const ListConditionalOrdersSchema: z.ZodObject<{
319
346
  state: z.ZodOptional<z.ZodEnum<{
320
347
  CANCELLED: "CANCELLED";
321
348
  EXPIRED: "EXPIRED";
349
+ FAILED: "FAILED";
322
350
  PENDING_PARENT: "PENDING_PARENT";
323
351
  ACTIVE: "ACTIVE";
324
352
  TRIGGERING: "TRIGGERING";
325
353
  TRIGGERED: "TRIGGERED";
326
- FAILED: "FAILED";
327
354
  }>>;
328
355
  page: z.ZodOptional<z.ZodNumber>;
329
356
  pageSize: z.ZodOptional<z.ZodNumber>;
@@ -437,6 +464,12 @@ export declare const BatchCreateOrderItemSchema: z.ZodObject<{
437
464
  leverage: z.ZodOptional<z.ZodString>;
438
465
  reduceOnly: z.ZodOptional<z.ZodBoolean>;
439
466
  postOnly: z.ZodOptional<z.ZodBoolean>;
467
+ selfTradePreventionMode: z.ZodOptional<z.ZodEnum<{
468
+ CANCEL_MAKER: "CANCEL_MAKER";
469
+ CANCEL_TAKER: "CANCEL_TAKER";
470
+ CANCEL_BOTH: "CANCEL_BOTH";
471
+ SKIP: "SKIP";
472
+ }>>;
440
473
  }, z.core.$strip>;
441
474
  /**
442
475
  * Maximum items per batch create/replace/cancel request. Mirrors the server's
@@ -491,6 +524,12 @@ export declare const BatchCreateOrdersSchema: z.ZodObject<{
491
524
  leverage: z.ZodOptional<z.ZodString>;
492
525
  reduceOnly: z.ZodOptional<z.ZodBoolean>;
493
526
  postOnly: z.ZodOptional<z.ZodBoolean>;
527
+ selfTradePreventionMode: z.ZodOptional<z.ZodEnum<{
528
+ CANCEL_MAKER: "CANCEL_MAKER";
529
+ CANCEL_TAKER: "CANCEL_TAKER";
530
+ CANCEL_BOTH: "CANCEL_BOTH";
531
+ SKIP: "SKIP";
532
+ }>>;
494
533
  }, z.core.$strip>>;
495
534
  }, z.core.$strip>;
496
535
  /**
@@ -505,6 +544,12 @@ export declare const BatchReplaceOrderItemSchema: z.ZodObject<{
505
544
  quantity: z.ZodOptional<z.ZodString>;
506
545
  useMasterBalance: z.ZodOptional<z.ZodBoolean>;
507
546
  postOnly: z.ZodOptional<z.ZodBoolean>;
547
+ selfTradePreventionMode: z.ZodOptional<z.ZodEnum<{
548
+ CANCEL_MAKER: "CANCEL_MAKER";
549
+ CANCEL_TAKER: "CANCEL_TAKER";
550
+ CANCEL_BOTH: "CANCEL_BOTH";
551
+ SKIP: "SKIP";
552
+ }>>;
508
553
  }, z.core.$strip>;
509
554
  /**
510
555
  * Batch Replace Orders validation schema
@@ -518,5 +563,11 @@ export declare const BatchReplaceOrdersSchema: z.ZodObject<{
518
563
  quantity: z.ZodOptional<z.ZodString>;
519
564
  useMasterBalance: z.ZodOptional<z.ZodBoolean>;
520
565
  postOnly: z.ZodOptional<z.ZodBoolean>;
566
+ selfTradePreventionMode: z.ZodOptional<z.ZodEnum<{
567
+ CANCEL_MAKER: "CANCEL_MAKER";
568
+ CANCEL_TAKER: "CANCEL_TAKER";
569
+ CANCEL_BOTH: "CANCEL_BOTH";
570
+ SKIP: "SKIP";
571
+ }>>;
521
572
  }, z.core.$strip>>;
522
573
  }, z.core.$strip>;
@@ -36,6 +36,12 @@ export const TimeInForceSchema = z.enum(["GTC", "IOC", "FOK"], {
36
36
  export const ConditionalTimeInForceSchema = z.enum(["GTC", "IOC"], {
37
37
  message: 'Conditional order time in force must be "GTC" or "IOC"',
38
38
  });
39
+ /**
40
+ * Per-order self-trade-prevention override validation
41
+ */
42
+ export const SelfTradePreventionModeSchema = z.enum(["CANCEL_MAKER", "CANCEL_TAKER", "CANCEL_BOTH", "SKIP"], {
43
+ message: 'Self-trade prevention mode must be "CANCEL_MAKER", "CANCEL_TAKER", "CANCEL_BOTH", or "SKIP"',
44
+ });
39
45
  /**
40
46
  * Order type validation
41
47
  */
@@ -153,6 +159,7 @@ export const PlaceLimitOrderSchema = z
153
159
  leverage: PositiveDecimalStringSchema.optional(),
154
160
  reduceOnly: z.boolean().optional(),
155
161
  postOnly: z.boolean().optional(),
162
+ selfTradePreventionMode: SelfTradePreventionModeSchema.optional(),
156
163
  takeProfit: ParentTpSlLegSchema.optional(),
157
164
  stopLoss: ParentTpSlLegSchema.optional(),
158
165
  })
@@ -231,6 +238,7 @@ export const PlaceMarketOrderSchema = z
231
238
  positionSide: PositionSideSchema.optional(),
232
239
  leverage: PositiveDecimalStringSchema.optional(),
233
240
  reduceOnly: z.boolean().optional(),
241
+ selfTradePreventionMode: SelfTradePreventionModeSchema.optional(),
234
242
  takeProfit: ParentTpSlLegSchema.optional(),
235
243
  stopLoss: ParentTpSlLegSchema.optional(),
236
244
  })
@@ -316,6 +324,8 @@ export const ReplaceOrderSchema = z.object({
316
324
  // replaceable fields — the server validates postOnly against the
317
325
  // persisted original order, which this client-side schema cannot see.
318
326
  postOnly: z.boolean().optional(),
327
+ // Re-stated per replace, never inherited from the original order.
328
+ selfTradePreventionMode: SelfTradePreventionModeSchema.optional(),
319
329
  }),
320
330
  });
321
331
  /**
@@ -530,6 +540,7 @@ export const BatchCreateOrderItemSchema = z
530
540
  leverage: PositiveDecimalStringSchema.optional(),
531
541
  reduceOnly: z.boolean().optional(),
532
542
  postOnly: z.boolean().optional(),
543
+ selfTradePreventionMode: SelfTradePreventionModeSchema.optional(),
533
544
  })
534
545
  .refine((data) => data.orderType !== "LIMIT" || data.price !== undefined, {
535
546
  message: "Price is required for LIMIT orders",
@@ -624,6 +635,8 @@ export const BatchReplaceOrderItemSchema = z
624
635
  // replaceable fields — the server validates postOnly against the
625
636
  // persisted original order, which this client-side schema cannot see.
626
637
  postOnly: z.boolean().optional(),
638
+ // Re-stated per replace, never inherited from the original order.
639
+ selfTradePreventionMode: SelfTradePreventionModeSchema.optional(),
627
640
  })
628
641
  .refine((data) => data.price !== undefined || data.quantity !== undefined, {
629
642
  message: "At least one of price or quantity must be provided",
@@ -4,7 +4,7 @@
4
4
  * TypeScript types for order websocket events matching the Rust backend definitions.
5
5
  * Each event type has specific data fields based on the event context.
6
6
  */
7
- import type { OrderRole, OrderSide, OrderStatus, OrderTerminalReason, OrderType, TimeInForce, TradingMode } from "../../trading";
7
+ import type { OrderRole, OrderSide, OrderStatus, OrderTerminalReason, OrderType, SelfTradePreventionMode, TimeInForce, TradingMode } from "../../trading";
8
8
  import type { RawEventMessage } from "../base";
9
9
  /**
10
10
  * Order event types
@@ -137,6 +137,19 @@ export interface CommonOrderEventData {
137
137
  * Wire: `post_only`.
138
138
  */
139
139
  postOnly?: boolean;
140
+ /**
141
+ * The self-trade-prevention override REQUESTED on the order
142
+ * (`"CANCEL_MAKER" | "CANCEL_TAKER" | "CANCEL_BOTH" | "SKIP"`), echoed so a
143
+ * subscriber can confirm what was accepted without a round trip to
144
+ * `getOrder`. Carried on the `OrderPlaced` acknowledgement, taker fills and
145
+ * remainder cancels, maker fills (the maker's OWN requested mode), the
146
+ * resting order's lifecycle frames, and the `orders` snapshot frame. Omitted
147
+ * when the order carried none — including every order that merely matched
148
+ * under a wallet or platform default, and every event emitted by a server
149
+ * predating the field: this echoes the request, never the resolved default.
150
+ * Wire: `self_trade_prevention_mode`.
151
+ */
152
+ selfTradePreventionMode?: SelfTradePreventionMode | (string & {});
140
153
  }
141
154
  /**
142
155
  * OrderPlaced event - emitted when a new order is placed
@@ -389,6 +402,21 @@ export interface OrderCancelledEvent extends OrderEvent {
389
402
  reason?: string;
390
403
  /** Stable machine-readable cancellation cause */
391
404
  terminalReason?: OrderTerminalReason | (string & {});
405
+ /**
406
+ * The counterparty order behind a self-trade-prevention cancellation: for
407
+ * a resting order cancelled because an order of the same owner arrived
408
+ * against it, the arriving order's id; for an arriving order whose
409
+ * remainder was cancelled instead, the owner's resting order it would
410
+ * have matched. The same audit back-pointer Bybit publishes as
411
+ * `smpOrderId`.
412
+ *
413
+ * Present ONLY when `terminalReason` is `SELF_TRADE_PREVENTION`, so
414
+ * presence is the whole signal. Absent means this was not an STP
415
+ * cancellation — or the event predates the field, including every event
416
+ * until the STP modes ship, since nothing emits it yet. Wire:
417
+ * `stp_counterparty_order_id`.
418
+ */
419
+ stpCounterpartyOrderId?: string;
392
420
  /**
393
421
  * Cumulative order fill at cancellation, mirroring `filledQuantity` on the
394
422
  * taker/maker fill events so consumers read one field across every order
@@ -481,6 +509,15 @@ export interface OrderPartiallyCancelledEvent extends OrderEvent {
481
509
  remainingQuantityRaw: string;
482
510
  /** Caller-supplied cancel reason; explicit `null` when none was given */
483
511
  reason: string | null;
512
+ /**
513
+ * Reserved: the counterparty order behind a self-trade-prevention
514
+ * REDUCTION. No shipped STP mode reduces a resting order — the four modes
515
+ * cancel in full, and DECREMENT/TRANSFER are out of scope — so nothing
516
+ * emits this today; the field exists so a future reducing mode needs no
517
+ * wire change. Same contract as `OrderCancelledEvent`'s field when it is
518
+ * present. Wire: `stp_counterparty_order_id`.
519
+ */
520
+ stpCounterpartyOrderId?: string;
484
521
  /** When the reduction happened (RFC3339 `Z`). Wire: `reduced_at`. */
485
522
  reducedAt: string;
486
523
  };
@@ -24,7 +24,7 @@
24
24
  * frame, so its callback is never invoked. That is a silent no-op, never an
25
25
  * error.
26
26
  */
27
- import type { OrderSide, OrderType, TimeInForce, TradingMode } from "../trading";
27
+ import type { OrderSide, OrderType, SelfTradePreventionMode, TimeInForce, TradingMode } from "../trading";
28
28
  /**
29
29
  * Receives one channel's complete subscribe-time state.
30
30
  *
@@ -59,8 +59,8 @@ export type SnapshotHandler<T> = (items: T[]) => void;
59
59
  * Nullability mirrors the wire exactly. Every optional field below is a Rust
60
60
  * `Option` serialized WITHOUT `skip_serializing_if`, so the key is always
61
61
  * present and carries `null` when unset — hence `| null` rather than `?`.
62
- * `clientOrderId` is the sole field the server omits outright, so it is the
63
- * sole `?`.
62
+ * `clientOrderId`, `selfTradePreventionMode` and `version` are the fields the
63
+ * server omits outright, so they are the `?`s.
64
64
  *
65
65
  * The value unions are widened (`Union | (string & {})`) for the same reason
66
66
  * the order event's are: the parser hands an unrecognized value through rather
@@ -122,6 +122,14 @@ export interface OrderSnapshotItem {
122
122
  * when the order carried none, matching the live event payload.
123
123
  */
124
124
  clientOrderId?: string;
125
+ /**
126
+ * The self-trade-prevention override REQUESTED on the order
127
+ * (`"CANCEL_MAKER" | "CANCEL_TAKER" | "CANCEL_BOTH" | "SKIP"`), carried for
128
+ * the `clientOrderId` reason above. Omitted — not `null` — when the order
129
+ * carried none, matching the live event payload: this echoes the request,
130
+ * never the resolved wallet or platform default.
131
+ */
132
+ selfTradePreventionMode?: SelfTradePreventionMode | (string & {});
125
133
  /**
126
134
  * Sequencer step this order's state was last written by — the SAME counter
127
135
  * the live order events and the REST endpoints carry (0XM-2440).
@@ -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_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_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", "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"];
14
14
  /** Union of every OpenAPI operationId in the spec. */
15
15
  export type OperationId = (typeof OPERATION_IDS)[number];
@@ -66,6 +66,7 @@ export const OPERATION_IDS = [
66
66
  "get_pulse",
67
67
  "get_rewards_balance",
68
68
  "get_screener",
69
+ "get_self_trade_prevention_default",
69
70
  "get_sub_account_limits",
70
71
  "get_sweeper_chains",
71
72
  "get_trade_by_id",
@@ -105,6 +106,7 @@ export const OPERATION_IDS = [
105
106
  "replace_order",
106
107
  "revoke_delegated_agent",
107
108
  "revoke_session",
109
+ "set_self_trade_prevention_default",
108
110
  "set_trader_code",
109
111
  "simulate_fees",
110
112
  "simulate_order_risk",