| | |
| | | * @param currentPrice 当前点位 |
| | | */ |
| | | public void settle(ContractOrder order, String profit_loss, BigDecimal currentPrice, List<ContractOrder> partyContractOrders) { |
| | | |
| | | |
| | | |
| | | Item item = itemService.findBySymbol(order.getSymbol()); |
| | | |
| | | /* |
| | | * 根据偏 差点数和手数算出盈亏金额 |
| | | */ |
| | | /** |
| | | * 偏差点位 |
| | | */ |
| | | BigDecimal point = currentPrice.subtract(order.getTradeAvgPrice()); |
| | | /* |
| | | * 根据偏 差点数和手数算出盈亏金额 |
| | | */ |
| | | BigDecimal amount = point.multiply(new BigDecimal("0.01")).multiply(order.getVolumeOpen()).setScale(4, BigDecimal.ROUND_DOWN);; |
| | | if (ContractOrder.DIRECTION_BUY.equals(order.getDirection())) { |
| | | order.setProfit(amount); |
| | | } else{ |
| | | order.setProfit(amount.negate()); |
| | | } |
| | | |
| | | Item item = itemService.findBySymbol(order.getSymbol()); |
| | | |
| | | // if ("profit".equals(profit_loss)) { |
| | | // /** |
| | | // * 盈 正数 |
| | | // */ |
| | | // order.setProfit(amount); |
| | | // } else if ("loss".equals(profit_loss)) { |
| | | // order.setProfit(amount); |
| | | // |
| | | // } |
| | | |
| | | order.setProfit(amount); |
| | | |
| | | double faceValue = 0.01; // 合约面值(固定面值不能调整) |
| | | double maintenanceMarginRate = 0.004; // 维持保证金率(固定不变) |
| | |
| | | // 获取当前账户余额并加到收益中 |
| | | Map<String, Object> moneyAll = walletService.getMoneyAll(order.getPartyId()); |
| | | earnings = earnings.add(new BigDecimal(moneyAll.get("money_all_coin").toString())); |
| | | |
| | | earnings = earnings.add(order.getDepositOpen()); |
| | | } else { |
| | | // 如果不符合条件,直接使用 order.getDepositOpen() 作为收益 |
| | | earnings = order.getDepositOpen(); |
| | |
| | | , maintenanceMarginRate, item.getUnitFee().doubleValue()); |
| | | order.setForceClosePrice(BigDecimal.valueOf(forceClosePrice).toString()); |
| | | }else{ |
| | | double forceClosePrice = strongLevelCalculationService.calculateLiquidationPrice(earnings.doubleValue(), |
| | | double forceClosePrice = strongLevelCalculationService.calculateEmptyLiquidationPrice(earnings.doubleValue(), |
| | | faceValue, order.getVolumeOpen().doubleValue(), order.getTradeAvgPrice().doubleValue() |
| | | , maintenanceMarginRate, item.getUnitFee().doubleValue()); |
| | | order.setForceClosePrice(BigDecimal.valueOf(forceClosePrice).toString()); |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | } else { |
| | | if(order.getDirection().equals("buy")){ |
| | | if (currentPrice.toString().compareTo(order.getForceClosePrice()) <= 0) {//达到强平价 |