| | |
| | | } |
| | | |
| | | if (!priceServices.isLimitUpBuy(stock.getStockCode())) { |
| | | return ServerResponse.createByErrorMsg("股票涨停,无法购买", request); |
| | | return ServerResponse.createByErrorMsg("暂无配额", request); |
| | | } |
| | | |
| | | //股票类型 现价 数据源的处理 |
| | |
| | | return ServerResponse.createByErrorMsg("该新股不存在"); |
| | | } |
| | | if (userStockSubscribe.getStatus() == 4 || userStockSubscribe.getStatus() == 3 && stockSubscribe.getType() == 2) { |
| | | Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockSpell, userStockSubscribe.getNewCode())); |
| | | Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, userStockSubscribe.getNewCode())); |
| | | if(null == stock){ |
| | | return ServerResponse.createByErrorMsg("该新股不存在"); |
| | | } |
| | |
| | | Result result = getResult(position); |
| | | if (result == null) continue; |
| | | |
| | | //利润为0不需要进行强制平仓 |
| | | if(result.signum == 0){ |
| | | continue; |
| | | } |
| | | boolean liquidation = false; |
| | | liquidation = isLiquidation(position, result.signum, result.profit, liquidation); |
| | | if(liquidation){ |
| | |
| | | } |
| | | |
| | | // 检查是否在交易时间内 |
| | | if (!tradingHourService.timeCheck(position.getStockCode())) { |
| | | log.info("不在交易时间之内,订单id: {}", position.getId()); |
| | | return null; |
| | | } |
| | | // if (!tradingHourService.timeCheck(position.getStockCode())) { |
| | | // log.info("不在交易时间之内,订单id: {}", position.getId()); |
| | | // return null; |
| | | // } |
| | | |
| | | //判断订单 |
| | | if (1 == position.getIsLock().intValue()) { |
| | |
| | | |
| | | // 检查股票是否垫停 |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", position.getStockCode())); |
| | | if (!priceServices.isLimitDownSell(stock.getStockCode())) { |
| | | log.info("股票跌停,无法平仓,订单id: {}", position.getId()); |
| | | return null; |
| | | } |
| | | // if (!priceServices.isLimitDownSell(stock.getStockCode())) { |
| | | // log.info("股票跌停,无法平仓,订单id: {}", position.getId()); |
| | | // return null; |
| | | // } |
| | | |
| | | //最新报价 |
| | | BigDecimal nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | if (nowPrice.compareTo(BigDecimal.ZERO) <= 0) { |
| | | log.info("报价0,平仓失败,订单id: {}", position.getId()); |
| | | return null; |
| | | } |
| | | // if (nowPrice.compareTo(BigDecimal.ZERO) <= 0) { |
| | | // log.info("报价0,平仓失败,订单id: {}", position.getId()); |
| | | // return null; |
| | | // } |
| | | |
| | | //判断订单是否已到强制平仓价格 |
| | | BigDecimal purchaseAmount = position.getBuyOrderPrice().multiply(new BigDecimal(position.getOrderNum()));// 买入价总额 |
| | |
| | | } |
| | | |
| | | //判断平仓 |
| | | private static boolean isLiquidation(UserPosition position, int signum, BigDecimal profit, boolean liquidation) { |
| | | private boolean isLiquidation(UserPosition position, int signum, BigDecimal profit, boolean liquidation) { |
| | | //最新报价 |
| | | BigDecimal nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | if(position.getOrderDirection().equals("买涨")){ |
| | | //判断亏损金额是否达到保证金金额 |
| | | BigDecimal negate = profit.negate(); |
| | | //如果买涨 signum 为-1则表示亏损 |
| | | if(signum == -1){ |
| | | //判断亏损金额是否达到保证金金额 |
| | | BigDecimal negate = profit.negate(); |
| | | if (negate.compareTo(position.getOrderTotalPrice()) >= 0){ |
| | | //止损 |
| | | if(null != position.getStopTargetPrice() && nowPrice.compareTo(position.getStopTargetPrice()) <= 0){ |
| | | //强制平仓 |
| | | liquidation = true; |
| | | return liquidation = true; |
| | | } |
| | | if (negate.compareTo(position.getOrderTotalPrice()) >= 0){//亏平强平 |
| | | //强制平仓 |
| | | return liquidation = true; |
| | | } |
| | | }else{ |
| | | //止盈 |
| | | if(null != position.getProfitTargetPrice() && nowPrice.compareTo(position.getProfitTargetPrice()) >= 0){ |
| | | //强制平仓 |
| | | return liquidation = true; |
| | | } |
| | | } |
| | | }else{ |
| | | //买跌 signum |
| | | if(signum == 1){ |
| | | //判断亏损金额是否达到保证金金额 |
| | | if (profit.compareTo(position.getOrderTotalPrice()) >= 0){ |
| | | //止损 |
| | | if(null != position.getStopTargetPrice() && nowPrice.compareTo(position.getStopTargetPrice()) >= 0){ |
| | | //强制平仓 |
| | | liquidation = true; |
| | | return liquidation = true; |
| | | } |
| | | //判断亏损金额是否达到保证金金额 |
| | | if (profit.compareTo(position.getOrderTotalPrice()) >= 0){//亏平强平 |
| | | //强制平仓 |
| | | return liquidation = true; |
| | | } |
| | | }else{ |
| | | //止盈 |
| | | if(null != position.getProfitTargetPrice() && nowPrice.compareTo(position.getProfitTargetPrice()) <= 0){ |
| | | //强制平仓 |
| | | return liquidation = true; |
| | | } |
| | | } |
| | | } |