@0xmonaco/core 0.8.14 → 0.8.16
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/README.md +42 -48
- package/dist/api/applications/api.js +4 -4
- package/dist/api/auth/api.d.ts +1 -1
- package/dist/api/auth/api.js +10 -10
- package/dist/api/base.d.ts +2 -2
- package/dist/api/base.js +2 -2
- package/dist/api/delegated-agents/api.js +12 -12
- package/dist/api/faucet/api.d.ts +1 -1
- package/dist/api/faucet/api.js +1 -1
- package/dist/api/fees/api.d.ts +13 -13
- package/dist/api/fees/api.js +18 -18
- package/dist/api/margin-accounts/api.js +23 -23
- package/dist/api/market/api.js +16 -16
- package/dist/api/orderbook/api.js +13 -13
- package/dist/api/perp/routes.d.ts +57 -53
- package/dist/api/perp/routes.js +1 -0
- package/dist/api/positions/api.js +19 -19
- package/dist/api/profile/api.d.ts +23 -23
- package/dist/api/profile/api.js +46 -46
- package/dist/api/sub-accounts/api.d.ts +2 -2
- package/dist/api/sub-accounts/api.js +2 -2
- package/dist/api/trades/api.d.ts +11 -11
- package/dist/api/trades/api.js +10 -10
- package/dist/api/trading/api.d.ts +6 -6
- package/dist/api/trading/api.js +69 -69
- package/dist/api/vault/api.js +4 -4
- package/dist/api/whitelist/api.d.ts +2 -2
- package/dist/api/whitelist/api.js +2 -2
- package/dist/api/withdrawals/api.d.ts +3 -2
- package/dist/api/withdrawals/api.js +7 -2
- package/dist/coverage.d.ts +1 -0
- package/dist/coverage.js +1 -0
- package/dist/sdk.js +3 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
# Monaco Core SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This package is currently in **early development**.
|
|
6
|
-
|
|
7
|
-
**Breaking changes are expected** and may occur without notice. This version is intended for:
|
|
8
|
-
- Early adopters and testing
|
|
9
|
-
- Development and experimentation
|
|
10
|
-
- Feedback collection
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
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.
|
|
3
|
+
Core SDK implementation for interacting with Monaco Protocol. This SDK provides a comprehensive implementation with Authentication, Vault, Trading, Market, and Profile APIs, featuring noncustodial session-key authentication and secure API Gateway integration.
|
|
15
4
|
|
|
16
5
|
## Installation
|
|
17
6
|
|
|
@@ -27,10 +16,10 @@ npm install viem@^2.31.7
|
|
|
27
16
|
## Features
|
|
28
17
|
|
|
29
18
|
### 🔐 **Authentication**
|
|
30
|
-
- **
|
|
31
|
-
- **Wallet Signature Verification**: EIP-712 signature
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
19
|
+
- **Session-key Authentication**: Noncustodial ed25519 session keys — the server never holds a credential that can impersonate you
|
|
20
|
+
- **Wallet Signature Verification**: EIP-712 signature authorizes each session key
|
|
21
|
+
- **Session Refresh**: Extend session expiry without re-prompting the wallet
|
|
22
|
+
- **Server-key Auth**: Optional `sk_...` application key for backend/service access
|
|
34
23
|
|
|
35
24
|
### 🏦 **Vault Operations**
|
|
36
25
|
- **Token Approvals**: ERC20 token approvals for vault usage
|
|
@@ -55,8 +44,8 @@ npm install viem@^2.31.7
|
|
|
55
44
|
- **Balance Tracking**: Cross-platform balance monitoring
|
|
56
45
|
|
|
57
46
|
### 🔐 **Security Features**
|
|
58
|
-
- **
|
|
59
|
-
- **EIP-712 Signatures**: Type-safe, structured data signing for
|
|
47
|
+
- **Session-key Signing**: Every authenticated request is signed with a locally held ed25519 key
|
|
48
|
+
- **EIP-712 Signatures**: Type-safe, structured data signing for session authorization
|
|
60
49
|
- **API Gateway Integration**: Secure communication with Monaco backend
|
|
61
50
|
- **TLS Encryption**: Secure API communications
|
|
62
51
|
|
|
@@ -114,9 +103,9 @@ async function authExample() {
|
|
|
114
103
|
// Login with client ID and auto-connect authenticated WebSocket channels (Orders)
|
|
115
104
|
const authState = await monaco.login("your-client-id", { connectWebSocket: true });
|
|
116
105
|
console.log("Authenticated:", authState.user);
|
|
117
|
-
console.log("
|
|
118
|
-
|
|
119
|
-
|
|
106
|
+
console.log("Session:", {
|
|
107
|
+
sessionPublicKey: authState.sessionPublicKey,
|
|
108
|
+
expiresAt: authState.expiresAt,
|
|
120
109
|
});
|
|
121
110
|
|
|
122
111
|
// Authenticated WebSocket channels are now connected - start receiving real-time updates
|
|
@@ -128,11 +117,11 @@ async function authExample() {
|
|
|
128
117
|
// Check authentication status
|
|
129
118
|
console.log("Is authenticated:", monaco.isAuthenticated());
|
|
130
119
|
|
|
131
|
-
// Logout (revokes the
|
|
120
|
+
// Logout (revokes the session and disconnects authenticated WebSockets)
|
|
132
121
|
await monaco.logout();
|
|
133
122
|
|
|
134
|
-
// Or manually revoke the
|
|
135
|
-
await monaco.auth.
|
|
123
|
+
// Or manually revoke the session
|
|
124
|
+
await monaco.auth.revokeSession();
|
|
136
125
|
}
|
|
137
126
|
|
|
138
127
|
// Market Data
|
|
@@ -250,9 +239,9 @@ interface SDKConfig {
|
|
|
250
239
|
}
|
|
251
240
|
```
|
|
252
241
|
|
|
253
|
-
### Authentication &
|
|
242
|
+
### Authentication & Session Management
|
|
254
243
|
|
|
255
|
-
The SDK uses
|
|
244
|
+
The SDK uses a noncustodial session-key scheme. On login it generates an ed25519 keypair locally, has your wallet authorize it via an EIP-712 signature, and signs every subsequent request with the private key — the server never holds a credential that can impersonate you.
|
|
256
245
|
|
|
257
246
|
```typescript
|
|
258
247
|
// After login, you receive an AuthState object
|
|
@@ -260,35 +249,40 @@ const authState = await sdk.login(clientId);
|
|
|
260
249
|
|
|
261
250
|
// AuthState structure:
|
|
262
251
|
interface AuthState {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
expiresAt: number;
|
|
266
|
-
user: User;
|
|
252
|
+
sessionPublicKey: string; // ed25519 public key registered with the server
|
|
253
|
+
sessionPrivateKey: string; // ed25519 private key used to sign requests (the long-lived credential)
|
|
254
|
+
expiresAt: number; // Unix timestamp (seconds) when the session expires
|
|
255
|
+
user: User; // User information
|
|
267
256
|
}
|
|
268
257
|
```
|
|
269
258
|
|
|
259
|
+
> The private key is the long-lived credential. Persist it (e.g. `localStorage`, same risk profile as a JWT) to survive page reloads without re-prompting the wallet. When the session expires, call `refreshAuth()` or re-`login()`.
|
|
260
|
+
|
|
270
261
|
```typescript
|
|
271
|
-
// Revoke the current session
|
|
272
|
-
await sdk.auth.
|
|
262
|
+
// Revoke the current session
|
|
263
|
+
await sdk.auth.revokeSession();
|
|
273
264
|
|
|
274
265
|
// 💡 TIP: Use the built-in logout method
|
|
275
|
-
await sdk.logout(); // Automatically calls
|
|
266
|
+
await sdk.logout(); // Automatically calls revokeSession internally
|
|
276
267
|
```
|
|
277
268
|
|
|
278
|
-
**
|
|
279
|
-
- `login(clientId, options?)` -
|
|
269
|
+
**Session Management Methods:**
|
|
270
|
+
- `login(clientId, options?)` - Authorize a session key and authenticate
|
|
280
271
|
- `clientId`: Your application's client ID
|
|
281
272
|
- `options.connectWebSocket`: (optional) Auto-connect WebSocket after login (default: `false`)
|
|
282
|
-
- Returns `AuthState` with
|
|
283
|
-
- `logout()` - Revoke
|
|
284
|
-
- Calls `auth.
|
|
273
|
+
- Returns `AuthState` with the session keypair, expiration, and user info
|
|
274
|
+
- `logout()` - Revoke the session, disconnect WebSocket, and clear state
|
|
275
|
+
- Calls `auth.revokeSession()` internally
|
|
285
276
|
- Disconnects authenticated WebSocket channels
|
|
286
277
|
- Clears local auth state
|
|
287
|
-
- `refreshAuth()` -
|
|
288
|
-
- `isAuthenticated()` - Check if
|
|
289
|
-
- `getAuthState()` - Get current auth state with
|
|
278
|
+
- `refreshAuth()` - Extend the current session's expiry
|
|
279
|
+
- `isAuthenticated()` - Check if a session is active
|
|
280
|
+
- `getAuthState()` - Get current auth state with the session keypair
|
|
290
281
|
- `setAuthState(authState)` - Set auth state directly (useful for sharing across SDK instances)
|
|
291
282
|
|
|
283
|
+
**Server-key Auth (backend/service access):**
|
|
284
|
+
- `setServerKey(serverKey)` - Authenticate with an application secret key (`sk_...`) instead of, or alongside, a session. Useful for server-side integrations.
|
|
285
|
+
|
|
292
286
|
### Vault API
|
|
293
287
|
|
|
294
288
|
The vault API provides secure token management operations:
|
|
@@ -391,7 +385,7 @@ monaco.websocket.orderbook.subscribeToOrderbookEvents("BTC/USDC", "SPOT", (event
|
|
|
391
385
|
|
|
392
386
|
#### Authenticated WebSockets (Orders)
|
|
393
387
|
|
|
394
|
-
Requires
|
|
388
|
+
Requires an authenticated session for personal order updates. You can either auto-connect during login or connect manually:
|
|
395
389
|
|
|
396
390
|
**Option 1: Auto-connect (recommended for authenticated channels)**
|
|
397
391
|
```typescript
|
|
@@ -515,15 +509,15 @@ bun run lint --filter @0xmonaco/core
|
|
|
515
509
|
|
|
516
510
|
## Security Features
|
|
517
511
|
|
|
518
|
-
###
|
|
519
|
-
- **
|
|
520
|
-
- **EIP-712 login**: Wallet signature
|
|
521
|
-
- **
|
|
522
|
-
- **
|
|
512
|
+
### Session-key Authentication
|
|
513
|
+
- **Noncustodial**: ed25519 session keys are generated locally; the server never holds a credential that can impersonate you
|
|
514
|
+
- **EIP-712 login**: Wallet signature authorizes each session key
|
|
515
|
+
- **Session refresh**: Extend expiry without re-prompting the wallet
|
|
516
|
+
- **Server-key auth**: Optional `sk_...` application key for backend/service access
|
|
523
517
|
|
|
524
518
|
### API Gateway Integration
|
|
525
519
|
- **Secure communication**: TLS encryption for all API calls
|
|
526
|
-
- **
|
|
520
|
+
- **Request signing**: Backend verifies the session signature on every authenticated request
|
|
527
521
|
- **Rate limiting**: Protection against abuse
|
|
528
522
|
- **Audit logging**: Complete transaction history
|
|
529
523
|
|
|
@@ -48,10 +48,10 @@ export class ApplicationsAPIImpl extends BaseAPI {
|
|
|
48
48
|
return {
|
|
49
49
|
id: data.id,
|
|
50
50
|
name: data.name,
|
|
51
|
-
allowedOrigins: data.
|
|
52
|
-
webhookUrl: data.
|
|
53
|
-
vaultContractAddress: data.
|
|
54
|
-
clientId: data.
|
|
51
|
+
allowedOrigins: data.allowedOrigins,
|
|
52
|
+
webhookUrl: data.webhookUrl,
|
|
53
|
+
vaultContractAddress: data.vaultContractAddress,
|
|
54
|
+
clientId: data.clientId,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
/**
|
package/dist/api/auth/api.d.ts
CHANGED
|
@@ -142,7 +142,7 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
|
|
|
142
142
|
* Extends the current session's expiry.
|
|
143
143
|
*
|
|
144
144
|
* The request is signed with the active session key (set via
|
|
145
|
-
* {@link setSessionKeypair}); the server bumps the session's `
|
|
145
|
+
* {@link setSessionKeypair}); the server bumps the session's `expiresAt`.
|
|
146
146
|
* No new credential is issued — the same keypair keeps working.
|
|
147
147
|
*
|
|
148
148
|
* @returns Promise resolving to the new expiry
|
package/dist/api/auth/api.js
CHANGED
|
@@ -157,15 +157,15 @@ export class AuthAPIImpl extends BaseAPI {
|
|
|
157
157
|
method: "POST",
|
|
158
158
|
body: JSON.stringify({
|
|
159
159
|
address,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
clientId: clientId,
|
|
161
|
+
chainId: this.chain.id,
|
|
162
|
+
sessionPublicKey: sessionPublicKey,
|
|
163
163
|
}),
|
|
164
164
|
});
|
|
165
165
|
return {
|
|
166
166
|
nonce: responseBody.nonce,
|
|
167
167
|
message: responseBody.message,
|
|
168
|
-
expiresAt: responseBody.
|
|
168
|
+
expiresAt: responseBody.expiresAt,
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
@@ -199,15 +199,15 @@ export class AuthAPIImpl extends BaseAPI {
|
|
|
199
199
|
address,
|
|
200
200
|
signature,
|
|
201
201
|
nonce,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
clientId: clientId,
|
|
203
|
+
chainId: this.chain.id,
|
|
204
|
+
sessionPublicKey: session.publicKey,
|
|
205
205
|
}),
|
|
206
206
|
});
|
|
207
207
|
return {
|
|
208
208
|
sessionPublicKey: session.publicKey,
|
|
209
209
|
sessionPrivateKey: session.privateKey,
|
|
210
|
-
expiresAt: responseBody.
|
|
210
|
+
expiresAt: responseBody.expiresAt,
|
|
211
211
|
user: {
|
|
212
212
|
id: responseBody.user.id,
|
|
213
213
|
address: responseBody.user.address,
|
|
@@ -219,7 +219,7 @@ export class AuthAPIImpl extends BaseAPI {
|
|
|
219
219
|
* Extends the current session's expiry.
|
|
220
220
|
*
|
|
221
221
|
* The request is signed with the active session key (set via
|
|
222
|
-
* {@link setSessionKeypair}); the server bumps the session's `
|
|
222
|
+
* {@link setSessionKeypair}); the server bumps the session's `expiresAt`.
|
|
223
223
|
* No new credential is issued — the same keypair keeps working.
|
|
224
224
|
*
|
|
225
225
|
* @returns Promise resolving to the new expiry
|
|
@@ -236,7 +236,7 @@ export class AuthAPIImpl extends BaseAPI {
|
|
|
236
236
|
method: "POST",
|
|
237
237
|
});
|
|
238
238
|
return {
|
|
239
|
-
expiresAt: responseBody.
|
|
239
|
+
expiresAt: responseBody.expiresAt,
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
242
|
/**
|
package/dist/api/base.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ export declare abstract class BaseAPI {
|
|
|
99
99
|
* '/api/v1/orders',
|
|
100
100
|
* {
|
|
101
101
|
* method: 'POST',
|
|
102
|
-
* body: JSON.stringify({
|
|
102
|
+
* body: JSON.stringify({ tradingPair: 'ETH-USD', side: 'BUY' })
|
|
103
103
|
* }
|
|
104
104
|
* );
|
|
105
105
|
* ```
|
|
@@ -155,7 +155,7 @@ export declare abstract class BaseAPI {
|
|
|
155
155
|
* '/api/v1/auth/challenge',
|
|
156
156
|
* {
|
|
157
157
|
* method: 'POST',
|
|
158
|
-
* body: JSON.stringify({ address,
|
|
158
|
+
* body: JSON.stringify({ address, clientId: clientId })
|
|
159
159
|
* }
|
|
160
160
|
* );
|
|
161
161
|
* ```
|
package/dist/api/base.js
CHANGED
|
@@ -241,7 +241,7 @@ export class BaseAPI {
|
|
|
241
241
|
* '/api/v1/orders',
|
|
242
242
|
* {
|
|
243
243
|
* method: 'POST',
|
|
244
|
-
* body: JSON.stringify({
|
|
244
|
+
* body: JSON.stringify({ tradingPair: 'ETH-USD', side: 'BUY' })
|
|
245
245
|
* }
|
|
246
246
|
* );
|
|
247
247
|
* ```
|
|
@@ -350,7 +350,7 @@ export class BaseAPI {
|
|
|
350
350
|
* '/api/v1/auth/challenge',
|
|
351
351
|
* {
|
|
352
352
|
* method: 'POST',
|
|
353
|
-
* body: JSON.stringify({ address,
|
|
353
|
+
* body: JSON.stringify({ address, clientId: clientId })
|
|
354
354
|
* }
|
|
355
355
|
* );
|
|
356
356
|
* ```
|
|
@@ -5,17 +5,17 @@ export class DelegatedAgentsAPIImpl extends BaseAPI {
|
|
|
5
5
|
return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.list(), {
|
|
6
6
|
method: "POST",
|
|
7
7
|
body: JSON.stringify({
|
|
8
|
-
|
|
8
|
+
agentAddress: request.agentAddress,
|
|
9
9
|
name: request.name,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
expiresAt: request.expiresAt,
|
|
11
|
+
allowedActions: request.allowedActions,
|
|
12
|
+
allowedTradingPairIds: request.allowedTradingPairIds,
|
|
13
|
+
allowedMarginAccountIds: request.allowedMarginAccountIds,
|
|
14
|
+
allowedOrderTypes: request.allowedOrderTypes,
|
|
15
|
+
allowedTimeInForce: request.allowedTimeInForce,
|
|
16
|
+
maxLeverage: request.maxLeverage,
|
|
17
|
+
maxOrderNotional: request.maxOrderNotional,
|
|
18
|
+
maxOpenOrders: request.maxOpenOrders,
|
|
19
19
|
}),
|
|
20
20
|
});
|
|
21
21
|
}
|
|
@@ -34,8 +34,8 @@ export class DelegatedAgentsAPIImpl extends BaseAPI {
|
|
|
34
34
|
return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.sessions(), {
|
|
35
35
|
method: "POST",
|
|
36
36
|
body: JSON.stringify({
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
ownerUserId: request.ownerUserId,
|
|
38
|
+
sessionPublicKey: request.sessionPublicKey,
|
|
39
39
|
}),
|
|
40
40
|
});
|
|
41
41
|
}
|
package/dist/api/faucet/api.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
|
-
* const { minted, failed,
|
|
11
|
+
* const { minted, failed, remainingRequests24h } = await sdk.faucet.mint();
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
import type { FaucetAPI, MintTokensResponse } from "@0xmonaco/types";
|
package/dist/api/faucet/api.js
CHANGED
package/dist/api/fees/api.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* // Simulate fees for an order
|
|
16
16
|
* const feeDetails = await feesAPI.simulateFees({
|
|
17
|
-
*
|
|
17
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
18
18
|
* side: "BUY",
|
|
19
19
|
* price: "40000.00",
|
|
20
20
|
* quantity: "0.5"
|
|
@@ -31,41 +31,41 @@ export declare class FeesAPIImpl extends BaseAPI implements FeesAPI {
|
|
|
31
31
|
* application fees, and total amounts the taker must pay or maker will receive.
|
|
32
32
|
*
|
|
33
33
|
* @param params - Parameters for fee simulation
|
|
34
|
-
* @param params.
|
|
34
|
+
* @param params.tradingPairId - The trading pair UUID
|
|
35
35
|
* @param params.side - The order side ("BUY" or "SELL")
|
|
36
36
|
* @param params.price - The price per unit as string
|
|
37
37
|
* @param params.quantity - The quantity to trade as string
|
|
38
|
-
* @param params.
|
|
39
|
-
* @param params.
|
|
38
|
+
* @param params.orderType - Order type: "LIMIT" (default) or "MARKET"
|
|
39
|
+
* @param params.slippageToleranceBps - Slippage tolerance in bps (0–1000, MARKET only, default 500)
|
|
40
40
|
* @returns Promise resolving to SimulateFeeResponse with fee breakdown
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* ```typescript
|
|
44
44
|
* // Simulate fees for a buy order
|
|
45
45
|
* const buyFees = await feesAPI.simulateFees({
|
|
46
|
-
*
|
|
46
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
47
47
|
* side: "BUY",
|
|
48
48
|
* price: "40000.00",
|
|
49
49
|
* quantity: "0.5"
|
|
50
50
|
* });
|
|
51
51
|
*
|
|
52
52
|
* console.log(`Notional value: ${buyFees.notional}`);
|
|
53
|
-
* console.log(`Monaco taker fee: ${buyFees.
|
|
54
|
-
* console.log(`Application taker fee: ${buyFees.
|
|
55
|
-
* console.log(`Total taker fees: ${buyFees.
|
|
56
|
-
* console.log(`Total payment required: ${buyFees.
|
|
57
|
-
* console.log(`Lock amount for BUY: ${buyFees.
|
|
53
|
+
* console.log(`Monaco taker fee: ${buyFees.monacoTakerFee}`);
|
|
54
|
+
* console.log(`Application taker fee: ${buyFees.applicationTakerFee}`);
|
|
55
|
+
* console.log(`Total taker fees: ${buyFees.totalTakerFees}`);
|
|
56
|
+
* console.log(`Total payment required: ${buyFees.takerTotalPayment}`);
|
|
57
|
+
* console.log(`Lock amount for BUY: ${buyFees.buyOrderLockAmount}`);
|
|
58
58
|
*
|
|
59
59
|
* // Simulate fees for a sell order
|
|
60
60
|
* const sellFees = await feesAPI.simulateFees({
|
|
61
|
-
*
|
|
61
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
62
62
|
* side: "SELL",
|
|
63
63
|
* price: "40000.00",
|
|
64
64
|
* quantity: "0.5"
|
|
65
65
|
* });
|
|
66
66
|
*
|
|
67
|
-
* console.log(`Maker rebate: ${sellFees.
|
|
68
|
-
* console.log(`Maker total receipt: ${sellFees.
|
|
67
|
+
* console.log(`Maker rebate: ${sellFees.monacoMakerRebate}`);
|
|
68
|
+
* console.log(`Maker total receipt: ${sellFees.makerTotalReceipt}`);
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
simulateFees(params: SimulateFeeParams): Promise<SimulateFeeResponse>;
|
package/dist/api/fees/api.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* // Simulate fees for an order
|
|
16
16
|
* const feeDetails = await feesAPI.simulateFees({
|
|
17
|
-
*
|
|
17
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
18
18
|
* side: "BUY",
|
|
19
19
|
* price: "40000.00",
|
|
20
20
|
* quantity: "0.5"
|
|
@@ -31,56 +31,56 @@ export class FeesAPIImpl extends BaseAPI {
|
|
|
31
31
|
* application fees, and total amounts the taker must pay or maker will receive.
|
|
32
32
|
*
|
|
33
33
|
* @param params - Parameters for fee simulation
|
|
34
|
-
* @param params.
|
|
34
|
+
* @param params.tradingPairId - The trading pair UUID
|
|
35
35
|
* @param params.side - The order side ("BUY" or "SELL")
|
|
36
36
|
* @param params.price - The price per unit as string
|
|
37
37
|
* @param params.quantity - The quantity to trade as string
|
|
38
|
-
* @param params.
|
|
39
|
-
* @param params.
|
|
38
|
+
* @param params.orderType - Order type: "LIMIT" (default) or "MARKET"
|
|
39
|
+
* @param params.slippageToleranceBps - Slippage tolerance in bps (0–1000, MARKET only, default 500)
|
|
40
40
|
* @returns Promise resolving to SimulateFeeResponse with fee breakdown
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* ```typescript
|
|
44
44
|
* // Simulate fees for a buy order
|
|
45
45
|
* const buyFees = await feesAPI.simulateFees({
|
|
46
|
-
*
|
|
46
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
47
47
|
* side: "BUY",
|
|
48
48
|
* price: "40000.00",
|
|
49
49
|
* quantity: "0.5"
|
|
50
50
|
* });
|
|
51
51
|
*
|
|
52
52
|
* console.log(`Notional value: ${buyFees.notional}`);
|
|
53
|
-
* console.log(`Monaco taker fee: ${buyFees.
|
|
54
|
-
* console.log(`Application taker fee: ${buyFees.
|
|
55
|
-
* console.log(`Total taker fees: ${buyFees.
|
|
56
|
-
* console.log(`Total payment required: ${buyFees.
|
|
57
|
-
* console.log(`Lock amount for BUY: ${buyFees.
|
|
53
|
+
* console.log(`Monaco taker fee: ${buyFees.monacoTakerFee}`);
|
|
54
|
+
* console.log(`Application taker fee: ${buyFees.applicationTakerFee}`);
|
|
55
|
+
* console.log(`Total taker fees: ${buyFees.totalTakerFees}`);
|
|
56
|
+
* console.log(`Total payment required: ${buyFees.takerTotalPayment}`);
|
|
57
|
+
* console.log(`Lock amount for BUY: ${buyFees.buyOrderLockAmount}`);
|
|
58
58
|
*
|
|
59
59
|
* // Simulate fees for a sell order
|
|
60
60
|
* const sellFees = await feesAPI.simulateFees({
|
|
61
|
-
*
|
|
61
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
62
62
|
* side: "SELL",
|
|
63
63
|
* price: "40000.00",
|
|
64
64
|
* quantity: "0.5"
|
|
65
65
|
* });
|
|
66
66
|
*
|
|
67
|
-
* console.log(`Maker rebate: ${sellFees.
|
|
68
|
-
* console.log(`Maker total receipt: ${sellFees.
|
|
67
|
+
* console.log(`Maker rebate: ${sellFees.monacoMakerRebate}`);
|
|
68
|
+
* console.log(`Maker total receipt: ${sellFees.makerTotalReceipt}`);
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
async simulateFees(params) {
|
|
72
72
|
// Validate parameters using the validate helper
|
|
73
73
|
const validatedParams = validate(SimulateFeeParamsSchema, params);
|
|
74
74
|
const searchParams = new URLSearchParams();
|
|
75
|
-
searchParams.append("
|
|
75
|
+
searchParams.append("tradingPairId", validatedParams.tradingPairId);
|
|
76
76
|
searchParams.append("side", validatedParams.side);
|
|
77
77
|
searchParams.append("price", validatedParams.price);
|
|
78
78
|
searchParams.append("quantity", validatedParams.quantity);
|
|
79
|
-
if (validatedParams.
|
|
80
|
-
searchParams.append("
|
|
79
|
+
if (validatedParams.orderType !== undefined) {
|
|
80
|
+
searchParams.append("orderType", validatedParams.orderType);
|
|
81
81
|
}
|
|
82
|
-
if (validatedParams.
|
|
83
|
-
searchParams.append("
|
|
82
|
+
if (validatedParams.slippageToleranceBps !== undefined) {
|
|
83
|
+
searchParams.append("slippageToleranceBps", String(validatedParams.slippageToleranceBps));
|
|
84
84
|
}
|
|
85
85
|
const endpoint = `/api/v1/fees/simulate?${searchParams.toString()}`;
|
|
86
86
|
return await this.makeAuthenticatedRequest(endpoint, {
|
|
@@ -9,19 +9,19 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
9
9
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.list(params
|
|
10
10
|
? {
|
|
11
11
|
page: params.page,
|
|
12
|
-
|
|
12
|
+
pageSize: params.pageSize,
|
|
13
13
|
state: params.state,
|
|
14
|
-
|
|
14
|
+
tradingPairId: params.tradingPairId,
|
|
15
15
|
}
|
|
16
16
|
: undefined));
|
|
17
17
|
}
|
|
18
18
|
async getMarginAccountSummary(marginAccountId, params) {
|
|
19
19
|
validate(GetMarginAccountSummarySchema, { marginAccountId, ...params });
|
|
20
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.summary(marginAccountId, {
|
|
20
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.summary(marginAccountId, { tradingPairId: params?.tradingPairId }));
|
|
21
21
|
}
|
|
22
22
|
async getParentMarginAccountSummary(params) {
|
|
23
23
|
validate(GetParentMarginAccountSummarySchema, params);
|
|
24
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.parentSummary({
|
|
24
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.parentSummary({ tradingPairId: params?.tradingPairId }));
|
|
25
25
|
}
|
|
26
26
|
async getAvailableCollateral(params) {
|
|
27
27
|
validate(GetAvailableCollateralSchema, params);
|
|
@@ -34,8 +34,8 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
34
34
|
body: JSON.stringify({
|
|
35
35
|
asset: request.asset,
|
|
36
36
|
amount: request.amount,
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
tradingPairId: request.tradingPairId,
|
|
38
|
+
strategyKey: request.strategyKey,
|
|
39
39
|
}),
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -56,8 +56,8 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
56
56
|
body: JSON.stringify({
|
|
57
57
|
asset: request.asset,
|
|
58
58
|
amount: request.amount,
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
tradingPairId: request.tradingPairId,
|
|
60
|
+
strategyKey: request.strategyKey,
|
|
61
61
|
}),
|
|
62
62
|
});
|
|
63
63
|
}
|
|
@@ -68,8 +68,8 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
68
68
|
body: JSON.stringify({
|
|
69
69
|
asset: request.asset,
|
|
70
70
|
amount: request.amount,
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
tradingPairId: request.tradingPairId,
|
|
72
|
+
strategyKey: request.strategyKey,
|
|
73
73
|
}),
|
|
74
74
|
});
|
|
75
75
|
}
|
|
@@ -96,14 +96,14 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
96
96
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateOrderRisk(marginAccountId), {
|
|
97
97
|
method: "POST",
|
|
98
98
|
body: JSON.stringify({
|
|
99
|
-
|
|
99
|
+
tradingPairId: request.tradingPairId,
|
|
100
100
|
side: request.side,
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
positionSide: request.positionSide,
|
|
102
|
+
orderType: request.orderType,
|
|
103
103
|
price: request.price,
|
|
104
104
|
quantity: request.quantity,
|
|
105
105
|
leverage: request.leverage,
|
|
106
|
-
|
|
106
|
+
reduceOnly: request.reduceOnly,
|
|
107
107
|
}),
|
|
108
108
|
});
|
|
109
109
|
}
|
|
@@ -112,14 +112,14 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
112
112
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateParentMarginOrderRisk(), {
|
|
113
113
|
method: "POST",
|
|
114
114
|
body: JSON.stringify({
|
|
115
|
-
|
|
115
|
+
tradingPairId: request.tradingPairId,
|
|
116
116
|
side: request.side,
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
positionSide: request.positionSide,
|
|
118
|
+
orderType: request.orderType,
|
|
119
119
|
price: request.price,
|
|
120
120
|
quantity: request.quantity,
|
|
121
121
|
leverage: request.leverage,
|
|
122
|
-
|
|
122
|
+
reduceOnly: request.reduceOnly,
|
|
123
123
|
}),
|
|
124
124
|
});
|
|
125
125
|
}
|
|
@@ -128,15 +128,15 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
128
128
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateRiskBucketOrderRisk(), {
|
|
129
129
|
method: "POST",
|
|
130
130
|
body: JSON.stringify({
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
tradingPairId: request.tradingPairId,
|
|
132
|
+
strategyKey: request.strategyKey,
|
|
133
133
|
side: request.side,
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
positionSide: request.positionSide,
|
|
135
|
+
orderType: request.orderType,
|
|
136
136
|
price: request.price,
|
|
137
137
|
quantity: request.quantity,
|
|
138
138
|
leverage: request.leverage,
|
|
139
|
-
|
|
139
|
+
reduceOnly: request.reduceOnly,
|
|
140
140
|
}),
|
|
141
141
|
});
|
|
142
142
|
}
|