Administrator
2025-06-12 4e5eed2226fae6a057c454155565211dbc9349e9
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
"""
持仓代码数据管理
"""
from code_atrribute.history_k_data_util import HistoryKDatasUtils
 
 
class PositionCodeDataManager:
    # 当前量
    __current_volume_dict = {}
    # 上个交易日的量
    __pre_day_volume_dict = {}
    #  现价
    __current_price_dict = {}
    # 当前买1数据
    __current_buy1_data_dict = {}
 
    @classmethod
    def set_current_l1_datas(cls, datas):
        """
        设置当前L1数据
        :param datas:[(代码,现价,涨幅,量,更新时间,买1价格,买1量)]
        :return:
        """
        if datas:
            for d in datas:
                code = d[0]
                price = d[1]
                buy1_price = d[5]
                volume = d[3]
                if not price or price <= 0.0:
                    price = buy1_price
                cls.__current_price_dict[code] = price
                cls.__current_buy1_data_dict[code] = (d[5], d[6])
                cls.__current_volume_dict[code] = volume
 
    # 获取L1现价
    @classmethod
    def get_l1_current_price(cls, code):
        return cls.__current_price_dict.get(code)
 
    @classmethod
    def get_l1_current_volume(cls, code):
        return cls.__current_volume_dict.get(code)
 
    @classmethod
    def get_l1_current_buy1_data(cls, code):
        return cls.__current_buy1_data_dict.get(code)
 
    @classmethod
    def get_pre_volume(cls, code):
        return cls.__pre_day_volume_dict.get(code)
 
    @classmethod
    def request_pre_volume(cls, code):
        # 获取前一天的量
        if code in cls.__pre_day_volume_dict:
            return
        bars = HistoryKDatasUtils.get_history_tick_n(code, 1)
        if bars:
            code = bars[0]['symbol'].split(".")[1]
            volume = bars[0]['volume']
            cls.__pre_day_volume_dict[code] = volume