| | |
| | | BigDecimal enable_user_amt = user.getEnableAmt(); |
| | | BigDecimal all_freez_amt = new BigDecimal("0"); |
| | | for (UserPosition position : userPositions) { |
| | | // PositionProfitVO positionProfitVO = iUserPositionService.getPositionProfitVO(position); |
| | | // if (positionProfitVO == null) { |
| | | // continue; |
| | | // } |
| | | |
| | | StockListVO stockListVO = new StockListVO(); |
| | | stockListVO=SinaStockApi.assembleLideStockListVO(LiDeDataUtils.getStock(position.getStockCode())); |
| | | if(org.springframework.util.ObjectUtils.isEmpty(stockListVO)){ |
| | | stockListVO = SinaStockApi.assembleStockListVO(SinaStockApi.getSinaStock(position.getStockGid())); |
| | | } |
| | | if (stockListVO == null) { |
| | | if (position.getStatus() != null && position.getStatus().intValue() == 0) { |
| | | continue; |
| | | } |
| | | |
| | | if(position.getProfitTargetPrice()!=null && position.getProfitTargetPrice().compareTo(new BigDecimal(stockListVO.getNowPrice())) <= 0 ||position.getStopTargetPrice() != null && position.getStopTargetPrice().compareTo(new BigDecimal(stockListVO.getNowPrice())) >= 0) { |
| | | StockListVO stockListVO = SinaStockApi.assembleLideStockListVO(LiDeDataUtils.getStock(position.getStockCode())); |
| | | if(org.springframework.util.ObjectUtils.isEmpty(stockListVO)){ |
| | | stockListVO = SinaStockApi.assembleStockListVO(SinaStockApi.getSinaStock(position.getStockGid())); |
| | | } |
| | | if (stockListVO == null || stockListVO.getNowPrice() == null) { |
| | | continue; |
| | | } |
| | | BigDecimal nowPrice; |
| | | try { |
| | | nowPrice = new BigDecimal(stockListVO.getNowPrice()); |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | |
| | | if (!shouldForceSellByProfitStop(position, nowPrice)) { |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | this.iUserPositionService.sell(position.getPositionSn(), 0); |
| | | ServerResponse sellResult = this.iUserPositionService.sell(position.getPositionSn(), 0); |
| | | if (sellResult != null && !sellResult.isSuccess()) { |
| | | log.warn("[止盈止损强平] positionSn={} 失败: {}", position.getPositionSn(), sellResult.getMsg()); |
| | | continue; |
| | | } |
| | | SiteTaskLog siteTaskLog = new SiteTaskLog(); |
| | | siteTaskLog.setTaskType("单股止盈止损强平任务-股票持仓"); |
| | | String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户"; |
| | |
| | | log.info("[盈利达到目标盈利]保存强制平仓task任务失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("[盈利达到目标盈利]强制平仓失败..."); |
| | | } |
| | | |
| | | log.error("[盈利达到目标盈利]强制平仓失败 positionSn={}", position.getPositionSn(), e); |
| | | } |
| | | |
| | | } |
| | | log.info("=========止盈止损定时任务============"); |
| | | } |
| | | } |
| | | |
| | | /** 买涨:现价>=止盈 或 现价<=止损;买跌:现价<=止盈 或 现价>=止损 */ |
| | | private boolean shouldForceSellByProfitStop(UserPosition position, BigDecimal nowPrice) { |
| | | if (position == null || nowPrice == null || nowPrice.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return false; |
| | | } |
| | | BigDecimal profitTarget = position.getProfitTargetPrice(); |
| | | BigDecimal stopTarget = position.getStopTargetPrice(); |
| | | boolean hasProfit = profitTarget != null && profitTarget.compareTo(BigDecimal.ZERO) > 0; |
| | | boolean hasStop = stopTarget != null && stopTarget.compareTo(BigDecimal.ZERO) > 0; |
| | | if (!hasProfit && !hasStop) { |
| | | return false; |
| | | } |
| | | boolean isLong = !"买跌".equals(position.getOrderDirection()); |
| | | if (isLong) { |
| | | if (hasProfit && nowPrice.compareTo(profitTarget) >= 0) { |
| | | return true; |
| | | } |
| | | return hasStop && nowPrice.compareTo(stopTarget) <= 0; |
| | | } |
| | | if (hasProfit && nowPrice.compareTo(profitTarget) <= 0) { |
| | | return true; |
| | | } |
| | | return hasStop && nowPrice.compareTo(stopTarget) >= 0; |
| | | } |
| | | /*用户股票持仓单-强平提醒推送消息定时*/ |
| | | public void ForceSellMessageTask() { |
| | | List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList(); |