XChange
XChange copied to clipboard
Proxy options with Xchange
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 , 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 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
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 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 , 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 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?
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 - 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 how about the result of your research? Now I am got the same issue) And i start my own investigating
Hi, There's a way to set also username and password in the proxy settings?
@archenroot i am not found/ Only realize it in xchange lib)
Any update here? I also need to connect via authenticated proxy.
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);
@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?
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
@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?