| | |
| | | |
| | | |
| | | # 在最近几天内股价是否长得太高 |
| | | def is_price_too_high_in_days(record_datas, limit_up_price, day_count=6): |
| | | def is_price_too_high_in_days(record_datas, limit_up_price, day_count=5): |
| | | datas = copy.deepcopy(record_datas) |
| | | datas.sort(key=lambda x: x["bob"]) |
| | | datas = datas[0 - day_count:] |
| | |
| | | limit_up_time, open_limit_up_time = self.__get_buy1_price_limit_up_info_cache(code) |
| | | if limit_up_time and open_limit_up_time: |
| | | # 获取计算当前的涨幅 |
| | | pre_close_price = round(float(limit_up_price) / 1.1, 2) |
| | | if (float(buy_1_price) - pre_close_price) / pre_close_price < 0.05: |
| | | # 炸开且涨幅小于5% |
| | | l2_trade_util.forbidden_trade(code, "涨停炸开后现价涨幅小于5%之后不买") |
| | | async_log_util.info(logger_trade_queue_price_info, f"涨停炸开后现价涨幅小于5%之后不买:code-{code}") |
| | | # pre_close_price = round(float(limit_up_price) / 1.1, 2) |
| | | # if (float(buy_1_price) - pre_close_price) / pre_close_price < 0.05: |
| | | # # 炸开且涨幅小于5% |
| | | # l2_trade_util.forbidden_trade(code, "涨停炸开后现价涨幅小于5%之后不买") |
| | | # async_log_util.info(logger_trade_queue_price_info, f"涨停炸开后现价涨幅小于5%之后不买:code-{code}") |
| | | # 之前涨停过且现在尚未涨停 |
| | | self.set_open_limit_up_lowest_price(code, buy_1_price) |
| | | |
| | |
| | | from line_profiler import LineProfiler |
| | | |
| | | import constant |
| | | from code_attribute import global_data_loader, code_volumn_manager, first_target_code_data_processor |
| | | from code_attribute import global_data_loader, code_volumn_manager, first_target_code_data_processor, gpcode_manager |
| | | from code_attribute.code_data_util import ZYLTGBUtil |
| | | from db import redis_manager_delegate as redis_manager |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_l2_codes_subscript |
| | | from third_data import kpl_data_manager, kpl_api |
| | | from trade import current_price_process_manager |
| | | from utils import tool, global_util, socket_util |
| | | from utils import tool, global_util, socket_util, init_data_util |
| | | |
| | | redisManager = redis_manager.RedisManager(4) |
| | | l2_codes_queue = queue.Queue() |
| | |
| | | |
| | | # 根据华鑫L2选出目标代码 |
| | | class HuaXinL1TargetCodesManager: |
| | | |
| | | __current_price_dict = {} |
| | | |
| | | @classmethod |
| | |
| | | # 获取自由流通市值 |
| | | if code not in global_util.zyltgb_map: |
| | | try: |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if not limit_up_price: |
| | | init_data_util.re_set_price_pre(code, True) |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | __start_time = time.time() |
| | | zylt = kpl_api.getZYLTAmount(code) |
| | | async_log_util.info(logger_l2_codes_subscript, |
| | | f"{request_id} {code}获取自由流通市值耗时-{round((time.time() - __start_time) * 1000)}ms") |
| | | if zylt: |
| | | if limit_up_price: |
| | | zylt = int(zylt / d[1] * float(limit_up_price)) |
| | | # 保存自由流通股本 |
| | | ZYLTGBUtil.save_async(code, zylt // 10000, 1) |
| | | global_util.zyltgb_map[code] = int(zylt) |
| | |
| | | return False, True, f"自由流通200亿以上,买1剩余档数大于10档,买一({buy1_price})涨停({limit_up_price})" |
| | | |
| | | open_limit_up_lowest_price = cls.__Buy1PriceManager.get_open_limit_up_lowest_price(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%以下" |
| | | # 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%以下" |
| | | |
| | | # 回封的票,下13:15买入需要判断板块是否为独苗 |
| | | if open_limit_up_lowest_price and int(total_data[-1]["val"]["time"].replace(":", "")) > 131500: |
| | |
| | | |
| | | @classmethod |
| | | def can_buy_first(cls, code, limit_up_price): |
| | | now_timestamp = int(tool.get_now_time_str().replace(":", "")) |
| | | # 判断板块 |
| | | can_buy_result = cls.__get_can_buy_block(code) |
| | | l2_log.debug(code, "获取到的板块信息:{}", can_buy_result) |
| | | if can_buy_result is None: |
| | | return False, True, "尚未获取到板块信息" |
| | | if not can_buy_result[0] and can_buy_result[1]: |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | # 独苗 |
| | | return False, True, f"独苗不下单({can_buy_result[4]})" |
| | | if now_timestamp > int("100000"): |
| | | return False, True, f"独苗不下单({can_buy_result[4]}) 10点后不下单" |
| | | elif zyltgb < 10 * 100000000 or zyltgb > 20 * 100000000: |
| | | return False, True, f"独苗不下单({can_buy_result[4]})自由流通市值({zyltgb})不满足条件" |
| | | |
| | | # -------量的约束-------- |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | |
| | | now_timestamp = int(tool.get_now_time_str().replace(":", "")) |
| | | |
| | | # 前一天炸板之后,今日10:00之前才能下单 |
| | | if k_format and len(k_format) >= 11 and k_format[10]: |
| | |
| | | # else: |
| | | if can_buy_result[0]: |
| | | return True, False, can_buy_result[2] |
| | | |
| | | if can_buy_result[1]: |
| | | return True, False, "买独苗" |
| | | |
| | | return False, True, can_buy_result[2] |
| | | |
| | | @classmethod |
| | |
| | | return params |
| | | |
| | | |
| | | # 获取开盘啦板块信息 |
| | | def get_kpl_block_info(code): |
| | | def format_plate_output(_plat): |
| | | return _plat, '' |
| | | |
| | | ##############################开盘啦相关信息################################## |
| | | industry = global_util.code_industry_map.get(code) |
| | | kpl_code_info = { |
| | | "industry": format_plate_output(industry)} |
| | | # 获取开盘啦板块 |
| | | plate_info = None |
| | | jingxuan_block_info = KPLCodeJXBlockManager().get_jx_blocks_cache(code) |
| | | if not jingxuan_block_info: |
| | | jingxuan_block_info = KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) |
| | | if jingxuan_block_info: |
| | | jingxuan_blocks = jingxuan_block_info[0] |
| | | plate_info = [(0, x, 0) for x in jingxuan_blocks] # set([x[1] for x in jingxuan_blocks]) |
| | | if not plate_info: |
| | | if code not in kpl_block_info_dict: |
| | | plate_info = kpl_api.getStockIDPlate(code) |
| | | else: |
| | | plate_info = kpl_block_info_dict.get(code) |
| | | if plate_info: |
| | | kpl_block_info_dict[code] = plate_info |
| | | plate_info.sort(key=lambda x: x[2]) |
| | | plate_info.reverse() |
| | | kpl_code_info["plate"] = [(k[0], k[1], k[2], format_plate_output(k[1])[1]) for k in plate_info] |
| | | |
| | | code_records = KPLLimitUpDataRecordManager.get_latest_infos(code, 4, False)[:2] |
| | | if code_records: |
| | | code_records = [(format_plate_output(k[0]), k[1], [format_plate_output(k1) for k1 in k[2].split("、")]) for k in |
| | | code_records] |
| | | kpl_code_info["code_records"] = code_records |
| | | |
| | | if not KPLLimitUpDataRecordManager.total_datas: |
| | | KPLLimitUpDataRecordManager.load_total_datas() |
| | | for d in KPLLimitUpDataRecordManager.total_datas: |
| | | if d[3] == code: |
| | | # 获取今日 |
| | | plates = d[6].split("、") |
| | | plates = [format_plate_output(p) for p in plates] |
| | | kpl_code_info["today"] = (format_plate_output(d[2]), d[1], plates) |
| | | break |
| | | return kpl_code_info |
| | | |
| | | |
| | | def __load_trade_record(code, total_datas): |
| | | def format_l2_data(item): |
| | | return f"{item['val']['time']}#{item['val']['num']}手#{round(item['val']['num'] * float(item['val']['price']) * 100 / 10000, 1)}万" |
| | |
| | | def is_too_high(datas): |
| | | limit_up_price = round(datas[0]["close"] * 1.1, 2) |
| | | datas.reverse() |
| | | is_new_high = code_nature_analyse.is_up_too_high_in_10d_with_limit_up(datas) |
| | | is_new_high = code_nature_analyse.is_price_too_high_in_days(datas,limit_up_price) |
| | | return is_new_high |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | code_str = "600748" |
| | | code_str = "603178" |
| | | codes = code_str.split(",") |
| | | for code in codes: |
| | | if not tool.is_shsz_code(code): |
| | | continue |
| | | try: |
| | | datas = init_data_util.get_volumns_by_code(code, 120) |
| | | result = code_nature_analyse.__is_yesterday_open_limit_up(datas) |
| | | result = is_too_high(datas) |
| | | if result: |
| | | print(code, result) |
| | | except: |
| | |
| | | |
| | | # 获取评分信息 |
| | | pass |
| | | elif url.path == "/get_kpl_block_info": |
| | | start_time = time.time() |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | code = ps_dict['code'] |
| | | try: |
| | | data = code_info_output.get_kpl_block_info(code) |
| | | response_data = json.dumps({"code": 0, "data": data}) |
| | | print("get_kpl_block_info 耗时:", time.time() - start_time) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | logging.exception(e) |
| | | |
| | | elif url.path == "/get_l2_datas": |
| | | # 获取L2的数据 |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |