XChange
XChange copied to clipboard
How to use Proxies
ExchangeSpecification exSpec = new AscendexExchange().getDefaultExchangeSpecification();
exSpec.setSslUri("https://asdx.me");
exSpec.setApiKey("api");
exSpec.setSecretKey("secret");
exSpec.setProxyHost("ip");
exSpec.setProxyPort(1572);
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(exSpec);
This setup does not work 2.
ClientConfig clientConfig = ExchangeRestProxyBuilder.createClientConfig(exSpec);
ClientConfig clientConfig1 = ClientConfigUtil.addBasicAuthCredentials(clientConfig, "username", "password");
Exchange build = ExchangeRestProxyBuilder.forInterface( AscendexExchange.class,exSpec).clientConfig(clientConfig1).build();
thorw:
Exception in thread "main" java.lang.NullPointerException
at si.mazi.rescu.RestInvocationHandler.<init>(RestInvocationHandler.java:59)
at si.mazi.rescu.RestProxyFactory.createProxy(RestProxyFactory.java:47)
at si.mazi.rescu.RestProxyFactoryImpl.createProxy(RestProxyFactoryImpl.java:9)
at org.knowm.xchange.client.ExchangeRestProxyBuilder.build(ExchangeRestProxyBuilder.java:80)
at cn.iocoder.yudao.module.asdx.service.api.apiTest.main(apiTest.java:51)
Because :


I don't know how to use it correctly, hope to get help
I think I solved that problem
1.find <yourExchange>BaseService
---other code----
ExchangeSpecification specWithAccountGroup = exchange.getDefaultExchangeSpecification();
specWithAccountGroup.setSslUri(exchange.getExchangeSpecification().getSslUri());
String proxyUsername = getExchangeSpecificParametersItem("proxyUsername");
String proxyPassword = getExchangeSpecificParametersItem("proxyPassword");
Proxy.Type proxyType = getExchangeSpecificParametersItem("proxyType");
// create ClientConfig
ClientConfig clientConfig = ExchangeRestProxyBuilder.createClientConfig(exchange.getExchangeSpecification());
clientConfig.setProxyType(proxyType);
// set password
ClientConfig addPassword = ClientConfigUtil.addBasicAuthCredentials(clientConfig, proxyUsername, proxyPassword);
// apply clientConfig
ascendexAuthenticated =
ExchangeRestProxyBuilder.forInterface(IAscendexAuthenticated.class, specWithAccountGroup)
.clientConfig(addPassword)
.build();
----other code----
public <T> T getExchangeSpecificParametersItem(String key){
try {
return (T)exchange.getExchangeSpecification().getExchangeSpecificParametersItem(key);
} catch (Exception e) {
return null;
}
}
2.add ExchangeSpecificParametersItem
ExchangeSpecification exSpec = new AscendexExchange().getDefaultExchangeSpecification();
// proxy
exSpec.setProxyHost("49.70.95.173");
exSpec.setProxyPort(4256);
exSpec.setExchangeSpecificParametersItem("proxyUsername","proxyUsername");
exSpec.setExchangeSpecificParametersItem("proxyPassword","proxyPassword");
exSpec.setExchangeSpecificParametersItem("proxyType", Proxy.Type.SOCKS);
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(exSpec);
AccountInfo accountInfo = exchange.getAccountService().getAccountInfo();
System.out.println(accountInfo);
3.over
| --- | http(no Auth) | https(no Auth) | socks(no Auth) | socks(Auth) |
|---|---|---|---|---|
| proxyUsername | --- | --- | --- | --- |
| proxyPassword | --- | --- | --- | --- |
| proxyType | --- | --- | --- | --- |
| status | deny | normal | normal | normal |
----other
I did a simple test and found that the agent works well with or without authentication.(maybe bug)
Meanwhile, my centos builds SS5, but they don't work when you fill in the configuration, although it works fine elsewhere .(Whether authentication is enabled or not)
