> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xmonaco.com/llms.txt
> Use this file to discover all available pages before exploring further.

# V0.8.5

# Monaco Protocol SDK v0.8.5

## App Statistics (Backend)

Backend users can now fetch aggregate volume and fee metrics for their application via a new endpoint available on both REST and gRPC. Auth requires a backend secret key (`sk_...`).

### REST

```
GET /api/v1/applications/stats
Authorization: Bearer sk_...
```

**Query parameters:**

| Param | Type | Required | Description |
| - | - | - | - |
| `since` | string (ISO 8601) | no | Filter stats from this datetime, e.g. `2026-01-01T00:00:00Z`. Omit for all-time |

**Response (`GetAppStatsResponse`):**

| Field | Type | Description |
| - | - | - |
| `volume` | string | Total quote volume for trades where this application's users were the taker |
| `maker_fee` | string | Total maker fees collected |
| `taker_fee` | string | Total taker fees collected |
| `application_taker_fee` | string | Application revenue share from taker fees |
| `trade_count` | number | Total number of trades |

All monetary values are normalized, human-readable strings in quote token units (e.g. `"12345.67"`).

### TypeScript SDK

```typescript theme={null}
// Requires backend SDK initialization (secret key)
const stats = await sdk.applications.getApplicationStats();
// With time filter:
const statsFrom = await sdk.applications.getApplicationStats({
  since: "2026-01-01T00:00:00Z",
});

console.log(stats.volume);               // "12345.67"
console.log(stats.application_taker_fee); // "5.67"
console.log(stats.trade_count);           // 42
```

### gRPC

RPC: `ApplicationsService/GetAppStats`

```protobuf theme={null}
message GetAppStatsRequest {
  optional string since = 1; // ISO 8601, e.g. "2026-01-01T00:00:00Z"
}

message GetAppStatsResponse {
  string volume = 1;
  string maker_fee = 2;
  string taker_fee = 3;
  string application_taker_fee = 4;
  int64 trade_count = 5;
}
```

Auth: `x-server-key: sk_...` header.

***

## Auto-Margin Funding & Risk Simulation

Two new `sdk.marginAccounts` methods let you fund and simulate orders against an auto-resolved margin bucket, using a `(tradingPairId, strategyKey)` pair instead of a raw `marginAccountId`. This complements the `strategyKey` introduced in v0.8.4 for delegated agents and strategy-segregated accounts.

### `transferCollateralToAutoMarginAccount`

Transfers collateral into the margin bucket for a given `tradingPairId` + optional `strategyKey`. Monaco resolves the parent account and ensures the bucket exists automatically.

```typescript theme={null}
await sdk.marginAccounts.transferCollateralToAutoMarginAccount({
  asset: "USDC",
  amount: "500",
  tradingPairId: btcPerpTradingPairId,
  strategyKey: "btc-mm-strategy-a", // optional
});
```

**Parameters (`TransferCollateralToAutoMarginAccountRequest`):**

| Field | Type | Required | Description |
| - | - | - | - |
| `asset` | string | yes | Collateral asset, e.g. `"USDC"` |
| `amount` | string | yes | Decimal amount to transfer in |
| `tradingPairId` | string (UUID) | yes | Trading pair the margin account is scoped to |
| `strategyKey` | string | no | Strategy tag — omit to target the default account for the pair |

Response shape is the same as `transferCollateralToMarginAccount` (`movement_id`, `margin_account_id`, `new_equity`, `new_total_collateral_value`, `new_withdrawable_collateral`).

### `simulateAutoMarginOrderRisk`

Preflight a perp order against the auto-resolved margin account for a `(tradingPairId, strategyKey)` — no `marginAccountId` lookup required.

```typescript theme={null}
const risk = await sdk.marginAccounts.simulateAutoMarginOrderRisk({
  tradingPairId: btcPerpTradingPairId,
  strategyKey: "btc-mm-strategy-a", // optional
  side: "BUY",
  positionSide: "LONG",
  orderType: "LIMIT",
  price: "65000",
  quantity: "0.5",
  leverage: "10",
});

if (!risk.accepted) {
  showError(risk.reject_reason);
}
```

**Parameters (`SimulateOrderRiskRequest`):**

| Field | Type | Required | Description |
| - | - | - | - |
| `tradingPairId` | string (UUID) | yes | Trading pair |
| `strategyKey` | string | no | Strategy key — omit for the default account |
| `side` | `"BUY"` \| `"SELL"` | yes | |
| `positionSide` | `"LONG"` \| `"SHORT"` \| `"NONE"` | yes | |
| `orderType` | `"LIMIT"` \| `"MARKET"` | yes | |
| `price` | string | for LIMIT | Required when `orderType` is `"LIMIT"` |
| `quantity` | string | yes | |
| `leverage` | string | yes | e.g. `"10"` |
| `reduceOnly` | boolean | no | |

Response shape is identical to `simulateOrderRisk`.

***

## `listMarginAccounts` — `tradingPairId` filter

`listMarginAccounts` now accepts an optional `tradingPairId` param to filter results to accounts scoped to a specific trading pair.

```typescript theme={null}
const { accounts } = await sdk.marginAccounts.listMarginAccounts({
  tradingPairId: btcPerpTradingPairId,
});
```

`MarginAccountSummary` also now includes `trading_pair_id?: string` and `strategy_key?: string` in its response shape.

***

## Upgrade

```bash theme={null}
npm install @0xmonaco/core@0.8.5 @0xmonaco/types@0.8.5 @0xmonaco/react@0.8.5
# or bun
bun add @0xmonaco/core@0.8.5 @0xmonaco/types@0.8.5 @0xmonaco/react@0.8.5
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.