@0xmonaco/types 1.0.60 → 1.0.62

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.
@@ -9,7 +9,7 @@
9
9
  * Query parameters for listing application orders.
10
10
  */
11
11
  export interface ListAppOrdersParams {
12
- /** Page number (starts from 1) */
12
+ /** Page number (starts from 1, at most 10,000 — the last page the listing counts towards) */
13
13
  page?: number;
14
14
  /** Items per page (max 100) */
15
15
  pageSize?: number;
@@ -43,7 +43,7 @@ export interface ListAppUsersParams {
43
43
  * Query parameters for listing application movements.
44
44
  */
45
45
  export interface ListAppMovementsParams {
46
- /** Page number (starts from 1) */
46
+ /** Page number (starts from 1, at most 10,000 — the last page the listing counts towards) */
47
47
  page?: number;
48
48
  /** Items per page (max 100) */
49
49
  pageSize?: number;
@@ -162,13 +162,21 @@ export interface AppBalance {
162
162
  */
163
163
  export interface ListAppOrdersResponse {
164
164
  orders: AppOrder[];
165
- /** Total matching orders */
165
+ /**
166
+ * Matching orders. Exact up to 10,000 pages of the requested page size
167
+ * (`pageSize` x 10,000 rows) and saturates there, so an application with
168
+ * more matching orders than the listing can page through reads the cap,
169
+ * not its lifetime total.
170
+ */
166
171
  total: number;
167
172
  /** Current page number */
168
173
  page: number;
169
174
  /** Items per page */
170
175
  pageSize: number;
171
- /** Total number of pages */
176
+ /**
177
+ * Number of pages at the requested page size. Exact up to 10,000 and
178
+ * saturates there, the last page this listing can reach.
179
+ */
172
180
  totalPages: number;
173
181
  }
174
182
  /**
@@ -190,13 +198,21 @@ export interface ListAppUsersResponse {
190
198
  */
191
199
  export interface ListAppMovementsResponse {
192
200
  movements: AppMovement[];
193
- /** Total matching movements */
201
+ /**
202
+ * Matching movements. Exact up to 10,000 pages of the requested page size
203
+ * (`pageSize` x 10,000 rows) and saturates there, so an application with
204
+ * more matching movements than the listing can page through reads the cap,
205
+ * not its lifetime total.
206
+ */
194
207
  total: number;
195
208
  /** Current page number */
196
209
  page: number;
197
210
  /** Items per page */
198
211
  pageSize: number;
199
- /** Total number of pages */
212
+ /**
213
+ * Number of pages at the requested page size. Exact up to 10,000 and
214
+ * saturates there, the last page this listing can reach.
215
+ */
200
216
  totalPages: number;
201
217
  }
202
218
  /**
@@ -43,6 +43,21 @@ export interface AuthState {
43
43
  expiresAt: number;
44
44
  /** Information about the authenticated user */
45
45
  user: User;
46
+ /**
47
+ * True when this verify created the user — the wallet's first-ever sign-in on
48
+ * this application. Gate first-time UX (e.g. the optional "have a referral
49
+ * code?" input) on it. Absent on responses from a server that predates the
50
+ * field.
51
+ */
52
+ isNewUser?: boolean;
53
+ /**
54
+ * True when a PitPass referral relationship was recorded on this verify: a
55
+ * valid, non-self TraderCode was presented on the wallet's first-ever sign-in
56
+ * and resolved to a known referrer. Use it to confirm the referral landed on
57
+ * the signup-success screen. Absent on responses from a server that predates
58
+ * the field.
59
+ */
60
+ referralApplied?: boolean;
46
61
  }
47
62
  export interface ApplicationInfo {
48
63
  /** Unique identifier for the application */
@@ -1,5 +1,5 @@
1
1
  import type { BaseAPI } from "../api";
2
- import type { OrderSide, OrderType, PositionSide } from "../trading";
2
+ import type { MatchResult, OrderSide, OrderType, PositionSide } from "../trading";
3
3
  export type MarginMode = "ISOLATED" | "CROSS";
4
4
  export interface MarginAccountSummary {
5
5
  marginAccountId: string;
@@ -245,6 +245,25 @@ export interface SimulateOrderRiskRequest {
245
245
  /** Required for normal orders; optional and ignored for reduce-only. */
246
246
  leverage?: string;
247
247
  reduceOnly?: boolean;
248
+ /**
249
+ * MARKET-only slippage tolerance in basis points, 0..1,000 — the rule the
250
+ * server applies to a placed MARKET order: a LIMIT preview carrying it is
251
+ * rejected with the message the order itself would get. It TIGHTENS the walk
252
+ * the preview runs (merged tighter-wins with the engine's 1,000 bps
253
+ * protective band), so `expectedMatchResult` and `estimatedFee` price under
254
+ * the band the real placement will run under. Omit for the placement
255
+ * default; it never widens the band.
256
+ *
257
+ * Carrying a previewed value into placement: the SDK's `placeMarketOrder`
258
+ * and batch helpers take `slippageTolerance` as a RATIO (`0.05` = 500 bps),
259
+ * so pass `slippageToleranceBps / 10_000`; a `slippageToleranceBps` key on
260
+ * those calls is not forwarded.
261
+ *
262
+ * On a first-use ISOLATED preview the value is also forwarded to the
263
+ * bucket's auto-funding for parity with placement; that path floors it at
264
+ * 1,000 bps, so today it does not change the funded figure.
265
+ */
266
+ slippageToleranceBps?: number;
248
267
  }
249
268
  export type SimulateIsolatedRiskBucketOrderRiskRequest = SimulateOrderRiskRequest & {
250
269
  marginMode?: "ISOLATED";
@@ -327,6 +346,51 @@ export interface SimulateOrderRiskResponse {
327
346
  * as unavailable, never as zero.
328
347
  */
329
348
  estimatedLiquidationPrice?: string;
349
+ /**
350
+ * The simulated match the engine ran to admit this order — the same
351
+ * `MatchResult` shape a placement's `matchResult` carries, from the same
352
+ * walk over the live book at the moment of the preview, under
353
+ * `slippageToleranceBps` merged tighter-wins with the 1,000 bps protective
354
+ * band and the caller's own self-trade-prevention default (the preview runs
355
+ * under the caller's wallet, as placement does). Not a client-side re-walk,
356
+ * so preflight and placement read the same numbers. What a preview cannot
357
+ * carry: `postOnly`, TP/SL legs and a per-order self-trade-prevention
358
+ * override — a post-only order that would cross is refused by placement, not
359
+ * by this preview.
360
+ *
361
+ * Read it as: `totalFilled` is what would execute; `remainingQuantity` what
362
+ * the band or the depth leaves unfilled (the partial-fill indicator — a
363
+ * MARKET preview with a non-zero remainder comes back partially filled when
364
+ * placed); `averageFillPrice` and `executionPriceRange.worstPrice` the fill
365
+ * levels, `null` when nothing crosses; `status` the status placement would
366
+ * end in — `FILLED` for a full fill, `CANCELLED` for a MARKET order the band
367
+ * or the depth cuts short (a MARKET remainder cannot rest, so the fills
368
+ * execute and the rest is cancelled; read `remainingQuantity` for the
369
+ * partial fill), `SUBMITTED` for a LIMIT that rests, `PARTIALLY_FILLED` for
370
+ * a LIMIT that crosses partly and rests the remainder; `actualSlippageBps`
371
+ * the realized slippage against `referencePrice`
372
+ * — for a LIMIT or IOC preview, against the limit price, and `null` when
373
+ * every fill improved on it; `maxSlippageBps` echoes your tolerance.
374
+ *
375
+ * Priced against the book RIGHT NOW. A take-profit / stop-loss closes later,
376
+ * on a different book, under the wider 1,200 bps band a triggered market leg
377
+ * carries — so for a TP/SL estimate apply `actualSlippageBps` to the TRIGGER
378
+ * price as an impact figure rather than displaying this absolute average.
379
+ *
380
+ * Present only when `accepted` is true. Absent (`null` on the wire, like
381
+ * `estimatedLiquidationPrice`) on every refused preview, including the
382
+ * post-match maker-risk rejection; treat absence as unknown, not as a zero
383
+ * fill.
384
+ */
385
+ expectedMatchResult?: MatchResult;
386
+ /**
387
+ * The touch on the taking side when a MARKET preview ran (best ask for a
388
+ * BUY, best bid for a SELL) — what `expectedMatchResult` and its
389
+ * `actualSlippageBps` are measured from. Present only when `accepted` is
390
+ * true and the preview is a MARKET order; a LIMIT or IOC preview is measured
391
+ * against its own limit price and publishes nothing here.
392
+ */
393
+ referencePrice?: string;
330
394
  }
331
395
  export interface MarginAccountsAPI extends BaseAPI {
332
396
  listMarginAccounts(params?: ListMarginAccountsParams): Promise<ListMarginAccountsResponse>;
@@ -312,23 +312,87 @@ export interface MarketStats {
312
312
  /** Life-to-date cumulative number of trades summed across all pairs */
313
313
  totalTradeCountLtd: number;
314
314
  }
315
+ /**
316
+ * One notional bracket of a market's margin ladder. Brackets are MARGINAL: a
317
+ * bracket's rate applies only to the notional inside it, and the deduction
318
+ * carries the cheaper margin already charged by the brackets below, so margin
319
+ * is continuous across every bound rather than jumping at it.
320
+ *
321
+ * `PerpMarketConfig.riskTiers` lists every bracket ascending by
322
+ * `lowerBoundNotional`. A position's bracket is the LAST tier whose
323
+ * `lowerBoundNotional` is at or below its notional, `abs(quantity) x markPrice`.
324
+ */
315
325
  export interface RiskTier {
326
+ /**
327
+ * Marginal initial-margin floor rate for notional inside this bracket, as a
328
+ * decimal fraction. The ladder floor is
329
+ * `IM_floor(N) = N x initialMarginRatio - initialMarginDeduction`.
330
+ * A position's requirement is the greater of this floor and its
331
+ * selected-leverage initial margin scaled to the current mark.
332
+ */
316
333
  initialMarginRatio: string;
334
+ /**
335
+ * Marginal maintenance-margin rate for notional inside this bracket, as a
336
+ * decimal fraction. Maintenance margin for a position of notional N in this
337
+ * bracket is `MM(N) = N x maintenanceMarginRatio - maintenanceMarginDeduction`.
338
+ */
317
339
  maintenanceMarginRatio: string;
318
340
  /** Maximum authoritative absolute base-asset quantity. */
319
341
  maxPositionSize?: string;
320
342
  /** @deprecated This legacy alias is base quantity, not notional. */
321
343
  maxPositionNotional?: string;
344
+ /** 1-based bracket index within the market's ladder; 1 is the lowest bracket. */
345
+ tierLevel: number;
346
+ /** USD notional at which this bracket starts, inclusive; "0" for tier 1. */
347
+ lowerBoundNotional: string;
348
+ /**
349
+ * Maximum leverage available inside this bracket. Absent only for a
350
+ * single-tier market configured from explicit margin rates rather than
351
+ * from a leverage.
352
+ */
353
+ maxLeverage?: string;
354
+ /**
355
+ * Continuity term of the ladder's initial-margin floor formula
356
+ * `IM_floor(N) = N x initialMarginRatio - initialMarginDeduction`; "0" for tier 1.
357
+ */
358
+ initialMarginDeduction: string;
359
+ /**
360
+ * Continuity term of the maintenance-margin formula
361
+ * `MM(N) = N x maintenanceMarginRatio - maintenanceMarginDeduction`; "0" for tier 1.
362
+ */
363
+ maintenanceMarginDeduction: string;
322
364
  }
323
365
  export interface PerpMarketConfig {
324
366
  tradingPairId: string;
325
367
  symbol: string;
326
368
  minLeverage: string;
369
+ /**
370
+ * Tier 1 (the lowest bracket) of `riskTiers` — its `maxLeverage`, mirrored
371
+ * here for backward compatibility. Brackets above tier 1 are described
372
+ * only by `riskTiers`.
373
+ */
327
374
  maxLeverage: string;
375
+ /**
376
+ * Tier 1 (the lowest bracket) of `riskTiers` — its `initialMarginRatio`,
377
+ * mirrored here for backward compatibility. Brackets above tier 1 are
378
+ * described only by `riskTiers`. This rate contributes to the ladder floor;
379
+ * selected leverage can produce a higher position initial-margin requirement.
380
+ */
328
381
  initialMarginRatio: string;
382
+ /**
383
+ * Tier 1 (the lowest bracket) of `riskTiers` — its `maintenanceMarginRatio`,
384
+ * mirrored here for backward compatibility. Brackets above tier 1 are
385
+ * described only by `riskTiers`.
386
+ */
329
387
  maintenanceMarginRatio: string;
330
388
  fundingIntervalSeconds: number;
331
389
  liquidationFeeBps?: string;
390
+ /**
391
+ * The market's full margin ladder, ascending by `lowerBoundNotional` and
392
+ * always non-empty (a market with no configured brackets reports a single
393
+ * tier). A position's bracket is the LAST tier whose `lowerBoundNotional`
394
+ * is at or below its notional, `abs(quantity) x markPrice`.
395
+ */
332
396
  riskTiers: RiskTier[];
333
397
  updatedAt: string;
334
398
  }
@@ -4,7 +4,7 @@
4
4
  * Types for PitPass TraderCode API: code lookup, rewards balance, and transfer.
5
5
  */
6
6
  import type { BaseAPI } from "../api";
7
- import type { GetRewardsBalanceResponse, TraderCodeAvailabilityResponse, TraderCodeInfoResponse, TraderCodeResponse, TransferRewardsParams, TransferRewardsResponse } from "./responses";
7
+ import type { GetMyReferralDownlineResponse, GetMyReferralPositionResponse, GetRewardsBalanceResponse, TraderCodeAvailabilityResponse, TraderCodeInfoResponse, TraderCodeResponse, TransferRewardsParams, TransferRewardsResponse } from "./responses";
8
8
  /**
9
9
  * PitPass TraderCode API interface.
10
10
  *
@@ -91,6 +91,30 @@ export interface PitpassAPI extends BaseAPI {
91
91
  * @returns Promise resolving to the post-transfer rewards and trading balances
92
92
  */
93
93
  transferRewards(params: TransferRewardsParams): Promise<TransferRewardsResponse>;
94
+ /**
95
+ * Read your own referral position: your direct (L1) referrer, total earned,
96
+ * and most recent reward rows.
97
+ *
98
+ * Self-scoped — the server derives your identity from the session, so you can
99
+ * only ever read your own chain. `referrer` is the empty string when you were
100
+ * not referred (use it to gate the "already referred" UX). Every other user is
101
+ * identified by their public wallet address (with a `display` handle-or-wallet
102
+ * variant), never an internal id.
103
+ *
104
+ * @returns Promise resolving to your referrer, total earned, and recent rewards
105
+ */
106
+ getMyReferralPosition(): Promise<GetMyReferralPositionResponse>;
107
+ /**
108
+ * Read your own downline: who you earn from and how much (earnings by source
109
+ * across L1/L2/L3), your L1 direct-referee roster (including referees who have
110
+ * not traded yet), and a per-level earnings summary.
111
+ *
112
+ * Self-scoped and read-only. Every source and referee is a public wallet
113
+ * address plus a `display` handle-or-wallet variant, never an internal id.
114
+ *
115
+ * @returns Promise resolving to earnings-by-source, the direct-referee roster, and a summary
116
+ */
117
+ getMyReferralDownline(): Promise<GetMyReferralDownlineResponse>;
94
118
  }
95
- export type { GetRewardsBalanceResponse, RewardsBalanceEntry, SetTraderCodeParams, TraderCodeAvailabilityReason, TraderCodeAvailabilityResponse, TraderCodeInfoResponse, TraderCodeResponse, TransferRewardsParams, TransferRewardsResponse, } from "./responses";
96
- export { GetRewardsBalanceResponseSchema, RewardsBalanceEntrySchema, SetTraderCodeParamsSchema, TraderCodeAvailabilityReasonSchema, TraderCodeAvailabilityResponseSchema, TraderCodeInfoResponseSchema, TraderCodeResponseSchema, TransferRewardsParamsSchema, TransferRewardsResponseSchema, } from "./responses";
119
+ export type { GetMyReferralDownlineResponse, GetMyReferralPositionResponse, GetRewardsBalanceResponse, ReferralDirectReferee, ReferralEarningsSource, ReferralEarningsSummary, ReferralRewardEntry, RewardsBalanceEntry, SetTraderCodeParams, TraderCodeAvailabilityReason, TraderCodeAvailabilityResponse, TraderCodeInfoResponse, TraderCodeResponse, TransferRewardsParams, TransferRewardsResponse, } from "./responses";
120
+ export { GetMyReferralDownlineResponseSchema, GetMyReferralPositionResponseSchema, GetRewardsBalanceResponseSchema, ReferralDirectRefereeSchema, ReferralEarningsSourceSchema, ReferralEarningsSummarySchema, ReferralRewardEntrySchema, RewardsBalanceEntrySchema, SetTraderCodeParamsSchema, TraderCodeAvailabilityReasonSchema, TraderCodeAvailabilityResponseSchema, TraderCodeInfoResponseSchema, TraderCodeResponseSchema, TransferRewardsParamsSchema, TransferRewardsResponseSchema, } from "./responses";
@@ -3,4 +3,4 @@
3
3
  *
4
4
  * Types for PitPass TraderCode API: code lookup, rewards balance, and transfer.
5
5
  */
6
- export { GetRewardsBalanceResponseSchema, RewardsBalanceEntrySchema, SetTraderCodeParamsSchema, TraderCodeAvailabilityReasonSchema, TraderCodeAvailabilityResponseSchema, TraderCodeInfoResponseSchema, TraderCodeResponseSchema, TransferRewardsParamsSchema, TransferRewardsResponseSchema, } from "./responses";
6
+ export { GetMyReferralDownlineResponseSchema, GetMyReferralPositionResponseSchema, GetRewardsBalanceResponseSchema, ReferralDirectRefereeSchema, ReferralEarningsSourceSchema, ReferralEarningsSummarySchema, ReferralRewardEntrySchema, RewardsBalanceEntrySchema, SetTraderCodeParamsSchema, TraderCodeAvailabilityReasonSchema, TraderCodeAvailabilityResponseSchema, TraderCodeInfoResponseSchema, TraderCodeResponseSchema, TransferRewardsParamsSchema, TransferRewardsResponseSchema, } from "./responses";
@@ -67,6 +67,75 @@ export declare const TransferRewardsResponseSchema: z.ZodObject<{
67
67
  rewardsBalance: z.ZodString;
68
68
  tradingBalance: z.ZodString;
69
69
  }, z.core.$strip>;
70
+ /** A single reward the caller has earned (one row per referred trade × level). */
71
+ export declare const ReferralRewardEntrySchema: z.ZodObject<{
72
+ source: z.ZodString;
73
+ sourceDisplay: z.ZodString;
74
+ level: z.ZodNumber;
75
+ amount: z.ZodString;
76
+ token: z.ZodString;
77
+ rateApplied: z.ZodString;
78
+ createdAt: z.ZodString;
79
+ }, z.core.$strip>;
80
+ /** The caller's own referral position: who referred them and what they've earned. */
81
+ export declare const GetMyReferralPositionResponseSchema: z.ZodObject<{
82
+ referrer: z.ZodString;
83
+ referrerDisplay: z.ZodString;
84
+ totalEarned: z.ZodString;
85
+ rewards: z.ZodArray<z.ZodObject<{
86
+ source: z.ZodString;
87
+ sourceDisplay: z.ZodString;
88
+ level: z.ZodNumber;
89
+ amount: z.ZodString;
90
+ token: z.ZodString;
91
+ rateApplied: z.ZodString;
92
+ createdAt: z.ZodString;
93
+ }, z.core.$strip>>;
94
+ }, z.core.$strip>;
95
+ /** One aggregated earnings row per (source trader, level, token) the caller earns from. */
96
+ export declare const ReferralEarningsSourceSchema: z.ZodObject<{
97
+ source: z.ZodString;
98
+ sourceDisplay: z.ZodString;
99
+ level: z.ZodNumber;
100
+ totalEarned: z.ZodString;
101
+ token: z.ZodString;
102
+ }, z.core.$strip>;
103
+ /** One direct (L1) referee of the caller, whether or not they have traded yet. */
104
+ export declare const ReferralDirectRefereeSchema: z.ZodObject<{
105
+ wallet: z.ZodString;
106
+ display: z.ZodString;
107
+ referredAt: z.ZodString;
108
+ totalEarned: z.ZodString;
109
+ }, z.core.$strip>;
110
+ /** Per-level breakdown of the caller's total referral earnings. */
111
+ export declare const ReferralEarningsSummarySchema: z.ZodObject<{
112
+ totalEarned: z.ZodString;
113
+ level1Earned: z.ZodString;
114
+ level2Earned: z.ZodString;
115
+ level3Earned: z.ZodString;
116
+ }, z.core.$strip>;
117
+ /** The caller's own downline: who they earn from, their L1 roster, and a summary. */
118
+ export declare const GetMyReferralDownlineResponseSchema: z.ZodObject<{
119
+ earningsBySource: z.ZodArray<z.ZodObject<{
120
+ source: z.ZodString;
121
+ sourceDisplay: z.ZodString;
122
+ level: z.ZodNumber;
123
+ totalEarned: z.ZodString;
124
+ token: z.ZodString;
125
+ }, z.core.$strip>>;
126
+ directReferees: z.ZodArray<z.ZodObject<{
127
+ wallet: z.ZodString;
128
+ display: z.ZodString;
129
+ referredAt: z.ZodString;
130
+ totalEarned: z.ZodString;
131
+ }, z.core.$strip>>;
132
+ summary: z.ZodObject<{
133
+ totalEarned: z.ZodString;
134
+ level1Earned: z.ZodString;
135
+ level2Earned: z.ZodString;
136
+ level3Earned: z.ZodString;
137
+ }, z.core.$strip>;
138
+ }, z.core.$strip>;
70
139
  export type RewardsBalanceEntry = z.infer<typeof RewardsBalanceEntrySchema>;
71
140
  export type GetRewardsBalanceResponse = z.infer<typeof GetRewardsBalanceResponseSchema>;
72
141
  export type TraderCodeResponse = z.infer<typeof TraderCodeResponseSchema>;
@@ -76,3 +145,9 @@ export type SetTraderCodeParams = z.infer<typeof SetTraderCodeParamsSchema>;
76
145
  export type TraderCodeInfoResponse = z.infer<typeof TraderCodeInfoResponseSchema>;
77
146
  export type TransferRewardsParams = z.infer<typeof TransferRewardsParamsSchema>;
78
147
  export type TransferRewardsResponse = z.infer<typeof TransferRewardsResponseSchema>;
148
+ export type ReferralRewardEntry = z.infer<typeof ReferralRewardEntrySchema>;
149
+ export type GetMyReferralPositionResponse = z.infer<typeof GetMyReferralPositionResponseSchema>;
150
+ export type ReferralEarningsSource = z.infer<typeof ReferralEarningsSourceSchema>;
151
+ export type ReferralDirectReferee = z.infer<typeof ReferralDirectRefereeSchema>;
152
+ export type ReferralEarningsSummary = z.infer<typeof ReferralEarningsSummarySchema>;
153
+ export type GetMyReferralDownlineResponse = z.infer<typeof GetMyReferralDownlineResponseSchema>;
@@ -101,3 +101,81 @@ export const TransferRewardsResponseSchema = z.object({
101
101
  /** Your trading balance for the token after the transfer, RAW atomic units. */
102
102
  tradingBalance: z.string(),
103
103
  });
104
+ /** A single reward the caller has earned (one row per referred trade × level). */
105
+ export const ReferralRewardEntrySchema = z.object({
106
+ /** Public wallet address of the trader (taker) whose trade generated this reward. */
107
+ source: z.string(),
108
+ /** Human-facing name for the source: their custom handle if claimed, else the wallet. */
109
+ sourceDisplay: z.string(),
110
+ /** Referral level (1 = direct/30%, 2 = 15%, 3 = 5%). */
111
+ level: z.number(),
112
+ /** Reward amount, in RAW atomic units of the token. */
113
+ amount: z.string(),
114
+ /** Reward token contract address (0x-prefixed). */
115
+ token: z.string(),
116
+ /** The referral rate applied, as a decimal fraction (e.g. `0.30` for L1). */
117
+ rateApplied: z.string(),
118
+ /** RFC 3339 timestamp when the reward row was recorded. */
119
+ createdAt: z.string(),
120
+ });
121
+ /** The caller's own referral position: who referred them and what they've earned. */
122
+ export const GetMyReferralPositionResponseSchema = z.object({
123
+ /**
124
+ * Public wallet address of the caller's direct (L1) referrer. Empty string
125
+ * when the caller was not referred. Only the direct referrer is exposed.
126
+ */
127
+ referrer: z.string(),
128
+ /** Human-facing name for the referrer: their custom handle if claimed, else the wallet (empty when not referred). */
129
+ referrerDisplay: z.string(),
130
+ /** Total reward amount earned across every level and token, in RAW atomic units. */
131
+ totalEarned: z.string(),
132
+ /** The caller's most recent reward rows, newest first (bounded server-side). */
133
+ rewards: z.array(ReferralRewardEntrySchema),
134
+ });
135
+ /** One aggregated earnings row per (source trader, level, token) the caller earns from. */
136
+ export const ReferralEarningsSourceSchema = z.object({
137
+ /** Public wallet address of the trader (taker) the caller earns from. */
138
+ source: z.string(),
139
+ /** Human-facing name for the source: their custom handle if claimed, else the wallet. */
140
+ sourceDisplay: z.string(),
141
+ /** Referral level the caller earns from this source at (1/2/3). */
142
+ level: z.number(),
143
+ /** Total earned from this source at this level and token, in RAW atomic units. */
144
+ totalEarned: z.string(),
145
+ /** Reward token contract address (0x-prefixed). */
146
+ token: z.string(),
147
+ });
148
+ /** One direct (L1) referee of the caller, whether or not they have traded yet. */
149
+ export const ReferralDirectRefereeSchema = z.object({
150
+ /** Public wallet address of the direct referee. */
151
+ wallet: z.string(),
152
+ /** Human-facing name for the referee: their custom handle if claimed, else the wallet. */
153
+ display: z.string(),
154
+ /** RFC 3339 timestamp when the referral relationship was recorded. */
155
+ referredAt: z.string(),
156
+ /** Total the caller has earned from this referee's own (L1) trades, RAW units. `0` if they haven't traded. */
157
+ totalEarned: z.string(),
158
+ });
159
+ /** Per-level breakdown of the caller's total referral earnings. */
160
+ export const ReferralEarningsSummarySchema = z.object({
161
+ /** Total earned across all levels and tokens, in RAW atomic units. */
162
+ totalEarned: z.string(),
163
+ /** Total earned from direct (L1) referees, in RAW atomic units. */
164
+ level1Earned: z.string(),
165
+ /** Total earned from L2 downline, in RAW atomic units. */
166
+ level2Earned: z.string(),
167
+ /** Total earned from L3 downline, in RAW atomic units. */
168
+ level3Earned: z.string(),
169
+ });
170
+ /** The caller's own downline: who they earn from, their L1 roster, and a summary. */
171
+ export const GetMyReferralDownlineResponseSchema = z.object({
172
+ /** One row per (source trader, level, token) the caller earns from, across L1/L2/L3. */
173
+ earningsBySource: z.array(ReferralEarningsSourceSchema),
174
+ /** The caller's direct (L1) referees, newest first, including those who haven't traded. */
175
+ directReferees: z.array(ReferralDirectRefereeSchema),
176
+ /**
177
+ * Total earned broken down by level (L1/L2/L3). The server always populates
178
+ * this — even a brand-new user gets a zeroed summary — so it is required.
179
+ */
180
+ summary: ReferralEarningsSummarySchema,
181
+ });
@@ -153,7 +153,10 @@ export interface TradingAPI extends BaseAPI {
153
153
  * partially filled order the replacement rests `total - filled` and locks
154
154
  * collateral for that remainder only (FIX convention: `LeavesQty =
155
155
  * OrderQty - CumQty`); must exceed the filled amount. Omitted, the
156
- * replacement keeps the unfilled remainder.
156
+ * replacement keeps the unfilled remainder. Margin reduce-only orders are
157
+ * the exception: their quantity is a close size measured against the live
158
+ * position, placed as given, so neither the subtraction nor the
159
+ * must-exceed-filled rule applies.
157
160
  * @param newOrder.useMasterBalance - Whether to use master balance (optional, defaults to false)
158
161
  * @param newOrder.postOnly - Re-states post-only intent for the replacement (nothing is inherited from the original order)
159
162
  * @returns Promise resolving to a `ReplaceOrderResponse`
@@ -99,6 +99,7 @@ export declare const SimulateOrderRiskSchema: z.ZodObject<{
99
99
  quantity: z.ZodString;
100
100
  leverage: z.ZodOptional<z.ZodString>;
101
101
  reduceOnly: z.ZodOptional<z.ZodBoolean>;
102
+ slippageToleranceBps: z.ZodOptional<z.ZodNumber>;
102
103
  }, z.core.$strict>;
103
104
  }, z.core.$strip>;
104
105
  export declare const SimulateParentMarginOrderRiskSchema: z.ZodObject<{
@@ -121,6 +122,7 @@ export declare const SimulateParentMarginOrderRiskSchema: z.ZodObject<{
121
122
  quantity: z.ZodString;
122
123
  leverage: z.ZodOptional<z.ZodString>;
123
124
  reduceOnly: z.ZodOptional<z.ZodBoolean>;
125
+ slippageToleranceBps: z.ZodOptional<z.ZodNumber>;
124
126
  }, z.core.$strict>;
125
127
  }, z.core.$strip>;
126
128
  export declare const SimulateRiskBucketOrderRiskSchema: z.ZodObject<{
@@ -148,6 +150,7 @@ export declare const SimulateRiskBucketOrderRiskSchema: z.ZodObject<{
148
150
  quantity: z.ZodString;
149
151
  leverage: z.ZodOptional<z.ZodString>;
150
152
  reduceOnly: z.ZodOptional<z.ZodBoolean>;
153
+ slippageToleranceBps: z.ZodOptional<z.ZodNumber>;
151
154
  tradingPairId: z.ZodUUID;
152
155
  strategyKey: z.ZodOptional<z.ZodString>;
153
156
  marginMode: z.ZodOptional<z.ZodLiteral<"ISOLATED">>;
@@ -172,6 +175,7 @@ export declare const SimulateRiskBucketOrderRiskSchema: z.ZodObject<{
172
175
  quantity: z.ZodString;
173
176
  leverage: z.ZodOptional<z.ZodString>;
174
177
  reduceOnly: z.ZodOptional<z.ZodBoolean>;
178
+ slippageToleranceBps: z.ZodOptional<z.ZodNumber>;
175
179
  marginMode: z.ZodLiteral<"CROSS">;
176
180
  selectedTradingPairIds: z.ZodOptional<z.ZodNever>;
177
181
  strategyKey: z.ZodOptional<z.ZodNever>;
@@ -2,7 +2,7 @@
2
2
  * Margin Account API Validation Schemas
3
3
  */
4
4
  import { z } from "zod";
5
- import { OrderSideSchema, OrderTypeSchema, PositionSideSchema, PositiveDecimalStringSchema, UUIDSchema } from "./trading";
5
+ import { MarketSlippageToleranceBpsSchema, OrderSideSchema, OrderTypeSchema, PositionSideSchema, PositiveDecimalStringSchema, UUIDSchema } from "./trading";
6
6
  const PaginationSchema = z.object({
7
7
  page: z.number().int().min(1, "Page must be at least 1").optional(),
8
8
  pageSize: z.number().int().min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
@@ -132,8 +132,23 @@ const BaseSimulateOrderRiskRequestSchema = z.object({
132
132
  quantity: PositiveDecimalStringSchema,
133
133
  leverage: PositiveDecimalStringSchema.optional(),
134
134
  reduceOnly: z.boolean().optional(),
135
+ // The server caps a preview's tolerance at 1,000 bps (the same cap
136
+ // placement enforces on a MARKET order), so 1,001..10,000 fail here rather
137
+ // than round-trip to a 400 — one shared schema, so the cap lives once.
138
+ slippageToleranceBps: MarketSlippageToleranceBpsSchema.optional(),
135
139
  });
136
140
  const validateOneWaySimulationFields = (data, ctx) => {
141
+ // Mirrors the server (`utils::slippage::validate_slippage_tolerance`, the
142
+ // rule placement applies): a tolerance is MARKET-only, so a LIMIT preview
143
+ // carrying one fails client-side with the same complaint the server would
144
+ // raise instead of round-tripping to a 400.
145
+ if (data.orderType !== "MARKET" && data.slippageToleranceBps !== undefined) {
146
+ ctx.addIssue({
147
+ code: z.ZodIssueCode.custom,
148
+ message: "slippageToleranceBps is only supported for MARKET orders",
149
+ path: ["slippageToleranceBps"],
150
+ });
151
+ }
137
152
  if (data.positionSide !== undefined) {
138
153
  const expected = data.side === "BUY" ? "LONG" : "SHORT";
139
154
  if (data.positionSide !== expected) {
@@ -76,6 +76,13 @@ export declare const ISO8601DateSchema: z.ZodISODateTime;
76
76
  */
77
77
  export declare const SlippageToleranceSchema: z.ZodOptional<z.ZodNumber>;
78
78
  export declare const SlippageToleranceBpsSchema: z.ZodNumber;
79
+ /**
80
+ * A standalone MARKET order's tolerance, and a MARKET risk preview's: the
81
+ * server caps it at 1,000 bps — the mandatory protective band, which a client
82
+ * value can only tighten — so anything wider fails here instead of
83
+ * round-tripping to a 400. The 10,000 bps schema above is for TP/SL legs.
84
+ */
85
+ export declare const MarketSlippageToleranceBpsSchema: z.ZodNumber;
79
86
  /** TWAP slices cap at 500 bps (5%) — tighter than standalone market orders. */
80
87
  export declare const TwapSlippageToleranceBpsSchema: z.ZodNumber;
81
88
  export declare const ParentTpSlLegSchema: z.ZodObject<{
@@ -84,6 +84,17 @@ export const SlippageToleranceBpsSchema = z
84
84
  .int()
85
85
  .min(0, "Slippage tolerance must be at least 0 bps")
86
86
  .max(10000, "Slippage tolerance cannot exceed 10000 bps");
87
+ /**
88
+ * A standalone MARKET order's tolerance, and a MARKET risk preview's: the
89
+ * server caps it at 1,000 bps — the mandatory protective band, which a client
90
+ * value can only tighten — so anything wider fails here instead of
91
+ * round-tripping to a 400. The 10,000 bps schema above is for TP/SL legs.
92
+ */
93
+ export const MarketSlippageToleranceBpsSchema = z
94
+ .number()
95
+ .int()
96
+ .min(0, "Slippage tolerance must be at least 0 bps")
97
+ .max(1000, "Slippage tolerance cannot exceed 1000 bps");
87
98
  /** TWAP slices cap at 500 bps (5%) — tighter than standalone market orders. */
88
99
  export const TwapSlippageToleranceBpsSchema = z
89
100
  .number()