Skip to content
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

I get errors when I try to use proxy with ccxt #20686

Closed
kerimSD opened this issue Jan 5, 2024 · 14 comments · Fixed by #22348
Closed

I get errors when I try to use proxy with ccxt #20686

kerimSD opened this issue Jan 5, 2024 · 14 comments · Fixed by #22348
Assignees

Comments

@kerimSD
Copy link

kerimSD commented Jan 5, 2024

Operating System

Windows

Programming Languages

JavaScript

CCXT Version

4.1.28

Description

I am trying to connect binance (also tried other exchanges) and retrieve my account balance by using a proxy. I've tested with http, https, socks5 proxies and with different implementations but even I can make any call without proxy, when I use proxy it gives error.

Could anyone help me about it?

Code

const ccxt = require("ccxt");
const binance = new ccxt.binance({
  });
binance.proxyUrl = "https://84.39.112.144:3128/";
const ticker = await binance.fetchTicker('BTC/USDT');
console.log("ticker",ticker)

This code gives that error:
image

also this one gives the same error

 binance.socksProxy = "socks5://199.187.210.54:4145/";

I also tried this implementation it doesn't give any error but it seems it doesn't make request via proxy but make the request with my own IP. (I added IP access restriction to my API Key but it still makes the request)

 const binance = new ccxt.binance({
            proxies: "http://103.231.78.36:80/"
        });
@carlosmiei
Copy link
Collaborator

@kerimSD Hello, from the log the proxyUrl usage seems correct ad you can see it appended the original request to the proxyUrl.

Regarding the socks5 issue, can you double-check if your proxy works as expected outside ccxt?

Also, we have made some updates to the proxies recently, can you update your ccxt version to make if it makes a difference?

Also, you can read more about the proxies we support here: https://docs.ccxt.com/#/README?id=supported-proxy-types

/cc @ttodua

@ttodua
Copy link
Member

ttodua commented Jan 5, 2024

@kerimSD

  1. have you tried binance.httpProxy or binance.httpsProxy ( https://docs.ccxt.com/#/README?id=httpproxy-and-httpsproxy ) instead of binance.proxyUrl? .proxyUrl concept is different than real proxy, you can read to the link above suggested by @carlosmiei
  2. also please update your installed ccxt package to latest version and let us know after you retest with latest version

@kerimSD
Copy link
Author

kerimSD commented Jan 8, 2024

@ttodua @carlosmiei
Thank you for your answers, I updated the ccxt and I tried both binance.httpProxy, binance.socksProxy but still I get the same error.
I tried proxies outside the ccxt and it seems like they work fine:
image
Error:
image

Could you try to use same proxy, to see if there is a problem with proxy or ccxt? (socks5://24.249.199.12:4145/)

@dooly9931
Copy link

I ran into the same issue.

Operating System

macOS 14.2.1

Programming Language

Typescript

CCXT version

4.2.9 (latest)

Description

I am getting same error with @kerimSD

Code

I have put https://${MY_PROXY_HOST}:80/ and http://${MY_PROXY_HOST}:80/ at .proxyUrl, .httpProxy, and .httpsProxy, and all of them failed.

const proxyUrl = `http://${MY_PROXY_HOST}:80/`;
const okx = new ccxt.okx({ ...this.key, proxyUrl });
const [balances, positions] = await Promise.all([
    (await okx.privateGetAccountBalance())["data"],
    (await okx.privateGetAccountPositions())["data"],
]);
NetworkError: okx GET http://my-proxy.host:80/https://www.okx.com/api/v5/account/balance fetch failed
NetworkError: okx GET https://www.okx.com/api/v5/account/balance fetch failed

I also tried HttpsProxyAgent as .agent, but it also failed.

Test Proxy out of CCXT

const res1 = await axios.get("https://api.ipify.org?format=json");
console.log(JSON.stringify(res1["data"], undefined, 2));
const res2 = await axios.get("https://api.ipify.org?format=json", { proxy: { protocol: "http", host: MY_PROXY_HOST, port: 80 } });
console.log(JSON.stringify(res2["data"], undefined, 2));

This code worked fine. Ouput:

{
  "ip": "43.103.68.0"
}
{
  "ip": "52.77.29.9"
}

@dooly9931
Copy link

dooly9931 commented Jan 9, 2024

Using .httpAgent instead of .proxyUrl, .httpProxy, .httpsProxy made my code run successfully.

const httpAgent = new HttpProxyAgent(`http://${MY_PROXY_HOST}:80`);
const okx = new ccxt.okx({ ...this.key, httpAgent });
const [balances, positions] = await Promise.all([
    (await okx.privateGetAccountBalance())["data"],
    (await okx.privateGetAccountPositions())["data"],
]);

It worked! But I still don't know why .proxyUrl and .httpProxy didn't work.

@kerimSD
Copy link
Author

kerimSD commented Jan 9, 2024

@dooly9931

Yes, it looks like working fine but even though I put an IP access restriction to my API Key, it still makes the request.
Isn't that means it doesn't use the proxy?

@dooly9931
Copy link

@kerimSD
You are right. I made a mistake during the proxy setting. I thought it worked, but it just didn't throw error, but still didn't use proxy actually.

@kerimSD
Copy link
Author

kerimSD commented Jan 10, 2024

I don't understand that if proxies don't work in ccxt at all?
or we can't correctly implement it? If that the case whats the issue and how to use proxies correctly, Can you please help @carlosmiei @ttodua

@dooly9931
Copy link

@kerimSD
How about trying using .httpsProxy with a proxy url starts with http://?
I think it worked for my case?

const httpsProxy = `http://${MY_PROXY_HOST}:80`;
const okx = new ccxt.okx({ ...this.key, httpsProxy });
const [balances, positions] = await Promise.all([
    (await okx.privateGetAccountBalance())["data"],
    (await okx.privateGetAccountPositions())["data"],
]);

@carlosmiei
Copy link
Collaborator

@kerimSD We use proxies daily on our tests pipeline (both for Rest and WS), so I think it is safe to say that they work.

@kerimSD
Copy link
Author

kerimSD commented Jan 10, 2024

@dooly9931 Thank you it worked! but I realise that only binance and gateio gives errors while using proxy, other exchanges like okx, kraken, huobi etc. are working fine.
@carlosmiei I wonder is Binance and Gateio made a protection against? Did you use proxy with these exchanges as well ?

@carlosmiei
Copy link
Collaborator

@kerimSD We do but for public queries, we are not sure if private ones have some kind of restriction, you might also try to change the proxy location to see if it makes a difference

@ttodua
Copy link
Member

ttodua commented Jan 11, 2024

Guys, to check if proxies work for you, please see an example at https://github.com/ccxt/ccxt/tree/master/examples and find file proxy-usage. there you will find how to test your proxies easily.

@bhdrgkz
Copy link

bhdrgkz commented Apr 6, 2024

hi everyone,

Operating System

macOS 14.2.1

Programming Language

Vanilla JavaScript

CCXT version

Latest

Description

I'm using CCXT since 2022 in my backend nodejs project and works fine.

I'm trying to implement CCXT browserside but i think i'm missing some points. I looked at the documents.

when i tried @dooly9931's and @kerimSD's codes for binance i got the this error:

NotSupported: binanceusdm you need to load JS proxy modules with .loadProxyModules() method at first to use proxies

when i tried .proxyUrl i got this error:

NetworkError: binanceusdm GET http://USERNAME:PASSWORD@PROXY_IP:PORT/https://api.binance.com/sapi/v1/capital/config/getall?timestamp=1712391286934&recvWindow=10000&signature=SIGNATUREHASH fetch failed

btw okx works fine.

CODE

const httpsProxy = `http://USERNAME:PASSWORD@PROXY_IP:PORT`;
const binance = new ccxt.binanceusdm({ ...this.key, httpsProxy });
const balance = binance.fetchBalance();
console.log(balance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants