| | |
| | | } |
| | | } |
| | | |
| | | // 逐仓委托 |
| | | if (ContractEntrustOrderEntity.POSITION_TYPE_ADD == memberEntity.getContractPositionType()) { |
| | | return entrustForAdd(submitEntrustDto, memberEntity); |
| | | // 全仓委托 |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(submitEntrustDto.getSymbol()); |
| | | PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); |
| | | |
| | | MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name()); |
| | | |
| | | // 保证金计算 -- 建仓价X规格X手数X(1/杠杆倍率) |
| | | BigDecimal bondAmount = CalculateUtil.getBondAmount(submitEntrustDto.getEntrustPrice(), lotNumber, submitEntrustDto.getSymbolCnt(), submitEntrustDto.getLeverRatio()); |
| | | |
| | | // 开仓手续费 建仓价*规格*手数*手续费率 |
| | | BigDecimal openFeePrice = CalculateUtil.getOpenFeePrice(submitEntrustDto.getEntrustPrice(), lotNumber, submitEntrustDto.getSymbolCnt(), tradeSettingEntity.getFeeRatio()); |
| | | log.info("手续费:{}", openFeePrice); |
| | | |
| | | // 预付款 |
| | | BigDecimal entrustTotalAmount = bondAmount.add(openFeePrice).add(openFeePrice); |
| | | log.info("预付款:{}", entrustTotalAmount); |
| | | |
| | | if (entrustTotalAmount.compareTo(walletContract.getAvailableBalance()) > -1) { |
| | | throw new GlobalException(MessageSourceUtils.getString("member_service_0085")); |
| | | } |
| | | |
| | | ContractEntrustOrderEntityMapper convert = ContractEntrustOrderEntityMapper.INSTANCE; |
| | | ContractEntrustOrderEntity entrustOrderEntity = convert.submitEntrustDtoToEntity(submitEntrustDto); |
| | | entrustOrderEntity.setOrderNo(commonService.generateOrderNo(memberEntity.getId())); |
| | | entrustOrderEntity.setMemberId(memberEntity.getId()); |
| | | entrustOrderEntity.setBondAmount(bondAmount.add(openFeePrice)); |
| | | entrustOrderEntity.setSymbolSku(lotNumber); |
| | | entrustOrderEntity.setEntrustAmount(entrustTotalAmount); |
| | | entrustOrderEntity.setPositionType(memberEntity.getContractPositionType()); |
| | | |
| | | int i = contractEntrustOrderDao.insert(entrustOrderEntity); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(entrustTotalAmount.negate(), null, entrustOrderEntity.getBondAmount(), walletContract.getId()); |
| | | if (i > 0) { |
| | | |
| | | // 发送委托单队列消息 |
| | | if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) { |
| | | OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买涨", "买涨:" + submitEntrustDto.getSymbol()); |
| | | } else { |
| | | OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买跌", "买跌:" + submitEntrustDto.getSymbol()); |
| | | } |
| | | |
| | | return Result.ok(MessageSourceUtils.getString("result_success_msg")); |
| | | } else { |
| | | return entrustForWhole(submitEntrustDto, memberEntity); |
| | | return Result.fail(MessageSourceUtils.getString("result_fail_msg")); |
| | | } |
| | | } |
| | | |
| | | return Result.fail(MessageSourceUtils.getString("result_fail_msg")); |
| | | } |
| | | |
| | | private Result entrustForAdd(SubmitEntrustDto submitEntrustDto, MemberEntity memberEntity) { |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(submitEntrustDto.getSymbol()); |
| | | PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); |
| | | |
| | | MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name()); |
| | | |
| | | // 保证金计算 -- 建仓价X规格X手数X(1/杠杆倍率) |
| | | BigDecimal bondAmount = CalculateUtil.getBondAmount(submitEntrustDto.getEntrustPrice(), lotNumber, submitEntrustDto.getSymbolCnt(), submitEntrustDto.getLeverRatio()); |
| | | |
| | | // 开仓手续费 建仓价*规格*手数*手续费率 |
| | | BigDecimal openFeePrice = CalculateUtil.getOpenFeePrice(submitEntrustDto.getEntrustPrice(), lotNumber, submitEntrustDto.getSymbolCnt(), tradeSettingEntity.getFeeRatio()); |
| | | log.info("手续费:{}", openFeePrice); |
| | | |
| | | // 预付款 |
| | | BigDecimal entrustTotalAmount = bondAmount.add(openFeePrice).add(openFeePrice); |
| | | log.info("预付款:{}", entrustTotalAmount); |
| | | |
| | | if (entrustTotalAmount.compareTo(walletContract.getAvailableBalance()) > -1) { |
| | | throw new GlobalException(MessageSourceUtils.getString("member_service_0085")); |
| | | } |
| | | |
| | | ContractEntrustOrderEntityMapper convert = ContractEntrustOrderEntityMapper.INSTANCE; |
| | | ContractEntrustOrderEntity entrustOrderEntity = convert.submitEntrustDtoToEntity(submitEntrustDto); |
| | | entrustOrderEntity.setOrderNo(commonService.generateOrderNo(memberEntity.getId())); |
| | | entrustOrderEntity.setMemberId(memberEntity.getId()); |
| | | entrustOrderEntity.setBondAmount(bondAmount.add(openFeePrice)); |
| | | entrustOrderEntity.setSymbolSku(lotNumber); |
| | | entrustOrderEntity.setEntrustAmount(entrustTotalAmount); |
| | | entrustOrderEntity.setPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD); |
| | | |
| | | int i = contractEntrustOrderDao.insert(entrustOrderEntity); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(entrustTotalAmount.negate(), null, entrustOrderEntity.getBondAmount(), walletContract.getId()); |
| | | if (i > 0) { |
| | | |
| | | // 发送委托单队列消息 |
| | | if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) { |
| | | OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买涨", "买涨:" + submitEntrustDto.getSymbol()); |
| | | } else { |
| | | OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买跌", "买跌:" + submitEntrustDto.getSymbol()); |
| | | } |
| | | |
| | | return Result.ok(MessageSourceUtils.getString("result_success_msg")); |
| | | } else { |
| | | return Result.fail(MessageSourceUtils.getString("result_fail_msg")); |
| | | } |
| | | } |
| | | |
| | | private Result entrustForWhole(SubmitEntrustDto submitEntrustDto, MemberEntity memberEntity) { |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(submitEntrustDto.getSymbol()); |
| | | PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); |
| | | |
| | | MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeConvert.convertContractTypeToCoin(submitEntrustDto.getSymbol())); |
| | | |
| | | ContractHoldOrderEntity holdOrderEntity = contractHoldOrderDao.selectWholeHoldOrderByOrderType(memberEntity.getId(), submitEntrustDto.getEntrustType(), submitEntrustDto.getSymbol()); |
| | | |
| | | BigDecimal bondAmount; |
| | | BigDecimal openFeePrice; |
| | | BigDecimal entrustTotalAmount; |
| | | |
| | | // 保证金计算 -- 建仓价X规格X手数X(1/杠杆倍率) |
| | | bondAmount = CalculateUtil.getBondAmount(submitEntrustDto.getEntrustPrice(), lotNumber, submitEntrustDto.getSymbolCnt(), submitEntrustDto.getLeverRatio()); |
| | | |
| | | // 开仓手续费 建仓价*规格*手数*手续费率 |
| | | openFeePrice = CalculateUtil.getOpenFeePrice(submitEntrustDto.getEntrustPrice(), lotNumber, submitEntrustDto.getSymbolCnt(), tradeSettingEntity.getFeeRatio()); |
| | | log.info("手续费:{}", openFeePrice); |
| | | |
| | | // 预付款 |
| | | entrustTotalAmount = bondAmount.add(openFeePrice).add(openFeePrice); |
| | | log.info("预付款:{}", entrustTotalAmount); |
| | | |
| | | if (entrustTotalAmount.compareTo(walletContract.getAvailableBalance()) > -1) { |
| | | throw new GlobalException(MessageSourceUtils.getString("member_service_0085")); |
| | | } |
| | | |
| | | ContractEntrustOrderEntityMapper convert = ContractEntrustOrderEntityMapper.INSTANCE; |
| | | ContractEntrustOrderEntity entrustOrderEntity = convert.submitEntrustDtoToEntity(submitEntrustDto); |
| | | entrustOrderEntity.setOrderNo(commonService.generateOrderNo(memberEntity.getId())); |
| | | entrustOrderEntity.setMemberId(memberEntity.getId()); |
| | | entrustOrderEntity.setBondAmount(bondAmount.add(openFeePrice)); |
| | | entrustOrderEntity.setSymbolSku(lotNumber); |
| | | entrustOrderEntity.setEntrustAmount(entrustTotalAmount); |
| | | entrustOrderEntity.setPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ALL); |
| | | |
| | | int i = contractEntrustOrderDao.insert(entrustOrderEntity); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(entrustTotalAmount.negate(), null, entrustOrderEntity.getBondAmount(), walletContract.getId()); |
| | | if (i > 0) { |
| | | |
| | | // 发送委托单队列消息 |
| | | if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) { |
| | | OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买涨", "买涨:" + submitEntrustDto.getSymbol()); |
| | | } else { |
| | | OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买跌", "买跌:" + submitEntrustDto.getSymbol()); |
| | | } |
| | | |
| | | return Result.ok(MessageSourceUtils.getString("result_success_msg")); |
| | | } else { |
| | | return Result.fail(MessageSourceUtils.getString("result_fail_msg")); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (entrustOrderEntity == null) { |
| | | return Result.fail(MessageSourceUtils.getString("entrust_order_not_exist")); |
| | | } |
| | | |
| | | MemberWalletContractEntity walletContractEntity; |
| | | if (ContractEntrustOrderEntity.POSITION_TYPE_ADD == entrustOrderEntity.getPositionType()) { |
| | | walletContractEntity = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), MemberWalletCoinEnum.WALLETCOINCODE.getValue()); |
| | | |
| | | BigDecimal total = entrustOrderEntity.getEntrustAmount(); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(total, null, entrustOrderEntity.getBondAmount().negate(), walletContractEntity.getId()); |
| | | |
| | | // 插入财务流水 |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), total, walletContractEntity.getAvailableBalance().add(total), entrustOrderEntity.getSymbol(), "撤销委托单", "撤销委托单"); |
| | | } else { |
| | | walletContractEntity = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeConvert.convertContractTypeToCoin(entrustOrderEntity.getSymbol())); |
| | | |
| | | memberWalletContractDao.increaseWalletContractBalanceById(entrustOrderEntity.getEntrustAmount(), null, entrustOrderEntity.getBondAmount().negate(), walletContractEntity.getId()); |
| | | } |
| | | |
| | | ContractOrderEntity orderEntity = ContractEntrustOrderEntityMapper.INSTANCE.entrustOrderToOrder(entrustOrderEntity); |
| | | orderEntity.setTradeType(ContractOrderEntity.TRADE_TYPE_MARK_PRICE); |
| | | orderEntity.setOrderStatus(ContractOrderEntity.ORDER_STATUS_CANCEL); |
| | |
| | | contractEntrustOrderDao.deleteById(entrustOrderEntity.getId()); |
| | | |
| | | if (i > 0) { |
| | | MemberWalletContractEntity walletContractEntity = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name()); |
| | | BigDecimal total = entrustOrderEntity.getEntrustAmount(); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(total, null, entrustOrderEntity.getBondAmount().negate(), walletContractEntity.getId()); |
| | | |
| | | // 插入财务流水 |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), total, walletContractEntity.getAvailableBalance().add(total), entrustOrderEntity.getSymbol(), "撤销委托单", "撤销委托单"); |
| | | |
| | | if (ContractEntrustOrderEntity.POSITION_TYPE_ALL == entrustOrderEntity.getPositionType()) { |
| | | ThreadPoolUtils.sendWholeForceClosingPrice(entrustOrderEntity.getSymbol(), memberEntity); |
| | | } |
| | | return Result.ok(MessageSourceUtils.getString("cancellation_success")); |
| | | } |
| | | return Result.fail(MessageSourceUtils.getString("cancellation_fail")); |
| | |
| | | closeType = ContractOrderEntity.ORDER_TYPE_CLOSE_LESS; |
| | | } |
| | | |
| | | |
| | | MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(member.getId(), CoinTypeConvert.convertContractTypeToCoin(holdOrderEntity.getSymbol())); |
| | | |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol()); |
| | | BigDecimal bondAmount = CalculateUtil.getBondAmount(holdOrderEntity.getOpeningPrice(), lotNumber, submitCloseEntrustDto.getSymbolCnt(), holdOrderEntity.getLeverRatio()); |
| | | |
| | |
| | | entrustOrder.setSymbol(holdOrderEntity.getSymbol()); |
| | | |
| | | int i = contractEntrustOrderDao.insert(entrustOrder); |
| | | |
| | | |
| | | // memberWalletContractDao.increaseWalletContractBalanceById(null, null, bondAmount, walletContract.getId()); |
| | | |
| | | if (i > 0) { |
| | | // 发送委托消息 |