mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
grid2: add last price == sell price case
This commit is contained in:
parent
862848721f
commit
8e426ca4bf
|
@ -245,6 +245,45 @@ func TestStrategy_generateGridOrders(t *testing.T) {
|
||||||
}, orders)
|
}, 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) {
|
t.Run("enough base + quote", func(t *testing.T) {
|
||||||
s := newTestStrategy()
|
s := newTestStrategy()
|
||||||
s.grid = NewGrid(s.LowerPrice, s.UpperPrice, fixedpoint.NewFromInt(s.GridNum), s.Market.TickSize)
|
s.grid = NewGrid(s.LowerPrice, s.UpperPrice, fixedpoint.NewFromInt(s.GridNum), s.Market.TickSize)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user