Code Monkey home page Code Monkey logo

Comments (9)

wannesdemaeght avatar wannesdemaeght commented on June 6, 2024 1

Today seems to be a bad day for binance websockets, but a great day for testing this library:

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: connect ETIMEDOUT 52.199.118.147:9443
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)

This also confirms that this library does not reopen dropped websockets, or handle timeouts properly.
Is there something we can do on our end to ensure this does not crash node (and preferably, retry to establish connection)?

from binance-api-node.

balthazar avatar balthazar commented on June 6, 2024

Not really, since it's possible to open multiple with one call, I only return the function to be able to close them. Why are you asking? Do you have connectivity issues?

from binance-api-node.

wannesdemaeght avatar wannesdemaeght commented on June 6, 2024

no, none so far.
I was just hoping to use the connected state as a safeguard to interrupt my program. (and restart the websocket)

The way it is written now, on a random disconnect, the price I have stored for binance would just stop updating, but no warning what so ever.
This would be dangerous because I am comparing the price between multiple exchanges and make trades based on that price difference.

Example from another library I use:

const Bittrex = require("node-bittrex-api");
Bittrex.options({
	websockets: {
		onConnect: function() {
			console.log('Bittrex connected');
			Polling_Bittrex = 1;
		},
		onDisconnect: function() {
			console.log('Bitrex disconnected');
			Polling_Bittrex = 0;
			Bittrex_Websocket();
		}
	}
});

I then check for the Polling_Bittrex state in every iteration of my program.

from binance-api-node.

wannesdemaeght avatar wannesdemaeght commented on June 6, 2024

Please note that the actual websocket call is not necessary to check the state of the websocket.
I only have 1 call for bittrex, but that doesn't matter for the safeguard.

from binance-api-node.

balthazar avatar balthazar commented on June 6, 2024

Hum I see, not sure what would be the best here, maybe passing two optional callbacks as parameters. The issue is what to do when people are opening multiple channels.

from binance-api-node.

wannesdemaeght avatar wannesdemaeght commented on June 6, 2024

This is my function of websocket feeds right now, how do you propose I would change it to have a sefeguard for the binance websocket?

	const Gdax_Websocket = new GdaxLib.WebsocketClient(Gdax_Market,"wss://ws-feed.gdax.com",null, {channels : [{"name" : "ticker"}]});
	Gdax_Websocket.on("message", data => { 
		if (data.type == "ticker") {
			for (x = 0; x < Number_of_Alts+1; x++) {
				if(data.product_id == Gdax_Market[x]) Gdax_BidPrice[x] = Number(data.best_bid)
			}
		}
	})
	Gdax_Websocket.on("open", data => {
		console.log("Websocket Gdax:        connected");
		Polling_Gdax = 1;
	})
	Gdax_Websocket.on("close", data => {
		Polling_Gdax = 0;
		console.log("Websocket Gdax:     disconnected")
		Gdax_Websocket();
	})
	
	const Bittrex_Websocket = new Bittrex.websockets.subscribe(Market_Bittrex.slice(1), function(data) {
		if (data.M === "updateExchangeState") {
			data.A.forEach(function(data_for) {
				for (x = 1; x < Number_of_Alts+1; x++) {
					if (data_for.MarketName == Market_Bittrex[x]) AskPrice_Bittrex[x] = data_for.Sells[0]["Rate"]
				}
				if (data_for.MarketName == "BTC-ZEC") ZEC_Price = data_for.Buys[0]["Rate"]
			})
		}
	})
	Bittrex.options({
		websockets: {
			onConnect: function() {
				console.log("Websocket Bittrex:     connected");
				Polling_Bittrex = 1;
			},
			onDisconnect: function() {
				console.log("Websocket Bittrex:  disconnected");
				Polling_Bittrex = 0;
				Bittrex_Websocket();
			}
		}
	});

	const Binance_Websocket = Binance.ws.ticker(Market_Binance.slice(1), ticker => {
		for (x = 1; x < Number_of_Alts+1; x++) {	
			if (ticker.symbol == Market_Binance[x]) AskPrice_Binance[x] = ticker.bestAsk
		}
	})

from binance-api-node.

wannesdemaeght avatar wannesdemaeght commented on June 6, 2024

I have fixed the safeguard issue by checking the eventtime of the tickers. on every loop, the new eventtime must be greater than the last. So that's working.

Only thing left to do is reopen websocket when it's been dropped, does this library do this?

from binance-api-node.

balthazar avatar balthazar commented on June 6, 2024

Nope, what I think I'll end up doing is simply having two optional callbacks in each method that people can use themselves. It wouldn't really work if they open multiple sockets at once but it should be something they take care about too.

from binance-api-node.

bennycode avatar bennycode commented on June 6, 2024

@balthazar When we return individual WS connections (#62), then it would be possible to iterate over them and query them for their state.

from binance-api-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.