Skip to content

Commit

Permalink
support proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
cody824 authored and guodong committed Oct 29, 2018
1 parent ac027e5 commit b75b131
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
26 changes: 18 additions & 8 deletions src/main/java/com/cf/client/HTTPClient.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.cf.client;

import java.io.IOException;
import java.util.List;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
Expand All @@ -14,12 +9,27 @@
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.List;

/**
*
* @author David
*/
public class HTTPClient
{

private final HttpHost proxy;

public HTTPClient() {
this.proxy = null;
}

public HTTPClient(HttpHost proxy) {
this.proxy = proxy;
}


public String postHttp(String url, List<NameValuePair> params, List<NameValuePair> headers) throws IOException
{
HttpPost post = new HttpPost(url);
Expand All @@ -34,7 +44,7 @@ public String postHttp(String url, List<NameValuePair> params, List<NameValuePai
}
}

HttpClient httpClient = HttpClientBuilder.create().build();
HttpClient httpClient = HttpClientBuilder.create().setProxy(proxy).build();
HttpResponse response = httpClient.execute(post);

HttpEntity entity = response.getEntity();
Expand All @@ -58,7 +68,7 @@ public String getHttp(String url, List<NameValuePair> headers) throws IOExceptio
}
}

HttpClient httpClient = HttpClientBuilder.create().build();
HttpClient httpClient = HttpClientBuilder.create().setProxy(proxy).build();
HttpResponse response = httpClient.execute(request);

HttpEntity entity = response.getEntity();
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/com/cf/client/poloniex/PoloniexExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@
import com.cf.PriceDataAPIClient;
import com.cf.TradingAPIClient;
import com.cf.data.map.poloniex.PoloniexDataMapper;
import com.cf.data.model.poloniex.PoloniexActiveLoanTypes;
import com.cf.data.model.poloniex.PoloniexChartData;
import com.cf.data.model.poloniex.PoloniexCompleteBalance;
import com.cf.data.model.poloniex.PoloniexFeeInfo;
import com.cf.data.model.poloniex.PoloniexOpenOrder;
import com.cf.data.model.poloniex.PoloniexOrderResult;
import com.cf.data.model.poloniex.PoloniexOrderTrade;
import com.cf.data.model.poloniex.PoloniexTicker;
import com.cf.data.model.poloniex.PoloniexTradeHistory;
import com.cf.data.model.poloniex.*;
import org.apache.http.HttpHost;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
*
* @author David
Expand All @@ -39,6 +32,12 @@ public PoloniexExchangeService(String apiKey, String apiSecret) {
this.mapper = new PoloniexDataMapper();
}

public PoloniexExchangeService(String apiKey, String apiSecret, HttpHost httpHost) {
this.publicClient = new PoloniexPublicAPIClient(httpHost);
this.tradingClient = new PoloniexTradingAPIClient(apiKey, apiSecret, httpHost);
this.mapper = new PoloniexDataMapper();
}

public PoloniexExchangeService(PriceDataAPIClient publicClient, TradingAPIClient tradingClient, PoloniexDataMapper mapper) {
this.publicClient = publicClient;
this.tradingClient = tradingClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cf.data.model.poloniex.PoloniexLendingHistory;
import com.cf.data.model.poloniex.PoloniexLendingResult;
import com.cf.data.model.poloniex.PoloniexLoanOffer;
import org.apache.http.HttpHost;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -31,6 +32,11 @@ public PoloniexLendingService(String apiKey, String apiSecret)
this.mapper = new PoloniexDataMapper();
}

public PoloniexLendingService(String apiKey, String apiSecret, HttpHost proxy) {
this.tradingClient = new PoloniexTradingAPIClient(apiKey, apiSecret, proxy);
this.mapper = new PoloniexDataMapper();
}

public PoloniexLendingService(TradingAPIClient tradingClient, PoloniexDataMapper mapper)
{
this.tradingClient = tradingClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.cf.PriceDataAPIClient;
import com.cf.client.HTTPClient;
import java.io.IOException;
import org.apache.http.HttpHost;
import org.apache.logging.log4j.LogManager;

import java.io.IOException;

/**
*
* @author David
Expand All @@ -15,11 +17,14 @@ public class PoloniexPublicAPIClient implements PriceDataAPIClient
private static final String PUBLIC_URL = "https://poloniex.com/public?";
private final HTTPClient client;

public PoloniexPublicAPIClient()
{
public PoloniexPublicAPIClient() {
this.client = new HTTPClient();
}

public PoloniexPublicAPIClient(HttpHost proxy) {
this.client = new HTTPClient(proxy);
}

public PoloniexPublicAPIClient(HTTPClient client)
{
this.client = client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.cf.TradingAPIClient;
import com.cf.client.HTTPClient;
import org.apache.commons.codec.binary.Hex;
import org.apache.http.HttpHost;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -34,6 +35,12 @@ public PoloniexTradingAPIClient(String apiKey, String apiSecret) {
this.client = new HTTPClient();
}

public PoloniexTradingAPIClient(String apiKey, String apiSecret, HttpHost httpHost) {
this.apiKey = apiKey;
this.apiSecret = apiSecret;
this.client = new HTTPClient(httpHost);
}

@Override
public String returnBalances() {
return this.returnTradingAPICommandResults("returnBalances");
Expand Down

0 comments on commit b75b131

Please sign in to comment.