| | |
| | | |
| | | |
| | | # 设置历史量 |
| | | def set_histry_volumn(code, max60, yesterday, max60_day=''): |
| | | def set_histry_volumn(code, max60, yesterday, max60_day, max60_day_count): |
| | | redis = __redis_manager.getRedis() |
| | | global_util.max60_volumn[code] = (max60, max60_day) |
| | | global_util.yesterday_volumn[code] = yesterday |
| | | try: |
| | | RedisUtils.setex_async(0, "volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day)), |
| | | RedisUtils.setex_async(0, "volumn_max60-{}".format(code), tool.get_expire(), |
| | | json.dumps((max60, max60_day, max60_day_count)), |
| | | auto_free=False) |
| | | RedisUtils.setex_async(0, "volumn_yes-{}".format(code), tool.get_expire(), yesterday, auto_free=False) |
| | | finally: |
| | |
| | | |
| | | |
| | | # 获取量参考日期 |
| | | # 返回(参考量日期,距今的交易日个数) |
| | | def get_volume_refer_date(code): |
| | | max60, yesterday = get_histry_volumn(code) |
| | | if max60 is None or yesterday is None: |
| | | raise Exception("获取失败") |
| | | if int(max60[0]) >= int(yesterday): |
| | | return max60[1] |
| | | return max60[1], max60[2] |
| | | else: |
| | | return "上个交易日" |
| | | return "上个交易日", 0 |
| | | |
| | | |
| | | # 获取量比索引 |
| | |
| | | limit_up_price, |
| | | volumes_data[:90])) |
| | | logger_first_code_record.info("{} 获取到首板60天最大量:{}", code, volumes) |
| | | code_volumn_manager.set_histry_volumn(code, volumes[0], volumes[1], volumes[2]) |
| | | code_volumn_manager.set_histry_volumn(code, volumes[0], volumes[1], volumes[2],volumes[3]) |
| | | |
| | | # 保存K线形态 |
| | | k_format = code_nature_analyse.get_k_format(limit_up_price, volumes_data) |
| | |
| | | has_limit_down_in_5 = True if k_format and len(k_format) >= 13 and k_format[12] else False |
| | | # 是否是强势10分钟 |
| | | is_in_strong_time = now_timestamp <= int("094000") |
| | | # 量参考是否在最近30天 |
| | | # is_refer_volume_date_in_30_days = False |
| | | # try: |
| | | # volume_refer_date, volume_refer_date_distance = code_volumn_manager.get_volume_refer_date(code) |
| | | # if volume_refer_date_distance < 30: |
| | | # is_refer_volume_date_in_30_days = True |
| | | # except: |
| | | # pass |
| | | |
| | | if k_format and (k_format[1][0] or k_format[3][0]) and len(k_format) >= 12 and k_format[11]: |
| | | # 破前高/接近前高且30天内有涨停 |
| | |
| | | |
| | | # 获取量参考日期 |
| | | try: |
| | | volume_refer_date = code_volumn_manager.get_volume_refer_date(code) |
| | | volume_refer_date,volume_refer_date_distance = code_volumn_manager.get_volume_refer_date(code) |
| | | params["trade_data"]["volume_refer_date"] = volume_refer_date |
| | | except: |
| | | pass |
| | |
| | | return is_new_high |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | code = "601022" |
| | | def __get_refer_volume_info(): |
| | | code = "001239" |
| | | limit_up_price = 22.80 |
| | | volumes_data = init_data_util.get_volumns_by_code(code, 150) |
| | | volumes_data = volumes_data[0:] |
| | | print( code_nature_analyse.is_special(volumes_data)) |
| | | volumes = init_data_util.parse_max_volume(volumes_data[:90], |
| | | code_nature_analyse.is_new_top( |
| | | limit_up_price, |
| | | volumes_data[:90]) or code_nature_analyse.is_near_top( |
| | | limit_up_price, |
| | | volumes_data[:90])) |
| | | print(volumes) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | __get_refer_volume_info() |
| | | # code = "601022" |
| | | # volumes_data = init_data_util.get_volumns_by_code(code, 150) |
| | | # volumes_data = volumes_data[0:] |
| | | # print( code_nature_analyse.is_special(volumes_data)) |
| | |
| | | return datas |
| | | |
| | | |
| | | # 解析最大量 |
| | | # 返回:(60天最大量,昨日量,量参考日期,参考量据今交易日数) |
| | | def parse_max_volume(datas, is_new_or_near_top=False): |
| | | max_volume = 0 |
| | | max_volume_date = None |
| | | max_volume_index = None |
| | | # 判断30天内是否有涨停 |
| | | if is_new_or_near_top: |
| | | # 30天内是否有涨停 |
| | |
| | | if latest_limit_up_index > 0 and datas[latest_limit_up_index - 1]["volume"] > datas[latest_limit_up_index][ |
| | | "volume"]: |
| | | return datas[latest_limit_up_index - 1]["volume"], datas[latest_limit_up_index - 1]["volume"], \ |
| | | datas[latest_limit_up_index - 1]['bob'].strftime("%Y-%m-%d") |
| | | datas[latest_limit_up_index - 1]['bob'].strftime("%Y-%m-%d"), latest_limit_up_index - 1 |
| | | else: |
| | | return datas[latest_limit_up_index]["volume"], datas[latest_limit_up_index]["volume"], \ |
| | | datas[latest_limit_up_index]['bob'].strftime("%Y-%m-%d") |
| | | datas[latest_limit_up_index]['bob'].strftime("%Y-%m-%d"), latest_limit_up_index |
| | | |
| | | if is_new_or_near_top: |
| | | # 如果是突破前高就取最大量 |
| | | for item in datas: |
| | | for i in range(len(datas)): |
| | | item = datas[i] |
| | | if max_volume < item["volume"]: |
| | | max_volume = item["volume"] |
| | | max_volume_date = item["bob"] |
| | | return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d") |
| | | max_volume_index = i |
| | | return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d"), max_volume_index |
| | | else: |
| | | date = None |
| | | target_volume = None |
| | |
| | | if volume < next_volume: |
| | | volume = next_volume |
| | | date = datas[i - 1]["bob"] |
| | | target_volume = (volume, date) |
| | | target_volume = (volume, date, i) |
| | | break |
| | | |
| | | # 90个交易日无涨停,取最近30天内的最高量作为参考量 |
| | |
| | | item = datas[i] |
| | | volume = item["volume"] |
| | | if max_30_volume_info[0] < volume: |
| | | max_30_volume_info = [volume, item["bob"]] |
| | | max_30_volume_info = [volume, item["bob"], i] |
| | | target_volume = max_30_volume_info |
| | | return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d") |
| | | return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d"), target_volume[2] |