@0xmonaco/core 0.0.0-develop-20260318132113 → 0.0.0-develop-20260412233650

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 CHANGED
@@ -125,7 +125,7 @@ async function authExample() {
125
125
  console.log("Authenticated:", authState.user);
126
126
  console.log("Tokens:", {
127
127
  accessToken: authState.accessToken,
128
- refreshToken: authState.refreshToken, // Use this for revokeToken()
128
+ refreshToken: authState.refreshToken,
129
129
  });
130
130
 
131
131
  // Authenticated WebSocket channels are now connected - start receiving real-time updates
@@ -141,8 +141,7 @@ async function authExample() {
141
141
  await monaco.logout();
142
142
 
143
143
  // Or manually revoke the token
144
- // ✅ CORRECT: Use authState.refreshToken
145
- await monaco.auth.revokeToken(authState.refreshToken);
144
+ await monaco.auth.revokeToken();
146
145
  }
147
146
 
148
147
  // Market Data
@@ -277,11 +276,9 @@ interface AuthState {
277
276
  }
278
277
  ```
279
278
 
280
- **⚠️ Important:** The authentication response contains `refreshToken`, NOT `revokeToken`.
281
-
282
279
  ```typescript
283
- // CORRECT: Revoke using refreshToken
284
- await sdk.auth.revokeToken(authState.refreshToken);
280
+ // Revoke the current session's token
281
+ await sdk.auth.revokeToken();
285
282
 
286
283
  // 💡 TIP: Use the built-in logout method
287
284
  await sdk.logout(); // Automatically calls revokeToken internally
@@ -182,14 +182,15 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
182
182
  */
183
183
  refreshToken(refreshToken: string): Promise<TokenRefreshResponse>;
184
184
  /**
185
- * Revokes a refresh token.
185
+ * Revokes the current session's refresh token.
186
186
  *
187
- * Invalidates a refresh token, preventing it from being used to obtain
188
- * new access tokens. This is useful for logout functionality or when
189
- * a token has been compromised.
187
+ * Invalidates the refresh token associated with the current access token,
188
+ * preventing it from being used to obtain new access tokens. This is useful
189
+ * for logout functionality or when a token has been compromised.
190
+ *
191
+ * The server identifies the token to revoke from the access token in the
192
+ * Authorization header — no request body is needed.
190
193
  *
191
- * **Important:** Pass the `refreshToken` from the authentication response.
192
- * @param refreshToken - The refresh token to revoke (from authResult.refreshToken)
193
194
  * @returns Promise resolving when the token is revoked
194
195
  * @throws {APIError} When token revocation fails
195
196
  *
@@ -197,9 +198,9 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
197
198
  * ```typescript
198
199
  * // After authentication
199
200
  * const authResult = await authAPI.authenticate(clientId);
200
- * await authAPI.revokeToken(authResult.refreshToken);
201
+ * await authAPI.revokeToken();
201
202
  * console.log("Token revoked successfully");
202
203
  * ```
203
204
  */
204
- revokeToken(refreshToken: string): Promise<void>;
205
+ revokeToken(): Promise<void>;
205
206
  }
@@ -277,14 +277,15 @@ export class AuthAPIImpl extends BaseAPI {
277
277
  };
278
278
  }
279
279
  /**
280
- * Revokes a refresh token.
280
+ * Revokes the current session's refresh token.
281
281
  *
282
- * Invalidates a refresh token, preventing it from being used to obtain
283
- * new access tokens. This is useful for logout functionality or when
284
- * a token has been compromised.
282
+ * Invalidates the refresh token associated with the current access token,
283
+ * preventing it from being used to obtain new access tokens. This is useful
284
+ * for logout functionality or when a token has been compromised.
285
+ *
286
+ * The server identifies the token to revoke from the access token in the
287
+ * Authorization header — no request body is needed.
285
288
  *
286
- * **Important:** Pass the `refreshToken` from the authentication response.
287
- * @param refreshToken - The refresh token to revoke (from authResult.refreshToken)
288
289
  * @returns Promise resolving when the token is revoked
289
290
  * @throws {APIError} When token revocation fails
290
291
  *
@@ -292,16 +293,13 @@ export class AuthAPIImpl extends BaseAPI {
292
293
  * ```typescript
293
294
  * // After authentication
294
295
  * const authResult = await authAPI.authenticate(clientId);
295
- * await authAPI.revokeToken(authResult.refreshToken);
296
+ * await authAPI.revokeToken();
296
297
  * console.log("Token revoked successfully");
297
298
  * ```
298
299
  */
299
- async revokeToken(refreshToken) {
300
+ async revokeToken() {
300
301
  await this.makeAuthenticatedRequest("/api/v1/auth/revoke", {
301
302
  method: "POST",
302
- body: JSON.stringify({
303
- refresh_token: refreshToken,
304
- }),
305
303
  });
306
304
  }
307
305
  }
@@ -35,6 +35,8 @@ export declare class FeesAPIImpl extends BaseAPI implements FeesAPI {
35
35
  * @param params.side - The order side ("BUY" or "SELL")
36
36
  * @param params.price - The price per unit as string
37
37
  * @param params.quantity - The quantity to trade as string
38
+ * @param params.order_type - Order type: "LIMIT" (default) or "MARKET"
39
+ * @param params.slippage_tolerance_bps - Slippage tolerance in bps (0–1000, MARKET only, default 500)
38
40
  * @returns Promise resolving to SimulateFeeResponse with fee breakdown
39
41
  *
40
42
  * @example
@@ -35,6 +35,8 @@ export class FeesAPIImpl extends BaseAPI {
35
35
  * @param params.side - The order side ("BUY" or "SELL")
36
36
  * @param params.price - The price per unit as string
37
37
  * @param params.quantity - The quantity to trade as string
38
+ * @param params.order_type - Order type: "LIMIT" (default) or "MARKET"
39
+ * @param params.slippage_tolerance_bps - Slippage tolerance in bps (0–1000, MARKET only, default 500)
38
40
  * @returns Promise resolving to SimulateFeeResponse with fee breakdown
39
41
  *
40
42
  * @example
@@ -74,6 +76,12 @@ export class FeesAPIImpl extends BaseAPI {
74
76
  searchParams.append("side", validatedParams.side);
75
77
  searchParams.append("price", validatedParams.price);
76
78
  searchParams.append("quantity", validatedParams.quantity);
79
+ if (validatedParams.order_type !== undefined) {
80
+ searchParams.append("order_type", validatedParams.order_type);
81
+ }
82
+ if (validatedParams.slippage_tolerance_bps !== undefined) {
83
+ searchParams.append("slippage_tolerance_bps", String(validatedParams.slippage_tolerance_bps));
84
+ }
77
85
  const endpoint = `/api/v1/fees/simulate?${searchParams.toString()}`;
78
86
  return await this.makeAuthenticatedRequest(endpoint, {
79
87
  method: "GET",
@@ -17,7 +17,7 @@
17
17
  * console.log(`User: ${profile.username} (${profile.address})`);
18
18
  * ```
19
19
  */
20
- import type { AccountBalance, GetPaginatedUserMovementsResponse, GetUserBalancesParams, GetUserBalancesResponse, GetUserMovementsParams, ProfileAPI, UserProfile } from "@0xmonaco/types";
20
+ import type { AccountBalance, GetPaginatedUserMovementsResponse, GetUserBalancesParams, GetUserBalancesResponse, GetUserMovementsParams, GetUserTradesParams, GetUserTradesResponse, PortfolioChartResponse, PortfolioMetric, PortfolioPeriod, PortfolioStats, ProfileAPI, UserProfile } from "@0xmonaco/types";
21
21
  import { BaseAPI } from "../base";
22
22
  export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
23
23
  /**
@@ -124,4 +124,68 @@ export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
124
124
  * ```
125
125
  */
126
126
  getUserBalanceByAssetId(assetId: string): Promise<AccountBalance>;
127
+ /**
128
+ * Get the current user's portfolio statistics for a given time period.
129
+ *
130
+ * Fetches aggregate stats from the /api/v1/accounts/me/portfolio endpoint.
131
+ * Requires a valid access token to be set.
132
+ *
133
+ * @param period - Time period to scope the stats ("24h" | "7d" | "30d" | "all")
134
+ * @returns Promise resolving to the user's portfolio statistics
135
+ * @throws {APIError} When the request fails or user is not authenticated
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const stats = await profileAPI.getPortfolioStats("30d");
140
+ * console.log(`PnL: ${stats.pnl}`);
141
+ * console.log(`Volume: ${stats.volume}`);
142
+ * console.log(`Total equity: ${stats.total_equity}`);
143
+ * ```
144
+ */
145
+ getPortfolioStats(period: PortfolioPeriod): Promise<PortfolioStats>;
146
+ /**
147
+ * Get the current user's portfolio chart time series for a given period and metric.
148
+ *
149
+ * Fetches bucketed time series data from the /api/v1/accounts/me/portfolio/chart endpoint.
150
+ * Requires a valid access token to be set.
151
+ *
152
+ * @param period - Time period ("24h" | "7d" | "30d" | "all")
153
+ * @param metric - Metric to chart ("volume" | "pnl")
154
+ * @returns Promise resolving to the portfolio chart response
155
+ * @throws {APIError} When the request fails or user is not authenticated
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const chart = await profileAPI.getPortfolioChart("7d", "pnl");
160
+ * chart.data.forEach(point => {
161
+ * console.log(`${point.timestamp}: ${point.value}`);
162
+ * });
163
+ * ```
164
+ */
165
+ getPortfolioChart(period: PortfolioPeriod, metric: PortfolioMetric): Promise<PortfolioChartResponse>;
166
+ /**
167
+ * Get the current user's trade history with pagination.
168
+ *
169
+ * Fetches the user's executed trades from the /api/v1/accounts/trades endpoint.
170
+ * Requires a valid access token to be set.
171
+ *
172
+ * @param params - Optional query parameters for pagination and filtering
173
+ * @param params.page - Page number (starts from 1, default: 1)
174
+ * @param params.limit - Number of items per page (default: 20, max: 100)
175
+ * @param params.trading_pair_id - Filter by trading pair ID (UUID)
176
+ * @returns Promise resolving to paginated trades response
177
+ * @throws {ValidationError} When the provided params fail client-side validation
178
+ * @throws {APIError} When the request fails or user is not authenticated
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Get first page of trades
183
+ * const trades = await profileAPI.getUserTrades();
184
+ * console.log(`Total trades: ${trades.total_count}`);
185
+ *
186
+ * // Filter by trading pair
187
+ * const pairTrades = await profileAPI.getUserTrades({ trading_pair_id: "550e8400-e29b-41d4-a716-446655440000" });
188
+ * ```
189
+ */
190
+ getUserTrades(params?: GetUserTradesParams): Promise<GetUserTradesResponse>;
127
191
  }
@@ -17,7 +17,7 @@
17
17
  * console.log(`User: ${profile.username} (${profile.address})`);
18
18
  * ```
19
19
  */
20
- import { GetUserMovementsSchema, validate } from "@0xmonaco/types";
20
+ import { GetUserMovementsSchema, GetUserTradesSchema, validate } from "@0xmonaco/types";
21
21
  import { APIError } from "../../errors";
22
22
  import { BaseAPI } from "../base";
23
23
  export class ProfileAPIImpl extends BaseAPI {
@@ -169,4 +169,91 @@ export class ProfileAPIImpl extends BaseAPI {
169
169
  const url = `/api/v1/accounts/balances/${assetId}`;
170
170
  return await this.makeAuthenticatedRequest(url);
171
171
  }
172
+ /**
173
+ * Get the current user's portfolio statistics for a given time period.
174
+ *
175
+ * Fetches aggregate stats from the /api/v1/accounts/me/portfolio endpoint.
176
+ * Requires a valid access token to be set.
177
+ *
178
+ * @param period - Time period to scope the stats ("24h" | "7d" | "30d" | "all")
179
+ * @returns Promise resolving to the user's portfolio statistics
180
+ * @throws {APIError} When the request fails or user is not authenticated
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const stats = await profileAPI.getPortfolioStats("30d");
185
+ * console.log(`PnL: ${stats.pnl}`);
186
+ * console.log(`Volume: ${stats.volume}`);
187
+ * console.log(`Total equity: ${stats.total_equity}`);
188
+ * ```
189
+ */
190
+ async getPortfolioStats(period) {
191
+ const searchParams = new URLSearchParams({ period });
192
+ return await this.makeAuthenticatedRequest(`/api/v1/accounts/me/portfolio?${searchParams}`);
193
+ }
194
+ /**
195
+ * Get the current user's portfolio chart time series for a given period and metric.
196
+ *
197
+ * Fetches bucketed time series data from the /api/v1/accounts/me/portfolio/chart endpoint.
198
+ * Requires a valid access token to be set.
199
+ *
200
+ * @param period - Time period ("24h" | "7d" | "30d" | "all")
201
+ * @param metric - Metric to chart ("volume" | "pnl")
202
+ * @returns Promise resolving to the portfolio chart response
203
+ * @throws {APIError} When the request fails or user is not authenticated
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const chart = await profileAPI.getPortfolioChart("7d", "pnl");
208
+ * chart.data.forEach(point => {
209
+ * console.log(`${point.timestamp}: ${point.value}`);
210
+ * });
211
+ * ```
212
+ */
213
+ async getPortfolioChart(period, metric) {
214
+ const searchParams = new URLSearchParams({ period, metric });
215
+ return await this.makeAuthenticatedRequest(`/api/v1/accounts/me/portfolio/chart?${searchParams}`);
216
+ }
217
+ /**
218
+ * Get the current user's trade history with pagination.
219
+ *
220
+ * Fetches the user's executed trades from the /api/v1/accounts/trades endpoint.
221
+ * Requires a valid access token to be set.
222
+ *
223
+ * @param params - Optional query parameters for pagination and filtering
224
+ * @param params.page - Page number (starts from 1, default: 1)
225
+ * @param params.limit - Number of items per page (default: 20, max: 100)
226
+ * @param params.trading_pair_id - Filter by trading pair ID (UUID)
227
+ * @returns Promise resolving to paginated trades response
228
+ * @throws {ValidationError} When the provided params fail client-side validation
229
+ * @throws {APIError} When the request fails or user is not authenticated
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * // Get first page of trades
234
+ * const trades = await profileAPI.getUserTrades();
235
+ * console.log(`Total trades: ${trades.total_count}`);
236
+ *
237
+ * // Filter by trading pair
238
+ * const pairTrades = await profileAPI.getUserTrades({ trading_pair_id: "550e8400-e29b-41d4-a716-446655440000" });
239
+ * ```
240
+ */
241
+ async getUserTrades(params) {
242
+ if (params) {
243
+ validate(GetUserTradesSchema, params);
244
+ }
245
+ const searchParams = new URLSearchParams();
246
+ if (params?.page !== undefined) {
247
+ searchParams.append("page", params.page.toString());
248
+ }
249
+ if (params?.limit !== undefined) {
250
+ searchParams.append("limit", params.limit.toString());
251
+ }
252
+ if (params?.trading_pair_id !== undefined) {
253
+ searchParams.append("trading_pair_id", params.trading_pair_id);
254
+ }
255
+ const queryString = searchParams.toString();
256
+ const url = queryString ? `/api/v1/accounts/trades?${queryString}` : "/api/v1/accounts/trades";
257
+ return await this.makeAuthenticatedRequest(url);
258
+ }
172
259
  }
package/dist/sdk.d.ts CHANGED
@@ -31,8 +31,8 @@ export declare class MonacoSDKImpl implements MonacoSDK {
31
31
  * - `expiresAt`: When the access token expires
32
32
  * - `user`: User information
33
33
  *
34
- * Note: There is NO separate `revokeToken` property. Use `authState.refreshToken`
35
- * when calling `auth.revokeToken()` or just call `sdk.logout()`.
34
+ * Note: Use `sdk.logout()` to revoke the token and clean up, or call
35
+ * `sdk.auth.revokeToken()` directly to just revoke.
36
36
  *
37
37
  * @param clientId - The client ID for authentication
38
38
  * @param options - Optional configuration
@@ -50,7 +50,7 @@ export declare class MonacoSDKImpl implements MonacoSDK {
50
50
  * await sdk.ws.connect();
51
51
  *
52
52
  * // Later, to revoke:
53
- * await sdk.auth.revokeToken(authState.refreshToken); // ✅
53
+ * await sdk.auth.revokeToken(); // ✅
54
54
  * // Or revoke and disconnect WebSocket:
55
55
  * await sdk.logout(); // ✅ Calls revokeToken internally and disconnects WebSocket
56
56
  * ```
@@ -76,7 +76,7 @@ export declare class MonacoSDKImpl implements MonacoSDK {
76
76
  *
77
77
  * This method revokes the refresh token (if available), disconnects all authenticated
78
78
  * WebSocket channels, and clears the local auth state.
79
- * It internally calls `auth.revokeToken(refreshToken)` to invalidate the token on the server.
79
+ * It internally calls `auth.revokeToken()` to invalidate the token on the server.
80
80
  *
81
81
  * @example
82
82
  * ```typescript
package/dist/sdk.js CHANGED
@@ -99,8 +99,8 @@ export class MonacoSDKImpl {
99
99
  * - `expiresAt`: When the access token expires
100
100
  * - `user`: User information
101
101
  *
102
- * Note: There is NO separate `revokeToken` property. Use `authState.refreshToken`
103
- * when calling `auth.revokeToken()` or just call `sdk.logout()`.
102
+ * Note: Use `sdk.logout()` to revoke the token and clean up, or call
103
+ * `sdk.auth.revokeToken()` directly to just revoke.
104
104
  *
105
105
  * @param clientId - The client ID for authentication
106
106
  * @param options - Optional configuration
@@ -118,7 +118,7 @@ export class MonacoSDKImpl {
118
118
  * await sdk.ws.connect();
119
119
  *
120
120
  * // Later, to revoke:
121
- * await sdk.auth.revokeToken(authState.refreshToken); // ✅
121
+ * await sdk.auth.revokeToken(); // ✅
122
122
  * // Or revoke and disconnect WebSocket:
123
123
  * await sdk.logout(); // ✅ Calls revokeToken internally and disconnects WebSocket
124
124
  * ```
@@ -161,7 +161,7 @@ export class MonacoSDKImpl {
161
161
  *
162
162
  * This method revokes the refresh token (if available), disconnects all authenticated
163
163
  * WebSocket channels, and clears the local auth state.
164
- * It internally calls `auth.revokeToken(refreshToken)` to invalidate the token on the server.
164
+ * It internally calls `auth.revokeToken()` to invalidate the token on the server.
165
165
  *
166
166
  * @example
167
167
  * ```typescript
@@ -172,7 +172,7 @@ export class MonacoSDKImpl {
172
172
  async logout() {
173
173
  if (this.authState?.refreshToken) {
174
174
  try {
175
- await this.auth.revokeToken(this.authState.refreshToken);
175
+ await this.auth.revokeToken();
176
176
  }
177
177
  catch (error) {
178
178
  // Log but don't throw - we want to clear the local state regardless
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "0.0.0-develop-20260318132113",
3
+ "version": "0.0.0-develop-20260412233650",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "dist"
15
15
  ],
16
16
  "scripts": {
17
- "build": "tsc -b --force",
17
+ "build": "tsc -b",
18
18
  "dev": "tsc --watch",
19
19
  "clean": "rm -rf dist",
20
20
  "lint": "biome lint ."
@@ -23,8 +23,8 @@
23
23
  "viem": "^2.45.2"
24
24
  },
25
25
  "dependencies": {
26
- "@0xmonaco/contracts": "0.0.0-develop-20260318132113",
27
- "@0xmonaco/types": "0.0.0-develop-20260318132113",
26
+ "@0xmonaco/contracts": "0.0.0-develop-20260412233650",
27
+ "@0xmonaco/types": "0.0.0-develop-20260412233650",
28
28
  "http-status-codes": "^2.3.0"
29
29
  },
30
30
  "devDependencies": {