func (s *Stream) Subscribe(channel string, handler func(msg interface{})) (err error) {
	switch {
	case channel == TradeUpdates:
		fallthrough
	case channel == AccountUpdates:
		fallthrough
	case strings.HasPrefix(channel, "Q."):
		fallthrough
	case strings.HasPrefix(channel, "T."):
		fallthrough
	case strings.HasPrefix(channel, "AM."):
	default:
		err = fmt.Errorf("invalid stream (%s)", channel)
		return
	}
	if s.conn == nil {
		s.conn, err = s.openSocket()
		if err != nil {
			return
		}
	}

	if err = s.auth(); err != nil {
		return
	}
	s.Do(func() {
		go s.start()
	})

	s.handlers.Store(channel, handler)

	if err = s.sub(channel); err != nil {
		s.handlers.Delete(channel)
		return
	}
	return
}
// Subscribe to the specified Alpaca stream channel.
Subscribe to the specified Alpaca stream channel.
// Subscribe to the specified Alpaca stream channel .
func (s *Stream) Subscribe(channel string, handler func(msg interface{})) (err error) {
	switch {
	case channel == TradeUpdates:
		fallthrough
	case channel == AccountUpdates:
		fallthrough
	case strings.HasPrefix(channel, "Q."):
		fallthrough
	case strings.HasPrefix(channel, "T."):
		fallthrough
	case strings.HasPrefix(channel, "AM."):
	default:
		err = fmt.Errorf("invalid stream (%s)", channel)
		return
	}
	if s.conn == nil {
		s.conn, err = s.openSocket()
		if err != nil {
			return
		}
	}
	if err = s.auth(); err != nil {
		return
	}
	s.Do(func() {
		go s.start()
	})
	s.handlers.Store(channel, handler)
	if err = s.sub(channel); err != nil {
		s.handlers.Delete(channel)
		return
	}
	return
}
func ( s * Stream ) Subscribe ( channel string , handler func ( msg interface { } ) ) ( err error ) { switch { case channel == TradeUpdates : fallthrough case channel == AccountUpdates : fallthrough case strings . HasPrefix ( channel , " " ) : fallthrough case strings . HasPrefix ( channel , " " ) : fallthrough case strings . HasPrefix ( channel , " " ) : default : err = fmt . Errorf ( " " , channel ) return } if s . conn == nil { s . conn , err = s . openSocket ( ) if err != nil { return } } if err = s . auth ( ) ; err != nil { return } s . Do ( func ( ) { go s . start ( ) } ) s . handlers . Store ( channel , handler ) if err = s . sub ( channel ) ; err != nil { s . handlers . Delete ( channel ) return } return }
Subscribe to the specified Alpaca stream channel.
Subscribe to the specified Alpaca stream channel .