| | |
| | | import com.yami.trading.service.StrongLevelCalculationService; |
| | | import com.yami.trading.service.WalletService; |
| | | import com.yami.trading.service.data.DataService; |
| | | import com.yami.trading.service.impl.StrongLevelCalculationServiceImpl; |
| | | import com.yami.trading.service.item.ItemService; |
| | | import com.yami.trading.service.syspara.SysparaService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | Item item = itemService.findBySymbol(order.getSymbol()); |
| | | |
| | | |
| | | if(null != order.getProfitLossRatio()){//根据后台设置的盈亏比来 |
| | | if(null != order.getProfitLossRatio() && order.getProfitLossRatio() > 0){//根据后台设置的盈亏比来 |
| | | order.setProfit(order.getDepositOpen().multiply(new BigDecimal((order.getProfitLossRatio()/100))).setScale(2, RoundingMode.DOWN)); |
| | | }else{ |
| | | /* |
| | |
| | | * 偏差点位 |
| | | */ |
| | | BigDecimal point = currentPrice.subtract(order.getTradeAvgPrice()); |
| | | BigDecimal amount = point.multiply(new BigDecimal("0.01")).multiply(order.getVolumeOpen()).setScale(4, BigDecimal.ROUND_DOWN);; |
| | | 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{ |
| | |
| | | }*/ |
| | | |
| | | // 获取当前账户余额并加到收益中 |
| | | Map<String, Object> moneyAll = walletService.getMoneyAll(order.getPartyId()); |
| | | earnings = earnings.add(new BigDecimal(moneyAll.get("money_all_coin").toString())); |
| | | //Map<String, Object> moneyAll = walletService.getMoneyAll(order.getPartyId()); |
| | | |
| | | Wallet wallet = walletService.saveWalletByPartyId(order.getPartyId()); |
| | | earnings = earnings.add(wallet.getMoney()); |
| | | earnings = earnings.add(order.getDepositOpen()); |
| | | } else { |
| | | // 如果不符合条件,直接使用 order.getDepositOpen() 作为收益 |
| | |
| | | /** |
| | | * 强平计算 |
| | | */ |
| | | //重新计算强平 |
| | | BigDecimal forceClosePrice = new BigDecimal(order.getForceClosePrice()); |
| | | if (currentPrice.compareTo(new BigDecimal(order.getForceClosePrice())) <= 0) {//达到强平价 |
| | | BigDecimal point = forceClosePrice.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()); |
| | | } |
| | | //强平利润固定-100% |
| | | order.setProfit(order.getDepositOpen().add(order.getAddDepositOpen()).negate()); |
| | | //全仓强平利润+账户余额 |
| | | if (order.getLocationType() == 1) { |
| | | Wallet wallet = this.walletService.findByUserId(order.getPartyId()); |
| | | order.setProfit(order.getProfit().subtract(wallet.getMoney())); |
| | | } |
| | | } |
| | | this.contractOrderService.updateByIdBuffer(order); |
| | | //判断是全仓还是逐仓 |
| | | if (order.getLocationType() == 1) { |
| | | // /** |
| | |
| | | |
| | | |
| | | // Wallet wallet = this.walletService.findByUserId(order.getPartyId().toString()); |
| | | this.contractOrderService.updateByIdBuffer(order); |
| | | //this.contractOrderService.updateByIdBuffer(order); |
| | | |
| | | // if (profit.add(wallet.getMoney()).compareTo(BigDecimal.ZERO) <= 0) { |
| | | //判断买涨还是买跌"buy":买(多) "sell":卖(空) |
| | |
| | | log.info("------------------order.getForceClosePrice()-------------"+order.getForceClosePrice()); |
| | | log.info("------------------开多强平-------------"); |
| | | this.contractOrderService.allClose(order.getPartyId()); |
| | | |
| | | } |
| | | }else{ |
| | | if (currentPrice.compareTo(new BigDecimal(order.getForceClosePrice()))>= 0) {//达到强平价 |
| | |
| | | this.order_close_line_type = order_close_line_type; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | StrongLevelCalculationService strongLevelCalculationService = new StrongLevelCalculationServiceImpl(); |
| | | double forceClosePrice = strongLevelCalculationService.calculateLiquidationPrice(100, |
| | | 0.01, 67704.80, 1.477 |
| | | , 0.004, 0.0005); |
| | | } |
| | | } |