Buying at the Best Price Considering Historical Data
Buy orders are placed at the best available price, provided it does not exceed the max_bid_price or the midpoint between the average closing price and the average daily low over the past month.
The grid places buy orders at the best price, with an additional parameter, gap, used to calculate the order prices. In this example, the gap is set to 1%.
Price reduction: 1+gap*(
order_pos
+1)
As supplementary parameters, daily candlestick data for the past 30 days is retrieved:
candles
('d1', '
base
-
counter
',count=30)
Based on this data, the following additional parameters are calculated:
Average closing price over 30 days:
mean
([price.close for price in candles_1d])
Average daily low over 30 days:
mean
([price.low for price in candles_1d])
The order price is then determined as the maximum of:
The current best bid.
The maximum bid price: max_bid_price. In this case minimum of the current best ask price minus two price_precision and average closing price over 30 days.
The midpoint between the average closing price and the average daily low over the past 30 days.
Orders will be placed until the counter token balance exceeds 5000
If needed, this restriction 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 the base token balance
Last updated