From 1b0e20f11a920ba8c0c38e4c8fef58e8fa1fe0d2 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 14 Jul 2020 19:41:31 +0800
Subject: [PATCH] Merge branch 'master' of https://gitee.com/chonggaoxiao/new_excoin

---
 src/test/java/com/xcong/excoin/SymbolsTest.java |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 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..cfe29de 100644
--- a/src/test/java/com/xcong/excoin/SymbolsTest.java
+++ b/src/test/java/com/xcong/excoin/SymbolsTest.java
@@ -1,17 +1,69 @@
 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.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.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;
@@ -20,4 +72,49 @@
     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);
+
+    }
 }

--
Gitblit v1.9.1