| | |
| | | MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name()); |
| | | |
| | | PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); |
| | | BigDecimal spread = memberEntity.getSpread(); |
| | | |
| | | Long id = memberEntity.getId(); |
| | | MemberEntity selectById = memberDao.selectById(id); |
| | | BigDecimal spread = selectById.getSpread(); |
| | | // 规格 |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(submitOrderDto.getSymbol()); |
| | | |
| | |
| | | holdOrderEntity.setIsCanClosing(ContractHoldOrderEntity.ORDER_CAN_CLOSING_Y); |
| | | holdOrderEntity.setPrePaymentAmount(prePaymentAmount); |
| | | holdOrderEntity.setBondAmount(bondAmount.add(openFeePrice)); |
| | | holdOrderEntity.setOperateNo(1); |
| | | |
| | | ContractOrderEntity contractOrderEntity = ContractHoldOrderEntityMapper.INSTANCE.holdOrderToOrder(holdOrderEntity); |
| | | contractOrderEntity.setOpeningTime(new Date()); |
| | | contractHoldOrderDao.insert(holdOrderEntity); |
| | | int i = contractOrderDao.insert(contractOrderEntity); |
| | | |
| | | if (i > 0) { |
| | | memberWalletContractDao.increaseWalletContractBalanceById(prePaymentAmount.negate(), openFeePrice.negate(), null, walletContract.getId()); |
| | | |
| | | // 发送爆仓消息 |
| | | sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo()); |
| | | |
| | | // 计算佣金 |
| | | ThreadPoolUtils.calReturnMoney(memberEntity.getId(), contractOrderEntity.getOpeningFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN); |
| | | |
| | | // 插入财务流水 |
| | | if (submitOrderDto.getOrderType() == ContractHoldOrderEntity.OPENING_TYPE_MORE) { |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), prePaymentAmount, walletContract.getAvailableBalance().subtract(prePaymentAmount), submitOrderDto.getSymbol(), "买涨持仓", "买涨:" + submitOrderDto.getSymbol()); |
| | | } else { |
| | | LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), prePaymentAmount, walletContract.getAvailableBalance().subtract(prePaymentAmount), submitOrderDto.getSymbol(), "买跌持仓", "买跌:" + submitOrderDto.getSymbol()); |
| | | } |
| | | return Result.ok("提交成功"); |
| | | } |
| | | return Result.fail("提交失败"); |
| | |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("hold", resultList); |
| | | result.put("totalProfitOrLoss", totalProfitOrLoss); |
| | | result.put("totalProfitOrLoss", totalProfitOrLoss.setScale(4, BigDecimal.ROUND_DOWN).toPlainString()); |
| | | return Result.ok(result); |
| | | } |
| | | return Result.ok("success"); |
| | |
| | | // 开多止盈 |
| | | if (stopProfitPrice != null) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | } |
| | | // 开多止损 |
| | | if (stopLessPrice != null) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | } |
| | | } else { |
| | | // 开空止盈 |
| | | if (stopProfitPrice != null) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | } |
| | | // 开空止损 |
| | | if (stopLessPrice != null) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | } |
| | | } |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | return Result.ok("设置成功"); |
| | | } |
| | | return Result.fail("设置失败"); |
| | |
| | | if (changeBondDto.getAmount().compareTo(walletContract.getAvailableBalance()) > 0) { |
| | | return Result.fail("可用余额不足"); |
| | | } |
| | | memberWalletContractDao.increaseWalletContractBalanceById(changeBondDto.getAmount().negate(), null, changeBondDto.getAmount(), walletContract.getId()); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(changeBondDto.getAmount().negate(), null, null, walletContract.getId()); |
| | | holdOrderEntity.setBondAmount(holdOrderEntity.getBondAmount().add(changeBondDto.getAmount())); |
| | | // 减少保证金 |
| | | } else { |
| | | if (holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getPrePaymentAmount()).subtract(changeBondDto.getAmount()).compareTo(BigDecimal.ZERO) < 0) { |
| | | return Result.fail("超出保证金最大减少金额"); |
| | | } |
| | | memberWalletContractDao.increaseWalletContractBalanceById(changeBondDto.getAmount(), null, changeBondDto.getAmount().negate(), walletContract.getId()); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(changeBondDto.getAmount(), null, null, walletContract.getId()); |
| | | holdOrderEntity.setBondAmount(holdOrderEntity.getBondAmount().subtract(changeBondDto.getAmount())); |
| | | } |
| | | |
| | |
| | | int i = contractHoldOrderDao.updateById(holdOrderEntity); |
| | | |
| | | if (i > 0) { |
| | | OrderModel model = null; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | // 开空 |
| | | } else { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | } |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | // 发送爆仓消息 |
| | | sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo()); |
| | | return Result.ok("调整成功"); |
| | | } |
| | | return Result.fail("调整失败"); |
| | |
| | | BigDecimal profitOrLess = BigDecimal.ZERO; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | profitOrLess = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber).multiply(holdOrderEntity.getSymbolSku()); |
| | | profitOrLess = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber); |
| | | // 开空 |
| | | } else { |
| | | profitOrLess = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber).multiply(holdOrderEntity.getSymbolSku()); |
| | | profitOrLess = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber); |
| | | } |
| | | |
| | | if (MemberEntity.IS_PROFIT_Y == memberEntity.getIsProfit()) { |
| | |
| | | } |
| | | |
| | | HoldOrderDetailVo holdOrderDetailVo = ContractHoldOrderEntityMapper.INSTANCE.holdOrderToOrderDetailVo(holdOrderEntity); |
| | | BigDecimal feeSpread = cacheSettingUtils.getTradeSetting().getFeeSpreadRatio(); |
| | | // holdOrderDetailVo.setOpeningFeeAmount(holdOrderDetailVo.getOpeningFeeAmount().multiply(feeSpread).setScale(8, BigDecimal.ROUND_DOWN)); |
| | | holdOrderDetailVo.setOpeningFeeAmount(holdOrderEntity.getOpeningFeeAmount(), feeSpread); |
| | | return Result.ok(holdOrderDetailVo); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | OrderDetailVo orderDetailVo = ContractOrderEntityMapper.INSTANCE.entityToDetailVo(contractOrderEntity); |
| | | BigDecimal feeSpread = cacheSettingUtils.getTradeSetting().getFeeSpreadRatio(); |
| | | // orderDetailVo.setClosingFeeAmount(orderDetailVo.getClosingFeeAmount() == null ? orderDetailVo.getClosingFeeAmount() : orderDetailVo.getClosingFeeAmount().multiply(feeSpread).setScale(8, BigDecimal.ROUND_DOWN)); |
| | | // orderDetailVo.setOpeningFeeAmount(orderDetailVo.getOpeningFeeAmount() == null ? orderDetailVo.getOpeningFeeAmount() : orderDetailVo.getOpeningFeeAmount().multiply(feeSpread).setScale(8, BigDecimal.ROUND_DOWN)); |
| | | orderDetailVo.setOpeningFeeAmount(contractOrderEntity.getOpeningFeeAmount(), feeSpread); |
| | | orderDetailVo.setClosingFeeAmount(contractOrderEntity.getClosingFeeAmount(), feeSpread); |
| | | return Result.ok(orderDetailVo); |
| | | } |
| | | |
| | |
| | | holdOrderEntity.setOperateNo(holdOrderEntity.getOperateNo() + 1); |
| | | contractHoldOrderDao.updateById(holdOrderEntity); |
| | | |
| | | OrderModel model = null; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), newForcePrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | // 开空 |
| | | } else { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), newForcePrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | } |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | // 发送爆仓消息 |
| | | sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), newForcePrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void sendOrderBombMsg(Long id, int type, BigDecimal forceClosingPrice, String symbol, int operateNo) { |
| | | OrderModel model = null; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == type) { |
| | | model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo); |
| | | // 开空 |
| | | } else { |
| | | model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo); |
| | | } |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | } |
| | | } |