admin
2025-06-10 568c763084b926a6f2d632b7ac65b9ec8280752f
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
import setting
import gm.api as gmapi
 
 
class JueJinApi:
    __previous_trading_date_cache = {}
 
    # 获取掘金参数
    @classmethod
    def getJueJinAccountInfo(cls):
        # strategy_id, token = setting.get_juejin_params()
        return "", "95a982ce-fc2d-11ec-8ff3-0a0027000010", "77fa387b37e9bc1586ae1135827e2ccb3e7cd4e4"
 
    @classmethod
    def get_juejin_code_list_with_prefix(cls, codes):
        list = []
        for d in codes:
            if d.find(".") > 0:
                list.append(d)
            elif d[0:2] == '00':
                list.append("SZSE.{}".format(d))
            elif d[0:2] == '60':
                list.append("SHSE.{}".format(d))
        return list
 
    @classmethod
    def get_gp_latest_info(cls, codes, fields=None):
        if not codes:
            return []
        symbols = cls.get_juejin_code_list_with_prefix(codes)
 
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        data = gmapi.get_instruments(symbols=",".join(symbols), fields=fields)
        return data
 
    @classmethod
    def get_history_tick_n(cls, code, count, fields=None, frequency="1d"):
        symbols = cls.get_juejin_code_list_with_prefix([code])
 
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        # 前除权
        results = gmapi.history_n(symbol=symbols[0], frequency=frequency, count=count, adjust=1, fields=fields)
        return results
 
    @classmethod
    def get_history_tick(cls, code, start_time, end_time, fields=None, frequency="1d"):
        symbols = cls.get_juejin_code_list_with_prefix([code])
 
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        # 前除权
        results = gmapi.history(symbol=symbols[0], frequency=frequency, start_time=start_time, end_time=end_time,
                                adjust=1, fields=fields)
        return results
 
    @classmethod
    def get_gp_current_info(cls, codes, fields=''):
        if not codes:
            return []
        symbols = cls.get_juejin_code_list_with_prefix(codes)
 
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        data = gmapi.current(symbols=",".join(symbols), fields=fields)
        return data
 
    # 获取交易所的代码
    @classmethod
    def get_exchanges_codes(cls, exchanges):
 
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        return gmapi.get_instruments(exchanges=exchanges, sec_types=[1], skip_suspended=True, skip_st=True,
                                     fields="symbol,sec_type,sec_id,sec_name,listed_date,sec_level,is_suspended,pre_close")
 
    @classmethod
    def get_previous_trading_date(cls, date):
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        return gmapi.get_previous_trading_date("SHSE", date)
 
    @classmethod
    def get_previous_trading_date_cache(cls, date):
        if date not in cls.__previous_trading_date_cache:
            pre_date = cls.get_previous_trading_date(date)
            if pre_date:
                cls.__previous_trading_date_cache[date] = pre_date
        return cls.__previous_trading_date_cache.get(date)
 
    # 返回指定日期的下个交易日
    @classmethod
    def get_next_trading_date(cls, date):
 
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        return gmapi.get_next_trading_date("SHSE", date)
 
    @classmethod
    def get_trading_dates(cls, start_date, end_date):
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        return gmapi.get_trading_dates("SHSE", start_date, end_date)
 
    @classmethod
    def get_codes(cls, sec_type):
        """
        代码获取
        :param sec_type: 8:可转债 1:股票
        :return:
        """
        account_id, s_id, token = cls.getJueJinAccountInfo()
        gmapi.set_token(token)
        return gmapi.get_instrumentinfos(exchanges="SHSE,SZSE", sec_types=[sec_type])
 
    @classmethod
    def get_underlying_code(cls, symbols):
        """
        获取可转债正股代码
        :param symbols: 如:[SZSE.128144]
        :return: 正股代码,如:[SZSE.002734]
        """
        account_id, s_id, token = JueJinApi.getJueJinAccountInfo()
        gmapi.set_token(token)
        datas = gmapi.get_instruments(symbols=",".join(symbols), sec_types="8",
                                      fields="symbol, sec_type, sec_id,sec_name, underlying_symbol")
        fdatas = {}
        for d in datas:
            fdatas[d['symbol']] = d['underlying_symbol']
        return fdatas
 
 
if __name__ == "__main__":
    print(JueJinApi.get_previous_trading_date("2024-12-31"))