mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
grid2: add one more test case for base + quote
This commit is contained in:
parent
1cf788c925
commit
26cbd60a66
|
@ -205,6 +205,46 @@ func TestStrategy_generateGridOrders(t *testing.T) {
|
|||
}, orders)
|
||||
})
|
||||
|
||||
t.Run("base and quote with pre-calculated baseGridNumber", 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(12300) // 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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user