grid2: use profit to buy more inventory

This commit is contained in:
c9s 2022-12-03 15:18:47 +08:00
parent d5cf1a7311
commit 9bb628328c
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -142,6 +142,10 @@ func (s *Strategy) handleOrderFilled(o types.Order) {
newPrice = fixedpoint.Value(pin) newPrice = fixedpoint.Value(pin)
} }
// use the profit to buy more inventory in the grid
quoteQuantity := o.Quantity.Mul(o.Price)
newQuantity = quoteQuantity.Div(newPrice)
case types.SideTypeBuy: case types.SideTypeBuy:
newSide = types.SideTypeSell newSide = types.SideTypeSell
if pin, ok := s.grid.NextHigherPin(newPrice); ok { if pin, ok := s.grid.NextHigherPin(newPrice); ok {
@ -156,8 +160,8 @@ func (s *Strategy) handleOrderFilled(o types.Order) {
Price: newPrice, Price: newPrice,
Side: newSide, Side: newSide,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
Tag: "grid",
Quantity: newQuantity, Quantity: newQuantity,
Tag: "grid",
} }
s.logger.Infof("SUBMIT ORDER: %s", orderForm.String()) s.logger.Infof("SUBMIT ORDER: %s", orderForm.String())