mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
grid2: add recoverGrid
This commit is contained in:
parent
1fd431df5f
commit
330be79ec6
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -986,6 +987,33 @@ func (s *Strategy) checkMinimalQuoteInvestment() error {
|
||||||
return nil
|
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 {
|
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
||||||
instanceID := s.InstanceID()
|
instanceID := s.InstanceID()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user