XChange icon indicating copy to clipboard operation
XChange copied to clipboard

Proxy options with Xchange

Open archenroot opened this issue 7 years ago • 16 comments

Hi guys, in situation like being on production system without direct connectivity to internet, what are proxy options with xchange?

Also I heard that exchanges might block connections detected coming from proxies, is there any way to clean up proxies from being detected?

Thanks for any hints.

Ladislav

archenroot avatar Jan 25 '18 19:01 archenroot

@archenroot , XChange has a "built-in" option for proxy at ExchangeSpecification . Fields String proxyHost and Integer proxyPort.

These properties are used internally by rescu library at BaseExchangeService class

In my humble opinion, these 2 properties aren't enough, because sometimes we face an authenticated proxy. So, I would add String proxyUsername and String proxyPassword properties at ExchangeSpecification

Also, you could test the Java Networking Properties at your application and hopely, it will works.

daniloguimaraes avatar Jan 26 '18 11:01 daniloguimaraes

@daniloguimaraes Thank you very much for confirmation and hint. I will test it carefully. I was already under impression of using standard:

System.setProperty("http.proxyHost", "");
System.setProperty("http.proxyPort", "");

or using OS level proxy settin (can be set per user), but both actually apply JVM wide setting.

The way you describe is even more robust, because you can create 2 exchange instances, each with its own proxy within the same JVM, is my assumption correct?

Best regards,

Ladislav

archenroot avatar Jan 26 '18 13:01 archenroot

Yeah, @archenroot . When you use System.setProperty, will be applied to entire JVM.

Now, using specific exchange specification you can mix proxies (even no proxy).

Good luck.

daniloguimaraes avatar Jan 26 '18 13:01 daniloguimaraes

@daniloguimaraes Thx budy, I actually implemented new method in rescu code: https://github.com/mmazi/rescu/issues/104

But I am not sure if that is enough or not.

I also extended in Xchange code ExchangeSpecification by adding proxyUser and proxyPassword, but where is the exact place to inject the header? I am quite new to this codebase and although it is well documented, I am not sure simply :-)

archenroot avatar Jan 27 '18 12:01 archenroot

@archenroot , I suppose a simple example could be like this:

Exchange yourFavoriteExchange = ExchangeFactory.INSTANCE.createExchange(YourFavoriteExchange.class.getName());

ExchangeSpecification exchangeSpec = yourFavoriteExchange.getDefaultExchangeSpecification();

exchangeSpec.setProxyHost("localhost");
exchangeSpec.setProxyPort(8080);

yourFavoriteExchange.applySpecification(exchangeSpec);

// Now 'yourFavoriteExchange' instance is ready to connect through proxy.

daniloguimaraes avatar Jan 28 '18 23:01 daniloguimaraes

@daniloguimaraes Well, this is easy one, which works well already, but the extension with ProxyAuthorization HTTP header aka user name and password, where to put it?

archenroot avatar Jan 29 '18 09:01 archenroot

There is method in BaseExchangeService called getClientConfig() (check here)

This method already set up proxy host and port, if needed. You could open a PR to add proxy username and password as well.

daniloguimaraes avatar Jan 29 '18 12:01 daniloguimaraes

@daniloguimaraes - I will open PR definitely I work on fork already, I think the change will need to happen in rescu lib. But still investigating

archenroot avatar Jan 29 '18 15:01 archenroot

@archenroot how about the result of your research? Now I am got the same issue) And i start my own investigating

FedrBodr avatar Feb 26 '18 16:02 FedrBodr

Hi, There's a way to set also username and password in the proxy settings?

ghost avatar May 06 '18 18:05 ghost

@archenroot i am not found/ Only realize it in xchange lib)

FedrBodr avatar May 16 '18 15:05 FedrBodr

Any update here? I also need to connect via authenticated proxy.

bbottema avatar Jul 15 '19 10:07 bbottema

My Xchange is 5.0.0-SNAPSHOT. My code is ok. ExchangeSpecification exSpec = new BinanceExchange().getDefaultExchangeSpecification(); exSpec.setProxyHost("127.0.0.1");//edit youself exSpec.setProxyPort(50772);////edit youself Exchange exchange = ExchangeFactory.INSTANCE.createExchange(exSpec);

mapleafly avatar May 30 '20 12:05 mapleafly

@daniloguimaraes - I will open PR definitely I work on fork already, I think the change will need to happen in rescu lib. But still investigating

Hi. Did you get solution for entering proxy credentials to exchange specification?

elkceo avatar Sep 11 '21 04:09 elkceo

I also encountered the same problem, how to set up a proxy with' username' and' password' ------
Or you could look at this :https://github.com/knowm/XChange/issues/4555

wodepig avatar Aug 22 '22 03:08 wodepig

@archenroot Hey! Looks like you didn't create PR, I am struggling with same problem right now - I need to enter proxy credentials. Did you solve this problem?

ArLeyar avatar Jan 25 '23 13:01 ArLeyar