1
zj
2024-07-15 3e94b30057748e7b89bf52185a98412882d8524e
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
package org.example.task;
 
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.example.common.MarketDataClient;
import org.example.pojo.Currency;
import org.example.pojo.ExchangeInfo;
import org.example.util.JsonUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
 
import static com.alibaba.druid.sql.ast.SQLPartitionValue.Operator.List;
 
/**
 * @program: demo
 * @description: mexc交易所
 * @create: 2024-07-15 17:22
 **/
@Component
@Slf4j
public class MexcStock {
 
    private final AtomicBoolean syncCurrency = new AtomicBoolean(false);
 
    private final Lock syncCurrencyLock = new ReentrantLock();
 
    /**
     * 同步mexc交易所交易对
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void syncCurrency() {
        if (syncCurrency.get()) {
            return;
        }
        if (syncCurrencyLock.tryLock()) {
            System.out.println("【同步mexc交易所交易对】---->开市");
            try {
                syncCurrency.set(true);
                sync();
            } catch (Exception e) {
                System.err.println("【同步mexc交易所交易对】出现异常: " + e.getMessage());
            } finally {
                syncCurrencyLock.unlock();
                syncCurrency.set(false);
                System.out.println("【同步mexc交易所交易对】---->结束");
            }
        }
    }
 
    public void sync() {
        HashMap<String, String> symbolParams = Maps.newHashMap(ImmutableMap.<String, String>builder()
                .build());
        String json = JsonUtil.toJson(exchangeInfo(symbolParams));
        Gson gson = new Gson();
        Map map = gson.fromJson(json, Map.class);
        String symbols = JsonUtil.toJson(map.get("symbols"));
        ArrayList arrayList = gson.fromJson(symbols, ArrayList.class);
    }
 
    public static ExchangeInfo exchangeInfo(Map<String, String> params) {
        return MarketDataClient.get("/api/v3/exchangeInfo", params, new TypeReference<ExchangeInfo>() {
        });
    }
 
}