| | |
| | | import code_data_util |
| | | import code_volumn_manager |
| | | import constant |
| | | import global_data_loader |
| | | import global_util |
| | | import gpcode_manager |
| | | import industry_codes_sort |
| | |
| | | from db import redis_manager |
| | | import ths_industry_util |
| | | import tool |
| | | from third_data import hot_block, hot_block_data_process |
| | | from trade import trade_data_manager, trade_manager, trade_queue_manager, l2_trade_factor, l2_trade_util, \ |
| | | trade_result_manager, first_code_score_manager |
| | | from l2 import safe_count_manager, l2_data_manager, l2_data_log, l2_log, l2_data_source_util, code_price_manager |
| | |
| | | from l2.l2_data_util import local_today_datas, L2DataUtil, load_l2_data, local_today_num_operate_map, local_latest_datas |
| | | import l2.l2_data_util |
| | | from log import logger_l2_trade, logger_l2_trade_cancel, logger_l2_trade_buy, logger_l2_process, logger_l2_error, \ |
| | | logger_buy_score |
| | | logger_place_order_score |
| | | |
| | | # TODO l2数据管理 |
| | | from trade.trade_data_manager import CodeActualPriceProcessor |
| | |
| | | score_dict[code] = score |
| | | return score_dict |
| | | |
| | | |
| | | @classmethod |
| | | # 数据处理入口 |
| | | # datas: 本次截图数据 |
| | |
| | | cls.__l2PlaceOrderParamsManagerDict[code] = l2_trade_factor.L2PlaceOrderParamsManager(code, is_first_code, |
| | | volume_rate, |
| | | volume_rate_index, |
| | | score) |
| | | score, |
| | | total_datas[-1][ |
| | | 'val']['time']) |
| | | cls.volume_rate_info[code] = (volume_rate, volume_rate_index) |
| | | |
| | | latest_time = add_datas[len(add_datas) - 1]["val"]["time"] |
| | |
| | | |
| | | if cancel_data: |
| | | l2_log.debug(code, "触发撤单,撤单位置:{} ,撤单原因:{}", cancel_data["index"], cancel_msg) |
| | | l2_log.trade_record(code, "撤单", "'index':{} , 'msg':'{}'", cancel_data["index"], cancel_msg) |
| | | # 撤单 |
| | | if cls.cancel_buy(code, cancel_msg): |
| | | _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, |
| | |
| | | if code in cls.unreal_buy_dict: |
| | | cls.unreal_buy_dict.pop(code) |
| | | |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos( |
| | | code) |
| | | if not can: |
| | | l2_log.debug(code, "不可以下单,原因:{}", reason) |
| | | if need_clear_data: |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos( |
| | | code) |
| | | trade_result_manager.real_cancel_success(code, buy_single_index, buy_exec_index, |
| | | local_today_datas.get(code)) |
| | | return |
| | | else: |
| | | l2_log.debug(code, "可以下单,原因:{}", reason) |
| | | logger_buy_score.info(f"{code}:{cls.__l2PlaceOrderParamsManagerDict[code].score_info}") |
| | | |
| | | try: |
| | | l2_log.debug(code, "开始执行买入") |
| | | trade_manager.start_buy(code, capture_timestamp, last_data, |
| | |
| | | ################下单成功处理################ |
| | | trade_result_manager.real_buy_success(code) |
| | | l2_log.debug(code, "执行买入成功") |
| | | params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc() |
| | | l2_log.debug(code, params_desc) |
| | | l2_log.trade_record(code, "下单", |
| | | "'buy_start_index':{} ,'buy_exec_index':{},'volume_reate':{},'score':{},'desc':'{}'", |
| | | buy_single_index, buy_exec_index, cls.volume_rate_info[code][0], |
| | | cls.__l2PlaceOrderParamsManagerDict[code].score, params_desc) |
| | | except Exception as e: |
| | | l2_log.debug(code, "执行买入异常:{}", str(e)) |
| | | pass |
| | |
| | | def __can_buy_first(cls, code): |
| | | if not trade_manager.TradeStateManager.is_can_buy(): |
| | | return False, True, f"今日已禁止交易" |
| | | limit_up_info = code_price_manager.Buy1PriceManager.get_limit_up_info(code) |
| | | if limit_up_info[0] is None and False: |
| | | total_data = local_today_datas.get(code) |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos( |
| | | code) |
| | | # 之前没有涨停过 |
| | | # 统计买入信号位到当前位置没有撤的大单金额 |
| | | min_money_w = l2_data_util.get_big_money_val(float(total_data[buy_single_index]["val"]["price"])) // 10000 |
| | | left_big_num = l2.cancel_buy_strategy.SecondCancelBigNumComputer.compute_left_big_num(code, |
| | | buy_single_index, |
| | | buy_exec_index, |
| | | total_data[-1][ |
| | | "index"], |
| | | total_data, |
| | | 0, min_money_w) |
| | | if left_big_num > 0: |
| | | # 重新获取分数与分数索引 |
| | | limit_up_time = limit_up_time_manager.get_limit_up_time(code) |
| | | if limit_up_time is None: |
| | | limit_up_time = tool.get_now_time_str() |
| | | score = first_code_score_manager.get_score(code, cls.volume_rate_info[code][0], limit_up_time, True, |
| | | left_big_num) |
| | | cls.__l2PlaceOrderParamsManagerDict[code].set_score(score) |
| | | |
| | | logger_place_order_score.info("code={},data='score_index':{},'score_info':{}", code, |
| | | cls.__l2PlaceOrderParamsManagerDict[code].score_index, |
| | | cls.__l2PlaceOrderParamsManagerDict[code].score_info) |
| | | |
| | | if not gpcode_manager.WantBuyCodesManager.is_in(code): |
| | | |
| | | # 查看分数等级 |
| | | score_index = cls.__l2PlaceOrderParamsManagerDict[code].score_index |
| | | score = cls.__l2PlaceOrderParamsManagerDict[code].score |
| | | score_info = cls.__l2PlaceOrderParamsManagerDict[code].score_info |
| | | |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb is None: |
| | | global_data_loader.load_zyltgb() |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | # 区分大票,小票 |
| | | if zyltgb >= 80 * 100000000: |
| | | if cls.volume_rate_info[code][0] < 0.5: |
| | | return False, True, f"大市值:量大于50%才下单,量比:{cls.volume_rate_info[code][0]}" |
| | | elif zyltgb <= 35 * 100000000: |
| | | # 获取板块中的票的数量 |
| | | if score_info[1][5]["limit_up_codes_count"] < 2: |
| | | return False, True, f"小市值:板块中必须2个涨停才能买,板块{score_info[1][5]['target_block_info'][0]}-涨停数{score_info[1][5]['limit_up_codes_count']}" |
| | | |
| | | # 尾盘偷跑票 |
| | | limit_up_time = score_info[1][7] |
| | | if limit_up_time is None: |
| | | limit_up_time = tool.get_now_time_str() |
| | | if int(limit_up_time.replace(":", "")) > int("143000"): |
| | | if not score_info[1][3][6][0]: |
| | | return False, True, f"尾盘偷跑:无任何形态" |
| | | if score_info[1][5]["limit_up_codes_count"] > 1: |
| | | return False, True, f"尾盘偷跑:板块{score_info[1][5]['target_block_info'][0]}-涨停数{score_info[1][5]['limit_up_codes_count']}" |
| | | if float(gpcode_manager.get_limit_up_price(code)) > 30: |
| | | return False, True, f"尾盘偷跑:股价大于30" |
| | | |
| | | if score_index < 0: |
| | | return False, True, f"分值:{score}未达到需要买入的分数线" |
| | | if score_index >= 3: |
| | | return False, True, f"分值:{score}未达到主动买入分数线" |
| | | return True, False, "" |
| | | # if -1 < score_index < 3 and (0.499 <= cls.volume_rate_info[code][0] <= 0.949): |
| | | # return True, False, f"分值:{score}达到主动买入的分数线且量足够,买入等级:f{score_index},量比:{cls.volume_rate_info[code][0]}" |
| | | is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |