bbgo: add persistence Sync api

This commit is contained in:
c9s 2022-05-05 18:02:08 +08:00
parent f3691489dd
commit 82c7c024ce
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 13 additions and 2 deletions

View File

@ -76,6 +76,16 @@ func (p *Persistence) Save(val interface{}, subIDs ...string) error {
return store.Save(val) return store.Save(val)
} }
func (p *Persistence) Sync(obj interface{}) error {
id := callID(obj)
if len(id) == 0 {
return nil
}
ps := p.Facade.Get()
return storePersistenceFields(obj, id, ps)
}
type StructFieldIterator func(tag string, ft reflect.StructField, fv reflect.Value) error type StructFieldIterator func(tag string, ft reflect.StructField, fv reflect.Value) error
func iterateFieldsByTag(obj interface{}, tagName string, cb StructFieldIterator) error { func iterateFieldsByTag(obj interface{}, tagName string, cb StructFieldIterator) error {

View File

@ -266,11 +266,12 @@ func (s *Strategy) Suspend(ctx context.Context) error {
log.WithError(err).Errorf("graceful cancel order error") log.WithError(err).Errorf("graceful cancel order error")
s.Notify("graceful cancel order error") s.Notify("graceful cancel order error")
} else { } else {
s.Notify("All orders cancelled.") s.Notify("All orders are cancelled.")
} }
s.tradeCollector.Process() s.tradeCollector.Process()
return nil
return s.Persistence.Sync(s)
} }
func (s *Strategy) Resume(ctx context.Context) error { func (s *Strategy) Resume(ctx context.Context) error {