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 767 forks source link

导致我偶尔出现IP被短暂的封禁 #471

Closed jianxing-xu closed 4 years ago

jianxing-xu commented 4 years ago

binance.websockets.depthCache(QUERY, (symbol, depth) => { } 我在0.7.1这个版本使用这个方法,导致我偶尔出现IP被短暂的封禁,返回的json数据错误码为 1003 : -1003 TOO_MANY_REQUESTS 请问这个问题有在最新版被解决吗 ?

jianxing-xu commented 4 years ago

I used this method in version 0.7.1, which caused me occasionally to temporarily ban the IP, and the returned json data error code was 1003:-1003 TOO_MANY_REQUESTS. Has this problem been resolved in the latest version?

jaggedsoft commented 4 years ago

you have to space out calls to depthCache https://github.com/jaggedsoft/node-binance-api/issues/307

jianxing-xu commented 4 years ago

you have to space out calls to depthCache

307

function binanceInit() {

  binance = new Binance().options({
    APIKEY: APP_KEY,
    APISECRET: APP_SECRET,
    useServerTime: true,
    // test: true,
  });
  pong = setTimeout(() => {
    sendMessage('binance', 'ANY');
  }, timeLimit);

  binance.websockets.depthCache(QUERY, (symbol, depth) => {
    let bids = binance.sortBids(depth.bids);
    let asks = binance.sortAsks(depth.asks);
    let price = parseFloat(binance.first(bids) + binance.first(asks) / 2).toFixed(8);
    //  console.log(symbol);
    //  console.log(price);
    if ('BTCUSDT' === symbol) {
      btcPrice = price;
      setHashData(symbol, 'binance', price);
    } else if ('EOSUSDT' === symbol || 'ETHUSDT' === symbol) {
      setHashData(symbol, 'binance', price);
    } else {

      if ('WTCBTC' === symbol && btcPrice) {
        setData('binance', 'WTCUSDT', price * btcPrice);
      } else if ('AEBTC' === symbol && btcPrice) {
        setData('binance', 'AEUSDT', price * btcPrice);
      }
       else if ('BATBTC' === symbol && btcPrice) {
        setData('binance', 'BATUSDT', price * btcPrice);
      }
      else if ('SNTBTC' === symbol && btcPrice) {
        setData('binance', 'SNTUSDT', price * btcPrice);
      }
      else if ('BTSBTC' === symbol && btcPrice) {
        setData('binance', 'BTSUSDT', price * btcPrice);
      }

      else if ('THETAUSDT' === symbol) {
        setData('binance', 'THETAUSDT', price);
      }
      else if ('OMGUSDT' === symbol) {
        setData('binance', 'OMGUSDT', price);
      }
      else if ('IOSTUSDT' === symbol) {
        setData('binance', 'IOSTUSDT', price);
      }
      else if ('LTCUSDT' === symbol) {
        setData('binance', 'LTCUSDT', price);
      }

      else if ('LRCBTC' === symbol && btcPrice){
        setData('binance', 'LRCUSDT', price * btcPrice);
      }
      else if ('TUSDBTC' === symbol){
        setData('binance', 'TUSDBTC', price);
      }else if ('TUSDETH' === symbol){
        setData('binance', 'TUSDETH', price);
      }
      else {
        setData('binance', symbol, price);
      }
    }
    // console.log(`sysmbol: ${symbol}  price: ${price}`);
    checkPong();
  });

}

This is my code, it looks a bit bad

jaggedsoft commented 4 years ago

all of that code looks fine, I suspect the problem is around wherever QUERY is set, and depthCache is being called too fast

jianxing-xu commented 4 years ago

I seem to know that when there was a problem last time, the first log was that the request timed out, and then I started the javascript process several times, and then the response was 1003. It should be our server that caused the request to time out except for the problem. , And then this problem appeared due to my stupid operation. It may be due to the automatic restart of pm2 management, and I restarted manually, which resulted in frequent calls. thank you for your reply!

jaggedsoft commented 4 years ago

np good luck