| | |
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
|
| | | import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | |
| | | import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinVo;
|
| | | import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletContractInfoVo;
|
| | | import com.xcong.excoin.modules.coin.service.CoinService;
|
| | | import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao;
|
| | | import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity;
|
| | | import com.xcong.excoin.modules.contract.mapper.ContractHoldOrderEntityMapper;
|
| | | import com.xcong.excoin.modules.contract.parameter.vo.HoldOrderListVo;
|
| | | import com.xcong.excoin.modules.member.dao.MemberDao;
|
| | | import com.xcong.excoin.modules.member.dao.MemberWalletAgentDao;
|
| | | import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
|
| | |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
|
| | | import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
|
| | | import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
|
| | | import com.xcong.excoin.utils.CacheSettingUtils;
|
| | | import com.xcong.excoin.utils.CoinTypeConvert;
|
| | | import com.xcong.excoin.utils.MessageSourceUtils;
|
| | | import com.xcong.excoin.utils.RedisUtils;
|
| | |
| | | MemberDao memberDao;
|
| | | @Resource
|
| | | RedisUtils redisUtils;
|
| | | @Resource
|
| | | private ContractHoldOrderDao contractHoldOrderDao;
|
| | | @Resource
|
| | | private CacheSettingUtils cacheSettingUtils;
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | | //获取用户ID
|
| | | Long memberId = LoginUserUtils.getAppLoginUser().getId();
|
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
|
| | | |
| | | List<ContractHoldOrderEntity> list = contractHoldOrderDao.selectHoldOrderListByMemberIdAndSymbol(memberEntity.getId(), symbol, 1);
|
| | | BigDecimal totalProfitOrLoss = BigDecimal.ZERO;
|
| | | if (CollUtil.isNotEmpty(list)) {
|
| | | for (ContractHoldOrderEntity holdOrderEntity : list) {
|
| | | // 获取最新价
|
| | | BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol())));
|
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol());
|
| | | // 盈亏
|
| | | BigDecimal rewardRatio = BigDecimal.ZERO;
|
| | | // 开多
|
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) {
|
| | | // (最新价-开仓价)*规格*张数
|
| | | rewardRatio = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(lotNumber).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale()));
|
| | | // 开空
|
| | | } else {
|
| | | // (开仓价-最新价)*规格*张数
|
| | | rewardRatio = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(lotNumber).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale()));
|
| | | }
|
| | |
|
| | | 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()));
|
| | | } |
| | | }
|
| | | totalProfitOrLoss = totalProfitOrLoss.add(rewardRatio);
|
| | | }
|
| | | }
|
| | |
|
| | | String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
|
| | | MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbol);
|
| | | BigDecimal availableBalance = walletContract.getAvailableBalance();
|
| | | // 扣币
|
| | | if (totalProfitOrLoss.compareTo(BigDecimal.ZERO) < 0) {
|
| | | availableBalance = availableBalance.add(totalProfitOrLoss);
|
| | | }
|
| | | BigDecimal availableSubtract = availableBalance.subtract(balance);
|
| | | if (availableSubtract.compareTo(BigDecimal.ZERO) < 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0007"));
|
| | |
| | | }
|
| | |
|
| | | //更新合约全仓模式下的订单权益
|
| | | MemberEntity memberEntity = memberDao.selectById(memberId);
|
| | | String symbols = symbol+"/USDT";
|
| | | ThreadPoolUtils.sendWholeForceClosingPrice(symbols, memberEntity);
|
| | |
|