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

Proxy module is needed when you a in a country wehere web is blocked #708

Open jzyzxx opened 3 years ago

jzyzxx commented 3 years ago

Proxy module is needed,especially the ws proxy.Now this is my proxy for http:

const Binance =require("node-binance-api");
const binance = new Binance().options({
  proxy:{
      host:"127.0.0.1",
      port:"49751"
  },
  APIKEY: '````',
  APISECRET: '````'
});

But i dont know how to deal with the ws proxy for websocket?

longlch commented 3 years ago

hi @jzyzxx How could you deal with proxy with future feature?

_binance = new BinanceApi().options({
        proxy:{
            host:"p.webshare.io",
            port:"80",
            auth: "userName:password"
        },
        'APIKEY': apiKey,
        'APISECRET': apiSecret,
        'test': true,
        useServerTime: true
    });

The error return tunneling socket could not be established, statusCode=407. Am I config correctly?

jzyzxx commented 3 years ago

hi @jzyzxx How could you deal with proxy with future feature?

_binance = new BinanceApi().options({
        proxy:{
            host:"p.webshare.io",
            port:"80",
            auth: "userName:password"
        },
        'APIKEY': apiKey,
        'APISECRET': apiSecret,
        'test': true,
        useServerTime: true
    });

The error return tunneling socket could not be established, statusCode=407. Am I config correctly?

The proxy did not work for ws connectionn,maybe you shoud get tips from the author

longlch commented 3 years ago

I can config successfully in http with username and password.

_binance = new BinanceApi().options({
        proxy:{
            host:"p.webshare.io",
            port:"80",
            auth: {
                username: "yourUserName",
                password: "yourPassword"
            },
        },
        'APIKEY': apiKey,
        'APISECRET': apiSecret,
        'test': true,
        useServerTime: true
    });
jzyzxx commented 3 years ago

I can config successfully in http with username and password.

_binance = new BinanceApi().options({
        proxy:{
            host:"p.webshare.io",
            port:"80",
            auth: {
                username: "yourUserName",
                password: "yourPassword"
            },
        },
        'APIKEY': apiKey,
        'APISECRET': apiSecret,
        'test': true,
        useServerTime: true
    });

But it dit not work for ws connection,the log indicated that the connection timeout.

jzyzxx commented 3 years ago

I can config successfully in http with username and password.

_binance = new BinanceApi().options({
        proxy:{
            host:"p.webshare.io",
            port:"80",
            auth: {
                username: "yourUserName",
                password: "yourPassword"
            },
        },
        'APIKEY': apiKey,
        'APISECRET': apiSecret,
        'test': true,
        useServerTime: true
    });

But it dit not work for ws connection,the log indicated that the connection timeout.

There are my logs:

[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]
[
  'Futures WebSocket error: btcusdt@miniTicker (ETIMEDOUT) connect ETIMEDOUT 31.13.69.160:443'
]
[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]
[
  'Futures WebSocket error: btcusdt@miniTicker (ETIMEDOUT) connect ETIMEDOUT 111.243.214.169:443'
]
[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]
neody commented 2 years ago

I can config successfully in http with username and password.

_binance = new BinanceApi().options({
        proxy:{
            host:"p.webshare.io",
            port:"80",
            auth: {
                username: "yourUserName",
                password: "yourPassword"
            },
        },
        'APIKEY': apiKey,
        'APISECRET': apiSecret,
        'test': true,
        useServerTime: true
    });

But it dit not work for ws connection,the log indicated that the connection timeout.

There are my logs:

[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]
[
  'Futures WebSocket error: btcusdt@miniTicker (ETIMEDOUT) connect ETIMEDOUT 31.13.69.160:443'
]
[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]
[
  'Futures WebSocket error: btcusdt@miniTicker (ETIMEDOUT) connect ETIMEDOUT 111.243.214.169:443'
]
[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]

bump, i have same problem

jzyzxx commented 2 years ago

I can config successfully in http with username and password.

_binance = new BinanceApi().options({
        proxy:{
            host:"p.webshare.io",
            port:"80",
            auth: {
                username: "yourUserName",
                password: "yourPassword"
            },
        },
        'APIKEY': apiKey,
        'APISECRET': apiSecret,
        'test': true,
        useServerTime: true
    });

But it dit not work for ws connection,the log indicated that the connection timeout.

There are my logs:

[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]
[
  'Futures WebSocket error: btcusdt@miniTicker (ETIMEDOUT) connect ETIMEDOUT 31.13.69.160:443'
]
[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]
[
  'Futures WebSocket error: btcusdt@miniTicker (ETIMEDOUT) connect ETIMEDOUT 111.243.214.169:443'
]
[ 'Futures WebSocket closed: btcusdt@miniTicker (1006)' ]
[ 'Futures WebSocket reconnecting: btcusdt@miniTicker...' ]

bump, i have same problem

I met the same problem too

liesauer commented 1 year ago

seems there is no way to use proxy option in websocket connection, only process.env.https_proxy and process.env.socks_proxy are accepted.

https://github.com/jaggedsoft/node-binance-api/blob/950d773a5f2c3a61c6e29b53e3af57594921a239/node-binance-api.js#L681-L701

liesauer commented 1 year ago

can't use custom proxyAgent either.

import Binance from 'node-binance-api';
import tunnel from "tunnel";

const proxy = tunnel.httpsOverHttp({
    proxy: {
        host: 'localhost',
        port: 8080,
        proxyAuth: "",
    },
});

// doesn't work
const binance = new Binance().options({
    proxy: proxy,
});