| | |
| | | package com.xcong.excoin.modules.contract.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.alibaba.druid.sql.visitor.functions.If; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.excoin.common.LoginUserUtils; |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import com.xcong.excoin.common.enumerates.RabbitPriceTypeEnum; |
| | | import com.xcong.excoin.common.response.Result; |
| | | import com.xcong.excoin.common.system.service.CommonService; |
| | | import com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao; |
| | | import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao; |
| | | import com.xcong.excoin.modules.contract.dao.ContractOrderDao; |
| | | import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity; |
| | | import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity; |
| | | import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; |
| | | import com.xcong.excoin.modules.contract.mapper.ContractHoldOrderEntityMapper; |
| | | import com.xcong.excoin.modules.contract.parameter.dto.ChangeBondDto; |
| | | import com.xcong.excoin.modules.contract.parameter.dto.ProfitOrLessDto; |
| | | import com.xcong.excoin.modules.contract.parameter.dto.SubmitOrderDto; |
| | | import com.xcong.excoin.modules.contract.parameter.vo.ContractMoneyInfoVo; |
| | | import com.xcong.excoin.modules.contract.parameter.vo.HoldOrderListVo; |
| | | import com.xcong.excoin.modules.contract.service.ContractHoldOrderService; |
| | | import com.xcong.excoin.modules.member.dao.MemberWalletContractDao; |
| | | import com.xcong.excoin.modules.member.entity.AgentReturnEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity; |
| | | import com.xcong.excoin.modules.platform.dao.TradeSettingDao; |
| | | import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity; |
| | | import com.xcong.excoin.utils.CacheSettingUtils; |
| | | import com.xcong.excoin.utils.CalculateUtil; |
| | | import com.xcong.excoin.utils.CoinTypeConvert; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import com.xcong.excoin.rabbit.producer.OrderProducer; |
| | | import com.xcong.excoin.utils.*; |
| | | import com.xcong.excoin.rabbit.pricequeue.OrderModel; |
| | | import jnr.a64asm.Mem; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import sun.rmi.runtime.Log; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | private ContractOrderDao contractOrderDao; |
| | | |
| | | @Resource |
| | | private ContractEntrustOrderDao contractEntrustOrderDao; |
| | | |
| | | @Resource |
| | | private CommonService commonService; |
| | | |
| | | @Resource |
| | |
| | | @Resource |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Resource |
| | | private OrderProducer producer; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Result submitOrder(SubmitOrderDto submitOrderDto) { |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | |
| | | ContractHoldOrderEntity holdOrderEntity = new ContractHoldOrderEntity(); |
| | | holdOrderEntity.setMemberId(memberEntity.getId()); |
| | | holdOrderEntity.setOrderNo(commonService.generateOrderNo(memberEntity.getId())); |
| | | holdOrderEntity.setPotionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD); |
| | | holdOrderEntity.setPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD); |
| | | holdOrderEntity.setTradeType(ContractHoldOrderEntity.TRADE_TYPE_MARK); |
| | | holdOrderEntity.setSymbol(submitOrderDto.getSymbol()); |
| | | holdOrderEntity.setSymbolCnt(submitOrderDto.getSymbolCnt()); |
| | |
| | | holdOrderEntity.setMarkPrice(newPrice); |
| | | holdOrderEntity.setIsCanClosing(ContractHoldOrderEntity.ORDER_CAN_CLOSING_Y); |
| | | holdOrderEntity.setPrePaymentAmount(prePaymentAmount); |
| | | holdOrderEntity.setBondAmount(bondAmount); |
| | | holdOrderEntity.setBondAmount(bondAmount.add(openFeePrice)); |
| | | |
| | | ContractOrderEntity contractOrderEntity = ContractHoldOrderEntityMapper.INSTANCE.holdOrderToOrder(holdOrderEntity); |
| | | |
| | | contractHoldOrderDao.insert(holdOrderEntity); |
| | | int i = contractOrderDao.insert(contractOrderEntity); |
| | | walletContract.setAvailableBalance(walletContract.getAvailableBalance().subtract(prePaymentAmount)); |
| | | walletContract.setFrozenBalance(walletContract.getFrozenBalance().add(prePaymentAmount)); |
| | | walletContract.setFrozenBalance(walletContract.getFrozenBalance().add(bondAmount.add(openFeePrice))); |
| | | memberWalletContractDao.updateById(walletContract); |
| | | |
| | | // 计算佣金 |
| | | ThreadPoolUtils.calReturnMoney(memberEntity.getId(), contractOrderEntity.getOpeningFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN); |
| | | if (i > 0) { |
| | | return Result.ok("success"); |
| | | } |
| | | return Result.fail("fail"); |
| | | } |
| | | |
| | | @Override |
| | | public int updateContractHoldOrderCanNotClosingByIds(List<OrderModel> list, String batchNo) { |
| | | return contractHoldOrderDao.updateContractHoldOrderCanNotClosingByIds(list, batchNo); |
| | | } |
| | | |
| | | @Override |
| | | public List<ContractHoldOrderEntity> selectContractHoldOrderByBatchNo(String batchNo) { |
| | | return contractHoldOrderDao.selectContractHoldOrderByBatchNo(batchNo); |
| | | } |
| | | |
| | | @Override |
| | | public void updateOrderIsCanClosingAndBatchNoById(Long id) { |
| | | contractHoldOrderDao.updateOrderIsCanClosingAndBatchNoById(id); |
| | | } |
| | | |
| | | @Override |
| | | public Result findHoldOrderList() { |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | |
| | | List<ContractHoldOrderEntity> list = contractHoldOrderDao.selectHoldOrderListByMemberId(memberEntity.getId()); |
| | | if (CollUtil.isNotEmpty(list)) { |
| | | BigDecimal totalProfitOrLoss = BigDecimal.ZERO; |
| | | List<HoldOrderListVo> resultList = new ArrayList<>(); |
| | | for (ContractHoldOrderEntity holdOrderEntity : list) { |
| | | HoldOrderListVo holdOrderListVo = ContractHoldOrderEntityMapper.INSTANCE.holdOrderToDto(holdOrderEntity); |
| | | String symbol = holdOrderEntity.getSymbol(); |
| | | // 获取最新价 |
| | | BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol))); |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(symbol); |
| | | // 盈亏 |
| | | BigDecimal rewardRatio = BigDecimal.ZERO; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | // (最新价-开仓价)*规格*张数 |
| | | rewardRatio = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(lotNumber).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())); |
| | | // 开空 |
| | | } else { |
| | | // (开仓价-最新价)*规格*张数 |
| | | rewardRatio = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(lotNumber).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())); |
| | | } |
| | | |
| | | if (memberEntity.getIsProfit() == MemberEntity.IS_PROFIT_Y) { |
| | | PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); |
| | | if (rewardRatio.compareTo(BigDecimal.ZERO) > -1) { |
| | | rewardRatio = rewardRatio.multiply(BigDecimal.ONE.subtract(tradeSettingEntity.getProfitParam())); |
| | | } else { |
| | | rewardRatio = rewardRatio.multiply(BigDecimal.ONE.add(tradeSettingEntity.getProfitParam())); |
| | | } |
| | | } |
| | | |
| | | // 回报率 |
| | | BigDecimal returnRate = rewardRatio.divide(holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount()), 8, BigDecimal.ROUND_DOWN); |
| | | |
| | | // 成本价格 |
| | | BigDecimal costPrice = holdOrderEntity.getOpeningPrice() |
| | | .multiply(lotNumber) |
| | | .multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())) |
| | | .divide(new BigDecimal(holdOrderEntity.getLeverRatio()), 8, BigDecimal.ROUND_DOWN); |
| | | |
| | | // 可增加最大保证金 |
| | | BigDecimal canAddMaxBond = holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount()).subtract(costPrice); |
| | | if (canAddMaxBond.compareTo(BigDecimal.ZERO) < 0) { |
| | | canAddMaxBond = BigDecimal.ZERO; |
| | | } |
| | | |
| | | holdOrderListVo.setCanAddMaxBond(canAddMaxBond); |
| | | holdOrderListVo.setReturnRate(returnRate); |
| | | holdOrderListVo.setProfitOrLoss(rewardRatio); |
| | | resultList.add(holdOrderListVo); |
| | | totalProfitOrLoss = totalProfitOrLoss.add(rewardRatio); |
| | | } |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("hold", resultList); |
| | | result.put("totalProfitOrLoss", totalProfitOrLoss); |
| | | return Result.ok(result); |
| | | } |
| | | return Result.ok("success"); |
| | | } |
| | | |
| | | @Override |
| | | public Result cancelHoldOrder(Long id) { |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | ContractHoldOrderEntity holdOrderEntity = contractHoldOrderDao.selectHoldOrderByMemberIdAndId(memberEntity.getId(), id); |
| | | if (holdOrderEntity == null) { |
| | | return Result.fail("订单不存在"); |
| | | } |
| | | |
| | | if (ContractHoldOrderEntity.ORDER_CAN_CLOSING_N == holdOrderEntity.getIsCanClosing()) { |
| | | return Result.fail("订单暂不可平仓"); |
| | | } |
| | | |
| | | contractHoldOrderDao.updateHoldOrderIsCanClosingById(ContractHoldOrderEntity.ORDER_CAN_CLOSING_N, id); |
| | | // 发送平仓消息 |
| | | List<Long> ids = new ArrayList<>(); |
| | | ids.add(id); |
| | | producer.sendCloseTrade(JSONObject.toJSONString(ids)); |
| | | |
| | | return Result.ok("平仓成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result cancelHoldOrderBatch() { |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | List<ContractHoldOrderEntity> holdOrderEntities = contractHoldOrderDao.selectHoldOrderListByMemberId(memberEntity.getId()); |
| | | if (CollUtil.isEmpty(holdOrderEntities)) { |
| | | return Result.fail("订单不存在"); |
| | | } |
| | | |
| | | List<Long> ids = new ArrayList<>(); |
| | | for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) { |
| | | contractHoldOrderDao.updateHoldOrderIsCanClosingById(ContractHoldOrderEntity.ORDER_CAN_CLOSING_N, holdOrderEntity.getId()); |
| | | ids.add(holdOrderEntity.getId()); |
| | | } |
| | | ; |
| | | producer.sendCloseTrade(JSONObject.toJSONString(ids)); |
| | | return Result.ok("平仓成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result setTargetProfitOrLess(ProfitOrLessDto profitOrLessDto) { |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | ContractHoldOrderEntity holdOrderEntity = contractHoldOrderDao.selectHoldOrderByMemberIdAndId(memberEntity.getId(), profitOrLessDto.getId()); |
| | | if (holdOrderEntity == null) { |
| | | return Result.fail("订单不存在"); |
| | | } |
| | | |
| | | // 获取最新价 |
| | | BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol()))); |
| | | // 开仓价 |
| | | BigDecimal openPrice = holdOrderEntity.getOpeningPrice(); |
| | | // 设置的止盈止损价 |
| | | BigDecimal price = profitOrLessDto.getPrice(); |
| | | |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { |
| | | // 当前价大于开仓价 |
| | | if (newPrice.compareTo(openPrice) > 0) { |
| | | // 如果止盈价小于当前价 |
| | | if (price.compareTo(newPrice) < 0) { |
| | | return Result.fail("止盈价必须高于当前价"); |
| | | } |
| | | } else { |
| | | if (price.compareTo(openPrice) < 0) { |
| | | return Result.fail("止盈价必须高于开仓价"); |
| | | } |
| | | } |
| | | } else { |
| | | if (newPrice.compareTo(openPrice) > 0) { |
| | | if (price.compareTo(openPrice) > 0) { |
| | | return Result.fail("止损价必须低于开仓价"); |
| | | } |
| | | } else { |
| | | if (price.compareTo(newPrice) > 0) { |
| | | return Result.fail("止损价必须低于当前价"); |
| | | } |
| | | } |
| | | } |
| | | // 开空 |
| | | } else { |
| | | if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { |
| | | if (newPrice.compareTo(openPrice) > 0) { |
| | | if (price.compareTo(openPrice) > 0) { |
| | | return Result.fail("止损价必须低于开仓价"); |
| | | } |
| | | } else { |
| | | if (price.compareTo(newPrice) > 0) { |
| | | return Result.fail("止损价必须低于当前价"); |
| | | } |
| | | } |
| | | } else { |
| | | if (newPrice.compareTo(openPrice) > 0) { |
| | | if (price.compareTo(newPrice) < 0) { |
| | | return Result.fail("止损价必须高于当前价"); |
| | | } |
| | | } else { |
| | | if (price.compareTo(openPrice) < 0) { |
| | | return Result.fail("止损价必须高于开仓价"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { |
| | | holdOrderEntity.setStopProfitPrice(price); |
| | | } else { |
| | | holdOrderEntity.setStopLossPrice(price); |
| | | } |
| | | |
| | | int i = contractHoldOrderDao.updateById(holdOrderEntity); |
| | | if (i > 0) { |
| | | OrderModel model = null; |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | // 开多止盈 |
| | | if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), price.toPlainString(), holdOrderEntity.getSymbol()); |
| | | // 开多止损 |
| | | } else { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), price.toPlainString(), holdOrderEntity.getSymbol()); |
| | | } |
| | | } else { |
| | | // 开空止盈 |
| | | if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | // 开空止损 |
| | | } else { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | } |
| | | } |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | return Result.ok("设置成功"); |
| | | } |
| | | |
| | | return Result.fail("设置失败"); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Result changeBond(ChangeBondDto changeBondDto) { |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | ContractHoldOrderEntity holdOrderEntity = contractHoldOrderDao.selectHoldOrderByMemberIdAndId(memberEntity.getId(), changeBondDto.getId()); |
| | | if (holdOrderEntity == null) { |
| | | return Result.fail("订单不存在"); |
| | | } |
| | | |
| | | MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name()); |
| | | |
| | | // 增加保证金 |
| | | if (ChangeBondDto.TYPE_ADD == changeBondDto.getType()) { |
| | | if (changeBondDto.getAmount().compareTo(walletContract.getAvailableBalance()) > 0) { |
| | | return Result.fail("可用余额不足"); |
| | | } |
| | | walletContract.setAvailableBalance(walletContract.getAvailableBalance().subtract(changeBondDto.getAmount())); |
| | | walletContract.setFrozenBalance(walletContract.getFrozenBalance().add(changeBondDto.getAmount())); |
| | | holdOrderEntity.setBondAmount(holdOrderEntity.getBondAmount().add(changeBondDto.getAmount())); |
| | | // 减少保证金 |
| | | } else { |
| | | if (holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getPrePaymentAmount()).subtract(changeBondDto.getAmount()).compareTo(BigDecimal.ZERO) < 0) { |
| | | return Result.fail("超出保证金最大减少金额"); |
| | | } |
| | | walletContract.setAvailableBalance(walletContract.getAvailableBalance().add(changeBondDto.getAmount())); |
| | | walletContract.setFrozenBalance(walletContract.getFrozenBalance().subtract(changeBondDto.getAmount())); |
| | | holdOrderEntity.setBondAmount(holdOrderEntity.getBondAmount().subtract(changeBondDto.getAmount())); |
| | | } |
| | | |
| | | BigDecimal forceClosingPrice = CalculateUtil.getForceSetPrice(holdOrderEntity.getBondAmount(), holdOrderEntity.getOpeningPrice(), holdOrderEntity.getSymbolCnt(), holdOrderEntity.getSymbolSku(), holdOrderEntity.getOpeningType(), memberEntity); |
| | | holdOrderEntity.setForceClosingPrice(forceClosingPrice); |
| | | holdOrderEntity.setOperateNo(holdOrderEntity.getOperateNo() + 1); |
| | | |
| | | int i = contractHoldOrderDao.updateById(holdOrderEntity); |
| | | int j = memberWalletContractDao.updateById(walletContract); |
| | | |
| | | OrderModel model = null; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | // 开空 |
| | | } else { |
| | | model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | } |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | |
| | | if (i > 0 && j > 0) { |
| | | return Result.ok("调整成功"); |
| | | } |
| | | return Result.fail("调整失败"); |
| | | } |
| | | |
| | | @Override |
| | | public Result findContractMoneyInfo(String symbol) { |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | |
| | | PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting(); |
| | | // 获取最新价 |
| | | BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol))); |
| | | |
| | | // 当前合约委托单 |
| | | List<ContractEntrustOrderEntity> entrustOrderEntities = contractEntrustOrderDao.selectEntrustOrderListByMemberId(memberEntity.getId()); |
| | | |
| | | // 当前持仓列表 |
| | | List<ContractHoldOrderEntity> holdOrderEntities = contractHoldOrderDao.selectHoldOrderListByMemberId(memberEntity.getId()); |
| | | |
| | | // 冻结保证金 -- 即委托单中的保证金之和 |
| | | BigDecimal frozenBondAmount = BigDecimal.ZERO; |
| | | if (CollUtil.isNotEmpty(entrustOrderEntities)) { |
| | | for (ContractEntrustOrderEntity entrustOrderEntity : entrustOrderEntities) { |
| | | frozenBondAmount = frozenBondAmount.add(entrustOrderEntity.getBondAmount()); |
| | | } |
| | | } |
| | | |
| | | // 占用保证金 -- 即持仓单中的保证金之和 |
| | | BigDecimal beUsedBondAmount = BigDecimal.ZERO; |
| | | // 总盈利 |
| | | BigDecimal totalProfitOrLess = BigDecimal.ZERO; |
| | | if (CollUtil.isNotEmpty(holdOrderEntities)) { |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(symbol); |
| | | for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) { |
| | | beUsedBondAmount = beUsedBondAmount.add(holdOrderEntity.getBondAmount()); |
| | | |
| | | // 单个订单盈利 |
| | | BigDecimal profitOrLess = BigDecimal.ZERO; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | profitOrLess = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber).multiply(holdOrderEntity.getSymbolSku()); |
| | | // 开空 |
| | | } else { |
| | | profitOrLess = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber).multiply(holdOrderEntity.getSymbolSku()); |
| | | } |
| | | |
| | | if (MemberEntity.IS_PROFIT_Y == memberEntity.getIsProfit()) { |
| | | if (profitOrLess.compareTo(BigDecimal.ZERO) > 0) { |
| | | profitOrLess = profitOrLess.multiply(BigDecimal.ONE.subtract(tradeSetting.getForceParam())); |
| | | } else { |
| | | profitOrLess = profitOrLess.multiply(BigDecimal.ONE.add(tradeSetting.getForceParam())); |
| | | } |
| | | } |
| | | |
| | | totalProfitOrLess = totalProfitOrLess.add(profitOrLess); |
| | | } |
| | | } |
| | | |
| | | MemberWalletContractEntity walletContractEntity = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name()); |
| | | |
| | | // 权益 |
| | | BigDecimal equity = walletContractEntity.getTotalBalance().add(totalProfitOrLess); |
| | | |
| | | ContractMoneyInfoVo contractMoneyInfoVo = new ContractMoneyInfoVo(); |
| | | contractMoneyInfoVo.setAvailableBalance(walletContractEntity.getAvailableBalance()); |
| | | contractMoneyInfoVo.setBeUsedBondAmount(beUsedBondAmount); |
| | | contractMoneyInfoVo.setFrozenBondAmount(frozenBondAmount); |
| | | contractMoneyInfoVo.setEquity(equity); |
| | | contractMoneyInfoVo.setFeeRatio(tradeSetting.getFeeRatio()); |
| | | contractMoneyInfoVo.setLeverAgeRatio(tradeSetting.getLeverageRatio()); |
| | | contractMoneyInfoVo.setNewPrice(newPrice); |
| | | contractMoneyInfoVo.setSymbolSku(cacheSettingUtils.getSymbolSku(symbol)); |
| | | return Result.ok(contractMoneyInfoVo); |
| | | } |
| | | } |