dparlevliet / node.bittrex.api

Node Bittrex API is an asynchronous node.js library for the Bittrex API, the data can be received either via GET request or Stream.
MIT License
253 stars 100 forks source link

Websockets unusable: 'Error 503 Negotiate Unknown' when using websockets.subscribe #154

Open Marvosg opened 6 years ago

Marvosg commented 6 years ago

Using the latest version (1.0.0), when using websockets to subscribe to the orderbook, the Bittrex client prints Error 503. The code which causes this issue for me:

bittrex.websockets.client(function () {
    bittrex.websockets.subscribe(['BTC-ADA'],
        function (data) {
            if (data.M === 'updateExchangeState') {
                data.A.forEach((data_for) => {
                    // Do stuff
                });
            }
        });

The console prints:

Error Message:  Negotiate Unknown
Exception:  undefined
Error Data:  503

The expected result is a working subscription to the orderbook updates. Instead the connection will retry several times, failing every time with Error 503, with no successful result.

The endpoint is at https://bittrex.com/api/v1.1/public/getorderbook?market=BTC-ADA&type=both and I can access it from the same machine with Firefox without a problem. As I understand this issue has to do with Bittrex enabling Cloudflare protection on the public api endpoints, but also that this issue is supposed to be fixed in this repository as per Issue #1 - Websockets and Cloudflare.

It seems to me that the issue is not solved. Or is there an accepted workaround that is not documented in the README? Error 503 has prevented me from using Bittrex websockets for the last two hours, during the main business hours of the exchange, so this issue is critical bug for my use case.

mountainmoon commented 6 years ago

I also met this problem recently. But sometimes it works normally.

amirdauti commented 6 years ago

Im having the same issue as well, anyone have a solution?

aloysius-pgast commented 6 years ago

On my side I have some cases where connection it fails for =~ 30 minutes (Bittrex answering with error 503 Service Temporarily Unavailable) but in the end I always manage to reconnect

amirdauti commented 6 years ago

are you manually reconnecting or is the socket connecting on its own? mine runs as a service so i have no way of verifying that it will eventually connect.

aloysius-pgast commented 6 years ago

Automatic reconnection

aloysius-pgast commented 6 years ago

Take a look at https://github.com/dparlevliet/node.bittrex.api/issues/153#issuecomment-373899585. Adding extra headers to CloudScraper helped improve connection delay on my side

Amindv1 commented 6 years ago

I'm getting the same error:

Error Message: Negotiate Unknown Exception: undefined Error Data: 503

It attempts to force a reconnect a couple times, but it ends up connecting multiple times. How can I avoid getting this error? I checked and the cookie and user agent are both included in the header.

Also, it ends up throwing me really old Nounces after being connected for a couple days, so I'm forced to reconnect. How can I avoid this?

mightymouse2045 commented 6 years ago

wait for beta api to be incorporated

Jonathanx5 commented 6 years ago

You talk about a beta api, but do we have a stable approach concerning this web socket issue ? How can we build a up to date and synchronised order book with web socket ? For now, I get data after some seconds, and then, it seems I have multiple connections (I receive the same data/nonce many times) If you have any idea, I would be very interrested . PS: I add a screenshot of what I receive, I think I receive data from many websocket in a not synchronized way (I receive nounces that do not follow each other, 434035, 435271 then 434036)

capture d ecran 2018-04-02 a 12 33 36

My code :

capture d ecran 2018-04-02 a 12 41 43
aloysius-pgast commented 6 years ago

@Jonathanx5 : a few months ago I also had the same problem with signalr-client not closing previous connections when a network error / disconnection occurred. The result was my client receiving multiple updates like you described. I ended up working on an alternate implementation for the WS part of Bittrex API (while keeping this lib for REST API). It's tailored for my own needs so it might not suit yours though

gRittyKitty commented 6 years ago

I had this problem. After I installed all of the dependencies, it worked for me. Doubting that is the problem for anyone here, but figured it was worth mentioning.

geekguy commented 6 years ago

Facing this problem in 0.8.3.

aloysius-pgast commented 6 years ago

You should change the headers passed to Cloud Scraper. Check https://github.com/dparlevliet/node.bittrex.api/issues/153#issuecomment-373899585. If you want to try master, a new option _cloudscraperheaders has been added just for that.