| | |
| | | 自定义板块流入金额 |
| | | """ |
| | | import copy |
| | | import itertools |
| | | import os |
| | | |
| | | import constant |
| | | from db import mysql_data_delegate as mysql_data |
| | | from huaxin_client import l1_subscript_codes_manager |
| | | from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager |
| | | from third_data.third_blocks_manager import BlockMapManager |
| | |
| | | """ |
| | | 板块流入流出管理 |
| | | """ |
| | | |
| | | __mysql_db = mysql_data.Mysqldb() |
| | | __code_blocks = {} |
| | | |
| | | __in_list = [] |
| | | __out_list = [] |
| | | # 最近这段时间的代码涨停次数 |
| | | __history_code_limit_up_count = {} |
| | | # 被排除的代码 |
| | | __exclude_codes = set() |
| | | |
| | | def __load_codes(self): |
| | | codes = [] |
| | |
| | | fblocks -= constant.KPL_INVALID_BLOCKS |
| | | self.__code_blocks[code] = fblocks |
| | | |
| | | def __load_exclude_codes(self): |
| | | """ |
| | | 获取之前4个交易日的数据 |
| | | @return: |
| | | """ |
| | | max_day = tool.get_now_date_str() |
| | | min_day = tool.date_sub(max_day, 30) |
| | | sql = f"select * from (select distinct(r.`_day`) as 'day' from `kpl_limit_up_record` r where r.`_day`<'{max_day}' and r.`_day`>'{min_day}') a order by a.day desc limit 4" |
| | | results = self.__mysql_db.select_all(sql) |
| | | dates = [r[0] for r in results] |
| | | # 获取之前4天涨停次数>=2次的代码 |
| | | day_codes = {} |
| | | for day in dates: |
| | | sql = f"select distinct(r._code) from kpl_limit_up_record r where r.`_day`='{day}'" |
| | | results = self.__mysql_db.select_all(sql) |
| | | day_codes[day] = set([x[0] for x in results]) |
| | | codes_list = [day_codes[k] for k in day_codes] |
| | | # 统计代码的涨停天数 |
| | | code_limit_up_count_dict = {} |
| | | for codes in codes_list: |
| | | for c in codes: |
| | | if c not in code_limit_up_count_dict: |
| | | code_limit_up_count_dict[c] = 0 |
| | | code_limit_up_count_dict[c] += 1 |
| | | self.__history_code_limit_up_count = code_limit_up_count_dict |
| | | self.load_today_limit_up_codes() |
| | | |
| | | def load_today_limit_up_codes(self): |
| | | # 加载今日涨停代码 |
| | | day = tool.get_now_date_str() |
| | | sql = f"select distinct(r._code) from kpl_limit_up_record r where r.`_day`='{day}'" |
| | | results = self.__mysql_db.select_all(sql) |
| | | codes = set([x[0] for x in results]) |
| | | # 计算需要排除的代码 |
| | | temp_limit_up_count = {} |
| | | # 统计总共涨停天数 |
| | | for c in self.__history_code_limit_up_count: |
| | | if c in codes: |
| | | temp_limit_up_count[c] = self.__history_code_limit_up_count[c] + 1 |
| | | else: |
| | | temp_limit_up_count[c] = self.__history_code_limit_up_count[c] |
| | | exclude_codes = set() |
| | | for c in temp_limit_up_count: |
| | | if temp_limit_up_count[c] < 3: |
| | | continue |
| | | exclude_codes.add(c) |
| | | self.__exclude_codes = exclude_codes |
| | | |
| | | def __init__(self): |
| | | self.codes = self.__load_codes() |
| | | self.__load_blocks() |
| | | self.__load_exclude_codes() |
| | | print("排除的代码", self.__exclude_codes) |
| | | |
| | | def get_codes(self): |
| | | return self.codes |
| | |
| | | codes = self.codes |
| | | block_money = {} |
| | | for code in codes: |
| | | if code in self.__exclude_codes: |
| | | continue |
| | | money = CodeInMoneyManager().get_money(code) |
| | | if money is None: |
| | | continue |
| | |
| | | temp_list.sort(key=lambda x: x[1]) |
| | | self.__out_list = temp_list |
| | | |
| | | def get_block_codes_money(self, block): |
| | | """ |
| | | 获取板块中代码的流入流出 |
| | | @param block: |
| | | @return:(代码, 金额, 是否被排除) |
| | | """ |
| | | codes = self.codes |
| | | fdatas = [] |
| | | for code in codes: |
| | | if code in self.__exclude_codes: |
| | | continue |
| | | money = CodeInMoneyManager().get_money(code) |
| | | if money is None: |
| | | continue |
| | | before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) |
| | | if not before_fblocks: |
| | | before_fblocks = set() |
| | | fblocks = BlockMapManager().filter_blocks(before_fblocks) |
| | | if block not in fblocks: |
| | | continue |
| | | fdatas.append((code, money, code in self.__exclude_codes)) |
| | | return fdatas |
| | | |
| | | def get_in_list(self): |
| | | return self.__in_list |
| | | |
| | |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | print(CodeInMoneyManager().get_money("300264")) |
| | | BlockInMoneyRankManager() |
| | | # print(CodeInMoneyManager().get_money("300264")) |
| | | # BlockInMoneyRankManager().compute() |
| | | # print(BlockInMoneyRankManager().get_in_list()[:20]) |
| | | # print(BlockInMoneyRankManager().get_out_list()[:20]) |