src/main/java/com/xcong/excoin/common/enumerates/RabbitPriceTypeEnum.java
@@ -16,6 +16,8 @@ */ ENTRUST_OPEN_MORE(2) , ENTRUST_OPEN_LESS(3) , CLOSE_MORE_BOMB(6) , CLOSE_LESS_BOMB(7) , CLOSE_MORE_STOP_PROFIT(9) , CLOSE_LESS_STOP_PROFIT(10) , CLOSE_MORE_STOP_LESS(11) src/main/java/com/xcong/excoin/modules/contract/controller/ContractOrderController.java
@@ -1,6 +1,7 @@ package com.xcong.excoin.modules.contract.controller; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.contract.parameter.dto.ChangeBondDto; import com.xcong.excoin.modules.contract.parameter.dto.ProfitOrLessDto; import com.xcong.excoin.modules.contract.parameter.dto.SubmitOrderDto; import com.xcong.excoin.modules.contract.parameter.vo.HoldOrderListVo; @@ -63,16 +64,16 @@ return contractHoldOrderService.cancelHoldOrderBatch(); } @ApiOperation(value = "未完成--设置止盈止损") @ApiOperation(value = "设置止盈止损") @PostMapping(value = "/setTargetProfitOrLoss") public Result setTargetProfitOrLoss(@RequestBody @Validated ProfitOrLessDto profitOrLessDto) { return null; return contractHoldOrderService.setTargetProfitOrLess(profitOrLessDto); } @ApiOperation(value = "未完成--调整保证金") @PostMapping(value = "/tuneUpBond") public Result tuneUpBond() { return null; @ApiOperation(value = "调整保证金") @PostMapping(value = "/changeBond") public Result changeBond(ChangeBondDto changeBondDto) { return contractHoldOrderService.changeBond(changeBondDto); } @ApiOperation(value = "未完成--分页查询历史订单列表") src/main/java/com/xcong/excoin/modules/contract/parameter/dto/ChangeBondDto.java
New file @@ -0,0 +1,35 @@ package com.xcong.excoin.modules.contract.parameter.dto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import java.math.BigDecimal; /** * @author wzy * @date 2020-06-02 **/ @Data @ApiModel(value = "ChangeBondDto", description = "调整保证金接口接受参数类") public class ChangeBondDto { public static final int TYPE_ADD = 1; public static final int TYPE_REDUCE = 2; @NotNull @ApiModelProperty(value = "订单ID", example = "1") private Long id; @NotNull @ApiModelProperty(value = "类型 1-增加2-减少", example = "1") private Integer type; @NotNull @Min(0) @ApiModelProperty(value = "金额", example = "90.00") private BigDecimal amount; } src/main/java/com/xcong/excoin/modules/contract/service/ContractHoldOrderService.java
@@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity; import com.xcong.excoin.modules.contract.parameter.dto.ChangeBondDto; import com.xcong.excoin.modules.contract.parameter.dto.ProfitOrLessDto; import com.xcong.excoin.modules.contract.parameter.dto.SubmitOrderDto; import com.xcong.excoin.rabbit.pricequeue.OrderModel; @@ -31,4 +32,6 @@ public Result setTargetProfitOrLess(ProfitOrLessDto profitOrLessDto); public Result changeBond(ChangeBondDto changeBondDto); } src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
@@ -15,6 +15,7 @@ import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity; import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; import com.xcong.excoin.modules.contract.mapper.ContractHoldOrderEntityMapper; import com.xcong.excoin.modules.contract.parameter.dto.ChangeBondDto; import com.xcong.excoin.modules.contract.parameter.dto.ProfitOrLessDto; import com.xcong.excoin.modules.contract.parameter.dto.SubmitOrderDto; import com.xcong.excoin.modules.contract.parameter.vo.HoldOrderListVo; @@ -378,4 +379,56 @@ return Result.fail("设置失败"); } @Transactional(rollbackFor = Exception.class) @Override public Result changeBond(ChangeBondDto changeBondDto) { MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); ContractHoldOrderEntity holdOrderEntity = contractHoldOrderDao.selectHoldOrderByMemberIdAndId(memberEntity.getId(), changeBondDto.getId()); if (holdOrderEntity == null) { return Result.fail("订单不存在"); } MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name()); // 增加保证金 if (ChangeBondDto.TYPE_ADD == changeBondDto.getType()) { if (changeBondDto.getAmount().compareTo(walletContract.getAvailableBalance()) > 0) { return Result.fail("可用余额不足"); } walletContract.setAvailableBalance(walletContract.getAvailableBalance().subtract(changeBondDto.getAmount())); walletContract.setFrozenBalance(walletContract.getFrozenBalance().add(changeBondDto.getAmount())); holdOrderEntity.setBondAmount(holdOrderEntity.getBondAmount().add(changeBondDto.getAmount())); // 减少保证金 } else { if (holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getPrePaymentAmount()).subtract(changeBondDto.getAmount()).compareTo(BigDecimal.ZERO) < 0) { return Result.fail("超出保证金最大减少金额"); } walletContract.setAvailableBalance(walletContract.getAvailableBalance().add(changeBondDto.getAmount())); walletContract.setFrozenBalance(walletContract.getFrozenBalance().subtract(changeBondDto.getAmount())); holdOrderEntity.setBondAmount(holdOrderEntity.getBondAmount().subtract(changeBondDto.getAmount())); } BigDecimal forceClosingPrice = CalculateUtil.getForceSetPrice(holdOrderEntity.getBondAmount(), holdOrderEntity.getOpeningPrice(), holdOrderEntity.getSymbolCnt(), holdOrderEntity.getSymbolSku(), holdOrderEntity.getOpeningType(), memberEntity); holdOrderEntity.setForceClosingPrice(forceClosingPrice); holdOrderEntity.setOperateNo(holdOrderEntity.getOperateNo() + 1); int i = contractHoldOrderDao.updateById(holdOrderEntity); int j = memberWalletContractDao.updateById(walletContract); OrderModel model = null; // 开多 if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.toPlainString(), holdOrderEntity.getSymbol()); // 开空 } else { model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.toPlainString(), holdOrderEntity.getSymbol()); } producer.sendPriceOperate(JSONObject.toJSONString(model)); if (i > 0 && j > 0) { return Result.ok("调整成功"); } return Result.fail("调整失败"); } }