|  |  | 
 |  |  | package com.xcong.excoin; | 
 |  |  |  | 
 |  |  | import cn.hutool.core.collection.CollUtil; | 
 |  |  | import com.xcong.excoin.common.LoginUserUtils; | 
 |  |  | import com.xcong.excoin.common.enumerates.CoinTypeEnum; | 
 |  |  | 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.ContractHoldOrderEntity; | 
 |  |  | import com.xcong.excoin.modules.contract.service.ContractHoldOrderService; | 
 |  |  | import com.xcong.excoin.modules.member.dao.MemberDao; | 
 |  |  | import com.xcong.excoin.modules.member.dao.MemberLevelRateDao; | 
 |  |  | import com.xcong.excoin.modules.member.dao.MemberWalletContractDao; | 
 |  |  | import com.xcong.excoin.modules.member.entity.MemberEntity; | 
 |  |  | import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity; | 
 |  |  | import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity; | 
 |  |  | import com.xcong.excoin.modules.symbols.service.SymbolsService; | 
 |  |  | import com.xcong.excoin.rabbit.producer.OrderProducer; | 
 |  |  | 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 lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.junit.jupiter.api.Test; | 
 |  |  | import org.springframework.boot.test.context.SpringBootTest; | 
 |  |  |  | 
 |  |  | import javax.annotation.Resource; | 
 |  |  | import java.math.BigDecimal; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @author wzy | 
 |  |  |  * @date 2020-05-26 | 
 |  |  |  **/ | 
 |  |  | @Slf4j | 
 |  |  | @SpringBootTest | 
 |  |  | public class SymbolsTest { | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ContractHoldOrderDao contractHoldOrderDao; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ContractOrderDao contractOrderDao; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ContractEntrustOrderDao contractEntrustOrderDao; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private CommonService commonService; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private MemberWalletContractDao memberWalletContractDao; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private MemberLevelRateDao memberLevelRateDao; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private CacheSettingUtils cacheSettingUtils; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private RedisUtils redisUtils; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private OrderProducer producer; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private MemberDao memberDao; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private SymbolsService symbolsService; | 
 |  |  | 
 |  |  |     public void symbolsTest() { | 
 |  |  |         symbolsService.updateSymbolsKine("1min"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Test | 
 |  |  |     public void moneyTest() { | 
 |  |  |         MemberEntity memberEntity = memberDao.selectById(11L); | 
 |  |  |         PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting(); | 
 |  |  |  | 
 |  |  |         List<ContractHoldOrderEntity> holdOrderEntities = contractHoldOrderDao.selectHoldOrderListByMemberId(memberEntity.getId()); | 
 |  |  |  | 
 |  |  |         BigDecimal beUsedBondAmount = BigDecimal.ZERO; | 
 |  |  |         // 总盈利 | 
 |  |  |         BigDecimal totalProfitOrLess = BigDecimal.ZERO; | 
 |  |  |         if (CollUtil.isNotEmpty(holdOrderEntities)) { | 
 |  |  |             for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) { | 
 |  |  |                 // 获取最新价 | 
 |  |  |                 BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol()))); | 
 |  |  |                 BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol()); | 
 |  |  |                 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); | 
 |  |  |                     // 开空 | 
 |  |  |                 } else { | 
 |  |  |                     profitOrLess = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 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()); | 
 |  |  |  | 
 |  |  |         log.info("--->{}", walletContractEntity.getTotalBalance()); | 
 |  |  |         log.info("----->{}", totalProfitOrLess); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Test | 
 |  |  |     public void forceTest() { | 
 |  |  |         ContractHoldOrderEntity hold = contractHoldOrderDao.selectById(28284L); | 
 |  |  |         MemberEntity memberEntity = memberDao.selectById(6L); | 
 |  |  |         BigDecimal forceSetPrice = CalculateUtil.getForceSetPrice(hold.getBondAmount(), hold.getOpeningPrice(), hold.getSymbolCnt(), hold.getSymbolSku(), hold.getOpeningType(), memberEntity); | 
 |  |  |         System.out.println(forceSetPrice); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ContractHoldOrderService contractHoldOrderService; | 
 |  |  |  | 
 |  |  |     @Test | 
 |  |  |     public void holdAmountTest() { | 
 |  |  |         try { | 
 |  |  |             contractHoldOrderService.calHoldOrderHoldFeeAmount(); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.info("-->", e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |