from utils import tool class TickDataProcess: # 最高价 __highest_price_infos = {} @classmethod def init_origin_price(cls, code, price, rate_percent): cls.__highest_price_infos[code] = ("09:25:00", price, rate_percent) # 价格信息(时间,现价,涨幅) # return 是否减仓 @classmethod def process_tick_data(cls, code, time_str, price, rate_percent, max_amplitude_rate_percent=1): # 非交易时间 if tool.trade_time_sub(time_str, "09:30:00") < 0: return False now_price_info = (time_str, price, rate_percent) # 如果比最高价高就取最高价 if code not in cls.__highest_price_infos: cls.__highest_price_infos[code] = now_price_info if cls.__highest_price_infos.get(code)[2] < now_price_info[2]: cls.__highest_price_infos[code] = now_price_info else: # 低于最高点阈值 if cls.__highest_price_infos.get(code)[2] - now_price_info[2] > max_amplitude_rate_percent: # 触发卖 cls.__highest_price_infos[code] = now_price_info return True return False @classmethod def clear(cls, code): if code in cls.__highest_price_infos: cls.__highest_price_infos.pop(code)