@0xmonaco/core 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/api/index.d.ts +3 -0
- package/dist/api/index.js +3 -0
- package/dist/api/margin-accounts/api.d.ts +12 -0
- package/dist/api/margin-accounts/api.js +69 -0
- package/dist/api/margin-accounts/index.d.ts +1 -0
- package/dist/api/margin-accounts/index.js +1 -0
- package/dist/api/market/api.d.ts +8 -1
- package/dist/api/market/api.js +34 -6
- package/dist/api/orderbook/api.js +1 -1
- package/dist/api/perp/index.d.ts +1 -0
- package/dist/api/perp/index.js +1 -0
- package/dist/api/perp/routes.d.ts +133 -0
- package/dist/api/perp/routes.js +85 -0
- package/dist/api/positions/api.d.ts +12 -0
- package/dist/api/positions/api.js +88 -0
- package/dist/api/positions/index.d.ts +1 -0
- package/dist/api/positions/index.js +1 -0
- package/dist/api/profile/api.d.ts +10 -10
- package/dist/api/profile/api.js +18 -18
- package/dist/api/trades/api.d.ts +4 -4
- package/dist/api/trades/api.js +8 -8
- package/dist/api/trading/api.d.ts +14 -3
- package/dist/api/trading/api.js +76 -15
- package/dist/api/websocket/types.d.ts +3 -1
- package/dist/api/websocket/websocket.js +153 -17
- package/dist/sdk.d.ts +3 -1
- package/dist/sdk.js +12 -4
- package/package.json +1 -1
package/dist/api/profile/api.js
CHANGED
|
@@ -64,12 +64,12 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
64
64
|
*
|
|
65
65
|
* @example
|
|
66
66
|
* ```typescript
|
|
67
|
-
* // Get first page with default
|
|
67
|
+
* // Get first page with default page_size (20)
|
|
68
68
|
* const movements = await profileAPI.getPaginatedUserMovements();
|
|
69
|
-
* console.log(`Total movements: ${movements.
|
|
69
|
+
* console.log(`Total movements: ${movements.total}`);
|
|
70
70
|
*
|
|
71
|
-
* // Get second page with custom
|
|
72
|
-
* const page2 = await profileAPI.getPaginatedUserMovements({ page: 2,
|
|
71
|
+
* // Get second page with custom page_size
|
|
72
|
+
* const page2 = await profileAPI.getPaginatedUserMovements({ page: 2, page_size: 50 });
|
|
73
73
|
* console.log(`Page ${page2.page} of ${page2.total_pages}`);
|
|
74
74
|
*
|
|
75
75
|
* // Filter by entry type and transaction type
|
|
@@ -87,8 +87,8 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
87
87
|
if (params?.page !== undefined) {
|
|
88
88
|
searchParams.append("page", params.page.toString());
|
|
89
89
|
}
|
|
90
|
-
if (params?.
|
|
91
|
-
searchParams.append("
|
|
90
|
+
if (params?.page_size !== undefined) {
|
|
91
|
+
searchParams.append("page_size", params.page_size.toString());
|
|
92
92
|
}
|
|
93
93
|
if (params?.entry_type !== undefined) {
|
|
94
94
|
searchParams.append("entry_type", params.entry_type);
|
|
@@ -110,8 +110,8 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
110
110
|
* Requires a valid access token to be set.
|
|
111
111
|
*
|
|
112
112
|
* @param params - Optional query parameters for pagination
|
|
113
|
-
* @param params.
|
|
114
|
-
* @param params.
|
|
113
|
+
* @param params.page - Page number (starts from 1, default: 1)
|
|
114
|
+
* @param params.page_size - Number of items per page (default: 20, max: 100)
|
|
115
115
|
* @returns Promise resolving to paginated balances response
|
|
116
116
|
* @throws {APIError} When the request fails or user is not authenticated
|
|
117
117
|
*
|
|
@@ -124,18 +124,18 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
124
124
|
* console.log(`${balance.symbol}: ${balance.available_balance}`);
|
|
125
125
|
* });
|
|
126
126
|
*
|
|
127
|
-
* // Get
|
|
128
|
-
* const nextBalances = await profileAPI.getUserBalances({
|
|
127
|
+
* // Get page 2 with 50 items per page
|
|
128
|
+
* const nextBalances = await profileAPI.getUserBalances({ page: 2, page_size: 50 });
|
|
129
129
|
* console.log(`Returned ${nextBalances.balances.length} balances`);
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
async getUserBalances(params) {
|
|
133
133
|
const searchParams = new URLSearchParams();
|
|
134
|
-
if (params?.
|
|
135
|
-
searchParams.append("
|
|
134
|
+
if (params?.page !== undefined) {
|
|
135
|
+
searchParams.append("page", params.page.toString());
|
|
136
136
|
}
|
|
137
|
-
if (params?.
|
|
138
|
-
searchParams.append("
|
|
137
|
+
if (params?.page_size !== undefined) {
|
|
138
|
+
searchParams.append("page_size", params.page_size.toString());
|
|
139
139
|
}
|
|
140
140
|
const queryString = searchParams.toString();
|
|
141
141
|
const url = queryString ? `/api/v1/accounts/balances?${queryString}` : "/api/v1/accounts/balances";
|
|
@@ -222,7 +222,7 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
222
222
|
*
|
|
223
223
|
* @param params - Optional query parameters for pagination and filtering
|
|
224
224
|
* @param params.page - Page number (starts from 1, default: 1)
|
|
225
|
-
* @param params.
|
|
225
|
+
* @param params.page_size - Number of items per page (default: 20, max: 100)
|
|
226
226
|
* @param params.trading_pair_id - Filter by trading pair ID (UUID)
|
|
227
227
|
* @returns Promise resolving to paginated trades response
|
|
228
228
|
* @throws {ValidationError} When the provided params fail client-side validation
|
|
@@ -232,7 +232,7 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
232
232
|
* ```typescript
|
|
233
233
|
* // Get first page of trades
|
|
234
234
|
* const trades = await profileAPI.getUserTrades();
|
|
235
|
-
* console.log(`Total trades: ${trades.
|
|
235
|
+
* console.log(`Total trades: ${trades.total}`);
|
|
236
236
|
*
|
|
237
237
|
* // Filter by trading pair
|
|
238
238
|
* const pairTrades = await profileAPI.getUserTrades({ trading_pair_id: "550e8400-e29b-41d4-a716-446655440000" });
|
|
@@ -246,8 +246,8 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
246
246
|
if (params?.page !== undefined) {
|
|
247
247
|
searchParams.append("page", params.page.toString());
|
|
248
248
|
}
|
|
249
|
-
if (params?.
|
|
250
|
-
searchParams.append("
|
|
249
|
+
if (params?.page_size !== undefined) {
|
|
250
|
+
searchParams.append("page_size", params.page_size.toString());
|
|
251
251
|
}
|
|
252
252
|
if (params?.trading_pair_id !== undefined) {
|
|
253
253
|
searchParams.append("trading_pair_id", params.trading_pair_id);
|
package/dist/api/trades/api.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { BaseAPI } from "../base";
|
|
|
5
5
|
*/
|
|
6
6
|
interface RawTradeEvent {
|
|
7
7
|
event_type: string;
|
|
8
|
-
|
|
8
|
+
trading_pair_id: string;
|
|
9
9
|
trading_mode: string;
|
|
10
10
|
data: {
|
|
11
11
|
trade_id: string;
|
|
@@ -23,10 +23,10 @@ export declare function parseRawTradeEvent(raw: RawTradeEvent): TradeEvent;
|
|
|
23
23
|
* Options for fetching trades
|
|
24
24
|
*/
|
|
25
25
|
export interface GetTradesOptions {
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/** Page number (starts from 1, default: 1) */
|
|
27
|
+
page?: number;
|
|
28
28
|
/** Maximum number of records to return (default: 25, max: 100) */
|
|
29
|
-
|
|
29
|
+
page_size?: number;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Trades API for fetching historical trade data
|
package/dist/api/trades/api.js
CHANGED
|
@@ -5,7 +5,7 @@ import { BaseAPI } from "../base";
|
|
|
5
5
|
export function parseRawTradeEvent(raw) {
|
|
6
6
|
return {
|
|
7
7
|
eventType: "trade",
|
|
8
|
-
tradingPairId: raw.
|
|
8
|
+
tradingPairId: raw.trading_pair_id,
|
|
9
9
|
tradingMode: raw.trading_mode.toUpperCase(),
|
|
10
10
|
data: {
|
|
11
11
|
tradeId: raw.data.trade_id,
|
|
@@ -28,15 +28,15 @@ export class TradesAPIImpl extends BaseAPI {
|
|
|
28
28
|
* @returns Array of TradeEvent records sorted by executed_at descending (newest first)
|
|
29
29
|
*/
|
|
30
30
|
async getTrades(tradingPairId, options = {}) {
|
|
31
|
-
const {
|
|
32
|
-
// Ensure
|
|
33
|
-
const
|
|
31
|
+
const { page = 1 } = options;
|
|
32
|
+
// Ensure page_size is a positive number between 1 and 100, defaulting to 25
|
|
33
|
+
const page_size = options.page_size != null && options.page_size > 0 ? Math.min(options.page_size, 100) : 25;
|
|
34
34
|
const params = new URLSearchParams();
|
|
35
|
-
if (
|
|
36
|
-
params.set("
|
|
35
|
+
if (page > 1) {
|
|
36
|
+
params.set("page", String(page));
|
|
37
37
|
}
|
|
38
|
-
params.set("
|
|
38
|
+
params.set("page_size", String(page_size));
|
|
39
39
|
const response = await this.makePublicRequest(`/api/v1/trades/${encodeURIComponent(tradingPairId)}?${params.toString()}`);
|
|
40
|
-
return response.
|
|
40
|
+
return response.trades.map(parseRawTradeEvent);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* );
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, OrderSide, ReplaceOrderResponse, TimeInForce, TradingAPI, TradingMode } from "@0xmonaco/types";
|
|
24
|
+
import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, CreateConditionalOrderParams, CreateConditionalOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, OrderSide, PositionSide, ReplaceOrderResponse, TimeInForce, TradingAPI, TradingMode } from "@0xmonaco/types";
|
|
25
25
|
import { BaseAPI } from "../base";
|
|
26
26
|
export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
27
27
|
/**
|
|
@@ -79,6 +79,10 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
79
79
|
useMasterBalance?: boolean;
|
|
80
80
|
expirationDate?: string;
|
|
81
81
|
timeInForce?: TimeInForce;
|
|
82
|
+
marginAccountId?: string;
|
|
83
|
+
positionSide?: PositionSide;
|
|
84
|
+
leverage?: string;
|
|
85
|
+
reduceOnly?: boolean;
|
|
82
86
|
}): Promise<CreateOrderResponse>;
|
|
83
87
|
/**
|
|
84
88
|
* Places a market order for immediate execution.
|
|
@@ -124,6 +128,10 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
124
128
|
placeMarketOrder(tradingPairId: string, side: OrderSide, quantity: string, options?: {
|
|
125
129
|
tradingMode?: TradingMode;
|
|
126
130
|
slippageTolerance?: number;
|
|
131
|
+
marginAccountId?: string;
|
|
132
|
+
positionSide?: PositionSide;
|
|
133
|
+
leverage?: string;
|
|
134
|
+
reduceOnly?: boolean;
|
|
127
135
|
}): Promise<CreateOrderResponse>;
|
|
128
136
|
/**
|
|
129
137
|
* Cancels an existing order.
|
|
@@ -142,6 +150,9 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
142
150
|
* ```
|
|
143
151
|
*/
|
|
144
152
|
cancelOrder(orderId: string): Promise<CancelOrderResponse>;
|
|
153
|
+
createConditionalOrder(params: CreateConditionalOrderParams): Promise<CreateConditionalOrderResponse>;
|
|
154
|
+
cancelConditionalOrder(conditionalOrderId: string): Promise<CancelConditionalOrderResponse>;
|
|
155
|
+
listConditionalOrders(params?: ListConditionalOrdersParams): Promise<ListConditionalOrdersResponse>;
|
|
145
156
|
/**
|
|
146
157
|
* Batch cancels specific orders by their IDs.
|
|
147
158
|
*
|
|
@@ -242,7 +253,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
242
253
|
*
|
|
243
254
|
* @param params - Query parameters for filtering orders
|
|
244
255
|
* @param params.status - Filter by order status (e.g., "SUBMITTED", "FILLED") (optional)
|
|
245
|
-
* @param params.
|
|
256
|
+
* @param params.trading_pair_id - Filter by trading pair UUID (optional)
|
|
246
257
|
* @param params.page - Page number for pagination (defaults to 1, must be > 0)
|
|
247
258
|
* @param params.page_size - Number of orders per page (defaults to 10, max 100, must be > 0)
|
|
248
259
|
* @returns Promise resolving to GetPaginatedOrdersResponse with orders and pagination info
|
|
@@ -253,7 +264,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
253
264
|
* // Get submitted orders for a specific trading pair with custom pagination
|
|
254
265
|
* const orders = await tradingAPI.getPaginatedOrders({
|
|
255
266
|
* status: "SUBMITTED",
|
|
256
|
-
*
|
|
267
|
+
* trading_pair_id: "456e7890-e12b-12d3-a456-426614174000",
|
|
257
268
|
* page: 1,
|
|
258
269
|
* page_size: 20
|
|
259
270
|
* });
|
package/dist/api/trading/api.js
CHANGED
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
* );
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
import { BatchCreateOrdersSchema, BatchReplaceOrdersSchema, CancelOrderSchema, GetPaginatedOrdersSchema, PlaceLimitOrderSchema, PlaceMarketOrderSchema, ReplaceOrderSchema, validate, } from "@0xmonaco/types";
|
|
24
|
+
import { BatchCreateOrdersSchema, BatchReplaceOrdersSchema, CancelConditionalOrderSchema, CancelOrderSchema, CreateConditionalOrderSchema, GetPaginatedOrdersSchema, ListConditionalOrdersSchema, PlaceLimitOrderSchema, PlaceMarketOrderSchema, ReplaceOrderSchema, validate, } from "@0xmonaco/types";
|
|
25
25
|
import { BaseAPI } from "../base";
|
|
26
|
+
import { perpRoutes } from "../perp";
|
|
26
27
|
export class TradingAPIImpl extends BaseAPI {
|
|
27
28
|
/**
|
|
28
29
|
* Places a limit order on the order book.
|
|
@@ -93,8 +94,12 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
93
94
|
use_master_balance: options?.useMasterBalance,
|
|
94
95
|
expiration_date: options?.expirationDate,
|
|
95
96
|
time_in_force: options?.timeInForce,
|
|
97
|
+
margin_account_id: options?.marginAccountId,
|
|
98
|
+
position_side: options?.positionSide,
|
|
99
|
+
leverage: options?.leverage,
|
|
100
|
+
reduce_only: options?.reduceOnly,
|
|
96
101
|
};
|
|
97
|
-
return await this.makeAuthenticatedRequest(
|
|
102
|
+
return await this.makeAuthenticatedRequest(perpRoutes.orders.create(), {
|
|
98
103
|
method: "POST",
|
|
99
104
|
body: JSON.stringify(requestBody),
|
|
100
105
|
});
|
|
@@ -156,8 +161,12 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
156
161
|
price: null, // Market orders don't need price
|
|
157
162
|
quantity,
|
|
158
163
|
trading_mode: options?.tradingMode || "SPOT",
|
|
164
|
+
margin_account_id: options?.marginAccountId,
|
|
165
|
+
position_side: options?.positionSide,
|
|
166
|
+
leverage: options?.leverage,
|
|
167
|
+
reduce_only: options?.reduceOnly,
|
|
159
168
|
};
|
|
160
|
-
return await this.makeAuthenticatedRequest(
|
|
169
|
+
return await this.makeAuthenticatedRequest(perpRoutes.orders.create(), {
|
|
161
170
|
method: "POST",
|
|
162
171
|
body: JSON.stringify(requestBody),
|
|
163
172
|
});
|
|
@@ -184,11 +193,53 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
184
193
|
const requestBody = {
|
|
185
194
|
order_id: orderId,
|
|
186
195
|
};
|
|
187
|
-
return await this.makeAuthenticatedRequest(
|
|
196
|
+
return await this.makeAuthenticatedRequest(perpRoutes.orders.cancel(), {
|
|
188
197
|
method: "POST",
|
|
189
198
|
body: JSON.stringify(requestBody),
|
|
190
199
|
});
|
|
191
200
|
}
|
|
201
|
+
async createConditionalOrder(params) {
|
|
202
|
+
validate(CreateConditionalOrderSchema, params);
|
|
203
|
+
const requestBody = {
|
|
204
|
+
trading_pair_id: params.tradingPairId,
|
|
205
|
+
margin_account_id: params.marginAccountId,
|
|
206
|
+
condition_type: params.conditionType,
|
|
207
|
+
trigger_price: params.triggerPrice,
|
|
208
|
+
trigger_source: params.triggerSource ?? "MARK_PRICE",
|
|
209
|
+
side: params.side,
|
|
210
|
+
position_side: params.positionSide,
|
|
211
|
+
order_type: params.orderType,
|
|
212
|
+
limit_price: params.limitPrice,
|
|
213
|
+
quantity: params.quantity,
|
|
214
|
+
reduce_only: params.reduceOnly ?? true,
|
|
215
|
+
time_in_force: params.timeInForce,
|
|
216
|
+
slippage_tolerance_bps: params.slippageToleranceBps,
|
|
217
|
+
expires_at: params.expiresAt,
|
|
218
|
+
};
|
|
219
|
+
return await this.makeAuthenticatedRequest(perpRoutes.orders.createConditional(), {
|
|
220
|
+
method: "POST",
|
|
221
|
+
body: JSON.stringify(requestBody),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
async cancelConditionalOrder(conditionalOrderId) {
|
|
225
|
+
validate(CancelConditionalOrderSchema, { conditionalOrderId });
|
|
226
|
+
return await this.makeAuthenticatedRequest(perpRoutes.orders.cancelConditional(conditionalOrderId), {
|
|
227
|
+
method: "DELETE",
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async listConditionalOrders(params) {
|
|
231
|
+
if (params) {
|
|
232
|
+
validate(ListConditionalOrdersSchema, params);
|
|
233
|
+
}
|
|
234
|
+
const { page = 1, page_size = 20, margin_account_id, trading_pair_id, state } = params || {};
|
|
235
|
+
return await this.makeAuthenticatedRequest(perpRoutes.orders.listConditional({
|
|
236
|
+
page,
|
|
237
|
+
page_size: Math.min(Math.max(page_size, 1), 100),
|
|
238
|
+
margin_account_id,
|
|
239
|
+
trading_pair_id,
|
|
240
|
+
state,
|
|
241
|
+
}), { method: "GET" });
|
|
242
|
+
}
|
|
192
243
|
/**
|
|
193
244
|
* Batch cancels specific orders by their IDs.
|
|
194
245
|
*
|
|
@@ -205,7 +256,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
205
256
|
if (!orderIds || orderIds.length === 0) {
|
|
206
257
|
throw new Error("orderIds is required and must not be empty");
|
|
207
258
|
}
|
|
208
|
-
return this.makeAuthenticatedRequest(
|
|
259
|
+
return this.makeAuthenticatedRequest(perpRoutes.orders.batchCancel(), {
|
|
209
260
|
method: "POST",
|
|
210
261
|
body: JSON.stringify({ order_ids: orderIds }),
|
|
211
262
|
});
|
|
@@ -227,7 +278,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
227
278
|
* ```
|
|
228
279
|
*/
|
|
229
280
|
async batchCancelAll(tradingPairId) {
|
|
230
|
-
const endpoint = tradingPairId ?
|
|
281
|
+
const endpoint = tradingPairId ? perpRoutes.orders.batchCancelAllByPair(tradingPairId) : perpRoutes.orders.batchCancelAll();
|
|
231
282
|
return this.makeAuthenticatedRequest(endpoint, {
|
|
232
283
|
method: "POST",
|
|
233
284
|
});
|
|
@@ -244,7 +295,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
244
295
|
if (newOrder.quantity !== undefined) {
|
|
245
296
|
requestBody.quantity = newOrder.quantity;
|
|
246
297
|
}
|
|
247
|
-
return await this.makeAuthenticatedRequest(
|
|
298
|
+
return await this.makeAuthenticatedRequest(perpRoutes.orders.replace(orderId), {
|
|
248
299
|
method: "PUT",
|
|
249
300
|
body: JSON.stringify(requestBody),
|
|
250
301
|
});
|
|
@@ -293,9 +344,13 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
293
344
|
use_master_balance: order.useMasterBalance,
|
|
294
345
|
expiration_date: order.expirationDate,
|
|
295
346
|
time_in_force: order.timeInForce,
|
|
347
|
+
margin_account_id: order.marginAccountId,
|
|
348
|
+
position_side: order.positionSide,
|
|
349
|
+
leverage: order.leverage,
|
|
350
|
+
reduce_only: order.reduceOnly,
|
|
296
351
|
})),
|
|
297
352
|
};
|
|
298
|
-
return this.makeAuthenticatedRequest(
|
|
353
|
+
return this.makeAuthenticatedRequest(perpRoutes.orders.batchCreate(), {
|
|
299
354
|
method: "POST",
|
|
300
355
|
body: JSON.stringify(requestBody),
|
|
301
356
|
});
|
|
@@ -335,7 +390,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
335
390
|
use_master_balance: order.useMasterBalance,
|
|
336
391
|
})),
|
|
337
392
|
};
|
|
338
|
-
return this.makeAuthenticatedRequest(
|
|
393
|
+
return this.makeAuthenticatedRequest(perpRoutes.orders.batchReplace(), {
|
|
339
394
|
method: "POST",
|
|
340
395
|
body: JSON.stringify(requestBody),
|
|
341
396
|
});
|
|
@@ -348,7 +403,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
348
403
|
*
|
|
349
404
|
* @param params - Query parameters for filtering orders
|
|
350
405
|
* @param params.status - Filter by order status (e.g., "SUBMITTED", "FILLED") (optional)
|
|
351
|
-
* @param params.
|
|
406
|
+
* @param params.trading_pair_id - Filter by trading pair UUID (optional)
|
|
352
407
|
* @param params.page - Page number for pagination (defaults to 1, must be > 0)
|
|
353
408
|
* @param params.page_size - Number of orders per page (defaults to 10, max 100, must be > 0)
|
|
354
409
|
* @returns Promise resolving to GetPaginatedOrdersResponse with orders and pagination info
|
|
@@ -359,7 +414,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
359
414
|
* // Get submitted orders for a specific trading pair with custom pagination
|
|
360
415
|
* const orders = await tradingAPI.getPaginatedOrders({
|
|
361
416
|
* status: "SUBMITTED",
|
|
362
|
-
*
|
|
417
|
+
* trading_pair_id: "456e7890-e12b-12d3-a456-426614174000",
|
|
363
418
|
* page: 1,
|
|
364
419
|
* page_size: 20
|
|
365
420
|
* });
|
|
@@ -375,7 +430,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
375
430
|
validate(GetPaginatedOrdersSchema, params);
|
|
376
431
|
}
|
|
377
432
|
// Set pagination defaults with destructuring and validation
|
|
378
|
-
const { page = 1, page_size = 10, status,
|
|
433
|
+
const { page = 1, page_size = 10, status, trading_pair_id, trading_mode, margin_account_id } = params || {};
|
|
379
434
|
const validPage = page > 0 ? page : 1;
|
|
380
435
|
const validPageSize = page_size > 0 ? page_size : 10;
|
|
381
436
|
const pageSize = Math.min(validPageSize, 100);
|
|
@@ -386,8 +441,14 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
386
441
|
if (status) {
|
|
387
442
|
searchParams.append("status", status);
|
|
388
443
|
}
|
|
389
|
-
if (
|
|
390
|
-
searchParams.append("
|
|
444
|
+
if (trading_pair_id) {
|
|
445
|
+
searchParams.append("trading_pair_id", trading_pair_id);
|
|
446
|
+
}
|
|
447
|
+
if (trading_mode) {
|
|
448
|
+
searchParams.append("trading_mode", trading_mode);
|
|
449
|
+
}
|
|
450
|
+
if (margin_account_id) {
|
|
451
|
+
searchParams.append("margin_account_id", margin_account_id);
|
|
391
452
|
}
|
|
392
453
|
const endpoint = `/api/v1/orders?${searchParams.toString()}`;
|
|
393
454
|
return await this.makeAuthenticatedRequest(endpoint, {
|
|
@@ -413,7 +474,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
413
474
|
* ```
|
|
414
475
|
*/
|
|
415
476
|
async getOrder(orderId) {
|
|
416
|
-
return await this.makeAuthenticatedRequest(
|
|
477
|
+
return await this.makeAuthenticatedRequest(perpRoutes.orders.get(orderId), {
|
|
417
478
|
method: "GET",
|
|
418
479
|
});
|
|
419
480
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Interval, OHLCVEvent, OrderbookEvent, OrderbookQuotationMode, OrderEvent, TradeEvent, TradingMode, UserBalanceEvent, UserMovementEvent, WebSocketStatus } from "@0xmonaco/types";
|
|
1
|
+
import type { ConditionalOrderEvent, Interval, OHLCVEvent, OrderbookEvent, OrderbookQuotationMode, OrderEvent, TradeEvent, TradingMode, UserBalanceEvent, UserMovementEvent, WebSocketStatus } from "@0xmonaco/types";
|
|
2
2
|
export type StatusHandler = (status: WebSocketStatus) => void;
|
|
3
3
|
export type MessageHandler<T> = (data: T) => void;
|
|
4
4
|
export interface MonacoWebSocketOptions {
|
|
@@ -36,4 +36,6 @@ export interface MonacoWebSocket {
|
|
|
36
36
|
userOrders: (handler: MessageHandler<OrderEvent>) => () => void;
|
|
37
37
|
/** Subscribe to user balance events (requires authentication) */
|
|
38
38
|
balances: (handler: MessageHandler<UserBalanceEvent>) => () => void;
|
|
39
|
+
/** Subscribe to conditional TP/SL lifecycle events (requires authentication) */
|
|
40
|
+
conditionalOrders: (handler: MessageHandler<ConditionalOrderEvent>, tradingPairId?: string) => () => void;
|
|
39
41
|
}
|