@0xmonaco/core 0.8.5 → 0.8.7-develop.0f12336
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 +3 -12
- package/dist/api/applications/api.d.ts +61 -8
- package/dist/api/applications/api.js +75 -11
- package/dist/api/auth/api.d.ts +44 -76
- package/dist/api/auth/api.js +68 -111
- package/dist/api/base.d.ts +50 -9
- package/dist/api/base.js +97 -14
- package/dist/api/delegated-agents/api.d.ts +2 -1
- package/dist/api/delegated-agents/api.js +15 -11
- package/dist/api/faucet/api.d.ts +25 -0
- package/dist/api/faucet/api.js +29 -0
- package/dist/api/faucet/index.d.ts +1 -0
- package/dist/api/faucet/index.js +1 -0
- package/dist/api/fees/api.d.ts +13 -13
- package/dist/api/fees/api.js +18 -18
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/margin-accounts/api.d.ts +9 -5
- package/dist/api/margin-accounts/api.js +70 -33
- package/dist/api/market/api.d.ts +5 -2
- package/dist/api/market/api.js +32 -16
- package/dist/api/orderbook/api.js +13 -12
- package/dist/api/perp/routes.d.ts +113 -37
- package/dist/api/perp/routes.js +37 -6
- package/dist/api/positions/api.d.ts +2 -1
- package/dist/api/positions/api.js +30 -18
- package/dist/api/profile/api.d.ts +40 -23
- package/dist/api/profile/api.js +78 -38
- package/dist/api/sub-accounts/api.d.ts +62 -0
- package/dist/api/sub-accounts/api.js +80 -0
- package/dist/api/sub-accounts/index.d.ts +1 -0
- package/dist/api/sub-accounts/index.js +1 -0
- package/dist/api/trades/api.d.ts +21 -10
- package/dist/api/trades/api.js +22 -10
- package/dist/api/trading/api.d.ts +11 -8
- package/dist/api/trading/api.js +76 -90
- package/dist/api/vault/api.d.ts +96 -29
- package/dist/api/vault/api.js +172 -43
- package/dist/api/vault/index.d.ts +1 -1
- package/dist/api/vault/index.js +1 -1
- package/dist/api/websocket/types.d.ts +5 -5
- package/dist/api/websocket/websocket.js +43 -22
- package/dist/api/whitelist/api.d.ts +27 -0
- package/dist/api/whitelist/api.js +32 -0
- package/dist/api/whitelist/index.d.ts +1 -0
- package/dist/api/whitelist/index.js +1 -0
- package/dist/api/withdrawals/api.d.ts +18 -0
- package/dist/api/withdrawals/api.js +35 -0
- package/dist/api/withdrawals/index.d.ts +1 -0
- package/dist/api/withdrawals/index.js +1 -0
- package/dist/coverage.d.ts +93 -0
- package/dist/coverage.js +93 -0
- package/dist/crypto/session.d.ts +40 -0
- package/dist/crypto/session.js +60 -0
- package/dist/sdk.d.ts +58 -20
- package/dist/sdk.js +156 -53
- package/package.json +5 -3
package/dist/api/profile/api.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* console.log(`User: ${profile.username} (${profile.address})`);
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
import { GetUserMovementsSchema, GetUserTradesSchema, validate } from "@0xmonaco/types";
|
|
20
|
+
import { GetUserMovementsSchema, GetUserTradesSchema, ListFundingPaymentsSchema, validate } from "@0xmonaco/types";
|
|
21
21
|
import { APIError } from "../../errors";
|
|
22
22
|
import { BaseAPI } from "../base";
|
|
23
23
|
export class ProfileAPIImpl extends BaseAPI {
|
|
@@ -40,8 +40,8 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
40
40
|
* console.log(`User ID: ${profile.id}`);
|
|
41
41
|
* console.log(`Address: ${profile.address}`);
|
|
42
42
|
* console.log(`Username: ${profile.username}`);
|
|
43
|
-
* console.log(`Account type: ${profile.
|
|
44
|
-
* console.log(`Can withdraw: ${profile.
|
|
43
|
+
* console.log(`Account type: ${profile.accountType}`);
|
|
44
|
+
* console.log(`Can withdraw: ${profile.canWithdraw}`);
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
47
|
async getProfile() {
|
|
@@ -56,27 +56,27 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
56
56
|
* @param params - Optional query parameters for pagination and filtering
|
|
57
57
|
* @param params.page - Page number (starts from 1, default: 1)
|
|
58
58
|
* @param params.limit - Number of items per page (default: 20, max: 100)
|
|
59
|
-
* @param params.
|
|
60
|
-
* @param params.
|
|
61
|
-
* @param params.
|
|
59
|
+
* @param params.entryType - Filter by entry type (CREDIT, DEBIT, LOCK, UNLOCK, FEE)
|
|
60
|
+
* @param params.transactionType - Filter by transaction type (DEPOSIT, WITHDRAWAL, TRADE, FEE, FUNDING, LIQUIDATION, INTEREST, REWARD)
|
|
61
|
+
* @param params.assetId - Filter by asset ID (UUID)
|
|
62
62
|
* @returns Promise resolving to paginated movements response
|
|
63
63
|
* @throws {APIError} When the request fails or user is not authenticated
|
|
64
64
|
*
|
|
65
65
|
* @example
|
|
66
66
|
* ```typescript
|
|
67
|
-
* // Get first page with default
|
|
67
|
+
* // Get first page with default pageSize (20)
|
|
68
68
|
* const movements = await profileAPI.getPaginatedUserMovements();
|
|
69
69
|
* console.log(`Total movements: ${movements.total}`);
|
|
70
70
|
*
|
|
71
|
-
* // Get second page with custom
|
|
72
|
-
* const page2 = await profileAPI.getPaginatedUserMovements({ page: 2,
|
|
73
|
-
* console.log(`Page ${page2.page} of ${page2.
|
|
71
|
+
* // Get second page with custom pageSize
|
|
72
|
+
* const page2 = await profileAPI.getPaginatedUserMovements({ page: 2, pageSize: 50 });
|
|
73
|
+
* console.log(`Page ${page2.page} of ${page2.totalPages}`);
|
|
74
74
|
*
|
|
75
75
|
* // Filter by entry type and transaction type
|
|
76
|
-
* const deposits = await profileAPI.getPaginatedUserMovements({
|
|
76
|
+
* const deposits = await profileAPI.getPaginatedUserMovements({ entryType: "CREDIT", transactionType: "DEPOSIT" });
|
|
77
77
|
*
|
|
78
78
|
* // Filter by asset
|
|
79
|
-
* const usdcMovements = await profileAPI.getPaginatedUserMovements({
|
|
79
|
+
* const usdcMovements = await profileAPI.getPaginatedUserMovements({ assetId: "550e8400-e29b-41d4-a716-446655440000" });
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
82
|
async getPaginatedUserMovements(params) {
|
|
@@ -87,17 +87,17 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
87
87
|
if (params?.page !== undefined) {
|
|
88
88
|
searchParams.append("page", params.page.toString());
|
|
89
89
|
}
|
|
90
|
-
if (params?.
|
|
91
|
-
searchParams.append("
|
|
90
|
+
if (params?.pageSize !== undefined) {
|
|
91
|
+
searchParams.append("pageSize", params.pageSize.toString());
|
|
92
92
|
}
|
|
93
|
-
if (params?.
|
|
94
|
-
searchParams.append("
|
|
93
|
+
if (params?.entryType !== undefined) {
|
|
94
|
+
searchParams.append("entryType", params.entryType);
|
|
95
95
|
}
|
|
96
|
-
if (params?.
|
|
97
|
-
searchParams.append("
|
|
96
|
+
if (params?.transactionType !== undefined) {
|
|
97
|
+
searchParams.append("transactionType", params.transactionType);
|
|
98
98
|
}
|
|
99
|
-
if (params?.
|
|
100
|
-
searchParams.append("
|
|
99
|
+
if (params?.assetId !== undefined) {
|
|
100
|
+
searchParams.append("assetId", params.assetId);
|
|
101
101
|
}
|
|
102
102
|
const queryString = searchParams.toString();
|
|
103
103
|
const url = queryString ? `/api/v1/accounts/movements?${queryString}` : "/api/v1/accounts/movements";
|
|
@@ -111,7 +111,7 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
111
111
|
*
|
|
112
112
|
* @param params - Optional query parameters for pagination
|
|
113
113
|
* @param params.page - Page number (starts from 1, default: 1)
|
|
114
|
-
* @param params.
|
|
114
|
+
* @param params.pageSize - Number of items per page (default: 20, max: 100)
|
|
115
115
|
* @returns Promise resolving to paginated balances response
|
|
116
116
|
* @throws {APIError} When the request fails or user is not authenticated
|
|
117
117
|
*
|
|
@@ -121,11 +121,11 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
121
121
|
* const balances = await profileAPI.getUserBalances();
|
|
122
122
|
* console.log(`Total balances: ${balances.total}`);
|
|
123
123
|
* balances.balances.forEach(balance => {
|
|
124
|
-
* console.log(`${balance.symbol}: ${balance.
|
|
124
|
+
* console.log(`${balance.symbol}: ${balance.availableBalance}`);
|
|
125
125
|
* });
|
|
126
126
|
*
|
|
127
127
|
* // Get page 2 with 50 items per page
|
|
128
|
-
* const nextBalances = await profileAPI.getUserBalances({ page: 2,
|
|
128
|
+
* const nextBalances = await profileAPI.getUserBalances({ page: 2, pageSize: 50 });
|
|
129
129
|
* console.log(`Returned ${nextBalances.balances.length} balances`);
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
@@ -134,8 +134,8 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
134
134
|
if (params?.page !== undefined) {
|
|
135
135
|
searchParams.append("page", params.page.toString());
|
|
136
136
|
}
|
|
137
|
-
if (params?.
|
|
138
|
-
searchParams.append("
|
|
137
|
+
if (params?.pageSize !== undefined) {
|
|
138
|
+
searchParams.append("pageSize", params.pageSize.toString());
|
|
139
139
|
}
|
|
140
140
|
const queryString = searchParams.toString();
|
|
141
141
|
const url = queryString ? `/api/v1/accounts/balances?${queryString}` : "/api/v1/accounts/balances";
|
|
@@ -144,7 +144,7 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
144
144
|
/**
|
|
145
145
|
* Get the current user's balance for a specific asset.
|
|
146
146
|
*
|
|
147
|
-
* Fetches the user's balance for a specific asset from the /api/v1/accounts/balances/{
|
|
147
|
+
* Fetches the user's balance for a specific asset from the /api/v1/accounts/balances/{assetId} endpoint.
|
|
148
148
|
* Requires a valid access token to be set. If no balance exists for a valid asset, returns zero balances.
|
|
149
149
|
*
|
|
150
150
|
* @param assetId - The asset identifier (UUID)
|
|
@@ -155,15 +155,15 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
155
155
|
* ```typescript
|
|
156
156
|
* // Get balance for a specific asset
|
|
157
157
|
* const balance = await profileAPI.getUserBalanceByAssetId('123e4567-e89b-12d3-a456-426614174000');
|
|
158
|
-
* console.log(`${balance.symbol}: ${balance.
|
|
159
|
-
* console.log(`Locked: ${balance.
|
|
160
|
-
* console.log(`Total: ${balance.
|
|
158
|
+
* console.log(`${balance.symbol}: ${balance.availableBalance}`);
|
|
159
|
+
* console.log(`Locked: ${balance.lockedBalance}`);
|
|
160
|
+
* console.log(`Total: ${balance.totalBalance}`);
|
|
161
161
|
* ```
|
|
162
162
|
*/
|
|
163
163
|
async getUserBalanceByAssetId(assetId) {
|
|
164
164
|
if (!assetId || assetId.trim() === "") {
|
|
165
165
|
throw new APIError("assetId is required and cannot be empty", {
|
|
166
|
-
endpoint: "/api/v1/accounts/balances/{
|
|
166
|
+
endpoint: "/api/v1/accounts/balances/{assetId}",
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
const url = `/api/v1/accounts/balances/${assetId}`;
|
|
@@ -184,7 +184,7 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
184
184
|
* const stats = await profileAPI.getPortfolioStats("30d");
|
|
185
185
|
* console.log(`PnL: ${stats.pnl}`);
|
|
186
186
|
* console.log(`Volume: ${stats.volume}`);
|
|
187
|
-
* console.log(`Total equity: ${stats.
|
|
187
|
+
* console.log(`Total equity: ${stats.totalEquity}`);
|
|
188
188
|
* ```
|
|
189
189
|
*/
|
|
190
190
|
async getPortfolioStats(period) {
|
|
@@ -222,8 +222,8 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
222
222
|
*
|
|
223
223
|
* @param params - Optional query parameters for pagination and filtering
|
|
224
224
|
* @param params.page - Page number (starts from 1, default: 1)
|
|
225
|
-
* @param params.
|
|
226
|
-
* @param params.
|
|
225
|
+
* @param params.pageSize - Number of items per page (default: 20, max: 100)
|
|
226
|
+
* @param params.tradingPairId - Filter by trading pair ID (UUID)
|
|
227
227
|
* @returns Promise resolving to paginated trades response
|
|
228
228
|
* @throws {ValidationError} When the provided params fail client-side validation
|
|
229
229
|
* @throws {APIError} When the request fails or user is not authenticated
|
|
@@ -235,7 +235,7 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
235
235
|
* console.log(`Total trades: ${trades.total}`);
|
|
236
236
|
*
|
|
237
237
|
* // Filter by trading pair
|
|
238
|
-
* const pairTrades = await profileAPI.getUserTrades({
|
|
238
|
+
* const pairTrades = await profileAPI.getUserTrades({ tradingPairId: "550e8400-e29b-41d4-a716-446655440000" });
|
|
239
239
|
* ```
|
|
240
240
|
*/
|
|
241
241
|
async getUserTrades(params) {
|
|
@@ -246,14 +246,54 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
246
246
|
if (params?.page !== undefined) {
|
|
247
247
|
searchParams.append("page", params.page.toString());
|
|
248
248
|
}
|
|
249
|
-
if (params?.
|
|
250
|
-
searchParams.append("
|
|
249
|
+
if (params?.pageSize !== undefined) {
|
|
250
|
+
searchParams.append("pageSize", params.pageSize.toString());
|
|
251
251
|
}
|
|
252
|
-
if (params?.
|
|
253
|
-
searchParams.append("
|
|
252
|
+
if (params?.tradingPairId !== undefined) {
|
|
253
|
+
searchParams.append("tradingPairId", params.tradingPairId);
|
|
254
254
|
}
|
|
255
255
|
const queryString = searchParams.toString();
|
|
256
256
|
const url = queryString ? `/api/v1/accounts/trades?${queryString}` : "/api/v1/accounts/trades";
|
|
257
257
|
return await this.makeAuthenticatedRequest(url);
|
|
258
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* List the current user's funding payment history with pagination and filters.
|
|
261
|
+
*
|
|
262
|
+
* Fetches funding payments from the /api/v1/accounts/funding-payments endpoint.
|
|
263
|
+
* Requires a valid access token to be set.
|
|
264
|
+
*
|
|
265
|
+
* @param params - Optional query parameters for pagination and filtering
|
|
266
|
+
* @returns Promise resolving to paginated funding payments response
|
|
267
|
+
* @throws {APIError} When the request fails or user is not authenticated
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const funding = await profileAPI.listFundingPayments({ tradingPairId: "550e8400-e29b-41d4-a716-446655440000" });
|
|
272
|
+
* console.log(`Total funding payments: ${funding.total}`);
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
async listFundingPayments(params) {
|
|
276
|
+
if (params) {
|
|
277
|
+
validate(ListFundingPaymentsSchema, params);
|
|
278
|
+
}
|
|
279
|
+
const searchParams = new URLSearchParams();
|
|
280
|
+
if (params?.page !== undefined) {
|
|
281
|
+
searchParams.append("page", params.page.toString());
|
|
282
|
+
}
|
|
283
|
+
if (params?.pageSize !== undefined) {
|
|
284
|
+
searchParams.append("pageSize", params.pageSize.toString());
|
|
285
|
+
}
|
|
286
|
+
if (params?.tradingPairId !== undefined) {
|
|
287
|
+
searchParams.append("tradingPairId", params.tradingPairId);
|
|
288
|
+
}
|
|
289
|
+
if (params?.positionId !== undefined) {
|
|
290
|
+
searchParams.append("positionId", params.positionId);
|
|
291
|
+
}
|
|
292
|
+
if (params?.marginAccountId !== undefined) {
|
|
293
|
+
searchParams.append("marginAccountId", params.marginAccountId);
|
|
294
|
+
}
|
|
295
|
+
const queryString = searchParams.toString();
|
|
296
|
+
const url = queryString ? `/api/v1/accounts/funding-payments?${queryString}` : "/api/v1/accounts/funding-payments";
|
|
297
|
+
return await this.makeAuthenticatedRequest(url);
|
|
298
|
+
}
|
|
259
299
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-Accounts API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Manage a master account's sub-accounts and their per-asset spending limits.
|
|
5
|
+
* All methods are session-authenticated. The limit mutations (`createLimit`,
|
|
6
|
+
* `updateLimit`, `deleteLimit`) additionally require the master account to hold
|
|
7
|
+
* the `ManageSubAccounts` permission — enforced server-side, so a non-master or
|
|
8
|
+
* unpermissioned caller receives a 403.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const { subAccounts } = await sdk.subAccounts.list();
|
|
13
|
+
* await sdk.subAccounts.createLimit({ subAccountId, assetId, maxAmount: "1000.00" });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import type { CreateSubAccountLimitRequest, CreateSubAccountLimitResponse, GetSubAccountLimitsResponse, ListSubAccountsResponse, SubAccountsAPI, UpdateSubAccountLimitBody, UpdateSubAccountLimitResponse } from "@0xmonaco/types";
|
|
17
|
+
import { BaseAPI } from "../base";
|
|
18
|
+
export declare class SubAccountsAPIImpl extends BaseAPI implements SubAccountsAPI {
|
|
19
|
+
/**
|
|
20
|
+
* Lists the authenticated master account's sub-accounts with balances.
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise resolving to the sub-accounts and total count
|
|
23
|
+
*/
|
|
24
|
+
list(): Promise<ListSubAccountsResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a per-asset spending limit on a sub-account.
|
|
27
|
+
*
|
|
28
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
29
|
+
*
|
|
30
|
+
* @param body - Sub-account, asset, max amount, and optional daily limit
|
|
31
|
+
* @returns Promise resolving to the created limit
|
|
32
|
+
*/
|
|
33
|
+
createLimit(body: CreateSubAccountLimitRequest): Promise<CreateSubAccountLimitResponse>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the limits configured for a sub-account.
|
|
36
|
+
*
|
|
37
|
+
* @param subAccountId - Sub-account UUID
|
|
38
|
+
* @returns Promise resolving to the sub-account's limits
|
|
39
|
+
*/
|
|
40
|
+
getLimits(subAccountId: string): Promise<GetSubAccountLimitsResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Updates a sub-account's per-asset limit (partial update).
|
|
43
|
+
*
|
|
44
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
45
|
+
*
|
|
46
|
+
* @param subAccountId - Sub-account UUID
|
|
47
|
+
* @param assetId - Asset UUID
|
|
48
|
+
* @param body - Fields to update
|
|
49
|
+
* @returns Promise resolving to the updated limit
|
|
50
|
+
*/
|
|
51
|
+
updateLimit(subAccountId: string, assetId: string, body: UpdateSubAccountLimitBody): Promise<UpdateSubAccountLimitResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Deletes a sub-account's per-asset limit.
|
|
54
|
+
*
|
|
55
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
56
|
+
*
|
|
57
|
+
* @param subAccountId - Sub-account UUID
|
|
58
|
+
* @param assetId - Asset UUID
|
|
59
|
+
* @returns Promise resolving when the limit is deleted
|
|
60
|
+
*/
|
|
61
|
+
deleteLimit(subAccountId: string, assetId: string): Promise<void>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-Accounts API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Manage a master account's sub-accounts and their per-asset spending limits.
|
|
5
|
+
* All methods are session-authenticated. The limit mutations (`createLimit`,
|
|
6
|
+
* `updateLimit`, `deleteLimit`) additionally require the master account to hold
|
|
7
|
+
* the `ManageSubAccounts` permission — enforced server-side, so a non-master or
|
|
8
|
+
* unpermissioned caller receives a 403.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const { subAccounts } = await sdk.subAccounts.list();
|
|
13
|
+
* await sdk.subAccounts.createLimit({ subAccountId, assetId, maxAmount: "1000.00" });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { BaseAPI } from "../base";
|
|
17
|
+
import { perpRoutes } from "../perp/routes";
|
|
18
|
+
export class SubAccountsAPIImpl extends BaseAPI {
|
|
19
|
+
/**
|
|
20
|
+
* Lists the authenticated master account's sub-accounts with balances.
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise resolving to the sub-accounts and total count
|
|
23
|
+
*/
|
|
24
|
+
async list() {
|
|
25
|
+
return await this.makeAuthenticatedRequest(perpRoutes.subAccounts.list());
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a per-asset spending limit on a sub-account.
|
|
29
|
+
*
|
|
30
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
31
|
+
*
|
|
32
|
+
* @param body - Sub-account, asset, max amount, and optional daily limit
|
|
33
|
+
* @returns Promise resolving to the created limit
|
|
34
|
+
*/
|
|
35
|
+
async createLimit(body) {
|
|
36
|
+
return await this.makeAuthenticatedRequest(perpRoutes.subAccounts.createLimit(), {
|
|
37
|
+
method: "POST",
|
|
38
|
+
body: JSON.stringify(body),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets the limits configured for a sub-account.
|
|
43
|
+
*
|
|
44
|
+
* @param subAccountId - Sub-account UUID
|
|
45
|
+
* @returns Promise resolving to the sub-account's limits
|
|
46
|
+
*/
|
|
47
|
+
async getLimits(subAccountId) {
|
|
48
|
+
return await this.makeAuthenticatedRequest(perpRoutes.subAccounts.getLimits(subAccountId));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Updates a sub-account's per-asset limit (partial update).
|
|
52
|
+
*
|
|
53
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
54
|
+
*
|
|
55
|
+
* @param subAccountId - Sub-account UUID
|
|
56
|
+
* @param assetId - Asset UUID
|
|
57
|
+
* @param body - Fields to update
|
|
58
|
+
* @returns Promise resolving to the updated limit
|
|
59
|
+
*/
|
|
60
|
+
async updateLimit(subAccountId, assetId, body) {
|
|
61
|
+
return await this.makeAuthenticatedRequest(perpRoutes.subAccounts.limit(subAccountId, assetId), {
|
|
62
|
+
method: "PUT",
|
|
63
|
+
body: JSON.stringify(body),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Deletes a sub-account's per-asset limit.
|
|
68
|
+
*
|
|
69
|
+
* Requires the `ManageSubAccounts` permission (enforced server-side).
|
|
70
|
+
*
|
|
71
|
+
* @param subAccountId - Sub-account UUID
|
|
72
|
+
* @param assetId - Asset UUID
|
|
73
|
+
* @returns Promise resolving when the limit is deleted
|
|
74
|
+
*/
|
|
75
|
+
async deleteLimit(subAccountId, assetId) {
|
|
76
|
+
await this.makeAuthenticatedRequest(perpRoutes.subAccounts.limit(subAccountId, assetId), {
|
|
77
|
+
method: "DELETE",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SubAccountsAPIImpl } from "./api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SubAccountsAPIImpl } from "./api";
|
package/dist/api/trades/api.d.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import type { TradeEvent } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
/**
|
|
4
|
-
* Raw trade event from the API (
|
|
4
|
+
* Raw trade event from the API (camelCase wire shape).
|
|
5
5
|
*/
|
|
6
6
|
interface RawTradeEvent {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
eventType: string;
|
|
8
|
+
tradingPairId: string;
|
|
9
|
+
tradingMode: string;
|
|
10
10
|
data: {
|
|
11
|
-
|
|
11
|
+
tradeId: string;
|
|
12
12
|
price: string;
|
|
13
13
|
quantity: string;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/** Raw (integer) quantity; present on single-trade lookups, ignored when mapping */
|
|
15
|
+
quantityRaw?: string;
|
|
16
|
+
makerSide: string;
|
|
17
|
+
/** Absent when the trade has no recorded execution time */
|
|
18
|
+
executedAt?: string;
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
/**
|
|
19
|
-
* Convert a raw trade event
|
|
22
|
+
* Convert a raw wire trade event to an ergonomic TradeEvent.
|
|
20
23
|
*/
|
|
21
24
|
export declare function parseRawTradeEvent(raw: RawTradeEvent): TradeEvent;
|
|
22
25
|
/**
|
|
@@ -26,7 +29,7 @@ export interface GetTradesOptions {
|
|
|
26
29
|
/** Page number (starts from 1, default: 1) */
|
|
27
30
|
page?: number;
|
|
28
31
|
/** Maximum number of records to return (default: 25, max: 100) */
|
|
29
|
-
|
|
32
|
+
pageSize?: number;
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
32
35
|
* Trades API for fetching historical trade data
|
|
@@ -37,8 +40,16 @@ export declare class TradesAPIImpl extends BaseAPI {
|
|
|
37
40
|
*
|
|
38
41
|
* @param tradingPairId - The trading pair UUID
|
|
39
42
|
* @param options - Pagination options
|
|
40
|
-
* @returns Array of TradeEvent records sorted by
|
|
43
|
+
* @returns Array of TradeEvent records sorted by executedAt descending (newest first)
|
|
41
44
|
*/
|
|
42
45
|
getTrades(tradingPairId: string, options?: GetTradesOptions): Promise<TradeEvent[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Get a single trade by its UUID.
|
|
48
|
+
*
|
|
49
|
+
* @param tradeId - The trade UUID
|
|
50
|
+
* @returns The matching TradeEvent
|
|
51
|
+
* @throws {APIError} If the trade is not found
|
|
52
|
+
*/
|
|
53
|
+
getTradeById(tradeId: string): Promise<TradeEvent>;
|
|
43
54
|
}
|
|
44
55
|
export {};
|
package/dist/api/trades/api.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { BaseAPI } from "../base";
|
|
2
|
+
import { perpRoutes } from "../perp";
|
|
2
3
|
/**
|
|
3
|
-
* Convert a raw trade event
|
|
4
|
+
* Convert a raw wire trade event to an ergonomic TradeEvent.
|
|
4
5
|
*/
|
|
5
6
|
export function parseRawTradeEvent(raw) {
|
|
6
7
|
return {
|
|
7
8
|
eventType: "trade",
|
|
8
|
-
tradingPairId: raw.
|
|
9
|
-
tradingMode: raw.
|
|
9
|
+
tradingPairId: raw.tradingPairId,
|
|
10
|
+
tradingMode: raw.tradingMode.toUpperCase(),
|
|
10
11
|
data: {
|
|
11
|
-
tradeId: raw.data.
|
|
12
|
+
tradeId: raw.data.tradeId,
|
|
12
13
|
price: raw.data.price,
|
|
13
14
|
quantity: raw.data.quantity,
|
|
14
|
-
makerSide: raw.data.
|
|
15
|
-
executedAt: raw.data.
|
|
15
|
+
makerSide: raw.data.makerSide.toUpperCase(),
|
|
16
|
+
executedAt: raw.data.executedAt ?? "",
|
|
16
17
|
},
|
|
17
18
|
};
|
|
18
19
|
}
|
|
@@ -25,18 +26,29 @@ export class TradesAPIImpl extends BaseAPI {
|
|
|
25
26
|
*
|
|
26
27
|
* @param tradingPairId - The trading pair UUID
|
|
27
28
|
* @param options - Pagination options
|
|
28
|
-
* @returns Array of TradeEvent records sorted by
|
|
29
|
+
* @returns Array of TradeEvent records sorted by executedAt descending (newest first)
|
|
29
30
|
*/
|
|
30
31
|
async getTrades(tradingPairId, options = {}) {
|
|
31
32
|
const { page = 1 } = options;
|
|
32
|
-
// Ensure
|
|
33
|
-
const
|
|
33
|
+
// Ensure pageSize is a positive number between 1 and 100, defaulting to 25
|
|
34
|
+
const pageSize = options.pageSize != null && options.pageSize > 0 ? Math.min(options.pageSize, 100) : 25;
|
|
34
35
|
const params = new URLSearchParams();
|
|
35
36
|
if (page > 1) {
|
|
36
37
|
params.set("page", String(page));
|
|
37
38
|
}
|
|
38
|
-
params.set("
|
|
39
|
+
params.set("pageSize", String(pageSize));
|
|
39
40
|
const response = await this.makePublicRequest(`/api/v1/trades/${encodeURIComponent(tradingPairId)}?${params.toString()}`);
|
|
40
41
|
return response.trades.map(parseRawTradeEvent);
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Get a single trade by its UUID.
|
|
45
|
+
*
|
|
46
|
+
* @param tradeId - The trade UUID
|
|
47
|
+
* @returns The matching TradeEvent
|
|
48
|
+
* @throws {APIError} If the trade is not found
|
|
49
|
+
*/
|
|
50
|
+
async getTradeById(tradeId) {
|
|
51
|
+
const response = await this.makePublicRequest(perpRoutes.trades.byId(tradeId));
|
|
52
|
+
return parseRawTradeEvent(response);
|
|
53
|
+
}
|
|
42
54
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* );
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse,
|
|
24
|
+
import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, OrderSide, ParentTpSlLegParams, PositionSide, ReplaceOrderResponse, TimeInForce, TradingAPI, TradingMode } from "@0xmonaco/types";
|
|
25
25
|
import { BaseAPI } from "../base";
|
|
26
26
|
export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
27
27
|
/**
|
|
@@ -80,6 +80,8 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
80
80
|
expirationDate?: string;
|
|
81
81
|
timeInForce?: TimeInForce;
|
|
82
82
|
marginAccountId?: string;
|
|
83
|
+
riskBucketId?: string;
|
|
84
|
+
riskBucketCollateral?: string;
|
|
83
85
|
strategyKey?: string;
|
|
84
86
|
positionSide?: PositionSide;
|
|
85
87
|
leverage?: string;
|
|
@@ -132,6 +134,8 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
132
134
|
tradingMode?: TradingMode;
|
|
133
135
|
slippageTolerance?: number;
|
|
134
136
|
marginAccountId?: string;
|
|
137
|
+
riskBucketId?: string;
|
|
138
|
+
riskBucketCollateral?: string;
|
|
135
139
|
strategyKey?: string;
|
|
136
140
|
positionSide?: PositionSide;
|
|
137
141
|
leverage?: string;
|
|
@@ -156,7 +160,6 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
156
160
|
* ```
|
|
157
161
|
*/
|
|
158
162
|
cancelOrder(orderId: string): Promise<CancelOrderResponse>;
|
|
159
|
-
createConditionalOrder(params: CreateConditionalOrderParams): Promise<CreateConditionalOrderResponse>;
|
|
160
163
|
cancelConditionalOrder(conditionalOrderId: string): Promise<CancelConditionalOrderResponse>;
|
|
161
164
|
listConditionalOrders(params?: ListConditionalOrdersParams): Promise<ListConditionalOrdersResponse>;
|
|
162
165
|
/**
|
|
@@ -259,9 +262,9 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
259
262
|
*
|
|
260
263
|
* @param params - Query parameters for filtering orders
|
|
261
264
|
* @param params.status - Filter by order status (e.g., "SUBMITTED", "FILLED") (optional)
|
|
262
|
-
* @param params.
|
|
265
|
+
* @param params.tradingPairId - Filter by trading pair UUID (optional)
|
|
263
266
|
* @param params.page - Page number for pagination (defaults to 1, must be > 0)
|
|
264
|
-
* @param params.
|
|
267
|
+
* @param params.pageSize - Number of orders per page (defaults to 10, max 100, must be > 0)
|
|
265
268
|
* @returns Promise resolving to GetPaginatedOrdersResponse with orders and pagination info
|
|
266
269
|
* @throws {APIError} When API communication fails
|
|
267
270
|
*
|
|
@@ -270,13 +273,13 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
270
273
|
* // Get submitted orders for a specific trading pair with custom pagination
|
|
271
274
|
* const orders = await tradingAPI.getPaginatedOrders({
|
|
272
275
|
* status: "SUBMITTED",
|
|
273
|
-
*
|
|
276
|
+
* tradingPairId: "456e7890-e12b-12d3-a456-426614174000",
|
|
274
277
|
* page: 1,
|
|
275
|
-
*
|
|
278
|
+
* pageSize: 20
|
|
276
279
|
* });
|
|
277
280
|
* console.log(`Found ${orders.total} orders, showing page ${orders.page}`);
|
|
278
281
|
*
|
|
279
|
-
* // Get all orders with default pagination (page=1,
|
|
282
|
+
* // Get all orders with default pagination (page=1, pageSize=10)
|
|
280
283
|
* const allOrders = await tradingAPI.getPaginatedOrders();
|
|
281
284
|
* ```
|
|
282
285
|
*/
|
|
@@ -296,7 +299,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
296
299
|
* // Get order details by ID
|
|
297
300
|
* const orderDetails = await tradingAPI.getOrder("order_123");
|
|
298
301
|
* console.log(`Order status: ${orderDetails.order.status}`);
|
|
299
|
-
* console.log(`Remaining quantity: ${orderDetails.order.
|
|
302
|
+
* console.log(`Remaining quantity: ${orderDetails.order.remainingQuantity}`);
|
|
300
303
|
* ```
|
|
301
304
|
*/
|
|
302
305
|
getOrder(orderId: string): Promise<GetOrderResponse>;
|