use of hry.trade.redis.model.EntrustTrade in project benchmark by seelunzi.
the class ExEntrustServiceImpl method getExEntrustChangeDephMarket.
/* */
/* */
public String getExEntrustChangeDephMarket(String coinCode, String fixPriceCoinCode, Integer n, BigDecimal jj) /* */
{
/* 669 */
MarketDepths marketDepths = new MarketDepths();
/* 670 */
Map<String, List<BigDecimal[]>> map = new HashMap();
/* 671 */
int keepDecimalForCoin = 4;
/* 672 */
int keepDecimalForCurrency = 4;
/* */
/* 674 */
CoinKeepDecimal coinKeepDecimal = null;
/* 675 */
String str = this.redisService.get("cn:coinInfoList");
/* 676 */
if (!StringUtils.isEmpty(str)) {
/* 677 */
List<CoinKeepDecimal> coins = JSON.parseArray(str, CoinKeepDecimal.class);
/* 678 */
if ((coins != null) && (coins.size() > 0)) {
/* 679 */
for (CoinKeepDecimal coin : coins) {
/* 680 */
if ((coinCode.equals(coin.getCoinCode())) && (fixPriceCoinCode.equals(coin.getFixPriceCoinCode()))) {
/* 681 */
coinKeepDecimal = coin;
/* */
}
/* */
}
/* */
}
/* */
}
/* 687 */
if (null != coinKeepDecimal) {
/* 688 */
keepDecimalForCoin = coinKeepDecimal.getKeepDecimalForCoin().intValue();
/* 689 */
keepDecimalForCurrency = coinKeepDecimal.getKeepDecimalForCurrency().intValue();
/* */
}
/* 691 */
int keepDecimalForCurrencysubone = keepDecimalForCurrency - 1;
/* 692 */
if (keepDecimalForCurrencysubone < 0) {
/* 693 */
keepDecimalForCurrencysubone = 0;
/* */
}
/* 695 */
BigDecimal depth = new BigDecimal(1).divide(getByn(keepDecimalForCurrencysubone), keepDecimalForCurrencysubone, 1);
/* 696 */
depth = depth.multiply(jj);
/* 697 */
List<BigDecimal[]> bids = new ArrayList();
/* 698 */
EntrustTrade sellexEntrust = new EntrustTrade();
/* 699 */
sellexEntrust.setCoinCode(coinCode);
/* 700 */
sellexEntrust.setFixPriceCoinCode(fixPriceCoinCode);
/* 701 */
sellexEntrust.setType(Integer.valueOf(2));
/* 702 */
List<BigDecimal> keyslistbuy = TradeRedis.getMatchkeys(sellexEntrust);
/* 703 */
if ((null != keyslistbuy) && (keyslistbuy.size() > 0)) {
/* 704 */
BigDecimal maxPrice = new BigDecimal(((BigDecimal) keyslistbuy.get(0)).toString());
/* 705 */
if (maxPrice.compareTo(BigDecimal.ZERO) > 0) {
/* 706 */
BigDecimal startPrice = maxPrice.setScale(depth.scale(), 1);
/* 707 */
startPrice = startPrice.subtract(depth);
/* 708 */
int i = 0;
/* 709 */
int flag = 0;
/* 710 */
for (int j = 0; j < 5; j++) {
/* 711 */
if (j > 0) {
/* 712 */
startPrice = startPrice.subtract(depth);
/* */
}
/* 714 */
if (flag == 1) {
/* */
break;
/* */
}
/* 717 */
if (startPrice.compareTo(new BigDecimal(0)) <= 0) {
/* 718 */
flag = 1;
/* 719 */
startPrice = new BigDecimal(0);
/* */
}
/* 721 */
BigDecimal surplusEntrustCount = new BigDecimal("0");
/* 722 */
while (i < keyslistbuy.size()) {
/* 723 */
BigDecimal keybig = (BigDecimal) keyslistbuy.get(i);
/* 724 */
if (keybig.compareTo(startPrice) < 0)
break;
/* 725 */
String keyall = TradeRedis.getHeaderMatch(sellexEntrust) + ":" + keybig.toString();
/* 726 */
List<EntrustTrade> list = TradeRedis.getMatchEntrustTradeBykey(keyall);
/* 727 */
if (null != list) {
/* 728 */
for (EntrustTrade entrustTrade : list) {
/* 729 */
surplusEntrustCount = surplusEntrustCount.add(entrustTrade.getSurplusEntrustCount());
/* */
}
/* */
}
/* 732 */
i++;
/* */
}
/* */
/* */
/* */
/* */
/* */
/* 739 */
BigDecimal[] array = new BigDecimal[2];
/* 740 */
array[0] = startPrice.setScale(keepDecimalForCurrency, 6);
/* 741 */
array[1] = surplusEntrustCount.setScale(keepDecimalForCoin, 6);
/* 742 */
bids.add(array);
/* */
}
/* */
}
/* */
}
/* 746 */
map.put("bids", bids);
/* */
/* */
/* 749 */
List<BigDecimal[]> asks = new ArrayList();
/* 750 */
EntrustTrade byllexEntrust = new EntrustTrade();
/* 751 */
byllexEntrust.setCoinCode(coinCode);
/* 752 */
byllexEntrust.setFixPriceCoinCode(fixPriceCoinCode);
/* 753 */
byllexEntrust.setType(Integer.valueOf(1));
/* 754 */
List<BigDecimal> keyslistsell = TradeRedis.getMatchkeys(byllexEntrust);
/* 755 */
if ((null != keyslistsell) && (keyslistsell.size() > 0)) {
/* 756 */
BigDecimal minPrice = new BigDecimal(((BigDecimal) keyslistsell.get(0)).toString());
/* 757 */
if (minPrice.compareTo(BigDecimal.ZERO) > 0) {
/* 758 */
BigDecimal startPrice = minPrice.setScale(depth.scale(), 1);
/* 759 */
startPrice = startPrice.add(depth);
/* 760 */
int k = 0;
/* 761 */
for (int j = 0; j < 5; j++) {
/* 762 */
if (j > 0) {
/* 763 */
startPrice = startPrice.add(depth);
/* */
}
/* 765 */
BigDecimal surplusEntrustCount = new BigDecimal("0");
/* 766 */
while (k < keyslistsell.size()) {
/* 767 */
BigDecimal keybig = (BigDecimal) keyslistsell.get(k);
/* 768 */
if (keybig.compareTo(startPrice) >= 1)
break;
/* 769 */
String keyall = TradeRedis.getHeaderMatch(byllexEntrust) + ":" + keybig.toString();
/* 770 */
List<EntrustTrade> list = TradeRedis.getMatchEntrustTradeBykey(keyall);
/* 771 */
if (null != list) {
/* 772 */
for (EntrustTrade entrustTrade : list) {
/* 773 */
surplusEntrustCount = surplusEntrustCount.add(entrustTrade.getSurplusEntrustCount());
/* */
}
/* */
}
/* 776 */
k++;
/* */
}
/* */
/* */
/* */
/* */
/* */
/* 783 */
BigDecimal[] array = new BigDecimal[2];
/* 784 */
array[0] = startPrice.setScale(keepDecimalForCurrency, 6);
/* 785 */
array[1] = surplusEntrustCount.setScale(keepDecimalForCoin, 6);
/* 786 */
asks.add(array);
/* */
}
/* */
}
/* */
}
/* */
/* 791 */
map.put("asks", asks);
/* 792 */
marketDepths.setDepths(map);
/* 793 */
return JSON.toJSONString(marketDepths).toString();
/* */
}
Aggregations