| | |
| | | BigDecimal ztRate = chaPrice.multiply(new BigDecimal("100")).divide(zsPrice, 2, 4); |
| | | |
| | | log.info("当前涨跌幅 = {} % , 涨停幅度 = {} %", Double.valueOf(stock_crease), ztRate); |
| | | if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && buyType |
| | | .intValue() == 0) { |
| | | return ServerResponse.createByErrorMsg("当前股票已涨停不能买涨"); |
| | | } |
| | | // if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && buyType |
| | | // .intValue() == 0) { |
| | | // return ServerResponse.createByErrorMsg("当前股票已涨停不能买涨"); |
| | | // } |
| | | |
| | | |
| | | if (stock.getStockPlate() == null || StringUtils.isEmpty(stock.getStockPlate())) { |
| | |
| | | } |
| | | |
| | | |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt); |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt_autual); |
| | | BigDecimal buy_debit = TradeFeeUtil.calcBuyDebit(buy_amt_autual, buy_fee_amt); |
| | | int compareUserAmtInt = user_enable_amt.compareTo(buy_debit); |
| | | log.info("用户可用金额 = {} 下单扣款(保证金+手续费) = {}", user_enable_amt, buy_debit); |
| | |
| | | |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | userPosition.setStatus(1); |
| | | |
| | | this.userPositionMapper.insert(userPosition); |
| | | if (userPosition.getId() != null && userPosition.getId() > 0) { |
| | |
| | | |
| | | |
| | | @Override |
| | | public ServerResponse fee(Integer buyNum, BigDecimal nowPrice) { |
| | | public ServerResponse fee(Integer buyNum, BigDecimal nowPrice, Integer lever) { |
| | | int leverValue = (lever == null || lever <= 0) ? 1 : lever; |
| | | BigDecimal buy_amt = nowPrice.multiply(new BigDecimal(buyNum.intValue())); |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt).setScale(2, 4); |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFeeByNotional(buy_amt, leverValue).setScale(2, 4); |
| | | return ServerResponse.createBySuccess(buy_fee_amt); |
| | | } |
| | | |
| | |
| | | .getBuyMaxAmtPercent().multiply(new BigDecimal("100")) + "%"); |
| | | } |
| | | |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt); |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt_autual); |
| | | BigDecimal buy_debit = TradeFeeUtil.calcBuyDebit(buy_amt_autual, buy_fee_amt); |
| | | if (user_enable_amt.compareTo(buy_debit) == -1) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,融资可用金额小于" + buy_debit + "元(含保证金及手续费)"); |
| | |
| | | } |
| | | |
| | | |
| | | private ServerResponse validateT1BeforeSell(UserPosition userPosition, int doType) { |
| | | if (doType == 0 || userPosition == null || userPosition.getBuyOrderTime() == null) { |
| | | return null; |
| | | } |
| | | String stockGid = userPosition.getStockGid(); |
| | | if (stockGid != null && (stockGid.contains("us") || stockGid.contains("hk"))) { |
| | | return null; |
| | | } |
| | | if (!DateTimeUtil.canSellByT1(userPosition.getBuyOrderTime())) { |
| | | return ServerResponse.createByErrorMsg("T+1交易制度,当日买入的股票需下一交易日才能平仓"); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private ServerResponse validateTransTimeBeforeSell(UserPosition userPosition, SiteSetting siteSetting) throws Exception { |
| | | if (userPosition == null || siteSetting == null) { |
| | | return null; |
| | | } |
| | | String stockGid = userPosition.getStockGid(); |
| | | boolean inSession; |
| | | if (stockGid != null && stockGid.contains("us")) { |
| | | inSession = BuyAndSellUtils.isInTransSession( |
| | | siteSetting.getTransAmBeginUs(), siteSetting.getTransAmEndUs(), |
| | | siteSetting.getTransPmBeginUs(), siteSetting.getTransPmEndUs()); |
| | | } else if (stockGid != null && stockGid.contains("hk")) { |
| | | inSession = BuyAndSellUtils.isInTransSession( |
| | | siteSetting.getTransAmBeginhk(), siteSetting.getTransAmEndhk(), |
| | | siteSetting.getTransPmBeginhk(), siteSetting.getTransPmEndhk()); |
| | | } else { |
| | | inSession = BuyAndSellUtils.isInTransSession( |
| | | siteSetting.getTransAmBegin(), siteSetting.getTransAmEnd(), |
| | | siteSetting.getTransPmBegin(), siteSetting.getTransPmEnd()); |
| | | } |
| | | if (!inSession) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内"); |
| | | } |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | if (siteProduct != null && siteProduct.getHolidayDisplay()) { |
| | | return ServerResponse.createByErrorMsg("周末或节假日不能交易!"); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public ServerResponse sell(String positionSn, int doType) throws Exception { |
| | | log.info("【用戶交易平倉】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType)); |
| | | |
| | |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | if (doType != 0) { |
| | | if (userPosition.getStockGid().contains("us")) { |
| | | 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("下单失败,系统设置错误"); |
| | | } |
| | | } else if (userPosition.getStockGid().contains("hk")) { |
| | | String am_begin = siteSetting.getTransAmBeginhk(); |
| | | String am_end = siteSetting.getTransAmEndhk(); |
| | | String pm_begin = siteSetting.getTransPmBeginhk(); |
| | | String pm_end = siteSetting.getTransPmEndhk(); |
| | | 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("下單失敗,不在港股股交易時段內"); |
| | | } |
| | | } 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); |
| | | log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag)); |
| | | |
| | | if (!am_flag && !pm_flag && siteProduct.getTranWithdrawDisplay()) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内"); |
| | | } |
| | | } |
| | | if (siteProduct.getHolidayDisplay() && siteProduct.getTranWithdrawDisplay()) { |
| | | return ServerResponse.createByErrorMsg("周末或节假日不能交易!"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | if (userPosition == null) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,订单不存在"); |
| | | } |
| | | |
| | | if (doType != 0) { |
| | | ServerResponse timeCheck = validateTransTimeBeforeSell(userPosition, siteSetting); |
| | | if (timeCheck != null) { |
| | | return timeCheck; |
| | | } |
| | | } |
| | | |
| | | |
| | | User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId()); |
| | | if (user == null) { |
| | |
| | | return ServerResponse.createByErrorMsg("平仓失败,此订单已平仓"); |
| | | } |
| | | |
| | | if (DateTimeUtil.isCanSellOneday(userPosition.getBuyOrderTime(), siteSetting.getCantSellTimes().intValue()) && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg(siteSetting.getCantSellTimes() + "分鐘內不能平倉"); |
| | | |
| | | return ServerResponse.createByErrorMsg("当日成交不可平仓"); |
| | | ServerResponse t1Check = validateT1BeforeSell(userPosition, doType); |
| | | if (t1Check != null) { |
| | | return t1Check; |
| | | } |
| | | |
| | | if (1 == userPosition.getIsLock().intValue()) { |
| | |
| | | |
| | | ztRate = ztRate.negate(); |
| | | log.info("股票當前漲跌幅 = {} 跌停幅度 = {}", Double.valueOf(stock_crease), ztRate); |
| | | if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && "買漲" |
| | | .equals(userPosition.getOrderDirection())) { |
| | | return ServerResponse.createByErrorMsg("当前股票已跌停不能卖出"); |
| | | } |
| | | // if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && "買漲" |
| | | // .equals(userPosition.getOrderDirection())) { |
| | | // return ServerResponse.createByErrorMsg("当前股票已跌停不能卖出"); |
| | | // } |
| | | |
| | | Integer buy_num = userPosition.getOrderNum(); |
| | | |
| | |
| | | ucd.setUserName(user.getRealName()); |
| | | ucd.setDeType("总盈亏"); |
| | | ucd.setDeAmt(all_profit); |
| | | ucd.setDeSummary("卖出股票," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",占用本金:" + freez_amt + ",总手续费:" + all_fee_amt + ",递延费:" + orderStayFee + ",印花稅:" + orderSpread + ",盈亏:" + profitLoss + ",总盈亏:" + all_profit); |
| | | ucd.setDeSummary("卖出股票," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",占用本金:" + freez_amt + ",总手续费:" + all_fee_amt + ",盈亏:" + profitLoss + ",总盈亏:" + all_profit); |
| | | |
| | | ucd.setAddTime(new Date()); |
| | | ucd.setIsRead(Integer.valueOf(0)); |
| | |
| | | } |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | if (userPosition == null) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,订单不存在"); |
| | | } |
| | | //部分平仓数量等于订单总数量,则调用全平接口 |
| | | if(quantity.equals(userPosition.getOrderNum())){ |
| | | return sell(positionSn,1); |
| | | } |
| | | //校验时间 |
| | | 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); |
| | | log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag)); |
| | | if (!am_flag && !pm_flag) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内"); |
| | | } |
| | | if (userPosition == null) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,订单不存在"); |
| | | ServerResponse timeCheck = validateTransTimeBeforeSell(userPosition, siteSetting); |
| | | if (timeCheck != null) { |
| | | return timeCheck; |
| | | } |
| | | User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId()); |
| | | if (user == null) { |
| | |
| | | if (1 == userPosition.getIsLock().intValue()) { |
| | | return ServerResponse.createByErrorMsg("平仓失败 " + userPosition.getLockMsg()); |
| | | } |
| | | if (!DateTimeUtil.isCanSell(userPosition.getBuyOrderTime(), siteSetting.getCantSellTimes().intValue())) { |
| | | return ServerResponse.createByErrorMsg("当日成交不可平仓"); |
| | | ServerResponse t1Check = validateT1BeforeSell(userPosition, 1); |
| | | if (t1Check != null) { |
| | | return t1Check; |
| | | } |
| | | |
| | | BigDecimal now_price; |
| | |
| | | BigDecimal user_enable_amt = user.getEnableAmt(); |
| | | log.info("用戶原本總資金 = {} , 可用 = {}", user_all_amt, user_enable_amt); |
| | | |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(all_buy_amt); |
| | | BigDecimal partialMargin = all_buy_amt.divide( |
| | | new BigDecimal(userPosition.getOrderLever()), 2, RoundingMode.HALF_UP); |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(partialMargin); |
| | | log.info("買入手續費 = {}", buy_fee_amt); |
| | | |
| | | BigDecimal orderSpread = all_buy_amt.multiply(siteSetting.getDutyFee()).setScale(2, 4); |
| | |
| | | BigDecimal buy_amt_autual = buy_amt.divide(new BigDecimal(lever.intValue()), 2, 4); |
| | | |
| | | |
| | | BigDecimal buy_fee_amt_check = TradeFeeUtil.calcBuyFee(buy_amt); |
| | | BigDecimal buy_fee_amt_check = TradeFeeUtil.calcBuyFee(buy_amt_autual); |
| | | BigDecimal buy_debit_check = TradeFeeUtil.calcBuyDebit(buy_amt_autual, buy_fee_amt_check); |
| | | if (user_enable_amt.compareTo(buy_debit_check) < 0) { |
| | | log.info("下单失败,用户可用金额小于{}元(含保证金及手续费)", buy_debit_check); |
| | |
| | | userPosition.setOrderStayDays(1); |
| | | |
| | | |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt).setScale(2, 4); |
| | | log.info("创建模拟持仓 手续费(配资后总资金 * 百分比) = {}", buy_fee_amt); |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt_autual).setScale(2, 4); |
| | | log.info("创建模拟持仓 手续费(保证金 * 百分比) = {}", buy_fee_amt); |
| | | userPosition.setOrderFee(buy_fee_amt); |
| | | |
| | | |
| | |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | userPosition.setSpreadRatePrice(new BigDecimal("0")); |
| | | userPosition.setStatus(1); |
| | | |
| | | this.userPositionMapper.insert(userPosition); |
| | | if (userPosition.getId() == null || userPosition.getId() <= 0) { |
| | |
| | | userPositionVO.setAllProfitAndLoseStr(positionProfitVO.getAllProfitAndLoseStr()); |
| | | userPositionVO.setOrderTotalPrice(positionProfitVO.getOrderTotalPrice()); |
| | | |
| | | if (position.getOrderLever() != null && position.getOrderLever() > 0 |
| | | && position.getBuyOrderPrice() != null && position.getOrderNum() != null) { |
| | | userPositionVO.setBuyAmtAutual( |
| | | position.getBuyOrderPrice() |
| | | .multiply(new BigDecimal(position.getOrderNum())) |
| | | .divide(new BigDecimal(position.getOrderLever()), 2, RoundingMode.HALF_UP)); |
| | | } |
| | | |
| | | return userPositionVO; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | BigDecimal buy_fee_amt_dz = TradeFeeUtil.calcBuyFee(buy_amt); |
| | | BigDecimal buy_fee_amt_dz = TradeFeeUtil.calcBuyFee(buy_amt_autual); |
| | | BigDecimal buy_debit_dz = TradeFeeUtil.calcBuyDebit(buy_amt_autual, buy_fee_amt_dz); |
| | | if (user_enable_amt.compareTo(buy_debit_dz) == -1) { |
| | | return ServerResponse.createByErrorMsg("下单失败,融资可用金额小于" + buy_debit_dz + "元(含保证金及手续费)"); |
| | |
| | | } |
| | | |
| | | |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt); |
| | | BigDecimal buy_fee_amt = TradeFeeUtil.calcBuyFee(buy_amt_autual); |
| | | BigDecimal buy_debit = TradeFeeUtil.calcBuyDebit(buy_amt_autual, buy_fee_amt); |
| | | if (user_enable_amt.compareTo(buy_debit) == -1) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,可用金額小於" + buy_debit + "元(含保证金及手续费)"); |