Comments (9)
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.
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.
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.
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.
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.
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.
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.
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.
@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)
- Partial depth not working
- How do you get the current position info for future account? HOT 1
- Reconnecting-websocket options not working? HOT 1
- TypeError: fetch failed HOT 1
- fix about node:fetch? HOT 1
- Module "crypto" has been externalized for browser compatibility HOT 2
- DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated.
- TypeError: Binance is not a function HOT 2
- futuresCancelBatchOrders lacks return-type annotation HOT 3
- Different data
- Opening an order with TP/SL HOT 5
- quantity parameter on Trailling Stop futuresOrder
- Incorrect data type of batchOrders in futuresBatchOrders
- futuresCancelBatchOrders return type error
- Websocket was closed before the connection was estabilshed with binance-api-node ticker and futuresticker
- Error: Invalid API-key, IP, or permissions for action. HOT 2
- How to keep TCP connection alive for REST requests
- Http-client : _crypto.default.createHmac is not a function
- How to i get a new depositAddress if I need it ?
- How to create valid takeprofit and stoploss in futures?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binance-api-node.