# Read your bot's Edge

`GET https://app.skylit.ai/api/nexus/v1/agent/edge`

API: Nexus.

Your bot's **Edge** (its average R per position, after fees) and **Proven Edge** (the lowest that average is likely to be, at 80% confidence), worked out the same way as your rank's, over your bot's own trades. Private to you: it's never written to a rank, a leaderboard, a season or your profile.

- **Shown while Skylit's ranks are on**, as they are for every member. If they're ever switched off, this answers `200` with `data` `{"enabled": false}` and no figures.
- Leave `account` and `port` out for your Bot account, or send `?port=` for Bot or one extra port. Main, by its port or `account=main`, answers `400 bad_request`: your own Edge is your rank.
- Under `minPositions` counted positions, `edge` is `null` and `reason` is `not_enough_positions`. Never zeros.
- `port` in the answer is the extra port read, or `null` for Bot.

## 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. |

## Example request

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

## Responses

### 200

The Edge, or why there isn't one yet.

Your Bot account with enough positions.:

```json
{
  "data": {
    "port": null,
    "edge": {
      "edgeR": 0.18,
      "provenEdge": 0.04,
      "provenEdgeConf": 0.8,
      "netRor": 0.0412
    },
    "reason": null,
    "positions": 34,
    "countedPositions": 31,
    "minPositions": 10,
    "windowDays": 180
  },
  "meta": {
    "account": "agent",
    "port": null
  }
}
```

An extra port with too few positions.:

```json
{
  "data": {
    "port": "9e8d7c6b-5a4f-4e3d-a2c1-0b9a8f7e6d03",
    "edge": null,
    "reason": "not_enough_positions",
    "positions": 4,
    "countedPositions": 3,
    "minPositions": 10,
    "windowDays": 180
  },
  "meta": {
    "account": "agent",
    "port": "9e8d7c6b-5a4f-4e3d-a2c1-0b9a8f7e6d03"
  }
}
```

Skylit's ranks are switched off.:

```json
{
  "data": {
    "enabled": false
  },
  "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."
  }
}
```

### 503

Try again in a moment (honour `Retry-After` when it's sent). Codes: `stale_quote` (the quote, or a stock's last trade, is more than 15 seconds old, so nothing filled), `no_live_price`, `rules_pending`, `unavailable`, `auth_unavailable`, `access_check_unavailable`, `api_keys_unavailable`, `trades_api_disabled`, `stream_unavailable` (the live stream isn't on, or the server is restarting: try again shortly, or poll the reads).

Headers: `Retry-After`.

No live price right now.:

```json
{
  "error": {
    "code": "no_live_price",
    "message": "There's no live price for this contract right now, so nothing was filled. Try again in a moment."
  }
}
```
