mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-13 02:23:51 +00:00
move out groupID to the maxapi package
This commit is contained in:
parent
706b38efa3
commit
2b27815929
|
@ -3,13 +3,13 @@ package grid
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/bbgo"
|
"github.com/c9s/bbgo/pkg/bbgo"
|
||||||
|
"github.com/c9s/bbgo/pkg/exchange/max"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
"github.com/c9s/bbgo/pkg/service"
|
"github.com/c9s/bbgo/pkg/service"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
@ -99,7 +99,7 @@ type Strategy struct {
|
||||||
activeOrders *bbgo.LocalActiveOrderBook
|
activeOrders *bbgo.LocalActiveOrderBook
|
||||||
|
|
||||||
// groupID is the group ID used for the strategy instance for canceling orders
|
// groupID is the group ID used for the strategy instance for canceling orders
|
||||||
groupID int64
|
groupID uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) ID() string {
|
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)
|
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)
|
log.Infof("using group id %d from fnv(%s)", s.groupID, instanceID)
|
||||||
|
|
||||||
var stateLoaded = false
|
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.Notify("current position %+v", s.state.Position)
|
||||||
|
|
||||||
|
|
||||||
s.orderStore = bbgo.NewOrderStore(s.Symbol)
|
s.orderStore = bbgo.NewOrderStore(s.Symbol)
|
||||||
s.orderStore.BindStream(session.Stream)
|
s.orderStore.BindStream(session.Stream)
|
||||||
|
|
||||||
|
@ -590,9 +589,3 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateGroupID(s string) int64 {
|
|
||||||
h := fnv.New32a()
|
|
||||||
h.Write([]byte(s))
|
|
||||||
return int64(h.Sum32())
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package xmaker
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
|
||||||
"math"
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -11,6 +10,7 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/bbgo"
|
"github.com/c9s/bbgo/pkg/bbgo"
|
||||||
|
"github.com/c9s/bbgo/pkg/exchange/max"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
"github.com/c9s/bbgo/pkg/service"
|
"github.com/c9s/bbgo/pkg/service"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
@ -74,7 +74,7 @@ type Strategy struct {
|
||||||
orderStore *bbgo.OrderStore
|
orderStore *bbgo.OrderStore
|
||||||
|
|
||||||
lastPrice float64
|
lastPrice float64
|
||||||
groupID int64
|
groupID uint32
|
||||||
|
|
||||||
stopC chan struct{}
|
stopC chan struct{}
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
||||||
|
|
||||||
// restore state
|
// restore state
|
||||||
instanceID := fmt.Sprintf("%s-%s", ID, s.Symbol)
|
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)
|
log.Infof("using group id %d from fnv(%s)", s.groupID, instanceID)
|
||||||
|
|
||||||
var state State
|
var state State
|
||||||
|
@ -482,8 +482,3 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateGroupID(s string) int64 {
|
|
||||||
h := fnv.New32a()
|
|
||||||
h.Write([]byte(s))
|
|
||||||
return int64(h.Sum32())
|
|
||||||
}
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ type SubmitOrder struct {
|
||||||
|
|
||||||
TimeInForce string `json:"timeInForce,omitempty" db:"time_in_force"` // GTC, IOC, FOK
|
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
|
MarginSideEffect MarginOrderSideEffectType `json:"marginSideEffect,omitempty"` // AUTO_REPAY = repay, MARGIN_BUY = borrow, defaults to NO_SIDE_EFFECT
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user