| | |
| | | if code == '600066': |
| | | print('进入调试') |
| | | # 昨日收盘价 |
| | | price_close = gpcode_manager.get_price_pre_cache(code) |
| | | price_close = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) |
| | | max_price = tool.to_price(decimal.Decimal(str(price_close)) * decimal.Decimal("1.1")) |
| | | min_price = tool.to_price(decimal.Decimal(str(price_close)) * decimal.Decimal("0.9")) |
| | | if min_price <= decimal.Decimal(str(price)) <= max_price: |
| | |
| | | return max60, yesterday |
| | | |
| | | |
| | | __today_volumn_cache = {} |
| | | |
| | | |
| | | # 量的变化大保存 |
| | | |
| | | # 设置今日量 |
| | | def set_today_volumn(code, volumn): |
| | | logger_day_volumn.info("code:{} volumn:{}".format(code, volumn)) |
| | | redis = __redis_manager.getRedis() |
| | | global_util.today_volumn[code] = volumn |
| | | # 有1000手的变化才保存 |
| | | if code in __today_volumn_cache and volumn - __today_volumn_cache[code] < 100000: |
| | | return |
| | | __today_volumn_cache[code] = volumn |
| | | redis = __redis_manager.getRedis() |
| | | RedisUtils.setex(redis, "volumn_today-{}".format(code), tool.get_expire(), volumn) |
| | | |
| | | |
| | |
| | | volumes_data) |
| | | except Exception as e: |
| | | logger_first_code_record.error(f"{code}:{str(e)}") |
| | | gpcode_manager.FirstCodeManager.add_record(codes) |
| | | gpcode_manager.FirstCodeManager().add_record(codes) |
| | | # 初始化板块信息 |
| | | for code in codes: |
| | | block_info.init_code(code) |
| | |
| | | limit_up_time = tool.get_now_time_str() |
| | | if is_limit_up: |
| | | # 加入首板涨停 |
| | | gpcode_manager.FirstCodeManager.add_limited_up_record([code]) |
| | | pricePre = gpcode_manager.get_price_pre_cache(code) |
| | | gpcode_manager.FirstCodeManager().add_limited_up_record([code]) |
| | | pricePre = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) |
| | | if pricePre is None: |
| | | inited_data.re_set_price_pres([code]) |
| | | |
| | |
| | | return __redisManager.getRedis() |
| | | |
| | | |
| | | __first_code_data_cache = {} |
| | | |
| | | |
| | | # 保存首板票的数据 |
| | | # 1.首次涨停时间 |
| | | # 2.最近涨停时间 |
| | |
| | | # 4.最近炸开时间 |
| | | # 5.是否已经涨停 |
| | | def __save_first_code_data(code, data): |
| | | tool.CodeDataCacheUtil.set_cache(__first_code_data_cache, code, data) |
| | | RedisUtils.setex(__redisManager.getRedis(), f"first_code_data-{code}", tool.get_expire(), json.dumps(data)) |
| | | |
| | | |
| | |
| | | if val is None: |
| | | return None |
| | | return json.loads(val) |
| | | |
| | | |
| | | def __get_first_code_data_cache(code): |
| | | cache_result = tool.CodeDataCacheUtil.get_cache(__first_code_data_cache, code) |
| | | if cache_result[0]: |
| | | return cache_result[1] |
| | | val = __get_first_code_data(code) |
| | | tool.CodeDataCacheUtil.set_cache(__first_code_data_cache, code, val) |
| | | return val |
| | | |
| | | |
| | | # 添加进首板未筛选票 |
| | |
| | | for price in prices: |
| | | code = price["code"] |
| | | time_ = price["time"] |
| | | old_data = __get_first_code_data(code) |
| | | old_data = __get_first_code_data_cache(code) |
| | | if old_data is None: |
| | | continue |
| | | limit_up = price["limit_up"] |
| | |
| | | |
| | | # 首板代码管理 |
| | | class FirstCodeManager: |
| | | redisManager = redis_manager.RedisManager(0) |
| | | __instance = None |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.redisManager.getRedis() |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(FirstCodeManager, cls).__new__(cls, *args, **kwargs) |
| | | # 初始化设置 |
| | | # 获取交易窗口的锁 |
| | | cls.__instance.redisManager = redis_manager.RedisManager(0) |
| | | cls.__instance.__first_code_record_cache = RedisUtils.smembers(cls.__instance.__get_redis(), |
| | | "first_code_record") |
| | | cls.__instance.__first_code_limited_up_record_cache = RedisUtils.smembers(cls.__instance.__get_redis(), |
| | | "first_code_limited_up_record") |
| | | return cls.__instance |
| | | |
| | | def __get_redis(self): |
| | | return self.redisManager.getRedis() |
| | | |
| | | # 加入首板历史记录 |
| | | @classmethod |
| | | def add_record(cls, codes): |
| | | def add_record(self, codes): |
| | | hasChanged = False |
| | | for code in codes: |
| | | RedisUtils.sadd(cls.__get_redis(), "first_code_record", code) |
| | | RedisUtils.expire(cls.__get_redis(), "first_code_record", tool.get_expire()) |
| | | if code not in self.__first_code_record_cache: |
| | | RedisUtils.sadd(self.__get_redis(), "first_code_record", code) |
| | | hasChanged = True |
| | | self.__first_code_record_cache.add(code) |
| | | if hasChanged: |
| | | RedisUtils.expire(self.__get_redis(), "first_code_record", tool.get_expire()) |
| | | |
| | | @classmethod |
| | | def is_in_first_record(cls, code): |
| | | if RedisUtils.sismember(cls.__get_redis(), "first_code_record", code): |
| | | def is_in_first_record(self, code): |
| | | if RedisUtils.sismember(self.__get_redis(), "first_code_record", code): |
| | | return True |
| | | else: |
| | | return False |
| | | |
| | | def is_in_first_record_cache(self, code): |
| | | return code in self.__first_code_record_cache |
| | | |
| | | # 加入首板涨停过代码集合 |
| | | @classmethod |
| | | def add_limited_up_record(cls, codes): |
| | | def add_limited_up_record(self, codes): |
| | | hasChanged = False |
| | | for code in codes: |
| | | RedisUtils.sadd(cls.__get_redis(), "first_code_limited_up_record", code) |
| | | RedisUtils.expire(cls.__get_redis(), "first_code_limited_up_record", tool.get_expire()) |
| | | if code not in self.__first_code_limited_up_record_cache: |
| | | RedisUtils.sadd(self.__get_redis(), "first_code_limited_up_record", code) |
| | | hasChanged = True |
| | | self.__first_code_limited_up_record_cache.add(code) |
| | | if hasChanged: |
| | | RedisUtils.expire(self.__get_redis(), "first_code_limited_up_record", tool.get_expire()) |
| | | |
| | | # 是否涨停过 |
| | | @classmethod |
| | | def is_limited_up(cls, code): |
| | | if RedisUtils.sismember(cls.__get_redis(), "first_code_limited_up_record", code): |
| | | def is_limited_up(self, code): |
| | | if RedisUtils.sismember(self.__get_redis(), "first_code_limited_up_record", code): |
| | | return True |
| | | else: |
| | | return False |
| | | |
| | | def is_limited_up_cache(self, code): |
| | | return code in self.__first_code_limited_up_record_cache |
| | | |
| | | |
| | | # 想要买的代码 |
| | |
| | | return list |
| | | |
| | | |
| | | # 获取收盘价 |
| | | def get_price_pre(code): |
| | | redis_instance = __redisManager.getRedis() |
| | | result = RedisUtils.get(redis_instance, "price-pre-{}".format(code)) |
| | | if result is not None: |
| | | return float(result) |
| | | return None |
| | | class CodePrePriceManager: |
| | | __price_pre_cache = {} |
| | | __redisManager = redis_manager.RedisManager(0) |
| | | |
| | | # 获取收盘价 |
| | | @classmethod |
| | | def get_price_pre(cls, code): |
| | | redis_instance = cls.__redisManager.getRedis() |
| | | result = RedisUtils.get(redis_instance, "price-pre-{}".format(code)) |
| | | if result is not None: |
| | | return float(result) |
| | | return None |
| | | |
| | | __price_pre_cache = {} |
| | | # 获取缓存 |
| | | @classmethod |
| | | def get_price_pre_cache(cls, code): |
| | | if code in cls.__price_pre_cache: |
| | | return cls.__price_pre_cache[code] |
| | | val = cls.get_price_pre(code) |
| | | if val: |
| | | cls.__price_pre_cache[code] = val |
| | | return val |
| | | |
| | | |
| | | # 获取缓存 |
| | | def get_price_pre_cache(code): |
| | | if code in __price_pre_cache: |
| | | return __price_pre_cache[code] |
| | | val = get_price_pre(code) |
| | | if val: |
| | | __price_pre_cache[code] = val |
| | | return val |
| | | |
| | | |
| | | # 设置收盘价 |
| | | def set_price_pre(code, price, force=False): |
| | | codes = get_gp_list() |
| | | if code not in codes and not FirstCodeManager.is_in_first_record(code) and not force: |
| | | return |
| | | redis_instance = __redisManager.getRedis() |
| | | RedisUtils.setex(redis_instance, "price-pre-{}".format(code), tool.get_expire(), str(price)) |
| | | # 设置收盘价 |
| | | @classmethod |
| | | def set_price_pre(cls, code, price, force=False): |
| | | codes = get_gp_list() |
| | | if code not in codes and not FirstCodeManager().is_in_first_record_cache(code) and not force: |
| | | return |
| | | redis_instance = cls.__redisManager.getRedis() |
| | | RedisUtils.setex(redis_instance, "price-pre-{}".format(code), tool.get_expire(), str(price)) |
| | | cls.__price_pre_cache[code] = price |
| | | |
| | | |
| | | __limit_up_price_dict = {} |
| | |
| | | # 读取内存中的值 |
| | | if code in __limit_up_price_dict: |
| | | return __limit_up_price_dict[code] |
| | | price = get_price_pre_cache(code) |
| | | price = CodePrePriceManager.get_price_pre_cache(code) |
| | | if price is None: |
| | | return None |
| | | limit_up_price = tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal("1.1")) |
| | |
| | | |
| | | # 获取跌停价 |
| | | def get_limit_down_price(code): |
| | | price = get_price_pre_cache(code) |
| | | price = CodePrePriceManager.get_price_pre_cache(code) |
| | | if price is None: |
| | | return None |
| | | return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal("0.9")) |
| | |
| | | pre_close = tool.to_price(decimal.Decimal(str(item['pre_close']))) |
| | | if sec_level == 1: |
| | | if symbol in codes: |
| | | gpcode_manager.set_price_pre(symbol, pre_close) |
| | | gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close) |
| | | else: |
| | | gpcode_manager.rm_gp(symbol) |
| | | |
| | |
| | | symbol = item['symbol'] |
| | | symbol = symbol.split(".")[1] |
| | | pre_close = tool.to_price(decimal.Decimal(str(item['pre_close']))) |
| | | gpcode_manager.set_price_pre(symbol, pre_close, force) |
| | | gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close, force) |
| | | |
| | | |
| | | __prices_now = {} |
| | |
| | | __redisManager = redis_manager.RedisManager(1) |
| | | __latest_data = {} |
| | | __current_buy_1_price = {} |
| | | __buy1_price_info_cache = {} |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | |
| | | # 保存买1价格信息 |
| | | @classmethod |
| | | def __save_buy1_price_info(cls, code, limit_up_time, open_limit_up_time): |
| | | RedisUtils.setex(cls.__get_redis(),f"buy1_price_limit_up_info-{code}", tool.get_expire(), |
| | | json.dumps((limit_up_time, open_limit_up_time))) |
| | | tool.CodeDataCacheUtil.set_cache(cls.__buy1_price_info_cache, code, (limit_up_time, open_limit_up_time)) |
| | | RedisUtils.setex(cls.__get_redis(), f"buy1_price_limit_up_info-{code}", tool.get_expire(), |
| | | json.dumps((limit_up_time, open_limit_up_time))) |
| | | |
| | | @classmethod |
| | | def __get_buy1_price_info(cls, code): |
| | |
| | | return data[0], data[1] |
| | | |
| | | @classmethod |
| | | def __get_buy1_price_info_cache(cls, code): |
| | | cache_result = tool.CodeDataCacheUtil.get_cache(cls.__buy1_price_info_cache, code) |
| | | if cache_result[0]: |
| | | return cache_result[1] |
| | | val = cls.__get_buy1_price_info(code) |
| | | tool.CodeDataCacheUtil.set_cache(cls.__buy1_price_info_cache, code, val) |
| | | return val |
| | | |
| | | @classmethod |
| | | def __save_buy1_price(cls, code, buy_1_price): |
| | | cls.__current_buy_1_price[code] = buy_1_price |
| | | RedisUtils.setex(cls.__get_redis(),f"buy1_price-{code}", tool.get_expire(), buy_1_price) |
| | | RedisUtils.setex(cls.__get_redis(), f"buy1_price-{code}", tool.get_expire(), buy_1_price) |
| | | |
| | | @classmethod |
| | | def __get_buy1_price(cls, code): |
| | |
| | | # 设置炸板后的最低价 |
| | | @classmethod |
| | | def __save_open_limit_up_lowest_price(cls, code, price): |
| | | RedisUtils.setex(cls.__get_redis(),f"open_limit_up_lowest_price-{code}", tool.get_expire(), f"{price}") |
| | | RedisUtils.setex(cls.__get_redis(), f"open_limit_up_lowest_price-{code}", tool.get_expire(), f"{price}") |
| | | |
| | | @classmethod |
| | | def __get_open_limit_up_lowest_price(cls, code): |
| | |
| | | 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) |
| | | old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info_cache(code) |
| | | if old_limit_up_time and old_open_limit_up_time: |
| | | return |
| | | if is_limit_up and old_limit_up_time is None and float(sell_1_price) < 0.1 and int(sell_1_volumn) <= 0: |
| | |
| | | # 是否可以下单 |
| | | @classmethod |
| | | def is_can_buy(cls, code): |
| | | old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info(code) |
| | | old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info_cache(code) |
| | | if old_limit_up_time and old_open_limit_up_time: |
| | | return True |
| | | return False |
| | |
| | | # 返回涨停时间与炸板时间 |
| | | @classmethod |
| | | def get_limit_up_info(cls, code): |
| | | old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info(code) |
| | | old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info_cache(code) |
| | | return old_limit_up_time, old_open_limit_up_time |
| | | |
| | | # 设置涨停时间 |
| | |
| | | |
| | | if len(add_datas) > 0: |
| | | # 是否为首板代码 |
| | | is_first_code = True # gpcode_manager.FirstCodeManager.is_in_first_record(code) |
| | | is_first_code = True # gpcode_manager.FirstCodeManager().is_in_first_record(code) |
| | | # 计算量 |
| | | volume_rate = code_volumn_manager.get_volume_rate(code) |
| | | volume_rate_index = code_volumn_manager.get_volume_rate_index(volume_rate) |
| | |
| | | return False, True, f"今日已禁止交易" |
| | | # 之前的代码 |
| | | # 首板代码且尚未涨停过的不能下单 |
| | | # is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |
| | | # is_limited_up = gpcode_manager.FirstCodeManager().is_limited_up(code) |
| | | # if not is_limited_up: |
| | | # gpcode_manager.FirstCodeManager.add_limited_up_record([code]) |
| | | # gpcode_manager.FirstCodeManager().add_limited_up_record([code]) |
| | | # place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count( |
| | | # code) |
| | | # if place_order_count == 0: |
| | |
| | | return False, True, f"自由流通200亿以上,买1剩余档数大于10档,买一({buy1_price})涨停({limit_up_price})" |
| | | |
| | | open_limit_up_lowest_price = code_price_manager.Buy1PriceManager.get_open_limit_up_lowest_price(code) |
| | | price_pre_close = gpcode_manager.get_price_pre_cache(code) |
| | | price_pre_close = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) |
| | | if open_limit_up_lowest_price and ( |
| | | float(open_limit_up_lowest_price) - price_pre_close) / price_pre_close < 0.05: |
| | | return False, True, f"炸板后最低价跌至5%以下" |
| | |
| | | |
| | | _start_time = t.time() |
| | | total_datas = local_today_datas[code] |
| | | is_first_code = gpcode_manager.FirstCodeManager.is_in_first_record(code) |
| | | is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code) |
| | | |
| | | buy_nums = origin_num |
| | | buy_count = origin_count |
| | |
| | | } |
| | | |
| | | day = tool.get_now_date_str() |
| | | is_target_code = gpcode_manager.FirstCodeManager.is_in_first_record(code) |
| | | is_target_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code) |
| | | code_extra_infos = [] |
| | | if l2_trade_util.BlackListCodeManager.is_in_cache(code): |
| | | code_extra_infos.append("黑名单") |
| | |
| | | code, price = d["code"], float(d["price"]) |
| | | gpcode_manager.set_price(code, price) |
| | | # 获取收盘价 |
| | | pricePre = gpcode_manager.get_price_pre_cache(code) |
| | | pricePre = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) |
| | | if pricePre is not None: |
| | | rate = round((price - pricePre) * 100 / pricePre, 2) |
| | | if first_codes and code in first_codes: |
| | |
| | | } |
| | | # 将代码本身的信息包含进去 |
| | | hot_block["limit_up_codes_count"] = hot_block["limit_up_codes_count"] + 1 |
| | | pre_close_price = gpcode_manager.get_price_pre_cache(code) |
| | | pre_close_price = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) |
| | | hot_block["block_codes_rates_info"] = ( |
| | | hot_block["block_codes_rates_info"][0] + round((limit_price - pre_close_price) * 100 / pre_close_price, 2), |
| | | hot_block["block_codes_rates_info"][1] + 1) |