Search in sources :

Example 1 with MarketDepths

use of hry.trade.websoketContext.model.MarketDepths in project benchmark by seelunzi.

the class ExEntrustServiceImpl method getExEntrustChangeMarket.

/*     */
/*     */
/*     */
public String getExEntrustChangeMarket(String coinCode, String fixPriceCoinCode, Integer n) /*     */
{
    /* 559 */
    MarketDepths marketDepths = new MarketDepths();
    /* 560 */
    Map<String, List<BigDecimal[]>> map = new HashMap();
    /* 561 */
    int keepDecimalForCoin = 4;
    /* 562 */
    int keepDecimalForCurrency = 4;
    /*     */
    /* 564 */
    CoinKeepDecimal coinKeepDecimal = null;
    /* 565 */
    String str = this.redisService.get("cn:coinInfoList");
    /* 566 */
    if (!StringUtils.isEmpty(str)) {
        /* 567 */
        List<CoinKeepDecimal> coins = JSON.parseArray(str, CoinKeepDecimal.class);
        /* 568 */
        if ((coins != null) && (coins.size() > 0)) {
            /* 569 */
            for (CoinKeepDecimal coin : coins) {
                /* 570 */
                if ((coinCode.equals(coin.getCoinCode())) && (fixPriceCoinCode.equals(coin.getFixPriceCoinCode()))) {
                    /* 571 */
                    coinKeepDecimal = coin;
                /*     */
                }
            /*     */
            }
        /*     */
        }
    /*     */
    }
    /* 576 */
    if (null != coinKeepDecimal) {
        /* 577 */
        keepDecimalForCoin = coinKeepDecimal.getKeepDecimalForCoin().intValue();
        /* 578 */
        keepDecimalForCurrency = coinKeepDecimal.getKeepDecimalForCurrency().intValue();
    /*     */
    }
    /*     */
    /* 581 */
    List<BigDecimal[]> bids = new ArrayList();
    /* 582 */
    EntrustTrade sellexEntrust = new EntrustTrade();
    /* 583 */
    sellexEntrust.setCoinCode(coinCode);
    /* 584 */
    sellexEntrust.setFixPriceCoinCode(fixPriceCoinCode);
    /* 585 */
    sellexEntrust.setType(Integer.valueOf(2));
    /* 586 */
    List<BigDecimal> keyslistbuy = TradeRedis.getMatchkeys(sellexEntrust);
    /* 587 */
    int i = 0;
    /* 588 */
    while (i < keyslistbuy.size()) {
        /* 589 */
        BigDecimal keybig = (BigDecimal) keyslistbuy.get(i);
        /* 590 */
        String keyall = TradeRedis.getHeaderMatch(sellexEntrust) + ":" + keybig.toString();
        /* 591 */
        List<EntrustTrade> list = TradeRedis.getMatchEntrustTradeBykey(keyall);
        /* 592 */
        BigDecimal entrustPrice = new BigDecimal("0");
        /* 593 */
        BigDecimal surplusEntrustCount = new BigDecimal("0");
        /* 594 */
        if (null != list) {
            /* 595 */
            for (EntrustTrade entrustTrade : list) {
                /* 596 */
                entrustPrice = entrustTrade.getEntrustPrice();
                /* 597 */
                surplusEntrustCount = surplusEntrustCount.add(entrustTrade.getSurplusEntrustCount());
            /*     */
            }
            /* 599 */
            BigDecimal[] array = new BigDecimal[2];
            /* 600 */
            array[0] = entrustPrice.setScale(keepDecimalForCurrency, 6);
            /* 601 */
            array[1] = surplusEntrustCount.setScale(keepDecimalForCoin, 6);
            /* 602 */
            bids.add(array);
        /*     */
        }
        /* 605 */
        if (i == n.intValue())
            /*     */
            break;
        /* 607 */
        i++;
    /*     */
    }
    /*     */
    /* 610 */
    map.put("bids", bids);
    /* 611 */
    if (keyslistbuy.size() > 0) {
        /* 612 */
        String keybuy = TradeRedis.getHeaderFront(sellexEntrust) + ":" + "buyonePrice";
        /* 613 */
        String v = this.redisService.get(keybuy);
        /* 614 */
        if (StringUtil.isEmpty(v)) {
            /* 615 */
            this.redisService.save(keybuy, JSON.toJSONString(((BigDecimal[]) bids.get(0))[0]));
        /*     */
        }
    /*     */
    }
    /*     */
    /* 619 */
    List<BigDecimal[]> asks = new ArrayList();
    /* 620 */
    EntrustTrade byllexEntrust = new EntrustTrade();
    /* 621 */
    byllexEntrust.setCoinCode(coinCode);
    /* 622 */
    byllexEntrust.setFixPriceCoinCode(fixPriceCoinCode);
    /* 623 */
    byllexEntrust.setType(Integer.valueOf(1));
    /* 624 */
    List<BigDecimal> keyslistsell = TradeRedis.getMatchkeys(byllexEntrust);
    /* 625 */
    int k = 0;
    /* 626 */
    while (k < keyslistsell.size()) {
        /* 627 */
        BigDecimal keybig = (BigDecimal) keyslistsell.get(k);
        /* 628 */
        String keyall = TradeRedis.getHeaderMatch(byllexEntrust) + ":" + keybig.toString();
        /* 629 */
        List<EntrustTrade> list = TradeRedis.getMatchEntrustTradeBykey(keyall);
        /* 630 */
        BigDecimal entrustPrice = new BigDecimal("0");
        /* 631 */
        BigDecimal surplusEntrustCount = new BigDecimal("0");
        /* 632 */
        if (null != list) {
            /* 633 */
            for (EntrustTrade entrustTrade : list) {
                /* 634 */
                entrustPrice = entrustTrade.getEntrustPrice();
                /* 635 */
                surplusEntrustCount = surplusEntrustCount.add(entrustTrade.getSurplusEntrustCount());
            /*     */
            }
            /* 637 */
            BigDecimal[] array = new BigDecimal[2];
            /* 638 */
            array[0] = entrustPrice.setScale(keepDecimalForCurrency, 6);
            /* 639 */
            array[1] = surplusEntrustCount.setScale(keepDecimalForCoin, 6);
            /* 640 */
            asks.add(array);
        /*     */
        }
        /* 642 */
        if (k == n.intValue())
            /*     */
            break;
        /* 644 */
        k++;
    /*     */
    }
    /* 646 */
    map.put("asks", asks);
    /* 647 */
    if (keyslistsell.size() > 0) {
        /* 648 */
        String keysell = TradeRedis.getHeaderFront(byllexEntrust) + ":" + "sellonePrice";
        /* 649 */
        String v = this.redisService.get(keysell);
        /* 650 */
        if (StringUtil.isEmpty(v)) {
            /* 651 */
            this.redisService.save(keysell, JSON.toJSONString(((BigDecimal[]) asks.get(0))[0]));
        /*     */
        }
    /*     */
    }
    /*     */
    /* 655 */
    marketDepths.setDepths(map);
    /* 656 */
    return JSON.toJSONString(marketDepths).toString();
/*     */
}
Also used : BigDecimal(java.math.BigDecimal) MarketDepths(hry.trade.websoketContext.model.MarketDepths) EntrustTrade(hry.trade.redis.model.EntrustTrade) CoinKeepDecimal(hry.trade.model.CoinKeepDecimal)

Example 2 with MarketDepths

use of hry.trade.websoketContext.model.MarketDepths 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();
/*     */
}
Also used : BigDecimal(java.math.BigDecimal) MarketDepths(hry.trade.websoketContext.model.MarketDepths) EntrustTrade(hry.trade.redis.model.EntrustTrade) CoinKeepDecimal(hry.trade.model.CoinKeepDecimal)

Aggregations

CoinKeepDecimal (hry.trade.model.CoinKeepDecimal)2 EntrustTrade (hry.trade.redis.model.EntrustTrade)2 MarketDepths (hry.trade.websoketContext.model.MarketDepths)2 BigDecimal (java.math.BigDecimal)2