Do not retry if the answer is a error result

This commit is contained in:
elroy 2017-07-14 19:33:04 +02:00
parent b7e4e41e74
commit 3a4b59de07
2 changed files with 9 additions and 7 deletions

View File

@ -83,6 +83,7 @@ public class GunbotProxyService {
retryPolicy = new RetryPolicy() retryPolicy = new RetryPolicy()
.retryOn(failure -> failure instanceof Exception) .retryOn(failure -> failure instanceof Exception)
.abortOn(failure -> failure.getMessage().startsWith("error:"))
.withDelay(500, TimeUnit.MILLISECONDS) .withDelay(500, TimeUnit.MILLISECONDS)
.withMaxRetries(maxRetries); .withMaxRetries(maxRetries);
} }
@ -274,7 +275,7 @@ public class GunbotProxyService {
String result = Failsafe.with(retryPolicy) String result = Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException) .onFailedAttempt(this::handleException)
.get(() -> analyzeResult(tradingAPIClient.buy(currencyPair, buyPrice, amount, false, false, false))); .get(() -> analyzeResult(tradingAPIClient.buy(currencyPair, buyPrice, amount, false, false, false)));
logger.info("Buy order" + result); logger.info(String.format("Buy order for %s -- %s", currencyPair, result));
return result; return result;
} }
@ -292,7 +293,7 @@ public class GunbotProxyService {
String result = Failsafe.with(retryPolicy) String result = Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException) .onFailedAttempt(this::handleException)
.get(() -> analyzeResult(tradingAPIClient.buy(currencyPair, buyPrice, amount, false, false, false))); .get(() -> analyzeResult(tradingAPIClient.buy(currencyPair, buyPrice, amount, false, false, false)));
logger.info("Buy order" + result); logger.info(String.format("Buy order for %s -- %s", currencyPair, result));
return result; return result;
} }
@ -309,7 +310,7 @@ public class GunbotProxyService {
String result = Failsafe.with(retryPolicy) String result = Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException) .onFailedAttempt(this::handleException)
.get(() -> analyzeResult(tradingAPIClient.sell(currencyPair, buyPrice, amount, false, true, false))); .get(() -> analyzeResult(tradingAPIClient.sell(currencyPair, buyPrice, amount, false, true, false)));
logger.info("Sell order" + result); logger.info(String.format("Sell order for %s -- %s", currencyPair, result));
return result; return result;
} }
@ -342,7 +343,7 @@ public class GunbotProxyService {
throw new ProxyHandledException("No value was returned"); throw new ProxyHandledException("No value was returned");
} else if (result.contains("Nonce")) { } else if (result.contains("Nonce")) {
throw new ProxyHandledException("nonce error: " + result); throw new ProxyHandledException("nonce error: " + result);
} else if (result.contains("error")) { } else if (result.contains("error:")) {
throw new RuntimeException(result); throw new RuntimeException(result);
} }
return result; return result;
@ -393,9 +394,8 @@ public class GunbotProxyService {
public String checkTradingKey(String apiKey) { public String checkTradingKey(String apiKey) {
PoloniexTradingAPIClient tradingAPIClient = poloniexTradingAPIClients.get(apiKey); PoloniexTradingAPIClient tradingAPIClient = poloniexTradingAPIClients.get(apiKey);
String result = Failsafe.with(retryPolicy) return Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException) .onFailedAttempt(this::handleException)
.get(() -> analyzeResult(tradingAPIClient.returnOpenOrders("ALL"))); .get(() -> analyzeResult(tradingAPIClient.returnOpenOrders("ALL")));
return result;
} }
} }

View File

@ -15,5 +15,7 @@ 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.7.jar %sp% %sks% %sksp% %skp% %da% %ds% %a% %as% %lnl% set dbp=--doubleBuyProtectionSeconds=60
java -jar GunbotProxyCommunity-0.9.7.jar %sp% %sks% %sksp% %skp% %da% %ds% %a% %as% %lnl% %dbp%
pause pause