# Trading (/docs/tools/trading)



These tools **place and change real orders and positions**. They register
whenever credentials are present, alongside the account tools. Whether a call
executes is decided by your key: Delta accepts what a **Trading** key sends and
rejects what a **Read Data** key sends (see
[Authentication](/docs/authentication)).

<Callout type="warn" title="These tools move real money">
  There is no rehearsal step. A call with a Trading key goes to Delta as sent, with
  no size cap and no confirmation prompt, sized in contracts rather than coins.
  Prices are sent exactly as typed, and Delta moves an off-tick price onto the
  product's tick. Mutations are **never** auto-retried, because re-sending an order
  can place it twice. Rehearse on `india_testnet`.
</Callout>

## What the server still checks [#what-the-server-still-checks]

Three request-shape checks remain, and they fail before anything is sent:

* Exactly one of `product_id` / `product_symbol` on every tool that names a
  product.
* Exactly one of `id` / `client_order_id` on `cancel_order`.
* At least one leg on `place_bracket_order`.

Everything else is Delta's answer, returned as given.

## place\_order [#place_order]

Place a single limit, market, or stop order. Supports attached brackets.

**Auth:** API key; a Trading key to execute

| Param                             | Type   | Required | Notes                                                 |
| --------------------------------- | ------ | -------- | ----------------------------------------------------- |
| `size`                            | int    | yes      | order size in contracts (positive)                    |
| `side`                            | string | yes      | `buy` or `sell`                                       |
| `order_type`                      | string | yes      | `limit_order` or `market_order`                       |
| `product_id`                      | int    | no       | pass exactly one of `product_id` / `product_symbol`   |
| `product_symbol`                  | string | no       | e.g. `BTCUSD`                                         |
| `limit_price`                     | string | no       | required for `limit_order`; ignored on `market_order` |
| `stop_order_type`                 | string | no       | `stop_loss_order` or `take_profit_order`              |
| `stop_price`                      | string | no       | trigger price for stop orders                         |
| `trail_amount`                    | string | no       | trailing-stop amount                                  |
| `stop_trigger_method`             | string | no       | `mark_price`, `last_traded_price`, `spot_price`       |
| `time_in_force`                   | string | no       | `gtc` or `ioc`                                        |
| `post_only`                       | bool   | no       | reject if it would take liquidity                     |
| `reduce_only`                     | bool   | no       | only reduce an existing position                      |
| `client_order_id`                 | string | no       | your id, max 32 chars                                 |
| `bracket_stop_loss_price`         | string | no       | attached-bracket SL trigger                           |
| `bracket_stop_loss_limit_price`   | string | no       | attached-bracket SL limit                             |
| `bracket_take_profit_price`       | string | no       | attached-bracket TP trigger                           |
| `bracket_take_profit_limit_price` | string | no       | attached-bracket TP limit                             |
| `bracket_trail_amount`            | string | no       | attached-bracket trailing amount                      |
| `bracket_stop_trigger_method`     | string | no       | trigger method for the bracket                        |

Passing the `bracket_*` params here creates an **entry-order** bracket whose id
(the returned order id) is what `edit_bracket_order` later expects. (That differs
from `place_bracket_order`, which attaches a bracket to an open position.)

**Prices are sent exactly as given.** Delta moves an off-tick price onto the
product's tick, so the `limit_price` in the response is the one that applies.

```text
Place a GTC limit buy of 5 ETHUSD at 3400 with a take-profit at 3600 and a
stop-loss at 3250.
```

## edit\_order [#edit_order]

Edit an open order's size or price.

**Auth:** API key; a Trading key to execute

| Param            | Type   | Required | Notes                                               |
| ---------------- | ------ | -------- | --------------------------------------------------- |
| `id`             | int    | yes      | order id to edit                                    |
| `size`           | int    | yes      | total size after the edit                           |
| `product_id`     | int    | no       | pass exactly one of `product_id` / `product_symbol` |
| `product_symbol` | string | no       | e.g. `BTCUSD`                                       |
| `limit_price`    | string | no       | new limit price                                     |
| `stop_price`     | string | no       | new stop trigger price                              |
| `trail_amount`   | string | no       | new trailing-stop amount                            |
| `post_only`      | bool   | no       | reject if it would take liquidity                   |

Prices are sent exactly as given. Delta moves an off-tick price onto the product's
tick, so the `limit_price` in the response is the one that applies.

```text
Move my open BTCUSD order 123456789 to a limit price of 71500.
```

## cancel\_order [#cancel_order]

Cancel a single order by id or client order id.

**Auth:** API key; a Trading key to execute

| Param             | Type   | Required | Notes                        |
| ----------------- | ------ | -------- | ---------------------------- |
| `product_id`      | int    | yes      | product the order belongs to |
| `id`              | int    | no       | order id to cancel           |
| `client_order_id` | string | no       | your client order id         |

Pass **exactly one** of `id` or `client_order_id`.

```text
Cancel my open BTCUSD order 123456789.
```

## cancel\_all\_orders [#cancel_all_orders]

Cancel open orders, optionally scoped by product or contract type.

**Auth:** API key; a Trading key to execute

| Param            | Type      | Required | Notes                                                 |
| ---------------- | --------- | -------- | ----------------------------------------------------- |
| `product_id`     | int       | no       | limit to one product                                  |
| `contract_types` | string\[] | no       | limit to contract types (ignored if `product_id` set) |

Limit orders, stop orders and reduce-only orders are all cancelled. There is no
flag to exclude a kind.

<Callout type="warn" title="With no filters this cancels everything">
  Called bare, this cancels every open order on the account. `product_id` and
  `contract_types` are the only way to narrow it.
</Callout>

```text
Cancel all my open orders on BTCUSD.
```

## place\_batch\_orders [#place_batch_orders]

Place several orders on one contract in a single request.

**Auth:** API key; a Trading key to execute

| Param            | Type      | Required | Notes                                                                                                                    |
| ---------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| `orders`         | object\[] | yes      | each `{size, side, order_type, limit_price?, time_in_force?, post_only?, client_order_id?}`. Same contract. No IOC/stop. |
| `product_id`     | int       | no       | pass exactly one of `product_id` / `product_symbol`                                                                      |
| `product_symbol` | string    | no       | e.g. `BTCUSD`                                                                                                            |

`client_order_id` must be unique within the batch. Delta's response is returned
as given, and nothing annotates it. When it comes back with fewer orders than you
sent, the missing ones were not accepted: compare the two lists before you resend
anything, because resending a leg that did go live places it twice.

```text
Place a ladder of 5 BTCUSD limit buys: 2 contracts each at 70000, 69500, 69000,
68500, 68000.
```

## edit\_batch\_orders [#edit_batch_orders]

Edit several orders on one contract in a single request.

**Auth:** API key; a Trading key to execute

| Param            | Type      | Required | Notes                                                   |
| ---------------- | --------- | -------- | ------------------------------------------------------- |
| `orders`         | object\[] | yes      | each `{id, size, order_type, limit_price?, post_only?}` |
| `product_id`     | int       | no       | pass exactly one of `product_id` / `product_symbol`     |
| `product_symbol` | string    | no       | e.g. `BTCUSD`                                           |

```text
Reprice all my open ETHUSD ladder orders down by 50.
```

## cancel\_batch\_orders [#cancel_batch_orders]

Cancel several orders on one contract in a single request.

**Auth:** API key; a Trading key to execute

| Param            | Type      | Required | Notes                                               |
| ---------------- | --------- | -------- | --------------------------------------------------- |
| `orders`         | object\[] | yes      | each `{id}` or `{client_order_id}`                  |
| `product_id`     | int       | no       | pass exactly one of `product_id` / `product_symbol` |
| `product_symbol` | string    | no       | e.g. `BTCUSD`                                       |

```text
Cancel orders 111, 222, and 333 on BTCUSD in one request.
```

## place\_bracket\_order [#place_bracket_order]

Attach a take-profit / stop-loss bracket to an open position. Provide at least
one leg.

**Auth:** API key; a Trading key to execute

| Param                         | Type   | Required | Notes                                                   |
| ----------------------------- | ------ | -------- | ------------------------------------------------------- |
| `product_id`                  | int    | no       | pass exactly one of `product_id` / `product_symbol`     |
| `product_symbol`              | string | no       | e.g. `BTCUSD`                                           |
| `stop_loss_order`             | object | no       | `{order_type, stop_price, limit_price?, trail_amount?}` |
| `take_profit_order`           | object | no       | `{order_type, stop_price, limit_price?}`                |
| `bracket_stop_trigger_method` | string | no       | `mark_price`, `last_traded_price`, `spot_price`         |

These position-bracket legs are **not** editable via `edit_bracket_order` — cancel
and re-place to change them. (`edit_bracket_order` only edits entry-order brackets
created through `place_order`.)

```text
On my open BTCUSD position, attach a stop-loss at 68000 and a take-profit at
75000.
```

## edit\_bracket\_order [#edit_bracket_order]

Edit the bracket (TP/SL) params on an existing **entry order**.

**Auth:** API key; a Trading key to execute

| Param                             | Type   | Required | Notes                                               |
| --------------------------------- | ------ | -------- | --------------------------------------------------- |
| `id`                              | int    | yes      | entry-order id whose bracket to update              |
| `product_id`                      | int    | no       | pass exactly one of `product_id` / `product_symbol` |
| `product_symbol`                  | string | no       | e.g. `BTCUSD`                                       |
| `bracket_stop_loss_price`         | string | no       | stop-loss trigger price                             |
| `bracket_stop_loss_limit_price`   | string | no       | stop-loss limit price                               |
| `bracket_take_profit_price`       | string | no       | take-profit trigger price                           |
| `bracket_take_profit_limit_price` | string | no       | take-profit limit price                             |
| `bracket_trail_amount`            | string | no       | trailing-stop amount                                |
| `bracket_stop_trigger_method`     | string | no       | `mark_price`, `last_traded_price`, `spot_price`     |

`id` is the **entry-order** id (an order created with `bracket_*` params via
`place_order`). It does not accept the leg ids of a position bracket from
`place_bracket_order`.

```text
On entry order 123456789, raise the take-profit to 76000.
```

## set\_product\_leverage [#set_product_leverage]

Set order leverage for a product.

**Auth:** API key; a Trading key to execute

| Param        | Type   | Required | Notes                            |
| ------------ | ------ | -------- | -------------------------------- |
| `product_id` | int    | yes      | product to set leverage for      |
| `leverage`   | string | yes      | leverage multiplier, e.g. `'10'` |

```text
Set my BTCUSD order leverage to 10x.
```

## adjust\_position\_margin [#adjust_position_margin]

Add or remove isolated margin on a position.

**Auth:** API key; a Trading key to execute

| Param          | Type   | Required | Notes                                                       |
| -------------- | ------ | -------- | ----------------------------------------------------------- |
| `product_id`   | int    | yes      | product id of the position                                  |
| `delta_margin` | string | yes      | margin to add (positive) or remove (negative), e.g. `'5.0'` |

```text
Add 5 USDT of isolated margin to my BTCUSD position.
```

## close\_all\_positions [#close_all_positions]

Close every open position on the account, both cross / portfolio-margined and
isolated.

**Auth:** API key; a Trading key to execute

No parameters.

<Callout type="warn" title="This closes your entire account">
  There is no narrower call. Both margin scopes are closed, and there is no flag
  that limits it to a product or a scope. The server looks up your `user_id`
  itself. To close less than everything, cancel and close by product instead.
</Callout>

```text
Close every open position on my account.
```

## configure\_auto\_topup [#configure_auto_topup]

Override auto top-up for a single position.

**Auth:** API key; a Trading key to execute

| Param        | Type | Required | Notes                                           |
| ------------ | ---- | -------- | ----------------------------------------------- |
| `product_id` | int  | yes      | product id of the position                      |
| `auto_topup` | bool | yes      | enable or disable auto top-up for this position |

```text
Turn on auto top-up for my BTCUSD position.
```
