From 61892eb2df10965da2de1241e8d239206901162e Mon Sep 17 00:00:00 2001 From: chiahung Date: Fri, 28 Apr 2023 16:02:22 +0800 Subject: [PATCH] renaming --- pkg/strategy/grid2/recover.go | 11 ++++++++++- pkg/strategy/grid2/twin_order.go | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/strategy/grid2/recover.go b/pkg/strategy/grid2/recover.go index 67f7111d4..0a69245cd 100644 --- a/pkg/strategy/grid2/recover.go +++ b/pkg/strategy/grid2/recover.go @@ -313,8 +313,8 @@ func addOrdersIntoPinOrderMap(pinOrders PinOrderMap, orders []types.Order) error func (s *Strategy) verifyFilledTwinGrid(pins []Pin, twinOrders TwinOrderMap, filledOrders []types.Order) error { s.debugLog("verifying filled grid - pins: %+v", pins) - s.debugLog("verifying filled grid - open twin orders:\n%s", twinOrders.String()) s.debugOrders("verifying filled grid - filled orders", filledOrders) + s.debugLog("verifying filled grid - open twin orders:\n%s", twinOrders.String()) if err := s.addOrdersIntoTwinOrderMap(twinOrders, filledOrders); err != nil { return errors.Wrapf(err, "verifying filled grid error when add orders into twin order map") @@ -323,6 +323,7 @@ func (s *Strategy) verifyFilledTwinGrid(pins []Pin, twinOrders TwinOrderMap, fil s.debugLog("verifying filled grid - filled twin orders:\n%+v", twinOrders.String()) for i, pin := range pins { + // we use twinOrderMap to make sure there are no duplicated order at one grid, and we use the sell price as key so we skip the pins[0] which is only for buy price if i == 0 { continue } @@ -335,6 +336,10 @@ func (s *Strategy) verifyFilledTwinGrid(pins []Pin, twinOrders TwinOrderMap, fil if !twin.Exist() { return fmt.Errorf("all the price need a twin") } + + if !twin.IsValid() { + return fmt.Errorf("all the twins need to be valid") + } } return nil @@ -421,6 +426,10 @@ func (s *Strategy) buildFilledTwinOrderMapFromTrades(ctx context.Context, histor // avoid query this order again existedOrders.Add(*order) + if order.GroupID != s.OrderGroupID { + continue + } + // add 1 to avoid duplicate fromTradeID = trade.ID + 1 diff --git a/pkg/strategy/grid2/twin_order.go b/pkg/strategy/grid2/twin_order.go index 12ffbaf95..e05e2b4e0 100644 --- a/pkg/strategy/grid2/twin_order.go +++ b/pkg/strategy/grid2/twin_order.go @@ -68,13 +68,13 @@ func findTwinOrderMapKey(grid *Grid, order types.Order) (fixedpoint.Value, error func (m TwinOrderMap) AscendingOrders() []types.Order { var orders []types.Order - for _, order := range m { + for _, twinOrder := range m { // skip empty order - if !order.Exist() { + if !twinOrder.Exist() { continue } - orders = append(orders, order.GetOrder()) + orders = append(orders, twinOrder.GetOrder()) } types.SortOrdersUpdateTimeAscending(orders)