@0xmonaco/core 0.8.11 → 0.8.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/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.d.ts +8 -3
- package/dist/api/margin-accounts/api.js +69 -25
- package/dist/api/market/api.d.ts +2 -2
- package/dist/api/market/api.js +19 -17
- package/dist/api/orderbook/api.js +13 -13
- package/dist/api/perp/routes.d.ts +68 -52
- package/dist/api/perp/routes.js +9 -2
- package/dist/api/positions/api.d.ts +2 -1
- package/dist/api/positions/api.js +30 -18
- 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 +10 -10
- package/dist/api/trading/api.js +69 -69
- package/dist/api/vault/api.d.ts +71 -28
- package/dist/api/vault/api.js +139 -39
- package/dist/api/whitelist/api.d.ts +2 -2
- package/dist/api/whitelist/api.js +2 -2
- package/dist/api/withdrawals/api.d.ts +8 -5
- package/dist/api/withdrawals/api.js +13 -5
- package/dist/coverage.d.ts +9 -2
- package/dist/coverage.js +9 -2
- package/dist/sdk.d.ts +2 -2
- package/dist/sdk.js +3 -3
- package/package.json +3 -3
|
@@ -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, {
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import type { GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, GetMarginAccountSummaryParams, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI,
|
|
1
|
+
import type { GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, GetMarginAccountSummaryParams, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, SimulateRiskBucketOrderRiskRequest, TransferCollateralFromParentMarginAccountRequest, TransferCollateralRequest, TransferCollateralResponse, TransferCollateralToParentMarginAccountRequest, TransferCollateralToRiskBucketRequest } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
export declare class MarginAccountsAPIImpl extends BaseAPI implements MarginAccountsAPI {
|
|
4
4
|
listMarginAccounts(params?: ListMarginAccountsParams): Promise<ListMarginAccountsResponse>;
|
|
5
5
|
getMarginAccountSummary(marginAccountId: string, params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
|
|
6
|
+
getParentMarginAccountSummary(params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
|
|
6
7
|
getAvailableCollateral(params?: GetAvailableCollateralParams): Promise<GetAvailableCollateralResponse>;
|
|
7
8
|
transferCollateralToMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
8
|
-
|
|
9
|
+
transferCollateralToParentMarginAccount(request: TransferCollateralToParentMarginAccountRequest): Promise<TransferCollateralResponse>;
|
|
10
|
+
transferCollateralToRiskBucket(request: TransferCollateralToRiskBucketRequest): Promise<TransferCollateralResponse>;
|
|
9
11
|
transferCollateralFromMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
12
|
+
transferCollateralFromParentMarginAccount(request: TransferCollateralFromParentMarginAccountRequest): Promise<TransferCollateralResponse>;
|
|
10
13
|
getMarginAccountMovements(marginAccountId: string, params?: GetMarginAccountMovementsParams): Promise<GetMarginAccountMovementsResponse>;
|
|
14
|
+
getParentMarginAccountMovements(params?: GetMarginAccountMovementsParams): Promise<GetMarginAccountMovementsResponse>;
|
|
11
15
|
simulateOrderRisk(marginAccountId: string, request: SimulateOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
12
|
-
|
|
16
|
+
simulateParentMarginOrderRisk(request: SimulateOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
17
|
+
simulateRiskBucketOrderRisk(request: SimulateRiskBucketOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
13
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema,
|
|
1
|
+
import { GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema, GetParentMarginAccountMovementsSchema, GetParentMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, SimulateParentMarginOrderRiskSchema, SimulateRiskBucketOrderRiskSchema, TransferCollateralFromParentMarginAccountSchema, TransferCollateralSchema, TransferCollateralToParentMarginAccountSchema, TransferCollateralToRiskBucketSchema, validate, } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
import { perpRoutes } from "../perp";
|
|
4
4
|
export class MarginAccountsAPIImpl extends BaseAPI {
|
|
@@ -9,15 +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
|
+
}
|
|
22
|
+
async getParentMarginAccountSummary(params) {
|
|
23
|
+
validate(GetParentMarginAccountSummarySchema, params);
|
|
24
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.parentSummary({ tradingPairId: params?.tradingPairId }));
|
|
21
25
|
}
|
|
22
26
|
async getAvailableCollateral(params) {
|
|
23
27
|
validate(GetAvailableCollateralSchema, params);
|
|
@@ -30,20 +34,30 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
30
34
|
body: JSON.stringify({
|
|
31
35
|
asset: request.asset,
|
|
32
36
|
amount: request.amount,
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
tradingPairId: request.tradingPairId,
|
|
38
|
+
strategyKey: request.strategyKey,
|
|
35
39
|
}),
|
|
36
40
|
});
|
|
37
41
|
}
|
|
38
|
-
async
|
|
39
|
-
validate(
|
|
40
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.
|
|
42
|
+
async transferCollateralToParentMarginAccount(request) {
|
|
43
|
+
validate(TransferCollateralToParentMarginAccountSchema, { request });
|
|
44
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferInParent(), {
|
|
41
45
|
method: "POST",
|
|
42
46
|
body: JSON.stringify({
|
|
43
47
|
asset: request.asset,
|
|
44
48
|
amount: request.amount,
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async transferCollateralToRiskBucket(request) {
|
|
53
|
+
validate(TransferCollateralToRiskBucketSchema, { request });
|
|
54
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferInRiskBucket(), {
|
|
55
|
+
method: "POST",
|
|
56
|
+
body: JSON.stringify({
|
|
57
|
+
asset: request.asset,
|
|
58
|
+
amount: request.amount,
|
|
59
|
+
tradingPairId: request.tradingPairId,
|
|
60
|
+
strategyKey: request.strategyKey,
|
|
47
61
|
}),
|
|
48
62
|
});
|
|
49
63
|
}
|
|
@@ -54,8 +68,18 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
54
68
|
body: JSON.stringify({
|
|
55
69
|
asset: request.asset,
|
|
56
70
|
amount: request.amount,
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
tradingPairId: request.tradingPairId,
|
|
72
|
+
strategyKey: request.strategyKey,
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async transferCollateralFromParentMarginAccount(request) {
|
|
77
|
+
validate(TransferCollateralFromParentMarginAccountSchema, { request });
|
|
78
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferOutParent(), {
|
|
79
|
+
method: "POST",
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
asset: request.asset,
|
|
82
|
+
amount: request.amount,
|
|
59
83
|
}),
|
|
60
84
|
});
|
|
61
85
|
}
|
|
@@ -63,36 +87,56 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
63
87
|
validate(GetMarginAccountMovementsSchema, { marginAccountId, ...params });
|
|
64
88
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.movements(marginAccountId, params));
|
|
65
89
|
}
|
|
90
|
+
async getParentMarginAccountMovements(params) {
|
|
91
|
+
validate(GetParentMarginAccountMovementsSchema, params);
|
|
92
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.parentMovements(params));
|
|
93
|
+
}
|
|
66
94
|
async simulateOrderRisk(marginAccountId, request) {
|
|
67
95
|
validate(SimulateOrderRiskSchema, { marginAccountId, request });
|
|
68
96
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateOrderRisk(marginAccountId), {
|
|
69
97
|
method: "POST",
|
|
70
98
|
body: JSON.stringify({
|
|
71
|
-
|
|
99
|
+
tradingPairId: request.tradingPairId,
|
|
100
|
+
side: request.side,
|
|
101
|
+
positionSide: request.positionSide,
|
|
102
|
+
orderType: request.orderType,
|
|
103
|
+
price: request.price,
|
|
104
|
+
quantity: request.quantity,
|
|
105
|
+
leverage: request.leverage,
|
|
106
|
+
reduceOnly: request.reduceOnly,
|
|
107
|
+
}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async simulateParentMarginOrderRisk(request) {
|
|
111
|
+
validate(SimulateParentMarginOrderRiskSchema, { request });
|
|
112
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateParentMarginOrderRisk(), {
|
|
113
|
+
method: "POST",
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
tradingPairId: request.tradingPairId,
|
|
72
116
|
side: request.side,
|
|
73
|
-
|
|
74
|
-
|
|
117
|
+
positionSide: request.positionSide,
|
|
118
|
+
orderType: request.orderType,
|
|
75
119
|
price: request.price,
|
|
76
120
|
quantity: request.quantity,
|
|
77
121
|
leverage: request.leverage,
|
|
78
|
-
|
|
122
|
+
reduceOnly: request.reduceOnly,
|
|
79
123
|
}),
|
|
80
124
|
});
|
|
81
125
|
}
|
|
82
|
-
async
|
|
83
|
-
validate(
|
|
84
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.
|
|
126
|
+
async simulateRiskBucketOrderRisk(request) {
|
|
127
|
+
validate(SimulateRiskBucketOrderRiskSchema, { request });
|
|
128
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateRiskBucketOrderRisk(), {
|
|
85
129
|
method: "POST",
|
|
86
130
|
body: JSON.stringify({
|
|
87
|
-
|
|
88
|
-
|
|
131
|
+
tradingPairId: request.tradingPairId,
|
|
132
|
+
strategyKey: request.strategyKey,
|
|
89
133
|
side: request.side,
|
|
90
|
-
|
|
91
|
-
|
|
134
|
+
positionSide: request.positionSide,
|
|
135
|
+
orderType: request.orderType,
|
|
92
136
|
price: request.price,
|
|
93
137
|
quantity: request.quantity,
|
|
94
138
|
leverage: request.leverage,
|
|
95
|
-
|
|
139
|
+
reduceOnly: request.reduceOnly,
|
|
96
140
|
}),
|
|
97
141
|
});
|
|
98
142
|
}
|
package/dist/api/market/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Candlestick, FundingState, GetCandlesticksParams, GetScreenerParams, GetScreenerResponse, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarketStats, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingPair } from "@0xmonaco/types";
|
|
1
|
+
import type { Candlestick, FundingState, GetCandlesticksParams, GetScreenerParams, GetScreenerResponse, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarketStats, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingMode, TradingPair } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
/**
|
|
4
4
|
* Market API Implementation
|
|
@@ -8,7 +8,7 @@ import { BaseAPI } from "../base";
|
|
|
8
8
|
export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
9
9
|
getPaginatedTradingPairs(params?: GetTradingPairsParams): Promise<GetTradingPairsResponse>;
|
|
10
10
|
getTradingPair(tradingPairId: string): Promise<TradingPair>;
|
|
11
|
-
getTradingPairBySymbol(symbol: string): Promise<TradingPair | undefined>;
|
|
11
|
+
getTradingPairBySymbol(symbol: string, marketType?: TradingMode): Promise<TradingPair | undefined>;
|
|
12
12
|
getCandlesticks(tradingPairId: string, interval: Interval, params?: GetCandlesticksParams): Promise<Candlestick[]>;
|
|
13
13
|
getMarketMetadata(tradingPairId: string): Promise<MarketMetadata>;
|
|
14
14
|
getPerpMarketConfig(tradingPairId: string): Promise<PerpMarketConfig>;
|
package/dist/api/market/api.js
CHANGED
|
@@ -12,20 +12,20 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
12
12
|
if (params?.page !== undefined) {
|
|
13
13
|
searchParams.append("page", params.page.toString());
|
|
14
14
|
}
|
|
15
|
-
if (params?.
|
|
16
|
-
searchParams.append("
|
|
15
|
+
if (params?.pageSize !== undefined) {
|
|
16
|
+
searchParams.append("pageSize", params.pageSize.toString());
|
|
17
17
|
}
|
|
18
|
-
if (params?.
|
|
19
|
-
searchParams.append("
|
|
18
|
+
if (params?.marketType) {
|
|
19
|
+
searchParams.append("marketType", params.marketType);
|
|
20
20
|
}
|
|
21
|
-
if (params?.
|
|
22
|
-
searchParams.append("
|
|
21
|
+
if (params?.baseToken) {
|
|
22
|
+
searchParams.append("baseToken", params.baseToken);
|
|
23
23
|
}
|
|
24
|
-
if (params?.
|
|
25
|
-
searchParams.append("
|
|
24
|
+
if (params?.quoteToken) {
|
|
25
|
+
searchParams.append("quoteToken", params.quoteToken);
|
|
26
26
|
}
|
|
27
|
-
if (params?.
|
|
28
|
-
searchParams.append("
|
|
27
|
+
if (params?.isActive !== undefined) {
|
|
28
|
+
searchParams.append("isActive", params.isActive.toString());
|
|
29
29
|
}
|
|
30
30
|
if (params?.category) {
|
|
31
31
|
searchParams.append("category", params.category);
|
|
@@ -37,12 +37,14 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
37
37
|
async getTradingPair(tradingPairId) {
|
|
38
38
|
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
39
39
|
const response = await this.makePublicRequest(perpRoutes.market.getTradingPair(tradingPairId));
|
|
40
|
-
return response.
|
|
40
|
+
return response.tradingPair;
|
|
41
41
|
}
|
|
42
|
-
async getTradingPairBySymbol(symbol) {
|
|
43
|
-
// Backend endpoint expects UUID, not symbol, so we fetch all pairs and filter
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
async getTradingPairBySymbol(symbol, marketType) {
|
|
43
|
+
// Backend endpoint expects UUID, not symbol, so we fetch all pairs and filter.
|
|
44
|
+
// An optional marketType narrows the listing so a symbol present in both
|
|
45
|
+
// SPOT and MARGIN resolves unambiguously instead of returning the first match.
|
|
46
|
+
const response = await this.getPaginatedTradingPairs({ pageSize: 100, marketType: marketType });
|
|
47
|
+
return response.tradingPairs.find((pair) => pair.symbol === symbol);
|
|
46
48
|
}
|
|
47
49
|
async getCandlesticks(tradingPairId, interval, params) {
|
|
48
50
|
// Validate inputs using the trading pair ID schema
|
|
@@ -55,10 +57,10 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
55
57
|
});
|
|
56
58
|
const searchParams = new URLSearchParams();
|
|
57
59
|
if (params?.startTime !== undefined) {
|
|
58
|
-
searchParams.append("
|
|
60
|
+
searchParams.append("startTime", params.startTime.toString());
|
|
59
61
|
}
|
|
60
62
|
if (params?.endTime !== undefined) {
|
|
61
|
-
searchParams.append("
|
|
63
|
+
searchParams.append("endTime", params.endTime.toString());
|
|
62
64
|
}
|
|
63
65
|
if (params?.limit !== undefined) {
|
|
64
66
|
searchParams.append("limit", params.limit.toString());
|
|
@@ -5,34 +5,34 @@ export class OrderbookAPIImpl extends BaseAPI {
|
|
|
5
5
|
const params = new URLSearchParams();
|
|
6
6
|
params.set("levels", String(depth));
|
|
7
7
|
if (tradingMode)
|
|
8
|
-
params.set("
|
|
8
|
+
params.set("tradingMode", tradingMode);
|
|
9
9
|
if (magnitude !== undefined)
|
|
10
10
|
params.set("magnitude", String(magnitude));
|
|
11
11
|
if (denomination)
|
|
12
12
|
params.set("denomination", denomination.toLowerCase());
|
|
13
13
|
const response = await this.makePublicRequest(`/api/v1/orderbook/${encodeURIComponent(tradingPairId)}?${params.toString()}`);
|
|
14
14
|
return {
|
|
15
|
-
// `
|
|
16
|
-
tradingPairId: response.
|
|
17
|
-
tradingMode: response.
|
|
15
|
+
// `tradingPairId` is the pair UUID; `symbol` is the display string.
|
|
16
|
+
tradingPairId: response.tradingPairId,
|
|
17
|
+
tradingMode: response.tradingMode,
|
|
18
18
|
bids: response.data.bids.map((level) => ({
|
|
19
19
|
price: level.price,
|
|
20
20
|
quantity: level.quantity,
|
|
21
|
-
orderCount: level.
|
|
21
|
+
orderCount: level.orderCount,
|
|
22
22
|
})),
|
|
23
23
|
asks: response.data.asks.map((level) => ({
|
|
24
24
|
price: level.price,
|
|
25
25
|
quantity: level.quantity,
|
|
26
|
-
orderCount: level.
|
|
26
|
+
orderCount: level.orderCount,
|
|
27
27
|
})),
|
|
28
|
-
bestBid: response.data.
|
|
29
|
-
bestAsk: response.data.
|
|
30
|
-
bidVolume: response.data.
|
|
31
|
-
askVolume: response.data.
|
|
32
|
-
baseDecimals: response.
|
|
33
|
-
quoteDecimals: response.
|
|
28
|
+
bestBid: response.data.bestBid,
|
|
29
|
+
bestAsk: response.data.bestAsk,
|
|
30
|
+
bidVolume: response.data.bidVolume,
|
|
31
|
+
askVolume: response.data.askVolume,
|
|
32
|
+
baseDecimals: response.baseDecimals,
|
|
33
|
+
quoteDecimals: response.quoteDecimals,
|
|
34
34
|
timestamp: response.timestamp,
|
|
35
|
-
sequence: response.
|
|
35
|
+
sequence: response.sequenceNumber,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
}
|