grid2: pull out processFilledOrder method

This commit is contained in:
c9s 2022-12-15 14:57:25 +08:00
parent 8c575f6f3c
commit 532d474564
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -197,7 +197,6 @@ func (s *Strategy) handleOrderCanceled(o types.Order) {
} }
} }
// TODO: consider order fee
func (s *Strategy) calculateProfit(o types.Order, buyPrice, buyQuantity fixedpoint.Value) *GridProfit { func (s *Strategy) calculateProfit(o types.Order, buyPrice, buyQuantity fixedpoint.Value) *GridProfit {
if s.EarnBase { if s.EarnBase {
// sell quantity - buy quantity // sell quantity - buy quantity
@ -300,14 +299,7 @@ func (s *Strategy) aggregateOrderBaseFee(o types.Order) fixedpoint.Value {
return fixedpoint.Zero return fixedpoint.Zero
} }
// handleOrderFilled is called when an order status is FILLED func (s *Strategy) processFilledOrder(o types.Order) {
func (s *Strategy) handleOrderFilled(o types.Order) {
if s.grid == nil {
return
}
s.logger.Infof("GRID ORDER FILLED: %s", o.String())
// check order fee // check order fee
newSide := types.SideTypeSell newSide := types.SideTypeSell
newPrice := o.Price newPrice := o.Price
@ -386,6 +378,16 @@ func (s *Strategy) handleOrderFilled(o types.Order) {
} }
} }
// handleOrderFilled is called when an order status is FILLED
func (s *Strategy) handleOrderFilled(o types.Order) {
if s.grid == nil {
return
}
s.logger.Infof("GRID ORDER FILLED: %s", o.String())
s.processFilledOrder(o)
}
func (s *Strategy) checkRequiredInvestmentByQuantity(baseBalance, quoteBalance, quantity, lastPrice fixedpoint.Value, pins []Pin) (requiredBase, requiredQuote fixedpoint.Value, err error) { func (s *Strategy) checkRequiredInvestmentByQuantity(baseBalance, quoteBalance, quantity, lastPrice fixedpoint.Value, pins []Pin) (requiredBase, requiredQuote fixedpoint.Value, err error) {
// check more investment budget details // check more investment budget details
requiredBase = fixedpoint.Zero requiredBase = fixedpoint.Zero