| | |
| | | import com.xcong.excoin.common.enumerates.RabbitPriceTypeEnum; |
| | | import com.xcong.excoin.common.response.Result; |
| | | import com.xcong.excoin.common.system.service.CommonService; |
| | | import com.xcong.excoin.modules.coin.service.CoinService; |
| | | import com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao; |
| | | import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao; |
| | | import com.xcong.excoin.modules.contract.dao.ContractOrderDao; |
| | |
| | | @Autowired |
| | | private FollowProducer followProducer; |
| | | |
| | | @Autowired |
| | | private CoinService coinService; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Result submitOrder(SubmitOrderDto submitOrderDto) { |
| | |
| | | return Result.loading("loading_type"); |
| | | } |
| | | |
| | | BigDecimal total = coinService.getAllWalletAmount(memberIdLong); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | if (total.compareTo(AppContants.BASE_MIN_AMOUNT) > 0) { |
| | | data.put("baseUrl", AppContants.BASE_URL_L2); |
| | | } else { |
| | | data.put("baseUrl", AppContants.BASE_URL_L1); |
| | | } |
| | | |
| | | // 判断当前对应的持仓/委托 |
| | | if (memberEntity.getContractPositionType() == ContractEntrustOrderEntity.POSITION_TYPE_ADD) { |
| | | List<ContractHoldOrderEntity> holdList = contractHoldOrderDao.selectMemberHoldOrderByPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ALL, memberEntity.getId()); |
| | |
| | | } |
| | | |
| | | // 逐仓逻辑 |
| | | return doPositionTypeForAdd(submitOrderDto, memberEntity); |
| | | Result result = doPositionTypeForAdd(submitOrderDto, memberEntity); |
| | | result.setData(data); |
| | | return result; |
| | | } else { |
| | | List<ContractHoldOrderEntity> holdList = contractHoldOrderDao.selectMemberHoldOrderByPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD, memberEntity.getId()); |
| | | List<ContractEntrustOrderEntity> entrustList = contractEntrustOrderDao.selectMemberEntrustOrderByPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD, memberEntity.getId()); |
| | |
| | | } |
| | | |
| | | // 全仓逻辑 |
| | | return doPositionTypeForWhole(submitOrderDto, memberEntity); |
| | | Result result = doPositionTypeForWhole(submitOrderDto, memberEntity); |
| | | result.setData(data); |
| | | return result; |
| | | } |
| | | |
| | | } |
| | |
| | | memberWalletContractDao.increaseWalletContractBalanceById(prePaymentAmount.negate(), openFeePrice.negate(), null, walletContract.getId()); |
| | | |
| | | // 发送预估强平价 |
| | | ThreadPoolUtils.sendWholeForceClosingPrice(submitOrderDto.getSymbol(), memberEntity); |
| | | // ThreadPoolUtils.sendWholeForceClosingPrice(submitOrderDto.getSymbol(), memberEntity); |
| | | // 计算佣金 |
| | | ThreadPoolUtils.calReturnMoney(memberEntity.getId(), openFeePrice, contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN); |
| | | |
| | |
| | | memberWalletContractDao.increaseWalletContractBalanceById(prePaymentAmount.negate(), openFeePrice.negate(), null, walletContract.getId()); |
| | | |
| | | // 发送预估强平价 |
| | | ThreadPoolUtils.sendWholeForceClosingPrice(submitOrderDto.getSymbol(), memberEntity); |
| | | // ThreadPoolUtils.sendWholeForceClosingPrice(submitOrderDto.getSymbol(), memberEntity); |
| | | // 计算佣金 |
| | | ThreadPoolUtils.calReturnMoney(memberEntity.getId(), contractOrderEntity.getOpeningFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN); |
| | | |
| | |
| | | holdOrderListVo.setReturnRate(returnRate); |
| | | holdOrderListVo.setProfitOrLoss(rewardRatio); |
| | | if (ContractEntrustOrderEntity.POSITION_TYPE_ALL == memberEntity.getContractPositionType()) { |
| | | BigDecimal forcePrice = CalculateUtil.calForcePriceForWhole(memberEntity, holdOrderEntity); |
| | | contractHoldOrderDao.updateForcePriceBySymbolAndMemberId(forcePrice, memberEntity.getId(), holdOrderEntity.getSymbol()); |
| | | BigDecimal forcePrice = CalculateUtil.calWholePriceTwo(memberEntity, holdOrderEntity, 1); |
| | | // contractHoldOrderDao.updateForcePriceBySymbolAndMemberId(forcePrice, memberEntity.getId(), holdOrderEntity.getSymbol()); |
| | | holdOrderListVo.setForceClosingPrice(forcePrice); |
| | | } |
| | | resultList.add(holdOrderListVo); |
| | |
| | | if (i > 0) { |
| | | // 发送爆仓消息 |
| | | sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo(), holdOrderEntity.getMemberId()); |
| | | |
| | | if (ContractOrderEntity.CONTRACTTYPE_DOCUMENTARY == holdOrderEntity.getContractType()) { |
| | | followProducer.sendChangeFollowOrderBond(changeBondDto); |
| | | } |
| | | return Result.ok("调整成功"); |
| | | } |
| | | return Result.fail("调整失败"); |
| | |
| | | // 发送爆仓消息 |
| | | sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), newForcePrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo(), holdOrderEntity.getMemberId()); |
| | | } else { |
| | | holdOrderEntity.setHoldAmount(holdAmount); |
| | | contractHoldOrderDao.updateById(holdOrderEntity); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(thisTimeHold.negate(), thisTimeHold.negate(), null, wallet.getId()); |
| | | ThreadPoolUtils.sendWholePrice(holdOrderEntity.getMemberId()); |
| | | // holdOrderEntity.setHoldAmount(holdAmount); |
| | | // contractHoldOrderDao.updateById(holdOrderEntity); |
| | | // memberWalletContractDao.increaseWalletContractBalanceById(thisTimeHold.negate(), thisTimeHold.negate(), null, wallet.getId()); |
| | | // ThreadPoolUtils.sendWholePrice(holdOrderEntity.getMemberId()); |
| | | } |
| | | } |
| | | } |