@0xmonaco/types 0.6.3 → 0.7.0
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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/margin-accounts/index.d.ts +106 -0
- package/dist/margin-accounts/index.js +0 -0
- package/dist/market/index.d.ts +105 -16
- package/dist/positions/index.d.ts +128 -0
- package/dist/positions/index.js +0 -0
- package/dist/profile/index.d.ts +19 -17
- package/dist/sdk/index.d.ts +11 -4
- package/dist/trading/index.d.ts +25 -5
- package/dist/trading/orders.d.ts +27 -1
- package/dist/trading/responses.d.ts +84 -15
- package/dist/validation/index.d.ts +2 -0
- package/dist/validation/index.js +2 -0
- package/dist/validation/margin-accounts.d.ts +55 -0
- package/dist/validation/margin-accounts.js +59 -0
- package/dist/validation/market.d.ts +2 -2
- package/dist/validation/market.js +2 -2
- package/dist/validation/positions.d.ts +89 -0
- package/dist/validation/positions.js +93 -0
- package/dist/validation/profile.d.ts +2 -2
- package/dist/validation/profile.js +2 -2
- package/dist/validation/trading.d.ts +123 -2
- package/dist/validation/trading.js +126 -5
- package/dist/websocket/events/conditional-order-events.d.ts +33 -0
- package/dist/websocket/events/conditional-order-events.js +0 -0
- package/dist/websocket/events/index.d.ts +1 -0
- package/dist/websocket/events/index.js +1 -0
- package/dist/websocket/events/orders-events.d.ts +2 -2
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Response types for trading operations.
|
|
5
5
|
*/
|
|
6
|
-
import type { Order, OrderSide, OrderStatus, OrderType, TimeInForce, TradingMode } from "./orders";
|
|
6
|
+
import type { ConditionalOrderConditionType, ConditionalOrderState, ConditionalOrderTriggerSource, Order, OrderSide, OrderStatus, OrderType, PositionSide, TimeInForce, TradingMode } from "./orders";
|
|
7
7
|
/**
|
|
8
8
|
* Match result information for order execution.
|
|
9
9
|
* Contains detailed information about trades, fills, and execution quality.
|
|
@@ -97,7 +97,11 @@ export interface GetPaginatedOrdersParams {
|
|
|
97
97
|
/** Filter by order status */
|
|
98
98
|
status?: OrderStatus;
|
|
99
99
|
/** Filter by trading pair UUID */
|
|
100
|
-
|
|
100
|
+
trading_pair_id?: string;
|
|
101
|
+
/** Filter by trading mode */
|
|
102
|
+
trading_mode?: TradingMode;
|
|
103
|
+
/** Filter by margin account UUID */
|
|
104
|
+
margin_account_id?: string;
|
|
101
105
|
/** Page number for pagination (default: 1) */
|
|
102
106
|
page?: number;
|
|
103
107
|
/** Number of orders per page (default: 10, max: 100) */
|
|
@@ -147,8 +151,6 @@ export interface BatchCancelError {
|
|
|
147
151
|
export interface BatchCancelResult {
|
|
148
152
|
/** Order identifier */
|
|
149
153
|
order_id: string;
|
|
150
|
-
/** Whether the cancellation was successful */
|
|
151
|
-
success: boolean;
|
|
152
154
|
/** Timestamp when the order was canceled (ISO 8601 format) */
|
|
153
155
|
cancelled_at?: string;
|
|
154
156
|
/** Error details if the cancellation failed */
|
|
@@ -158,8 +160,6 @@ export interface BatchCancelResult {
|
|
|
158
160
|
* Response from batch cancelling orders
|
|
159
161
|
*/
|
|
160
162
|
export interface BatchCancelOrdersResponse {
|
|
161
|
-
/** Overall operation success */
|
|
162
|
-
success: boolean;
|
|
163
163
|
/** Total number of orders requested to cancel */
|
|
164
164
|
total_requested: number;
|
|
165
165
|
/** Total number of orders successfully canceled */
|
|
@@ -184,8 +184,6 @@ export interface BatchError {
|
|
|
184
184
|
export interface BatchCreateResult {
|
|
185
185
|
/** Order identifier (empty string if creation failed before ID assignment) */
|
|
186
186
|
order_id: string;
|
|
187
|
-
/** Whether the order was successfully created */
|
|
188
|
-
success: boolean;
|
|
189
187
|
/** Match result information if the order was processed */
|
|
190
188
|
match_result?: MatchResult;
|
|
191
189
|
/** Error details if the creation failed */
|
|
@@ -195,8 +193,6 @@ export interface BatchCreateResult {
|
|
|
195
193
|
* Response from batch creating orders
|
|
196
194
|
*/
|
|
197
195
|
export interface BatchCreateOrdersResponse {
|
|
198
|
-
/** Overall operation success */
|
|
199
|
-
success: boolean;
|
|
200
196
|
/** Total number of orders requested to create */
|
|
201
197
|
total_requested: number;
|
|
202
198
|
/** Total number of orders successfully created */
|
|
@@ -212,8 +208,6 @@ export interface BatchCreateOrdersResponse {
|
|
|
212
208
|
export interface BatchReplaceResult {
|
|
213
209
|
/** Original order identifier */
|
|
214
210
|
original_order_id: string;
|
|
215
|
-
/** Whether the order was successfully replaced */
|
|
216
|
-
success: boolean;
|
|
217
211
|
/** New order identifier (if successful) */
|
|
218
212
|
new_order_id?: string;
|
|
219
213
|
/** Fields that were updated (if successful) */
|
|
@@ -227,8 +221,6 @@ export interface BatchReplaceResult {
|
|
|
227
221
|
* Response from batch replacing orders
|
|
228
222
|
*/
|
|
229
223
|
export interface BatchReplaceOrdersResponse {
|
|
230
|
-
/** Overall operation success */
|
|
231
|
-
success: boolean;
|
|
232
224
|
/** Total number of orders requested to replace */
|
|
233
225
|
total_requested: number;
|
|
234
226
|
/** Total number of orders successfully replaced */
|
|
@@ -253,7 +245,7 @@ export interface BatchCreateOrderParams {
|
|
|
253
245
|
/** Order quantity */
|
|
254
246
|
quantity: string;
|
|
255
247
|
/** Trading mode (defaults to "SPOT") */
|
|
256
|
-
tradingMode?:
|
|
248
|
+
tradingMode?: TradingMode;
|
|
257
249
|
/** Maximum slippage for market orders as decimal (e.g., 0.01 for 1%) */
|
|
258
250
|
slippageTolerance?: number;
|
|
259
251
|
/** For sub-accounts: use master's balance */
|
|
@@ -262,6 +254,14 @@ export interface BatchCreateOrderParams {
|
|
|
262
254
|
expirationDate?: string;
|
|
263
255
|
/** Time in force: "GTC", "IOC", or "FOK" */
|
|
264
256
|
timeInForce?: Extract<TimeInForce, "GTC" | "IOC" | "FOK">;
|
|
257
|
+
/** Margin account UUID for margin/perp orders */
|
|
258
|
+
marginAccountId?: string;
|
|
259
|
+
/** Position side for margin/perp orders */
|
|
260
|
+
positionSide?: PositionSide;
|
|
261
|
+
/** Leverage for margin/perp orders */
|
|
262
|
+
leverage?: string;
|
|
263
|
+
/** Whether the order can only reduce existing exposure */
|
|
264
|
+
reduceOnly?: boolean;
|
|
265
265
|
}
|
|
266
266
|
/**
|
|
267
267
|
* Parameters for a single order in a batch replace request
|
|
@@ -276,3 +276,72 @@ export interface BatchReplaceOrderParams {
|
|
|
276
276
|
/** For sub-accounts: use master's balance (optional) */
|
|
277
277
|
useMasterBalance?: boolean;
|
|
278
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Parameters for creating a standalone conditional TP/SL order.
|
|
281
|
+
*/
|
|
282
|
+
export interface CreateConditionalOrderParams {
|
|
283
|
+
tradingPairId: string;
|
|
284
|
+
marginAccountId: string;
|
|
285
|
+
conditionType: ConditionalOrderConditionType;
|
|
286
|
+
triggerPrice: string;
|
|
287
|
+
triggerSource?: ConditionalOrderTriggerSource;
|
|
288
|
+
side: OrderSide;
|
|
289
|
+
positionSide: Exclude<PositionSide, "NONE">;
|
|
290
|
+
orderType: OrderType;
|
|
291
|
+
limitPrice?: string;
|
|
292
|
+
quantity?: string;
|
|
293
|
+
reduceOnly?: boolean;
|
|
294
|
+
timeInForce?: Extract<TimeInForce, "GTC" | "IOC">;
|
|
295
|
+
slippageToleranceBps?: number;
|
|
296
|
+
expiresAt?: string;
|
|
297
|
+
}
|
|
298
|
+
export interface CreateConditionalOrderResponse {
|
|
299
|
+
conditional_order_id: string;
|
|
300
|
+
status: "SUCCESS" | "FAILED";
|
|
301
|
+
message: string;
|
|
302
|
+
state: ConditionalOrderState;
|
|
303
|
+
}
|
|
304
|
+
export interface CancelConditionalOrderResponse {
|
|
305
|
+
conditional_order_id: string;
|
|
306
|
+
status: "SUCCESS" | "FAILED";
|
|
307
|
+
message: string;
|
|
308
|
+
}
|
|
309
|
+
export interface ListConditionalOrdersParams {
|
|
310
|
+
margin_account_id?: string;
|
|
311
|
+
trading_pair_id?: string;
|
|
312
|
+
state?: ConditionalOrderState;
|
|
313
|
+
page?: number;
|
|
314
|
+
page_size?: number;
|
|
315
|
+
}
|
|
316
|
+
export interface ConditionalOrder {
|
|
317
|
+
conditional_order_id: string;
|
|
318
|
+
trading_pair_id: string;
|
|
319
|
+
margin_account_id: string;
|
|
320
|
+
position_id?: string;
|
|
321
|
+
linked_group_id?: string;
|
|
322
|
+
condition_type: ConditionalOrderConditionType;
|
|
323
|
+
trigger_source: ConditionalOrderTriggerSource;
|
|
324
|
+
trigger_price: string;
|
|
325
|
+
side: OrderSide;
|
|
326
|
+
position_side: PositionSide;
|
|
327
|
+
order_type: OrderType;
|
|
328
|
+
limit_price?: string;
|
|
329
|
+
quantity?: string;
|
|
330
|
+
slippage_tolerance_bps?: number;
|
|
331
|
+
reduce_only: boolean;
|
|
332
|
+
time_in_force?: TimeInForce;
|
|
333
|
+
state: ConditionalOrderState;
|
|
334
|
+
triggered_order_id?: string;
|
|
335
|
+
triggered_at?: string;
|
|
336
|
+
cancelled_at?: string;
|
|
337
|
+
expires_at?: string;
|
|
338
|
+
failure_reason?: string;
|
|
339
|
+
created_at: string;
|
|
340
|
+
updated_at: string;
|
|
341
|
+
}
|
|
342
|
+
export interface ListConditionalOrdersResponse {
|
|
343
|
+
orders: ConditionalOrder[];
|
|
344
|
+
total: number;
|
|
345
|
+
page: number;
|
|
346
|
+
page_size: number;
|
|
347
|
+
}
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* - Market schemas (trading pairs, candlesticks)
|
|
15
15
|
*/
|
|
16
16
|
export * from "./common.js";
|
|
17
|
+
export * from "./margin-accounts.js";
|
|
17
18
|
export * from "./market.js";
|
|
19
|
+
export * from "./positions.js";
|
|
18
20
|
export * from "./profile.js";
|
|
19
21
|
export * from "./trading.js";
|
|
20
22
|
export * from "./vault.js";
|
package/dist/validation/index.js
CHANGED
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
*/
|
|
16
16
|
// Export validation utilities
|
|
17
17
|
export * from "./common.js";
|
|
18
|
+
export * from "./margin-accounts.js";
|
|
18
19
|
export * from "./market.js";
|
|
20
|
+
export * from "./positions.js";
|
|
19
21
|
// Export module-specific schemas
|
|
20
22
|
export * from "./profile.js";
|
|
21
23
|
export * from "./trading.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Margin Account API Validation Schemas
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export declare const ListMarginAccountsSchema: z.ZodObject<{
|
|
6
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
page_size: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
state: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export declare const CreateMarginAccountSchema: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
label: z.ZodOptional<z.ZodString>;
|
|
12
|
+
collateralAsset: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
export declare const GetMarginAccountSummarySchema: z.ZodObject<{
|
|
15
|
+
marginAccountId: z.ZodUUID;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare const GetAvailableCollateralSchema: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
asset: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
export declare const TransferCollateralSchema: z.ZodObject<{
|
|
21
|
+
marginAccountId: z.ZodUUID;
|
|
22
|
+
request: z.ZodObject<{
|
|
23
|
+
asset: z.ZodString;
|
|
24
|
+
amount: z.ZodString;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export declare const GetMarginAccountMovementsSchema: z.ZodObject<{
|
|
28
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
page_size: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
marginAccountId: z.ZodUUID;
|
|
31
|
+
movement_type: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export declare const SimulateOrderRiskSchema: z.ZodObject<{
|
|
34
|
+
marginAccountId: z.ZodUUID;
|
|
35
|
+
request: z.ZodObject<{
|
|
36
|
+
tradingPairId: z.ZodUUID;
|
|
37
|
+
side: z.ZodEnum<{
|
|
38
|
+
BUY: "BUY";
|
|
39
|
+
SELL: "SELL";
|
|
40
|
+
}>;
|
|
41
|
+
positionSide: z.ZodEnum<{
|
|
42
|
+
LONG: "LONG";
|
|
43
|
+
SHORT: "SHORT";
|
|
44
|
+
NONE: "NONE";
|
|
45
|
+
}>;
|
|
46
|
+
orderType: z.ZodEnum<{
|
|
47
|
+
LIMIT: "LIMIT";
|
|
48
|
+
MARKET: "MARKET";
|
|
49
|
+
}>;
|
|
50
|
+
price: z.ZodOptional<z.ZodString>;
|
|
51
|
+
quantity: z.ZodString;
|
|
52
|
+
leverage: z.ZodString;
|
|
53
|
+
reduceOnly: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Margin Account API Validation Schemas
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { OrderSideSchema, OrderTypeSchema, PositionSideSchema, PositiveDecimalStringSchema, UUIDSchema } from "./trading";
|
|
6
|
+
const PaginationSchema = z.object({
|
|
7
|
+
page: z.number().int().min(1, "Page must be at least 1").optional(),
|
|
8
|
+
page_size: z.number().int().min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
|
|
9
|
+
});
|
|
10
|
+
export const ListMarginAccountsSchema = PaginationSchema.extend({
|
|
11
|
+
state: z.string().trim().min(1, "State cannot be empty").optional(),
|
|
12
|
+
});
|
|
13
|
+
export const CreateMarginAccountSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
label: z.string().trim().min(1, "Label cannot be empty").optional(),
|
|
16
|
+
collateralAsset: z.string().trim().min(1, "Collateral asset cannot be empty").optional(),
|
|
17
|
+
})
|
|
18
|
+
.optional();
|
|
19
|
+
export const GetMarginAccountSummarySchema = z.object({
|
|
20
|
+
marginAccountId: UUIDSchema,
|
|
21
|
+
});
|
|
22
|
+
export const GetAvailableCollateralSchema = z
|
|
23
|
+
.object({
|
|
24
|
+
asset: z.string().trim().min(1, "Asset cannot be empty").optional(),
|
|
25
|
+
})
|
|
26
|
+
.optional();
|
|
27
|
+
export const TransferCollateralSchema = z.object({
|
|
28
|
+
marginAccountId: UUIDSchema,
|
|
29
|
+
request: z.object({
|
|
30
|
+
asset: z.string().trim().min(1, "Asset cannot be empty"),
|
|
31
|
+
amount: PositiveDecimalStringSchema,
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
export const GetMarginAccountMovementsSchema = PaginationSchema.extend({
|
|
35
|
+
marginAccountId: UUIDSchema,
|
|
36
|
+
movement_type: z.string().trim().min(1, "Movement type cannot be empty").optional(),
|
|
37
|
+
});
|
|
38
|
+
export const SimulateOrderRiskSchema = z
|
|
39
|
+
.object({
|
|
40
|
+
marginAccountId: UUIDSchema,
|
|
41
|
+
request: z.object({
|
|
42
|
+
tradingPairId: UUIDSchema,
|
|
43
|
+
side: OrderSideSchema,
|
|
44
|
+
positionSide: PositionSideSchema,
|
|
45
|
+
orderType: OrderTypeSchema,
|
|
46
|
+
price: PositiveDecimalStringSchema.optional(),
|
|
47
|
+
quantity: PositiveDecimalStringSchema,
|
|
48
|
+
leverage: PositiveDecimalStringSchema,
|
|
49
|
+
reduceOnly: z.boolean().optional(),
|
|
50
|
+
}),
|
|
51
|
+
})
|
|
52
|
+
.refine((data) => data.request.orderType !== "LIMIT" || data.request.price !== undefined, {
|
|
53
|
+
message: "price is required for LIMIT risk simulations",
|
|
54
|
+
path: ["request", "price"],
|
|
55
|
+
})
|
|
56
|
+
.refine((data) => data.request.orderType !== "MARKET" || data.request.price === undefined, {
|
|
57
|
+
message: "price must not be provided for MARKET risk simulations",
|
|
58
|
+
path: ["request", "price"],
|
|
59
|
+
});
|
|
@@ -203,8 +203,8 @@ export declare const GetTradingPairSchema: z.ZodObject<{
|
|
|
203
203
|
*/
|
|
204
204
|
export declare const SearchTradingPairsSchema: z.ZodObject<{
|
|
205
205
|
query: z.ZodOptional<z.ZodString>;
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
page_size: z.ZodOptional<z.ZodNumber>;
|
|
207
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
208
208
|
}, z.core.$strip>;
|
|
209
209
|
/**
|
|
210
210
|
* Get Market Metadata validation schema
|
|
@@ -214,8 +214,8 @@ export const GetTradingPairSchema = z.object({
|
|
|
214
214
|
*/
|
|
215
215
|
export const SearchTradingPairsSchema = z.object({
|
|
216
216
|
query: z.string().min(1, "Search query cannot be empty").optional(),
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
page_size: z.number().int().min(1).max(100).optional(),
|
|
218
|
+
page: z.number().int().min(1).optional(),
|
|
219
219
|
});
|
|
220
220
|
/**
|
|
221
221
|
* Get Market Metadata validation schema
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Positions API Validation Schemas
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export declare const ListPositionsSchema: z.ZodObject<{
|
|
6
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
page_size: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
margin_account_id: z.ZodOptional<z.ZodUUID>;
|
|
9
|
+
trading_pair_id: z.ZodOptional<z.ZodUUID>;
|
|
10
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
OPEN: "OPEN";
|
|
12
|
+
CLOSED: "CLOSED";
|
|
13
|
+
LIQUIDATING: "LIQUIDATING";
|
|
14
|
+
}>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export declare const GetPositionSchema: z.ZodObject<{
|
|
17
|
+
positionId: z.ZodUUID;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export declare const ClosePositionSchema: z.ZodObject<{
|
|
20
|
+
positionId: z.ZodUUID;
|
|
21
|
+
request: z.ZodObject<{
|
|
22
|
+
closeType: z.ZodEnum<{
|
|
23
|
+
LIMIT: "LIMIT";
|
|
24
|
+
MARKET: "MARKET";
|
|
25
|
+
IOC: "IOC";
|
|
26
|
+
}>;
|
|
27
|
+
limitPrice: z.ZodOptional<z.ZodString>;
|
|
28
|
+
slippageToleranceBps: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
quantity: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export declare const GetPositionRiskSchema: z.ZodObject<{
|
|
33
|
+
positionId: z.ZodUUID;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
export declare const AddPositionMarginSchema: z.ZodObject<{
|
|
36
|
+
positionId: z.ZodUUID;
|
|
37
|
+
request: z.ZodObject<{
|
|
38
|
+
amount: z.ZodString;
|
|
39
|
+
asset: z.ZodString;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
export declare const ReducePositionMarginSchema: z.ZodObject<{
|
|
43
|
+
positionId: z.ZodUUID;
|
|
44
|
+
request: z.ZodObject<{
|
|
45
|
+
amount: z.ZodString;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export declare const AttachPositionTpSlSchema: z.ZodObject<{
|
|
49
|
+
positionId: z.ZodUUID;
|
|
50
|
+
request: z.ZodObject<{
|
|
51
|
+
takeProfit: z.ZodOptional<z.ZodObject<{
|
|
52
|
+
triggerPrice: z.ZodString;
|
|
53
|
+
orderType: z.ZodEnum<{
|
|
54
|
+
LIMIT: "LIMIT";
|
|
55
|
+
MARKET: "MARKET";
|
|
56
|
+
}>;
|
|
57
|
+
limitPrice: z.ZodOptional<z.ZodString>;
|
|
58
|
+
quantity: z.ZodOptional<z.ZodString>;
|
|
59
|
+
timeInForce: z.ZodOptional<z.ZodEnum<{
|
|
60
|
+
GTC: "GTC";
|
|
61
|
+
IOC: "IOC";
|
|
62
|
+
}>>;
|
|
63
|
+
slippageToleranceBps: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
expiresAt: z.ZodOptional<z.ZodISODateTime>;
|
|
65
|
+
}, z.core.$strip>>;
|
|
66
|
+
stopLoss: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
triggerPrice: z.ZodString;
|
|
68
|
+
orderType: z.ZodEnum<{
|
|
69
|
+
LIMIT: "LIMIT";
|
|
70
|
+
MARKET: "MARKET";
|
|
71
|
+
}>;
|
|
72
|
+
limitPrice: z.ZodOptional<z.ZodString>;
|
|
73
|
+
quantity: z.ZodOptional<z.ZodString>;
|
|
74
|
+
timeInForce: z.ZodOptional<z.ZodEnum<{
|
|
75
|
+
GTC: "GTC";
|
|
76
|
+
IOC: "IOC";
|
|
77
|
+
}>>;
|
|
78
|
+
slippageToleranceBps: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
expiresAt: z.ZodOptional<z.ZodISODateTime>;
|
|
80
|
+
}, z.core.$strip>>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
export declare const ListPositionHistorySchema: z.ZodObject<{
|
|
84
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
page_size: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
position_id: z.ZodOptional<z.ZodUUID>;
|
|
87
|
+
margin_account_id: z.ZodOptional<z.ZodUUID>;
|
|
88
|
+
trading_pair_id: z.ZodOptional<z.ZodUUID>;
|
|
89
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Positions API Validation Schemas
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { ConditionalTimeInForceSchema, ISO8601DateSchema, OrderTypeSchema, PositiveDecimalStringSchema, SlippageToleranceBpsSchema, UUIDSchema, } from "./trading";
|
|
6
|
+
const PaginationSchema = z.object({
|
|
7
|
+
page: z.number().int().min(1, "Page must be at least 1").optional(),
|
|
8
|
+
page_size: z.number().int().min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
|
|
9
|
+
});
|
|
10
|
+
const PositionStatusSchema = z.enum(["OPEN", "CLOSED", "LIQUIDATING"], {
|
|
11
|
+
message: 'Position status must be "OPEN", "CLOSED", or "LIQUIDATING"',
|
|
12
|
+
});
|
|
13
|
+
const ClosePositionTypeSchema = z.enum(["MARKET", "LIMIT", "IOC"], {
|
|
14
|
+
message: 'Close type must be "MARKET", "LIMIT", or "IOC"',
|
|
15
|
+
});
|
|
16
|
+
const PositionIdSchema = z.object({
|
|
17
|
+
positionId: UUIDSchema,
|
|
18
|
+
});
|
|
19
|
+
export const ListPositionsSchema = PaginationSchema.extend({
|
|
20
|
+
margin_account_id: UUIDSchema.optional(),
|
|
21
|
+
trading_pair_id: UUIDSchema.optional(),
|
|
22
|
+
status: PositionStatusSchema.optional(),
|
|
23
|
+
});
|
|
24
|
+
export const GetPositionSchema = PositionIdSchema;
|
|
25
|
+
export const ClosePositionSchema = PositionIdSchema.extend({
|
|
26
|
+
request: z.object({
|
|
27
|
+
closeType: ClosePositionTypeSchema,
|
|
28
|
+
limitPrice: PositiveDecimalStringSchema.optional(),
|
|
29
|
+
slippageToleranceBps: SlippageToleranceBpsSchema.optional(),
|
|
30
|
+
quantity: PositiveDecimalStringSchema.optional(),
|
|
31
|
+
}),
|
|
32
|
+
})
|
|
33
|
+
.refine((data) => data.request.closeType !== "LIMIT" || data.request.limitPrice !== undefined, {
|
|
34
|
+
message: "limitPrice is required for LIMIT close requests",
|
|
35
|
+
path: ["request", "limitPrice"],
|
|
36
|
+
})
|
|
37
|
+
.refine((data) => data.request.closeType === "LIMIT" || data.request.limitPrice === undefined, {
|
|
38
|
+
message: "limitPrice is only allowed for LIMIT close requests",
|
|
39
|
+
path: ["request", "limitPrice"],
|
|
40
|
+
});
|
|
41
|
+
export const GetPositionRiskSchema = PositionIdSchema;
|
|
42
|
+
export const AddPositionMarginSchema = PositionIdSchema.extend({
|
|
43
|
+
request: z.object({
|
|
44
|
+
amount: PositiveDecimalStringSchema,
|
|
45
|
+
asset: z.string().trim().min(1, "Asset cannot be empty"),
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
export const ReducePositionMarginSchema = PositionIdSchema.extend({
|
|
49
|
+
request: z.object({
|
|
50
|
+
amount: PositiveDecimalStringSchema,
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
const TpSlLegSchema = z
|
|
54
|
+
.object({
|
|
55
|
+
triggerPrice: PositiveDecimalStringSchema,
|
|
56
|
+
orderType: OrderTypeSchema,
|
|
57
|
+
limitPrice: PositiveDecimalStringSchema.optional(),
|
|
58
|
+
quantity: PositiveDecimalStringSchema.optional(),
|
|
59
|
+
timeInForce: ConditionalTimeInForceSchema.optional(),
|
|
60
|
+
slippageToleranceBps: SlippageToleranceBpsSchema.optional(),
|
|
61
|
+
expiresAt: ISO8601DateSchema.optional(),
|
|
62
|
+
})
|
|
63
|
+
.refine((data) => data.orderType !== "LIMIT" || data.limitPrice !== undefined, {
|
|
64
|
+
message: "limitPrice is required for LIMIT TP/SL legs",
|
|
65
|
+
path: ["limitPrice"],
|
|
66
|
+
})
|
|
67
|
+
.refine((data) => data.orderType !== "MARKET" || data.limitPrice === undefined, {
|
|
68
|
+
message: "limitPrice must not be provided for MARKET TP/SL legs",
|
|
69
|
+
path: ["limitPrice"],
|
|
70
|
+
})
|
|
71
|
+
.refine((data) => data.orderType !== "MARKET" || data.timeInForce === undefined, {
|
|
72
|
+
message: "timeInForce is only allowed for LIMIT TP/SL legs",
|
|
73
|
+
path: ["timeInForce"],
|
|
74
|
+
})
|
|
75
|
+
.refine((data) => data.orderType !== "LIMIT" || data.slippageToleranceBps === undefined, {
|
|
76
|
+
message: "slippageToleranceBps is only allowed for MARKET TP/SL legs",
|
|
77
|
+
path: ["slippageToleranceBps"],
|
|
78
|
+
});
|
|
79
|
+
export const AttachPositionTpSlSchema = PositionIdSchema.extend({
|
|
80
|
+
request: z
|
|
81
|
+
.object({
|
|
82
|
+
takeProfit: TpSlLegSchema.optional(),
|
|
83
|
+
stopLoss: TpSlLegSchema.optional(),
|
|
84
|
+
})
|
|
85
|
+
.refine((data) => data.takeProfit !== undefined || data.stopLoss !== undefined, {
|
|
86
|
+
message: "At least one of takeProfit or stopLoss is required",
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
export const ListPositionHistorySchema = PaginationSchema.extend({
|
|
90
|
+
position_id: UUIDSchema.optional(),
|
|
91
|
+
margin_account_id: UUIDSchema.optional(),
|
|
92
|
+
trading_pair_id: UUIDSchema.optional(),
|
|
93
|
+
});
|
|
@@ -36,7 +36,7 @@ export declare const TransactionTypeSchema: z.ZodEnum<{
|
|
|
36
36
|
*/
|
|
37
37
|
export declare const GetUserMovementsSchema: z.ZodObject<{
|
|
38
38
|
page: z.ZodOptional<z.ZodNumber>;
|
|
39
|
-
|
|
39
|
+
page_size: z.ZodOptional<z.ZodNumber>;
|
|
40
40
|
entry_type: z.ZodOptional<z.ZodEnum<{
|
|
41
41
|
CREDIT: "CREDIT";
|
|
42
42
|
DEBIT: "DEBIT";
|
|
@@ -64,6 +64,6 @@ export declare const GetUserMovementsSchema: z.ZodObject<{
|
|
|
64
64
|
*/
|
|
65
65
|
export declare const GetUserTradesSchema: z.ZodObject<{
|
|
66
66
|
page: z.ZodOptional<z.ZodNumber>;
|
|
67
|
-
|
|
67
|
+
page_size: z.ZodOptional<z.ZodNumber>;
|
|
68
68
|
trading_pair_id: z.ZodOptional<z.ZodUUID>;
|
|
69
69
|
}, z.core.$strip>;
|
|
@@ -26,7 +26,7 @@ export const TransactionTypeSchema = z.enum(["DEPOSIT", "WITHDRAWAL", "TRADE", "
|
|
|
26
26
|
*/
|
|
27
27
|
export const GetUserMovementsSchema = z.object({
|
|
28
28
|
page: z.number().int("Page must be an integer").min(1, "Page must be at least 1").optional(),
|
|
29
|
-
|
|
29
|
+
page_size: z.number().int("Page size must be an integer").min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
|
|
30
30
|
entry_type: LedgerEntryTypeSchema.optional(),
|
|
31
31
|
transaction_type: TransactionTypeSchema.optional(),
|
|
32
32
|
asset_id: UUIDSchema.optional(),
|
|
@@ -39,6 +39,6 @@ export const GetUserMovementsSchema = z.object({
|
|
|
39
39
|
*/
|
|
40
40
|
export const GetUserTradesSchema = z.object({
|
|
41
41
|
page: z.number().int("Page must be an integer").min(1, "Page must be at least 1").optional(),
|
|
42
|
-
|
|
42
|
+
page_size: z.number().int("Page size must be an integer").min(1, "Page size must be at least 1").max(100, "Page size cannot exceed 100").optional(),
|
|
43
43
|
trading_pair_id: UUIDSchema.optional(),
|
|
44
44
|
});
|