xalign: allocate and bind order store

This commit is contained in:
c9s 2023-06-13 23:23:41 +08:00
parent 45aaad1629
commit 1fd52f78a9
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -37,6 +37,8 @@ type Strategy struct {
sessions map[string]*bbgo.ExchangeSession sessions map[string]*bbgo.ExchangeSession
orderBooks map[string]*bbgo.ActiveOrderBook orderBooks map[string]*bbgo.ActiveOrderBook
orderStore *bbgo.OrderStore
} }
func (s *Strategy) ID() string { func (s *Strategy) ID() string {
@ -222,12 +224,16 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
s.sessions = make(map[string]*bbgo.ExchangeSession) s.sessions = make(map[string]*bbgo.ExchangeSession)
s.orderBooks = make(map[string]*bbgo.ActiveOrderBook) s.orderBooks = make(map[string]*bbgo.ActiveOrderBook)
s.orderStore = bbgo.NewOrderStore("")
for _, sessionName := range s.PreferredSessions { for _, sessionName := range s.PreferredSessions {
session, ok := sessions[sessionName] session, ok := sessions[sessionName]
if !ok { if !ok {
return fmt.Errorf("incorrect preferred session name: %s is not defined", sessionName) return fmt.Errorf("incorrect preferred session name: %s is not defined", sessionName)
} }
s.orderStore.BindStream(session.UserDataStream)
orderBook := bbgo.NewActiveOrderBook("") orderBook := bbgo.NewActiveOrderBook("")
orderBook.BindStream(session.UserDataStream) orderBook.BindStream(session.UserDataStream)