Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Errorr Message: Negotiate Unknown, 503 #67

Closed
LRonHubs opened this issue Sep 8, 2017 · 56 comments
Closed

Errorr Message: Negotiate Unknown, 503 #67

LRonHubs opened this issue Sep 8, 2017 · 56 comments

Comments

@LRonHubs
Copy link

LRonHubs commented Sep 8, 2017

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

I get this error when trying to connect to WebSockets. Is this something on bittrex's end? If so is it a permanent thing?

@ale316
Copy link

ale316 commented Sep 8, 2017

Getting this too. They said they were attacked (https://twitter.com/ramikawach/status/906184766969356289), which prompted them to CloudFlare all their endpoints, including the signalr ones.

@zduerr
Copy link

zduerr commented Sep 8, 2017

is there a workaround for this?

@LRonHubs
Copy link
Author

LRonHubs commented Sep 8, 2017

Spam the PUSH api i guess

@masalinas
Copy link

masalinas commented Sep 8, 2017

@LRonHubs what do you mean with Spam the PUSH api??

@TimLaMason
Copy link

TimLaMason commented Sep 8, 2017 via email

@masalinas
Copy link

masalinas commented Sep 8, 2017

@TimLaMason I was using the API more than one week and I never received any error, or banned ... meaby is it a temporal problem?? I created other key and the error is the same

@junkomatic
Copy link

Then endpoint is giving '503 - Service Temporarily Unavailable'. I presume they will reactivate it later, or else enable functionality for account auth headers. I have an alert set for if it reactivates normally. Keep us posted if anyone here's anything.

@TimLaMason
Copy link

TimLaMason commented Sep 8, 2017 via email

@masalinas
Copy link

How can I receive the complete error from bittrex?

@junkomatic
Copy link

SignalR websocket hubs we're primarily designed for .net. if you code a c# hub client it outputs the error message, and you can also enable tracing to see the raw feed.

@masalinas
Copy link

My client I have this code:

// listen to Bittrex WebSocket
    var websocketsclient = bittrex.websockets.listen( function( data ) {
        if (data.M === 'updateSummaryState') {
            data.A.forEach(function(data_for) {
                app.io.emit('bittrex-event', data_for.Deltas);
            });
        }
    });

    websocketsclient.serviceHandlers.connectFailed = function(error) {
        console.log("Websocket connectFailed: ", error);
    };

    websocketsclient.serviceHandlers.onerror = function(error) {
        console.log("Websocket error: ", error);
    };

    websocketsclient.serviceHandlers.connectionLost = function(error) {
        console.log("Connection Lost: ", error);
    };

But not receive any erro detail only the:

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

But where is the callback that receive this error??? how can I get this error in my code???

@masalinas
Copy link

masalinas commented Sep 8, 2017

@junkomatic how do you code for receive the error: '503 - Service Temporarily Unavailable'?
because i only reveive the error: Error Data: 503

@junkomatic
Copy link

junkomatic commented Sep 8, 2017

503 is an http error response code that literally means "Service Temporarily Unavailable". There's not much more data than that.

@LRonHubs
Copy link
Author

LRonHubs commented Sep 8, 2017 via email

@ale316
Copy link

ale316 commented Sep 8, 2017

@masalinas You can go into the signalr-client node module and print the request out.

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

Is just a catch all error.

What Bittrex is returning is the CloudFlare HTML page saying that they're verifying your connection. I believe the only thing we can do is wait.

@n0mad01
Copy link
Owner

n0mad01 commented Sep 8, 2017

i've created a pull request for the signalR lib to at least fix the pass of binding errors into the onerror serviceHandler.
mwwhited-archives/signalr-client-nodejs#20

the 503 issue i haven't looked more closely yet.

@strelov1
Copy link

strelov1 commented Sep 8, 2017

Hmm, why using this service https://www.websocket.org/echo.html WS bittrex is available?

@AGoetzDev
Copy link

As already mentioned, the websocket endpoint is currently protected by cloudflare's anti bot system. It is possible to bypass it, by executing a request to the negotiate endpoint (or any page on bittrex really) just as a regular browser would and letting cloudflare do its thing (how cloudflare's bot protection works is explained here: link) then grab the identity cookie and the clearance cookie and send those as the Cookie header together with the User-Agent header (which must be the same as in the request used to obtain the cookies) with the negotiate and websocket connect request. As an example, for python cloudflare-scrape does just that.

@ThePrimeagen
Copy link

@AlxGDev how is that a solution? My bot has a lot of responsibility and this really worries me that I could just be taken offline for several hours...

@usmankhanic
Copy link

Does anyone know if bittrex have commented on this?

@ninesalt
Copy link

ninesalt commented Sep 9, 2017

Need a fix for this asap

@TimLaMason
Copy link

TimLaMason commented Sep 9, 2017 via email

@metachris
Copy link

@AlxGDev thanks for your suggestion! It also worked for me.

For anyone interested: the goal is to add your cookie and user-agent headers to the signalR websockets connection here: https://github.com/mwwhited/signalr-client-nodejs/blob/master/WhitedUS.SignalR/WhitedUS.signalR/signalR.js#L295

I copied the bittrex and signalr node modules intop my project and modified them a little to achieve this. But you could also edit the signalr-client file directly (not recommended, but the quickest way).

@bigdataboss
Copy link

bigdataboss commented Sep 9, 2017

Just replace connectws() function. For the future we could add headers opt. To get cookie without browser you can use nightmare.js

var connectws = function(callback) {
    wsclient = new signalR.client(
      opts.websockets_baseurl,
      opts.websockets_hubs, 
      undefined, true
    );
    wsclient.headers['User-Agent'] = 'YOUR BROWSER UA';
    wsclient.headers['cookie'] = 'cf_clearance=YOUR CF_CLEARENCE FROM BROWSER';
    wsclient.start(); 
    wsclient.serviceHandlers = {
      bound: function() {
        ((opts.verbose) ? console.log('Websocket bound') : '');
      },
      connectFailed: function(error) {
        ((opts.verbose) ? console.log('Websocket connectFailed: ', error) : '');
      },
      disconnected: function() {
        ((opts.verbose) ? console.log('Websocket disconnected') : '');
      },
      onerror: function(error) {
        ((opts.verbose) ? console.log('Websocket onerror: ', error) : '');
      },
      bindingError: function(error) {
        ((opts.verbose) ? console.log('Websocket bindingError: ', error) : '');
      },
      connectionLost: function(error) {
        ((opts.verbose) ? console.log('Connection Lost: ', error) : '');
      },
      reconnecting: function(retry) {
        ((opts.verbose) ? console.log('Websocket Retrying: ', retry) : '');
        // change to true to stop retrying
        return false;
      }
    };
    return wsclient;
  };

@0b01
Copy link

0b01 commented Sep 9, 2017

@CyberWlf I did exactly that. But it's still not working for me...

@bigdataboss
Copy link

@RickyHan double check everything. If Bittrex works in your browser and you copied user-agent and the cookie correctly it should work.

@ale316
Copy link

ale316 commented Sep 9, 2017

@RickyHan Hey, I just got it to work on my server. Make sure that the IP you used to get the cf_clearance is the same as the one making the subsequent requests.

For the server I used this python library (https://libraries.io/github/Limero/cloudflare-scrape), to grab User-Agent and cf_clearance cookie, then did what @CyberWlf suggested (thanks!) and it worked.

@0b01
Copy link

0b01 commented Sep 9, 2017

@CyberWlf @ale316 Thanks, I'll try that on my IPv4 server. My home address uses IPv6.

Update: It's working! Thank you! It's indeed because of IPv6.

@0xecute
Copy link

0xecute commented Sep 9, 2017

Did you make it work with python?
I got the correct cookie and the correct user agent header, but I got the following error from signalr-client:
error: There was an error invoking Hub method 'corehub.SubscribeToExchangeDeltas'.

Thanks for your help

@ale316
Copy link

ale316 commented Sep 9, 2017

@0xecute If it throws that error, it is connected, so it seems to not be an issue with Cloudflare's protection. I guess make sure you're invoking the call correctly.

@thanhlm86
Copy link

thanhlm86 commented Sep 9, 2017

@armandohg help me, i run node scraper.js

{ errorType: 0, error: { Error: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 3128 3128:8 0 at ClientRequest.onError (C:\Users\ThinkPad\Desktop\node-bittrex-api\node_modules\tunne l-agent\index.js:177:17) at Object.onceWrapper (events.js:316:30) at emitOne (events.js:115:13) at ClientRequest.emit (events.js:210:7) at Socket.socketErrorListener (_http_client.js:401:9) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) code: 'ECONNRESET' } }

@mjmau
Copy link

mjmau commented Sep 9, 2017

Thanks to @CyberWlf and @armandohg, combining your two fixes works great!

@bigdataboss
Copy link

Now let's combine them! Your connectws():

var connectws = function(callback) {
   wsclient = new signalR.client(
     opts.websockets_baseurl,
     opts.websockets_hubs, 
     undefined, true
   );
   if (opts.headers) {
     wsclient.headers['User-Agent'] = opts.headers.user_agent;
     wsclient.headers['cookie'] = opts.headers.cookie;
   }
   wsclient.start(); 
   wsclient.serviceHandlers = {
     bound: function() {
       ((opts.verbose) ? console.log('Websocket bound') : '');
     },
     connectFailed: function(error) {
       ((opts.verbose) ? console.log('Websocket connectFailed: ', error) : '');
     },
     disconnected: function() {
       ((opts.verbose) ? console.log('Websocket disconnected') : '');
     },
     onerror: function(error) {
       ((opts.verbose) ? console.log('Websocket onerror: ', error) : '');
     },
     bindingError: function(error) {
       ((opts.verbose) ? console.log('Websocket bindingError: ', error) : '');
     },
     connectionLost: function(error) {
       ((opts.verbose) ? console.log('Connection Lost: ', error) : '');
     },
     reconnecting: function(retry) {
       ((opts.verbose) ? console.log('Websocket Retrying: ', retry) : '');
       // change to true to stop retrying
       return false;
     }
   };
   return wsclient;
 };

Your main code:

const bittrex = require('node.bittrex.api');
const cloudscraper = require('cloudscraper');

cloudscraper.get('https://bittrex.com/', function (error, response, body) {
    if (error) {
        console.log('Cloudscraper error occurred');
    } else {  
        bittrex.options({
            headers: {
                cookie: response.request.headers["cookie"],
                user_agent: response.request.headers["User-Agent"]
            }
        });
        console.log('CloudFlare nailed');
        start(); // Your code here
    }
});

@ninesalt
Copy link

ninesalt commented Sep 9, 2017

Can we expect an official update to the module soon though?

@bigdataboss
Copy link

@Swailem95 Take a look: https://github.com/n0mad01/node.bittrex.api

@ninesalt
Copy link

ninesalt commented Sep 9, 2017

Well that sucks. Maybe someone's going to open a PR and fix it himself. That would be great.

@glaucoheitor
Copy link

Just need to update you code @CyberWlf, because response.request.headers["cookie"] replies with __cfduid AND cf_clearance.

@bigdataboss
Copy link

@glaucoheitor It's a hot fix, not an official solution. BTW, what's the problem with __cfduid ? It seems working

@glaucoheitor
Copy link

I know it's a hotfix. I am trying to use this here too.
Here don't work with that code. but if I put the cf_clearence code directly to signalR it works

@bigdataboss
Copy link

@glaucoheitor Works on my side. I don't see any reason why __cfduid could interrupt the process. You can update my solution btw :)

@glaucoheitor
Copy link

That what's weird, cause it works directly on the module file.

I was trying to update your solution, but I dont have that much knowledge. lol

@bigdataboss
Copy link

@glaucoheitor double check that you copied the exact code. Especially connectws() function. I use new "headers" option

@thanhlm86
Copy link

Any body help,

i try the way @armandohg, it show error :

{ errorType: 0, error: { Error: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 3128 3128:80 at ClientRequest.onError (C:\Users\ThinkPad\Desktop\node-bittrex-api\node_modules\tunnel-agent\index.js:177:17) at Object.onceWrapper (events.js:316:30) at emitOne (events.js:115:13) at ClientRequest.emit (events.js:210:7) at Socket.socketErrorListener (_http_client.js:401:9) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) code: 'ECONNRESET' } }
how to fix problem? Thanks.

@dparlevliet
Copy link
Contributor

For those looking for an integrated fix for this issue I have committed it to https://github.com/dparlevliet/node.bittrex.api

Important note: this makes the websocket connection asynchronous so please see the updated documentation https://github.com/dparlevliet/node.bittrex.api#websockets

There is a unit test added which you can test with npm test tests/websocket.js to ensure it works for you.

If you have any further comments or suggestions please add them to here dparlevliet#1

@LRonHubs
Copy link
Author

Thank you @dparlevliet

@masalinas
Copy link

Thank you @dparlevliet

@p0ntsNL
Copy link

p0ntsNL commented Nov 12, 2017

So for those that have issues with this on python, for me this works now:

Please correct me if I am wrong! :)


from requests import Session
from signalr import Connection
import cfscrape
import time

markets = ['BTC-DGB', 'BTC-STRAT']

with cfscrape.create_scraper() as session:
  connection = Connection('http://socket.bittrex.com/signalr', session)

corehub = connection.register_hub('coreHub')

#create error handler
def print_error(error):
  print('error: ', error)

# debug information, show all data
def print_raw_data(*args, **kwargs):
  print (args, kwargs)

def ticker_data(*args, **kwargs):
  print ticker, (args, kwargs)

def market_data(*args, **kwargs):
  print market, (args, kwargs)

#connection.received += print_raw_data
connection.error += print_error

connection.start()
print "sending subscription request"
for market in markets:
  corehub.server.invoke('SubscribeToExchangeDeltas', market)

#corehub.client.on('updateSummaryState', ticker_data)
corehub.client.on('updateExchangeState', market_data)

connection.wait(120000) # close the connection if no message is received after this many seconds

@jmontija
Copy link

jmontija commented Nov 12, 2017

Nicely done cfscrape do the job. I don't know why we got this error the bittrex_socket is on and everything was working fine until yersterday.
Thanks

@p0ntsNL
Copy link

p0ntsNL commented Nov 12, 2017

Nicely done cfscrape do the job. I don't know why we got this error the bittrex_socket is on and everything was working fine until yersterday. As well I was wondering if you know how to handle connection status to catch disconnection ? because I'm looping infinitly on connection.wait(0)
Thanks

I think its because Bittrex enabled Cloudflare today again :) so thats why I was working with cfscrape today

@rclai
Copy link

rclai commented Mar 20, 2018

Is this still an issue? Just wondering since it's been months since there was any activity here.

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

No branches or pull requests