diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index 4f7ddd4d2..3a0a9bdd4 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -504,14 +504,16 @@ func (environ *Environment) BindSync(config *SyncConfig) { } for _, session := range environ.sessions { + // avoid using the iterator variable. + s2 := session // if trade sync is on, we will write all received trades if config.UserDataStream.Trades { - tradeWriter := tradeWriterCreator(session) + tradeWriter := tradeWriterCreator(s2) session.UserDataStream.OnTradeUpdate(tradeWriter) } if config.UserDataStream.FilledOrders { - orderWriter := orderWriterCreator(session) + orderWriter := orderWriterCreator(s2) session.UserDataStream.OnOrderUpdate(orderWriter) } }