Helius
2021-01-29 76676ab94016b4deab91d7b76c34c152dd5bcf03
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.xcong.excoin;
 
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.common.enumerates.RabbitPriceTypeEnum;
import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao;
import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity;
import com.xcong.excoin.modules.contract.service.RabbitOrderService;
import com.xcong.excoin.modules.member.dao.MemberDao;
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.rabbit.pricequeue.OrderModel;
import com.xcong.excoin.rabbit.pricequeue.OrderOperatePriceService;
import com.xcong.excoin.rabbit.pricequeue.WebsocketPriceService;
import com.xcong.excoin.rabbit.producer.OrderProducer;
import com.xcong.excoin.utils.CalculateUtil;
import com.xcong.excoin.utils.RedisUtils;
import com.xcong.excoin.utils.ThreadPoolUtils;
import lombok.SneakyThrows;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
/**
 * @author wzy
 * @date 2020-08-14
 **/
@SpringBootTest
public class WholeTest {
 
    @Resource
    private MemberDao memberDao;
    @Autowired
    private ContractHoldOrderDao contractHoldOrderDao;
 
    @Autowired
    private RabbitOrderService rabbitOrderService;
 
    @Autowired
    private MemberWalletContractDao memberWalletContractDao;
 
    @Test
    public void forceClosePriceTest() {
        MemberEntity memberEntity = memberDao.selectById(5L);
        try {
            CalculateUtil.getForceSetPriceForWhole("BTC/USDT", memberEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @Test
    public void closingOrderTest() {
        List<Long> ids = new ArrayList<>();
        ids.add(836L);
        rabbitOrderService.cancelHoldOrder(ids);
    }
 
    @Test
    public void wholeContractWalletTest() {
        List<MemberEntity> memberEntities = memberDao.selectAllMember();
        for (MemberEntity member : memberEntities) {
            CoinTypeEnum[] values = CoinTypeEnum.values();
            for (CoinTypeEnum value : values) {
                MemberWalletContractEntity walletContract = new MemberWalletContractEntity();
                if (value.name().equals(CoinTypeEnum.USDT.name())) {
                    continue;
                }
 
                walletContract.setMemberId(member.getId());
                walletContract.setAvailableBalance(AppContants.INIT_MONEY);
                walletContract.setFrozenBalance(AppContants.INIT_MONEY);
                walletContract.setTotalBalance(AppContants.INIT_MONEY);
                walletContract.setBorrowedFund(AppContants.INIT_MONEY);
                walletContract.setWalletCode(value.name());
                memberWalletContractDao.insert(walletContract);
            }
        }
    }
 
 
    @Test
    public void bondAmountTest() {
        BigDecimal openPrice = BigDecimal.valueOf(412.52124800);
 
        System.out.println(CalculateUtil.getBondAmount(openPrice, BigDecimal.valueOf(6), 1, 5));
    }
 
    @Autowired
    private OrderProducer orderProducer;
 
 
    // 面值*(多单张数*多单开仓价-空单张数*空单开仓价)-余额-已实现盈亏 / 面值*(多单张数-空单张数)-(维持保证金率+TAKER手续费)*面值*(开多张数+开空张数)
 
    /*
    面值 : 0.1000 * 678
    多单张数 : 300  开仓价 : 11400.53000000   -> 3420159
    空单张数 : 300  开仓价 : 11398.27000000   -> 3419481
    余额 : 562.92683993    -495.12
 
    手续费率 : 0.0460
 
 
     */
    @Test
    public void forceSetPriceTest() {
        MemberEntity memberEntity = memberDao.selectById(21L);
        CalculateUtil.getForceSetPriceForWhole("BTC/USDT", memberEntity);
    }
 
    @Resource
    private RedisUtils redisUtils;
 
    @Test
    public void redisTest() {
        for (int i = 827; i < 999; i++) {
            redisUtils.del(AppContants.CLOSING_ORDER_PREFIX + i);
        }
    }
 
    @Resource
    private WebsocketPriceService websocketPriceService;
 
    @Test
    public void wholeBombTest() {
        websocketPriceService.wholeBomb("BTC/USDT", "9000");
    }
 
    @Test
    public void forceTest() {
        MemberEntity memberEntity = memberDao.selectById(5L);
        CalculateUtil.getForceSetPriceForWhole(null, memberEntity);
    }
 
    public static void main(String[] args) {
        Map<String, String> map = new ConcurrentHashMap<>();
        map.put("1", "1");
        map.put("2", "2");
        map.put("3", "3");
        map.put("4", "4");
        map.put("5", "5");
 
        new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                for (Map.Entry<String, String> entry : map.entrySet()) {
                    System.out.println(entry.getKey() + " - " + entry.getValue());
                    if (entry.getKey().equals("3")) {
                        System.out.println(11);
                        map.remove("3");
                    }
                    Thread.sleep(1000);
                }
 
                System.out.println(map.get("3"));
            }
        }).start();
 
    }
 
    @Test
    public void mapTest() {
//        websocketPriceService.wholeBomb();
        OrderOperatePriceService.wholePriceDataOperation(63L);
    }
 
 
    @Test
    public void wholeForceTest() {
        // 8301.38608660
//        System.out.println(new BigDecimal("9925.29996175").subtract(new BigDecimal("1623.91387515")));
 
        BigDecimal aa = new BigDecimal("9925.29996175").subtract(new BigDecimal("8301.38608660").negate()).subtract(new BigDecimal("1623.91387515")).subtract(new BigDecimal("0.1").multiply(new BigDecimal(50)).multiply(new BigDecimal("32478.27750300")));
        BigDecimal bb = new BigDecimal(50).multiply(new BigDecimal("0.1"));
        BigDecimal divide = aa.divide(bb, 8, BigDecimal.ROUND_DOWN);
        System.out.println(divide);
        // -(账户权益-委托保证金-全仓维持保证金-全仓未实现盈利-数量*面值*开仓价格)/(数量*面值)
        // 30818.00028568 --
        // 29157.72306836 --
    }
 
}