> For the complete documentation index, see [llms.txt](https://ocx.gitbook.io/ocx-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ocx.gitbook.io/ocx-doc/ocx/api/perpetuals-trading.md).

# perpetuals trading

A single set of endpoints under `/perps/*` handles linear products — spot, perpetuals, and quarterly futures. The `marketId` determines the product type.

***

## POST /perps/orders

Place a single linear order.

**Auth**: required (`trade` scope).

**Request**

```json
{
  "marketId":        "BTC-PERP",
  "clientOrderId":   "bot-42",
  "type":            "limit",
  "side":            "buy",
  "price":           "67000.00",
  "quantity":        "0.5",
  "timeInForce":     "gtc",
  "postOnly":        false,
  "reduceOnly":      false,
  "marginMode":      "cross",
  "stopPrice":       null,
  "takeProfitPrice": null,
  "stopLossPrice":   null
}
```

| Field             | Type                          | Description                                              |
| ----------------- | ----------------------------- | -------------------------------------------------------- |
| `marketId`        | string                        | E.g., `BTC-PERP`, `BTC-USDC-SPOT`, `BTC-USDC-2026-06-26` |
| `clientOrderId`   | string?                       | Your idempotency key. Recommended.                       |
| `type`            | `"limit"` \| `"market"`       | Default `"limit"`                                        |
| `side`            | `"buy"` \| `"sell"`           |                                                          |
| `price`           | string                        | Required for limit orders                                |
| `quantity`        | string                        |                                                          |
| `timeInForce`     | `"gtc"` \| `"ioc"` \| `"fok"` | Default `"gtc"`                                          |
| `postOnly`        | boolean                       | Cancels if the order would cross                         |
| `reduceOnly`      | boolean                       | Cannot increase position                                 |
| `marginMode`      | `"cross"` \| `"isolated"`     | Default `"cross"`                                        |
| `stopPrice`       | string?                       | Creates a conditional stop order                         |
| `takeProfitPrice` | string?                       | Attached take-profit trigger                             |
| `stopLossPrice`   | string?                       | Attached stop-loss trigger                               |

**Response**

```json
{
  "id":             "01HW...",
  "userId":         "01HW...",
  "marketId":       "BTC-PERP",
  "clientOrderId":  "bot-42",
  "side":           "buy",
  "type":           "limit",
  "price":          "67000.00",
  "quantity":       "0.5",
  "filledQuantity": "0",
  "status":         "open",
  "marginMode":     "cross",
  "createdAt":      "2026-04-24T12:00:00Z",
  "updatedAt":      "2026-04-24T12:00:00Z"
}
```

`status` is one of `open`, `filled`, `canceled`, `rejected`.

***

## POST /perps/orders/preview

Margin impact of a hypothetical order. Same request shape as `/perps/orders`.

**Auth**: required (`trade` scope).

**Response**

```json
{
  "approved":     true,
  "reason":       null,
  "marginImpact": {
    "initialMargin":     "5025.00",
    "maintenanceMargin": "3350.00"
  }
}
```

***

## POST /perps/quotes

Two-sided linear quote. Identical shape to `/quotes` in options.

***

## POST /perps/quotes/bulk

Bulk linear quotes. Identical shape to `/quotes/bulk` in options.

***

## POST /perps/orders/:id/cancel

Cancel a single order.

**Auth**: required (`trade` scope).

***

## POST /perps/orders/cancel-all

Cancel all orders, optionally filtered by `marketId`, `quoteId`, or `clientOrderId`.

**Auth**: required (`trade` scope).

**Response**

```json
{ "canceled": 5, "ids": ["01HW...", "..."] }
```

***

## GET /perps/orders

Your orders.

**Auth**: required.

**Query**

| Parameter    | Type                      | Description           |
| ------------ | ------------------------- | --------------------- |
| `limit`      | number                    | Default 100           |
| `marketId`   | string                    | Filter by market      |
| `marginMode` | `"cross"` \| `"isolated"` | Filter by margin mode |

***

## GET /perps/orders/open

Open orders only.

**Auth**: required.

***

## GET /perps/positions

Your open positions across spot, perps, and futures.

**Auth**: required.

**Response**

```json
[
  {
    "marketId":       "BTC-PERP",
    "side":           "long",
    "quantity":       "0.5",
    "avgPrice":       "66500.00",
    "markPrice":      "67000.00",
    "realizedPnl":    "0",
    "unrealizedPnl":  "250.00",
    "fundingPayment": "-1.25",
    "marginMode":     "cross",
    "initialMargin":  "5025.00",
    "maintenanceMargin": "3350.00"
  }
]
```

***

## POST /perps/positions/close

Close a position by placing the appropriate reduce-only market order.

**Auth**: required (`trade` scope).

**Request**

```json
{ "marketId": "BTC-PERP", "quantity": "0.5" }
```

Omit `quantity` to close the full position.

**Response**: the resulting fill or reduce-only order object.

***

## GET /perps/trades

Your fills across linear products.

**Auth**: required.

**Response**

```json
[
  {
    "tradeId":   "01HW...",
    "marketId":  "BTC-PERP",
    "orderId":   "01HW...",
    "side":      "buy",
    "price":     "66500.00",
    "quantity":  "0.5",
    "fee":       "16.625",
    "feeBps":    "5",
    "role":      "taker",
    "createdAt": "2026-04-24T11:55:00Z"
  }
]
```

`role` is either `taker` or `maker`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ocx.gitbook.io/ocx-doc/ocx/api/perpetuals-trading.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
