jaggedsoft / node-binance-api

Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use.
MIT License
1.58k stars 768 forks source link

candlesticks endpoint returning ECONNREFUSED #151

Closed dseravalli closed 6 years ago

dseravalli commented 6 years ago

My bot was running fine and all of a sudden I started getting errors from the candlesticks endpoint but it's not returning a standard Binance error that I'm used to (like when I hit a rate limit). It's returning a generic ECONNREFUSED.

I don't think this is rate limit related though. Immediately after running this test script I can hit the API with Postman and it works fine. The rate limit is supposed to be 1200/minute and I'm nowhere near that. Also this code worked fine hours ago. Is it possible they've implemented a per second rate limit now?

Error received:

{ Error: connect ECONNREFUSED 52.193.87.1:443
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '52.193.87.1',
  port: 443 }

Here's a test script. For me, any value of i over 6 will error every request over 6. So there's always six success and then all errors basically.

const binanceApi = require('node-binance-api');

binanceApi.options({
  APIKEY: process.env.BINANCE_KEY,
  APISECRET: process.env.BINANCE_SECRET,
  useServerTime: true,
  test: true,
});

for(let i=0; i < 7; i++) {
  binanceApi.candlesticks('ETHBTC', '1m', (error, ticks) => {
    if (error) {
      console.log(error);
    } else {
      console.log('success');
    }
  });
}
dseravalli commented 6 years ago

I think this is due to concurrent requests. Binance must only allow 6 concurrent HTTP requests? Works fine If I write the code in a way that waits for previous request to finish first. Not sure why it was working before....

jaggedsoft commented 6 years ago

Recommend using websocket chart endpoint if possible

dseravalli commented 6 years ago

I am, this is just to grab all the symbol’s candlesticks once on app startup

dseravalli commented 6 years ago

Turns out it wasnt concurrent requests...getting it now with just one.

jaggedsoft commented 6 years ago

Best solution is to keep a daemon running that's listening to all the charts, and writing that data to json file so you always have it up to date. This is a job for Websockets.

dseravalli commented 6 years ago

Turns out this was a Docker networking glitch and nothing to do with this library or Binance.

dajneem23 commented 2 years ago

Author

i got same issue how u solve it ?