Buying at the Best Price with Maximum Price and Balance Constraints

Buying at the best price with a cap on maximum buy price and current counter token balance

{
"gap": "0.005",
"execute_price": "min(orderbook().bid[0].price+symbol().price_precision,max_bid_price)*(1+gap*(order_pos+1))",
"max_bid_price": "orderbook().ask[0].price-symbol().price_precision",
"execute_volume": "10/execute_price+abs(order_pos)*10/execute_price",
"buy_orders_count": "5 if balance('counter').total > 5000 else 0",
"sell_orders_count": "0"
}

The grid places buy orders at the best available price. An additional parameter, gap, is used in calculating the order prices. In this example, gap is set to 0.5%.

1+gap*(order_pos-1)

max_bid_priceparameter in this case is defined as:

orderbook().ask[0].price-symbol().price_precision

which sets the maximum buy price to one price_precision below the best ask price. Alternatively, a specific numerical value can be used to set the limit.

The execute_volume parameter determines the base token amount, equivalent to 20 counter tokens for the first order, with an increment of 10 counter tokens for each subsequent order. The formula used is:

10/execute_price+abs(order_pos)*10/execute_price

Orders will continue to be placed until the balance of the counter token drops below 5000.

If needed, this limitation can be replaced with the aggregated balance across multiple exchanges group_balance('counter').current.total

5 if group_balance('counter').current.total > 5000 else 0

or with the balance of the base token, defined as: balance('base').total

5 if balance('base').total < 5000 else 0

Last updated