Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bittrex streaming updates #23

Open
simongui opened this issue Jul 5, 2017 · 24 comments
Open

Bittrex streaming updates #23

simongui opened this issue Jul 5, 2017 · 24 comments

Comments

@simongui
Copy link

simongui commented Jul 5, 2017

Does this support the Bittrex socket API for streaming updates? I would like to hook into the live streaming updates :)

@saniales
Copy link

In brief. NO.
I am trying to reverse engineering the 2.0 API to allow streaming updates.
https://github.com/AlessandroSanino1994/golang-bittrex-api
I am building a document, if you (and others from this repository too) can help me

@themotu
Copy link

themotu commented Aug 8, 2017

Would be amazing if we could stream pricing in and make faster trading decisions.

@TimLaMason
Copy link

This is not in Go, but there is a nice paper in regards to the websocket API. I believe it came from Bittrex, not sure where though:

https://github.com/n0mad01/node.bittrex.api/files/1104308/WebSocketAPI_MarketTracking.docx

@avdva
Copy link
Contributor

avdva commented Sep 7, 2017

Hi, here I implemented streaming updates and it's working. Two moments:

  1. I had to change the type of Orderb's fields to decimal.Decimal, as with floats it's not very reliable to update an order book, searching an order by price.
  2. It may seem excessive to use doAsyncTimeout, but its really what is needed to build a reliable function, that does not hang. github.com/thebotguys/signalr does not support timeouts, and a few times CallHub got stuck somewhere inside it.

If you like it, I'll do a PR.

@dezza
Copy link

dezza commented Sep 22, 2017

Yeah that PR would be kindly appreciated :)

@simongui
Copy link
Author

Yeah, this would be really nice. Can we get this integrated?

@dezza
Copy link

dezza commented Sep 22, 2017

@KLIM8D has some updates for the websocket as well he can explain. We used it together in a project.

@brunocassol
Copy link

Is there a way to listen to changes in all markets? Would be nice to have it track all markets if none was specified.

I'm not sure what would be the best way to implement this. Perhaps track all markets if specified market is an empty string ""?

@kilpatty
Copy link

Also curious if there is a way to implement listening to all markets.

@avdva
Copy link
Contributor

avdva commented Oct 16, 2017

It looks like it's possible to listen to all markets. I'll review @KLIM8D 's PR, and after it try to implement that listening.

@avdva
Copy link
Contributor

avdva commented Oct 17, 2017

Hi, here I added SubscribeMarkets.
So, to sub for several markets, call GetMarketSummary(), get the markets you need, and pass them to SubscribeMarkets.
Bug reports or any feedback is appreciated.

@kilpatty
Copy link

@avdva Amazing. I will be trying this out today, and let you know how it goes. Just in time for what I need - thanks again!

@mightymouse2045
Copy link

Can we get some examples on streaming please? I can't seem to get this working...

@avdva
Copy link
Contributor

avdva commented Dec 29, 2017

Yes, the sad story is that about 10 days ago they put ws behind Cloudflare, so until they give some open ws endpoint, this won't work.

@vlddlv
Copy link

vlddlv commented Jan 11, 2018

@avdva I created a super quick fork https://github.com/vlddlv/signalr and I tried to solve the bypass using https://github.com/cardigann/go-cloudflare-scraper

While it does work and I'm able to retrieve the signalr connection token, I wasn't able to handshake with the web socket due to unknown reason. Any ideas?

The particular status code for bad handshake was: 503 Service Temporarily Unavailable but interestingly enough, I was able to connect to the web socket using the same URL from a chrome extension.

@ybbkrishna
Copy link

@vlddlv I was able to make it working by adding the headers returned from cloudflare scrapper to ws

@mightymouse2045
Copy link

@ybbkrishna can you please provide an example of how you got this working?

@KeKs0r
Copy link

KeKs0r commented Jan 29, 2018

@ybbkrishna Care to share your solution? Can this fix be added to this library?

I think 2 things need to be added to the headers: the user-agent and cookie. I think a similar Node module ran into the same issue: n0mad01/node.bittrex.api#67

@OpinionatedGeek
Copy link

OpinionatedGeek commented Feb 26, 2018

Hi folks,

I'd really like this to be working and available, so I took a deeper look at it all.

The good news: I have it working.

The bad news: it requires changes to multiple dependencies - signalr and go-cloudflare-scraper. (go-cloudflare-scraper is a new dependency with this change but it also requires a small edit.)

I've put all the changes to all 3 repos up on my Github.

The changes to go-cloudflare-scraper expose the CookieJar so that it can be re-used by the websocket:
https://github.com/OpinionatedGeek/go-cloudflare-scraper/commit/c65485b29c3ae21873bb6246a07adc02e491884f

(There's already a similar pull-request for this.)

The changes to signalr allow it to take a *http.Client which provides the scraper transport and the cookie jar:
https://github.com/OpinionatedGeek/signalr/commit/e19c5a5788a7c124c5afa8f16f4131ae268bd6d9

The changes to go-bittrex create the scraper transport and pass that to signalr:
https://github.com/OpinionatedGeek/go-bittrex/commit/3cdf07f8514782aa1c9af429ecdcd9b4e61105d4

I tried to make the changes as minimal as I could (with the possible exception of the re-use of the user agent in the signalr negotiate() function - it works without that change but I figured it should still be there).

Here's the test program I used:

package main

import (
	"fmt"

	"github.com/OpinionatedGeek/go-bittrex"
)

func main() {
	bt := bittrex.New("", "")
	ch := make(chan bittrex.ExchangeState, 16)
	go func() {
		for st := range ch {
			fmt.Println("Message:", st)
		}
	}()
	bt.SubscribeExchangeUpdate("USDT-BTC", ch, nil)
}

Unfortunately I couldn't see a sensible way of isolating the changes to just go-bittrex. Maybe one of you can see a better way? (The lack of activity on both those dependencies makes me worry that pull requests would be ignored.)

@9cat
Copy link

9cat commented Mar 19, 2018

halt on the here as following. what's wrong with it?

USDT-BTC
2018/03/19 07:27:12 Solving challenge for socket.bittrex.com
2018/03/19 07:27:16 Requesting https://socket.bittrex.com/cdn-cgi/l/chk_jschl?jschl_answer=218&jschl_vc=4d3eca6aa8bd15497eecd863335ff469&pass=1521458836.533-OTK4IueTkC

@OpinionatedGeek
Copy link

@9cat I'm not sure. When I run it now it seems to go from the Cloudflare page to a Cloudflare CAPTCHA page, which the go-cloudflare package doesn't expect and so it quits.

I should have put in some logging of the error, if there is one, so maybe try this instead:

package main

import (
	"fmt"

	"github.com/OpinionatedGeek/go-bittrex"
)

func main() {
	bt := bittrex.New("", "")
	ch := make(chan bittrex.ExchangeState, 16)
	go func() {
		for st := range ch {
			fmt.Println("Message:", st)
		}
	}()
	err := bt.SubscribeExchangeUpdate("USDT-BTC", ch, nil)
	if err != nil {
		fmt.Println("Error:", err)
	}
}

On my setup it sometimes prints out: Error: invalid character '<' looking for beginning of value It doesn't do so consistently though - sometimes it works fine, sometimes it doesn't.

@9cat
Copy link

9cat commented Apr 5, 2018

@OpinionatedGeek Thanks.
I encouter the simliar problem. but it works.
However, since yesterday, I encouter the problem like:

doAsync Timeout ... %!(EXTRA *url.Error=Get https://socket.bittrex.com/signalr/negotiate: TypeError: Cannot access member 'value' of undefined) 2018/04/05 14:51:15 SubscribeExchangeUpdateing ...

anyone encounter this issues. any ideas?

@OpinionatedGeek
Copy link

@9cat Yes, it started happening to me yesterday afternoon/evening.

At that point I gave up and started integrating Binance's API into my code. Sorry.

Geoff

@zoh
Copy link

zoh commented Apr 16, 2018

I fix it in https://github.com/zoh/go-cloudflare-scraper
and you can use my fork github.com/zoh/go-bittrex. It is work.

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests