From 5575818556096be1dadaf5ff356b5db4c832aaa2 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Wed, 26 May 2021 19:27:09 +0800 Subject: [PATCH] modify --- src/test/java/com/xcong/excoin/SymbolsTest.java | 129 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 129 insertions(+), 0 deletions(-) diff --git a/src/test/java/com/xcong/excoin/SymbolsTest.java b/src/test/java/com/xcong/excoin/SymbolsTest.java index 663e834..d32a23f 100644 --- a/src/test/java/com/xcong/excoin/SymbolsTest.java +++ b/src/test/java/com/xcong/excoin/SymbolsTest.java @@ -1,17 +1,73 @@ 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.quartz.job.UsdtCnyExchangePriceUpdateJob; +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.beans.factory.annotation.Autowired; 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; @@ -20,4 +76,77 @@ 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.calHoldFeeAmountForBondAmount(); + } catch (Exception e) { + log.info("-->", e); + } + } + + @Autowired + private UsdtCnyExchangePriceUpdateJob usdtCnyExchangePriceUpdateJob; + + @Test + public void usdtCnyTest() { + usdtCnyExchangePriceUpdateJob.updateUsdtCnyExchange(); + } } -- Gitblit v1.9.1