| | |
| | | |
| | | import tool |
| | | from db import redis_manager |
| | | from log import logger_trade_queue_price_info |
| | | |
| | | |
| | | class Buy1PriceManager: |
| | | __redisManager = redis_manager.RedisManager(1) |
| | | __latest_data = {} |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | |
| | | |
| | | # 处理 |
| | | @classmethod |
| | | def process(cls, code, buy_1_price, time_str, limit_up_price): |
| | | def process(cls, code, buy_1_price, time_str, limit_up_price, sell_1_price, sell_1_volumn): |
| | | data_str = f"{buy_1_price},{time_str},{limit_up_price},{sell_1_price},{sell_1_volumn}" |
| | | if cls.__latest_data.get(code) == data_str: |
| | | return |
| | | cls.__latest_data[code] = data_str |
| | | # 记录日志 |
| | | logger_trade_queue_price_info.info( |
| | | f"code={code} data: time_str-{time_str}, buy_1_price-{buy_1_price},limit_up_price-{limit_up_price},sell_1_price-{sell_1_price},sell_1_volumn-{sell_1_volumn}") |
| | | # 买1价格不能小于1块 |
| | | if float(buy_1_price) < 1.0: |
| | | return |
| | | |
| | | is_limit_up = abs(float(limit_up_price) - float(buy_1_price)) < 0.01 |
| | | old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info(code) |
| | | if old_limit_up_time and old_open_limit_up_time: |
| | | return |
| | | if is_limit_up and old_limit_up_time is None: |
| | | if is_limit_up and old_limit_up_time is None and float(sell_1_price) < 0.1 and int(sell_1_volumn) <= 0: |
| | | # 卖1消失,买1为涨停价则表示涨停 |
| | | cls.__save_buy1_price_info(code, time_str, None) |
| | | elif old_limit_up_time and not is_limit_up and old_open_limit_up_time is None: |
| | | # 有涨停时间,当前没有涨停,之前没有打开涨停 |
| | |
| | | # 获取涨停信息 |
| | | # 返回涨停时间与炸板时间 |
| | | @classmethod |
| | | def get_limit_up_info(cls,code): |
| | | def get_limit_up_info(cls, code): |
| | | old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info(code) |
| | | return old_limit_up_time, old_open_limit_up_time |
| | | |
| | | |
| | | # 设置涨停时间 |
| | | @classmethod |
| | | def set_limit_up_time(cls, code, time_str): |
| | | limit_up_time, open_limit_up_time = cls.get_limit_up_info(code) |
| | | if limit_up_time is None: |
| | | cls.__save_buy1_price_info(code, time_str, None) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | code = "000333" |
| | | limit_up_price = "54.00" |
| | | Buy1PriceManager.process("000333", "53.00", "09:56:00", limit_up_price) |
| | | print(Buy1PriceManager.is_can_buy(code)) |
| | | Buy1PriceManager.process("000333", "54.00", "09:57:00", limit_up_price) |
| | | print(Buy1PriceManager.is_can_buy(code)) |
| | | Buy1PriceManager.process("000333", "53.00", "09:58:00", limit_up_price) |
| | | print(Buy1PriceManager.is_can_buy(code)) |
| | | Buy1PriceManager.process("000333", "54.00", "09:59:00", limit_up_price) |
| | | print(Buy1PriceManager.is_can_buy(code)) |
| | | print(Buy1PriceManager.get_limit_up_info("002777")) |