| | |
| | | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | |
| | | |
| | | @Autowired |
| | | UserPositionCheckDzService userPositionCheckDzService; |
| | | @Autowired |
| | | UserPendingorderMapper userPendingorderMapper; |
| | | |
| | | |
| | | |
| | | @Transactional |
| | | public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) { |
| | | public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget,BigDecimal preMarketPrice, HttpServletRequest request) { |
| | | |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | |
| | | if (stopTarget != null && stopTarget.compareTo(new BigDecimal("0")) > 0) { |
| | | userPosition.setStopTargetPrice(stopTarget); |
| | | } |
| | | userPosition.setPositionType(user.getAccountType()); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(user.getId()); |
| | | userPosition.setNickName(user.getRealName()); |
| | | userPosition.setAgentId(user.getAgentId()); |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockName(stock.getStockName()); |
| | | userPosition.setStockGid(stock.getStockType()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(nowPrice); |
| | | userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌"); |
| | | userPosition.setOrderNum(buyNum); |
| | | if (stock.getStockPlate() != null) { |
| | | userPosition.setStockPlate(stock.getStockPlate()); |
| | | } |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setOrderLever(lever); |
| | | userPosition.setOrderTotalPrice(buyAmt); |
| | | // 手续费 |
| | | //判断是否盘前,和价格 |
| | | StockSetting stockSetting = tradingHourService.preMarketPrice(stock.getStockCode()); |
| | | if(null != preMarketPrice && preMarketPrice.compareTo(new BigDecimal(0)) > 0 && null != stockSetting && preMarketPrice.compareTo(new BigDecimal(stockSetting.getPrice())) != 0){ |
| | | //挂单 |
| | | UserPendingorder userPendingorder = new UserPendingorder(); |
| | | userPendingorder.setUserId(user.getId()); |
| | | userPendingorder.setStockId(String.valueOf(stockId)); |
| | | userPendingorder.setBuyNum(buyNum); |
| | | userPendingorder.setBuyType(buyType); |
| | | userPendingorder.setLever(lever); |
| | | userPendingorder.setProfitTarget(profitTarget); |
| | | userPendingorder.setStopTarget(stopTarget); |
| | | userPendingorder.setNowPrice(new BigDecimal(0)); |
| | | userPendingorder.setTargetPrice(preMarketPrice); |
| | | userPendingorder.setAddTime(new Date()); |
| | | userPendingorder.setStatus(0); |
| | | userPendingorder.setBuyAmt(preMarketPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever))); |
| | | int ret = userPendingorderMapper.insert(userPendingorder); |
| | | buyAmt = userPendingorder.getBuyAmt(); |
| | | orderFree = siteSettingBuyFee.multiply(buyAmt); |
| | | }else { |
| | | userPosition.setPositionType(user.getAccountType()); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(user.getId()); |
| | | userPosition.setNickName(user.getRealName()); |
| | | userPosition.setAgentId(user.getAgentId()); |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockName(stock.getStockName()); |
| | | userPosition.setStockGid(stock.getStockType()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(null == preMarketPrice ? nowPrice : preMarketPrice); |
| | | userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌"); |
| | | userPosition.setOrderNum(buyNum); |
| | | if (stock.getStockPlate() != null) { |
| | | userPosition.setStockPlate(stock.getStockPlate()); |
| | | } |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setOrderLever(lever); |
| | | userPosition.setOrderTotalPrice(buyAmt); |
| | | // 手续费 |
| | | |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | |
| | | } |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |