grid2: add last price == sell price case

This commit is contained in:
c9s 2023-05-25 13:31:19 +08:00
parent 862848721f
commit 8e426ca4bf
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -245,6 +245,45 @@ func TestStrategy_generateGridOrders(t *testing.T) {
}, orders)
})
t.Run("base and quote with last price eq sell price", func(t *testing.T) {
s := newTestStrategy()
s.grid = NewGrid(s.LowerPrice, s.UpperPrice, fixedpoint.NewFromInt(s.GridNum), s.Market.TickSize)
s.grid.CalculateArithmeticPins()
s.BaseGridNum = 4
quoteInvestment := number(10_000.0)
baseInvestment := number(0.1)
lastPrice := number(17000) // last price should not affect the sell order calculation
quantity, err := s.calculateBaseQuoteInvestmentQuantity(quoteInvestment, baseInvestment, lastPrice, s.grid.Pins)
assert.NoError(t, err)
assert.Equal(t, number(0.025), quantity)
s.QuantityOrAmount.Quantity = quantity
orders, err := s.generateGridOrders(quoteInvestment, baseInvestment, lastPrice)
assert.NoError(t, err)
if !assert.Equal(t, 10, len(orders)) {
for _, o := range orders {
t.Logf("- %s %s", o.Price.String(), o.Side)
}
}
assertPriceSide(t, []PriceSideAssert{
{number(20000.0), types.SideTypeSell},
{number(19000.0), types.SideTypeSell},
{number(18000.0), types.SideTypeSell},
{number(17000.0), types.SideTypeSell},
// -- 16_000 should be empty
{number(15000.0), types.SideTypeBuy},
{number(14000.0), types.SideTypeBuy},
{number(13000.0), types.SideTypeBuy},
{number(12000.0), types.SideTypeBuy},
{number(11000.0), types.SideTypeBuy},
{number(10000.0), types.SideTypeBuy},
}, orders)
})
t.Run("enough base + quote", func(t *testing.T) {
s := newTestStrategy()
s.grid = NewGrid(s.LowerPrice, s.UpperPrice, fixedpoint.NewFromInt(s.GridNum), s.Market.TickSize)