Helius
2020-10-21 907b4dbbef4739f7ee0a65dcfa0df1ae1180ff83
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
@@ -34,6 +34,8 @@
import com.xcong.excoin.modules.member.entity.*;
import com.xcong.excoin.modules.platform.dao.TradeSettingDao;
import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity;
import com.xcong.excoin.modules.symbols.parameter.vo.HomeSymbolsVo;
import com.xcong.excoin.modules.symbols.service.SymbolsService;
import com.xcong.excoin.rabbit.producer.OrderProducer;
import com.xcong.excoin.utils.*;
import com.xcong.excoin.rabbit.pricequeue.OrderModel;
@@ -93,12 +95,15 @@
    private FollowTraderInfoDao followTraderInfoDao;
    @Resource
    private FollowFollowerOrderRelationDao followFollowerOrderRelationDao;
    @Resource
    private SymbolsService symbolsService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result submitOrder(SubmitOrderDto submitOrderDto) {
        MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
        log.info("订单类型:{}", memberEntity.getContractPositionType());
        // 判断当前对应的持仓/委托
        if (memberEntity.getContractPositionType() == ContractEntrustOrderEntity.POSITION_TYPE_ADD) {
            List<ContractHoldOrderEntity> holdList = contractHoldOrderDao.selectMemberHoldOrderByPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ALL, memberEntity.getId());
@@ -222,7 +227,7 @@
        holdOrderEntity.setOpeningPrice(openingPrice);
        holdOrderEntity.setOpeningType(submitOrderDto.getOrderType());
        holdOrderEntity.setMarkPrice(newPrice);
        holdOrderEntity.setIsCanClosing(ContractHoldOrderEntity.ORDER_CAN_CLOSING_N);
        holdOrderEntity.setIsCanClosing(ContractHoldOrderEntity.ORDER_CAN_CLOSING_Y);
        holdOrderEntity.setPrePaymentAmount(prePaymentAmount);
        holdOrderEntity.setBondAmount(bondAmount.add(openFeePrice));
        holdOrderEntity.setOperateNo(1);
@@ -474,6 +479,11 @@
//                    canAddMaxBond = BigDecimal.ZERO;
//                }
                BigDecimal canReduceMaxBond = holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getPrePaymentAmount());
                if (rewardRatio.compareTo(BigDecimal.ZERO) < 0) {
                    canReduceMaxBond = canReduceMaxBond.add(rewardRatio);
                }
                if (canReduceMaxBond.compareTo(BigDecimal.ZERO) < 0) {
                    canReduceMaxBond = BigDecimal.ZERO;
                }
@@ -791,23 +801,26 @@
        // 权益
        BigDecimal equity = walletContractEntity.getTotalBalance().add(totalProfitOrLess);
        // 全仓模式,可用余额需随着盈亏变动
        if (memberEntity.getContractPositionType() == ContractEntrustOrderEntity.POSITION_TYPE_ALL) {
            BigDecimal available = walletContractEntity.getAvailableBalance().add(totalProfitOrLess);
            if (available.compareTo(BigDecimal.ZERO) < 0) {
                available = BigDecimal.ZERO;
            }
            contractMoneyInfoVo.setAvailableBalance(available);
        }
//        if (memberEntity.getContractPositionType() == ContractEntrustOrderEntity.POSITION_TYPE_ALL) {
//            BigDecimal available = walletContractEntity.getAvailableBalance().add(totalProfitOrLess);
//            if (available.compareTo(BigDecimal.ZERO) < 0) {
//                available = BigDecimal.ZERO;
//            }
//            contractMoneyInfoVo.setAvailableBalance(available);
//        }
        HomeSymbolsVo symbolReturnData = symbolsService.getSymbolReturnData(symbol);
        contractMoneyInfoVo.setBeUsedBondAmount(beUsedBondAmount);
        contractMoneyInfoVo.setFrozenBondAmount(frozenBondAmount);
        contractMoneyInfoVo.setAvailableBalance(walletContractEntity.getAvailableBalance());
        contractMoneyInfoVo.setEquity(equity);
        contractMoneyInfoVo.setFeeRatio(tradeSetting.getFeeRatio());
        contractMoneyInfoVo.setLeverAgeRatio(tradeSetting.getLeverageRatio());
        contractMoneyInfoVo.setNewPrice(newPriceSymbol);
        contractMoneyInfoVo.setSymbolSku(cacheSettingUtils.getSymbolSku(symbol));
        contractMoneyInfoVo.setLeverRate(rateEntity.getLevelRateUp());
        contractMoneyInfoVo.setUpOrDown(symbolReturnData.getUpOrDown());
        return Result.ok(contractMoneyInfoVo);
    }