diff --git a/pkg/strategy/grid/strategy.go b/pkg/strategy/grid/strategy.go index d19c5c7d4..a16efe08a 100644 --- a/pkg/strategy/grid/strategy.go +++ b/pkg/strategy/grid/strategy.go @@ -3,13 +3,13 @@ package grid import ( "context" "fmt" - "hash/fnv" "sync" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/c9s/bbgo/pkg/bbgo" + "github.com/c9s/bbgo/pkg/exchange/max" "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/service" "github.com/c9s/bbgo/pkg/types" @@ -99,7 +99,7 @@ type Strategy struct { activeOrders *bbgo.LocalActiveOrderBook // groupID is the group ID used for the strategy instance for canceling orders - groupID int64 + groupID uint32 } func (s *Strategy) ID() string { @@ -500,7 +500,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se } instanceID := fmt.Sprintf("grid-%s-%d-%d-%d", s.Symbol, s.GridNum, s.UpperPrice, s.LowerPrice) - s.groupID = generateGroupID(instanceID) + s.groupID = max.GenerateGroupID(instanceID) log.Infof("using group id %d from fnv(%s)", s.groupID, instanceID) var stateLoaded = false @@ -537,7 +537,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se s.Notify("current position %+v", s.state.Position) - s.orderStore = bbgo.NewOrderStore(s.Symbol) s.orderStore.BindStream(session.Stream) @@ -590,9 +589,3 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se return nil } - -func generateGroupID(s string) int64 { - h := fnv.New32a() - h.Write([]byte(s)) - return int64(h.Sum32()) -} diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index 2b76122e2..799bc2e08 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -3,7 +3,6 @@ package xmaker import ( "context" "fmt" - "hash/fnv" "math" "sync" "time" @@ -11,6 +10,7 @@ import ( "github.com/sirupsen/logrus" "github.com/c9s/bbgo/pkg/bbgo" + "github.com/c9s/bbgo/pkg/exchange/max" "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/service" "github.com/c9s/bbgo/pkg/types" @@ -74,7 +74,7 @@ type Strategy struct { orderStore *bbgo.OrderStore lastPrice float64 - groupID int64 + groupID uint32 stopC chan struct{} } @@ -398,7 +398,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se // restore state instanceID := fmt.Sprintf("%s-%s", ID, s.Symbol) - s.groupID = generateGroupID(instanceID) + s.groupID = max.GenerateGroupID(instanceID) log.Infof("using group id %d from fnv(%s)", s.groupID, instanceID) var state State @@ -482,8 +482,3 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se return nil } -func generateGroupID(s string) int64 { - h := fnv.New32a() - h.Write([]byte(s)) - return int64(h.Sum32()) -} diff --git a/pkg/types/order.go b/pkg/types/order.go index 927922494..9961eed10 100644 --- a/pkg/types/order.go +++ b/pkg/types/order.go @@ -108,7 +108,7 @@ type SubmitOrder struct { TimeInForce string `json:"timeInForce,omitempty" db:"time_in_force"` // GTC, IOC, FOK - GroupID int64 `json:"groupID,omitempty"` + GroupID uint32 `json:"groupID,omitempty"` MarginSideEffect MarginOrderSideEffectType `json:"marginSideEffect,omitempty"` // AUTO_REPAY = repay, MARGIN_BUY = borrow, defaults to NO_SIDE_EFFECT }