# Generate grid for orders

I want to build some function that will generate a grid of orders with some conditions. I want to generate 10 orders with a base asset price of 100 to 200. I'm using geometric progression for it

minPrice = 100
maxPrice = 200
orders = 10

k = (maxPrice/minPrice) ** (1/ (orders-1))

prices = [minPrice]
for i in range (orders-1):
minPrice = minPrice * k
prices.append(minPrice)
print([round(price,2) for price in prices])
>>> [100, 108.01, 116.65, 125.99, 136.08, 146.97, 158.74, 171.45, 185.17, 200.0]


I have a limit of quote currency - \$1000.

So for now I need to define the base/quote amount for each price level. My purpose that after all limit orders filled my entry price need to be around 135. I need some common algo that would work with any price range and orders amount and put my entry price on 35% in min/max price range.

• Not clear to me what is given and what is to be found. If the prices you listed are given, and we choose the order amounts based on a linear progression then amounts proportional to [1.0000, 0.9867 ,0.9733, 0.9600, 0.9467, 0.9334, 0.9200, 0.9067, 0.8934, 0.8800] would give an average price of 135. Does that work? Jul 2, 2021 at 13:35
• Yep, this would work. How did you get K for this linear progression? Jul 2, 2021 at 13:42
• That's over my excel skills. Could you give me more info? Or way how to turn it into a formula? Jul 2, 2021 at 14:09

I will write some pseudocode.

N = 10 /* number of orders */
prices = [100, 108.01, 116.65, 125.99, 136.08, 146.97, 158.74, 171.45, 185.17, 200.0] /* these are the given prices */
ones = [1,1,1,1,1,1,1,1,1,1] /* N ones */
staircase = [0,1,2,3,4,5,6,7,8,9] /* starts at 0 and counts up by 1 until N-1 */
desired_avg_price = 135

avg_price_eqweighted = AVERAGE(prices) /* average price when all orders are of size 1 */
print(avg_price_eqweighted) => 144.906...
trial = SUMPRODUCT(prices, staircase)/N /* average with staircase as weights */
print(trial) => 743.24
delta = (desired_avg_price-avg_price_eqweighted)/trial
print(delta) => -0.013328131
weights = ones+delta*staircase
print(weights) => [1.0000, 0.9867 ,0.9733, 0.9600, 0.9467, 0.9334, 0.9200, 0.9067, 0.8934, 0.8800]


It is a bit clumsy but it does the job. It needs to be rewritten in proper Python and tested.

print(SUMPRODUCT(prices,weights)/N) => 135