| | |
| | | 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; |
| | | } |
| | | |
| | | public ServerResponse sell(String positionSn, int doType) throws Exception { |
| | | log.info("【用戶交易平倉】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType)); |
| | | |
| | |
| | | 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)); |
| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | |
| | | 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 + "元(含保证金及手续费)"); |