mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
grid2: check if we have o.AveragePrice, use it for newQuantity
This commit is contained in:
parent
7eb953093c
commit
04da988639
|
@ -363,7 +363,13 @@ func (s *Strategy) processFilledOrder(o types.Order) {
|
|||
newSide := types.SideTypeSell
|
||||
newPrice := o.Price
|
||||
newQuantity := o.Quantity
|
||||
orderQuoteQuantity := o.Quantity.Mul(o.Price)
|
||||
executedPrice := o.Price
|
||||
if o.AveragePrice.Sign() > 0 {
|
||||
executedPrice = o.AveragePrice
|
||||
}
|
||||
|
||||
// will be used for calculating quantity
|
||||
orderExecutedQuoteAmount := o.Quantity.Mul(executedPrice)
|
||||
|
||||
// collect trades
|
||||
baseSellQuantityReduction := fixedpoint.Zero
|
||||
|
@ -382,7 +388,7 @@ func (s *Strategy) processFilledOrder(o types.Order) {
|
|||
|
||||
// use the profit to buy more inventory in the grid
|
||||
if s.Compound || s.EarnBase {
|
||||
newQuantity = fixedpoint.Max(orderQuoteQuantity.Div(newPrice), s.Market.MinQuantity)
|
||||
newQuantity = fixedpoint.Max(orderExecutedQuoteAmount.Div(newPrice), s.Market.MinQuantity)
|
||||
} else if s.QuantityOrAmount.Quantity.Sign() > 0 {
|
||||
newQuantity = s.QuantityOrAmount.Quantity
|
||||
}
|
||||
|
@ -415,7 +421,7 @@ func (s *Strategy) processFilledOrder(o types.Order) {
|
|||
}
|
||||
|
||||
if s.EarnBase {
|
||||
newQuantity = fixedpoint.Max(orderQuoteQuantity.Div(newPrice).Sub(baseSellQuantityReduction), s.Market.MinQuantity)
|
||||
newQuantity = fixedpoint.Max(orderExecutedQuoteAmount.Div(newPrice).Sub(baseSellQuantityReduction), s.Market.MinQuantity)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user