@0xmonaco/core 0.4.2 → 0.5.1
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 +34 -16
- package/dist/api/applications/index.d.ts +0 -1
- package/dist/api/applications/index.d.ts.map +1 -1
- package/dist/api/applications/index.js.map +1 -1
- package/dist/api/auth/index.d.ts +0 -1
- package/dist/api/auth/index.d.ts.map +1 -1
- package/dist/api/auth/index.js.map +1 -1
- package/dist/api/base.d.ts +26 -1
- package/dist/api/base.d.ts.map +1 -1
- package/dist/api/base.js +172 -42
- package/dist/api/base.js.map +1 -1
- package/dist/api/fees/api.js +3 -3
- package/dist/api/fees/api.js.map +1 -1
- package/dist/api/market/api.d.ts.map +1 -1
- package/dist/api/market/api.js +11 -2
- package/dist/api/market/api.js.map +1 -1
- package/dist/api/market/index.d.ts +0 -1
- package/dist/api/market/index.d.ts.map +1 -1
- package/dist/api/market/index.js.map +1 -1
- package/dist/api/orderbook/api.d.ts.map +1 -1
- package/dist/api/orderbook/api.js.map +1 -1
- package/dist/api/profile/api.d.ts +9 -10
- package/dist/api/profile/api.d.ts.map +1 -1
- package/dist/api/profile/api.js +16 -10
- package/dist/api/profile/api.js.map +1 -1
- package/dist/api/trades/api.d.ts +1 -1
- package/dist/api/trades/api.d.ts.map +1 -1
- package/dist/api/trades/api.js.map +1 -1
- package/dist/api/trading/api.d.ts +0 -1
- package/dist/api/trading/api.d.ts.map +1 -1
- package/dist/api/trading/api.js +9 -1
- package/dist/api/trading/api.js.map +1 -1
- package/dist/api/trading/index.d.ts +0 -1
- package/dist/api/trading/index.d.ts.map +1 -1
- package/dist/api/trading/index.js.map +1 -1
- package/dist/api/vault/api.d.ts +16 -18
- package/dist/api/vault/api.d.ts.map +1 -1
- package/dist/api/vault/api.js +56 -44
- package/dist/api/vault/api.js.map +1 -1
- package/dist/api/vault/index.d.ts +0 -1
- package/dist/api/vault/index.d.ts.map +1 -1
- package/dist/api/vault/index.js.map +1 -1
- package/dist/api/websocket/types.d.ts.map +1 -1
- package/dist/api/websocket/websocket.d.ts.map +1 -1
- package/dist/api/websocket/websocket.js +1 -6
- package/dist/api/websocket/websocket.js.map +1 -1
- package/dist/errors/errors.d.ts +382 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/errors/errors.js +801 -0
- package/dist/errors/errors.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +2 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -17
- package/dist/index.js.map +1 -1
- package/dist/networks/index.d.ts +2 -0
- package/dist/networks/index.d.ts.map +1 -0
- package/dist/networks/index.js +2 -0
- package/dist/networks/index.js.map +1 -0
- package/dist/networks/networks.d.ts.map +1 -0
- package/dist/{networks.js → networks/networks.js} +8 -3
- package/dist/networks/networks.js.map +1 -0
- package/dist/sdk.d.ts +4 -3
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +41 -52
- package/dist/sdk.js.map +1 -1
- package/package.json +5 -7
- package/dist/errors.d.ts +0 -103
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -108
- package/dist/errors.js.map +0 -1
- package/dist/networks.d.ts.map +0 -1
- package/dist/networks.js.map +0 -1
- /package/dist/{networks.d.ts → networks/networks.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -127,23 +127,47 @@ If you see an error about `TEST_PRIVATE_KEY` not being set:
|
|
|
127
127
|
|
|
128
128
|
## Network Support
|
|
129
129
|
|
|
130
|
-
The SDK supports
|
|
130
|
+
The SDK supports multiple preset networks and custom API URLs. Configure the network by providing the `network` and `seiRpcUrl` parameters:
|
|
131
|
+
|
|
132
|
+
**Preset Networks:**
|
|
133
|
+
- `"development"` - Development environment (https://develop.apimonaco.xyz)
|
|
134
|
+
- `"staging"` - Staging environment (https://staging.apimonaco.xyz)
|
|
135
|
+
- `"mainnet"` - Production environment (https://api.monaco.xyz)
|
|
136
|
+
- `"local"` - Local development (http://localhost:8080)
|
|
131
137
|
|
|
132
138
|
```typescript
|
|
133
139
|
import { MonacoSDK } from "@0xmonaco/core";
|
|
134
140
|
|
|
135
|
-
//
|
|
136
|
-
const
|
|
141
|
+
// Development configuration
|
|
142
|
+
const devSdk = new MonacoSDK({
|
|
143
|
+
walletClient,
|
|
144
|
+
network: "development",
|
|
145
|
+
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com", // Atlantic-2 testnet
|
|
146
|
+
wsUrl: "wss://develop.apimonaco.xyz/ws"
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Staging configuration
|
|
150
|
+
const stagingSdk = new MonacoSDK({
|
|
137
151
|
walletClient,
|
|
138
|
-
network: "
|
|
139
|
-
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com" // Atlantic-2 testnet
|
|
152
|
+
network: "staging",
|
|
153
|
+
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com", // Atlantic-2 testnet
|
|
154
|
+
wsUrl: "wss://staging.apimonaco.xyz/ws"
|
|
140
155
|
});
|
|
141
156
|
|
|
142
157
|
// Mainnet configuration
|
|
143
158
|
const mainnetSdk = new MonacoSDK({
|
|
144
159
|
walletClient,
|
|
145
160
|
network: "mainnet",
|
|
146
|
-
seiRpcUrl: "https://evm-rpc.sei-apis.com" // Pacific-1 mainnet
|
|
161
|
+
seiRpcUrl: "https://evm-rpc.sei-apis.com", // Pacific-1 mainnet
|
|
162
|
+
wsUrl: "wss://api.monaco.xyz/ws"
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Custom API URL
|
|
166
|
+
const customSdk = new MonacoSDK({
|
|
167
|
+
walletClient,
|
|
168
|
+
network: "https://my-custom-api.com",
|
|
169
|
+
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com",
|
|
170
|
+
wsUrl: "wss://my-custom-api.com/ws"
|
|
147
171
|
});
|
|
148
172
|
```
|
|
149
173
|
|
|
@@ -164,8 +188,9 @@ const walletClient = createWalletClient({
|
|
|
164
188
|
|
|
165
189
|
const monaco = new MonacoSDK({
|
|
166
190
|
walletClient,
|
|
167
|
-
network: "
|
|
168
|
-
seiRpcUrl: "https://evm-rpc.sei-apis.com" // or https://evm-rpc
|
|
191
|
+
network: "development", // or "staging", "mainnet"
|
|
192
|
+
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com", // or https://evm-rpc.sei-apis.com for mainnet
|
|
193
|
+
wsUrl: "wss://develop.apimonaco.xyz/ws" // or wss://staging.apimonaco.xyz/ws, wss://api.monaco.xyz/ws
|
|
169
194
|
});
|
|
170
195
|
|
|
171
196
|
// Authentication
|
|
@@ -525,7 +550,7 @@ monaco.websocket.orders.subscribeToOrderEvents("BTC/USDC", "SPOT", (event) => {
|
|
|
525
550
|
The SDK uses structured error classes for comprehensive error handling:
|
|
526
551
|
|
|
527
552
|
```typescript
|
|
528
|
-
import { APIError, ContractError
|
|
553
|
+
import { APIError, ContractError } from "@0xmonaco/core";
|
|
529
554
|
|
|
530
555
|
try {
|
|
531
556
|
await sdk.vault.deposit(token, amount);
|
|
@@ -536,11 +561,6 @@ try {
|
|
|
536
561
|
} else if (error instanceof APIError) {
|
|
537
562
|
console.error("API error:", error.message);
|
|
538
563
|
console.error("Status:", error.status);
|
|
539
|
-
} else if (error instanceof TransactionError) {
|
|
540
|
-
console.error("Transaction error:", error.message);
|
|
541
|
-
} else if (error instanceof OrderError) {
|
|
542
|
-
console.error("Order error:", error.message);
|
|
543
|
-
console.error("Market:", error.market);
|
|
544
564
|
}
|
|
545
565
|
}
|
|
546
566
|
```
|
|
@@ -549,8 +569,6 @@ try {
|
|
|
549
569
|
- `MonacoCoreError`: Base error class for all SDK errors
|
|
550
570
|
- `APIError`: API request failures and communication errors
|
|
551
571
|
- `ContractError`: Smart contract operation errors
|
|
552
|
-
- `TransactionError`: Blockchain transaction errors
|
|
553
|
-
- `OrderError`: Trading order specific errors
|
|
554
572
|
- `InvalidConfigError`: Configuration validation errors
|
|
555
573
|
- `InvalidStateError`: Invalid state or operation errors
|
|
556
574
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/applications/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/applications/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/applications/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/applications/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/api/auth/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/api/base.d.ts
CHANGED
|
@@ -20,15 +20,21 @@
|
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
+
export interface RetryOptions {
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
baseDelayMs?: number;
|
|
26
|
+
}
|
|
23
27
|
export declare abstract class BaseAPI {
|
|
24
28
|
protected readonly apiUrl: string;
|
|
25
29
|
protected accessToken?: string;
|
|
30
|
+
protected retryOptions: Required<RetryOptions>;
|
|
26
31
|
/**
|
|
27
32
|
* Creates a new BaseAPI instance.
|
|
28
33
|
*
|
|
29
34
|
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
35
|
+
* @param retryOptions - Configuration for retry behavior on network failures
|
|
30
36
|
*/
|
|
31
|
-
constructor(apiUrl: string);
|
|
37
|
+
constructor(apiUrl: string, retryOptions?: RetryOptions);
|
|
32
38
|
/**
|
|
33
39
|
* Set the access token for authenticated requests.
|
|
34
40
|
*
|
|
@@ -41,6 +47,25 @@ export declare abstract class BaseAPI {
|
|
|
41
47
|
* @returns The current access token or undefined if not set
|
|
42
48
|
*/
|
|
43
49
|
protected getAccessToken(): string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Parse request body for error logging
|
|
52
|
+
*
|
|
53
|
+
* Attempts to extract meaningful data from various BodyInit types for debugging.
|
|
54
|
+
* Note: Binary data (Blob, ArrayBuffer, ReadableStream) is logged as metadata only
|
|
55
|
+
* to avoid performance issues and maintain log readability.
|
|
56
|
+
*
|
|
57
|
+
* @param body - Request body from fetch options
|
|
58
|
+
* @returns Parsed body for logging, or metadata for binary types
|
|
59
|
+
*/
|
|
60
|
+
private parseRequestBody;
|
|
61
|
+
/**
|
|
62
|
+
* Extract metadata from response headers
|
|
63
|
+
*/
|
|
64
|
+
private extractResponseMetadata;
|
|
65
|
+
/**
|
|
66
|
+
* Execute HTTP request with error handling
|
|
67
|
+
*/
|
|
68
|
+
private executeRequest;
|
|
44
69
|
/**
|
|
45
70
|
* Makes an authenticated API request with automatic token handling.
|
|
46
71
|
*
|
package/dist/api/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,8BAAsB,OAAO;IAWzB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAVnC,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAE/C;;;;;OAKG;gBAEkB,MAAM,EAAE,MAAM,EACjC,YAAY,CAAC,EAAE,YAAY;IAQ7B;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAInC;;;;OAIG;IACH,SAAS,CAAC,cAAc,IAAI,MAAM,GAAG,SAAS;IAI9C;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;IAkDxB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAgB/B;;OAEG;YACW,cAAc;IA8E5B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;cACa,wBAAwB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,CAAC;IA0BpG;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;cACa,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,CAAC;CAiB9F"}
|
package/dist/api/base.js
CHANGED
|
@@ -21,14 +21,20 @@
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
import { APIError } from "../errors";
|
|
24
|
+
import { StatusCodes } from "http-status-codes";
|
|
24
25
|
export class BaseAPI {
|
|
25
26
|
/**
|
|
26
27
|
* Creates a new BaseAPI instance.
|
|
27
28
|
*
|
|
28
29
|
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
30
|
+
* @param retryOptions - Configuration for retry behavior on network failures
|
|
29
31
|
*/
|
|
30
|
-
constructor(apiUrl) {
|
|
32
|
+
constructor(apiUrl, retryOptions) {
|
|
31
33
|
this.apiUrl = apiUrl;
|
|
34
|
+
this.retryOptions = {
|
|
35
|
+
maxRetries: retryOptions?.maxRetries ?? 3,
|
|
36
|
+
baseDelayMs: retryOptions?.baseDelayMs ?? 1000,
|
|
37
|
+
};
|
|
32
38
|
}
|
|
33
39
|
/**
|
|
34
40
|
* Set the access token for authenticated requests.
|
|
@@ -46,6 +52,149 @@ export class BaseAPI {
|
|
|
46
52
|
getAccessToken() {
|
|
47
53
|
return this.accessToken;
|
|
48
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Parse request body for error logging
|
|
57
|
+
*
|
|
58
|
+
* Attempts to extract meaningful data from various BodyInit types for debugging.
|
|
59
|
+
* Note: Binary data (Blob, ArrayBuffer, ReadableStream) is logged as metadata only
|
|
60
|
+
* to avoid performance issues and maintain log readability.
|
|
61
|
+
*
|
|
62
|
+
* @param body - Request body from fetch options
|
|
63
|
+
* @returns Parsed body for logging, or metadata for binary types
|
|
64
|
+
*/
|
|
65
|
+
parseRequestBody(body) {
|
|
66
|
+
if (!body)
|
|
67
|
+
return undefined;
|
|
68
|
+
// String bodies (most common case) - parse as JSON if possible
|
|
69
|
+
if (typeof body === "string") {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(body);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return body; // Return as-is if not valid JSON
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// FormData - convert to object for logging
|
|
78
|
+
if (body instanceof FormData) {
|
|
79
|
+
const formObject = {};
|
|
80
|
+
body.forEach((value, key) => {
|
|
81
|
+
formObject[key] = value instanceof File ? `[File: ${value.name}]` : value;
|
|
82
|
+
});
|
|
83
|
+
return formObject;
|
|
84
|
+
}
|
|
85
|
+
// URLSearchParams - convert to object
|
|
86
|
+
if (body instanceof URLSearchParams) {
|
|
87
|
+
const params = {};
|
|
88
|
+
body.forEach((value, key) => {
|
|
89
|
+
params[key] = value;
|
|
90
|
+
});
|
|
91
|
+
return params;
|
|
92
|
+
}
|
|
93
|
+
// Blob - log metadata only (avoid reading binary data)
|
|
94
|
+
if (body instanceof Blob) {
|
|
95
|
+
return { type: "[Blob]", size: body.size, contentType: body.type };
|
|
96
|
+
}
|
|
97
|
+
// ArrayBuffer/ArrayBufferView - log metadata only
|
|
98
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {
|
|
99
|
+
const size = body instanceof ArrayBuffer ? body.byteLength : body.byteLength;
|
|
100
|
+
return { type: "[ArrayBuffer]", size };
|
|
101
|
+
}
|
|
102
|
+
// ReadableStream - log metadata only (cannot read without consuming)
|
|
103
|
+
if (typeof ReadableStream !== "undefined" && body instanceof ReadableStream) {
|
|
104
|
+
return { type: "[ReadableStream]", note: "Stream body not captured for logging" };
|
|
105
|
+
}
|
|
106
|
+
// Fallback for unknown types
|
|
107
|
+
return { type: "[Unknown]", bodyType: typeof body };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Extract metadata from response headers
|
|
111
|
+
*/
|
|
112
|
+
extractResponseMetadata(headers) {
|
|
113
|
+
if (!headers)
|
|
114
|
+
return {};
|
|
115
|
+
const requestId = headers.get("x-request-id") || headers.get("request-id") || headers.get("x-correlation-id") || undefined;
|
|
116
|
+
// Parse Retry-After header with validation
|
|
117
|
+
const retryAfterHeader = headers.get("retry-after");
|
|
118
|
+
let retryAfter;
|
|
119
|
+
if (retryAfterHeader !== null) {
|
|
120
|
+
const parsed = Number.parseInt(retryAfterHeader, 10);
|
|
121
|
+
retryAfter = Number.isNaN(parsed) ? undefined : parsed;
|
|
122
|
+
}
|
|
123
|
+
return { requestId, retryAfter };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Execute HTTP request with error handling
|
|
127
|
+
*/
|
|
128
|
+
async executeRequest(url, endpoint, options, requestBody) {
|
|
129
|
+
let response;
|
|
130
|
+
try {
|
|
131
|
+
response = await fetch(url, options);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
throw new APIError(`Network request failed for ${endpoint}`, {
|
|
135
|
+
endpoint: url,
|
|
136
|
+
cause: error instanceof Error ? error : new Error(String(error)),
|
|
137
|
+
requestBody,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// Parse response body with error handling for non-JSON responses
|
|
141
|
+
let responseBody;
|
|
142
|
+
const contentType = response.headers?.get("content-type") || "unknown";
|
|
143
|
+
// Clone the response to avoid consuming the body stream twice (if clone method exists)
|
|
144
|
+
const responseClone = response.clone ? response.clone() : response;
|
|
145
|
+
try {
|
|
146
|
+
responseBody = await response.json();
|
|
147
|
+
}
|
|
148
|
+
catch (parseError) {
|
|
149
|
+
// If JSON parsing fails, try to get response as text for better error messages
|
|
150
|
+
let responseText;
|
|
151
|
+
try {
|
|
152
|
+
responseText = await responseClone.text();
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
responseText = "[Unable to read response body]";
|
|
156
|
+
}
|
|
157
|
+
// If response is not OK and we can't parse JSON, it's likely an error page (HTML, plain text, etc.)
|
|
158
|
+
if (!response.ok) {
|
|
159
|
+
const errorMessage = `API request failed: ${response.status}. Response is not JSON (Content-Type: ${contentType})`;
|
|
160
|
+
const { requestId, retryAfter } = this.extractResponseMetadata(response.headers);
|
|
161
|
+
throw new APIError(errorMessage, {
|
|
162
|
+
endpoint: url,
|
|
163
|
+
statusCode: response.status,
|
|
164
|
+
responseBody: {
|
|
165
|
+
rawResponse: responseText.substring(0, 500), // Limit to 500 chars to avoid huge error logs
|
|
166
|
+
contentType,
|
|
167
|
+
parseError: parseError instanceof Error ? parseError.message : String(parseError),
|
|
168
|
+
},
|
|
169
|
+
cause: parseError instanceof Error ? parseError : undefined,
|
|
170
|
+
requestBody,
|
|
171
|
+
requestId,
|
|
172
|
+
retryAfter,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
// If response is OK but not JSON, throw a more specific error
|
|
176
|
+
throw new APIError(`Expected JSON response but received ${contentType}`, {
|
|
177
|
+
endpoint: url,
|
|
178
|
+
statusCode: response.status,
|
|
179
|
+
responseBody: { rawResponse: responseText.substring(0, 500), contentType },
|
|
180
|
+
cause: parseError instanceof Error ? parseError : undefined,
|
|
181
|
+
requestBody,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (!response.ok) {
|
|
185
|
+
const errorMessage = responseBody?.message || responseBody?.error || `API request failed: ${response.status}`;
|
|
186
|
+
const { requestId, retryAfter } = this.extractResponseMetadata(response.headers);
|
|
187
|
+
throw new APIError(errorMessage, {
|
|
188
|
+
endpoint: url,
|
|
189
|
+
statusCode: response.status,
|
|
190
|
+
responseBody,
|
|
191
|
+
requestBody,
|
|
192
|
+
requestId,
|
|
193
|
+
retryAfter,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return responseBody;
|
|
197
|
+
}
|
|
49
198
|
/**
|
|
50
199
|
* Makes an authenticated API request with automatic token handling.
|
|
51
200
|
*
|
|
@@ -74,30 +223,21 @@ export class BaseAPI {
|
|
|
74
223
|
*/
|
|
75
224
|
async makeAuthenticatedRequest(endpoint, options = {}) {
|
|
76
225
|
if (!this.accessToken) {
|
|
77
|
-
throw new APIError("Access token not set. Call setAccessToken() first.",
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
response = await fetch(`${this.apiUrl}${endpoint}`, {
|
|
82
|
-
headers: {
|
|
83
|
-
"Content-Type": "application/json",
|
|
84
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
85
|
-
...options.headers,
|
|
86
|
-
},
|
|
87
|
-
...options,
|
|
226
|
+
throw new APIError("Access token not set. Call setAccessToken() first.", {
|
|
227
|
+
endpoint: `${this.apiUrl}${endpoint}`,
|
|
228
|
+
statusCode: StatusCodes.UNAUTHORIZED,
|
|
88
229
|
});
|
|
89
230
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
return responseBody;
|
|
231
|
+
const url = `${this.apiUrl}${endpoint}`;
|
|
232
|
+
const requestBody = this.parseRequestBody(options.body);
|
|
233
|
+
return this.executeRequest(url, endpoint, {
|
|
234
|
+
...options,
|
|
235
|
+
headers: {
|
|
236
|
+
"Content-Type": "application/json",
|
|
237
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
238
|
+
...options.headers,
|
|
239
|
+
},
|
|
240
|
+
}, requestBody);
|
|
101
241
|
}
|
|
102
242
|
/**
|
|
103
243
|
* Makes an unauthenticated API request.
|
|
@@ -126,25 +266,15 @@ export class BaseAPI {
|
|
|
126
266
|
* ```
|
|
127
267
|
*/
|
|
128
268
|
async makePublicRequest(endpoint, options = {}) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
throw new APIError(`Network request failed for ${endpoint}`, `${this.apiUrl}${endpoint}`, undefined, undefined, error instanceof Error ? error : new Error(String(error)));
|
|
141
|
-
}
|
|
142
|
-
const responseBody = await response.json();
|
|
143
|
-
if (!response.ok) {
|
|
144
|
-
const errorMessage = responseBody?.message || responseBody?.error || `API request failed: ${response.status}`;
|
|
145
|
-
throw new APIError(errorMessage, `${this.apiUrl}${endpoint}`, response.status, responseBody);
|
|
146
|
-
}
|
|
147
|
-
return responseBody;
|
|
269
|
+
const url = `${this.apiUrl}${endpoint}`;
|
|
270
|
+
const requestBody = this.parseRequestBody(options.body);
|
|
271
|
+
return this.executeRequest(url, endpoint, {
|
|
272
|
+
...options,
|
|
273
|
+
headers: {
|
|
274
|
+
"Content-Type": "application/json",
|
|
275
|
+
...options.headers,
|
|
276
|
+
},
|
|
277
|
+
}, requestBody);
|
|
148
278
|
}
|
|
149
279
|
}
|
|
150
280
|
//# sourceMappingURL=base.js.map
|
package/dist/api/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,MAAM,OAAgB,OAAO;IAI3B;;;;;OAKG;IACH,YACqB,MAAc,EACjC,YAA2B;QADR,WAAM,GAAN,MAAM,CAAQ;QAGjC,IAAI,CAAC,YAAY,GAAG;YAClB,UAAU,EAAE,YAAY,EAAE,UAAU,IAAI,CAAC;YACzC,WAAW,EAAE,YAAY,EAAE,WAAW,IAAI,IAAI;SAC/C,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,KAAa;QAC1B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACO,cAAc;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;;;;;;;OASG;IACK,gBAAgB,CAAC,IAAsB;QAC7C,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAE5B,+DAA+D;Q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-21,7 +21,7 @@
|
|
|
21
21
|
* });
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
import { SimulateFeeParamsSchema } from "@0xmonaco/types";
|
|
24
|
+
import { SimulateFeeParamsSchema, validate } from "@0xmonaco/types";
|
|
25
25
|
import { BaseAPI } from "../base";
|
|
26
26
|
export class FeesAPIImpl extends BaseAPI {
|
|
27
27
|
/**
|
|
@@ -67,8 +67,8 @@ export class FeesAPIImpl extends BaseAPI {
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
async simulateFees(params) {
|
|
70
|
-
// Validate parameters using
|
|
71
|
-
const validatedParams = SimulateFeeParamsSchema
|
|
70
|
+
// Validate parameters using the validate helper
|
|
71
|
+
const validatedParams = validate(SimulateFeeParamsSchema, params);
|
|
72
72
|
const searchParams = new URLSearchParams();
|
|
73
73
|
searchParams.append("trading_pair_id", validatedParams.trading_pair_id);
|
|
74
74
|
searchParams.append("side", validatedParams.side);
|
package/dist/api/fees/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/fees/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/fees/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,OAAO,WAAY,SAAQ,OAAO;IACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,KAAK,CAAC,YAAY,CAAC,MAAyB;QAC1C,gDAAgD;QAChD,MAAM,eAAe,GAAG,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;QAElE,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAC;QAC3C,YAAY,CAAC,MAAM,CAAC,iBAAiB,EAAE,eAAe,CAAC,eAAe,CAAC,CAAC;QACxE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;QACpD,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;QAE1D,MAAM,QAAQ,GAAG,yBAAyB,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC;QAEpE,OAAO,MAAM,IAAI,CAAC,wBAAwB,CAAsB,QAAQ,EAAE;YACxE,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA0B,qBAAqB,EAAE,uBAAuB,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE7J,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,OAAQ,YAAW,SAAS;IACvD,wBAAwB,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IA4B1F,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAMxE,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAoBtH"}
|
package/dist/api/market/api.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GetCandlesticksBySymbolSchema, validate } from "@0xmonaco/types";
|
|
1
2
|
import { BaseAPI } from "../base";
|
|
2
3
|
/**
|
|
3
4
|
* Market API Implementation
|
|
@@ -30,10 +31,18 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
30
31
|
return await this.makePublicRequest(url);
|
|
31
32
|
}
|
|
32
33
|
async getTradingPairBySymbol(symbol) {
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
// Backend endpoint expects UUID, not symbol, so we fetch all pairs and filter
|
|
35
|
+
const response = await this.getPaginatedTradingPairs({ limit: 100 });
|
|
36
|
+
return response.data.data.find((pair) => pair.symbol === symbol);
|
|
35
37
|
}
|
|
36
38
|
async getCandlesticks(symbol, interval, startTime, endTime) {
|
|
39
|
+
// Validate inputs using the symbol-based schema
|
|
40
|
+
validate(GetCandlesticksBySymbolSchema, {
|
|
41
|
+
symbol,
|
|
42
|
+
interval,
|
|
43
|
+
startTime,
|
|
44
|
+
endTime,
|
|
45
|
+
});
|
|
37
46
|
const params = new URLSearchParams();
|
|
38
47
|
params.append("start_time", startTime.toString());
|
|
39
48
|
params.append("end_time", endTime.toString());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,OAAO;IACxC,KAAK,CAAC,wBAAwB,C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,CAAC,wBAAwB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACrE,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,MAAc,EAAE,QAAkB,EAAE,SAAiB,EAAE,OAAe;QAC1F,gDAAgD;QAChD,QAAQ,CAAC,6BAA6B,EAAE;YACtC,MAAM;YACN,QAAQ;YACR,SAAS;YACT,OAAO;SACR,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAClD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAE9C,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,2CAA2C,kBAAkB,CAAC,MAAM,CAAC,IAAI,QAAQ,IAAI,WAAW,EAAE,CAAC;QAE/G,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAyB,GAAG,CAAC,CAAC;QAE3E,OAAO,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/market/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/market/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/market/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/market/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/orderbook/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAmBlC,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,iGAAiG;IACjG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,YAAY,CAAC,EAAE,sBAAsB,CAAC;CACvC;AAED,qBAAa,gBAAiB,SAAQ,OAAO;IACrC,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/orderbook/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAmBlC,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,iGAAiG;IACjG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,YAAY,CAAC,EAAE,sBAAsB,CAAC;CACvC;AAED,qBAAa,gBAAiB,SAAQ,OAAO;IACrC,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC;CAkCtG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/orderbook/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AA8BlC,MAAM,OAAO,gBAAiB,SAAQ,OAAO;IAC3C,KAAK,CAAC,YAAY,CAAC,aAAqB,EAAE,UAA+B,EAAE;QACzE,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAErE,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACpC,IAAI,WAAW;YAAE,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;QACzD,IAAI,SAAS,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QACxE,IAAI,YAAY;YAAE,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC;QAEzE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/orderbook/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AA8BlC,MAAM,OAAO,gBAAiB,SAAQ,OAAO;IAC3C,KAAK,CAAC,YAAY,CAAC,aAAqB,EAAE,UAA+B,EAAE;QACzE,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;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AAE,QAAQ,CAAC,IAAI,CAAC,UAAU;YACnC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU;YACnC,YAAY,EAAE,QAAQ,CAAC,aAAa;YACpC,aAAa,EAAE,QAAQ,CAAC,cAAc;YACtC,SAAS,EAAE,QAAQ,CAAC,SAAS;YAC7B,QAAQ,EAAE,QAAQ,CAAC,eAAe;SACnC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
import type { AccountBalance, GetPaginatedUserMovementsResponse, GetUserBalancesParams, GetUserBalancesResponse, GetUserMovementsParams, ProfileAPI, UserProfile } from "@0xmonaco/types";
|
|
21
|
-
import type { Address } from "viem";
|
|
22
21
|
import { BaseAPI } from "../base";
|
|
23
22
|
export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
|
|
24
23
|
/**
|
|
@@ -97,24 +96,24 @@ export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
|
|
|
97
96
|
*/
|
|
98
97
|
getUserBalances(params?: GetUserBalancesParams): Promise<GetUserBalancesResponse>;
|
|
99
98
|
/**
|
|
100
|
-
* Get the current user's balance for a specific
|
|
99
|
+
* Get the current user's balance for a specific asset.
|
|
101
100
|
*
|
|
102
|
-
* Fetches the user's balance for a specific
|
|
103
|
-
* Requires a valid access token to be set.
|
|
101
|
+
* Fetches the user's balance for a specific asset from the /api/v1/accounts/balances/{asset_id} endpoint.
|
|
102
|
+
* Requires a valid access token to be set. If no balance exists for a valid asset, returns zero balances.
|
|
104
103
|
*
|
|
105
|
-
* @param
|
|
106
|
-
* @returns Promise resolving to the
|
|
107
|
-
* @throws {APIError} When the request fails, user is not authenticated, or
|
|
104
|
+
* @param assetId - The asset identifier (UUID)
|
|
105
|
+
* @returns Promise resolving to the account balance for the asset
|
|
106
|
+
* @throws {APIError} When the request fails, user is not authenticated, or asset not found (404)
|
|
108
107
|
*
|
|
109
108
|
* @example
|
|
110
109
|
* ```typescript
|
|
111
|
-
* // Get balance for a specific
|
|
112
|
-
* const balance = await profileAPI.
|
|
110
|
+
* // Get balance for a specific asset
|
|
111
|
+
* const balance = await profileAPI.getUserBalanceByAssetId('123e4567-e89b-12d3-a456-426614174000');
|
|
113
112
|
* console.log(`${balance.symbol}: ${balance.available_balance}`);
|
|
114
113
|
* console.log(`Locked: ${balance.locked_balance}`);
|
|
115
114
|
* console.log(`Total: ${balance.total_balance}`);
|
|
116
115
|
* ```
|
|
117
116
|
*/
|
|
118
|
-
|
|
117
|
+
getUserBalanceByAssetId(assetId: string): Promise<AccountBalance>;
|
|
119
118
|
}
|
|
120
119
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/profile/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,iCAAiC,EACjC,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,UAAU,EACV,WAAW,EACZ,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/profile/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,iCAAiC,EACjC,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,UAAU,EACV,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,cAAe,SAAQ,OAAQ,YAAW,UAAU;IAC/D;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;IAgBxC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,yBAAyB,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,iCAAiC,CAAC;IAgB5G;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,eAAe,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAgBvF;;;;;;;;;;;;;;;;;;OAkBG;IACG,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CASxE"}
|