| | |
| | | import ths_industry_util |
| | | import tool |
| | | from trade import trade_data_manager, trade_manager, trade_queue_manager, l2_trade_factor, l2_trade_util, \ |
| | | trade_result_manager |
| | | 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.cancel_buy_strategy import SecondCancelBigNumComputer, HourCancelBigNumComputer, L2LimitUpMoneyStatisticUtil, \ |
| | | L2LimitUpSellStatisticUtil |
| | |
| | | __ths_l2_trade_queue_manager = trade_queue_manager.thsl2tradequeuemanager() |
| | | __thsBuy1VolumnManager = trade_queue_manager.THSBuy1VolumnManager() |
| | | __buyL2SafeCountManager = safe_count_manager.BuyL2SafeCountManager() |
| | | __l2PlaceOrderParamsManager = l2_trade_factor.L2PlaceOrderParamsManager() |
| | | __l2PlaceOrderParamsManagerDict = {} |
| | | |
| | | @classmethod |
| | | # 数据处理入口 |
| | |
| | | "l2数据预处理时间") |
| | | |
| | | if len(add_datas) > 0: |
| | | # 是否为首板代码 |
| | | is_first_code = gpcode_manager.FirstCodeManager.is_in_first_record(code) |
| | | # 计算量 |
| | | volume_rate = code_volumn_manager.get_volume_rate(code) |
| | | volume_rate_index = code_volumn_manager.get_volume_rate_index(volume_rate) |
| | | l2_log.debug(code,"量比:{},量索引:{}",volume_rate,volume_rate_index) |
| | | # 计算分值 |
| | | 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, volume_rate, limit_up_time) |
| | | cls.__l2PlaceOrderParamsManagerDict[code] = l2_trade_factor.L2PlaceOrderParamsManager(code, is_first_code, |
| | | volume_rate, |
| | | volume_rate_index, |
| | | score) |
| | | l2_log.debug(code, "量比:{},量索引:{}", volume_rate, volume_rate_index) |
| | | cls.volume_rate_info[code] = (volume_rate, volume_rate_index) |
| | | # 是否为首板代码 |
| | | is_first_code = gpcode_manager.FirstCodeManager.is_in_first_record(code) |
| | | |
| | | latest_time = add_datas[len(add_datas) - 1]["val"]["time"] |
| | | # 时间差不能太大才能处理 |
| | | if not l2_trade_util.is_in_forbidden_trade_codes(code): |
| | |
| | | b_need_cancel, b_cancel_data = SecondCancelBigNumComputer.need_cancel(code, buy_single_index, |
| | | buy_exec_index, start_index, |
| | | end_index, total_data, |
| | | code_volumn_manager.get_volume_rate_index(buy_volume_rate), |
| | | code_volumn_manager.get_volume_rate_index( |
| | | buy_volume_rate), |
| | | cls.volume_rate_info[code][1], |
| | | is_first_code) |
| | | if b_need_cancel: |
| | |
| | | @classmethod |
| | | def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code): |
| | | __start_time = tool.get_now_timestamp() |
| | | can, need_clear_data, reason = cls.__can_buy(code, is_first_code) |
| | | can, need_clear_data, reason = False,False,"" |
| | | if not is_first_code: |
| | | can, need_clear_data, reason = cls.__can_buy(code) |
| | | else: |
| | | can, need_clear_data, reason = cls.__can_buy_first(code) |
| | | __start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - __start_time, "最后判断是否能下单", force=True) |
| | | # 删除虚拟下单 |
| | | if code in cls.unreal_buy_dict: |
| | |
| | | # 是否可以买 |
| | | # 返回是否可以买,是否需要清除之前的买入信息,原因 |
| | | @classmethod |
| | | def __can_buy(cls, code, is_first_code): |
| | | def __can_buy(cls, code): |
| | | __start_time = t.time() |
| | | # 判断是否为首板代码 |
| | | if is_first_code: |
| | | if not gpcode_manager.WantBuyCodesManager.is_in(code): |
| | | is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |
| | | gpcode_manager.FirstCodeManager.add_limited_up_record([code]) |
| | | if not code_price_manager.Buy1PriceManager.is_can_buy(code): |
| | | return False, True, "首板代码,没在想要买名单中且未打开涨停板" |
| | | if not is_limited_up: |
| | | return False, True, "首板代码,没在想要买名单中且未涨停过" |
| | | |
| | | # 之前的代码 |
| | | # 首板代码且尚未涨停过的不能下单 |
| | | # is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |
| | |
| | | |
| | | # 量比超过1.3的不能买 |
| | | volumn_rate = cls.volume_rate_info[code][0] |
| | | if not is_first_code and volumn_rate >= 1.3: |
| | | if volumn_rate >= 1.3: |
| | | return False, False, "最大量比超过1.3不能买" |
| | | elif is_first_code and volumn_rate >= 1.1: |
| | | return False, False, "首板最大量比超过1.1不能买" |
| | | |
| | | |
| | | limit_up_time = limit_up_time_manager.get_limit_up_time(code) |
| | | if limit_up_time is not None: |
| | | limit_up_time_seconds = l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | limit_up_time) |
| | | if not is_first_code and limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | if limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | "13:00:00"): |
| | | return False, False, "二板下午涨停的不能买,涨停时间为{}".format(limit_up_time) |
| | | if limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second("14:55:00"): |
| | |
| | | return True, False, None |
| | | finally: |
| | | l2_data_log.l2_time(code, round((t.time() - __start_time) * 1000), "是否可以下单计算") |
| | | |
| | | @classmethod |
| | | def __can_buy_first(cls, code): |
| | | |
| | | if not gpcode_manager.WantBuyCodesManager.is_in(code): |
| | | # 查看分数等级 |
| | | score_index = cls.__l2PlaceOrderParamsManagerDict[code].score_index |
| | | score = cls.__l2PlaceOrderParamsManagerDict[code].score |
| | | if score_index < 0: |
| | | return False, True, f"分值:{score}未达到需要买入的分数线" |
| | | if -1 < score_index < 3: |
| | | return True, False, f"分值:{score}达到主动买入的分数线,买入等级:f{score_index}" |
| | | is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |
| | | gpcode_manager.FirstCodeManager.add_limited_up_record([code]) |
| | | if not code_price_manager.Buy1PriceManager.is_can_buy(code): |
| | | return False, True, f"首板代码,没在想要买名单中且未打开涨停板,分数:{score}" |
| | | if not is_limited_up: |
| | | return False, True, f"首板代码,没在想要买名单中且未涨停过,分数:{score}" |
| | | return True, False, "" |
| | | else: |
| | | return True, False, "在想买名单中" |
| | | |
| | | @classmethod |
| | | def __cancel_buy(cls, code): |
| | |
| | | # 是否为新获取到的位置 |
| | | new_get_single = False |
| | | if buy_single_index is None: |
| | | continue_count = cls.__l2PlaceOrderParamsManager.get_begin_continue_buy_count(cls.volume_rate_info[code][1]) |
| | | continue_count = cls.__l2PlaceOrderParamsManagerDict[code].get_begin_continue_buy_count() |
| | | # 有买入信号 |
| | | has_single, _index = cls.__compute_order_begin_pos(code, max( |
| | | (compute_start_index - continue_count - 1) if new_add else compute_start_index, 0), continue_count, |
| | |
| | | return |
| | | |
| | | if compute_index is not None: |
| | | l2_log.debug(code, "获取到买入执行位置:{} m值:{} 纯买手数:{} 纯买单数:{} 数据:{}", compute_index, threshold_money, buy_nums, |
| | | buy_count, total_datas[compute_index]) |
| | | l2_log.debug(code, "获取到买入执行位置:{} m值:{} 纯买手数:{} 纯买单数:{} 数据:{} ,量比:{} ", compute_index, threshold_money, buy_nums, |
| | | buy_count, total_datas[compute_index],cls.volume_rate_info[code][0]) |
| | | |
| | | f1 = dask.delayed(cls.__save_order_begin_data)(code, buy_single_index, compute_index, compute_index, |
| | | buy_nums, buy_count, max_num_set_new, |
| | |
| | | |
| | | @classmethod |
| | | def __get_threshmoney(cls, code): |
| | | return l2_trade_factor.L2TradeFactorUtil.compute_m_value(code, cls.volume_rate_info[code][1]) |
| | | return cls.__l2PlaceOrderParamsManagerDict[code].get_m_val() |
| | | |
| | | # 计算万手哥笔数 |
| | | @classmethod |
| | |
| | | |
| | | # place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(code) |
| | | # 目标订单数量 |
| | | threshold_count = cls.__buyL2SafeCountManager.get_safe_count(code, is_first_code, |
| | | cls.__l2PlaceOrderParamsManager.get_safe_count_rate( |
| | | cls.volume_rate_info[code][1])) |
| | | threshold_count = cls.__l2PlaceOrderParamsManagerDict[code].get_safe_count() |
| | | |
| | | buy_single_time_seconds = L2DataUtil.get_time_as_second(total_datas[buy_single_index]["val"]["time"]) |
| | | |
| | |
| | | trigger_buy = True |
| | | |
| | | # 间隔最大时间依次为:3,9,27,81 |
| | | max_space_time = cls.__l2PlaceOrderParamsManager.get_time_range(cls.volume_rate_info[code][1]) |
| | | max_space_time = cls.__l2PlaceOrderParamsManagerDict[code].get_time_range() |
| | | # 最大买量 |
| | | max_buy_num = 0 |
| | | max_buy_num_set = set(max_num_set) |
| | | |
| | | # 需要的最小大单笔数 |
| | | big_num_count = cls.__l2PlaceOrderParamsManager.get_big_num_count(cls.volume_rate_info[code][1]) |
| | | big_num_count = cls.__l2PlaceOrderParamsManagerDict[code].get_big_num_count() |
| | | |
| | | # 较大单的手数 |
| | | bigger_num = round(5900 / limit_up_price) |