Helius
2020-07-07 71006e38797a533a59ea3e5180157e70ede50795
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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;
 
    @Test
    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);
 
    }
}