@0xmonaco/core 0.7.7 → 0.7.9

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.
Files changed (77) hide show
  1. package/dist/api/applications/api.d.ts +43 -0
  2. package/dist/api/applications/api.js +54 -0
  3. package/dist/api/applications/index.d.ts +4 -0
  4. package/dist/api/applications/index.js +4 -0
  5. package/dist/api/auth/api.d.ts +206 -0
  6. package/dist/api/auth/api.js +305 -0
  7. package/dist/api/auth/index.d.ts +4 -0
  8. package/dist/api/auth/index.js +4 -0
  9. package/dist/api/base.d.ts +123 -0
  10. package/dist/api/base.js +286 -0
  11. package/dist/api/fees/api.d.ts +72 -0
  12. package/dist/api/fees/api.js +90 -0
  13. package/dist/api/fees/index.d.ts +6 -0
  14. package/dist/api/fees/index.js +6 -0
  15. package/dist/api/index.d.ts +18 -0
  16. package/dist/api/index.js +18 -0
  17. package/dist/api/margin-accounts/api.d.ts +12 -0
  18. package/dist/api/margin-accounts/api.js +69 -0
  19. package/dist/api/margin-accounts/index.d.ts +1 -0
  20. package/dist/api/margin-accounts/index.js +1 -0
  21. package/dist/api/market/api.d.ts +20 -0
  22. package/dist/api/market/api.js +97 -0
  23. package/dist/api/market/index.d.ts +1 -0
  24. package/dist/api/market/index.js +1 -0
  25. package/dist/api/orderbook/api.d.ts +15 -0
  26. package/dist/api/orderbook/api.js +37 -0
  27. package/dist/api/orderbook/index.d.ts +1 -0
  28. package/dist/api/orderbook/index.js +1 -0
  29. package/dist/api/perp/index.d.ts +1 -0
  30. package/dist/api/perp/index.js +1 -0
  31. package/dist/api/perp/routes.d.ts +133 -0
  32. package/dist/api/perp/routes.js +85 -0
  33. package/dist/api/positions/api.d.ts +12 -0
  34. package/dist/api/positions/api.js +86 -0
  35. package/dist/api/positions/index.d.ts +1 -0
  36. package/dist/api/positions/index.js +1 -0
  37. package/dist/api/profile/api.d.ts +191 -0
  38. package/dist/api/profile/api.js +259 -0
  39. package/dist/api/profile/index.d.ts +6 -0
  40. package/dist/api/profile/index.js +6 -0
  41. package/dist/api/trades/api.d.ts +44 -0
  42. package/dist/api/trades/api.js +42 -0
  43. package/dist/api/trades/index.d.ts +1 -0
  44. package/dist/api/trades/index.js +1 -0
  45. package/dist/api/trading/api.d.ts +301 -0
  46. package/dist/api/trading/api.js +497 -0
  47. package/dist/api/trading/index.d.ts +4 -0
  48. package/dist/api/trading/index.js +4 -0
  49. package/dist/api/vault/api.d.ts +261 -0
  50. package/dist/api/vault/api.js +506 -0
  51. package/dist/api/vault/index.d.ts +4 -0
  52. package/dist/api/vault/index.js +4 -0
  53. package/dist/api/websocket/index.d.ts +3 -0
  54. package/dist/api/websocket/index.js +3 -0
  55. package/dist/api/websocket/types.d.ts +41 -0
  56. package/dist/api/websocket/types.js +0 -0
  57. package/dist/api/websocket/utils.d.ts +8 -0
  58. package/dist/api/websocket/utils.js +22 -0
  59. package/dist/api/websocket/websocket.d.ts +5 -0
  60. package/dist/api/websocket/websocket.js +560 -0
  61. package/dist/errors/errors.d.ts +381 -0
  62. package/dist/errors/errors.js +815 -0
  63. package/dist/errors/index.d.ts +1 -0
  64. package/dist/errors/index.js +1 -0
  65. package/dist/index.d.ts +5 -0
  66. package/dist/index.js +5 -0
  67. package/dist/networks/index.d.ts +1 -0
  68. package/dist/networks/index.js +1 -0
  69. package/dist/networks/networks.d.ts +21 -0
  70. package/dist/networks/networks.js +46 -0
  71. package/dist/sdk.d.ts +134 -0
  72. package/dist/sdk.js +294 -0
  73. package/dist/utils/index.d.ts +1 -0
  74. package/dist/utils/index.js +1 -0
  75. package/dist/utils/magnitude.d.ts +26 -0
  76. package/dist/utils/magnitude.js +31 -0
  77. package/package.json +3 -3
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Trading API Implementation
3
+ *
4
+ * Handles trading operations including order placement and management.
5
+ * All operations use JWT authentication and go through the API Gateway.
6
+ *
7
+ * This class provides a complete interface for trading operations on the Monaco protocol,
8
+ * including various order types, order management, and position operations.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const tradingAPI = new TradingAPIImpl(apiUrl);
13
+ * tradingAPI.setAccessToken(jwtToken);
14
+ *
15
+ * // Place a limit order
16
+ * const order = await tradingAPI.placeLimitOrder(
17
+ * "123e4567-e89b-12d3-a456-426614174000", // trading pair UUID
18
+ * "BUY",
19
+ * "1.5",
20
+ * "2000.50"
21
+ * );
22
+ * ```
23
+ */
24
+ import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, CreateConditionalOrderParams, CreateConditionalOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, OrderSide, ParentTpSlLegParams, PositionSide, ReplaceOrderResponse, TimeInForce, TradingAPI, TradingMode } from "@0xmonaco/types";
25
+ import { BaseAPI } from "../base";
26
+ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
27
+ /**
28
+ * Places a limit order on the order book.
29
+ *
30
+ * Limit orders are executed only when the market price reaches or improves upon
31
+ * the specified price. They provide price protection but may not execute immediately.
32
+ *
33
+ * @param tradingPairId - The trading pair UUID
34
+ * @param side - The order side ("BUY" or "SELL")
35
+ * @param quantity - The order quantity as string
36
+ * @param price - The limit price as string
37
+ * @param options - Optional parameters for the limit order
38
+ * @param options.tradingMode - Trading mode (e.g., "SPOT")
39
+ * @param options.useMasterBalance - Whether to use master balance for sub-accounts
40
+ * @param options.expirationDate - Optional expiration date for GTC orders (ISO 8601 format)
41
+ * @param options.timeInForce - Time in force ("GTC", "IOC", or "FOK")
42
+ * @returns Promise resolving to CreateOrderResponse with order details
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * // Regular limit order
47
+ * const order = await tradingAPI.placeLimitOrder(
48
+ * "123e4567-e89b-12d3-a456-426614174000",
49
+ * "BUY",
50
+ * "0.5",
51
+ * "35000.00",
52
+ * { tradingMode: "SPOT" }
53
+ * );
54
+ *
55
+ * // GTC order with custom expiration
56
+ * const gtcOrder = await tradingAPI.placeLimitOrder(
57
+ * "123e4567-e89b-12d3-a456-426614174000",
58
+ * "BUY",
59
+ * "0.5",
60
+ * "35000.00",
61
+ * {
62
+ * tradingMode: "SPOT",
63
+ * expirationDate: "2024-12-31T23:59:59Z" // GTC until this date
64
+ * }
65
+ * );
66
+ *
67
+ * // IOC order (execute immediately or cancel)
68
+ * const iocOrder = await tradingAPI.placeLimitOrder(
69
+ * "123e4567-e89b-12d3-a456-426614174000",
70
+ * "BUY",
71
+ * "0.5",
72
+ * "35000.00",
73
+ * { timeInForce: "IOC" }
74
+ * );
75
+ * ```
76
+ */
77
+ placeLimitOrder(tradingPairId: string, side: OrderSide, quantity: string, price: string, options?: {
78
+ tradingMode?: TradingMode;
79
+ useMasterBalance?: boolean;
80
+ expirationDate?: string;
81
+ timeInForce?: TimeInForce;
82
+ marginAccountId?: string;
83
+ positionSide?: PositionSide;
84
+ leverage?: string;
85
+ reduceOnly?: boolean;
86
+ takeProfit?: ParentTpSlLegParams;
87
+ stopLoss?: ParentTpSlLegParams;
88
+ }): Promise<CreateOrderResponse>;
89
+ /**
90
+ * Places a market order for immediate execution.
91
+ *
92
+ * Market orders execute immediately at the current market price. They provide
93
+ * immediate execution but may experience slippage.
94
+ *
95
+ * @param tradingPairId - The trading pair UUID
96
+ * @param side - The order side ("BUY" or "SELL")
97
+ * @param quantity - The order quantity as string
98
+ * @param options - Optional parameters for the market order
99
+ * @param options.tradingMode - Trading mode (e.g., "SPOT")
100
+ * @param options.slippageTolerance - Slippage tolerance as decimal (e.g., 0.01 for 1%, 0 for best price only, undefined for unlimited slippage)
101
+ * @returns Promise resolving to CreateOrderResponse with order details
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // Market order with 1% slippage tolerance
106
+ * const order1 = await tradingAPI.placeMarketOrder(
107
+ * "123e4567-e89b-12d3-a456-426614174000",
108
+ * "SELL",
109
+ * "0.5",
110
+ * { tradingMode: "SPOT", slippageTolerance: 0.01 } // 1% slippage
111
+ * );
112
+ *
113
+ * // Market order with zero slippage (only execute at best price)
114
+ * const order2 = await tradingAPI.placeMarketOrder(
115
+ * "123e4567-e89b-12d3-a456-426614174000",
116
+ * "BUY",
117
+ * "1.0",
118
+ * { slippageTolerance: 0 } // Only execute at best ask price
119
+ * );
120
+ *
121
+ * // Market order with unlimited slippage
122
+ * const order3 = await tradingAPI.placeMarketOrder(
123
+ * "123e4567-e89b-12d3-a456-426614174000",
124
+ * "BUY",
125
+ * "1.0"
126
+ * // No slippageTolerance specified = unlimited slippage
127
+ * );
128
+ * ```
129
+ */
130
+ placeMarketOrder(tradingPairId: string, side: OrderSide, quantity: string, options?: {
131
+ tradingMode?: TradingMode;
132
+ slippageTolerance?: number;
133
+ marginAccountId?: string;
134
+ positionSide?: PositionSide;
135
+ leverage?: string;
136
+ reduceOnly?: boolean;
137
+ takeProfit?: ParentTpSlLegParams;
138
+ stopLoss?: ParentTpSlLegParams;
139
+ }): Promise<CreateOrderResponse>;
140
+ /**
141
+ * Cancels an existing order.
142
+ *
143
+ * Cancels an open order by its ID. The order must be in an open state to be canceled.
144
+ * Canceled orders cannot be recovered.
145
+ *
146
+ * @param orderId - The ID of the order to cancel
147
+ * @returns Promise resolving to CancelOrderResponse with cancellation details
148
+ * @throws {APIError} When API communication fails
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const result = await tradingAPI.cancelOrder("order_123");
153
+ * console.log(`Order canceled: ${result.status}`);
154
+ * ```
155
+ */
156
+ cancelOrder(orderId: string): Promise<CancelOrderResponse>;
157
+ createConditionalOrder(params: CreateConditionalOrderParams): Promise<CreateConditionalOrderResponse>;
158
+ cancelConditionalOrder(conditionalOrderId: string): Promise<CancelConditionalOrderResponse>;
159
+ listConditionalOrders(params?: ListConditionalOrdersParams): Promise<ListConditionalOrdersResponse>;
160
+ /**
161
+ * Batch cancels specific orders by their IDs.
162
+ *
163
+ * @param orderIds - Array of order IDs to cancel
164
+ * @returns Promise resolving to BatchCancelOrdersResponse with cancellation details
165
+ * @throws {APIError} When API communication fails
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const result = await tradingAPI.batchCancel(["order_123", "order_456"]);
170
+ * ```
171
+ */
172
+ batchCancel(orderIds: string[]): Promise<BatchCancelOrdersResponse>;
173
+ /**
174
+ * Cancels all active orders, optionally filtered by trading pair.
175
+ *
176
+ * @param tradingPairId - Optional trading pair ID to filter cancellation
177
+ * @returns Promise resolving to BatchCancelOrdersResponse with cancellation details
178
+ * @throws {APIError} When API communication fails
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Cancel all active orders globally
183
+ * await tradingAPI.batchCancelAll();
184
+ *
185
+ * // Cancel all orders for a specific trading pair
186
+ * await tradingAPI.batchCancelAll("123e4567-e89b-12d3-a456-426614174000");
187
+ * ```
188
+ */
189
+ batchCancelAll(tradingPairId?: string): Promise<BatchCancelOrdersResponse>;
190
+ replaceOrder(orderId: string, newOrder: {
191
+ price?: string;
192
+ quantity?: string;
193
+ useMasterBalance?: boolean;
194
+ }): Promise<ReplaceOrderResponse>;
195
+ /**
196
+ * Batch creates multiple orders in a single request.
197
+ *
198
+ * Each order is validated and processed through the matching engine.
199
+ * Failed orders do not prevent other orders from being created.
200
+ *
201
+ * @param orders - Array of order parameters to create
202
+ * @returns Promise resolving to BatchCreateOrdersResponse with individual results
203
+ * @throws {APIError} When API communication fails
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const result = await tradingAPI.batchCreate([
208
+ * {
209
+ * tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
210
+ * orderType: "LIMIT",
211
+ * side: "BUY",
212
+ * price: "35000.00",
213
+ * quantity: "0.5",
214
+ * },
215
+ * {
216
+ * tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
217
+ * orderType: "LIMIT",
218
+ * side: "SELL",
219
+ * price: "36000.00",
220
+ * quantity: "0.3",
221
+ * },
222
+ * ]);
223
+ * ```
224
+ */
225
+ batchCreate(orders: BatchCreateOrderParams[]): Promise<BatchCreateOrdersResponse>;
226
+ /**
227
+ * Batch replaces multiple orders in a single request.
228
+ *
229
+ * Each order is canceled and re-created with new parameters.
230
+ * Failed replacements do not prevent other orders from being replaced.
231
+ *
232
+ * @param orders - Array of order replacement parameters
233
+ * @returns Promise resolving to BatchReplaceOrdersResponse with individual results
234
+ * @throws {APIError} When API communication fails
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * const result = await tradingAPI.batchReplace([
239
+ * {
240
+ * orderId: "f47ac10b-58cc-4372-a567-0e02b2c3d479",
241
+ * price: "35500.00",
242
+ * quantity: "0.7",
243
+ * },
244
+ * {
245
+ * orderId: "7c9e6679-7425-40de-944b-e07fc1f90ae7",
246
+ * price: "36500.00",
247
+ * },
248
+ * ]);
249
+ * ```
250
+ */
251
+ batchReplace(orders: BatchReplaceOrderParams[]): Promise<BatchReplaceOrdersResponse>;
252
+ /**
253
+ * Gets paginated orders based on query parameters with automatic pagination.
254
+ *
255
+ * Retrieves orders with optional filtering by status, trading pair, and pagination.
256
+ * Pagination parameters are always included with sensible defaults for consistent API behavior.
257
+ *
258
+ * @param params - Query parameters for filtering orders
259
+ * @param params.status - Filter by order status (e.g., "SUBMITTED", "FILLED") (optional)
260
+ * @param params.trading_pair_id - Filter by trading pair UUID (optional)
261
+ * @param params.page - Page number for pagination (defaults to 1, must be > 0)
262
+ * @param params.page_size - Number of orders per page (defaults to 10, max 100, must be > 0)
263
+ * @returns Promise resolving to GetPaginatedOrdersResponse with orders and pagination info
264
+ * @throws {APIError} When API communication fails
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * // Get submitted orders for a specific trading pair with custom pagination
269
+ * const orders = await tradingAPI.getPaginatedOrders({
270
+ * status: "SUBMITTED",
271
+ * trading_pair_id: "456e7890-e12b-12d3-a456-426614174000",
272
+ * page: 1,
273
+ * page_size: 20
274
+ * });
275
+ * console.log(`Found ${orders.total} orders, showing page ${orders.page}`);
276
+ *
277
+ * // Get all orders with default pagination (page=1, page_size=10)
278
+ * const allOrders = await tradingAPI.getPaginatedOrders();
279
+ * ```
280
+ */
281
+ getPaginatedOrders(params?: GetPaginatedOrdersParams): Promise<GetPaginatedOrdersResponse>;
282
+ /**
283
+ * Gets a single order by its ID.
284
+ *
285
+ * Retrieves detailed information about a specific order using its unique identifier.
286
+ * This endpoint provides complete order details including status, quantities, and timestamps.
287
+ *
288
+ * @param orderId - The unique identifier of the order to retrieve
289
+ * @returns Promise resolving to GetOrderResponse with order details
290
+ * @throws {APIError} When API communication fails or order is not found
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * // Get order details by ID
295
+ * const orderDetails = await tradingAPI.getOrder("order_123");
296
+ * console.log(`Order status: ${orderDetails.order.status}`);
297
+ * console.log(`Remaining quantity: ${orderDetails.order.remaining_quantity}`);
298
+ * ```
299
+ */
300
+ getOrder(orderId: string): Promise<GetOrderResponse>;
301
+ }