Skip to content
All library documents

Creating Market, Limit, Stop-Loss, and Trailing Orders in OctoBot

Article OctoBot

Summary

This guide explains how to create market, limit, stop-loss, and trailing-market orders with OctoBot Script. It describes order sizing for spot and futures trading, including fixed asset amounts, percentages of portfolio value, and percentages of available holdings. Price offsets can be relative to the current market price or set to an absolute price; market orders do not use offsets.

The guide also covers attaching stop-loss and take-profit orders that activate after an entry fills. When both are attached, they are grouped so that filling or canceling one cancels the other. For futures, regular orders open or update positions, an opposite-side order or a zero target position can close a position, and leverage can be changed separately. The document is an API usage explanation rather than a strategy evaluation: it provides examples but no performance evidence, and it does not discuss execution risks, exchange differences, or how to select order parameters.

Key ideas

  • Orders support market, limit, stop-loss, and trailing-market types.
  • Order amounts can be expressed as fixed units or as a share of portfolio value or available holdings.
  • Limit prices and attached stop-loss or take-profit prices use relative or absolute offsets.
  • Paired stop-loss and take-profit orders cancel the other when either is filled or canceled.
  • Futures positions can be opened or adjusted with regular orders and closed by setting the target position to zero.

Tags

Full text
# Créer des ordres de trading


---
title: "Créer des ordres"
description: "Apprenez comment créer des ordres de marché, à seuil, de limite, de stop-loss et de trailing avec Python en utilisant OctoBot Script."
sidebar_position: 6
---



# Créer des ordres de trading

:::info
  La traduction française de cette page est en cours.
:::

Orders can be created using the following keywords:
- `market`
- `limit`
- `stop_loss`
- `trailing_market`

## Montant
Each order accept the following optional arguments:
- `amount`: for spot and futures trading
- `target_position`: futures trading only: create the associated order to update to position size to the given value. Uses the same format as the order amount.

To specify the amount per order, use the following syntax:
- `0.1` to trade 0.1 BTC on BTC/USD 
- `2%` to trade 2% of the total portfolio value
- `12%a` to trade 12% of the available holdings

``` python
# create a buy market order using 10% of the total portfolio
await obs.market(ctx, "buy", amount="10%")
```

## Prix
Orders set their price using the `offset` argument.

To specify the order price, use the following syntax:
- `10` to set the price 10 USD above the current BTC/USD market price 
- `2%` to set the price 2% USD above the current BTC/USD market price
- `@15555` to set the price at exactly 15555 USD regardless of the current BTC/USD market price

``` python
# create a buy limit order of 0.2 units (BTC when trading BTC/USD) 
# with a price at 1% below the current price
await obs.limit(ctx, "buy", amount="0.2", offset="-1%")
```

Note: market orders do not accept the `offset` argument.

## Take profit et stop losses automatisés
When creating orders, it is possible to automate the associated 
stop loss and / or take profits. When doing to, the associated take profit/stop loss will have 
the same amount as the initial order.

Their price can be set according to the same rules as the initial order price 
(the `offset` argument) using the following optional argument:
- `stop_loss_offset`: automate a stop loss creation when the initial order is filled and set the stop loss price
- `take_profit_offset`: automate a take profit creation when the initial order is filled and set the take profit price

``` python
# create a buy limit order of 0.2 units (BTC when trading BTC/USD) with: 
# - price at 1% below the current price
# - stop loss at 10% loss
# - take profit at 15% profit
await obs.limit(ctx, "buy", amount="0.2", offset="-1%", stop_loss_offset="-10%", take_profit_offset="15%")
```

> When using both `stop_loss_offset` and `take_profit_offset`, two orders will be created after the initial order fill.
Those two orders will be grouped together, meaning that if one is cancelled or filled, the other will be cancelled.

## Trader des futures

### Ouvrir une position
Use regular orders to open a position. When the order is filled, the associated position will be created, updated or closed.

A sell order will open a short position if your balance becomes negative after filling this order.

### Clôturer une position
Set the position size to 0 to close it. You can do it either by:
- Filling an order with the same amount as the position size and an opposite side
- Or using `target_position=0` as order parameters


### Changer le levier

Use `set_leverage` to update the current leverage value when trading futures.

``` python
await obs.set_leverage(ctx, 5)
```

Shown in full with attribution under the source's licence. Licence: GPL-3.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.