mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
grid2: fix require quote and require base calculation
This commit is contained in:
parent
2c373959a8
commit
4c8db08ccc
|
@ -200,12 +200,32 @@ func (s *Strategy) setupGridOrders(ctx context.Context, session *bbgo.ExchangeSe
|
|||
pin := s.grid.Pins[i]
|
||||
price := fixedpoint.Value(pin)
|
||||
|
||||
q := s.QuantityOrAmount.CalculateQuantity(price)
|
||||
if price.Compare(lastPrice) >= 0 {
|
||||
// sell
|
||||
requiredBase = requiredBase.Add(q)
|
||||
// sell orders
|
||||
if requiredBase.Compare(totalBase) < 0 {
|
||||
if q := s.QuantityOrAmount.Quantity; !q.IsZero() {
|
||||
requiredBase = requiredBase.Add(s.QuantityOrAmount.Quantity)
|
||||
} else if amount := s.QuantityOrAmount.Amount; !amount.IsZero() {
|
||||
qq := s.QuantityOrAmount.CalculateQuantity(price)
|
||||
requiredBase = requiredBase.Add(qq)
|
||||
}
|
||||
} else if i > 0 {
|
||||
// convert buy quote to requiredQuote
|
||||
nextLowerPin := s.grid.Pins[i-1]
|
||||
nextLowerPrice := fixedpoint.Value(nextLowerPin)
|
||||
if q := s.QuantityOrAmount.Quantity; !q.IsZero() {
|
||||
requiredQuote = requiredQuote.Add(q.Mul(nextLowerPrice))
|
||||
} else if amount := s.QuantityOrAmount.Amount; !amount.IsZero() {
|
||||
requiredQuote = requiredQuote.Add(amount)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requiredQuote = requiredQuote.Add(q)
|
||||
// buy orders
|
||||
if q := s.QuantityOrAmount.Quantity; !q.IsZero() {
|
||||
requiredQuote = requiredQuote.Add(q.Mul(price))
|
||||
} else if amount := s.QuantityOrAmount.Amount; !amount.IsZero() {
|
||||
requiredQuote = requiredQuote.Add(amount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user