mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix channel type and add map guard
This commit is contained in:
parent
30a5193923
commit
9d26adb245
|
@ -43,7 +43,7 @@ type ExchangeSession struct {
|
|||
Trades map[string][]types.Trade
|
||||
}
|
||||
|
||||
func (session *ExchangeSession) Subscribe(channel string, symbol string, options types.SubscribeOptions) *ExchangeSession {
|
||||
func (session *ExchangeSession) Subscribe(channel types.Channel, symbol string, options types.SubscribeOptions) *ExchangeSession {
|
||||
session.Symbols(symbol)
|
||||
|
||||
session.Subscriptions = append(session.Subscriptions, types.Subscription{
|
||||
|
@ -56,6 +56,14 @@ func (session *ExchangeSession) Subscribe(channel string, symbol string, options
|
|||
}
|
||||
|
||||
func (session *ExchangeSession) Symbols(symbols ...string) *ExchangeSession {
|
||||
if session.loadedSymbols == nil {
|
||||
session.loadedSymbols = make(map[string]struct{})
|
||||
}
|
||||
|
||||
if session.Markets == nil {
|
||||
session.Markets = make(map[string]types.Market)
|
||||
}
|
||||
|
||||
for _, symbol := range symbols {
|
||||
session.loadedSymbols[symbol] = struct{}{}
|
||||
|
||||
|
@ -117,6 +125,10 @@ func (trader *Trader) AddExchange(name string, exchange *binance.Exchange) (sess
|
|||
Exchange: exchange,
|
||||
}
|
||||
|
||||
if trader.ExchangeSessions == nil {
|
||||
trader.ExchangeSessions = make(map[string]*ExchangeSession)
|
||||
}
|
||||
|
||||
trader.ExchangeSessions[name] = session
|
||||
return session
|
||||
}
|
||||
|
@ -146,6 +158,9 @@ func (trader *Trader) Connect(ctx context.Context) (err error) {
|
|||
}
|
||||
|
||||
log.Infof("symbol %s: %d trades loaded", symbol, len(trades))
|
||||
if session.Trades == nil {
|
||||
session.Trades = make(map[string][]types.Trade)
|
||||
}
|
||||
session.Trades[symbol] = trades
|
||||
|
||||
stockManager := &StockManager{
|
||||
|
|
Loading…
Reference in New Issue
Block a user