> 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/getting-started/first-trade.md).

# first trade

This walkthrough covers buying `BTC-PERP` from both the UI and the API.

## From the UI

{% stepper %}
{% step %}

### Open the **Perps** page and select `BTC-PERP` from the market selector.

{% endstep %}

{% step %}

### Check the orderbook, mark price, and funding rate shown in the market header.

{% endstep %}

{% step %}

### In the order ticket:

* Choose **Limit** or **Market** order.
* Enter your **price** (limit only) and **size**.
* Pick a **time in force**: `GTC`, `IOC`, or `FOK`.
* Optionally enable **Post Only** (limit only — guarantees the order sits on the book as a maker).
  {% endstep %}

{% step %}

### Click **Buy / Long** or **Sell / Short**.

{% endstep %}

{% step %}

### Confirm the order preview showing the resulting position, initial margin, and estimated fees.

{% endstep %}
{% endstepper %}

The order appears under **Open Orders** or — if it executes immediately — under **Positions**.

## From the API

Before placing orders, make sure your `perps` bucket has collateral. See [Deposit USDC](broken://pages/69b82e7fcac3bbb5789a3ff3baa328e144d86672) for the transfer step.

{% stepper %}
{% step %}

### Preview the order

It's a good habit to preview every order so you know the margin impact before committing:

```http
POST /perps/orders/preview
Authorization: Bearer ocx_sk_...

{
  "marketId": "BTC-PERP",
  "side": "buy",
  "type": "limit",
  "price": "67000",
  "quantity": "0.1",
  "timeInForce": "gtc",
  "marginMode": "cross"
}
```

```json
{
  "approved": true,
  "reason": null,
  "marginImpact": {
    "initialMargin":     "100.50",
    "maintenanceMargin": "67.00"
  }
}
```

If `approved` is `false`, `reason` tells you why (usually `INSUFFICIENT_MARGIN`).
{% endstep %}

{% step %}

### Place the order

```http
POST /perps/orders
Authorization: Bearer ocx_sk_...

{
  "marketId": "BTC-PERP",
  "clientOrderId": "my-first-trade",
  "side": "buy",
  "type": "limit",
  "price": "67000",
  "quantity": "0.1",
  "timeInForce": "gtc",
  "marginMode": "cross"
}
```

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

{% endstep %}

{% step %}

### Watch fills and position

```http
GET /perps/positions
```

```http
GET /perps/trades
```

For live updates, subscribe to the orderbook stream at `/perps/book-stream` (SSE) or the price stream at `/ws/perps/prices` (WebSocket). See [Streams](file:///7302513/api/streams.md).
{% endstep %}

{% step %}

### Cancel an open order

```http
POST /perps/orders/{id}/cancel
```

Or cancel all open orders on a market:

```http
POST /perps/orders/cancel-all
{ "marketId": "BTC-PERP" }
```

{% endstep %}
{% endstepper %}

## Order types at a glance

| Type     | Behavior                                                                               |
| -------- | -------------------------------------------------------------------------------------- |
| `limit`  | Rests on the book at your specified price. Fills at that price or better when matched. |
| `market` | Executes immediately against the best available price. Can partially fill.             |

| Time in force | Behavior                                                                           |
| ------------- | ---------------------------------------------------------------------------------- |
| `gtc`         | Good-til-cancelled. Rests until filled or cancelled.                               |
| `ioc`         | Immediate-or-cancel. Fills what it can immediately; the rest is cancelled.         |
| `fok`         | Fill-or-kill. Either fills completely at the limit price or is cancelled entirely. |

| Flag         | Behavior                                                              |
| ------------ | --------------------------------------------------------------------- |
| `postOnly`   | Order is cancelled if it would cross the book (guarantees maker fee). |
| `reduceOnly` | Order cannot increase your position — only reduce it.                 |

## What's next

* Learn how [Margin & Risk](file:///7302513/product/margin-and-risk.md) computes your requirements.
* Browse the full [Perpetuals Trading API](file:///7302513/api/perpetuals-trading.md).
* Connect a live bot with [API Keys](file:///7302513/authentication/api-keys.md).


---

# 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/getting-started/first-trade.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.
