// SubscribeExchangeUpdate subscribes for updates of the market.
// Updates will be sent to dataCh.
// To stop subscription, send to, or close 'stop'.
SubscribeExchangeUpdate subscribes for updates of the market.
Updates will be sent to dataCh.
To stop subscription, send to, or close 'stop'.
// SubscribeExchangeUpdate subscribes for updates of the market . // Updates will be sent to dataCh . // To stop subscription send to or close ' stop ' .
func (b *Bittrex) SubscribeExchangeUpdate(market string, dataCh chan ExchangeState, stop chan bool) error {
	transport := http.DefaultTransport
	if b.client.httpClient != nil && b.client.httpClient.Transport != nil {
		transport = b.client.httpClient.Transport
	}
	scraper, transportErr := scraper.NewTransport(transport)
	if transportErr != nil {
		return errors.Wrap(transportErr, "Error creating new scraper transport")
	}
	c := http.Client{Transport: scraper, Jar: scraper.CookieJar()}
	const timeout = 10 * time.Second
	client := signalr.NewWebsocketClient()
	client.OnClientMethod = func(hub string, method string, messages []json.RawMessage) {
		if hub != WS_HUB || method != "updateExchangeState" {
			return
		}
		parseStates(messages, dataCh, market)
	}
	err := doAsyncTimeout(func() error {
		return client.ConnectWithClient("https", WS_BASE, []string{WS_HUB}, &c)
	}, func(err error) {
		if err == nil {
			client.Close()
		}
	}, timeout)
	if err != nil {
		return errors.Wrap(err, "Error attempting ws async connect")
	}
	defer client.Close()
	var msg json.RawMessage
	err = doAsyncTimeout(func() error {
		var err error
		msg, err = subForMarket(client, market)
		return errors.Wrap(err, "Error subscribing to market events")
	}, nil, timeout)
	if err != nil {
		return errors.Wrap(err, "Performing market subscriptoin async task")
	}
	var st ExchangeState
	if err = json.Unmarshal(msg, &st); err != nil {
		return errors.Wrap(err, "Error unmarshalling response")
	}
	st.Initial = true
	st.MarketName = market
	sendStateAsync(dataCh, st)
	select {
	case <-stop:
	case <-client.DisconnectedChannel:
		stop <- false
	}
	return nil
}
func ( b * Bittrex ) SubscribeExchangeUpdate ( market string , dataCh chan ExchangeState , stop chan bool ) error { transport := http . DefaultTransport if b . client . httpClient != nil && b . client . httpClient . Transport != nil { transport = b . client . httpClient . Transport } scraper , transportErr := scraper . NewTransport ( transport ) if transportErr != nil { return errors . Wrap ( transportErr , " " ) } c := http . Client { Transport : scraper , Jar : scraper . CookieJar ( ) } const timeout = 10 * time . Second client := signalr . NewWebsocketClient ( ) client . OnClientMethod = func ( hub string , method string , messages [ ] json . RawMessage ) { if hub != WS_HUB || method != " " { return } parseStates ( messages , dataCh , market ) } err := doAsyncTimeout ( func ( ) error { return client . ConnectWithClient ( " " , WS_BASE , [ ] string { WS_HUB } , & c ) } , func ( err error ) { if err == nil { client . Close ( ) } } , timeout ) if err != nil { return errors . Wrap ( err , " " ) } defer client . Close ( ) var msg json . RawMessage err = doAsyncTimeout ( func ( ) error { var err error msg , err = subForMarket ( client , market ) return errors . Wrap ( err , " " ) } , nil , timeout ) if err != nil { return errors . Wrap ( err , " " ) } var st ExchangeState if err = json . Unmarshal ( msg , & st ) ; err != nil { return errors . Wrap ( err , " " ) } st . Initial = true st . MarketName = market sendStateAsync ( dataCh , st ) select { case <- stop : case <- client . DisconnectedChannel : stop <- false } return nil }
SubscribeExchangeUpdate subscribes for updates of the market.
SubscribeExchangeUpdate subscribes for updates of the market .