xiaoyong931011
2020-06-03 d26eb4f2156a11335459f11cd72bc6924842f4d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.xcong.excoin.utils;
 
 
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity;
 
import java.math.BigDecimal;
 
/**
 * @author helius
 */
public class CalculateUtil {
 
    /**
     * 计算预估强平价
     *
     * @param bondAmount        保证金
     * @param openPrice       开仓价
     * @param symbolSkuNumber 张数
     * @param lotNumber       规格
     * @param type            1:买多2:卖空
     * @return
     */
    public static BigDecimal getForceSetPrice(BigDecimal bondAmount, BigDecimal openPrice, int symbolSkuNumber, BigDecimal lotNumber,
                                              int type, MemberEntity member) {
        CacheSettingUtils cacheSettingUtils = SpringContextHolder.getBean(CacheSettingUtils.class);
        PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting();
        BigDecimal forcePrice = BigDecimal.ZERO;
        BigDecimal money = bondAmount.divide(new BigDecimal(symbolSkuNumber).multiply(lotNumber), 8, BigDecimal.ROUND_DOWN);
        //卖空
        if (type == 2) {
            forcePrice = money.add(openPrice);
            if (member.getIsProfit() == 1) {
                //预估强平价 = 预估强平价-预估强平价*系数
                forcePrice = forcePrice.subtract(forcePrice.multiply(tradeSetting.getForceParam()));
            }
        } else {//开多
            forcePrice = openPrice.subtract(money);
            if (member.getIsProfit() == 1) {
                //预估强平价 = 预估强平价-预估强平价*系数
                forcePrice = forcePrice.add(forcePrice.multiply(tradeSetting.getForceParam()));
            }
        }
        if (forcePrice.compareTo(BigDecimal.ZERO) < 0) {
            forcePrice = BigDecimal.ZERO;
        }
        return forcePrice;
    }
}