@0xmonaco/core 0.0.0-develop-20260120180031
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 +693 -0
- package/dist/api/applications/api.d.ts +44 -0
- package/dist/api/applications/api.d.ts.map +1 -0
- package/dist/api/applications/api.js +54 -0
- package/dist/api/applications/api.js.map +1 -0
- package/dist/api/applications/index.d.ts +5 -0
- package/dist/api/applications/index.d.ts.map +1 -0
- package/dist/api/applications/index.js +5 -0
- package/dist/api/applications/index.js.map +1 -0
- package/dist/api/auth/api.d.ts +201 -0
- package/dist/api/auth/api.d.ts.map +1 -0
- package/dist/api/auth/api.js +293 -0
- package/dist/api/auth/api.js.map +1 -0
- package/dist/api/auth/index.d.ts +5 -0
- package/dist/api/auth/index.d.ts.map +1 -0
- package/dist/api/auth/index.js +5 -0
- package/dist/api/auth/index.js.map +1 -0
- package/dist/api/base.d.ts +124 -0
- package/dist/api/base.d.ts.map +1 -0
- package/dist/api/base.js +284 -0
- package/dist/api/base.js.map +1 -0
- package/dist/api/fees/api.d.ts +71 -0
- package/dist/api/fees/api.d.ts.map +1 -0
- package/dist/api/fees/api.js +83 -0
- package/dist/api/fees/api.js.map +1 -0
- package/dist/api/fees/index.d.ts +7 -0
- package/dist/api/fees/index.d.ts.map +1 -0
- package/dist/api/fees/index.js +7 -0
- package/dist/api/fees/index.js.map +1 -0
- package/dist/api/index.d.ts +16 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +16 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/market/api.d.ts +14 -0
- package/dist/api/market/api.d.ts.map +1 -0
- package/dist/api/market/api.js +70 -0
- package/dist/api/market/api.js.map +1 -0
- package/dist/api/market/index.d.ts +2 -0
- package/dist/api/market/index.d.ts.map +1 -0
- package/dist/api/market/index.js +2 -0
- package/dist/api/market/index.js.map +1 -0
- package/dist/api/orderbook/api.d.ts +16 -0
- package/dist/api/orderbook/api.d.ts.map +1 -0
- package/dist/api/orderbook/api.js +38 -0
- package/dist/api/orderbook/api.js.map +1 -0
- package/dist/api/orderbook/index.d.ts +2 -0
- package/dist/api/orderbook/index.d.ts.map +1 -0
- package/dist/api/orderbook/index.js +2 -0
- package/dist/api/orderbook/index.js.map +1 -0
- package/dist/api/profile/api.d.ts +119 -0
- package/dist/api/profile/api.d.ts.map +1 -0
- package/dist/api/profile/api.js +162 -0
- package/dist/api/profile/api.js.map +1 -0
- package/dist/api/profile/index.d.ts +7 -0
- package/dist/api/profile/index.d.ts.map +1 -0
- package/dist/api/profile/index.js +7 -0
- package/dist/api/profile/index.js.map +1 -0
- package/dist/api/trades/api.d.ts +45 -0
- package/dist/api/trades/api.d.ts.map +1 -0
- package/dist/api/trades/api.js +43 -0
- package/dist/api/trades/api.js.map +1 -0
- package/dist/api/trades/index.d.ts +2 -0
- package/dist/api/trades/index.d.ts.map +1 -0
- package/dist/api/trades/index.js +2 -0
- package/dist/api/trades/index.js.map +1 -0
- package/dist/api/trading/api.d.ts +213 -0
- package/dist/api/trading/api.d.ts.map +1 -0
- package/dist/api/trading/api.js +285 -0
- package/dist/api/trading/api.js.map +1 -0
- package/dist/api/trading/index.d.ts +5 -0
- package/dist/api/trading/index.d.ts.map +1 -0
- package/dist/api/trading/index.js +5 -0
- package/dist/api/trading/index.js.map +1 -0
- package/dist/api/vault/api.d.ts +257 -0
- package/dist/api/vault/api.d.ts.map +1 -0
- package/dist/api/vault/api.js +526 -0
- package/dist/api/vault/api.js.map +1 -0
- package/dist/api/vault/index.d.ts +5 -0
- package/dist/api/vault/index.d.ts.map +1 -0
- package/dist/api/vault/index.js +5 -0
- package/dist/api/vault/index.js.map +1 -0
- package/dist/api/websocket/index.d.ts +4 -0
- package/dist/api/websocket/index.d.ts.map +1 -0
- package/dist/api/websocket/index.js +4 -0
- package/dist/api/websocket/index.js.map +1 -0
- package/dist/api/websocket/types.d.ts +36 -0
- package/dist/api/websocket/types.d.ts.map +1 -0
- package/dist/api/websocket/types.js +2 -0
- package/dist/api/websocket/types.js.map +1 -0
- package/dist/api/websocket/utils.d.ts +9 -0
- package/dist/api/websocket/utils.d.ts.map +1 -0
- package/dist/api/websocket/utils.js +23 -0
- package/dist/api/websocket/utils.js.map +1 -0
- package/dist/api/websocket/websocket.d.ts +6 -0
- package/dist/api/websocket/websocket.d.ts.map +1 -0
- package/dist/api/websocket/websocket.js +345 -0
- package/dist/api/websocket/websocket.js.map +1 -0
- 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 +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- 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 +15 -0
- package/dist/networks/networks.d.ts.map +1 -0
- package/dist/networks/networks.js +34 -0
- package/dist/networks/networks.js.map +1 -0
- package/dist/sdk.d.ts +128 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +272 -0
- package/dist/sdk.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/magnitude.d.ts +27 -0
- package/dist/utils/magnitude.d.ts.map +1 -0
- package/dist/utils/magnitude.js +32 -0
- package/dist/utils/magnitude.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality for all API classes including access token management,
|
|
5
|
+
* authenticated request handling, and standardized error responses.
|
|
6
|
+
*
|
|
7
|
+
* This base class eliminates code duplication across API implementations and provides
|
|
8
|
+
* a consistent interface for token-based authentication and HTTP request handling.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class MyAPIImpl extends BaseAPI implements MyAPI {
|
|
13
|
+
* constructor(apiUrl: string) {
|
|
14
|
+
* super(apiUrl);
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* async getData(): Promise<any> {
|
|
18
|
+
* return this.makeAuthenticatedRequest<any>('/api/v1/data');
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export interface RetryOptions {
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
baseDelayMs?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare abstract class BaseAPI {
|
|
28
|
+
protected readonly apiUrl: string;
|
|
29
|
+
protected accessToken?: string;
|
|
30
|
+
protected retryOptions: Required<RetryOptions>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new BaseAPI instance.
|
|
33
|
+
*
|
|
34
|
+
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
35
|
+
* @param retryOptions - Configuration for retry behavior on network failures
|
|
36
|
+
*/
|
|
37
|
+
constructor(apiUrl: string, retryOptions?: RetryOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Set the access token for authenticated requests.
|
|
40
|
+
*
|
|
41
|
+
* @param token - JWT access token
|
|
42
|
+
*/
|
|
43
|
+
setAccessToken(token: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get the current access token.
|
|
46
|
+
*
|
|
47
|
+
* @returns The current access token or undefined if not set
|
|
48
|
+
*/
|
|
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;
|
|
69
|
+
/**
|
|
70
|
+
* Makes an authenticated API request with automatic token handling.
|
|
71
|
+
*
|
|
72
|
+
* This method automatically includes the Authorization header with the Bearer token
|
|
73
|
+
* and provides consistent error handling across all API operations.
|
|
74
|
+
*
|
|
75
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
76
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
77
|
+
* @returns Promise resolving to the response data
|
|
78
|
+
* @throws {APIError} When access token is not set or API request fails
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // GET request
|
|
83
|
+
* const data = await this.makeAuthenticatedRequest<UserProfile>('/api/v1/profile');
|
|
84
|
+
*
|
|
85
|
+
* // POST request
|
|
86
|
+
* const result = await this.makeAuthenticatedRequest<CreateOrderResponse>(
|
|
87
|
+
* '/api/v1/orders',
|
|
88
|
+
* {
|
|
89
|
+
* method: 'POST',
|
|
90
|
+
* body: JSON.stringify({ trading_pair: 'ETH-USD', side: 'BUY' })
|
|
91
|
+
* }
|
|
92
|
+
* );
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
protected makeAuthenticatedRequest<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Makes an unauthenticated API request.
|
|
98
|
+
*
|
|
99
|
+
* This method is useful for endpoints that don't require authentication,
|
|
100
|
+
* such as public data endpoints or authentication endpoints themselves.
|
|
101
|
+
*
|
|
102
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
103
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
104
|
+
* @returns Promise resolving to the response data
|
|
105
|
+
* @throws {APIError} When API request fails
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // Public endpoint
|
|
110
|
+
* const data = await this.makePublicRequest<PublicData>('/api/v1/public/markets');
|
|
111
|
+
*
|
|
112
|
+
* // Authentication endpoint
|
|
113
|
+
* const challenge = await this.makePublicRequest<ChallengeResponse>(
|
|
114
|
+
* '/api/v1/auth/challenge',
|
|
115
|
+
* {
|
|
116
|
+
* method: 'POST',
|
|
117
|
+
* body: JSON.stringify({ address, client_id: clientId })
|
|
118
|
+
* }
|
|
119
|
+
* );
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
protected makePublicRequest<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;IAmF5B;;;;;;;;;;;;;;;;;;;;;;;;;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
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality for all API classes including access token management,
|
|
5
|
+
* authenticated request handling, and standardized error responses.
|
|
6
|
+
*
|
|
7
|
+
* This base class eliminates code duplication across API implementations and provides
|
|
8
|
+
* a consistent interface for token-based authentication and HTTP request handling.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class MyAPIImpl extends BaseAPI implements MyAPI {
|
|
13
|
+
* constructor(apiUrl: string) {
|
|
14
|
+
* super(apiUrl);
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* async getData(): Promise<any> {
|
|
18
|
+
* return this.makeAuthenticatedRequest<any>('/api/v1/data');
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import { StatusCodes } from "http-status-codes";
|
|
24
|
+
import { APIError } from "../errors";
|
|
25
|
+
export class BaseAPI {
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new BaseAPI instance.
|
|
28
|
+
*
|
|
29
|
+
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
30
|
+
* @param retryOptions - Configuration for retry behavior on network failures
|
|
31
|
+
*/
|
|
32
|
+
constructor(apiUrl, retryOptions) {
|
|
33
|
+
this.apiUrl = apiUrl;
|
|
34
|
+
this.retryOptions = {
|
|
35
|
+
maxRetries: retryOptions?.maxRetries ?? 3,
|
|
36
|
+
baseDelayMs: retryOptions?.baseDelayMs ?? 1000,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set the access token for authenticated requests.
|
|
41
|
+
*
|
|
42
|
+
* @param token - JWT access token
|
|
43
|
+
*/
|
|
44
|
+
setAccessToken(token) {
|
|
45
|
+
this.accessToken = token;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the current access token.
|
|
49
|
+
*
|
|
50
|
+
* @returns The current access token or undefined if not set
|
|
51
|
+
*/
|
|
52
|
+
getAccessToken() {
|
|
53
|
+
return this.accessToken;
|
|
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
|
+
// Runtime validation before extracting error message from response body
|
|
186
|
+
const errorBody = responseBody !== null && typeof responseBody === "object" ? responseBody : undefined;
|
|
187
|
+
const errorMessage = (typeof errorBody?.message === "string" ? errorBody.message : undefined) ||
|
|
188
|
+
(typeof errorBody?.error === "string" ? errorBody.error : undefined) ||
|
|
189
|
+
`API request failed: ${response.status}`;
|
|
190
|
+
const { requestId, retryAfter } = this.extractResponseMetadata(response.headers);
|
|
191
|
+
throw new APIError(errorMessage, {
|
|
192
|
+
endpoint: url,
|
|
193
|
+
statusCode: response.status,
|
|
194
|
+
responseBody,
|
|
195
|
+
requestBody,
|
|
196
|
+
requestId,
|
|
197
|
+
retryAfter,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return responseBody;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Makes an authenticated API request with automatic token handling.
|
|
204
|
+
*
|
|
205
|
+
* This method automatically includes the Authorization header with the Bearer token
|
|
206
|
+
* and provides consistent error handling across all API operations.
|
|
207
|
+
*
|
|
208
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
209
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
210
|
+
* @returns Promise resolving to the response data
|
|
211
|
+
* @throws {APIError} When access token is not set or API request fails
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* // GET request
|
|
216
|
+
* const data = await this.makeAuthenticatedRequest<UserProfile>('/api/v1/profile');
|
|
217
|
+
*
|
|
218
|
+
* // POST request
|
|
219
|
+
* const result = await this.makeAuthenticatedRequest<CreateOrderResponse>(
|
|
220
|
+
* '/api/v1/orders',
|
|
221
|
+
* {
|
|
222
|
+
* method: 'POST',
|
|
223
|
+
* body: JSON.stringify({ trading_pair: 'ETH-USD', side: 'BUY' })
|
|
224
|
+
* }
|
|
225
|
+
* );
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
async makeAuthenticatedRequest(endpoint, options = {}) {
|
|
229
|
+
if (!this.accessToken) {
|
|
230
|
+
throw new APIError("Access token not set. Call setAccessToken() first.", {
|
|
231
|
+
endpoint: `${this.apiUrl}${endpoint}`,
|
|
232
|
+
statusCode: StatusCodes.UNAUTHORIZED,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
const url = `${this.apiUrl}${endpoint}`;
|
|
236
|
+
const requestBody = this.parseRequestBody(options.body);
|
|
237
|
+
return this.executeRequest(url, endpoint, {
|
|
238
|
+
...options,
|
|
239
|
+
headers: {
|
|
240
|
+
"Content-Type": "application/json",
|
|
241
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
242
|
+
...options.headers,
|
|
243
|
+
},
|
|
244
|
+
}, requestBody);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Makes an unauthenticated API request.
|
|
248
|
+
*
|
|
249
|
+
* This method is useful for endpoints that don't require authentication,
|
|
250
|
+
* such as public data endpoints or authentication endpoints themselves.
|
|
251
|
+
*
|
|
252
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
253
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
254
|
+
* @returns Promise resolving to the response data
|
|
255
|
+
* @throws {APIError} When API request fails
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* // Public endpoint
|
|
260
|
+
* const data = await this.makePublicRequest<PublicData>('/api/v1/public/markets');
|
|
261
|
+
*
|
|
262
|
+
* // Authentication endpoint
|
|
263
|
+
* const challenge = await this.makePublicRequest<ChallengeResponse>(
|
|
264
|
+
* '/api/v1/auth/challenge',
|
|
265
|
+
* {
|
|
266
|
+
* method: 'POST',
|
|
267
|
+
* body: JSON.stringify({ address, client_id: clientId })
|
|
268
|
+
* }
|
|
269
|
+
* );
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
async makePublicRequest(endpoint, options = {}) {
|
|
273
|
+
const url = `${this.apiUrl}${endpoint}`;
|
|
274
|
+
const requestBody = this.parseRequestBody(options.body);
|
|
275
|
+
return this.executeRequest(url, endpoint, {
|
|
276
|
+
...options,
|
|
277
|
+
headers: {
|
|
278
|
+
"Content-Type": "application/json",
|
|
279
|
+
...options.headers,
|
|
280
|
+
},
|
|
281
|
+
}, requestBody);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAOrC,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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AC,OAAO;aACnB;SACF,EACD,WAAW,CACZ,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACO,KAAK,CAAC,iBAAiB,CAAI,QAAgB,EAAE,UAAuB,EAAE;QAC9E,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAExD,OAAO,IAAI,CAAC,cAAc,CACxB,GAAG,EACH,QAAQ,EACR;YACE,GAAG,OAAO;YACV,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO,CAAC,OAAO;aACnB;SACF,EACD,WAAW,CACZ,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fees API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Handles fee simulation and calculation operations.
|
|
5
|
+
* All operations use JWT authentication and go through the API Gateway.
|
|
6
|
+
*
|
|
7
|
+
* This class provides a complete interface for fee-related operations on the Monaco protocol,
|
|
8
|
+
* including simulating fees before placing orders.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const feesAPI = new FeesAPIImpl(apiUrl);
|
|
13
|
+
* feesAPI.setAccessToken(jwtToken);
|
|
14
|
+
*
|
|
15
|
+
* // Simulate fees for an order
|
|
16
|
+
* const feeDetails = await feesAPI.simulateFees({
|
|
17
|
+
* trading_pair_id: "123e4567-e89b-12d3-a456-426614174000",
|
|
18
|
+
* side: "BUY",
|
|
19
|
+
* price: "40000.00",
|
|
20
|
+
* quantity: "0.5"
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import type { FeesAPI, SimulateFeeParams, SimulateFeeResponse } from "@0xmonaco/types";
|
|
25
|
+
import { BaseAPI } from "../base";
|
|
26
|
+
export declare class FeesAPIImpl extends BaseAPI implements FeesAPI {
|
|
27
|
+
/**
|
|
28
|
+
* Simulate fees for an order before placing it.
|
|
29
|
+
*
|
|
30
|
+
* Returns exact fees for that specific order including Monaco protocol fees,
|
|
31
|
+
* application fees, and total amounts the taker must pay or maker will receive.
|
|
32
|
+
*
|
|
33
|
+
* @param params - Parameters for fee simulation
|
|
34
|
+
* @param params.trading_pair_id - The trading pair UUID
|
|
35
|
+
* @param params.side - The order side ("BUY" or "SELL")
|
|
36
|
+
* @param params.price - The price per unit as string
|
|
37
|
+
* @param params.quantity - The quantity to trade as string
|
|
38
|
+
* @returns Promise resolving to SimulateFeeResponse with fee breakdown
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Simulate fees for a buy order
|
|
43
|
+
* const buyFees = await feesAPI.simulateFees({
|
|
44
|
+
* trading_pair_id: "123e4567-e89b-12d3-a456-426614174000",
|
|
45
|
+
* side: "BUY",
|
|
46
|
+
* price: "40000.00",
|
|
47
|
+
* quantity: "0.5"
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* console.log(`Notional value: ${buyFees.notional}`);
|
|
51
|
+
* console.log(`Monaco taker fee: ${buyFees.monaco_taker_fee}`);
|
|
52
|
+
* console.log(`Application taker fee: ${buyFees.application_taker_fee}`);
|
|
53
|
+
* console.log(`Total taker fees: ${buyFees.total_taker_fees}`);
|
|
54
|
+
* console.log(`Total payment required: ${buyFees.taker_total_payment}`);
|
|
55
|
+
* console.log(`Lock amount for BUY: ${buyFees.buy_order_lock_amount}`);
|
|
56
|
+
*
|
|
57
|
+
* // Simulate fees for a sell order
|
|
58
|
+
* const sellFees = await feesAPI.simulateFees({
|
|
59
|
+
* trading_pair_id: "123e4567-e89b-12d3-a456-426614174000",
|
|
60
|
+
* side: "SELL",
|
|
61
|
+
* price: "40000.00",
|
|
62
|
+
* quantity: "0.5"
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* console.log(`Maker rebate: ${sellFees.monaco_maker_rebate}`);
|
|
66
|
+
* console.log(`Maker total receipt: ${sellFees.maker_total_receipt}`);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
simulateFees(params: SimulateFeeParams): Promise<SimulateFeeResponse>;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/fees/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,WAAY,SAAQ,OAAQ,YAAW,OAAO;IACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACG,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAgB5E"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fees API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Handles fee simulation and calculation operations.
|
|
5
|
+
* All operations use JWT authentication and go through the API Gateway.
|
|
6
|
+
*
|
|
7
|
+
* This class provides a complete interface for fee-related operations on the Monaco protocol,
|
|
8
|
+
* including simulating fees before placing orders.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const feesAPI = new FeesAPIImpl(apiUrl);
|
|
13
|
+
* feesAPI.setAccessToken(jwtToken);
|
|
14
|
+
*
|
|
15
|
+
* // Simulate fees for an order
|
|
16
|
+
* const feeDetails = await feesAPI.simulateFees({
|
|
17
|
+
* trading_pair_id: "123e4567-e89b-12d3-a456-426614174000",
|
|
18
|
+
* side: "BUY",
|
|
19
|
+
* price: "40000.00",
|
|
20
|
+
* quantity: "0.5"
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { SimulateFeeParamsSchema, validate } from "@0xmonaco/types";
|
|
25
|
+
import { BaseAPI } from "../base";
|
|
26
|
+
export class FeesAPIImpl extends BaseAPI {
|
|
27
|
+
/**
|
|
28
|
+
* Simulate fees for an order before placing it.
|
|
29
|
+
*
|
|
30
|
+
* Returns exact fees for that specific order including Monaco protocol fees,
|
|
31
|
+
* application fees, and total amounts the taker must pay or maker will receive.
|
|
32
|
+
*
|
|
33
|
+
* @param params - Parameters for fee simulation
|
|
34
|
+
* @param params.trading_pair_id - The trading pair UUID
|
|
35
|
+
* @param params.side - The order side ("BUY" or "SELL")
|
|
36
|
+
* @param params.price - The price per unit as string
|
|
37
|
+
* @param params.quantity - The quantity to trade as string
|
|
38
|
+
* @returns Promise resolving to SimulateFeeResponse with fee breakdown
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Simulate fees for a buy order
|
|
43
|
+
* const buyFees = await feesAPI.simulateFees({
|
|
44
|
+
* trading_pair_id: "123e4567-e89b-12d3-a456-426614174000",
|
|
45
|
+
* side: "BUY",
|
|
46
|
+
* price: "40000.00",
|
|
47
|
+
* quantity: "0.5"
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* console.log(`Notional value: ${buyFees.notional}`);
|
|
51
|
+
* console.log(`Monaco taker fee: ${buyFees.monaco_taker_fee}`);
|
|
52
|
+
* console.log(`Application taker fee: ${buyFees.application_taker_fee}`);
|
|
53
|
+
* console.log(`Total taker fees: ${buyFees.total_taker_fees}`);
|
|
54
|
+
* console.log(`Total payment required: ${buyFees.taker_total_payment}`);
|
|
55
|
+
* console.log(`Lock amount for BUY: ${buyFees.buy_order_lock_amount}`);
|
|
56
|
+
*
|
|
57
|
+
* // Simulate fees for a sell order
|
|
58
|
+
* const sellFees = await feesAPI.simulateFees({
|
|
59
|
+
* trading_pair_id: "123e4567-e89b-12d3-a456-426614174000",
|
|
60
|
+
* side: "SELL",
|
|
61
|
+
* price: "40000.00",
|
|
62
|
+
* quantity: "0.5"
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* console.log(`Maker rebate: ${sellFees.monaco_maker_rebate}`);
|
|
66
|
+
* console.log(`Maker total receipt: ${sellFees.maker_total_receipt}`);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
async simulateFees(params) {
|
|
70
|
+
// Validate parameters using the validate helper
|
|
71
|
+
const validatedParams = validate(SimulateFeeParamsSchema, params);
|
|
72
|
+
const searchParams = new URLSearchParams();
|
|
73
|
+
searchParams.append("trading_pair_id", validatedParams.trading_pair_id);
|
|
74
|
+
searchParams.append("side", validatedParams.side);
|
|
75
|
+
searchParams.append("price", validatedParams.price);
|
|
76
|
+
searchParams.append("quantity", validatedParams.quantity);
|
|
77
|
+
const endpoint = `/api/v1/fees/simulate?${searchParams.toString()}`;
|
|
78
|
+
return await this.makeAuthenticatedRequest(endpoint, {
|
|
79
|
+
method: "GET",
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/fees/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/fees/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Module Exports
|
|
3
|
+
*
|
|
4
|
+
* This module exports the new simplified APIs for the Monaco SDK.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./applications/index";
|
|
7
|
+
export * from "./base";
|
|
8
|
+
export * from "./fees";
|
|
9
|
+
export * from "./market";
|
|
10
|
+
export * from "./orderbook";
|
|
11
|
+
export * from "./profile";
|
|
12
|
+
export * from "./trades";
|
|
13
|
+
export * from "./trading";
|
|
14
|
+
export * from "./vault";
|
|
15
|
+
export * from "./websocket";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Module Exports
|
|
3
|
+
*
|
|
4
|
+
* This module exports the new simplified APIs for the Monaco SDK.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./applications/index";
|
|
7
|
+
export * from "./base";
|
|
8
|
+
export * from "./fees";
|
|
9
|
+
export * from "./market";
|
|
10
|
+
export * from "./orderbook";
|
|
11
|
+
export * from "./profile";
|
|
12
|
+
export * from "./trades";
|
|
13
|
+
export * from "./trading";
|
|
14
|
+
export * from "./vault";
|
|
15
|
+
export * from "./websocket";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Candlestick, GetCandlesticksParams, GetTradingPairsParams, GetTradingPairsResponse, Interval, MarketAPI, MarketMetadata, TradingPair } from "@0xmonaco/types";
|
|
2
|
+
import { BaseAPI } from "../base";
|
|
3
|
+
/**
|
|
4
|
+
* Market API Implementation
|
|
5
|
+
*
|
|
6
|
+
* Provides read-only market metadata endpoints such as trading pair listings.
|
|
7
|
+
*/
|
|
8
|
+
export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
9
|
+
getPaginatedTradingPairs(params?: GetTradingPairsParams): Promise<GetTradingPairsResponse>;
|
|
10
|
+
getTradingPairBySymbol(symbol: string): Promise<TradingPair | undefined>;
|
|
11
|
+
getCandlesticks(tradingPairId: string, interval: Interval, params?: GetCandlesticksParams): Promise<Candlestick[]>;
|
|
12
|
+
getMarketMetadata(tradingPairId: string): Promise<MarketMetadata>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=api.d.ts.map
|