mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
call bbgo.Sync to sync persistence
This commit is contained in:
parent
5b239ad8ee
commit
6ef54bf2fb
|
@ -91,14 +91,18 @@ func (p *Persistence) Sync(obj interface{}) error {
|
|||
}
|
||||
|
||||
// Sync syncs the object properties into the persistence layer
|
||||
func Sync(obj interface{}) error {
|
||||
func Sync(obj interface{}) {
|
||||
id := callID(obj)
|
||||
if len(id) == 0 {
|
||||
return nil
|
||||
log.Warnf("InstanceID() is not provided, can not sync persistence")
|
||||
return
|
||||
}
|
||||
|
||||
ps := PersistenceServiceFacade.Get()
|
||||
return storePersistenceFields(obj, id, ps)
|
||||
err := storePersistenceFields(obj, id, ps)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("persistence sync failed")
|
||||
}
|
||||
}
|
||||
|
||||
func loadPersistenceFields(obj interface{}, id string, persistence service.PersistenceService) error {
|
||||
|
|
|
@ -494,7 +494,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
s.OnSuspend(func() {
|
||||
s.Status = types.StrategyStatusStopped
|
||||
_ = s.orderExecutor.GracefulCancel(ctx)
|
||||
_ = s.Persistence.Sync(s)
|
||||
bbgo.Sync(s)
|
||||
})
|
||||
|
||||
s.OnEmergencyStop(func() {
|
||||
|
@ -578,9 +578,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
|
||||
// TODO: migrate persistance to singleton
|
||||
s.orderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
|
||||
if err := s.Persistence.Sync(s); err != nil {
|
||||
log.WithError(err).Errorf("can not sync state to persistence")
|
||||
}
|
||||
bbgo.Sync(s)
|
||||
})
|
||||
|
||||
s.SmartStops.RunStopControllers(ctx, session, s.orderExecutor.TradeCollector())
|
||||
|
|
|
@ -231,6 +231,9 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
s.orderExecutor.BindEnvironment(s.Environment)
|
||||
s.orderExecutor.BindProfitStats(s.ProfitStats)
|
||||
s.orderExecutor.BindTradeStats(s.TradeStats)
|
||||
s.orderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
|
||||
bbgo.Sync(s)
|
||||
})
|
||||
s.orderExecutor.Bind()
|
||||
|
||||
store, _ := session.MarketDataStore(s.Symbol)
|
||||
|
|
|
@ -3,9 +3,10 @@ package supertrend
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/c9s/bbgo/pkg/util"
|
||||
"sync"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/util"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
|
@ -256,9 +257,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
|
||||
// Sync position to redis on trade
|
||||
s.orderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
|
||||
if err := s.Persistence.Sync(s); err != nil {
|
||||
log.WithError(err).Errorf("can not sync state to persistence")
|
||||
}
|
||||
bbgo.Sync(s)
|
||||
})
|
||||
|
||||
s.stopC = make(chan struct{})
|
||||
|
|
|
@ -352,7 +352,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
s.OnSuspend(func() {
|
||||
// Cancel all order
|
||||
_ = s.orderExecutor.GracefulCancel(ctx)
|
||||
_ = s.Persistence.Sync(s)
|
||||
bbgo.Sync(s)
|
||||
})
|
||||
|
||||
s.OnEmergencyStop(func() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user