WIP flexible double buy protection
This commit is contained in:
parent
c75eac6c45
commit
361b0f4d80
|
@ -7,9 +7,7 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
|
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
|
||||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||||
import org.springframework.cache.CacheManager;
|
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.cache.ehcache.EhCacheCacheManager;
|
|
||||||
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
|
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
@ -36,29 +34,43 @@ public class Application {
|
||||||
private int additionalPort;
|
private int additionalPort;
|
||||||
@Value("${server.address:0.0.0.0}")
|
@Value("${server.address:0.0.0.0}")
|
||||||
private String serverAddress;
|
private String serverAddress;
|
||||||
|
@Value("${doubleBuyProtectionSeconds:0}")
|
||||||
|
private int doubleBuyProtectionSeconds;
|
||||||
|
@Value("${doubleBuyProtection:false}")
|
||||||
|
private boolean doubleBuyProtection;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CacheManager cacheManager() {
|
public net.sf.ehcache.management.CacheManager cacheManager() {
|
||||||
net.sf.ehcache.CacheManager cacheManager = ehCacheCacheManager().getObject();
|
net.sf.ehcache.CacheManager cacheManager = ehCacheCacheManager().getObject();
|
||||||
Cache tickerCache = new Cache("ticker", 500, false, false, 0, 0);
|
Cache tickerCache = new Cache("ticker", 500, false, false, 0, 0);
|
||||||
Cache tradeHistoryCache = new Cache("tradeHistory", 500, false, false, 0, 0);
|
Cache tradeHistoryCache = new Cache("tradeHistory", 500, false, false, 0, 0);
|
||||||
Cache openOrdersCache = new Cache("openOrders", 500, false, false, 0, 0);
|
Cache openOrdersCache = new Cache("openOrders", 500, false, false, 0, 0);
|
||||||
Cache completeBalancesCache = new Cache("completeBalances", 5, false, false, 0, 0);
|
Cache completeBalancesCache = new Cache("completeBalances", 5, false, false, 0, 0);
|
||||||
Cache chartDataCache = new Cache("chartData", 500, false, false, 30, 30);
|
Cache chartDataCache = new Cache("chartData", 500, false, false, 30, 30);
|
||||||
Cache buyOrderProtectionCache = new Cache("buyOrderProtection", 100, false, false, 30, 30);
|
|
||||||
Cache balancesCache = new Cache("balances", 5, false, false, 0, 0);
|
Cache balancesCache = new Cache("balances", 5, false, false, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
cacheManager.addCache(tickerCache);
|
cacheManager.addCache(tickerCache);
|
||||||
cacheManager.addCache(tradeHistoryCache);
|
cacheManager.addCache(tradeHistoryCache);
|
||||||
cacheManager.addCache(openOrdersCache);
|
cacheManager.addCache(openOrdersCache);
|
||||||
cacheManager.addCache(completeBalancesCache);
|
cacheManager.addCache(completeBalancesCache);
|
||||||
cacheManager.addCache(chartDataCache);
|
cacheManager.addCache(chartDataCache);
|
||||||
cacheManager.addCache(buyOrderProtectionCache);
|
|
||||||
cacheManager.addCache(balancesCache);
|
cacheManager.addCache(balancesCache);
|
||||||
return new EhCacheCacheManager(cacheManager);
|
|
||||||
|
if (doubleBuyProtectionSeconds > 0) {
|
||||||
|
Cache buyOrderProtectionCache = new Cache("buyOrderProtection", 100, false, false, doubleBuyProtectionSeconds, doubleBuyProtectionSeconds);
|
||||||
|
cacheManager.addCache(buyOrderProtectionCache);
|
||||||
|
} else if (doubleBuyProtection) {
|
||||||
|
Cache buyOrderProtectionCache = new Cache("buyOrderProtection", 100, false, false, 30, 30);
|
||||||
|
cacheManager.addCache(buyOrderProtectionCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new net.sf.ehcache.management.CacheManager(cacheManager);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -33,6 +33,8 @@ public class GunbotProxyController {
|
||||||
private GunbotProxyService gunbotProxyService;
|
private GunbotProxyService gunbotProxyService;
|
||||||
@Value("${doubleBuyProtection:false}")
|
@Value("${doubleBuyProtection:false}")
|
||||||
private boolean doubleBuyProtection;
|
private boolean doubleBuyProtection;
|
||||||
|
@Value("${doubleBuyProtectionSeconds:0}")
|
||||||
|
private int doubleBuyProtectionSeconds;
|
||||||
private Logger logger = LogManager.getLogger(GunbotProxyController.class);
|
private Logger logger = LogManager.getLogger(GunbotProxyController.class);
|
||||||
private PoloniexDataMapper mapper = new PoloniexDataMapper();
|
private PoloniexDataMapper mapper = new PoloniexDataMapper();
|
||||||
|
|
||||||
|
@ -141,7 +143,7 @@ public class GunbotProxyController {
|
||||||
@RequestParam BigDecimal amount) {
|
@RequestParam BigDecimal amount) {
|
||||||
|
|
||||||
String key = request.getHeader("key");
|
String key = request.getHeader("key");
|
||||||
if (doubleBuyProtection) {
|
if (doubleBuyProtection || doubleBuyProtectionSeconds > 0) {
|
||||||
return gunbotProxyService.buyOrderWithProtection(key, currencyPair, rate, amount);
|
return gunbotProxyService.buyOrderWithProtection(key, currencyPair, rate, amount);
|
||||||
} else {
|
} else {
|
||||||
return gunbotProxyService.buyOrder(key, currencyPair, rate, amount);
|
return gunbotProxyService.buyOrder(key, currencyPair, rate, amount);
|
||||||
|
|
Loading…
Reference in New Issue