# Trim or close an options or stock trade

`POST https://app.skylit.ai/api/nexus/v1/trades/{id}/exits`

API: Nexus.

Sell part of a trade with `quantity`, or all of what's left with `"closeAll": true`. Not both. Fills at market (the live bid for options), or at your own `price` inside the window, as on an open. On a short stock trade an exit buys it back.

**Close at your price.** `"orderType": "limit"` with `limitPrice` (the least you'll take, or the most you'll pay to cover a short) rests until the market gets there: an option fills at your limit when the bid comes up to it (at the bid right away if it's already there). A stock also takes `"orderType": "stop"` with `stopPrice`. Add `timeInForce` for `gtc`. It answers `201` with the order and `meta.tradeId`. You can't close more than the trade holds (`400 invalid_quantity`), and if you hold the same contract on more than one trade in that wallet, the fill closes the oldest first.

**Protect an options trade.** Send `stopLoss`, `takeProfit` or both. They're prices of the **stock**, not the option: a stop at 585 on an SPY call fires when SPY trades at or under 585. On a call the stop sits under the stock's price and the target over it, on a put the other way round. Both together are one bracket order: whichever the stock reaches first fires and the other goes with it. When a level hits, the covered contracts sell at the market, at the option's live bid. With no live quote (nothing in the last 15 seconds) nothing sells and it tries again a few seconds later. It stays on until it fires, you cancel it, or the contract expires, so it takes no `timeInForce`. `"orderType": "stop"` with `stopPrice` works too, the same as `stopLoss` alone. It answers `201` with the order (`orderType` `stop`, `take_profit` or `bracket`, `"triggerOn": "underlying"`). `meta.underlyingPrice` is the stock's price now, and `meta.firesNow: true` means it's already through a level and fires on the next check. A stop goes on a trade you hold, never on an entry.

On a test order's id this is a test exit, whatever the body says. Futures have no exits: close a futures position with the account close route.

## Authentication

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

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes | The trade's id, from the open or the list. |
| `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
{
  "quantity": 0,
  "closeAll": false,
  "price": 0,
  "ifOutside": "reject",
  "orderType": "market",
  "limitPrice": 0,
  "stopPrice": 0,
  "timeInForce": "day",
  "stopLoss": 0,
  "takeProfit": 0,
  "clientOrderId": "string",
  "test": false
}
```

## Example request

```bash
curl "https://app.skylit.ai/api/nexus/v1/trades/6f1c2a4e-8b1d-4c39-9a51-2d7e0b3c9f10/exits" \
  -H "Authorization: Bearer $SKYLIT_API_KEY"
```

## Responses

### 200

The trade with its new exit. `meta.fill.quantity` is how many this exit sold.

Trimmed 1 at the live bid. One contract is still open.:

```json
{
  "data": {
    "id": "6f1c2a4e-8b1d-4c39-9a51-2d7e0b3c9f10",
    "ticker": "SPY",
    "strike": 600,
    "expiration": "2026-10-16",
    "direction": "call",
    "assetClass": "options",
    "averageEntryPrice": 1.84,
    "totalQuantity": 2,
    "remainingQuantity": 1,
    "status": "active",
    "exits": [
      {
        "id": "f6a7b8c9-d0e1-4f2a-9b3c-5d6e7f809102",
        "price": 2.1,
        "quantity": 1,
        "date": "2026-10-09T15:05:41Z",
        "type": "partial",
        "orderType": "market"
      }
    ],
    "source": "api"
  },
  "meta": {
    "fill": {
      "price": 2.1,
      "priceSource": "market",
      "quantity": 1
    },
    "clientOrderId": "bot-0144"
  }
}
```

Closed the last contract at the live bid. The trade is closed.:

```json
{
  "data": {
    "id": "6f1c2a4e-8b1d-4c39-9a51-2d7e0b3c9f10",
    "ticker": "SPY",
    "strike": 600,
    "expiration": "2026-10-16",
    "direction": "call",
    "assetClass": "options",
    "averageEntryPrice": 1.84,
    "totalQuantity": 2,
    "remainingQuantity": 0,
    "status": "closed",
    "exitDate": "2026-10-09T15:20:02Z",
    "exits": [
      {
        "id": "f6a7b8c9-d0e1-4f2a-9b3c-5d6e7f809102",
        "price": 2.1,
        "quantity": 1,
        "date": "2026-10-09T15:05:41Z",
        "type": "partial",
        "orderType": "market"
      },
      {
        "id": "07b8c9d0-e1f2-4a3b-8c4d-6e7f80910213",
        "price": 2.25,
        "quantity": 1,
        "date": "2026-10-09T15:20:02Z",
        "type": "full",
        "orderType": "market"
      }
    ],
    "source": "api"
  },
  "meta": {
    "fill": {
      "price": 2.25,
      "priceSource": "market",
      "quantity": 1
    }
  }
}
```

### 201

A resting exit: a limit or stop to close, or an options stop-loss and target. The order, with `meta.tradeId`. Manage it with the Options and stocks resting orders routes.

The sell, resting at 2.50. A close holds back no buying power.:

```json
{
  "data": {
    "id": "8f9a0b1c-2d3e-4f5a-9b6c-7d8e9f0a1b2c",
    "assetClass": "options",
    "source": "api",
    "book": "main",
    "clientOrderId": "spy-tp-0001",
    "ticker": "SPY",
    "strike": 600,
    "direction": "call",
    "expiration": "2026-10-16",
    "side": "sell",
    "positionEffect": "close",
    "quantity": 2,
    "filledQuantity": 0,
    "orderType": "limit",
    "timeInForce": "gtc",
    "status": "working",
    "limitPrice": 2.5,
    "reservedCents": 0,
    "placedAt": "2026-10-12T15:02:44Z",
    "expiresAt": "2026-10-16T20:00:00Z"
  },
  "meta": {
    "clientOrderId": "spy-tp-0001",
    "tradeId": "6f1c2a4e-8b1d-4c39-9a51-2d7e0b3c9f10"
  }
}
```

The sell stop, resting until AAPL trades through 180.00.:

```json
{
  "data": {
    "id": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e",
    "assetClass": "stocks",
    "source": "api",
    "book": "main",
    "clientOrderId": "api-0d9c8b7a-6f5e-4d3c-8b2a-1f0e9d8c7b6a",
    "ticker": "AAPL",
    "direction": "long",
    "side": "sell",
    "positionEffect": "close",
    "quantity": 25,
    "filledQuantity": 0,
    "orderType": "stop",
    "timeInForce": "day",
    "status": "working",
    "stopPrice": 180,
    "reservedCents": 0,
    "placedAt": "2026-10-12T15:04:10Z",
    "expiresAt": "2026-10-12T20:00:00Z"
  },
  "meta": {
    "tradeId": "9e8d7c6b-5a4f-4e3d-8c2b-1a0f9e8d7c6b"
  }
}
```

The bracket, armed on SPY's price. SPY is at 598.40, so neither level has hit.:

```json
{
  "data": {
    "id": "3c4d5e6f-7a8b-4c9d-8e0f-2a3b4c5d6e7f",
    "assetClass": "options",
    "source": "api",
    "book": "main",
    "clientOrderId": "spy-bracket-1",
    "ticker": "SPY",
    "strike": 600,
    "direction": "call",
    "expiration": "2026-10-16",
    "side": "sell",
    "positionEffect": "close",
    "quantity": 2,
    "filledQuantity": 0,
    "orderType": "bracket",
    "timeInForce": "gtc",
    "status": "working",
    "stopLoss": 585,
    "takeProfit": 610,
    "triggerOn": "underlying",
    "underlying": "SPY",
    "tradeId": "6f1c2a4e-8b1d-4c39-9a51-2d7e0b3c9f10",
    "reservedCents": 0,
    "placedAt": "2026-10-12T15:06:30Z"
  },
  "meta": {
    "clientOrderId": "spy-bracket-1",
    "tradeId": "6f1c2a4e-8b1d-4c39-9a51-2d7e0b3c9f10",
    "triggerOn": "underlying",
    "underlyingPrice": 598.4,
    "marketOpen": true,
    "firesNow": false
  }
}
```

### 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`, `limit_price_required` (a limit with no `limitPrice`), `invalid_limit_price` (not in cents, or outside 0.01 to 99,999.99 for options or 999,999.99 for stocks), `stop_price_required` (a stop with no `stopPrice`), `invalid_stop_price` (not in cents, or outside 0.01 to 999,999.99), `invalid_take_profit`, `test_orders_unavailable`, `test_modify_unavailable`, `bad_symbol` (a quotes symbol that isn't OCC).

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

### 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`: add to it instead), `trade_closed`, `open_position_limit` (open positions plus resting opens through the API are at 50), `working_order_limit` (50 options and stock orders already resting through the API), `position_size_limit` (an add would take the position past 1,000 contracts or 100,000 shares), `client_order_id_used`, `request_in_progress`, `account_locked`, `account_busy`, `account_ended`, `order_not_working` (it already filled, expired, or was cancelled or rejected), `stop_triggered` (a stop that's been set off is filling now, so it can't be cancelled or changed).

You already hold this contract.:

```json
{
  "error": {
    "code": "duplicate_position",
    "message": "You already hold an open position on this contract. Add to it with POST /api/nexus/v1/trades/{id}/adds (the id is tradeId), or close it first.",
    "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`, `order_rejected` (a resting order that tried to fill right away and couldn't; `orderId` points to it). A resting order that can't be covered answers `insufficient_buying_power` with `orderId` too: it's recorded as rejected.

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

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