# Split your closed trades by one dimension

`GET https://app.skylit.ai/api/nexus/v1/journal/breakdown`

API: Nexus.

Closed trades in `range`, split along `by`. Only slices with trades come back.

- `best` and `worst` are the slices with the highest and lowest `avgPnl` among those with at least `minSampleForVerdict` (5) measured trades, and are left out when none qualifies.
- `orderType` (how the position was opened) and `exitOrderType` (how it was closed) have the keys `market`, `limit`, `stop` ("Stop / target"), `expired` (exits only), `mixed` and `unknown` ("Not recorded"). One fill with no recorded type makes the position `unknown`; it's never folded into `market`. `unknown` and `expired` are never `best` or `worst`.
- Closed Simulated spreads on your Main account count here, one closed position per spread: its close time is its exit and its total realized P&L its result. A spread shows dollars only: when it is `bestTrade` or `worstTrade` it carries `kind: "spread"` and no `pnlPercent`. The Bot and your ports never hold a spread.

## Authentication

Send your Skylit API key as a bearer token: `Authorization: Bearer <key>`. No other header is accepted.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `account` | query | string | no | `main` (your own simulated wallet, the default) or `agent` (your bot's). (one of `main`, `agent`) |
| `port` | query | string (uuid) | no | One of your ports (see Ports in the Nexus Trades guide), by id. `account`, if you send it too, must agree: `agent` (or left out) for Bot and an extra port, left out for Main. Left out, `account` alone decides. |
| `range` | query | string | no | How far back, in New York time. Left out, `30d`. (one of `7d`, `30d`, `90d`, `ytd`, `all`; default `30d`) |
| `by` | query | string | no | The dimension. Left out, `duration`. `session` is when the trade was opened, `weekday` the day it was closed, `playbook` the setup you tagged it with. (one of `duration`, `session`, `weekday`, `direction`, `ticker`, `playbook`, `orderType`, `exitOrderType`; default `duration`) |

## Example request

```bash
curl "https://app.skylit.ai/api/nexus/v1/journal/breakdown" \
  -H "Authorization: Bearer $SKYLIT_API_KEY"
```

## Responses

### 200

The slices.

Your bot's entries by order type over 90 days.:

```json
{
  "data": {
    "range": "90d",
    "by": "orderType",
    "buckets": [
      {
        "key": "market",
        "label": "Market",
        "trades": 31,
        "measuredTrades": 31,
        "wins": 17,
        "losses": 13,
        "winRate": 56.67,
        "netPnl": 820,
        "avgPnl": 26.45
      },
      {
        "key": "limit",
        "label": "Limit",
        "trades": 12,
        "measuredTrades": 12,
        "wins": 8,
        "losses": 4,
        "winRate": 66.67,
        "netPnl": 640,
        "avgPnl": 53.33
      },
      {
        "key": "unknown",
        "label": "Not recorded",
        "trades": 2,
        "measuredTrades": 2,
        "wins": 1,
        "losses": 1,
        "winRate": 50,
        "netPnl": -35,
        "avgPnl": -17.5
      }
    ],
    "best": {
      "key": "limit",
      "label": "Limit",
      "trades": 12,
      "measuredTrades": 12,
      "wins": 8,
      "losses": 4,
      "winRate": 66.67,
      "netPnl": 640,
      "avgPnl": 53.33
    },
    "worst": {
      "key": "market",
      "label": "Market",
      "trades": 31,
      "measuredTrades": 31,
      "wins": 17,
      "losses": 13,
      "winRate": 56.67,
      "netPnl": 820,
      "avgPnl": 26.45
    },
    "minSampleForVerdict": 5
  },
  "meta": {
    "account": "agent",
    "port": null
  }
}
```

### 400

Code: `bad_request`. `account`, `range`, `by` or `month` isn't one of the allowed values, `account` doesn't agree with `port`, or Main was sent to `agent/edge`. The message says which.

A range that isn't allowed.:

```json
{
  "error": {
    "code": "bad_request",
    "message": "range must be one of 7d, 30d, 90d, ytd, all."
  }
}
```

### 401

No key, or a key that isn't valid. Codes: `missing_api_key`, `invalid_api_key`.

No key sent.:

```json
{
  "error": {
    "code": "missing_api_key",
    "message": "Send your Skylit API key in the Authorization header: Authorization: Bearer YOUR_SKYLIT_API_KEY."
  }
}
```

### 403

The key works but this can't be done. Codes: `feature_disabled` (ports are switched off on the server: leave `port` out), `account_suspended`, `nexus_access_denied`.

Ports are switched off on the server.:

```json
{
  "error": {
    "code": "feature_disabled",
    "message": "Ports aren't open to members yet."
  }
}
```

### 404

Codes: `port_not_found` (no live port with that id on your account), `user_not_found` (this Skylit account hasn't used Nexus yet, so it has no journal).

Not one of your ports.:

```json
{
  "error": {
    "code": "port_not_found",
    "message": "No port with that id on your account."
  }
}
```

### 429

Over a rate limit. Wait `Retry-After` seconds, then retry. Codes: `rate_limited`, and `stream_limit_reached` (too many live streams open: 3 per key, 6 per account).

Headers: `Retry-After`, `X-RateLimit-Limit`, `X-RateLimit-Remaining`.

Too many writes from this key.:

```json
{
  "error": {
    "code": "rate_limited",
    "message": "Too many requests (limit 30). Slow down and retry in 12 seconds."
  }
}
```

### 500

Something went wrong on our side. If you sent a `clientOrderId`, retry with the same one. Code: `internal_error`.

Retry with the same clientOrderId.:

```json
{
  "error": {
    "code": "internal_error",
    "message": "Something went wrong on our side. If you sent a clientOrderId, retry with the same one (it can't fill twice). Otherwise check your account before retrying."
  }
}
```
