@0xmonaco/types 1.0.56 → 1.0.58-develop.f12e78b

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.
@@ -31,10 +31,24 @@ export interface AuthAPI extends BaseAPI {
31
31
  /**
32
32
  * Signs a challenge message using the wallet client.
33
33
  *
34
- * Signs the provided message using the wallet's private key.
35
- * This is used in the authentication flow to prove ownership of the wallet.
34
+ * Asks the connected wallet to authorize the message, proving control of the
35
+ * address. An EOA signs it with its private key (EIP-191 `personal_sign`). A
36
+ * smart-contract wallet such as a Safe has no private key and returns a
37
+ * signature its own contract will accept, which the server checks under
38
+ * EIP-1271; the wallet client handles that difference, and the returned value
39
+ * is submitted unchanged either way.
36
40
  *
37
- * @param message - The message to sign
41
+ * The returned signature is therefore not guaranteed to be 65 bytes — a
42
+ * contract signature is usually longer — so callers must not assume the
43
+ * EOA shape.
44
+ *
45
+ * Note the scope. Server-side EIP-1271 verification is deliberately narrow:
46
+ * it is offered only to a wallet holding a BuilderCodes payout bucket, on a
47
+ * deployment with the contract-wallet flag on and a chain RPC endpoint
48
+ * configured. An ordinary smart-contract trading account is not covered — it
49
+ * still takes the recovery path, which it cannot satisfy.
50
+ *
51
+ * @param message - The message to authorize
38
52
  * @returns Promise resolving to the signature
39
53
  */
40
54
  signChallenge(message: string): Promise<string>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * BuilderCodes Types
3
+ *
4
+ * Types for the BuilderCodes API: reading and claiming an enrolled frontend's
5
+ * per-trade revenue share.
6
+ */
7
+ import type { BaseAPI } from "../api";
8
+ import type { ClaimBuildercodeRewardsParams, ClaimBuildercodeRewardsResponse, GetBuildercodePayoutSummaryResponse, GetBuildercodeRewardsBalanceResponse, GetBuildercodesConfigResponse, ListBuildercodePayoutsParams, ListBuildercodePayoutsResponse } from "./responses";
9
+ /**
10
+ * BuilderCodes payout API interface.
11
+ *
12
+ * BuilderCodes is Monaco's per-trade frontend revenue share: an enrolled
13
+ * frontend earns a configured share of the net take on every fill its users
14
+ * generate, accruing to a reserved payout bucket owned by the frontend's
15
+ * configured payout wallet. Accrual is internal accounting only — this API is
16
+ * how that balance is claimed into a tradeable (and then withdrawable) balance.
17
+ */
18
+ export interface BuildercodesAPI extends BaseAPI {
19
+ /** Read this authenticated frontend's enrollment, payout address, and live budget. */
20
+ getConfig(): Promise<GetBuildercodesConfigResponse>;
21
+ /** List this authenticated frontend's per-trade BuilderCodes credits. */
22
+ listPayouts(params?: ListBuildercodePayoutsParams): Promise<ListBuildercodePayoutsResponse>;
23
+ /** Summarize this authenticated frontend's BuilderCodes credits by token. */
24
+ getPayoutSummary(): Promise<GetBuildercodePayoutSummaryResponse>;
25
+ /** Read the authenticated wallet's available reserved reward balances. */
26
+ getRewardsBalance(): Promise<GetBuildercodeRewardsBalanceResponse>;
27
+ /**
28
+ * Claim accrued BuilderCodes payout balance into a trading balance.
29
+ *
30
+ * Moves the specified amount of a payout token out of the authenticated
31
+ * caller's reserved payout bucket and into their trading balance under the
32
+ * authenticated application, from where the ordinary withdrawal flow applies.
33
+ * Ledger-only — no on-chain transaction and no gas, and the funds are
34
+ * immediately tradeable.
35
+ *
36
+ * The payout wallet may be an EOA or a smart-contract wallet. An EOA answers
37
+ * the signature challenge directly; a multisig such as a Safe authenticates by
38
+ * EIP-1271 contract signature instead. That path is offered only to a wallet
39
+ * holding a BuilderCodes payout bucket, only while `contract_wallet_auth_enabled`
40
+ * is on, and only where the deployment has a chain RPC endpoint configured —
41
+ * otherwise login is EOA-only and a contract payout wallet can neither call
42
+ * this endpoint nor withdraw afterwards.
43
+ *
44
+ * The bucket is resolved from the authenticated caller's own wallet address,
45
+ * so a caller can only ever claim their own accrued balance. A wallet that
46
+ * has never been an enrolled frontend's payout address has nothing to claim.
47
+ * A wallet that *used to be* a payout address keeps what it accrued back then
48
+ * and can still claim it — payout-address changes are not retroactive.
49
+ *
50
+ * Throws 403 when the caller is refused: BuilderCodes is not enabled, or
51
+ * the session is a delegated agent — which is rejected before the feature is
52
+ * checked, so it is a permanent restriction on that session type, not a
53
+ * rollout state. Throws 409 when the payout balance is insufficient for the
54
+ * requested amount. Throws 503 when the matching engine is unreachable,
55
+ * restarting, or slow to answer — an UNKNOWN outcome, not a rejection: the
56
+ * claim is admitted to the sequencer before its reply is sent, so it may
57
+ * still commit, and with no idempotency key a blind retry can claim twice.
58
+ * Do not retry automatically: a balance read cannot settle it, because an
59
+ * admitted claim may still be queued. Ambiguous failures are thrown
60
+ * with `retryable: false` so retry logic driven off that flag cannot claim
61
+ * twice. Two pre-admission rejections stay retryable because they committed
62
+ * nothing: a maintenance block (`OPERATIONS_BLOCKED`) and a sequencer
63
+ * overload (`OVERLOADED`).
64
+ *
65
+ * @param params - Payout token address and raw-unit amount to claim
66
+ * @returns Promise resolving to the post-claim payout and trading balances
67
+ */
68
+ claimBuildercodeRewards(params: ClaimBuildercodeRewardsParams): Promise<ClaimBuildercodeRewardsResponse>;
69
+ }
70
+ export type { BuildercodePayout, BuildercodePayoutTokenTotal, BuildercodeRewardsBalance, ClaimBuildercodeRewardsParams, ClaimBuildercodeRewardsResponse, GetBuildercodePayoutSummaryResponse, GetBuildercodeRewardsBalanceResponse, GetBuildercodesConfigResponse, ListBuildercodePayoutsParams, ListBuildercodePayoutsResponse, } from "./responses";
71
+ export { BuildercodePayoutSchema, BuildercodePayoutTokenTotalSchema, BuildercodeRewardsBalanceSchema, ClaimBuildercodeRewardsParamsSchema, ClaimBuildercodeRewardsResponseSchema, GetBuildercodePayoutSummaryResponseSchema, GetBuildercodeRewardsBalanceResponseSchema, GetBuildercodesConfigResponseSchema, ListBuildercodePayoutsParamsSchema, ListBuildercodePayoutsResponseSchema, } from "./responses";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * BuilderCodes Types
3
+ *
4
+ * Types for the BuilderCodes API: reading and claiming an enrolled frontend's
5
+ * per-trade revenue share.
6
+ */
7
+ export { BuildercodePayoutSchema, BuildercodePayoutTokenTotalSchema, BuildercodeRewardsBalanceSchema, ClaimBuildercodeRewardsParamsSchema, ClaimBuildercodeRewardsResponseSchema, GetBuildercodePayoutSummaryResponseSchema, GetBuildercodeRewardsBalanceResponseSchema, GetBuildercodesConfigResponseSchema, ListBuildercodePayoutsParamsSchema, ListBuildercodePayoutsResponseSchema, } from "./responses";
@@ -0,0 +1,94 @@
1
+ /**
2
+ * BuilderCodes Response Types
3
+ *
4
+ * Types for the BuilderCodes earnings and payout API responses and requests.
5
+ * All types are derived from Zod schemas for runtime validation.
6
+ */
7
+ import { z } from "zod";
8
+ /** Schema for this frontend's current BuilderCodes program state. */
9
+ export declare const GetBuildercodesConfigResponseSchema: z.ZodObject<{
10
+ applicationId: z.ZodString;
11
+ enrolled: z.ZodBoolean;
12
+ payoutAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
13
+ buildercodesEnabled: z.ZodBoolean;
14
+ buildercodesBudgetBps: z.ZodNumber;
15
+ }, z.core.$strip>;
16
+ /** Pagination accepted by the per-trade payout history endpoint. */
17
+ export declare const ListBuildercodePayoutsParamsSchema: z.ZodObject<{
18
+ page: z.ZodOptional<z.ZodNumber>;
19
+ pageSize: z.ZodOptional<z.ZodNumber>;
20
+ }, z.core.$strip>;
21
+ /** One per-trade BuilderCodes credit. Amounts are RAW atomic units. */
22
+ export declare const BuildercodePayoutSchema: z.ZodObject<{
23
+ tradeId: z.ZodString;
24
+ payoutAddress: z.ZodString;
25
+ token: z.ZodString;
26
+ amount: z.ZodString;
27
+ appliedBps: z.ZodNumber;
28
+ createdAt: z.ZodString;
29
+ }, z.core.$strip>;
30
+ /** Schema for the paginated per-trade payout history. */
31
+ export declare const ListBuildercodePayoutsResponseSchema: z.ZodObject<{
32
+ payouts: z.ZodArray<z.ZodObject<{
33
+ tradeId: z.ZodString;
34
+ payoutAddress: z.ZodString;
35
+ token: z.ZodString;
36
+ amount: z.ZodString;
37
+ appliedBps: z.ZodNumber;
38
+ createdAt: z.ZodString;
39
+ }, z.core.$strip>>;
40
+ total: z.ZodNumber;
41
+ page: z.ZodNumber;
42
+ pageSize: z.ZodNumber;
43
+ totalPages: z.ZodNumber;
44
+ }, z.core.$strip>;
45
+ /** One token-denominated BuilderCodes earnings total. */
46
+ export declare const BuildercodePayoutTokenTotalSchema: z.ZodObject<{
47
+ token: z.ZodString;
48
+ totalAmount: z.ZodString;
49
+ payoutCount: z.ZodNumber;
50
+ lastCreditedAt: z.ZodString;
51
+ }, z.core.$strip>;
52
+ /** Schema for this frontend's payout summary. */
53
+ export declare const GetBuildercodePayoutSummaryResponseSchema: z.ZodObject<{
54
+ totalPayouts: z.ZodNumber;
55
+ lastCreditedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ byToken: z.ZodArray<z.ZodObject<{
57
+ token: z.ZodString;
58
+ totalAmount: z.ZodString;
59
+ payoutCount: z.ZodNumber;
60
+ lastCreditedAt: z.ZodString;
61
+ }, z.core.$strip>>;
62
+ }, z.core.$strip>;
63
+ /** One available balance in the reserved BuilderCodes reward bucket. */
64
+ export declare const BuildercodeRewardsBalanceSchema: z.ZodObject<{
65
+ token: z.ZodString;
66
+ available: z.ZodString;
67
+ }, z.core.$strip>;
68
+ /** Schema for the caller wallet's reserved BuilderCodes balances. */
69
+ export declare const GetBuildercodeRewardsBalanceResponseSchema: z.ZodObject<{
70
+ balances: z.ZodArray<z.ZodObject<{
71
+ token: z.ZodString;
72
+ available: z.ZodString;
73
+ }, z.core.$strip>>;
74
+ }, z.core.$strip>;
75
+ /** Schema for the claim-BuilderCodes-rewards request body. */
76
+ export declare const ClaimBuildercodeRewardsParamsSchema: z.ZodObject<{
77
+ token: z.ZodString;
78
+ amount: z.ZodString;
79
+ }, z.core.$strip>;
80
+ /** Schema for the claim-BuilderCodes-rewards response. */
81
+ export declare const ClaimBuildercodeRewardsResponseSchema: z.ZodObject<{
82
+ payoutBalance: z.ZodString;
83
+ tradingBalance: z.ZodString;
84
+ }, z.core.$strip>;
85
+ export type ClaimBuildercodeRewardsParams = z.infer<typeof ClaimBuildercodeRewardsParamsSchema>;
86
+ export type ClaimBuildercodeRewardsResponse = z.infer<typeof ClaimBuildercodeRewardsResponseSchema>;
87
+ export type GetBuildercodesConfigResponse = z.infer<typeof GetBuildercodesConfigResponseSchema>;
88
+ export type ListBuildercodePayoutsParams = z.infer<typeof ListBuildercodePayoutsParamsSchema>;
89
+ export type BuildercodePayout = z.infer<typeof BuildercodePayoutSchema>;
90
+ export type ListBuildercodePayoutsResponse = z.infer<typeof ListBuildercodePayoutsResponseSchema>;
91
+ export type BuildercodePayoutTokenTotal = z.infer<typeof BuildercodePayoutTokenTotalSchema>;
92
+ export type GetBuildercodePayoutSummaryResponse = z.infer<typeof GetBuildercodePayoutSummaryResponseSchema>;
93
+ export type BuildercodeRewardsBalance = z.infer<typeof BuildercodeRewardsBalanceSchema>;
94
+ export type GetBuildercodeRewardsBalanceResponse = z.infer<typeof GetBuildercodeRewardsBalanceResponseSchema>;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * BuilderCodes Response Types
3
+ *
4
+ * Types for the BuilderCodes earnings and payout API responses and requests.
5
+ * All types are derived from Zod schemas for runtime validation.
6
+ */
7
+ import { z } from "zod";
8
+ /** Schema for this frontend's current BuilderCodes program state. */
9
+ export const GetBuildercodesConfigResponseSchema = z.object({
10
+ applicationId: z.string().uuid(),
11
+ enrolled: z.boolean(),
12
+ // Nullable, not merely absent: `payout_address` is an `optional` proto field
13
+ // with no skip-serializing, so the server sends an explicit `null` when no
14
+ // address is configured. `.optional()` alone accepts `undefined` and would
15
+ // throw on that valid response. Matches `lastCreditedAt` below.
16
+ payoutAddress: z.string().nullable().optional(),
17
+ buildercodesEnabled: z.boolean(),
18
+ buildercodesBudgetBps: z.number().int().min(0).max(10_000),
19
+ });
20
+ /** Pagination accepted by the per-trade payout history endpoint. */
21
+ export const ListBuildercodePayoutsParamsSchema = z.object({
22
+ page: z.number().int().min(1).max(10_000).optional(),
23
+ pageSize: z.number().int().min(1).max(100).optional(),
24
+ });
25
+ /** One per-trade BuilderCodes credit. Amounts are RAW atomic units. */
26
+ export const BuildercodePayoutSchema = z.object({
27
+ tradeId: z.string().uuid(),
28
+ payoutAddress: z.string(),
29
+ token: z.string(),
30
+ amount: z.string(),
31
+ appliedBps: z.number().int(),
32
+ createdAt: z.string(),
33
+ });
34
+ /** Schema for the paginated per-trade payout history. */
35
+ export const ListBuildercodePayoutsResponseSchema = z.object({
36
+ payouts: z.array(BuildercodePayoutSchema),
37
+ total: z.number().int().nonnegative(),
38
+ page: z.number().int().positive(),
39
+ pageSize: z.number().int().positive(),
40
+ totalPages: z.number().int().nonnegative(),
41
+ });
42
+ /** One token-denominated BuilderCodes earnings total. */
43
+ export const BuildercodePayoutTokenTotalSchema = z.object({
44
+ token: z.string(),
45
+ totalAmount: z.string(),
46
+ payoutCount: z.number().int().nonnegative(),
47
+ lastCreditedAt: z.string(),
48
+ });
49
+ /** Schema for this frontend's payout summary. */
50
+ export const GetBuildercodePayoutSummaryResponseSchema = z.object({
51
+ totalPayouts: z.number().int().nonnegative(),
52
+ lastCreditedAt: z.string().nullable().optional(),
53
+ byToken: z.array(BuildercodePayoutTokenTotalSchema),
54
+ });
55
+ /** One available balance in the reserved BuilderCodes reward bucket. */
56
+ export const BuildercodeRewardsBalanceSchema = z.object({
57
+ token: z.string(),
58
+ available: z.string(),
59
+ });
60
+ /** Schema for the caller wallet's reserved BuilderCodes balances. */
61
+ export const GetBuildercodeRewardsBalanceResponseSchema = z.object({
62
+ balances: z.array(BuildercodeRewardsBalanceSchema),
63
+ });
64
+ /** Schema for the claim-BuilderCodes-rewards request body. */
65
+ export const ClaimBuildercodeRewardsParamsSchema = z.object({
66
+ /**
67
+ * Payout token contract address (0x-prefixed) to claim. BuilderCodes shares
68
+ * accrue in the quote token of the traded pair.
69
+ */
70
+ token: z
71
+ .string()
72
+ .trim()
73
+ .min(1, "token is required")
74
+ .regex(/^0x[0-9a-fA-F]{40}$/, "token must be a 0x-prefixed EVM address"),
75
+ /**
76
+ * Amount to claim, in RAW atomic units of the token. Must be a positive
77
+ * integer string and no greater than the accrued payout balance — the server
78
+ * rejects an over-claim with 409 rather than moving a partial amount.
79
+ */
80
+ amount: z
81
+ .string()
82
+ .trim()
83
+ .min(1, "amount is required")
84
+ .refine((v) => /^\d+$/.test(v) && BigInt(v) > 0n, "amount must be a positive integer string"),
85
+ });
86
+ /** Schema for the claim-BuilderCodes-rewards response. */
87
+ export const ClaimBuildercodeRewardsResponseSchema = z.object({
88
+ /** Your BuilderCodes payout-bucket balance after the claim, RAW atomic units. */
89
+ payoutBalance: z.string(),
90
+ /** Your trading balance for the token after the claim, RAW atomic units. */
91
+ tradingBalance: z.string(),
92
+ });
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  export * from "./api";
8
8
  export * from "./applications";
9
9
  export * from "./auth";
10
+ export * from "./buildercodes";
10
11
  export * from "./contracts";
11
12
  export * from "./delegated-agents";
12
13
  export * from "./faucet";
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@
8
8
  export * from "./api";
9
9
  export * from "./applications";
10
10
  export * from "./auth";
11
+ export * from "./buildercodes";
11
12
  export * from "./contracts";
12
13
  export * from "./delegated-agents";
13
14
  export * from "./faucet";
@@ -107,6 +107,34 @@ export interface Position {
107
107
  * an understated partial.
108
108
  */
109
109
  cumFees?: string;
110
+ /**
111
+ * Opaque, non-negative producer-owned row version for this position
112
+ * (0XM-2673). Compare only within the same `positionId`; higher is newer.
113
+ *
114
+ * The same number the WebSocket `positions` snapshot and a RANKED live
115
+ * `position_update` frame carry, so this read can be ranked against them.
116
+ * Some live frames are deliberately unranked and omit `version` even when
117
+ * their state matches this row.
118
+ * `0` is the unranked legacy sentinel and never participates in ordering:
119
+ * treat it exactly as an absent version and fall back to a full field
120
+ * comparison rather than ranking it as oldest.
121
+ *
122
+ * The merge rule is PER FIELD GROUP, never per payload. On an EQUAL version
123
+ * skip the versioned fields as an idempotent redelivery — EXCEPT
124
+ * `isolatedMargin`, which the WebSocket positions snapshot overlays from an
125
+ * independent live matching-engine read rather than from the versioned row,
126
+ * so it can reflect a later command than the version names and must be
127
+ * taken from the newer payload. Also still take
128
+ * `markPrice`, `unrealizedPnl`, `liquidationPrice` and `leverage` from the
129
+ * newer payload: those four are re-derived from the oracle mark on every
130
+ * read, carry no version, and the version does not advance for them.
131
+ * Discarding a whole payload on an equal version freezes displayed PnL
132
+ * until the position's next real mutation.
133
+ *
134
+ * A response served from live matching-engine state reports `0`: the engine
135
+ * holds the state but not the version, so it cannot rank itself.
136
+ */
137
+ version?: number;
110
138
  }
111
139
  export interface ListPositionsParams {
112
140
  marginAccountId?: string;
@@ -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
  }
@@ -1,6 +1,7 @@
1
1
  import type { Address, PublicClient, TransactionReceipt, WalletClient } from "viem";
2
2
  import type { ApplicationsAPI } from "../applications";
3
3
  import type { AuthAPI, AuthState } from "../auth/index";
4
+ import type { BuildercodesAPI } from "../buildercodes";
4
5
  import type { DelegatedAgentsAPI } from "../delegated-agents";
5
6
  import type { FaucetAPI } from "../faucet";
6
7
  import type { FeesAPI } from "../fees";
@@ -111,6 +112,8 @@ export interface MonacoSDK {
111
112
  subAccounts: SubAccountsAPI;
112
113
  /** PitPass TraderCode referral and rewards API */
113
114
  pitpass: PitpassAPI;
115
+ /** BuilderCodes frontend revenue-share payout API */
116
+ buildercodes: BuildercodesAPI;
114
117
  /** Testnet faucet API */
115
118
  faucet: FaucetAPI;
116
119
  /** Deposit-address registration (sweeper) API; requires a session */
@@ -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
  *