| | |
| | | RedisUtils.delete_async(self.__db, k) |
| | | |
| | | |
| | | # 涨幅过高的票管理 |
| | | class HighIncreaseCodeManager: |
| | | __db = 0 |
| | | __instance = None |
| | | __redis_manager = redis_manager.RedisManager(0) |
| | | __high_increase_codes = set() |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(HighIncreaseCodeManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_datas() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __load_datas(cls): |
| | | __redis = cls.__get_redis() |
| | | try: |
| | | cls.__high_increase_codes = RedisUtils.smembers(__redis, "high_increase_codes") |
| | | finally: |
| | | RedisUtils.realse(__redis) |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.__redis_manager.getRedis() |
| | | |
| | | def add_code(self, code): |
| | | if self.__high_increase_codes is None: |
| | | self.__high_increase_codes = set() |
| | | self.__high_increase_codes.add(code) |
| | | RedisUtils.sadd_async(self.__db, "high_increase_codes", code) |
| | | RedisUtils.expire_async(self.__db, "high_increase_codes", tool.get_expire()) |
| | | |
| | | def is_in(self, code): |
| | | return code in self.__high_increase_codes |
| | | |
| | | # 加载全部 |
| | | def list_all(self): |
| | | return self.__high_increase_codes |
| | | |
| | | def clear(self): |
| | | if self.__high_increase_codes: |
| | | self.__high_increase_codes.clear() |
| | | RedisUtils.delete_async(self.__db, "high_increase_codes") |
| | | |
| | | |
| | | # 设置历史K线 |
| | | def set_record_datas(code, limit_up_price, record_datas): |
| | | k_format = get_k_format(float(limit_up_price), record_datas) |
| | |
| | | for t in temp_datas: |
| | | if t[1]: |
| | | t_count += 1 |
| | | if t_count >= 3 and limit_down_rate < 0.2: |
| | | if t_count >= 3 and limit_down_rate < 0.15: |
| | | # 降幅小于20% |
| | | return True |
| | | |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | print(CodeNatureRecordManager.get_k_format("603717")) |
| | | HighIncreaseCodeManager().add_code("000333") |
| | | print(HighIncreaseCodeManager().is_in("000333")) |
| | | print(HighIncreaseCodeManager().is_in("000222")) |
| | | |
| | |
| | | from code_attribute import gpcode_manager, gpcode_first_screen_manager, code_nature_analyse, \ |
| | | code_volumn_manager |
| | | from code_attribute.code_data_util import ZYLTGBUtil |
| | | from code_attribute.code_nature_analyse import HighIncreaseCodeManager |
| | | from log_module.log import logger_first_code_record, logger_l2_codes_subscript |
| | | from third_data.code_plate_key_manager import CodesHisReasonAndBlocksManager |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | |
| | | if code_nature_analyse.is_up_too_high_in_10d(volumes_data): |
| | | # 判断是否太高 |
| | | l2_trade_util.forbidden_trade(code, "股价长得太高") |
| | | HighIncreaseCodeManager().add_code(code) |
| | | |
| | | if code_nature_analyse.is_up_too_high_in_120d(volumes_data): |
| | | # 判断是否太高 |
| | | l2_trade_util.forbidden_trade(code, "120天内股价长得太高") |
| | | HighIncreaseCodeManager().add_code(code) |
| | | |
| | | if code_nature_analyse.is_have_latest_max_volume(volumes_data, 2): |
| | | # 最近2天是否是最高量 |
| | |
| | | return break_time, records_new, records_new_data |
| | | |
| | | |
| | | # 返回内容[(类型,buy_single_index,indexes)] |
| | | def load_trade_record_cancel_watch_indexes(code, cancel_type=None): |
| | | fresults = [] |
| | | records = [] |
| | | try: |
| | | records = log_export.load_trade_recod(code) |
| | | except: |
| | | pass |
| | | if records: |
| | | for record in records: |
| | | time_ = record[0] |
| | | type = record[1] |
| | | data = record[2] |
| | | if type == trade_record_log_util.TYPE_CANCEL_WATCH_INDEXES: |
| | | indexes = data['watch_indexes'] |
| | | if indexes: |
| | | if cancel_type and cancel_type != data.get("cancel_type"): |
| | | continue |
| | | fresults.append((data.get("cancel_type"), data.get('buy_single_index'), indexes)) |
| | | return fresults |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | code = '002786' |
| | | l2_data_util.load_l2_data(code) |
| | | print(__load_trade_record(code, l2_data_util.local_today_datas.get(code))) |
| | | code = '000670' |
| | | fresults = load_trade_record_cancel_watch_indexes(code) |
| | | print(fresults) |
| | |
| | | import json |
| | | |
| | | import constant |
| | | from code_attribute.code_nature_analyse import HighIncreaseCodeManager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from third_data import kpl_block_util, kpl_api |
| | | from utils import global_util, tool |
| | |
| | | if not self.get_jx_blocks_cache(code): |
| | | blocks = kpl_api.getCodeJingXuanBlocks(code) |
| | | self.save_jx_blocks(code, blocks) |
| | | async_log_util.info(logger_kpl_block_can_buy,f"{code}:获取到精选板块-{blocks}") |
| | | async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块-{blocks}") |
| | | elif price_rate > 0.03: |
| | | # 添加备用板块 |
| | | if not self.get_jx_blocks_cache(code, by=True): |
| | | blocks = kpl_api.getCodeJingXuanBlocks(code) |
| | | self.save_jx_blocks(code, blocks, by=True) |
| | | async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(备用)-{blocks}") |
| | | |
| | | |
| | | |
| | | # 开盘啦禁止交易板块管理 |
| | |
| | | # msg_list.append(f"\n实时top10(涨停数量:{len(current_limit_up_datas)})") |
| | | # msg_list.append(f"历史top20(涨停数量:{len(top_8_record)})") |
| | | |
| | | # 需要排除的代码 |
| | | exclude_codes = HighIncreaseCodeManager().list_all() |
| | | |
| | | # 获取主板实时身位,剔除高位板 |
| | | current_shsz_rank, front_current_shsz_rank_codes = kpl_block_util.get_code_current_rank(code, block, |
| | | current_limit_up_datas, |
| | | code_limit_up_reason_dict, |
| | | yesterday_current_limit_up_codes, |
| | | exclude_codes, |
| | | shsz=True) |
| | | record_shsz_rank, record_shsz_rank_codes = kpl_block_util.get_code_record_rank(code, block, |
| | | limit_up_record_datas, |
| | |
| | | yesterday_current_limit_up_codes, |
| | | shsz=True) |
| | | # 获取主板历史身位 |
| | | |
| | | open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas, |
| | | code_limit_up_reason_dict) |
| | | if open_limit_up_codes: |
| | |
| | | from urllib.parse import parse_qs |
| | | from output import code_info_output, limit_up_data_filter, output_util, kp_client_msg_manager |
| | | |
| | | from trade import bidding_money_manager, trade_manager, l2_trade_util |
| | | from trade import bidding_money_manager, trade_manager, l2_trade_util, trade_record_log_util |
| | | from trade.l2_trade_util import BlackListCodeManager |
| | | import concurrent.futures |
| | | |
| | |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | code = ps_dict['code'] |
| | | trade_progress, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code) |
| | | datas = data_export_util.get_l2_datas(code) |
| | | response_data = json.dumps( |
| | | {"code": 0, "data": {"trade_progress": trade_progress, "is_default": is_default}}) |
| | | elif url.path == "/get_l_cancel_datas": |
| | | # 最新的l撤数据 |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | code = ps_dict['code'] |
| | | records = code_info_output.load_trade_record_cancel_watch_indexes(code) |
| | | # 获取最新的L上与L下 |
| | | records.reverse() |
| | | up_indexes = [] |
| | | down_indexes = [] |
| | | for r in records: |
| | | if r[0] == trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_UP: |
| | | up_indexes = r[2] |
| | | break |
| | | for r in records: |
| | | if r[0] == trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN: |
| | | down_indexes = r[2] |
| | | break |
| | | |
| | | response_data = json.dumps( |
| | | {"code": 0, "data": {"up": up_indexes, "down": down_indexes}}) |
| | | elif url.path == "/get_h_cancel_datas": |
| | | # 最新的H撤数据 |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | code = ps_dict['code'] |
| | | records = code_info_output.load_trade_record_cancel_watch_indexes(code, |
| | | trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_H) |
| | | # 获取最新的L上与L下 |
| | | records.reverse() |
| | | indexes = [] |
| | | for r in records: |
| | | indexes = r[2] |
| | | break |
| | | response_data = json.dumps( |
| | | {"code": 0, "data":indexes}) |
| | | elif url.path == "/kpl/get_limit_up_list": |
| | | response_data = self.__get_limit_up_list() |
| | | |
| | |
| | | # 获取当日实时身位 |
| | | # before_blocks_dict格式位{"代码":set("板块")} |
| | | def get_code_current_rank(code, block, current_limit_up_datas, code_limit_up_reason_dict, |
| | | yesterday_current_limit_up_codes, shsz=False): |
| | | yesterday_current_limit_up_codes, exclude_codes, shsz=False): |
| | | block_codes_infos = [] |
| | | limit_up_time = time.time() |
| | | for k in current_limit_up_datas: |
| | |
| | | if k[0] in yesterday_current_limit_up_codes: |
| | | continue |
| | | if code_limit_up_reason_dict.get(k[0]) == block: |
| | | if k[0] != code: |
| | | if k[0] != code and k[0] not in exclude_codes: |
| | | # 代码.涨停时间 |
| | | block_codes_infos.append((k[0], int(k[2]))) |
| | | block_codes_infos.append((code, limit_up_time)) |