grid2: add recoverGrid

This commit is contained in:
c9s 2022-12-20 15:56:38 +08:00
parent 1fd431df5f
commit 330be79ec6
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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()