@0xmonaco/core 0.0.0-develop-20260120180031

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 (130) hide show
  1. package/README.md +693 -0
  2. package/dist/api/applications/api.d.ts +44 -0
  3. package/dist/api/applications/api.d.ts.map +1 -0
  4. package/dist/api/applications/api.js +54 -0
  5. package/dist/api/applications/api.js.map +1 -0
  6. package/dist/api/applications/index.d.ts +5 -0
  7. package/dist/api/applications/index.d.ts.map +1 -0
  8. package/dist/api/applications/index.js +5 -0
  9. package/dist/api/applications/index.js.map +1 -0
  10. package/dist/api/auth/api.d.ts +201 -0
  11. package/dist/api/auth/api.d.ts.map +1 -0
  12. package/dist/api/auth/api.js +293 -0
  13. package/dist/api/auth/api.js.map +1 -0
  14. package/dist/api/auth/index.d.ts +5 -0
  15. package/dist/api/auth/index.d.ts.map +1 -0
  16. package/dist/api/auth/index.js +5 -0
  17. package/dist/api/auth/index.js.map +1 -0
  18. package/dist/api/base.d.ts +124 -0
  19. package/dist/api/base.d.ts.map +1 -0
  20. package/dist/api/base.js +284 -0
  21. package/dist/api/base.js.map +1 -0
  22. package/dist/api/fees/api.d.ts +71 -0
  23. package/dist/api/fees/api.d.ts.map +1 -0
  24. package/dist/api/fees/api.js +83 -0
  25. package/dist/api/fees/api.js.map +1 -0
  26. package/dist/api/fees/index.d.ts +7 -0
  27. package/dist/api/fees/index.d.ts.map +1 -0
  28. package/dist/api/fees/index.js +7 -0
  29. package/dist/api/fees/index.js.map +1 -0
  30. package/dist/api/index.d.ts +16 -0
  31. package/dist/api/index.d.ts.map +1 -0
  32. package/dist/api/index.js +16 -0
  33. package/dist/api/index.js.map +1 -0
  34. package/dist/api/market/api.d.ts +14 -0
  35. package/dist/api/market/api.d.ts.map +1 -0
  36. package/dist/api/market/api.js +70 -0
  37. package/dist/api/market/api.js.map +1 -0
  38. package/dist/api/market/index.d.ts +2 -0
  39. package/dist/api/market/index.d.ts.map +1 -0
  40. package/dist/api/market/index.js +2 -0
  41. package/dist/api/market/index.js.map +1 -0
  42. package/dist/api/orderbook/api.d.ts +16 -0
  43. package/dist/api/orderbook/api.d.ts.map +1 -0
  44. package/dist/api/orderbook/api.js +38 -0
  45. package/dist/api/orderbook/api.js.map +1 -0
  46. package/dist/api/orderbook/index.d.ts +2 -0
  47. package/dist/api/orderbook/index.d.ts.map +1 -0
  48. package/dist/api/orderbook/index.js +2 -0
  49. package/dist/api/orderbook/index.js.map +1 -0
  50. package/dist/api/profile/api.d.ts +119 -0
  51. package/dist/api/profile/api.d.ts.map +1 -0
  52. package/dist/api/profile/api.js +162 -0
  53. package/dist/api/profile/api.js.map +1 -0
  54. package/dist/api/profile/index.d.ts +7 -0
  55. package/dist/api/profile/index.d.ts.map +1 -0
  56. package/dist/api/profile/index.js +7 -0
  57. package/dist/api/profile/index.js.map +1 -0
  58. package/dist/api/trades/api.d.ts +45 -0
  59. package/dist/api/trades/api.d.ts.map +1 -0
  60. package/dist/api/trades/api.js +43 -0
  61. package/dist/api/trades/api.js.map +1 -0
  62. package/dist/api/trades/index.d.ts +2 -0
  63. package/dist/api/trades/index.d.ts.map +1 -0
  64. package/dist/api/trades/index.js +2 -0
  65. package/dist/api/trades/index.js.map +1 -0
  66. package/dist/api/trading/api.d.ts +213 -0
  67. package/dist/api/trading/api.d.ts.map +1 -0
  68. package/dist/api/trading/api.js +285 -0
  69. package/dist/api/trading/api.js.map +1 -0
  70. package/dist/api/trading/index.d.ts +5 -0
  71. package/dist/api/trading/index.d.ts.map +1 -0
  72. package/dist/api/trading/index.js +5 -0
  73. package/dist/api/trading/index.js.map +1 -0
  74. package/dist/api/vault/api.d.ts +257 -0
  75. package/dist/api/vault/api.d.ts.map +1 -0
  76. package/dist/api/vault/api.js +526 -0
  77. package/dist/api/vault/api.js.map +1 -0
  78. package/dist/api/vault/index.d.ts +5 -0
  79. package/dist/api/vault/index.d.ts.map +1 -0
  80. package/dist/api/vault/index.js +5 -0
  81. package/dist/api/vault/index.js.map +1 -0
  82. package/dist/api/websocket/index.d.ts +4 -0
  83. package/dist/api/websocket/index.d.ts.map +1 -0
  84. package/dist/api/websocket/index.js +4 -0
  85. package/dist/api/websocket/index.js.map +1 -0
  86. package/dist/api/websocket/types.d.ts +36 -0
  87. package/dist/api/websocket/types.d.ts.map +1 -0
  88. package/dist/api/websocket/types.js +2 -0
  89. package/dist/api/websocket/types.js.map +1 -0
  90. package/dist/api/websocket/utils.d.ts +9 -0
  91. package/dist/api/websocket/utils.d.ts.map +1 -0
  92. package/dist/api/websocket/utils.js +23 -0
  93. package/dist/api/websocket/utils.js.map +1 -0
  94. package/dist/api/websocket/websocket.d.ts +6 -0
  95. package/dist/api/websocket/websocket.d.ts.map +1 -0
  96. package/dist/api/websocket/websocket.js +345 -0
  97. package/dist/api/websocket/websocket.js.map +1 -0
  98. package/dist/errors/errors.d.ts +382 -0
  99. package/dist/errors/errors.d.ts.map +1 -0
  100. package/dist/errors/errors.js +801 -0
  101. package/dist/errors/errors.js.map +1 -0
  102. package/dist/errors/index.d.ts +2 -0
  103. package/dist/errors/index.d.ts.map +1 -0
  104. package/dist/errors/index.js +2 -0
  105. package/dist/errors/index.js.map +1 -0
  106. package/dist/index.d.ts +6 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +6 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/networks/index.d.ts +2 -0
  111. package/dist/networks/index.d.ts.map +1 -0
  112. package/dist/networks/index.js +2 -0
  113. package/dist/networks/index.js.map +1 -0
  114. package/dist/networks/networks.d.ts +15 -0
  115. package/dist/networks/networks.d.ts.map +1 -0
  116. package/dist/networks/networks.js +34 -0
  117. package/dist/networks/networks.js.map +1 -0
  118. package/dist/sdk.d.ts +128 -0
  119. package/dist/sdk.d.ts.map +1 -0
  120. package/dist/sdk.js +272 -0
  121. package/dist/sdk.js.map +1 -0
  122. package/dist/utils/index.d.ts +2 -0
  123. package/dist/utils/index.d.ts.map +1 -0
  124. package/dist/utils/index.js +2 -0
  125. package/dist/utils/index.js.map +1 -0
  126. package/dist/utils/magnitude.d.ts +27 -0
  127. package/dist/utils/magnitude.d.ts.map +1 -0
  128. package/dist/utils/magnitude.js +32 -0
  129. package/dist/utils/magnitude.js.map +1 -0
  130. package/package.json +49 -0
@@ -0,0 +1,213 @@
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
+ * "ETH-USD",
18
+ * "BUY",
19
+ * "1.5",
20
+ * "2000.50"
21
+ * );
22
+ *
23
+ * // Get open orders
24
+ * const openOrders = await tradingAPI.getOpenOrders({ market: "ETH-USD" });
25
+ * ```
26
+ */
27
+ import type { CancelOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, OrderSide, ReplaceOrderResponse, TimeInForce, TradingAPI, TradingMode } from "@0xmonaco/types";
28
+ import { BaseAPI } from "../base";
29
+ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
30
+ /**
31
+ * Places a limit order on the order book.
32
+ *
33
+ * Limit orders are executed only when the market price reaches or improves upon
34
+ * the specified price. They provide price protection but may not execute immediately.
35
+ *
36
+ * @param tradingPairId - The trading pair UUID
37
+ * @param side - The order side ("BUY" or "SELL")
38
+ * @param quantity - The order quantity as string
39
+ * @param price - The limit price as string
40
+ * @param options - Optional parameters for the limit order
41
+ * @param options.tradingMode - Trading mode (e.g., "SPOT")
42
+ * @param options.useMasterBalance - Whether to use master balance for sub-accounts
43
+ * @param options.expirationDate - Optional expiration date for GTC orders (ISO 8601 format)
44
+ * @param options.timeInForce - Time in force ("GTC", "IOC", or "FOK")
45
+ * @returns Promise resolving to CreateOrderResponse with order details
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Regular limit order
50
+ * const order = await tradingAPI.placeLimitOrder(
51
+ * "123e4567-e89b-12d3-a456-426614174000",
52
+ * "BUY",
53
+ * "0.5",
54
+ * "35000.00",
55
+ * { tradingMode: "SPOT" }
56
+ * );
57
+ *
58
+ * // GTC order with custom expiration
59
+ * const gtcOrder = await tradingAPI.placeLimitOrder(
60
+ * "123e4567-e89b-12d3-a456-426614174000",
61
+ * "BUY",
62
+ * "0.5",
63
+ * "35000.00",
64
+ * {
65
+ * tradingMode: "SPOT",
66
+ * expirationDate: "2024-12-31T23:59:59Z" // GTC until this date
67
+ * }
68
+ * );
69
+ *
70
+ * // IOC order (execute immediately or cancel)
71
+ * const iocOrder = await tradingAPI.placeLimitOrder(
72
+ * "123e4567-e89b-12d3-a456-426614174000",
73
+ * "BUY",
74
+ * "0.5",
75
+ * "35000.00",
76
+ * { timeInForce: "IOC" }
77
+ * );
78
+ * ```
79
+ */
80
+ placeLimitOrder(tradingPairId: string, side: OrderSide, quantity: string, price: string, options?: {
81
+ tradingMode?: TradingMode;
82
+ useMasterBalance?: boolean;
83
+ expirationDate?: string;
84
+ timeInForce?: TimeInForce;
85
+ }): Promise<CreateOrderResponse>;
86
+ /**
87
+ * Places a market order for immediate execution.
88
+ *
89
+ * Market orders execute immediately at the current market price. They provide
90
+ * immediate execution but may experience slippage.
91
+ *
92
+ * @param tradingPairId - The trading pair UUID
93
+ * @param side - The order side ("BUY" or "SELL")
94
+ * @param quantity - The order quantity as string
95
+ * @param options - Optional parameters for the market order
96
+ * @param options.tradingMode - Trading mode (e.g., "SPOT")
97
+ * @param options.slippageTolerance - Slippage tolerance as decimal (e.g., 0.01 for 1%, 0 for best price only, undefined for unlimited slippage)
98
+ * @param options.timeInForce - Time in force ("GTC", "IOC", or "FOK")
99
+ * @returns Promise resolving to CreateOrderResponse with order details
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // Market order with 1% slippage tolerance
104
+ * const order1 = await tradingAPI.placeMarketOrder(
105
+ * "123e4567-e89b-12d3-a456-426614174000",
106
+ * "SELL",
107
+ * "0.5",
108
+ * { tradingMode: "SPOT", slippageTolerance: 0.01 } // 1% slippage
109
+ * );
110
+ *
111
+ * // Market order with zero slippage (only execute at best price)
112
+ * const order2 = await tradingAPI.placeMarketOrder(
113
+ * "123e4567-e89b-12d3-a456-426614174000",
114
+ * "BUY",
115
+ * "1.0",
116
+ * { slippageTolerance: 0 } // Only execute at best ask price
117
+ * );
118
+ *
119
+ * // Market order with unlimited slippage
120
+ * const order3 = await tradingAPI.placeMarketOrder(
121
+ * "123e4567-e89b-12d3-a456-426614174000",
122
+ * "BUY",
123
+ * "1.0"
124
+ * // No slippageTolerance specified = unlimited slippage
125
+ * );
126
+ *
127
+ * // FOK order (fill completely or cancel)
128
+ * const fokOrder = await tradingAPI.placeMarketOrder(
129
+ * "123e4567-e89b-12d3-a456-426614174000",
130
+ * "BUY",
131
+ * "1.0",
132
+ * { timeInForce: "FOK" }
133
+ * );
134
+ * ```
135
+ */
136
+ placeMarketOrder(tradingPairId: string, side: OrderSide, quantity: string, options?: {
137
+ tradingMode?: TradingMode;
138
+ slippageTolerance?: number;
139
+ timeInForce?: TimeInForce;
140
+ }): Promise<CreateOrderResponse>;
141
+ /**
142
+ * Cancels an existing order.
143
+ *
144
+ * Cancels an open order by its ID. The order must be in an open state to be cancelled.
145
+ * Cancelled orders cannot be recovered.
146
+ *
147
+ * @param orderId - The ID of the order to cancel
148
+ * @returns Promise resolving to CancelOrderResponse with cancellation details
149
+ * @throws {APIError} When API communication fails
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const result = await tradingAPI.cancelOrder("order_123");
154
+ * console.log(`Order cancelled: ${result.status}`);
155
+ * ```
156
+ */
157
+ cancelOrder(orderId: string): Promise<CancelOrderResponse>;
158
+ replaceOrder(orderId: string, newOrder: {
159
+ price?: string;
160
+ quantity?: string;
161
+ useMasterBalance?: boolean;
162
+ }): Promise<ReplaceOrderResponse>;
163
+ /**
164
+ * Gets paginated orders based on query parameters with automatic pagination.
165
+ *
166
+ * Retrieves orders with optional filtering by status, trading pair, and pagination.
167
+ * Pagination parameters are always included with sensible defaults for consistent API behavior.
168
+ *
169
+ * @param params - Query parameters for filtering orders
170
+ * @param params.status - Filter by order status (e.g., "PENDING", "FILLED") (optional)
171
+ * @param params.trading_pair - Filter by trading pair (e.g., "USDCo/MTK") (optional)
172
+ * @param params.page - Page number for pagination (defaults to 1, must be > 0)
173
+ * @param params.page_size - Number of orders per page (defaults to 10, max 100, must be > 0)
174
+ * @returns Promise resolving to GetPaginatedOrdersResponse with orders and pagination info
175
+ * @throws {APIError} When API communication fails
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * // Get pending orders for a specific trading pair with custom pagination
180
+ * const orders = await tradingAPI.getPaginatedOrders({
181
+ * status: "PENDING",
182
+ * trading_pair: "USDCo/MTK",
183
+ * page: 1,
184
+ * page_size: 20
185
+ * });
186
+ * console.log(`Found ${orders.total} orders, showing page ${orders.page}`);
187
+ *
188
+ * // Get all orders with default pagination (page=1, page_size=10)
189
+ * const allOrders = await tradingAPI.getPaginatedOrders();
190
+ * ```
191
+ */
192
+ getPaginatedOrders(params?: GetPaginatedOrdersParams): Promise<GetPaginatedOrdersResponse>;
193
+ /**
194
+ * Gets a single order by its ID.
195
+ *
196
+ * Retrieves detailed information about a specific order using its unique identifier.
197
+ * This endpoint provides complete order details including status, quantities, and timestamps.
198
+ *
199
+ * @param orderId - The unique identifier of the order to retrieve
200
+ * @returns Promise resolving to GetOrderResponse with order details
201
+ * @throws {APIError} When API communication fails or order is not found
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * // Get order details by ID
206
+ * const orderDetails = await tradingAPI.getOrder("order_123");
207
+ * console.log(`Order status: ${orderDetails.order.status}`);
208
+ * console.log(`Remaining quantity: ${orderDetails.order.remaining_quantity}`);
209
+ * ```
210
+ */
211
+ getOrder(orderId: string): Promise<GetOrderResponse>;
212
+ }
213
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/trading/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,0BAA0B,EAC1B,SAAS,EAET,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,cAAe,SAAQ,OAAQ,YAAW,UAAU;IAC/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACG,eAAe,CACnB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,WAAW,CAAC,EAAE,WAAW,CAAC;KAC3B,GACA,OAAO,CAAC,mBAAmB,CAAC;IA4B/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACG,gBAAgB,CACpB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,WAAW,CAAC,EAAE,WAAW,CAAC;KAC3B,GACA,OAAO,CAAC,mBAAmB,CAAC;IAkB/B;;;;;;;;;;;;;;;OAeG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAW1D,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,GACA,OAAO,CAAC,oBAAoB,CAAC;IAuBhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,kBAAkB,CAAC,MAAM,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IA2BhG;;;;;;;;;;;;;;;;;OAiBG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAK3D"}
@@ -0,0 +1,285 @@
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
+ * "ETH-USD",
18
+ * "BUY",
19
+ * "1.5",
20
+ * "2000.50"
21
+ * );
22
+ *
23
+ * // Get open orders
24
+ * const openOrders = await tradingAPI.getOpenOrders({ market: "ETH-USD" });
25
+ * ```
26
+ */
27
+ import { PlaceLimitOrderSchema, validate } from "@0xmonaco/types";
28
+ import { BaseAPI } from "../base";
29
+ export class TradingAPIImpl extends BaseAPI {
30
+ /**
31
+ * Places a limit order on the order book.
32
+ *
33
+ * Limit orders are executed only when the market price reaches or improves upon
34
+ * the specified price. They provide price protection but may not execute immediately.
35
+ *
36
+ * @param tradingPairId - The trading pair UUID
37
+ * @param side - The order side ("BUY" or "SELL")
38
+ * @param quantity - The order quantity as string
39
+ * @param price - The limit price as string
40
+ * @param options - Optional parameters for the limit order
41
+ * @param options.tradingMode - Trading mode (e.g., "SPOT")
42
+ * @param options.useMasterBalance - Whether to use master balance for sub-accounts
43
+ * @param options.expirationDate - Optional expiration date for GTC orders (ISO 8601 format)
44
+ * @param options.timeInForce - Time in force ("GTC", "IOC", or "FOK")
45
+ * @returns Promise resolving to CreateOrderResponse with order details
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Regular limit order
50
+ * const order = await tradingAPI.placeLimitOrder(
51
+ * "123e4567-e89b-12d3-a456-426614174000",
52
+ * "BUY",
53
+ * "0.5",
54
+ * "35000.00",
55
+ * { tradingMode: "SPOT" }
56
+ * );
57
+ *
58
+ * // GTC order with custom expiration
59
+ * const gtcOrder = await tradingAPI.placeLimitOrder(
60
+ * "123e4567-e89b-12d3-a456-426614174000",
61
+ * "BUY",
62
+ * "0.5",
63
+ * "35000.00",
64
+ * {
65
+ * tradingMode: "SPOT",
66
+ * expirationDate: "2024-12-31T23:59:59Z" // GTC until this date
67
+ * }
68
+ * );
69
+ *
70
+ * // IOC order (execute immediately or cancel)
71
+ * const iocOrder = await tradingAPI.placeLimitOrder(
72
+ * "123e4567-e89b-12d3-a456-426614174000",
73
+ * "BUY",
74
+ * "0.5",
75
+ * "35000.00",
76
+ * { timeInForce: "IOC" }
77
+ * );
78
+ * ```
79
+ */
80
+ async placeLimitOrder(tradingPairId, side, quantity, price, options) {
81
+ // Validate inputs before making API call
82
+ validate(PlaceLimitOrderSchema, {
83
+ tradingPairId,
84
+ side,
85
+ quantity,
86
+ price,
87
+ options,
88
+ });
89
+ const requestBody = {
90
+ trading_pair_id: tradingPairId,
91
+ order_type: "LIMIT",
92
+ side,
93
+ price,
94
+ quantity,
95
+ trading_mode: options?.tradingMode || "SPOT",
96
+ use_master_balance: options?.useMasterBalance,
97
+ expiration_date: options?.expirationDate,
98
+ time_in_force: options?.timeInForce,
99
+ };
100
+ return await this.makeAuthenticatedRequest("/api/v1/orders", {
101
+ method: "POST",
102
+ body: JSON.stringify(requestBody),
103
+ });
104
+ }
105
+ /**
106
+ * Places a market order for immediate execution.
107
+ *
108
+ * Market orders execute immediately at the current market price. They provide
109
+ * immediate execution but may experience slippage.
110
+ *
111
+ * @param tradingPairId - The trading pair UUID
112
+ * @param side - The order side ("BUY" or "SELL")
113
+ * @param quantity - The order quantity as string
114
+ * @param options - Optional parameters for the market order
115
+ * @param options.tradingMode - Trading mode (e.g., "SPOT")
116
+ * @param options.slippageTolerance - Slippage tolerance as decimal (e.g., 0.01 for 1%, 0 for best price only, undefined for unlimited slippage)
117
+ * @param options.timeInForce - Time in force ("GTC", "IOC", or "FOK")
118
+ * @returns Promise resolving to CreateOrderResponse with order details
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // Market order with 1% slippage tolerance
123
+ * const order1 = await tradingAPI.placeMarketOrder(
124
+ * "123e4567-e89b-12d3-a456-426614174000",
125
+ * "SELL",
126
+ * "0.5",
127
+ * { tradingMode: "SPOT", slippageTolerance: 0.01 } // 1% slippage
128
+ * );
129
+ *
130
+ * // Market order with zero slippage (only execute at best price)
131
+ * const order2 = await tradingAPI.placeMarketOrder(
132
+ * "123e4567-e89b-12d3-a456-426614174000",
133
+ * "BUY",
134
+ * "1.0",
135
+ * { slippageTolerance: 0 } // Only execute at best ask price
136
+ * );
137
+ *
138
+ * // Market order with unlimited slippage
139
+ * const order3 = await tradingAPI.placeMarketOrder(
140
+ * "123e4567-e89b-12d3-a456-426614174000",
141
+ * "BUY",
142
+ * "1.0"
143
+ * // No slippageTolerance specified = unlimited slippage
144
+ * );
145
+ *
146
+ * // FOK order (fill completely or cancel)
147
+ * const fokOrder = await tradingAPI.placeMarketOrder(
148
+ * "123e4567-e89b-12d3-a456-426614174000",
149
+ * "BUY",
150
+ * "1.0",
151
+ * { timeInForce: "FOK" }
152
+ * );
153
+ * ```
154
+ */
155
+ async placeMarketOrder(tradingPairId, side, quantity, options) {
156
+ const requestBody = {
157
+ trading_pair_id: tradingPairId,
158
+ order_type: "MARKET",
159
+ side,
160
+ slippage_tolerance_bps: options?.slippageTolerance !== undefined ? Math.round(options.slippageTolerance * 10000) : undefined,
161
+ price: null, // Market orders don't need price
162
+ quantity,
163
+ trading_mode: options?.tradingMode || "SPOT",
164
+ time_in_force: options?.timeInForce,
165
+ };
166
+ return await this.makeAuthenticatedRequest("/api/v1/orders", {
167
+ method: "POST",
168
+ body: JSON.stringify(requestBody),
169
+ });
170
+ }
171
+ /**
172
+ * Cancels an existing order.
173
+ *
174
+ * Cancels an open order by its ID. The order must be in an open state to be cancelled.
175
+ * Cancelled orders cannot be recovered.
176
+ *
177
+ * @param orderId - The ID of the order to cancel
178
+ * @returns Promise resolving to CancelOrderResponse with cancellation details
179
+ * @throws {APIError} When API communication fails
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * const result = await tradingAPI.cancelOrder("order_123");
184
+ * console.log(`Order cancelled: ${result.status}`);
185
+ * ```
186
+ */
187
+ async cancelOrder(orderId) {
188
+ const requestBody = {
189
+ order_id: orderId,
190
+ };
191
+ return await this.makeAuthenticatedRequest("/api/v1/orders/cancel", {
192
+ method: "POST",
193
+ body: JSON.stringify(requestBody),
194
+ });
195
+ }
196
+ async replaceOrder(orderId, newOrder) {
197
+ const requestBody = {
198
+ use_master_balance: newOrder.useMasterBalance ?? false,
199
+ };
200
+ if (newOrder.price !== undefined) {
201
+ requestBody.price = newOrder.price;
202
+ }
203
+ if (newOrder.quantity !== undefined) {
204
+ requestBody.quantity = newOrder.quantity;
205
+ }
206
+ return await this.makeAuthenticatedRequest(`/api/v1/orders/${orderId}`, {
207
+ method: "PUT",
208
+ body: JSON.stringify(requestBody),
209
+ });
210
+ }
211
+ /**
212
+ * Gets paginated orders based on query parameters with automatic pagination.
213
+ *
214
+ * Retrieves orders with optional filtering by status, trading pair, and pagination.
215
+ * Pagination parameters are always included with sensible defaults for consistent API behavior.
216
+ *
217
+ * @param params - Query parameters for filtering orders
218
+ * @param params.status - Filter by order status (e.g., "PENDING", "FILLED") (optional)
219
+ * @param params.trading_pair - Filter by trading pair (e.g., "USDCo/MTK") (optional)
220
+ * @param params.page - Page number for pagination (defaults to 1, must be > 0)
221
+ * @param params.page_size - Number of orders per page (defaults to 10, max 100, must be > 0)
222
+ * @returns Promise resolving to GetPaginatedOrdersResponse with orders and pagination info
223
+ * @throws {APIError} When API communication fails
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * // Get pending orders for a specific trading pair with custom pagination
228
+ * const orders = await tradingAPI.getPaginatedOrders({
229
+ * status: "PENDING",
230
+ * trading_pair: "USDCo/MTK",
231
+ * page: 1,
232
+ * page_size: 20
233
+ * });
234
+ * console.log(`Found ${orders.total} orders, showing page ${orders.page}`);
235
+ *
236
+ * // Get all orders with default pagination (page=1, page_size=10)
237
+ * const allOrders = await tradingAPI.getPaginatedOrders();
238
+ * ```
239
+ */
240
+ async getPaginatedOrders(params) {
241
+ // Set pagination defaults with destructuring and validation
242
+ const { page = 1, page_size = 10, status, trading_pair } = params || {};
243
+ const validPage = page > 0 ? page : 1;
244
+ const validPageSize = page_size > 0 ? page_size : 10;
245
+ const pageSize = Math.min(validPageSize, 100);
246
+ const searchParams = new URLSearchParams();
247
+ // Always include pagination parameters for consistent API behavior
248
+ searchParams.append("page", validPage.toString());
249
+ searchParams.append("page_size", pageSize.toString());
250
+ if (status) {
251
+ searchParams.append("status", status);
252
+ }
253
+ if (trading_pair) {
254
+ searchParams.append("trading_pair", trading_pair);
255
+ }
256
+ const endpoint = `/api/v1/orders?${searchParams.toString()}`;
257
+ return await this.makeAuthenticatedRequest(endpoint, {
258
+ method: "GET",
259
+ });
260
+ }
261
+ /**
262
+ * Gets a single order by its ID.
263
+ *
264
+ * Retrieves detailed information about a specific order using its unique identifier.
265
+ * This endpoint provides complete order details including status, quantities, and timestamps.
266
+ *
267
+ * @param orderId - The unique identifier of the order to retrieve
268
+ * @returns Promise resolving to GetOrderResponse with order details
269
+ * @throws {APIError} When API communication fails or order is not found
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * // Get order details by ID
274
+ * const orderDetails = await tradingAPI.getOrder("order_123");
275
+ * console.log(`Order status: ${orderDetails.order.status}`);
276
+ * console.log(`Remaining quantity: ${orderDetails.order.remaining_quantity}`);
277
+ * ```
278
+ */
279
+ async getOrder(orderId) {
280
+ return await this.makeAuthenticatedRequest(`/api/v1/orders/${orderId}`, {
281
+ method: "GET",
282
+ });
283
+ }
284
+ }
285
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/trading/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAeH,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,OAAO,cAAe,SAAQ,OAAO;IACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACH,KAAK,CAAC,eAAe,CACnB,aAAqB,EACrB,IAAe,EACf,QAAgB,EAChB,KAAa,EACb,OAKC;QAED,yCAAyC;QACzC,QAAQ,CAAC,qBAAqB,EAAE;YAC9B,aAAa;YACb,IAAI;YACJ,QAAQ;YACR,KAAK;YACL,OAAO;SACR,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG;YAClB,eAAe,EAAE,aAAa;YAC9B,UAAU,EAAE,OAAoB;YAChC,IAAI;YACJ,KAAK;YACL,QAAQ;YACR,YAAY,EAAE,OAAO,EAAE,WAAW,IAAI,MAAM;YAC5C,kBAAkB,EAAE,OAAO,EAAE,gBAAgB;YAC7C,eAAe,EAAE,OAAO,EAAE,cAAc;YACxC,aAAa,EAAE,OAAO,EAAE,WAAW;SACpC,CAAC;QAEF,OAAO,MAAM,IAAI,C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M,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,YAAY,EAAE,CAAC;YACjB,YAAY,CAAC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;QACpD,CAAC;QAED,MAAM,QAAQ,GAAG,kBAAkB,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC;QAE7D,OAAO,MAAM,IAAI,CAAC,wBAAwB,CAA6B,QAAQ,EAAE;YAC/E,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,OAAO,MAAM,IAAI,CAAC,wBAAwB,CAAmB,kBAAkB,OAAO,EAAE,EAAE;YACxF,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Trading API Module
3
+ */
4
+ export { TradingAPIImpl } from "./api";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/trading/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Trading API Module
3
+ */
4
+ export { TradingAPIImpl } from "./api";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/trading/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC"}