-
Notifications
You must be signed in to change notification settings - Fork 501
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
Websockets state #13
Comments
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? |
no, none so far. 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. 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. |
Please note that the actual websocket call is not necessary to check the state of the websocket. |
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. |
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
}
}) |
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? |
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. |
Today seems to be a bad day for binance websockets, but a great day for testing this library:
This also confirms that this library does not reopen dropped websockets, or handle timeouts properly. |
@balthazar When we return individual WS connections (#62), then it would be possible to iterate over them and query them for their state. |
Is there anyway to determine the state of the websocket (closed, connecting, connected, ..)?
The text was updated successfully, but these errors were encountered: