# Close a futures position, or flatten the account

`POST https://app.skylit.ai/api/nexus/v1/trading/accounts/{account}/close`

API: Nexus.

Send `ticker` to close one position at market, or `"closeAll": true` to flatten every position in the account. Not both. A close works on a quiet price, and it's the same close as the Flatten button in Nexus.

Nothing to close answers `200` with an empty `closed` list and `meta.nothingToClose: true`. If `closeAll` closes some positions and fails on one, the error says how many closed and which is still open. Send it again (with a new `clientOrderId` if you sent one). A repeated `closeAll` id returns what already closed, plus `meta.stillOpen` if anything is.

## 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` | path | string | yes | `practice`, `evaluation` or `funded` (when you have exactly one running), or a futures account id from capabilities. |
| `Idempotency-Key` | header | string | no | Your `clientOrderId`, as a header instead of a body field. If you send both they must match. |

## Request body

`application/json`

```json
{
  "ticker": "string",
  "closeAll": false,
  "clientOrderId": "string",
  "test": false
}
```

## Example request

```bash
curl "https://app.skylit.ai/api/nexus/v1/trading/accounts/practice/close" \
  -H "Authorization: Bearer $SKYLIT_API_KEY"
```

## Responses

### 200

What closed.

Closed 1 NQ long at the last trade less one tick.:

```json
{
  "data": {
    "account": {
      "id": "3c2b1a90-5e4d-4f3a-8b2c-1d0e9f8a7b6c",
      "kind": "practice",
      "name": "Paper"
    },
    "closed": [
      {
        "id": "18c9d0e1-f2a3-4b4c-9d5e-7f8091021324",
        "assetClass": "futures",
        "source": "api",
        "account": {
          "id": "3c2b1a90-5e4d-4f3a-8b2c-1d0e9f8a7b6c",
          "kind": "practice",
          "name": "Paper"
        },
        "symbol": "NQZ26",
        "side": "sell",
        "quantity": 1,
        "role": "close",
        "orderType": "market",
        "status": "filled",
        "fillPrice": 25330.5,
        "placedAt": "2026-10-09T15:12:44Z",
        "filledAt": "2026-10-09T15:12:44Z"
      }
    ]
  },
  "meta": {
    "clientOrderId": "bot-0145"
  }
}
```

Flattened a long NQ and a short MNQ. With nothing open it answers an empty closed list and meta.nothingToClose, and the id isn't used up.:

```json
{
  "data": {
    "account": {
      "id": "3c2b1a90-5e4d-4f3a-8b2c-1d0e9f8a7b6c",
      "kind": "practice",
      "name": "Paper"
    },
    "closed": [
      {
        "id": "5c03b4c5-d6e7-4f80-9102-132435465768",
        "assetClass": "futures",
        "source": "api",
        "account": {
          "id": "3c2b1a90-5e4d-4f3a-8b2c-1d0e9f8a7b6c",
          "kind": "practice",
          "name": "Paper"
        },
        "symbol": "MNQZ26",
        "side": "buy",
        "quantity": 2,
        "role": "close",
        "orderType": "market",
        "status": "filled",
        "fillPrice": 25329,
        "placedAt": "2026-10-09T15:55:02Z",
        "filledAt": "2026-10-09T15:55:02Z"
      },
      {
        "id": "6d14c5d6-e7f8-4091-8213-243546576879",
        "assetClass": "futures",
        "source": "api",
        "account": {
          "id": "3c2b1a90-5e4d-4f3a-8b2c-1d0e9f8a7b6c",
          "kind": "practice",
          "name": "Paper"
        },
        "symbol": "NQZ26",
        "side": "sell",
        "quantity": 1,
        "role": "close",
        "orderType": "market",
        "status": "filled",
        "fillPrice": 25328.25,
        "placedAt": "2026-10-09T15:55:02Z",
        "filledAt": "2026-10-09T15:55:02Z"
      }
    ]
  },
  "meta": {
    "clientOrderId": "flat-1555"
  }
}
```

### 400

The request was refused before anything was traded. Codes: `bad_request`, `bad_contract`, `invalid_quantity`, `invalid_price`, `unsupported_asset_class`, `unsupported_order_type`, `only_market_orders`, `test_orders_unavailable`, `test_modify_unavailable`.

A typo in the body.:

```json
{
  "error": {
    "code": "bad_request",
    "message": "Unknown field \"quantitty\". See the trades API docs for the fields you can send."
  }
}
```

### 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 the account can't do this. Codes: `account_suspended`, `nexus_access_denied`, `futures_access_denied`.

The account doesn't include Nexus.:

```json
{
  "error": {
    "code": "nexus_access_denied",
    "message": "This Skylit account doesn't include Nexus, so it can't place Nexus trades."
  }
}
```

### 404

Not on your account. Codes: `trade_not_found`, `account_not_found`, `order_not_found`.

Not your trade, or no such trade.:

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

### 409

The order clashes with what you hold or sent before. Codes: `duplicate_position` (with `tradeId`), `trade_closed`, `open_position_limit`, `client_order_id_used`, `request_in_progress`, `account_locked`, `account_busy`, `account_ended`, `order_not_working`.

You already hold this contract.:

```json
{
  "error": {
    "code": "duplicate_position",
    "message": "You already hold an open position on this contract. Close it first, or add to it in Nexus.",
    "tradeId": "6f1c2a4e-8b1d-4c39-9a51-2d7e0b3c9f10"
  }
}
```

### 422

Read fine, but the market or the account says no. Codes: `market_closed`, `contract_expired`, `contract_not_offered`, `price_outside_market`, `insufficient_buying_power`, `account_not_tradable`, `account_ambiguous`, `reduce_only_would_open`, `order_refused`.

Outside market hours.:

```json
{
  "error": {
    "code": "market_closed",
    "message": "The market is closed for this contract right now, so nothing was filled."
  }
}
```

### 429

Over a rate limit. Wait `Retry-After` seconds, then retry. Code: `rate_limited`.

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`, `no_live_price`, `rules_pending`, `unavailable`, `auth_unavailable`, `access_check_unavailable`, `api_keys_unavailable`, `trades_api_disabled`.

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."
  }
}
```
