| | |
| | | log.info("------------------currentPrice-------------:"+currentPrice); |
| | | log.info("------------------order.getForceClosePrice()-------------"+order.getForceClosePrice()); |
| | | log.info("------------------开多强平-------------"); |
| | | |
| | | double number = strongLevelCalculationService.countSheets(earnings.doubleValue(), order.getLeverRate().intValue(), 0.01, order.getTradeAvgPrice().doubleValue()); |
| | | BigDecimal qpPoint = currentPrice.subtract(order.getTradeAvgPrice()); |
| | | BigDecimal qpAmount = qpPoint.multiply(new BigDecimal("0.01")).multiply(new BigDecimal(number)).setScale(4, BigDecimal.ROUND_DOWN);; |
| | | log.info(order.getOrderNo()+"--------强平收益:"+amount); |
| | | order.setProfit(qpAmount); |
| | | this.contractOrderService.allClose(order.getPartyId()); |
| | | |
| | | } |
| | |
| | | log.info("------------------currentPrice-------------:"+currentPrice); |
| | | log.info("------------------order.getForceClosePrice()-------------"+order.getForceClosePrice()); |
| | | log.info("------------------开空强平-------------"); |
| | | double number = strongLevelCalculationService.countSheets(earnings.doubleValue(), order.getLeverRate().intValue(), 0.01, order.getTradeAvgPrice().doubleValue()); |
| | | BigDecimal qpPoint = currentPrice.subtract(order.getTradeAvgPrice()); |
| | | BigDecimal qpAmount = qpPoint.multiply(new BigDecimal("0.01")).multiply(new BigDecimal(number)).setScale(4, BigDecimal.ROUND_DOWN);; |
| | | log.info(order.getOrderNo()+"--------强平收益:"+amount); |
| | | order.setProfit(qpAmount.negate()); |
| | | this.contractOrderService.allClose(order.getPartyId()); |
| | | |
| | | } |
| | |
| | | BigDecimal close = realtime.getClose(); |
| | | BigDecimal point = close.subtract(order.getTradeAvgPrice()); |
| | | BigDecimal profit = point.multiply(new BigDecimal("0.01")).multiply(order.getVolumeOpen()).setScale(4, BigDecimal.ROUND_DOWN);; |
| | | if(null != order.getProfitLossRatio() || order.getProfitLossRatio() > 0){ |
| | | profit = order.getDepositOpen().multiply(new BigDecimal((order.getProfitLossRatio()/100))).setScale(2, RoundingMode.DOWN); |
| | | } |
| | | BigDecimal rentalProfit = order.getDeposit().add(profit); |
| | | BigDecimal rate = volume.divide(order.getVolumeOpen(), 2, RoundingMode.HALF_UP); |
| | | order.setAmountClose(order.getAmountClose().add(profit)); |
| | |
| | | } |
| | | |
| | | |
| | | public static double sss(double earnestMoney, int level, double faceValue, double recentQuotation){ |
| | | double result = earnestMoney * level / (faceValue * recentQuotation); |
| | | |
| | | BigDecimal bd = new BigDecimal(result).setScale(2, RoundingMode.DOWN); |
| | | |
| | | return bd.doubleValue(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | // 给定参数 |
| | | double marginBalance = 3857.51; // 保证金余额 |
| | | double marginBalance = 925; // 保证金余额 |
| | | double faceValue = 0.01; // 合约面值(固定面值不能调整) |
| | | double contractQuantity = 1.0304; // 合约张数 张数=可用保证金*杠杆倍数/(面值*最新成交价) |
| | | double openingPrice = 97016.4; // 开仓均价 |
| | | double contractQuantity = 86.52218241682178; // 合约张数 张数=可用保证金*杠杆倍数/(面值*最新成交价) |
| | | double openingPrice = 106909; // 开仓均价 |
| | | double maintenanceMarginRate = 0.004; // 维持保证金率(固定不变) |
| | | double feeRate = 0.0005; // 手续费率 根据实际设置 |
| | | |
| | | double sss = sss(1000, 100, 0.01, 106909); |
| | | |
| | | |
| | | System.out.println(sss); |
| | | |
| | | // 计算强平价 |
| | | double liquidationPrice = demoA(marginBalance, faceValue, contractQuantity, |
| | | openingPrice, maintenanceMarginRate, feeRate); |