Helius
2020-09-07 5869138e0dafa923173b74679f3564e43c4c683d
modify
5 files modified
40 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/contract/service/impl/RabbitOrderServiceImpl.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/NewestPriceUpdateJob.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java 20 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/utils/CalculateUtil.java 11 ●●●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/WholeTest.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/service/impl/RabbitOrderServiceImpl.java
@@ -321,6 +321,7 @@
            contractOrderEntity.setRewardAmount(profitOrLoss);
            contractOrderEntity.setBondAmount(bondAmount.add(fee));
            contractOrderEntity.setClosingFeeAmount(fee);
            contractOrderEntity.setClosingTime(new Date());
            contractOrderDao.insert(contractOrderEntity);
            if (holdOrderEntity.getSymbolCntSale() != 0) {
src/main/java/com/xcong/excoin/quartz/job/NewestPriceUpdateJob.java
@@ -54,7 +54,9 @@
                // 比较
                websocketPriceService.comparePriceAsc(symbol, price);
                websocketPriceService.comparePriceDesc(symbol, price);
                if ("etcusdt".equalsIgnoreCase(symbol)) {
//                websocketPriceService.wholeBomb(symbol, price);
                }
                //System.out.println("比较完毕:"+symbol+"-"+price);
            }
src/main/java/com/xcong/excoin/rabbit/pricequeue/WebsocketPriceService.java
@@ -11,10 +11,7 @@
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
import com.xcong.excoin.rabbit.producer.OrderProducer;
import com.xcong.excoin.utils.CacheSettingUtils;
import com.xcong.excoin.utils.CalculateUtil;
import com.xcong.excoin.utils.RedisUtils;
import com.xcong.excoin.utils.SpringContextHolder;
import com.xcong.excoin.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -292,16 +289,23 @@
                if (CollUtil.isNotEmpty(holdOrderEntities)) {
                    BigDecimal totalProfitOrLess = BigDecimal.ZERO;
                    String currentPrice = null;
                    for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) {
                        if (symbol.equalsIgnoreCase(holdOrderEntity.getSymbol())) {
                            currentPrice = price;
                        } else {
                            currentPrice = redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol()));
                        }
                        BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol());
                        BigDecimal profitOrLess = CalculateUtil.calOrderProfitOrLess(holdOrderEntity.getOpeningType(), new BigDecimal(price), holdOrderEntity.getOpeningPrice(), lotNumber, holdOrderEntity.getSymbolCntSale(), memberEntity.getIsProfit());
                        BigDecimal profitOrLess = CalculateUtil.calOrderProfitOrLess(holdOrderEntity.getOpeningType(), new BigDecimal(currentPrice), holdOrderEntity.getOpeningPrice(), lotNumber, holdOrderEntity.getSymbolCntSale(), memberEntity.getIsProfit());
                        log.info("profitOrLess : {}, id : {}, symbol : {}, price : {}", profitOrLess, holdOrderEntity.getId(), holdOrderEntity.getSymbol(), currentPrice);
                        totalProfitOrLess = totalProfitOrLess.add(profitOrLess);
                    }
                    log.info("totalProfitOrLess : {}", totalProfitOrLess);
                    MemberWalletContractEntity wallet = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, CoinTypeEnum.USDT.name());
                    BigDecimal sub = wallet.getTotalBalance().subtract(totalProfitOrLess);
                    BigDecimal sub = wallet.getTotalBalance().add(totalProfitOrLess);
                    log.info("sub : {}, memberId : {}", sub, memberId);
                    if (sub.compareTo(BigDecimal.ZERO) <= 0) {
                        List<OrderModel> list = new ArrayList<>();
                        OrderModel orderModel = new OrderModel(null, 0, price, symbol, memberId);
src/main/java/com/xcong/excoin/utils/CalculateUtil.java
@@ -112,10 +112,14 @@
                BigDecimal profitOrLoss = BigDecimal.ZERO;
                // 杠杆
                int leverRatio = 0;
                boolean isAloneLess = true;
                for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) {
                    BigDecimal bondAmount = holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount());
                    if (symbol.equalsIgnoreCase(holdOrderEntity.getSymbol())) {
                        if (holdOrderEntity.getOpeningType() == ContractHoldOrderEntity.OPENING_TYPE_MORE) {
                            isAloneLess = false;
                        }
                        symbolFeeAmount = symbolFeeAmount.add(holdOrderEntity.getOpeningFeeAmount());
                        symbolBondAmount = symbolBondAmount.add(bondAmount);
@@ -139,7 +143,12 @@
                BigDecimal divide2 = openPrice.divide(BigDecimal.valueOf(leverRatio), 8, BigDecimal.ROUND_DOWN);
//                log.info("divide2 -- {}", divide2);
                BigDecimal forcePrice = openPrice.subtract(divide.multiply(divide2));
                BigDecimal forcePrice = BigDecimal.ZERO;
                if (isAloneLess) {
                    forcePrice  = openPrice.add(divide.multiply(divide2));
                } else {
                    forcePrice  = openPrice.subtract(divide.multiply(divide2));
                }
//                log.info("forcePrice -- {}", forcePrice);
                if (StrUtil.isBlank(currentSymbol)) {
                    holdOrderDao.updateForcePriceBySymbolAndMemberId(forcePrice, memberId, symbol);
src/test/java/com/xcong/excoin/WholeTest.java
@@ -13,6 +13,7 @@
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
import com.xcong.excoin.rabbit.pricequeue.OrderModel;
import com.xcong.excoin.rabbit.pricequeue.WebsocketPriceService;
import com.xcong.excoin.rabbit.producer.OrderProducer;
import com.xcong.excoin.utils.CalculateUtil;
import com.xcong.excoin.utils.RedisUtils;
@@ -141,9 +142,12 @@
        }
    }
    @Resource
    private WebsocketPriceService websocketPriceService;
    @Test
    public void wholeBombTest() {
        orderProducer.sendWholeBomb("1234567");
        websocketPriceService.wholeBomb("BTC/USDT", "9000");
    }
}