grid2: narrow down orderQueryService support checking

This commit is contained in:
c9s 2022-12-05 19:31:44 +08:00
parent 5d441e3efe
commit fae61bd91f

View File

@ -241,14 +241,17 @@ func (s *Strategy) handleOrderFilled(o types.Order) {
// collect trades
baseSellQuantityReduction := fixedpoint.Zero
if s.orderQueryService != nil {
orderTrades := s.historicalTrades.GetOrderTrades(o)
s.logger.Infof("FILLED ORDER TRADES: %+v", orderTrades)
if len(orderTrades) > 0 {
s.logger.Infof("FOUND FILLED ORDER TRADES: %+v", orderTrades)
}
// TODO: check if there is no missing trades
// TODO: should be only for BUY order
if !s.verifyOrderTrades(o, orderTrades) {
s.logger.Warnf("missing order trades or missing trade fee, pulling order trades from API")
// if orderQueryService is supported, use it to query the trades of the filled order
if s.orderQueryService != nil {
apiOrderTrades, err := s.orderQueryService.QueryOrderTrades(context.Background(), types.OrderQuery{
Symbol: o.Symbol,
OrderID: strconv.FormatUint(o.OrderID, 10),
@ -259,6 +262,7 @@ func (s *Strategy) handleOrderFilled(o types.Order) {
orderTrades = apiOrderTrades
}
}
}
if s.verifyOrderTrades(o, orderTrades) {
// check if there is a BaseCurrency fee collected
@ -268,7 +272,6 @@ func (s *Strategy) handleOrderFilled(o types.Order) {
s.logger.Infof("baseSellQuantityReduction: %f %s", baseSellQuantityReduction.Float64(), s.Market.BaseCurrency)
}
}
}
// check order fee
newSide := types.SideTypeSell