> For the complete documentation index, see [llms.txt](https://docs.origami.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.origami.tech/user-guide/grids-examples/placing-orders-at-the-best-price-or-with-a-minimum-spread.md).

# Placing Orders at the Best Price or with a Minimum Spread

Orders are placed either with a spread around the current price or at the best price if the spread exceeds the minimum set value.

```json
{
"gap": "0.005",
"min_spread": "0.02",
"pivot_price": "(orderbook().ask[0].price+orderbook().bid[0].price+ticker())/3",
"execute_price": "(pivot_price*(1-min_spread/2+(order_pos+1)*gap) if pivot_price*(1-min_spread/2)<=(orderbook().bid[0].price+symbol().price_precision) else min(orderbook().bid[0].price + symbol().price_precision,orderbook().ask[0].price - symbol().price_precision)*(1+gap*(order_pos+1))) if side=='buy' else (pivot_price*(1+min_spread/2+(order_pos-1)*gap) if pivot_price*(1+min_spread/2)>=(orderbook().ask[0].price-symbol().price_precision) else max(orderbook().ask[0].price - symbol().price_precision,orderbook().bid[0].price + symbol().price_precision)*(1+gap*(order_pos-1)))",
"execute_volume": "20/execute_price + 0 * abs(order_pos)/execute_price",
"buy_orders_count": "5",
"sell_orders_count": "5"
}
```

In this example, the order price is determined as the average of three values:

* The last market trade.
* The best ask price.
* The best bid price.

<mark style="color:red;">`(`</mark> [<mark style="color:blue;">`orderbook`</mark>](/function/functions/orderbook.md)<mark style="color:red;">`().ask[0].price +`</mark> [<mark style="color:blue;">`orderbook`</mark>](/function/functions/orderbook.md)<mark style="color:red;">`().bid[0].price +`</mark>[<mark style="color:blue;">`ticker`</mark>](/function/functions/ticker.md)<mark style="color:red;">`())/3`</mark>

Orders are then placed either at the best price or with a 2% spread if the current spread is smaller.

The price increment is defined as `(`[<mark style="color:blue;">`order_pos`</mark>](/function/pre-defined-parameters/order-pos.md) `+ 1) * gap` for bids and `(`[<mark style="color:blue;">`order_pos`</mark>](/function/pre-defined-parameters/order-pos.md) `- 1) * gap` for asks, where gap is set to 0.5%.

Each order is placed for the equivalent of 20 counter tokens without increasing the volume for subsequent orders. To enable volume increments, replace 0 with the desired increment value.

<mark style="color:red;">`20/`</mark>[<mark style="color:blue;">`execute_price`</mark>](/function/required-parameters/execute-price.md) <mark style="color:red;">`+ 0 *`</mark> [<mark style="color:blue;">`abs`</mark>](/function/functions/abs.md)<mark style="color:red;">`(`</mark>[<mark style="color:blue;">`order_pos`</mark>](/function/pre-defined-parameters/order-pos.md)<mark style="color:red;">`)/`</mark>[<mark style="color:blue;">`execute_price`</mark>](/function/required-parameters/execute-price.md)
