@0xmonaco/core 0.8.7 → 0.8.10
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.d.ts +61 -8
- package/dist/api/applications/api.js +71 -7
- package/dist/api/auth/api.d.ts +44 -76
- package/dist/api/auth/api.js +61 -104
- package/dist/api/base.d.ts +48 -7
- package/dist/api/base.js +95 -12
- package/dist/api/delegated-agents/api.d.ts +2 -1
- package/dist/api/delegated-agents/api.js +4 -0
- 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/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/margin-accounts/api.d.ts +3 -4
- package/dist/api/margin-accounts/api.js +8 -15
- package/dist/api/market/api.d.ts +3 -1
- package/dist/api/market/api.js +8 -0
- package/dist/api/orderbook/api.js +2 -1
- package/dist/api/perp/routes.d.ts +62 -4
- package/dist/api/perp/routes.js +27 -4
- package/dist/api/profile/api.d.ts +18 -1
- package/dist/api/profile/api.js +41 -1
- 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 +12 -1
- package/dist/api/trades/api.js +13 -1
- package/dist/api/trading/api.d.ts +5 -2
- package/dist/api/trading/api.js +13 -27
- 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 +15 -0
- package/dist/api/withdrawals/api.js +27 -0
- package/dist/api/withdrawals/index.d.ts +1 -0
- package/dist/api/withdrawals/index.js +1 -0
- package/dist/coverage.d.ts +85 -0
- package/dist/coverage.js +85 -0
- package/dist/crypto/session.d.ts +40 -0
- package/dist/crypto/session.js +60 -0
- package/dist/sdk.d.ts +56 -18
- package/dist/sdk.js +156 -53
- package/package.json +5 -3
package/dist/api/base.d.ts
CHANGED
|
@@ -20,13 +20,18 @@
|
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
+
import type { SessionCredentials } from "@0xmonaco/types";
|
|
24
|
+
import { type SessionKeypair } from "../crypto/session";
|
|
23
25
|
export interface RetryOptions {
|
|
24
26
|
maxRetries?: number;
|
|
25
27
|
baseDelayMs?: number;
|
|
26
28
|
}
|
|
27
29
|
export declare abstract class BaseAPI {
|
|
28
30
|
protected readonly apiUrl: string;
|
|
29
|
-
|
|
31
|
+
/** Active session keypair (raw bytes) used to sign authenticated requests. */
|
|
32
|
+
protected sessionKeypair?: SessionKeypair;
|
|
33
|
+
/** Application secret key (`sk_...`) sent in the `x-server-key` header for backend-authenticated requests. */
|
|
34
|
+
protected serverKey?: string;
|
|
30
35
|
protected retryOptions: Required<RetryOptions>;
|
|
31
36
|
/**
|
|
32
37
|
* Creates a new BaseAPI instance.
|
|
@@ -36,17 +41,24 @@ export declare abstract class BaseAPI {
|
|
|
36
41
|
*/
|
|
37
42
|
constructor(apiUrl: string, retryOptions?: RetryOptions);
|
|
38
43
|
/**
|
|
39
|
-
* Set the
|
|
44
|
+
* Set (or clear) the session keypair used to sign authenticated requests.
|
|
40
45
|
*
|
|
41
|
-
* @param
|
|
46
|
+
* @param credentials - Hex-encoded session keypair, or `undefined` to clear.
|
|
42
47
|
*/
|
|
43
|
-
|
|
48
|
+
setSessionKeypair(credentials: SessionCredentials | undefined): void;
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
50
|
+
* Set (or clear) the application secret key used for backend-authenticated
|
|
51
|
+
* requests.
|
|
46
52
|
*
|
|
47
|
-
*
|
|
53
|
+
* Backend endpoints (those annotated `#[require_backend]` on the gateway)
|
|
54
|
+
* authenticate with a static application secret key rather than a session
|
|
55
|
+
* signature. When set, the raw key is sent verbatim in the `x-server-key`
|
|
56
|
+
* header on every {@link makeBackendRequest}. This is independent of the
|
|
57
|
+
* session keypair — a client may hold both.
|
|
58
|
+
*
|
|
59
|
+
* @param serverKey - The application secret key (`sk_...`), or `undefined` to clear.
|
|
48
60
|
*/
|
|
49
|
-
|
|
61
|
+
setServerKey(serverKey: string | undefined): void;
|
|
50
62
|
/**
|
|
51
63
|
* Parse request body for error logging
|
|
52
64
|
*
|
|
@@ -93,6 +105,35 @@ export declare abstract class BaseAPI {
|
|
|
93
105
|
* ```
|
|
94
106
|
*/
|
|
95
107
|
protected makeAuthenticatedRequest<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
108
|
+
/**
|
|
109
|
+
* Compute the per-request ed25519 signature headers.
|
|
110
|
+
*
|
|
111
|
+
* The signed payload is `METHOD\nPATH_WITH_QUERY\nTIMESTAMP_MS\nSHA256_BODY_HEX`,
|
|
112
|
+
* matching the server (`handlers::auth::compose_signing_string`). `endpoint`
|
|
113
|
+
* is the path-with-query exactly as sent; the body hash covers the raw bytes
|
|
114
|
+
* so a request can't be replayed with a different body.
|
|
115
|
+
*/
|
|
116
|
+
private buildSignatureHeaders;
|
|
117
|
+
/**
|
|
118
|
+
* Makes a backend-authenticated API request using the application secret key.
|
|
119
|
+
*
|
|
120
|
+
* Sends the raw `sk_...` key (set via {@link setServerKey}) in the
|
|
121
|
+
* `x-server-key` header. The gateway hashes and matches it against the
|
|
122
|
+
* application on every request — there is no signing and no token exchange.
|
|
123
|
+
* Use this for endpoints annotated `#[require_backend]`.
|
|
124
|
+
*
|
|
125
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
126
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
127
|
+
* @returns Promise resolving to the response data
|
|
128
|
+
* @throws {APIError} When the server key is not set or the API request fails
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* this.setServerKey("sk_live_...");
|
|
133
|
+
* const orders = await this.makeBackendRequest<ListAppOrdersResponse>('/api/v1/applications/orders');
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
protected makeBackendRequest<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
96
137
|
/**
|
|
97
138
|
* Makes an unauthenticated API request.
|
|
98
139
|
*
|
package/dist/api/base.js
CHANGED
|
@@ -20,11 +20,16 @@
|
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
+
import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils";
|
|
23
24
|
import { StatusCodes } from "http-status-codes";
|
|
25
|
+
import { composeSigningString, keypairFromHex, sha256Hex, signMessage } from "../crypto/session";
|
|
24
26
|
import { APIError } from "../errors";
|
|
25
27
|
export class BaseAPI {
|
|
26
28
|
apiUrl;
|
|
27
|
-
|
|
29
|
+
/** Active session keypair (raw bytes) used to sign authenticated requests. */
|
|
30
|
+
sessionKeypair;
|
|
31
|
+
/** Application secret key (`sk_...`) sent in the `x-server-key` header for backend-authenticated requests. */
|
|
32
|
+
serverKey;
|
|
28
33
|
retryOptions;
|
|
29
34
|
/**
|
|
30
35
|
* Creates a new BaseAPI instance.
|
|
@@ -40,20 +45,27 @@ export class BaseAPI {
|
|
|
40
45
|
};
|
|
41
46
|
}
|
|
42
47
|
/**
|
|
43
|
-
* Set the
|
|
48
|
+
* Set (or clear) the session keypair used to sign authenticated requests.
|
|
44
49
|
*
|
|
45
|
-
* @param
|
|
50
|
+
* @param credentials - Hex-encoded session keypair, or `undefined` to clear.
|
|
46
51
|
*/
|
|
47
|
-
|
|
48
|
-
this.
|
|
52
|
+
setSessionKeypair(credentials) {
|
|
53
|
+
this.sessionKeypair = credentials ? keypairFromHex(credentials.publicKey, credentials.privateKey) : undefined;
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
|
-
*
|
|
56
|
+
* Set (or clear) the application secret key used for backend-authenticated
|
|
57
|
+
* requests.
|
|
52
58
|
*
|
|
53
|
-
*
|
|
59
|
+
* Backend endpoints (those annotated `#[require_backend]` on the gateway)
|
|
60
|
+
* authenticate with a static application secret key rather than a session
|
|
61
|
+
* signature. When set, the raw key is sent verbatim in the `x-server-key`
|
|
62
|
+
* header on every {@link makeBackendRequest}. This is independent of the
|
|
63
|
+
* session keypair — a client may hold both.
|
|
64
|
+
*
|
|
65
|
+
* @param serverKey - The application secret key (`sk_...`), or `undefined` to clear.
|
|
54
66
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
setServerKey(serverKey) {
|
|
68
|
+
this.serverKey = serverKey;
|
|
57
69
|
}
|
|
58
70
|
/**
|
|
59
71
|
* Parse request body for error logging
|
|
@@ -175,6 +187,12 @@ export class BaseAPI {
|
|
|
175
187
|
retryAfter,
|
|
176
188
|
});
|
|
177
189
|
}
|
|
190
|
+
// A successful response with an empty body (e.g. 204 No Content from a
|
|
191
|
+
// DELETE) is not an error — there is simply nothing to parse. Return
|
|
192
|
+
// `undefined` so void-returning methods resolve cleanly.
|
|
193
|
+
if (responseText.trim() === "") {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
178
196
|
// If response is OK but not JSON, throw a more specific error
|
|
179
197
|
throw new APIError(`Expected JSON response but received ${contentType}`, {
|
|
180
198
|
endpoint: url,
|
|
@@ -229,8 +247,73 @@ export class BaseAPI {
|
|
|
229
247
|
* ```
|
|
230
248
|
*/
|
|
231
249
|
async makeAuthenticatedRequest(endpoint, options = {}) {
|
|
232
|
-
if (!this.
|
|
233
|
-
throw new APIError("
|
|
250
|
+
if (!this.sessionKeypair) {
|
|
251
|
+
throw new APIError("Session keypair not set. Authenticate (login) first.", {
|
|
252
|
+
endpoint: `${this.apiUrl}${endpoint}`,
|
|
253
|
+
statusCode: StatusCodes.UNAUTHORIZED,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
const url = `${this.apiUrl}${endpoint}`;
|
|
257
|
+
const requestBody = this.parseRequestBody(options.body);
|
|
258
|
+
const signatureHeaders = this.buildSignatureHeaders(endpoint, options);
|
|
259
|
+
return this.executeRequest(url, endpoint, {
|
|
260
|
+
...options,
|
|
261
|
+
headers: {
|
|
262
|
+
"Content-Type": "application/json",
|
|
263
|
+
...signatureHeaders,
|
|
264
|
+
...options.headers,
|
|
265
|
+
},
|
|
266
|
+
}, requestBody);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Compute the per-request ed25519 signature headers.
|
|
270
|
+
*
|
|
271
|
+
* The signed payload is `METHOD\nPATH_WITH_QUERY\nTIMESTAMP_MS\nSHA256_BODY_HEX`,
|
|
272
|
+
* matching the server (`handlers::auth::compose_signing_string`). `endpoint`
|
|
273
|
+
* is the path-with-query exactly as sent; the body hash covers the raw bytes
|
|
274
|
+
* so a request can't be replayed with a different body.
|
|
275
|
+
*/
|
|
276
|
+
buildSignatureHeaders(endpoint, options) {
|
|
277
|
+
if (!this.sessionKeypair) {
|
|
278
|
+
throw new APIError("Session keypair not set. Authenticate (login) first.", {
|
|
279
|
+
endpoint: `${this.apiUrl}${endpoint}`,
|
|
280
|
+
statusCode: StatusCodes.UNAUTHORIZED,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const method = (options.method ?? "GET").toUpperCase();
|
|
284
|
+
const timestampMs = Date.now();
|
|
285
|
+
const bodyBytes = typeof options.body === "string" ? utf8ToBytes(options.body) : new Uint8Array(0);
|
|
286
|
+
const bodyHash = sha256Hex(bodyBytes);
|
|
287
|
+
const signingString = composeSigningString(method, endpoint, timestampMs, bodyHash);
|
|
288
|
+
const signature = signMessage(this.sessionKeypair.privateKey, signingString);
|
|
289
|
+
return {
|
|
290
|
+
"X-Monaco-PublicKey": bytesToHex(this.sessionKeypair.publicKey),
|
|
291
|
+
"X-Monaco-Timestamp": String(timestampMs),
|
|
292
|
+
"X-Monaco-Signature": signature,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Makes a backend-authenticated API request using the application secret key.
|
|
297
|
+
*
|
|
298
|
+
* Sends the raw `sk_...` key (set via {@link setServerKey}) in the
|
|
299
|
+
* `x-server-key` header. The gateway hashes and matches it against the
|
|
300
|
+
* application on every request — there is no signing and no token exchange.
|
|
301
|
+
* Use this for endpoints annotated `#[require_backend]`.
|
|
302
|
+
*
|
|
303
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
304
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
305
|
+
* @returns Promise resolving to the response data
|
|
306
|
+
* @throws {APIError} When the server key is not set or the API request fails
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* this.setServerKey("sk_live_...");
|
|
311
|
+
* const orders = await this.makeBackendRequest<ListAppOrdersResponse>('/api/v1/applications/orders');
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
async makeBackendRequest(endpoint, options = {}) {
|
|
315
|
+
if (!this.serverKey) {
|
|
316
|
+
throw new APIError("Server key not set. Call setServerKey(sk_...) first.", {
|
|
234
317
|
endpoint: `${this.apiUrl}${endpoint}`,
|
|
235
318
|
statusCode: StatusCodes.UNAUTHORIZED,
|
|
236
319
|
});
|
|
@@ -241,7 +324,7 @@ export class BaseAPI {
|
|
|
241
324
|
...options,
|
|
242
325
|
headers: {
|
|
243
326
|
"Content-Type": "application/json",
|
|
244
|
-
|
|
327
|
+
"x-server-key": this.serverKey,
|
|
245
328
|
...options.headers,
|
|
246
329
|
},
|
|
247
330
|
}, requestBody);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { CreateDelegatedSessionRequest, CreateDelegatedSessionResponse, DelegatedAgent, DelegatedAgentsAPI, ListDelegatedAgentsResponse, UpsertDelegatedAgentRequest } from "@0xmonaco/types";
|
|
1
|
+
import type { CreateDelegatedSessionRequest, CreateDelegatedSessionResponse, DelegatedAgent, DelegatedAgentsAPI, ListDelegatedAgentsResponse, ListDelegatedOwnersResponse, UpsertDelegatedAgentRequest } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
export declare class DelegatedAgentsAPIImpl extends BaseAPI implements DelegatedAgentsAPI {
|
|
4
4
|
upsertDelegatedAgent(request: UpsertDelegatedAgentRequest): Promise<DelegatedAgent>;
|
|
5
5
|
listDelegatedAgents(): Promise<ListDelegatedAgentsResponse>;
|
|
6
|
+
listDelegatedOwners(): Promise<ListDelegatedOwnersResponse>;
|
|
6
7
|
revokeDelegatedAgent(delegatedAgentId: string): Promise<{
|
|
7
8
|
status: "REVOKED";
|
|
8
9
|
}>;
|
|
@@ -22,6 +22,9 @@ export class DelegatedAgentsAPIImpl extends BaseAPI {
|
|
|
22
22
|
async listDelegatedAgents() {
|
|
23
23
|
return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.list());
|
|
24
24
|
}
|
|
25
|
+
async listDelegatedOwners() {
|
|
26
|
+
return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.owners());
|
|
27
|
+
}
|
|
25
28
|
async revokeDelegatedAgent(delegatedAgentId) {
|
|
26
29
|
return this.makeAuthenticatedRequest(perpRoutes.delegatedAgents.byId(delegatedAgentId), {
|
|
27
30
|
method: "DELETE",
|
|
@@ -32,6 +35,7 @@ export class DelegatedAgentsAPIImpl extends BaseAPI {
|
|
|
32
35
|
method: "POST",
|
|
33
36
|
body: JSON.stringify({
|
|
34
37
|
owner_user_id: request.ownerUserId,
|
|
38
|
+
session_public_key: request.sessionPublicKey,
|
|
35
39
|
}),
|
|
36
40
|
});
|
|
37
41
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Faucet API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Testnet token faucet. Session-authenticated. Performs real on-chain mints
|
|
5
|
+
* from a backend-operator-funded signer and is rate-limited per user
|
|
6
|
+
* (default 1 request / 24h). It is unavailable if the gateway operator has not
|
|
7
|
+
* configured a signer — the SDK caller has no control over that.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const { minted, failed, remaining_requests_24h } = await sdk.faucet.mint();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import type { FaucetAPI, MintTokensResponse } from "@0xmonaco/types";
|
|
15
|
+
import { BaseAPI } from "../base";
|
|
16
|
+
export declare class FaucetAPIImpl extends BaseAPI implements FaucetAPI {
|
|
17
|
+
/**
|
|
18
|
+
* Mints the full set of testnet tokens to the authenticated user.
|
|
19
|
+
*
|
|
20
|
+
* Partial success is possible — inspect `minted` and `failed` in the response.
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise resolving to the minted/failed tokens and remaining quota
|
|
23
|
+
*/
|
|
24
|
+
mint(): Promise<MintTokensResponse>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Faucet API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Testnet token faucet. Session-authenticated. Performs real on-chain mints
|
|
5
|
+
* from a backend-operator-funded signer and is rate-limited per user
|
|
6
|
+
* (default 1 request / 24h). It is unavailable if the gateway operator has not
|
|
7
|
+
* configured a signer — the SDK caller has no control over that.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const { minted, failed, remaining_requests_24h } = await sdk.faucet.mint();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { BaseAPI } from "../base";
|
|
15
|
+
import { perpRoutes } from "../perp/routes";
|
|
16
|
+
export class FaucetAPIImpl extends BaseAPI {
|
|
17
|
+
/**
|
|
18
|
+
* Mints the full set of testnet tokens to the authenticated user.
|
|
19
|
+
*
|
|
20
|
+
* Partial success is possible — inspect `minted` and `failed` in the response.
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise resolving to the minted/failed tokens and remaining quota
|
|
23
|
+
*/
|
|
24
|
+
async mint() {
|
|
25
|
+
return await this.makeAuthenticatedRequest(perpRoutes.faucet.mint(), {
|
|
26
|
+
method: "POST",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FaucetAPIImpl } from "./api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FaucetAPIImpl } from "./api";
|
package/dist/api/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./base";
|
|
8
8
|
export * from "./delegated-agents";
|
|
9
|
+
export * from "./faucet";
|
|
9
10
|
export * from "./fees";
|
|
10
11
|
export * from "./margin-accounts";
|
|
11
12
|
export * from "./market";
|
|
@@ -13,7 +14,10 @@ export * from "./orderbook";
|
|
|
13
14
|
export * from "./perp";
|
|
14
15
|
export * from "./positions";
|
|
15
16
|
export * from "./profile";
|
|
17
|
+
export * from "./sub-accounts";
|
|
16
18
|
export * from "./trades";
|
|
17
19
|
export * from "./trading";
|
|
18
20
|
export * from "./vault";
|
|
19
21
|
export * from "./websocket";
|
|
22
|
+
export * from "./whitelist";
|
|
23
|
+
export * from "./withdrawals";
|
package/dist/api/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./base";
|
|
8
8
|
export * from "./delegated-agents";
|
|
9
|
+
export * from "./faucet";
|
|
9
10
|
export * from "./fees";
|
|
10
11
|
export * from "./margin-accounts";
|
|
11
12
|
export * from "./market";
|
|
@@ -13,7 +14,10 @@ export * from "./orderbook";
|
|
|
13
14
|
export * from "./perp";
|
|
14
15
|
export * from "./positions";
|
|
15
16
|
export * from "./profile";
|
|
17
|
+
export * from "./sub-accounts";
|
|
16
18
|
export * from "./trades";
|
|
17
19
|
export * from "./trading";
|
|
18
20
|
export * from "./vault";
|
|
19
21
|
export * from "./websocket";
|
|
22
|
+
export * from "./whitelist";
|
|
23
|
+
export * from "./withdrawals";
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, GetMarginAccountSummaryParams, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI, SimulateAutoMarginOrderRiskRequest, SimulateOrderRiskRequest, SimulateOrderRiskResponse, TransferCollateralRequest, TransferCollateralResponse, TransferCollateralToAutoMarginAccountRequest } 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
|
-
|
|
6
|
-
getMarginAccountSummary(marginAccountId: string): Promise<MarginAccountSummary>;
|
|
5
|
+
getMarginAccountSummary(marginAccountId: string, params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
|
|
7
6
|
getAvailableCollateral(params?: GetAvailableCollateralParams): Promise<GetAvailableCollateralResponse>;
|
|
8
7
|
transferCollateralToMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
9
8
|
transferCollateralToAutoMarginAccount(request: TransferCollateralToAutoMarginAccountRequest): Promise<TransferCollateralResponse>;
|
|
10
9
|
transferCollateralFromMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
11
10
|
getMarginAccountMovements(marginAccountId: string, params?: GetMarginAccountMovementsParams): Promise<GetMarginAccountMovementsResponse>;
|
|
12
11
|
simulateOrderRisk(marginAccountId: string, request: SimulateOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
13
|
-
simulateAutoMarginOrderRisk(request:
|
|
12
|
+
simulateAutoMarginOrderRisk(request: SimulateAutoMarginOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
14
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateAutoMarginOrderRiskSchema, SimulateOrderRiskSchema, TransferCollateralSchema, TransferCollateralToAutoMarginAccountSchema, validate, } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
import { perpRoutes } from "../perp";
|
|
4
4
|
export class MarginAccountsAPIImpl extends BaseAPI {
|
|
@@ -15,19 +15,9 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
15
15
|
}
|
|
16
16
|
: undefined));
|
|
17
17
|
}
|
|
18
|
-
async
|
|
19
|
-
validate(
|
|
20
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.
|
|
21
|
-
method: "POST",
|
|
22
|
-
body: JSON.stringify({
|
|
23
|
-
label: request?.label,
|
|
24
|
-
collateral_asset: request?.collateralAsset,
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async getMarginAccountSummary(marginAccountId) {
|
|
29
|
-
validate(GetMarginAccountSummarySchema, { marginAccountId });
|
|
30
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.summary(marginAccountId));
|
|
18
|
+
async getMarginAccountSummary(marginAccountId, params) {
|
|
19
|
+
validate(GetMarginAccountSummarySchema, { marginAccountId, ...params });
|
|
20
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.summary(marginAccountId, { trading_pair_id: params?.tradingPairId }));
|
|
31
21
|
}
|
|
32
22
|
async getAvailableCollateral(params) {
|
|
33
23
|
validate(GetAvailableCollateralSchema, params);
|
|
@@ -40,6 +30,8 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
40
30
|
body: JSON.stringify({
|
|
41
31
|
asset: request.asset,
|
|
42
32
|
amount: request.amount,
|
|
33
|
+
trading_pair_id: request.tradingPairId,
|
|
34
|
+
strategy_key: request.strategyKey,
|
|
43
35
|
}),
|
|
44
36
|
});
|
|
45
37
|
}
|
|
@@ -62,6 +54,8 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
62
54
|
body: JSON.stringify({
|
|
63
55
|
asset: request.asset,
|
|
64
56
|
amount: request.amount,
|
|
57
|
+
trading_pair_id: request.tradingPairId,
|
|
58
|
+
strategy_key: request.strategyKey,
|
|
65
59
|
}),
|
|
66
60
|
});
|
|
67
61
|
}
|
|
@@ -75,7 +69,6 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
75
69
|
method: "POST",
|
|
76
70
|
body: JSON.stringify({
|
|
77
71
|
trading_pair_id: request.tradingPairId,
|
|
78
|
-
strategy_key: request.strategyKey,
|
|
79
72
|
side: request.side,
|
|
80
73
|
position_side: request.positionSide,
|
|
81
74
|
order_type: request.orderType,
|
package/dist/api/market/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Candlestick, FundingState, GetCandlesticksParams, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingPair } from "@0xmonaco/types";
|
|
1
|
+
import type { Candlestick, FundingState, GetCandlesticksParams, GetScreenerParams, GetScreenerResponse, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingPair } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
/**
|
|
4
4
|
* Market API Implementation
|
|
@@ -7,6 +7,7 @@ import { BaseAPI } from "../base";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
9
9
|
getPaginatedTradingPairs(params?: GetTradingPairsParams): Promise<GetTradingPairsResponse>;
|
|
10
|
+
getTradingPair(tradingPairId: string): Promise<TradingPair>;
|
|
10
11
|
getTradingPairBySymbol(symbol: string): Promise<TradingPair | undefined>;
|
|
11
12
|
getCandlesticks(tradingPairId: string, interval: Interval, params?: GetCandlesticksParams): Promise<Candlestick[]>;
|
|
12
13
|
getMarketMetadata(tradingPairId: string): Promise<MarketMetadata>;
|
|
@@ -17,4 +18,5 @@ export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
|
17
18
|
getFundingState(tradingPairId: string): Promise<FundingState>;
|
|
18
19
|
listFundingHistory(tradingPairId: string, params?: ListFundingHistoryParams): Promise<ListFundingHistoryResponse>;
|
|
19
20
|
getOpenInterest(tradingPairId: string): Promise<OpenInterest>;
|
|
21
|
+
getScreener(params?: GetScreenerParams): Promise<GetScreenerResponse>;
|
|
20
22
|
}
|
package/dist/api/market/api.js
CHANGED
|
@@ -31,6 +31,11 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
31
31
|
const url = queryString ? `/api/v1/market/pairs?${queryString}` : "/api/v1/market/pairs";
|
|
32
32
|
return await this.makePublicRequest(url);
|
|
33
33
|
}
|
|
34
|
+
async getTradingPair(tradingPairId) {
|
|
35
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
36
|
+
const response = await this.makePublicRequest(perpRoutes.market.getTradingPair(tradingPairId));
|
|
37
|
+
return response.trading_pair;
|
|
38
|
+
}
|
|
34
39
|
async getTradingPairBySymbol(symbol) {
|
|
35
40
|
// Backend endpoint expects UUID, not symbol, so we fetch all pairs and filter
|
|
36
41
|
const response = await this.getPaginatedTradingPairs({ page_size: 100 });
|
|
@@ -94,4 +99,7 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
94
99
|
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
95
100
|
return await this.makePublicRequest(perpRoutes.market.getOpenInterest(tradingPairId));
|
|
96
101
|
}
|
|
102
|
+
async getScreener(params) {
|
|
103
|
+
return await this.makePublicRequest(perpRoutes.market.getScreener(params));
|
|
104
|
+
}
|
|
97
105
|
}
|
|
@@ -12,7 +12,8 @@ export class OrderbookAPIImpl extends BaseAPI {
|
|
|
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
|
-
|
|
15
|
+
// `trading_pair_id` is the pair UUID; `symbol` is the display string.
|
|
16
|
+
tradingPairId: response.trading_pair_id,
|
|
16
17
|
tradingMode: response.trading_mode,
|
|
17
18
|
bids: response.data.bids.map((level) => ({
|
|
18
19
|
price: level.price,
|
|
@@ -17,7 +17,6 @@ export declare const perpRoutes: {
|
|
|
17
17
|
readonly batchCancelAllByPair: (tradingPairId: string) => string;
|
|
18
18
|
readonly batchCreate: () => string;
|
|
19
19
|
readonly batchReplace: () => string;
|
|
20
|
-
readonly createConditional: () => string;
|
|
21
20
|
readonly listConditional: (params?: {
|
|
22
21
|
margin_account_id?: string;
|
|
23
22
|
trading_pair_id?: string;
|
|
@@ -29,9 +28,14 @@ export declare const perpRoutes: {
|
|
|
29
28
|
};
|
|
30
29
|
readonly delegatedAgents: {
|
|
31
30
|
readonly list: () => string;
|
|
31
|
+
readonly owners: () => string;
|
|
32
32
|
readonly byId: (delegatedAgentId: string) => string;
|
|
33
33
|
readonly sessions: () => string;
|
|
34
34
|
};
|
|
35
|
+
readonly withdrawals: {
|
|
36
|
+
readonly initiate: () => string;
|
|
37
|
+
readonly byIndex: (withdrawalIndex: number) => string;
|
|
38
|
+
};
|
|
35
39
|
readonly market: {
|
|
36
40
|
readonly listTradingPairs: (params?: {
|
|
37
41
|
page?: number;
|
|
@@ -60,6 +64,12 @@ export declare const perpRoutes: {
|
|
|
60
64
|
page_size?: number;
|
|
61
65
|
}) => string;
|
|
62
66
|
readonly getOpenInterest: (tradingPairId: string) => string;
|
|
67
|
+
readonly getScreener: (params?: {
|
|
68
|
+
page?: number;
|
|
69
|
+
page_size?: number;
|
|
70
|
+
market_type?: string;
|
|
71
|
+
is_active?: boolean;
|
|
72
|
+
}) => string;
|
|
63
73
|
};
|
|
64
74
|
readonly orderbook: {
|
|
65
75
|
readonly get: (tradingPairId: string, params?: {
|
|
@@ -74,6 +84,7 @@ export declare const perpRoutes: {
|
|
|
74
84
|
skip?: number;
|
|
75
85
|
limit?: number;
|
|
76
86
|
}) => string;
|
|
87
|
+
readonly byId: (tradeId: string) => string;
|
|
77
88
|
readonly user: (params?: {
|
|
78
89
|
margin_account_id?: string;
|
|
79
90
|
trading_pair_id?: string;
|
|
@@ -81,6 +92,53 @@ export declare const perpRoutes: {
|
|
|
81
92
|
page_size?: number;
|
|
82
93
|
}) => string;
|
|
83
94
|
};
|
|
95
|
+
readonly applications: {
|
|
96
|
+
readonly orders: (params?: {
|
|
97
|
+
page?: number;
|
|
98
|
+
page_size?: number;
|
|
99
|
+
status?: string;
|
|
100
|
+
user_id?: string;
|
|
101
|
+
trading_pair_id?: string;
|
|
102
|
+
side?: string;
|
|
103
|
+
order_type?: string;
|
|
104
|
+
}) => string;
|
|
105
|
+
readonly users: (params?: {
|
|
106
|
+
page?: number;
|
|
107
|
+
page_size?: number;
|
|
108
|
+
is_active?: boolean;
|
|
109
|
+
account_type?: string;
|
|
110
|
+
address?: string;
|
|
111
|
+
}) => string;
|
|
112
|
+
readonly movements: (params?: {
|
|
113
|
+
page?: number;
|
|
114
|
+
page_size?: number;
|
|
115
|
+
user_id?: string;
|
|
116
|
+
transaction_type?: string;
|
|
117
|
+
entry_type?: string;
|
|
118
|
+
asset_id?: string;
|
|
119
|
+
}) => string;
|
|
120
|
+
readonly balances: (params?: {
|
|
121
|
+
page?: number;
|
|
122
|
+
page_size?: number;
|
|
123
|
+
user_id?: string;
|
|
124
|
+
asset_id?: string;
|
|
125
|
+
}) => string;
|
|
126
|
+
readonly stats: (params?: {
|
|
127
|
+
since?: string;
|
|
128
|
+
}) => string;
|
|
129
|
+
};
|
|
130
|
+
readonly subAccounts: {
|
|
131
|
+
readonly list: () => string;
|
|
132
|
+
readonly createLimit: () => string;
|
|
133
|
+
readonly getLimits: (subAccountId: string) => string;
|
|
134
|
+
readonly limit: (subAccountId: string, assetId: string) => string;
|
|
135
|
+
};
|
|
136
|
+
readonly faucet: {
|
|
137
|
+
readonly mint: () => string;
|
|
138
|
+
};
|
|
139
|
+
readonly whitelist: {
|
|
140
|
+
readonly submit: () => string;
|
|
141
|
+
};
|
|
84
142
|
readonly positions: {
|
|
85
143
|
readonly list: (params?: {
|
|
86
144
|
margin_account_id?: string;
|
|
@@ -110,8 +168,9 @@ export declare const perpRoutes: {
|
|
|
110
168
|
state?: string;
|
|
111
169
|
trading_pair_id?: string;
|
|
112
170
|
}) => string;
|
|
113
|
-
readonly
|
|
114
|
-
|
|
171
|
+
readonly summary: (marginAccountId: string, params?: {
|
|
172
|
+
trading_pair_id?: string;
|
|
173
|
+
}) => string;
|
|
115
174
|
readonly availableCollateral: (params?: {
|
|
116
175
|
asset?: string;
|
|
117
176
|
}) => string;
|
|
@@ -134,7 +193,6 @@ export declare const perpRoutes: {
|
|
|
134
193
|
readonly privateTrades: () => string;
|
|
135
194
|
readonly orders: () => string;
|
|
136
195
|
readonly positions: () => string;
|
|
137
|
-
readonly marginAccount: () => string;
|
|
138
196
|
readonly funding: () => string;
|
|
139
197
|
readonly liquidationAlerts: () => string;
|
|
140
198
|
};
|