fix monitoring

This commit is contained in:
elroy 2017-07-06 15:59:50 +02:00
parent 87080bdc05
commit aa7ced0042
6 changed files with 47 additions and 26 deletions

View File

@ -5,7 +5,7 @@
<groupId>nl.komtek</groupId> <groupId>nl.komtek</groupId>
<artifactId>GunbotProxyCommunity</artifactId> <artifactId>GunbotProxyCommunity</artifactId>
<version>0.9.4</version> <version>0.9.5</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>GunbotProxyCommunity</name> <name>GunbotProxyCommunity</name>

View File

@ -43,21 +43,25 @@ public class MonitoringController {
Resource[] logResources = resourcePatternResolver.getResources(logFilePatern); Resource[] logResources = resourcePatternResolver.getResources(logFilePatern);
List<String> logPaths = new ArrayList<>(); List<String> logPaths = new ArrayList<>();
for (Resource resource : logResources){ for (Resource resource : logResources) {
logPaths.add(resource.getFilename().replace("-log.txt", "")); logPaths.add(resource.getFilename().replace("-log.txt", ""));
} }
List<MonitoringData> monitoringDatas = new ArrayList<>(); List<MonitoringData> monitoringDatas = new ArrayList<>();
for (Resource resource : saveResources) { for (Resource resource : saveResources) {
String tmpName = resource.getFilename().replace("-save.json",""); String tmpName = resource.getFilename().replace("-save.json", "");
if (!logPaths.contains(tmpName)){ if (!logPaths.contains(tmpName)) {
continue; continue;
} }
byte[] data = Files.readAllBytes(resource.getFile().toPath()); byte[] data = Files.readAllBytes(resource.getFile().toPath());
monitoringDatas.add(gson.fromJson(new String(data), MonitoringData.class)); monitoringDatas.add(gson.fromJson(new String(data), MonitoringData.class));
} }
modelMap.put("monitoringDatas", monitoringDatas); modelMap.put("monitoringDatas", monitoringDatas);
modelMap.put("balance", gunbotProxyService.getBTCBalance("default")); String market = "default";
return new ModelAndView("index",modelMap); if (gunbotProxyService.isUsingMultipleMarkets()) {
market = "BTC";
}
modelMap.put("balance", gunbotProxyService.getBTCBalance(market));
return new ModelAndView("index", modelMap);
} }
} }

View File

@ -187,7 +187,7 @@ public class GunbotProxyService {
.onFailedAttempt(this::handleException) .onFailedAttempt(this::handleException)
.get(() -> analyzeResult(publicClient.returnTicker())); .get(() -> analyzeResult(publicClient.returnTicker()));
if (logger.getLevel().isLessSpecificThan(Level.DEBUG)) { if (logger.getLevel().isMoreSpecificThan(Level.INFO)) {
logger.info("ticker updated"); logger.info("ticker updated");
} else { } else {
logger.info("ticker: " + result); logger.info("ticker: " + result);
@ -215,14 +215,6 @@ public class GunbotProxyService {
return getCompleteBalancesScheduled(market); return getCompleteBalancesScheduled(market);
} }
@Cacheable(value = "balances", key = "#market")
public double getBTCBalance(String market) {
String result = getBalancesScheduled(market);
JsonElement jsonElement = new JsonParser().parse(result);
JsonObject jsonObject = jsonElement.getAsJsonObject();
return jsonObject.get("BTC").getAsDouble();
}
@CachePut(value = "completeBalances", key = "#market") @CachePut(value = "completeBalances", key = "#market")
public String getCompleteBalancesScheduled(String market) { public String getCompleteBalancesScheduled(String market) {
PoloniexTradingAPIClient tradingAPIClient = getMarketDefaultTradingClient(market); PoloniexTradingAPIClient tradingAPIClient = getMarketDefaultTradingClient(market);
@ -233,14 +225,22 @@ public class GunbotProxyService {
return result; return result;
} }
@CachePut(value = "balances", key = "market") @Cacheable(value = "balances", key = "#market")
public String getBalancesScheduled(String market) { public double getBTCBalance(String market) {
return getBalancesScheduled(market);
}
@CachePut(value = "balances", key = "#market")
public double getBalancesScheduled(String market) {
PoloniexTradingAPIClient tradingAPIClient = getMarketDefaultTradingClient(market); PoloniexTradingAPIClient tradingAPIClient = getMarketDefaultTradingClient(market);
String result = Failsafe.with(retryPolicy) String result = Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException) .onFailedAttempt(this::handleException)
.get(() -> analyzeResult(tradingAPIClient.returnBalances())); .get(() -> analyzeResult(tradingAPIClient.returnBalances()));
logger.debug("balances" + result); logger.debug("balances" + result);
return result; JsonElement jsonElement = new JsonParser().parse(result);
JsonObject jsonObject = jsonElement.getAsJsonObject();
return jsonObject.get("BTC").getAsDouble();
} }
@Cacheable(value = "openOrders", key = "#market", sync = true) @Cacheable(value = "openOrders", key = "#market", sync = true)

View File

@ -121,4 +121,12 @@ public class ScheduledTasks {
} }
} }
@Scheduled(fixedDelay = 10000)
public void updateBalances() {
String market = "default";
if (gunbotProxyService.isUsingMultipleMarkets()) {
market = "BTC";
}
gunbotProxyService.getBalancesScheduled(market);
}
} }

View File

@ -2,7 +2,7 @@
<diskStore path="cache" /> <diskStore path="cache" />
<cache <cache
name="tradeHistory" name="tradeHistory"
maxElementsInMemory="10000" maxElementsInMemory="500"
eternal="false" eternal="false"
timeToIdleSeconds="0" timeToIdleSeconds="0"
timeToLiveSeconds="0" timeToLiveSeconds="0"
@ -11,7 +11,7 @@
<cache <cache
name="openOrders" name="openOrders"
maxElementsInMemory="10000" maxElementsInMemory="500"
eternal="false" eternal="false"
timeToIdleSeconds="0" timeToIdleSeconds="0"
timeToLiveSeconds="0" timeToLiveSeconds="0"
@ -20,7 +20,7 @@
<cache <cache
name="completeBalances" name="completeBalances"
maxElementsInMemory="10000" maxElementsInMemory="5"
eternal="false" eternal="false"
timeToIdleSeconds="0" timeToIdleSeconds="0"
timeToLiveSeconds="0" timeToLiveSeconds="0"
@ -29,7 +29,7 @@
<cache <cache
name="chartData" name="chartData"
maxElementsInMemory="10000" maxElementsInMemory="500"
eternal="false" eternal="false"
timeToIdleSeconds="0" timeToIdleSeconds="0"
timeToLiveSeconds="10" timeToLiveSeconds="10"
@ -38,7 +38,7 @@
<cache <cache
name="ticker" name="ticker"
maxElementsInMemory="10000" maxElementsInMemory="500"
eternal="false" eternal="false"
timeToIdleSeconds="0" timeToIdleSeconds="0"
timeToLiveSeconds="0" timeToLiveSeconds="0"
@ -47,11 +47,20 @@
<cache <cache
name="buyOrderProtection" name="buyOrderProtection"
maxElementsInMemory="10000" maxElementsInMemory="500"
eternal="false" eternal="false"
timeToIdleSeconds="30" timeToIdleSeconds="30"
timeToLiveSeconds="30" timeToLiveSeconds="30"
overflowToDisk="false" overflowToDisk="false"
memoryStoreEvictionPolicy="LFU" /> memoryStoreEvictionPolicy="LFU" />
<cache
name="balances"
maxElementsInMemory="5"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
memoryStoreEvictionPolicy="LFU" />
</ehcache> </ehcache>

View File

@ -2,7 +2,7 @@ set sp=--server.port=443
set sks=--server.ssl.key-store=classpath:poloniex.keystore set sks=--server.ssl.key-store=classpath:poloniex.keystore
set sksp=--server.ssl.key-store-password=poloniex set sksp=--server.ssl.key-store-password=poloniex
set skp=--server.ssl.key-password=poloniex set skp=--server.ssl.key-password=poloniex
set gbl=--gunbot.location=file://C:/Users/Elroy/OneDrive/Documents/GUNBOT_v3.3.2 set gbl=--gunbot.location=file://C:/Users/Elroy/Documents/GUNBOT_v3.3.2
set lnl=--logging.level.nl.komtek=DEBUG set lnl=--logging.level.nl.komtek=DEBUG
@ -14,5 +14,5 @@ REM This apiKey will do the buying and selling and orders canceling stuff. You c
set a=--apiKey1=another apiKey set a=--apiKey1=another apiKey
set as=--apiSecret1=your secret set as=--apiSecret1=your secret
java -jar GunbotProxyCommunity-0.9.2.jar %sp% %sks% %sksp% %skp% %da% %ds% %a% %as% %lnl% java -jar GunbotProxyCommunity-0.9.5.jar %sp% %sks% %sksp% %skp% %da% %ds% %a% %as% %lnl%
pause pause