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.

{
"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.

( orderbook().ask[0].price + orderbook().bid[0].price +ticker())/3

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 (order_pos + 1) * gap for bids and (order_pos - 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.

20/execute_price + 0 * abs(order_pos)/execute_price

Last updated