| | |
| | | @Transactional |
| | | public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) throws Exception { |
| | | |
| | | // 判断周末不能买 |
| | | // Date today = new Date(); |
| | | // Calendar c = Calendar.getInstance(); |
| | | // c.setTime(today); |
| | | /*实名认证开关开启*/ |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("Order failed, account has been locked"); |
| | | } |
| | | |
| | | SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting(); |
| | | if (siteSetting == null) { |
| | | log.error("下单出错,网站设置表不存在"); |
| | |
| | | if (stock == null) { |
| | | return ServerResponse.createByErrorMsg("Order failed, stock code error"); |
| | | } |
| | | |
| | | // if (Objects.equals(stock.getStockType(), EStockType.US.getCode())) { |
| | | // if (buyNum < siteSetting.getDzMinByCount()) { |
| | | // return ServerResponse.createByErrorMsg("Minimum purchase for bulk commodities " + siteSetting.getDzMinByCount()); |
| | | // } |
| | | // String am_begin = siteSetting.getTransAmBeginUs(); |
| | | // String am_end = siteSetting.getTransAmEndUs(); |
| | | // String pm_begin = siteSetting.getTransPmBeginUs(); |
| | | // String pm_end = siteSetting.getTransPmEndUs(); |
| | | // boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | // boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | // log.info("是否在上午交易时间 = {} 是否在下午交易时间 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag)); |
| | | // if (!am_flag && !pm_flag) { |
| | | // return ServerResponse.createByErrorMsg("Order failed, not in the stock trading session"); |
| | | // } |
| | | // } else { |
| | | // String am_begin = siteSetting.getTransAmBegin(); |
| | | // String am_end = siteSetting.getTransAmEnd(); |
| | | // String pm_begin = siteSetting.getTransPmBegin(); |
| | | // String pm_end = siteSetting.getTransPmEnd(); |
| | | // boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | // boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | // if (!am_flag && !pm_flag) { |
| | | // return ServerResponse.createByErrorMsg("Order failed, out of trading hours"); |
| | | // } |
| | | // if (siteProduct.getHolidayDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("No trading on weekends or holidays!"); |
| | | // } |
| | | // } |
| | | //判断股票是否在可交易时间段 |
| | | Boolean b = tradingHourService.timeCheck(); |
| | | if (!b) { |
| | |
| | | } |
| | | |
| | | |
| | | if (stock.getIsLock().intValue() != 0) { |
| | | if (stock.getIsLock() != 0) { |
| | | return ServerResponse.createByErrorMsg("Order failed, shares cannot be traded at present"); |
| | | } |
| | | |
| | | List dbPosition = findPositionByStockCodeAndTimes(siteSetting.getBuySameTimes().intValue(), stock |
| | | .getStockCode(), user.getId()); |
| | | if (dbPosition.size() >= siteSetting.getBuySameNums().intValue()) { |
| | | return ServerResponse.createByErrorMsg("Frequent trading," + siteSetting.getBuySameTimes() + "Hold no more than one stock within a minute" + siteSetting |
| | | .getBuySameNums() + "article"); |
| | | } |
| | | |
| | | Integer transNum = findPositionNumByTimes(siteSetting.getBuyNumTimes().intValue(), user.getId()); |
| | | if (transNum.intValue() / 100 >= siteSetting.getBuyNumLots().intValue()) { |
| | | return ServerResponse.createByErrorMsg("Frequent trading," + siteSetting |
| | | .getBuyNumTimes() + "Hold no more than one stock within a minute" + siteSetting.getBuyNumLots() + "hand"); |
| | | } |
| | | |
| | | if (buyNum.intValue() < siteSetting.getBuyMinNum().intValue()) { |
| | | return ServerResponse.createByErrorMsg("Order failed, purchase quantity is less than" + siteSetting |
| | | .getBuyMinNum() ); |
| | | } |
| | | if (buyNum.intValue() > siteSetting.getBuyMaxNum().intValue()) { |
| | | return ServerResponse.createByErrorMsg("Order failed, purchase quantity is greater than于" + siteSetting |
| | | .getBuyMaxNum() + "stocks"); |
| | | } |
| | | BigDecimal now_price; |
| | | //股票类型 现价 数据源的处理 |
| | | StockListVO stockListVO = StockApi.getStockRealTime(stock); |