From 330be79ec6fd60f8a2746d4c68f20de385431a98 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 20 Dec 2022 15:56:38 +0800 Subject: [PATCH] grid2: add recoverGrid --- pkg/strategy/grid2/strategy.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index 6c80df5ec..c829ae3f8 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -5,6 +5,7 @@ import ( "fmt" "strconv" "sync" + "time" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -986,6 +987,33 @@ func (s *Strategy) checkMinimalQuoteInvestment() error { return nil } +func (s *Strategy) recoverGrid(ctx context.Context, session *bbgo.ExchangeSession) error { + historyService, ok := session.Exchange.(types.ExchangeTradeHistoryService) + if !ok { + return nil + } + + orders, err := session.Exchange.QueryOpenOrders(ctx, s.Symbol) + if err != nil { + return err + } + + firstOrderTime := orders[0].CreationTime.Time() + for _, o := range orders { + if o.CreationTime.Before(firstOrderTime) { + firstOrderTime = o.CreationTime.Time() + } + } + + closedOrders, err := historyService.QueryClosedOrders(ctx, s.Symbol, firstOrderTime, time.Now(), 0) + if err != nil { + return err + } + + _ = closedOrders + return nil +} + func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { instanceID := s.InstanceID()