@0xmonaco/core 1.0.15 → 1.0.21

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/base.js CHANGED
@@ -24,6 +24,16 @@ import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils";
24
24
  import { StatusCodes } from "http-status-codes";
25
25
  import { composeSigningString, keypairFromHex, sha256Hex, signMessage } from "../crypto/session";
26
26
  import { APIError } from "../errors";
27
+ /**
28
+ * Product token sent as the `User-Agent` on every request. Monaco's edge
29
+ * rejects requests with an empty or absent `User-Agent`, so we set one
30
+ * explicitly to identify SDK traffic and keep it from being blocked.
31
+ *
32
+ * Note: `User-Agent` is a forbidden header in browsers — `fetch` silently
33
+ * ignores this value there and uses the browser's own (non-empty) UA. It
34
+ * only takes effect in server runtimes (Node/undici, Bun, Deno).
35
+ */
36
+ const SDK_USER_AGENT = "@0xmonaco/core";
27
37
  export class BaseAPI {
28
38
  apiUrl;
29
39
  /** Active session keypair (raw bytes) used to sign authenticated requests. */
@@ -142,8 +152,12 @@ export class BaseAPI {
142
152
  */
143
153
  async executeRequest(url, endpoint, options, requestBody) {
144
154
  let response;
155
+ // Default the User-Agent (see SDK_USER_AGENT) while letting an explicit
156
+ // per-request header win. This is the single fetch site, so it covers the
157
+ // authenticated, backend, and public request paths.
158
+ const headers = { "User-Agent": SDK_USER_AGENT, ...options.headers };
145
159
  try {
146
- response = await fetch(url, options);
160
+ response = await fetch(url, { ...options, headers });
147
161
  }
148
162
  catch (error) {
149
163
  throw new APIError(`Network request failed for ${endpoint}`, {
@@ -13,6 +13,7 @@ export * from "./market";
13
13
  export * from "./orderbook";
14
14
  export * from "./perp";
15
15
  export * from "./pitpass";
16
+ export * from "./portfolio";
16
17
  export * from "./positions";
17
18
  export * from "./profile";
18
19
  export * from "./sub-accounts";
package/dist/api/index.js CHANGED
@@ -13,6 +13,7 @@ export * from "./market";
13
13
  export * from "./orderbook";
14
14
  export * from "./perp";
15
15
  export * from "./pitpass";
16
+ export * from "./portfolio";
16
17
  export * from "./positions";
17
18
  export * from "./profile";
18
19
  export * from "./sub-accounts";
@@ -0,0 +1,9 @@
1
+ import type { PortfolioAPI, PortfolioAssets, PortfolioMargin, PortfolioPerformance, PortfolioPeriodParams, PortfolioRealizedPnl, PortfolioSummary } from "@0xmonaco/types";
2
+ import { BaseAPI } from "../base";
3
+ export declare class PortfolioAPIImpl extends BaseAPI implements PortfolioAPI {
4
+ getSummary(params?: PortfolioPeriodParams): Promise<PortfolioSummary>;
5
+ getPerformance(params?: PortfolioPeriodParams): Promise<PortfolioPerformance>;
6
+ getRealizedPnl(params?: PortfolioPeriodParams): Promise<PortfolioRealizedPnl>;
7
+ getAssets(params?: PortfolioPeriodParams): Promise<PortfolioAssets>;
8
+ getMargin(): Promise<PortfolioMargin>;
9
+ }
@@ -0,0 +1,25 @@
1
+ import { BaseAPI } from "../base";
2
+ const BASE_PATH = "/api/v1/accounts/me/portfolio";
3
+ function withPeriod(path, params) {
4
+ if (!params?.period) {
5
+ return path;
6
+ }
7
+ return `${path}?${new URLSearchParams({ period: params.period })}`;
8
+ }
9
+ export class PortfolioAPIImpl extends BaseAPI {
10
+ async getSummary(params) {
11
+ return await this.makeAuthenticatedRequest(withPeriod(`${BASE_PATH}/summary`, params));
12
+ }
13
+ async getPerformance(params) {
14
+ return await this.makeAuthenticatedRequest(withPeriod(`${BASE_PATH}/performance`, params));
15
+ }
16
+ async getRealizedPnl(params) {
17
+ return await this.makeAuthenticatedRequest(withPeriod(`${BASE_PATH}/realized-pnl`, params));
18
+ }
19
+ async getAssets(params) {
20
+ return await this.makeAuthenticatedRequest(withPeriod(`${BASE_PATH}/assets`, params));
21
+ }
22
+ async getMargin() {
23
+ return await this.makeAuthenticatedRequest(`${BASE_PATH}/margin`);
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export { PortfolioAPIImpl } from "./api";
@@ -0,0 +1 @@
1
+ export { PortfolioAPIImpl } from "./api";
@@ -38,8 +38,13 @@ export declare const COVERED: {
38
38
  get_orders: string;
39
39
  get_perp_market_config: string;
40
40
  get_perp_market_summary: string;
41
+ get_portfolio_assets: string;
41
42
  get_portfolio_chart: string;
43
+ get_portfolio_margin: string;
44
+ get_portfolio_performance: string;
45
+ get_portfolio_realized_pnl: string;
42
46
  get_portfolio_stats: string;
47
+ get_portfolio_summary: string;
43
48
  get_position: string;
44
49
  get_position_pnl_history: string;
45
50
  get_position_risk: string;
@@ -95,6 +100,5 @@ export declare const COVERED: {
95
100
  };
96
101
  /** operationId → reason it is intentionally not covered by @0xmonaco/core. */
97
102
  export declare const INTENTIONALLY_EXCLUDED: {
98
- authenticate_backend: string;
99
103
  health_check: string;
100
104
  };
package/dist/coverage.js CHANGED
@@ -38,8 +38,13 @@ export const COVERED = {
38
38
  get_orders: "getPaginatedOrders",
39
39
  get_perp_market_config: "getPerpMarketConfig",
40
40
  get_perp_market_summary: "getPerpMarketSummary",
41
+ get_portfolio_assets: "portfolio.getAssets",
41
42
  get_portfolio_chart: "getPortfolioChart",
43
+ get_portfolio_margin: "portfolio.getMargin",
44
+ get_portfolio_performance: "portfolio.getPerformance",
45
+ get_portfolio_realized_pnl: "portfolio.getRealizedPnl",
42
46
  get_portfolio_stats: "getPortfolioStats",
47
+ get_portfolio_summary: "portfolio.getSummary",
43
48
  get_position: "getPosition",
44
49
  get_position_pnl_history: "getPositionPnlHistory",
45
50
  get_position_risk: "getPositionRisk",
@@ -95,6 +100,5 @@ export const COVERED = {
95
100
  };
96
101
  /** operationId → reason it is intentionally not covered by @0xmonaco/core. */
97
102
  export const INTENTIONALLY_EXCLUDED = {
98
- authenticate_backend: "Backend auth is header-based via setServerKey()/the x-server-key header, not an endpoint method (MON-1486).",
99
103
  health_check: "Infrastructure liveness probe (GET /health); not part of the data SDK surface.",
100
104
  };
package/dist/sdk.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FaucetAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PitpassAPI, PositionsAPI, ProfileAPI, SDKConfig, SubAccountsAPI, TradingAPI, VaultAPI, WhitelistAPI, WithdrawalsAPI } from "@0xmonaco/types";
1
+ import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FaucetAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PitpassAPI, PortfolioAPI, PositionsAPI, ProfileAPI, SDKConfig, SubAccountsAPI, TradingAPI, VaultAPI, WhitelistAPI, WithdrawalsAPI } from "@0xmonaco/types";
2
2
  import { type Address, type PublicClient, type TransactionReceipt, type WalletClient } from "viem";
3
3
  import { type MonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
4
4
  export declare class MonacoSDKImpl implements MonacoSDK {
@@ -13,6 +13,7 @@ export declare class MonacoSDKImpl implements MonacoSDK {
13
13
  market: MarketAPI;
14
14
  marginAccounts: MarginAccountsAPI;
15
15
  positions: PositionsAPI;
16
+ portfolio: PortfolioAPI;
16
17
  subAccounts: SubAccountsAPI;
17
18
  faucet: FaucetAPI;
18
19
  whitelist: WhitelistAPI;
package/dist/sdk.js CHANGED
@@ -9,6 +9,7 @@ import { FeesAPIImpl } from "./api/fees";
9
9
  import { MarginAccountsAPIImpl } from "./api/margin-accounts";
10
10
  import { MarketAPIImpl } from "./api/market";
11
11
  import { PitpassAPIImpl } from "./api/pitpass";
12
+ import { PortfolioAPIImpl } from "./api/portfolio";
12
13
  import { PositionsAPIImpl } from "./api/positions";
13
14
  import { ProfileAPIImpl } from "./api/profile";
14
15
  import { SubAccountsAPIImpl } from "./api/sub-accounts";
@@ -41,6 +42,7 @@ export class MonacoSDKImpl {
41
42
  market;
42
43
  marginAccounts;
43
44
  positions;
45
+ portfolio;
44
46
  subAccounts;
45
47
  faucet;
46
48
  whitelist;
@@ -69,6 +71,7 @@ export class MonacoSDKImpl {
69
71
  this.market.setSessionKeypair(credentials);
70
72
  this.marginAccounts.setSessionKeypair(credentials);
71
73
  this.positions.setSessionKeypair(credentials);
74
+ this.portfolio.setSessionKeypair(credentials);
72
75
  this.subAccounts.setSessionKeypair(credentials);
73
76
  this.faucet.setSessionKeypair(credentials);
74
77
  this.whitelist.setSessionKeypair(credentials);
@@ -106,6 +109,7 @@ export class MonacoSDKImpl {
106
109
  this.market.setServerKey(serverKey);
107
110
  this.marginAccounts.setServerKey(serverKey);
108
111
  this.positions.setServerKey(serverKey);
112
+ this.portfolio.setServerKey(serverKey);
109
113
  this.subAccounts.setServerKey(serverKey);
110
114
  this.faucet.setServerKey(serverKey);
111
115
  this.whitelist.setServerKey(serverKey);
@@ -162,6 +166,7 @@ export class MonacoSDKImpl {
162
166
  this.market = new MarketAPIImpl(apiUrl);
163
167
  this.marginAccounts = new MarginAccountsAPIImpl(apiUrl);
164
168
  this.positions = new PositionsAPIImpl(apiUrl);
169
+ this.portfolio = new PortfolioAPIImpl(apiUrl);
165
170
  this.subAccounts = new SubAccountsAPIImpl(apiUrl);
166
171
  this.faucet = new FaucetAPIImpl(apiUrl);
167
172
  this.whitelist = new WhitelistAPIImpl(apiUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "1.0.15",
3
+ "version": "1.0.21",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,8 +23,8 @@
23
23
  "viem": "^2.45.2"
24
24
  },
25
25
  "dependencies": {
26
- "@0xmonaco/contracts": "1.0.15",
27
- "@0xmonaco/types": "1.0.15",
26
+ "@0xmonaco/contracts": "1.0.21",
27
+ "@0xmonaco/types": "1.0.21",
28
28
  "@noble/curves": "^1.9.1",
29
29
  "@noble/hashes": "^1.8.0",
30
30
  "http-status-codes": "^2.3.0"