"""
|
持仓代码数据管理
|
"""
|
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
|