Add support for gunbot 3.3.3 and implement some missing polo endpoints

This commit is contained in:
elroy 2017-07-29 11:21:24 +02:00
parent 7172466764
commit bf6e16fafa
4 changed files with 88 additions and 14 deletions

View File

@ -5,7 +5,7 @@
<groupId>nl.komtek</groupId>
<artifactId>GunbotProxyCommunity</artifactId>
<version>0.9.8</version>
<version>0.9.9</version>
<packaging>jar</packaging>
<name>GunbotProxyCommunity</name>
@ -83,7 +83,7 @@
<dependency>
<groupId>com.cf</groupId>
<artifactId>PoloniexClient</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
</dependency>
<dependency>

View File

@ -54,6 +54,8 @@ public class Application {
Cache completeBalancesCache = new Cache("completeBalances", 5, false, true, 0, 0);
Cache chartDataCache = new Cache("chartData", 500, false, false, 30, 30);
Cache balancesCache = new Cache("balances", 5, false, true, 0, 0);
Cache orderBookCache = new Cache("orderBook", 5, false, true, 0, 0);
Cache publicTradeHistoryCache = new Cache("publicTradeHistory", 5, false, true, 0, 0);
cacheManager.addCache(tickerCache);
@ -62,6 +64,8 @@ public class Application {
cacheManager.addCache(completeBalancesCache);
cacheManager.addCache(chartDataCache);
cacheManager.addCache(balancesCache);
cacheManager.addCache(orderBookCache);
cacheManager.addCache(publicTradeHistoryCache);
if (doubleBuyProtectionSeconds > 0) {
Cache buyOrderProtectionCache = new Cache("buyOrderProtection", 100, false, false, doubleBuyProtectionSeconds, doubleBuyProtectionSeconds);

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -49,10 +50,53 @@ public class GunbotProxyController {
@RequestMapping(value = "/public/**")
@ResponseBody
public String interceptAllCalls(HttpServletRequest request) {
logger.debug("intercepted -- " + request.getRequestURL() + "?" + request.getQueryString() + "?command=" + request.getParameter("command"));
logger.info("intercepted -- " + request.getRequestURL() + "?" + request.getQueryString() + "?command=" + request.getParameter("command"));
return "intercepted";
}
@RequestMapping(value = "/tradingApi/**")
@ResponseBody
public String tradingRequests(HttpServletRequest request) {
logger.debug(request.getRequestURL() + "??command=" + request.getParameter("command"));
request.getParameterMap().keySet().forEach((e) -> System.out.print(e + "-"));
return "trading api intercepted";
}
@RequestMapping(value = "/public/**", params = "command=return24hVolume")
@ResponseBody
public String publicRequestOrderBook(@RequestParam String currencyPair) {
return gunbotProxyService.getOrderBook(currencyPair);
}
@RequestMapping(value = "/public/**", params = "command=return24hVolume")
@ResponseBody
public String publicRequest24hVolume() {
return gunbotProxyService.get24hVolume();
}
@RequestMapping(value = "/public/**", params = "command=returnTradeHistory")
@ResponseBody
public String publicRequestTradeHistory(@RequestParam String currencyPair,
@RequestParam(required = false) String start,
@RequestParam(required = false) String end) {
final long startLong;
if (start.indexOf(".") > 0) {
startLong = Long.valueOf(start.substring(0, start.indexOf(".")));
} else {
startLong = Long.valueOf(start);
}
final long endLong;
if (end == null) {
Calendar cal = Calendar.getInstance();
endLong = cal.getTimeInMillis() / 1000;
} else if (end.indexOf(".") > 0) {
endLong = Long.valueOf(end.substring(0, end.indexOf(".")));
} else {
endLong = Long.valueOf(end);
}
return gunbotProxyService.getPublicTradeHistory(currencyPair, startLong, endLong);
}
@RequestMapping(value = "/public/**", params = "command=returnChartData")
@ResponseBody
public String publicRequestChartData(HttpServletRequest request,
@ -71,14 +115,6 @@ public class GunbotProxyController {
return gunbotProxyService.getTicker();
}
@RequestMapping(value = "/tradingApi/**")
@ResponseBody
public String tradingRequests(HttpServletRequest request) {
logger.debug(request.getRequestURL() + "??command=" + request.getParameter("command"));
request.getParameterMap().keySet().stream().forEach((e) -> System.out.print(e + "-"));
return "trading api";
}
@RequestMapping(value = "/tradingApi/**", params = "command=returnCompleteBalances")
@ResponseBody
public String tradingRequestCompleteBalances(HttpServletRequest request) {
@ -235,14 +271,14 @@ public class GunbotProxyController {
return filteredjArray.toString();
}
private JsonArray hideOpenOrders(JsonArray jsonArray){
private JsonArray hideOpenOrders(JsonArray jsonArray) {
for (Iterator<JsonElement> it = jsonArray.iterator(); it.hasNext(); ) {
JsonElement element = it.next();
JsonObject jsonObject = element.getAsJsonObject();
String orderNumber = jsonObject.get("orderNumber").getAsString();
String[] orderNumbersToHide = StringUtils.trimAllWhitespace(util.getConfigurationProperty("hideOrders","")).split(",");
if (Arrays.asList(orderNumbersToHide).contains(orderNumber)){
String[] orderNumbersToHide = StringUtils.trimAllWhitespace(util.getConfigurationProperty("hideOrders", "")).split(",");
if (Arrays.asList(orderNumbersToHide).contains(orderNumber)) {
it.remove();
}
}

View File

@ -180,6 +180,40 @@ public class GunbotProxyService {
return result;
}
@Cacheable(value = "orderBook", key = "#currencyPair")
public String getOrderBook(String currencyPair) {
return getOrderBookScheduled(currencyPair);
}
public String get24hVolume() {
return publicClient.return24Volume();
}
@CachePut(value = "orderBook", key = "#currencyPair")
public String getOrderBookScheduled(String currencyPair) {
String result = Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException)
.get(() -> analyzeResult(publicClient.returnOrderBook(currencyPair)));
logger.debug("OrderBook: " + result);
return result;
}
@Cacheable(value = "publicTradeHistory", key = "#currencyPair", sync = true)
public String getPublicTradeHistory(String currencyPair, long start, long end) {
return getPublicTradeHistoryScheduled(currencyPair, start, end);
}
@CachePut(value = "publicTradeHistory", key = "#market")
public String getPublicTradeHistoryScheduled(String currencyPair, long start, long end) {
String result = Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException)
.get(() -> analyzeResult(publicClient.returnTradeHistory(currencyPair, start, end)));
logger.debug(currencyPair + "-" + "public trade history: " + result);
return result;
}
@Cacheable(value = "tradeHistory", key = "#market", sync = true)
public String getTradeHistory(String market) {
return getTradeHistoryScheduled(market);