From f3691489dd6a2e53b6aaca7c292384b90a1954a2 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 5 May 2022 17:56:41 +0800 Subject: [PATCH] add state key as the prefix --- pkg/bbgo/persistence.go | 4 ++-- pkg/bbgo/persistence_test.go | 4 ++-- pkg/service/memory.go | 2 -- pkg/service/memory_test.go | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/bbgo/persistence.go b/pkg/bbgo/persistence.go index 5915783e5..c151df185 100644 --- a/pkg/bbgo/persistence.go +++ b/pkg/bbgo/persistence.go @@ -134,7 +134,7 @@ func loadPersistenceFields(obj interface{}, id string, persistence service.Persi return iterateFieldsByTag(obj, "persistence", func(tag string, field reflect.StructField, value reflect.Value) error { newValueInf := newTypeValueInterface(value.Type()) // inf := value.Interface() - store := persistence.NewStore(id, tag) + store := persistence.NewStore("state", id, tag) if err := store.Load(&newValueInf); err != nil { if err == service.ErrPersistenceNotExists { return nil @@ -159,7 +159,7 @@ func storePersistenceFields(obj interface{}, id string, persistence service.Pers return iterateFieldsByTag(obj, "persistence", func(tag string, ft reflect.StructField, fv reflect.Value) error { inf := fv.Interface() - store := persistence.NewStore(id, tag) + store := persistence.NewStore("state", id, tag) return store.Save(inf) }) } diff --git a/pkg/bbgo/persistence_test.go b/pkg/bbgo/persistence_test.go index a75e9da9f..97916a172 100644 --- a/pkg/bbgo/persistence_test.go +++ b/pkg/bbgo/persistence_test.go @@ -70,13 +70,13 @@ func Test_storePersistenceFields(t *testing.T) { assert.NoError(t, err) var i int64 - store := ps.NewStore("test-struct", "integer") + store := ps.NewStore("state", "test-struct", "integer") err = store.Load(&i) assert.NoError(t, err) assert.Equal(t, int64(1), i) var p *types.Position - store = ps.NewStore("test-struct", "position") + store = ps.NewStore("state", "test-struct", "position") err = store.Load(&p) assert.NoError(t, err) assert.Equal(t, fixedpoint.NewFromFloat(10.0), p.Base) diff --git a/pkg/service/memory.go b/pkg/service/memory.go index ab1a97599..92ee9f6cd 100644 --- a/pkg/service/memory.go +++ b/pkg/service/memory.go @@ -1,7 +1,6 @@ package service import ( - "fmt" "reflect" "strings" ) @@ -38,7 +37,6 @@ func (store *MemoryStore) Load(val interface{}) error { v := reflect.ValueOf(val) if data, ok := store.memory.Slots[store.Key]; ok { dataRV := reflect.ValueOf(data) - fmt.Printf("load %s = %v\n", store.Key, dataRV) v.Elem().Set(dataRV) } else { return ErrPersistenceNotExists diff --git a/pkg/service/memory_test.go b/pkg/service/memory_test.go index 3accd9608..e6106d78b 100644 --- a/pkg/service/memory_test.go +++ b/pkg/service/memory_test.go @@ -21,7 +21,7 @@ func TestMemoryService(t *testing.T) { store := service.NewStore("test") i := 3 - err := store.Save(&i) + err := store.Save(i) assert.NoError(t, err)