From 79224bc3495cf80370855e9e2fe9e2acd1f3e63b Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Wed, 07 Apr 2021 17:16:52 +0800
Subject: [PATCH] modify whole force price

---
 src/test/java/com/xcong/excoin/WholeTest.java           |    4 
 src/test/java/com/xcong/excoin/LocalTest.java           |  160 ++++++++++++++++++++++++++--------------------------
 src/main/java/com/xcong/excoin/utils/CalculateUtil.java |    9 ++
 3 files changed, 90 insertions(+), 83 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/utils/CalculateUtil.java b/src/main/java/com/xcong/excoin/utils/CalculateUtil.java
index ba61bf6..e350857 100644
--- a/src/main/java/com/xcong/excoin/utils/CalculateUtil.java
+++ b/src/main/java/com/xcong/excoin/utils/CalculateUtil.java
@@ -204,6 +204,13 @@
         return forcePrice;
     }
 
+    /**
+     * 权益-维持保证金+开仓价*张数*规格-开仓价*费率-(总账户-维持保证金) / 规格*张数
+     *
+     * @param memberEntity
+     * @param contractHoldOrderEntity
+     * @return
+     */
     public static BigDecimal calWholePriceTwo(MemberEntity memberEntity, ContractHoldOrderEntity contractHoldOrderEntity) {
         ContractHoldOrderDao holdOrderDao = SpringContextHolder.getBean(ContractHoldOrderDao.class);
         MemberWalletContractDao walletContractDao = SpringContextHolder.getBean(MemberWalletContractDao.class);
@@ -247,7 +254,7 @@
 //            BigDecimal divideChild = walletContract.getTotalBalance().add(totalProfitOrLoss).subtract(holdBond).subtract(cost).add(newPrice.multiply(new BigDecimal("0.005")));
             BigDecimal divideParent = contractHoldOrderEntity.getSymbolSku().multiply(new BigDecimal(contractHoldOrderEntity.getSymbolCntSale()));
 
-            forcePrice = divideChild.divide(divideParent, 8, BigDecimal.ROUND_DOWN).negate();
+            forcePrice = divideChild.divide(divideParent, 8, BigDecimal.ROUND_DOWN);
         }
         return forcePrice;
     }
diff --git a/src/test/java/com/xcong/excoin/LocalTest.java b/src/test/java/com/xcong/excoin/LocalTest.java
index 03b5c02..a40bfba 100644
--- a/src/test/java/com/xcong/excoin/LocalTest.java
+++ b/src/test/java/com/xcong/excoin/LocalTest.java
@@ -90,85 +90,85 @@
     private FollowTraderLabelDao followTraderLabelDao;
     @Resource
     private MemberSettingDao memberSettingDao;
-	
-    @Test
-	public void traderProfitUpdate() {
-		log.info("交易员定时任务执行");
-		// 查询所有交易员信息
-		List<FollowTraderInfoEntity> allTraders = followTraderInfoDao.selectAllTraderInfo();
-		if (CollUtil.isNotEmpty(allTraders)) {
-			for (FollowTraderInfoEntity trader : allTraders) {
-				Long tradeMemberId = trader.getMemberId();
-				//获取交易员的当前跟随者
-				Map<String, Object> hashMap = new HashMap<>();
-				hashMap.put("trade_member_id", tradeMemberId);
-				hashMap.put("is_follow", FollowFollowerProfitEntity.IS_FOLLOW_Y);
-				List<FollowFollowerProfitEntity> followFollowerProfitEntityList = followFollowerProfitDao.selectByMap(hashMap);
-				if(CollUtil.isNotEmpty(followFollowerProfitEntityList)) {
-					for(FollowFollowerProfitEntity followFollowerProfitEntity : followFollowerProfitEntityList) {
-						//获取当前跟随者的跟随本金
-						Long memberId = followFollowerProfitEntity.getMemberId();
-						BigDecimal sumBondAmountBigDecimal = followFollowerProfitDao.selectSumBondAmountBymemberId(memberId,trader.getId());
-						sumBondAmountBigDecimal = (sumBondAmountBigDecimal == null?BigDecimal.ZERO:sumBondAmountBigDecimal.setScale(2, BigDecimal.ROUND_DOWN));
-						followFollowerProfitEntity.setTotalPrincipal(sumBondAmountBigDecimal);
-						//获取当前的盈亏
-						BigDecimal sumRewardAmountBigDecimal = followFollowerProfitDao.selectSumRewardAmountByMemberId(memberId,trader.getId());
-						sumRewardAmountBigDecimal = (sumRewardAmountBigDecimal == null?BigDecimal.ZERO:sumRewardAmountBigDecimal.setScale(2, BigDecimal.ROUND_DOWN));
-						followFollowerProfitEntity.setTotalProfit(sumRewardAmountBigDecimal);
-						followFollowerProfitDao.updateById(followFollowerProfitEntity);
-					}
-				}
-
-
-				FollowTraderProfitInfoEntity traderInfoProfit = followTraderProfitInfoDao.selectTraderInfoProfitByMemberId(tradeMemberId);
-				// 累计收益率
-				BigDecimal ljsyl = contractOrderDao.selectFollowOrderTotalProfitByMemberId(tradeMemberId);
-				BigDecimal totalProfitRatio = (ljsyl == null?BigDecimal.ZERO:ljsyl.setScale(2, BigDecimal.ROUND_DOWN));
-				traderInfoProfit.setTotalProfitRatio(totalProfitRatio);
-				// 带单总收益,只查询交易员自己的带单总收益
-				BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfitSelf(tradeMemberId);
-				//BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfit(tradeMemberId);
-				traderInfoProfit.setTotalProfit(totalProfit);
-				// 交易笔数
-//                List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderByMemberId(tradeMemberId);
-				List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderListByMemberId(tradeMemberId);
-				traderInfoProfit.setTotalOrderCnt(CollUtil.isNotEmpty(orders) ? orders.size() : 0);
-				// 近三周胜率
-				Integer winCnt = contractOrderDao.selectFollowOrderCntForWinRate(tradeMemberId, 1);
-				Integer allCnt = contractOrderDao.selectFollowOrderCntForWinRate(tradeMemberId, null);
-
-				if (winCnt != null && allCnt != null && allCnt!=0) {
-					BigDecimal winRate = BigDecimal.valueOf(winCnt).divide(BigDecimal.valueOf(allCnt), 4, BigDecimal.ROUND_DOWN);
-					traderInfoProfit.setWinRate(winRate);
-				}
-				Date date = new Date();
-				DateTime offsetDay = DateUtil.offsetDay(new Date(), -30);
-				//30天胜率(30天盈利总单数/30平仓总单数)
-				BigDecimal thirtyTotalCnt = contractOrderDao.selectThirtyTotalCntByMemberId(tradeMemberId,date,offsetDay);
-				BigDecimal thirtyWinCnt = contractOrderDao.selectThirtyWinCntByMemberId(tradeMemberId,date,offsetDay);
-				BigDecimal thirtyTotalCntRatio = (thirtyTotalCnt == null?BigDecimal.ZERO:thirtyTotalCnt.setScale(2, BigDecimal.ROUND_DOWN));
-				BigDecimal thirtyWinCntRatio = (thirtyWinCnt == null?BigDecimal.ZERO:thirtyWinCnt.setScale(2, BigDecimal.ROUND_DOWN));
-				BigDecimal thirtyProfitRatio = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_DOWN);;
-				if(thirtyTotalCnt.compareTo(BigDecimal.ZERO) > 0) {
-					thirtyProfitRatio = thirtyWinCntRatio.divide(thirtyTotalCntRatio, 2, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
-				}
-				traderInfoProfit.setThirtyProfitRatio(thirtyProfitRatio);
-				//30天最大回撤率(30天最高收益率-30天最低收益率)
-				BigDecimal thirtyMaxRatio = contractOrderDao.selectThirtyMaxRatioByMemberId(tradeMemberId,date,offsetDay);
-				BigDecimal thirtyMinRatio = contractOrderDao.selectThirtyMinRatioByMemberId(tradeMemberId,date,offsetDay);
-				BigDecimal thirtyRatio = (thirtyMaxRatio == null?BigDecimal.ZERO:thirtyMaxRatio.setScale(2, BigDecimal.ROUND_DOWN))
-						.subtract((thirtyMinRatio == null?BigDecimal.ZERO:thirtyMinRatio.setScale(2, BigDecimal.ROUND_DOWN)));
-				traderInfoProfit.setThirtyRatio(thirtyRatio);
-				// 当前跟随者总收益
-				BigDecimal followerProfit = followFollowerProfitDao.selectAllFollowerProfit(tradeMemberId);
-				traderInfoProfit.setFollowerTotalProfit(followerProfit);
-				// 当前跟随人数
-				int followerCnt = followFollowerProfitDao.selectFollowerCntByTradeMemberId(tradeMemberId);
-				traderInfoProfit.setTotalFollowerCnt(followerCnt);
-
-				followTraderProfitInfoDao.updateById(traderInfoProfit);
-			}
-		}
-	}
+//
+//    @Test
+//	public void traderProfitUpdate() {
+//		log.info("交易员定时任务执行");
+//		// 查询所有交易员信息
+//		List<FollowTraderInfoEntity> allTraders = followTraderInfoDao.selectAllTraderInfo();
+//		if (CollUtil.isNotEmpty(allTraders)) {
+//			for (FollowTraderInfoEntity trader : allTraders) {
+//				Long tradeMemberId = trader.getMemberId();
+//				//获取交易员的当前跟随者
+//				Map<String, Object> hashMap = new HashMap<>();
+//				hashMap.put("trade_member_id", tradeMemberId);
+//				hashMap.put("is_follow", FollowFollowerProfitEntity.IS_FOLLOW_Y);
+//				List<FollowFollowerProfitEntity> followFollowerProfitEntityList = followFollowerProfitDao.selectByMap(hashMap);
+//				if(CollUtil.isNotEmpty(followFollowerProfitEntityList)) {
+//					for(FollowFollowerProfitEntity followFollowerProfitEntity : followFollowerProfitEntityList) {
+//						//获取当前跟随者的跟随本金
+//						Long memberId = followFollowerProfitEntity.getMemberId();
+//						BigDecimal sumBondAmountBigDecimal = followFollowerProfitDao.selectSumBondAmountBymemberId(memberId,trader.getId());
+//						sumBondAmountBigDecimal = (sumBondAmountBigDecimal == null?BigDecimal.ZERO:sumBondAmountBigDecimal.setScale(2, BigDecimal.ROUND_DOWN));
+//						followFollowerProfitEntity.setTotalPrincipal(sumBondAmountBigDecimal);
+//						//获取当前的盈亏
+//						BigDecimal sumRewardAmountBigDecimal = followFollowerProfitDao.selectSumRewardAmountByMemberId(memberId,trader.getId());
+//						sumRewardAmountBigDecimal = (sumRewardAmountBigDecimal == null?BigDecimal.ZERO:sumRewardAmountBigDecimal.setScale(2, BigDecimal.ROUND_DOWN));
+//						followFollowerProfitEntity.setTotalProfit(sumRewardAmountBigDecimal);
+//						followFollowerProfitDao.updateById(followFollowerProfitEntity);
+//					}
+//				}
+//
+//
+//				FollowTraderProfitInfoEntity traderInfoProfit = followTraderProfitInfoDao.selectTraderInfoProfitByMemberId(tradeMemberId);
+//				// 累计收益率
+//				BigDecimal ljsyl = contractOrderDao.selectFollowOrderTotalProfitByMemberId(tradeMemberId);
+//				BigDecimal totalProfitRatio = (ljsyl == null?BigDecimal.ZERO:ljsyl.setScale(2, BigDecimal.ROUND_DOWN));
+//				traderInfoProfit.setTotalProfitRatio(totalProfitRatio);
+//				// 带单总收益,只查询交易员自己的带单总收益
+//				BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfitSelf(tradeMemberId);
+//				//BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfit(tradeMemberId);
+//				traderInfoProfit.setTotalProfit(totalProfit);
+//				// 交易笔数
+////                List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderByMemberId(tradeMemberId);
+//				List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderListByMemberId(tradeMemberId);
+//				traderInfoProfit.setTotalOrderCnt(CollUtil.isNotEmpty(orders) ? orders.size() : 0);
+//				// 近三周胜率
+//				Integer winCnt = contractOrderDao.selectFollowOrderCntForWinRate(tradeMemberId, 1);
+//				Integer allCnt = contractOrderDao.selectFollowOrderCntForWinRate(tradeMemberId, null);
+//
+//				if (winCnt != null && allCnt != null && allCnt!=0) {
+//					BigDecimal winRate = BigDecimal.valueOf(winCnt).divide(BigDecimal.valueOf(allCnt), 4, BigDecimal.ROUND_DOWN);
+//					traderInfoProfit.setWinRate(winRate);
+//				}
+//				Date date = new Date();
+//				DateTime offsetDay = DateUtil.offsetDay(new Date(), -30);
+//				//30天胜率(30天盈利总单数/30平仓总单数)
+//				BigDecimal thirtyTotalCnt = contractOrderDao.selectThirtyTotalCntByMemberId(tradeMemberId,date,offsetDay);
+//				BigDecimal thirtyWinCnt = contractOrderDao.selectThirtyWinCntByMemberId(tradeMemberId,date,offsetDay);
+//				BigDecimal thirtyTotalCntRatio = (thirtyTotalCnt == null?BigDecimal.ZERO:thirtyTotalCnt.setScale(2, BigDecimal.ROUND_DOWN));
+//				BigDecimal thirtyWinCntRatio = (thirtyWinCnt == null?BigDecimal.ZERO:thirtyWinCnt.setScale(2, BigDecimal.ROUND_DOWN));
+//				BigDecimal thirtyProfitRatio = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_DOWN);;
+//				if(thirtyTotalCnt.compareTo(BigDecimal.ZERO) > 0) {
+//					thirtyProfitRatio = thirtyWinCntRatio.divide(thirtyTotalCntRatio, 2, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
+//				}
+//				traderInfoProfit.setThirtyProfitRatio(thirtyProfitRatio);
+//				//30天最大回撤率(30天最高收益率-30天最低收益率)
+//				BigDecimal thirtyMaxRatio = contractOrderDao.selectThirtyMaxRatioByMemberId(tradeMemberId,date,offsetDay);
+//				BigDecimal thirtyMinRatio = contractOrderDao.selectThirtyMinRatioByMemberId(tradeMemberId,date,offsetDay);
+//				BigDecimal thirtyRatio = (thirtyMaxRatio == null?BigDecimal.ZERO:thirtyMaxRatio.setScale(2, BigDecimal.ROUND_DOWN))
+//						.subtract((thirtyMinRatio == null?BigDecimal.ZERO:thirtyMinRatio.setScale(2, BigDecimal.ROUND_DOWN)));
+//				traderInfoProfit.setThirtyRatio(thirtyRatio);
+//				// 当前跟随者总收益
+//				BigDecimal followerProfit = followFollowerProfitDao.selectAllFollowerProfit(tradeMemberId);
+//				traderInfoProfit.setFollowerTotalProfit(followerProfit);
+//				// 当前跟随人数
+//				int followerCnt = followFollowerProfitDao.selectFollowerCntByTradeMemberId(tradeMemberId);
+//				traderInfoProfit.setTotalFollowerCnt(followerCnt);
+//
+//				followTraderProfitInfoDao.updateById(traderInfoProfit);
+//			}
+//		}
+//	}
 
 }
diff --git a/src/test/java/com/xcong/excoin/WholeTest.java b/src/test/java/com/xcong/excoin/WholeTest.java
index 1123b19..f993ff9 100644
--- a/src/test/java/com/xcong/excoin/WholeTest.java
+++ b/src/test/java/com/xcong/excoin/WholeTest.java
@@ -201,9 +201,9 @@
     @Test
     public void wholeForceNewTest() {
         MemberEntity memberEntity = memberDao.selectById(15L);
-        ContractHoldOrderEntity holdOrder = contractHoldOrderDao.selectById(400L);
+        ContractHoldOrderEntity holdOrder = contractHoldOrderDao.selectById(724L);
 
-        System.out.println(CalculateUtil.calForcePriceForWhole(memberEntity, holdOrder));
+        System.out.println(CalculateUtil.calWholePriceTwo(memberEntity, holdOrder));
     }
 
 }

--
Gitblit v1.9.1