1
zj
2025-07-17 7a9533c3d1bbf7342227284ea25df95b40d7cf77
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
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.stream.CollectorUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yami.trading.bean.data.domain.Kline;
import com.yami.trading.common.http.HttpHelper;
import org.apache.commons.codec.digest.DigestUtils;
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
 
 
public class Test {
 
    public static void main(String[] args) throws FileNotFoundException {
        String format = "Your verification code is 78948";
        String apiKey = "5PUIQ2KvNDeC6XfuS0Bl8g==";
        String apiSecret = "5981db6ff1f94264a88d8ead7b90c93e";
        String send_url = "https://api.i51sms.com/outauth/verifCodeSend";
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyyMMddHHmmss");
 
        Map<String,Object> param = new HashMap<>();
        param.put("apikey",apiKey);
        param.put("timestamp",dateFormat.format(date));
        param.put("sign", DigestUtils.md5Hex(apiKey+dateFormat.format(date)+apiSecret));
        param.put("mobile","12183966258");
        param.put("content",format);
        String s = HttpHelper.sendPostHttpSMS(send_url, param, true);
        System.out.println(s);
 
 
//        File file = new File("/Users/sentry/Desktop/work/workspace/trading-order/trading-order-admin/src/main/test/source.txt");
//        RandomAccessFile accessFile = new RandomAccessFile(file, "r");
//        String jsonStr = FileUtil.readLine(accessFile, Charset.defaultCharset());
//
//        JSONObject jsonObject = (JSONObject) JSON.parse(jsonStr);
//
//
//        JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("item");
//
//
//        List<Kline> klines = new ArrayList<>(jsonArray.size());
//        for (int i = 0; i < jsonArray.size(); i++) {
//            JSONArray item = (JSONArray) jsonArray.get(i);
//            Kline kline = new Kline();
//            Long timestamp = Long.valueOf(item.get(0).toString());
//            Double volume = Double.valueOf(item.get(1).toString());
//            Double open = Double.valueOf(item.get(2).toString());
//            Double high = Double.valueOf(item.get(3).toString());
//            Double low = Double.valueOf(item.get(4).toString());
//            Double close = Double.valueOf(item.get(5).toString());
//            kline.setTs(timestamp);
//            kline.setVolume(BigDecimal.valueOf(volume));
//            kline.setOpen(BigDecimal.valueOf(open));
//            kline.setHigh(BigDecimal.valueOf(high));
//            kline.setLow(BigDecimal.valueOf(low));
//            kline.setClose(BigDecimal.valueOf(close));
//            klines.add(kline);
//        }
//
//
//        List<Kline> collect = null;
//        int day = 0;
//        do {
//            long zore = zore(day);
//            collect = klines.stream().filter(k -> k.getTs() > zore).collect(Collectors.toList());
//            day ++;
//        } while (CollectionUtil.isEmpty(collect));
//
//        collect.sort(Kline::compareTo);
//
//
//        List<Kline> newklines = new ArrayList<>(collect.size());
//        Kline secondKline = null;
//        for (Kline kline : collect) {
//            List<BigDecimal> bigDecimals = splitBigDecimal(kline.getVolume(), 60,30);
//            BigDecimal open = secondKline == null ? kline.getOpen() : secondKline.getClose();
//            for (int i = 0; i < 60; i++) {
//                secondKline = new Kline();
//                secondKline.setTs(kline.getTs() + i * 1000);
//                secondKline.setOpen(open);
//                if (i == 59) {
//                    secondKline.setClose(kline.getClose());
//                } else {
//                    secondKline.setClose(randomBigDecimal(kline.getOpen(),kline.getClose()));
//                }
//                secondKline.setHigh(randomBigDecimal(secondKline.getClose(),kline.getHigh()));
//                secondKline.setLow(randomBigDecimal(kline.getLow(),secondKline.getClose()).min(secondKline.getOpen()));
//                secondKline.setVolume(bigDecimals.get(i));
//                open = secondKline.getClose();
//                newklines.add(secondKline);
//            }
//        }
//
//
//        List<List<Object>> result = new ArrayList<>();
//        List<String> time = new ArrayList<>();
//
//
//// 格式化时间
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//        for (Kline kline : newklines) {
//            List<Object> tmp = new ArrayList<>();
//            tmp.add(simpleDateFormat.format(new Date(kline.getTs())));
//            tmp.add(kline.getOpen().setScale(2, BigDecimal.ROUND_HALF_UP));
//            tmp.add(kline.getHigh().setScale(2, BigDecimal.ROUND_HALF_UP));
//            tmp.add(kline.getLow().setScale(2, BigDecimal.ROUND_HALF_UP));
//            tmp.add(kline.getClose().setScale(2, BigDecimal.ROUND_HALF_UP));
//            tmp.add(kline.getVolume().setScale(2, BigDecimal.ROUND_HALF_UP));
//            result.add(tmp);
//        }
//
////        System.out.println(JSON.toJSONString(time));
//
//        System.out.println(JSON.toJSONString(result));
    }
 
    public static long zore(int day) {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
 
        LocalDate localDate = currentDate.minusDays(day);
 
        // 获取当天0点的时间
        LocalDateTime zeroTime = LocalDateTime.of(localDate, LocalTime.MIDNIGHT);
 
        // 转换成时间戳
        long zeroTimestamp = zeroTime.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000;
 
        return zeroTimestamp;
    }
 
    public static BigDecimal randomBigDecimal(BigDecimal a, BigDecimal b) {
        BigDecimal diff = b.subtract(a);
        Random random = new Random();
        BigDecimal randNum = diff.multiply(new BigDecimal(random.nextDouble()));
        BigDecimal result = a.add(randNum);
        return result;
    }
 
 
    public static List<BigDecimal> splitBigDecimal(BigDecimal value, int numOfParts, double maxDifferencePercentage) {
        List<BigDecimal> parts = new ArrayList<>(numOfParts);
        Random random = new Random();
 
        BigDecimal remaining = value;
        BigDecimal minAllowedValue = value.multiply(BigDecimal.valueOf(1 - maxDifferencePercentage / 100)).divide(BigDecimal.valueOf(numOfParts), value.scale(), BigDecimal.ROUND_HALF_UP);
        BigDecimal maxAllowedValue = value.multiply(BigDecimal.valueOf(1 + maxDifferencePercentage / 100)).divide(BigDecimal.valueOf(numOfParts), value.scale(), BigDecimal.ROUND_HALF_UP);
 
        for (int i = 0; i < numOfParts - 1; i++) {
            BigDecimal part = getRandomBigDecimal(minAllowedValue, maxAllowedValue, random);
            while (remaining.subtract(part).compareTo(minAllowedValue.multiply(BigDecimal.valueOf(numOfParts - i - 1))) < 0) {
                part = getRandomBigDecimal(minAllowedValue, maxAllowedValue, random);
            }
            parts.add(part);
            remaining = remaining.subtract(part);
        }
 
        parts.add(remaining);
        return parts;
    }
 
    private static BigDecimal getRandomBigDecimal(BigDecimal min, BigDecimal max, Random random) {
        BigDecimal range = max.subtract(min);
        BigDecimal randomValue = range.multiply(new BigDecimal(random.nextDouble())).setScale(min.scale(), BigDecimal.ROUND_HALF_UP);
        return min.add(randomValue);
    }
}