@0xmonaco/core 0.1.6 → 0.1.7

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 (44) hide show
  1. package/README.md +180 -108
  2. package/dist/api/index.d.ts +1 -0
  3. package/dist/api/index.d.ts.map +1 -1
  4. package/dist/api/index.js +1 -0
  5. package/dist/api/index.js.map +1 -1
  6. package/dist/api/market/api.d.ts +12 -0
  7. package/dist/api/market/api.d.ts.map +1 -0
  8. package/dist/api/market/api.js +31 -0
  9. package/dist/api/market/api.js.map +1 -0
  10. package/dist/api/market/index.d.ts +3 -0
  11. package/dist/api/market/index.d.ts.map +1 -0
  12. package/dist/api/market/index.js +2 -0
  13. package/dist/api/market/index.js.map +1 -0
  14. package/dist/api/trading/api.d.ts +20 -29
  15. package/dist/api/trading/api.d.ts.map +1 -1
  16. package/dist/api/trading/api.js +39 -42
  17. package/dist/api/trading/api.js.map +1 -1
  18. package/dist/api/vault/api.d.ts +86 -36
  19. package/dist/api/vault/api.d.ts.map +1 -1
  20. package/dist/api/vault/api.js +208 -95
  21. package/dist/api/vault/api.js.map +1 -1
  22. package/dist/api/websocket/base-ws-client.d.ts +59 -0
  23. package/dist/api/websocket/base-ws-client.d.ts.map +1 -0
  24. package/dist/api/websocket/{client.js → base-ws-client.js} +21 -17
  25. package/dist/api/websocket/base-ws-client.js.map +1 -0
  26. package/dist/api/websocket/index.d.ts +3 -2
  27. package/dist/api/websocket/index.d.ts.map +1 -1
  28. package/dist/api/websocket/index.js +3 -2
  29. package/dist/api/websocket/index.js.map +1 -1
  30. package/dist/api/websocket/order-ws-client.d.ts +29 -0
  31. package/dist/api/websocket/order-ws-client.d.ts.map +1 -0
  32. package/dist/api/websocket/order-ws-client.js +128 -0
  33. package/dist/api/websocket/order-ws-client.js.map +1 -0
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/sdk.d.ts +3 -2
  38. package/dist/sdk.d.ts.map +1 -1
  39. package/dist/sdk.js +10 -9
  40. package/dist/sdk.js.map +1 -1
  41. package/package.json +16 -6
  42. package/dist/api/websocket/client.d.ts +0 -57
  43. package/dist/api/websocket/client.d.ts.map +0 -1
  44. package/dist/api/websocket/client.js.map +0 -1
package/README.md CHANGED
@@ -11,7 +11,7 @@ This package is currently in **early development** (v0.1.0).
11
11
 
12
12
  ---
13
13
 
14
- Core SDK implementation for interacting with Monaco Protocol. This SDK provides a comprehensive implementation with Vault and Trading APIs, featuring EIP-712 intent signatures and secure API Gateway integration.
14
+ Core SDK implementation for interacting with Monaco Protocol. This SDK provides a comprehensive implementation with Authentication, Vault, Trading, Market, and Profile APIs, featuring JWT authentication and secure API Gateway integration.
15
15
 
16
16
  ## Installation
17
17
 
@@ -21,25 +21,38 @@ npm install @0xmonaco/core
21
21
 
22
22
  ## Features
23
23
 
24
+ ### 🔐 **Authentication**
25
+ - **JWT-based Authentication**: Secure token-based authentication
26
+ - **Wallet Signature Verification**: EIP-712 signature-based login
27
+ - **Token Refresh**: Automatic token refresh and management
28
+ - **Session Management**: Secure session handling
29
+
24
30
  ### 🏦 **Vault Operations**
25
31
  - **Token Approvals**: ERC20 token approvals for vault usage
26
- - **Deposits**: Secure token deposits with EIP-712 signatures
32
+ - **Deposits**: Secure token deposits with signature validation
27
33
  - **Withdrawals**: Token withdrawals with cryptographic validation
28
34
  - **Balance Queries**: Real-time vault balance tracking
29
- - **Allowance Management**: Efficient approval checking and management
30
35
 
31
36
  ### 📈 **Trading Operations**
32
- - **Order Types**: Limit (with timeInForce: GTC/IOC/FOK), Market, Post-Only orders
33
- - **Order Management**: Place, replace (cancel + new), and cancel orders
34
- - **Position Management**: Close positions with slippage control
35
- - **Order Queries**: Open orders, order history, and individual order details
36
- - **Real-time Updates**: Live order status and execution tracking
37
+ - **Order Types**: Limit and Market orders
38
+ - **Order Management**: Place, replace, and cancel orders
39
+ - **Order Queries**: Paginated orders, order history, and individual order details
40
+ - **Real-time Updates**: WebSocket support for live order updates
41
+
42
+ ### 📊 **Market Data**
43
+ - **Trading Pairs**: Complete trading pair metadata
44
+ - **Market Information**: Fees, tick sizes, order limits
45
+ - **Pair Discovery**: Search and filter available markets
46
+
47
+ ### 👤 **Profile Management**
48
+ - **User Profiles**: Account information and settings
49
+ - **Sub-accounts**: Multi-account management
50
+ - **Balance Tracking**: Cross-platform balance monitoring
37
51
 
38
52
  ### 🔐 **Security Features**
39
- - **EIP-712 Signatures**: Type-safe, structured data signing
40
- - **Intent-Based Authorization**: Every action explicitly authorized
53
+ - **JWT Authentication**: Secure API access with token validation
54
+ - **EIP-712 Signatures**: Type-safe, structured data signing for authentication
41
55
  - **API Gateway Integration**: Secure communication with Monaco backend
42
- - **Nonce Protection**: Replay attack prevention
43
56
  - **TLS Encryption**: Secure API communications
44
57
 
45
58
  ## Test Setup
@@ -110,80 +123,103 @@ const testnetConfig = NETWORK_ENDPOINTS.testnet; // Atlantic-2 testnet
110
123
 
111
124
  ```typescript
112
125
  import { MonacoSDK } from "@0xmonaco/core";
126
+ import { createWalletClient, http } from "viem";
127
+ import { privateKeyToAccount } from "viem/accounts";
128
+
129
+ // Initialize the SDK with wallet client
130
+ const account = privateKeyToAccount("0x...");
131
+ const walletClient = createWalletClient({
132
+ account,
133
+ transport: http()
134
+ });
113
135
 
114
- // Initialize the SDK with private key
115
136
  const monaco = new MonacoSDK({
116
- privateKey: "0x...", // Your private key
137
+ walletClient,
117
138
  network: "mainnet", // or "testnet"
118
139
  });
119
140
 
141
+ // Authentication
142
+ async function authExample() {
143
+ // Login with client ID
144
+ const authState = await monaco.login("your-client-id");
145
+ console.log("Authenticated:", authState.user);
146
+
147
+ // Check authentication status
148
+ console.log("Is authenticated:", monaco.isAuthenticated());
149
+ }
150
+
151
+ // Market Data
152
+ async function marketExample() {
153
+ // Get all trading pairs
154
+ const pairs = await monaco.market.getTradingPairs();
155
+ console.log("Available pairs:", pairs.length);
156
+
157
+ // Get specific trading pair
158
+ const btcPair = await monaco.market.getTradingPairBySymbol("BTC/USDC");
159
+ console.log("BTC pair:", btcPair?.symbol, btcPair?.maker_fee_bps);
160
+ }
161
+
120
162
  // Vault Operations
121
163
  async function vaultExample() {
122
164
  // Check vault balance
123
165
  const balance = await monaco.vault.getBalance("0x..."); // token address
124
166
  console.log("Vault balance:", balance.formatted, balance.symbol);
125
167
 
126
- // Check if approval is needed
127
- const needsApproval = await monaco.vault.needsApproval("0x...", parseEther("100"));
128
- if (needsApproval) {
129
- // Approve vault to spend tokens
130
- const approval = await monaco.vault.approve("0x...", parseEther("1000"));
131
- console.log("Approval transaction:", approval.hash);
132
- }
168
+ // Approve vault to spend tokens
169
+ const approval = await monaco.vault.approve("0x...", parseEther("1000"));
170
+ console.log("Approval transaction:", approval.hash);
133
171
 
134
172
  // Deposit tokens
135
173
  const result = await monaco.vault.deposit("0x...", parseEther("100"));
136
174
  console.log("Deposit transaction:", result.hash);
175
+
176
+ // Withdraw tokens
177
+ const withdrawal = await monaco.vault.withdraw("0x...", parseEther("50"));
178
+ console.log("Withdrawal transaction:", withdrawal.hash);
137
179
  }
138
180
 
139
181
  // Trading Operations
140
182
  async function tradingExample() {
141
183
  // Place a limit order
142
184
  const order = await monaco.trading.placeLimitOrder(
143
- "ETH-USDC", // market
144
- "buy", // side
145
- parseEther("1.0"), // size (1 ETH)
146
- parseUnits("2000", 6) // price (2000 USDC)
185
+ "BTC/USDC", // market
186
+ "BUY", // side
187
+ "0.001", // quantity
188
+ "50000" // price
147
189
  );
148
- console.log("Order placed:", order.orderId);
190
+ console.log("Order placed:", order.order_id);
149
191
 
150
- // Place a market order with slippage protection
192
+ // Place a market order
151
193
  const marketOrder = await monaco.trading.placeMarketOrder(
152
- "ETH-USDC",
153
- "sell",
154
- parseEther("0.5"),
155
- { slippageToleranceBps: 50 } // 0.5% max slippage (50 basis points)
156
- );
157
- console.log("Market order placed:", marketOrder.orderId);
158
-
159
- // Place a limit order with IOC time in force
160
- const iocOrder = await monaco.trading.placeLimitOrder(
161
- "ETH-USDC",
162
- "buy",
163
- parseEther("1.0"),
164
- parseUnits("2000", 6),
165
- { timeInForce: "IOC" } // Immediate-or-Cancel
194
+ "BTC/USDC",
195
+ "SELL",
196
+ "0.001"
166
197
  );
167
- console.log("IOC order placed:", iocOrder.orderId);
168
-
169
- // Get open orders
170
- const openOrders = await monaco.trading.getOpenOrders({ market: "ETH-USDC" });
171
- console.log("Open orders:", openOrders.length);
198
+ console.log("Market order placed:", marketOrder.order_id);
199
+
200
+ // Get paginated orders
201
+ const orders = await monaco.trading.getPaginatedOrders({
202
+ status: "PENDING",
203
+ trading_pair: "BTC/USDC",
204
+ page: 1,
205
+ page_size: 10
206
+ });
207
+ console.log("Orders:", orders.data.length);
172
208
 
173
- // Replace an order (cancel + new)
209
+ // Replace an order
174
210
  const replaceResult = await monaco.trading.replaceOrder("order-id", {
175
- market: "ETH-USDC",
176
- side: "buy",
177
- size: parseEther("2.0"),
178
- price: parseUnits("2100", 6),
179
- type: "limit",
180
- timeInForce: "FOK" // Fill-or-Kill
211
+ quantity: "0.002",
212
+ price: "51000"
181
213
  });
182
- console.log("Order replaced:", replaceResult.orderId);
214
+ console.log("Order replaced:", replaceResult.order_id);
183
215
 
184
216
  // Cancel an order
185
217
  const cancelResult = await monaco.trading.cancelOrder("order-id");
186
218
  console.log("Order cancelled:", cancelResult.status);
219
+
220
+ // Get specific order
221
+ const orderDetails = await monaco.trading.getOrder("order-id");
222
+ console.log("Order details:", orderDetails.order);
187
223
  }
188
224
  ```
189
225
 
@@ -195,12 +231,31 @@ The main SDK class that provides access to all protocol features.
195
231
 
196
232
  ```typescript
197
233
  class MonacoSDK {
234
+ readonly applications: ApplicationsAPI;
235
+ readonly auth: AuthAPI;
198
236
  readonly vault: VaultAPI;
199
237
  readonly trading: TradingAPI;
238
+ readonly market: MarketAPI;
239
+ readonly profile: ProfileAPI;
240
+ readonly websocket: OrderWebSocketClient;
200
241
  readonly walletClient: WalletClient;
201
242
  readonly publicClient: PublicClient;
202
243
 
203
244
  constructor(config: SDKConfig);
245
+
246
+ // Authentication
247
+ login(clientId: string): Promise<AuthState>;
248
+ logout(): Promise<void>;
249
+ refreshAuth(): Promise<AuthState>;
250
+ getAuthState(): AuthState | undefined;
251
+ isAuthenticated(): boolean;
252
+
253
+ // Network utilities
254
+ isConnected(): boolean;
255
+ getAccountAddress(): string;
256
+ getNetwork(): Network;
257
+ getChainId(): number;
258
+ waitForTransaction(hash: string, confirmations?: number, timeout?: number): Promise<TransactionReceipt>;
204
259
  }
205
260
  ```
206
261
 
@@ -208,17 +263,14 @@ class MonacoSDK {
208
263
 
209
264
  ```typescript
210
265
  interface SDKConfig {
211
- /** Private key as hex string (0x-prefixed) */
212
- privateKey?: Hex;
213
-
214
- /** Viem Account for advanced account management */
215
- signer?: PrivateKeyAccount;
216
-
217
- /** Custom Account implementation (overrides privateKey/signer) */
218
- account?: Account;
266
+ /** Wallet client for signing operations */
267
+ walletClient: WalletClient;
219
268
 
220
269
  /** Optional network override (defaults to 'mainnet') */
221
270
  network?: Network;
271
+
272
+ /** Optional transport for the public client */
273
+ transport?: Transport;
222
274
  }
223
275
  ```
224
276
 
@@ -227,58 +279,73 @@ interface SDKConfig {
227
279
  The vault API provides secure token management operations:
228
280
 
229
281
  ```typescript
230
- interface VaultAPI {
231
- // Token approvals
232
- approve(token: string, amount: bigint): Promise<TransactionResult>;
282
+ interface VaultAPI extends BaseAPI {
283
+ // Vault address management
284
+ setVaultAddress(vaultAddress: Address): void;
285
+ getVaultAddress(): Address | undefined;
233
286
 
234
- // Deposit and withdrawal
235
- deposit(token: string, amount: bigint): Promise<TransactionResult>;
236
- withdraw(token: string, amount: bigint): Promise<TransactionResult>;
287
+ // Token operations
288
+ approve(token: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
289
+ deposit(token: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
290
+ withdraw(token: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
237
291
 
238
- // Balance and allowance queries
292
+ // Balance queries
239
293
  getBalance(token: string): Promise<Balance>;
240
- getAllowance(token: string): Promise<bigint>;
241
- needsApproval(token: string, amount: bigint): Promise<boolean>;
242
294
  }
243
295
  ```
244
296
 
245
297
  ### Trading API
246
298
 
247
- The trading API provides comprehensive order management with support for different execution policies:
248
-
249
- #### Order Types and Execution Policies
250
-
251
- - **Limit Orders**: Standard limit orders with optional `timeInForce` parameter
252
- - `GTC` (Good Till Cancelled): Default behavior, order stays active until filled or cancelled
253
- - `IOC` (Immediate or Cancel): Order fills what it can immediately, then cancels the rest
254
- - `FOK` (Fill or Kill): Order must fill completely or not at all
255
-
256
- - **Market Orders**: Immediate execution with optional slippage protection
257
- - **Post-Only Orders**: Limit orders that never execute immediately, only add liquidity
258
-
259
- #### Order Management
260
-
261
- - **Replace Orders**: Cancel existing order and place a new one (atomic operation)
262
- - **Cancel Orders**: Cancel any open order by ID
299
+ The trading API provides comprehensive order management:
263
300
 
264
301
  ```typescript
265
- interface TradingAPI {
302
+ interface TradingAPI extends BaseAPI {
266
303
  // Order placement
267
- placeLimitOrder(market: string, side: OrderSide, size: bigint, price: bigint, options?: { timeInForce?: TimeInForce }): Promise<OrderResponse>;
268
- placeMarketOrder(market: string, side: OrderSide, size: bigint, options?: { slippageToleranceBps?: number }): Promise<OrderResponse>;
269
- placePostOnlyOrder(market: string, side: OrderSide, size: bigint, price: bigint): Promise<OrderResponse>;
304
+ placeLimitOrder(
305
+ market: string,
306
+ side: OrderSide,
307
+ quantity: string,
308
+ price: string,
309
+ options?: {
310
+ tradingMode?: string;
311
+ useMasterBalance?: boolean;
312
+ expirationDate?: string;
313
+ }
314
+ ): Promise<CreateOrderResponse>;
315
+
316
+ placeMarketOrder(
317
+ market: string,
318
+ side: OrderSide,
319
+ quantity: string,
320
+ options?: { tradingMode?: string; }
321
+ ): Promise<CreateOrderResponse>;
270
322
 
271
323
  // Order management
272
- replaceOrder(originalOrderId: string, newOrder: { market: string; side: OrderSide; size: bigint; price?: bigint; type: OrderType; timeInForce?: TimeInForce }): Promise<OrderResponse>;
273
324
  cancelOrder(orderId: string): Promise<CancelOrderResponse>;
274
-
275
- // Position management
276
- closePosition(market: string, options?: { maxSlippage?: number }): Promise<ClosePositionResponse>;
325
+ replaceOrder(
326
+ orderId: string,
327
+ newOrder: {
328
+ price?: string;
329
+ quantity: string;
330
+ useMasterBalance?: boolean;
331
+ }
332
+ ): Promise<ReplaceOrderResponse>;
277
333
 
278
334
  // Order queries
279
- getOrder(orderId: string): Promise<Order>;
280
- getOpenOrders(params?: GetOpenOrdersParams): Promise<Order[]>;
281
- getOrderHistory(params: OrderHistoryParams): Promise<PaginatedOrders>;
335
+ getPaginatedOrders(params?: GetPaginatedOrdersParams): Promise<GetPaginatedOrdersResponse>;
336
+ getOrder(orderId: string): Promise<GetOrderResponse>;
337
+ }
338
+ ```
339
+
340
+ ### Market API
341
+
342
+ The market API provides access to trading pair metadata:
343
+
344
+ ```typescript
345
+ interface MarketAPI extends BaseAPI {
346
+ // Market data
347
+ getTradingPairs(): Promise<TradingPair[]>;
348
+ getTradingPairBySymbol(symbol: string): Promise<TradingPair | undefined>;
282
349
  }
283
350
  ```
284
351
 
@@ -322,11 +389,16 @@ try {
322
389
  packages/core/
323
390
  ├── src/ # Source code
324
391
  │ ├── api/ # API implementations
392
+ │ │ ├── applications/ # Applications API
393
+ │ │ ├── auth/ # Authentication API
394
+ │ │ ├── base.ts # Base API class
395
+ │ │ ├── market/ # Market data API
396
+ │ │ ├── profile/ # Profile management API
397
+ │ │ ├── trading/ # Trading operations API
325
398
  │ │ ├── vault/ # Vault operations API
326
- │ │ │ └── api.ts # Vault API implementation with comprehensive docs
327
- │ │ └── trading/ # Trading operations API
328
- │ └── api.ts # Trading API implementation with comprehensive docs
329
- │ ├── chains.ts # Chain definitions (Sei mainnet/testnet)
399
+ │ │ ├── websocket/ # WebSocket client
400
+ │ │ └── index.ts # API exports
401
+ ├── constants/ # Constants and configurations
330
402
  │ ├── errors.ts # Error classes and codes
331
403
  │ ├── networks.ts # Network endpoint configurations
332
404
  │ ├── sdk.ts # Main SDK implementation
@@ -371,22 +443,22 @@ pnpm lint --filter @0xmonaco/core
371
443
 
372
444
  ## Security Features
373
445
 
374
- ### EIP-712 Intent Signatures
375
- - **Type-safe signing**: Structured data with domain separation
376
- - **Intent-based authorization**: Every action explicitly authorized
377
- - **Nonce protection**: Prevents replay attacks
378
- - **Domain validation**: Ensures signatures are valid for specific contracts
446
+ ### JWT Authentication
447
+ - **Token-based security**: Secure JWT tokens for API access
448
+ - **EIP-712 login**: Wallet signature-based authentication
449
+ - **Automatic refresh**: Seamless token renewal
450
+ - **Session management**: Secure session handling
379
451
 
380
452
  ### API Gateway Integration
381
453
  - **Secure communication**: TLS encryption for all API calls
382
- - **Signature validation**: Backend validates all signed intents
454
+ - **Token validation**: Backend validates all JWT tokens
383
455
  - **Rate limiting**: Protection against abuse
384
456
  - **Audit logging**: Complete transaction history
385
457
 
386
458
  ### On-chain Security
387
459
  - **Smart contract validation**: All operations validated on-chain
460
+ - **Signature verification**: EIP-712 signatures for authentication
388
461
  - **Multi-signature support**: Advanced security for institutional users
389
- - **Emergency stops**: Circuit breakers for critical situations
390
462
 
391
463
  ## Performance Considerations
392
464
 
@@ -7,6 +7,7 @@ export * from "./applications";
7
7
  export * from "./base";
8
8
  export * from "./profile";
9
9
  export * from "./trading";
10
+ export * from "./market";
10
11
  export * from "./vault";
11
12
  export * from "./websocket";
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
package/dist/api/index.js CHANGED
@@ -7,6 +7,7 @@ export * from "./applications";
7
7
  export * from "./base";
8
8
  export * from "./profile";
9
9
  export * from "./trading";
10
+ export * from "./market";
10
11
  export * from "./vault";
11
12
  export * from "./websocket";
12
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { MarketAPI, TradingPair } from "@0xmonaco/types";
2
+ import { BaseAPI } from "../base";
3
+ /**
4
+ * Market API Implementation
5
+ *
6
+ * Provides read-only market metadata endpoints such as trading pair listings.
7
+ */
8
+ export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
9
+ getTradingPairs(): Promise<TradingPair[]>;
10
+ getTradingPairBySymbol(symbol: string): Promise<TradingPair | undefined>;
11
+ }
12
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,SAAS,EACT,WAAW,EAGX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,OAAQ,YAAW,SAAS;IACxD,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAczC,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;CAa9E"}
@@ -0,0 +1,31 @@
1
+ import { BaseAPI } from "../base";
2
+ /**
3
+ * Market API Implementation
4
+ *
5
+ * Provides read-only market metadata endpoints such as trading pair listings.
6
+ */
7
+ export class MarketAPIImpl extends BaseAPI {
8
+ async getTradingPairs() {
9
+ try {
10
+ const response = await this.makePublicRequest("/api/v1/market/pairs");
11
+ return response.data.data;
12
+ }
13
+ catch (error) {
14
+ // For now, return empty array on error - could throw APIError instead
15
+ console.error("Failed to fetch trading pairs:", error);
16
+ return [];
17
+ }
18
+ }
19
+ async getTradingPairBySymbol(symbol) {
20
+ try {
21
+ const response = await this.makePublicRequest(`/api/v1/market/pairs/${encodeURIComponent(symbol)}`);
22
+ return response.data;
23
+ }
24
+ catch (error) {
25
+ // Return undefined if not found or on error
26
+ console.error(`Failed to fetch trading pair ${symbol}:`, error);
27
+ return undefined;
28
+ }
29
+ }
30
+ }
31
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,OAAO;IACzC,KAAK,CAAC,eAAe;QACpB,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAC5C,sBAAsB,CACtB,CAAC;YAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,sEAAsE;YACtE,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;YACvD,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,MAAc;QAC1C,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAC5C,wBAAwB,kBAAkB,CAAC,MAAM,CAAC,EAAE,CACpD,CAAC;YAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,4CAA4C;YAC5C,OAAO,CAAC,KAAK,CAAC,gCAAgC,MAAM,GAAG,EAAE,KAAK,CAAC,CAAC;YAChE,OAAO,SAAS,CAAC;QAClB,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,3 @@
1
+ export { MarketAPIImpl } from "./api";
2
+ export type { MarketAPI } from "@0xmonaco/types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/market/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { MarketAPIImpl } from "./api";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/market/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC"}
@@ -24,15 +24,33 @@
24
24
  * const openOrders = await tradingAPI.getOpenOrders({ market: "ETH-USD" });
25
25
  * ```
26
26
  */
27
- import type { TradingAPI, CreateOrderResponse, CancelOrderResponse, UpdateOrderResponse, ReplaceOrderResponse, GetPaginatedOrdersResponse, GetPaginatedOrdersParams, GetOrderResponse, OrderSide } from "@0xmonaco/types";
27
+ import type { TradingAPI, CreateOrderResponse, CancelOrderResponse, ReplaceOrderResponse, GetPaginatedOrdersResponse, GetPaginatedOrdersParams, GetOrderResponse, OrderSide, MarketAPI } from "@0xmonaco/types";
28
28
  import { BaseAPI } from "../base";
29
29
  export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
30
+ private marketAPI;
30
31
  /**
31
32
  * Creates a new TradingAPI instance.
32
33
  *
34
+ * @param marketAPI - The market API instance for symbol validation
33
35
  * @param apiUrl - The base URL for the Monaco API Gateway
34
36
  */
35
- constructor(apiUrl: string);
37
+ constructor(marketAPI: MarketAPI, apiUrl: string);
38
+ /**
39
+ * Validates if a trading symbol exists and is active.
40
+ *
41
+ * @param symbol - The trading pair symbol to validate (e.g., "BTC-USDC")
42
+ * @returns Promise resolving to true if valid and active, false if invalid/inactive.
43
+ * Returns true on API errors (fail-open approach to avoid blocking trades).
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const isValid = await tradingAPI.validateSymbol("BTC-USDC");
48
+ * if (!isValid) {
49
+ * throw new Error("Invalid trading pair");
50
+ * }
51
+ * ```
52
+ */
53
+ private validateSymbol;
36
54
  /**
37
55
  * Places a limit order on the order book.
38
56
  *
@@ -122,33 +140,6 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
122
140
  * ```
123
141
  */
124
142
  cancelOrder(orderId: string): Promise<CancelOrderResponse>;
125
- /**
126
- * Updates an existing order (price and/or quantity).
127
- *
128
- * Updates an open order by changing its price or quantity.
129
- * This creates a new order and cancels the old one.
130
- *
131
- * @param orderId - The ID of the order to update
132
- * @param updates - Fields to update
133
- * @param updates.price - New price (optional)
134
- * @param updates.quantity - New quantity (optional)
135
- * @returns Promise resolving to UpdateOrderResponse with update details
136
- * @throws {OrderError} When update fails
137
- * @throws {APIError} When API communication fails
138
- *
139
- * @example
140
- * ```typescript
141
- * const result = await tradingAPI.updateOrder("order_123", {
142
- * price: "2100.00",
143
- * quantity: "2.0"
144
- * });
145
- * console.log(`Order updated: ${result.order_id}`);
146
- * ```
147
- */
148
- updateOrder(orderId: string, updates: {
149
- price?: string;
150
- quantity?: string;
151
- }): Promise<UpdateOrderResponse>;
152
143
  replaceOrder(orderId: string, newOrder: {
153
144
  price?: string;
154
145
  quantity: string;
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/trading/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,0BAA0B,EAC1B,wBAAwB,EACxB,gBAAgB,EAChB,SAAS,EAEV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,cAAe,SAAQ,OAAQ,YAAW,UAAU;IAC/D;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IACG,eAAe,CACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GACA,OAAO,CAAC,mBAAmB,CAAC;IA6B/B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,gBAAgB,CACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,E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