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

View File

@ -54,6 +54,8 @@ public class Application {
Cache completeBalancesCache = new Cache("completeBalances", 5, false, true, 0, 0); Cache completeBalancesCache = new Cache("completeBalances", 5, false, true, 0, 0);
Cache chartDataCache = new Cache("chartData", 500, false, false, 30, 30); Cache chartDataCache = new Cache("chartData", 500, false, false, 30, 30);
Cache balancesCache = new Cache("balances", 5, false, true, 0, 0); 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); cacheManager.addCache(tickerCache);
@ -62,6 +64,8 @@ public class Application {
cacheManager.addCache(completeBalancesCache); cacheManager.addCache(completeBalancesCache);
cacheManager.addCache(chartDataCache); cacheManager.addCache(chartDataCache);
cacheManager.addCache(balancesCache); cacheManager.addCache(balancesCache);
cacheManager.addCache(orderBookCache);
cacheManager.addCache(publicTradeHistoryCache);
if (doubleBuyProtectionSeconds > 0) { if (doubleBuyProtectionSeconds > 0) {
Cache buyOrderProtectionCache = new Cache("buyOrderProtection", 100, false, false, doubleBuyProtectionSeconds, doubleBuyProtectionSeconds); 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.math.BigDecimal;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -49,10 +50,53 @@ public class GunbotProxyController {
@RequestMapping(value = "/public/**") @RequestMapping(value = "/public/**")
@ResponseBody @ResponseBody
public String interceptAllCalls(HttpServletRequest request) { 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"; 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") @RequestMapping(value = "/public/**", params = "command=returnChartData")
@ResponseBody @ResponseBody
public String publicRequestChartData(HttpServletRequest request, public String publicRequestChartData(HttpServletRequest request,
@ -71,14 +115,6 @@ public class GunbotProxyController {
return gunbotProxyService.getTicker(); 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") @RequestMapping(value = "/tradingApi/**", params = "command=returnCompleteBalances")
@ResponseBody @ResponseBody
public String tradingRequestCompleteBalances(HttpServletRequest request) { public String tradingRequestCompleteBalances(HttpServletRequest request) {

View File

@ -180,6 +180,40 @@ public class GunbotProxyService {
return result; 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) @Cacheable(value = "tradeHistory", key = "#market", sync = true)
public String getTradeHistory(String market) { public String getTradeHistory(String market) {
return getTradeHistoryScheduled(market); return getTradeHistoryScheduled(market);