|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | //                    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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | // 权益 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|