| | |
| | | |
| | | if watch_indexes or watch_indexes_up: |
| | | watch_indexes |= watch_indexes_up |
| | | self.__save_watch_index_set(code, buy_single_index, watch_indexes) |
| | | self.__save_watch_index_set(code, buy_single_index, watch_indexes) |
| | | l2_log.h_cancel_debug(code, f"设置监听范围, 数据范围:{real_place_order_index}-{end_index} 监听范围-{watch_indexes}") |
| | | # 设置真实下单位置 |
| | | |
| | |
| | | temp_index = int(temp_count * 9 / 10) |
| | | self.__start_compute_index_dict[code] = not_cancel_indexes[temp_index] |
| | | except Exception as e: |
| | | async_log_util.exception(logger_l2_h_cancel,e) |
| | | async_log_util.exception(logger_l2_h_cancel, e) |
| | | l2_log.h_cancel_debug(code, "设置真实下单位置出错:{}", str(e)) |
| | | |
| | | def need_cancel(self, code, buy_single_index, buy_exec_index, start_index, end_index, total_data, |
| | |
| | | if temp_rate >= 1: |
| | | if temp_rate > 3: |
| | | temp_rate = 3 |
| | | deal_rate = round((temp_rate * 3.5 - 2.5) / 100, 4) if is_up else round((temp_rate * 10.5 - 7.5) / 100, 4) |
| | | deal_rate = round((temp_rate * 3.5 - 2.5) / 100, 4) if is_up else round( |
| | | (temp_rate * 10.5 - 7.5) / 100, 4) |
| | | |
| | | base_rate += block_rate |
| | | base_rate += deal_rate |
| | |
| | | if indexes: |
| | | trade_record_log_util.add_cancel_watch_indexes_log(code, |
| | | trade_record_log_util.CancelWatchIndexesInfo( |
| | | trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN,buy_single_index, |
| | | trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN, |
| | | buy_single_index, |
| | | list(indexes))) |
| | | |
| | | def __get_watch_indexes(self, code): |
| | |
| | | if indexes: |
| | | trade_record_log_util.add_cancel_watch_indexes_log(code, |
| | | trade_record_log_util.CancelWatchIndexesInfo( |
| | | trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_UP,buy_single_index, |
| | | trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_UP, |
| | | buy_single_index, |
| | | list(indexes))) |
| | | self.__near_by_trade_progress_index_cache[code] = indexes |
| | | RedisUtils.setex_async(self.__db, f"l_cancel_near_by_index-{code}", tool.get_expire(), |
| | |
| | | |
| | | # 计算观察索引,倒序计算 |
| | | def compute_watch_index(self, code, buy_single_index, start_index, end_index): |
| | | total_datas = local_today_datas.get(code) |
| | | if total_datas: |
| | | # 计算的上截至位距离下截至位纯买额要小于2.5倍m值 |
| | | # thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | # thresh_hold_money = int(thresh_hold_money * 2.5) |
| | | min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code)))) |
| | | # 统计净涨停买的数量 |
| | | not_cancel_indexes = [] |
| | | re_start_index = start_index |
| | | MAX_COUNT = 5 |
| | | for j in range(start_index, end_index): |
| | | data = total_datas[j] |
| | | val = data['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | |
| | | if val["num"] < min_num: |
| | | continue |
| | | |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, |
| | | j, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | not_cancel_indexes.append(j) |
| | | if not_cancel_indexes: |
| | | temp_count = len(not_cancel_indexes) |
| | | # 取后1/3的数据 |
| | | if temp_count >= 30: |
| | | temp_index = int(temp_count * 5 / 6) |
| | | re_start_index = not_cancel_indexes[temp_index] |
| | | MAX_COUNT = len(not_cancel_indexes[temp_index:]) |
| | | elif temp_count >= 5: |
| | | re_start_index = not_cancel_indexes[-5] |
| | | else: |
| | | re_start_index = not_cancel_indexes[0] |
| | | MIN_MONEYS = [300, 200, 100, 50] |
| | | watch_indexes = set() |
| | | for min_money in MIN_MONEYS: |
| | | for i in range(end_index, re_start_index, -1): |
| | | try: |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | # 小金额过滤 |
| | | if float(val['price']) * val['num'] < min_money * 100: |
| | | continue |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, |
| | | i, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | watch_indexes.add(i) |
| | | if len(watch_indexes) >= MAX_COUNT: |
| | | break |
| | | except Exception as e: |
| | | logger_l2_l_cancel.error(f"{code}: 范围: {start_index}-{end_index} 位置:{i}") |
| | | logger_l2_l_cancel.exception(e) |
| | | if len(watch_indexes) >= MAX_COUNT: |
| | | break |
| | | if watch_indexes: |
| | | ##判断监听的数据中是否有大单## |
| | | has_big_num = False |
| | | for i in watch_indexes: |
| | | # 是否有大单 |
| | | data = total_datas[i] |
| | | try: |
| | | l2_log.l_cancel_debug(code, f"计算L后囊括范围:{start_index}-{end_index}") |
| | | total_datas = local_today_datas.get(code) |
| | | if total_datas: |
| | | # 计算的上截至位距离下截至位纯买额要小于2.5倍m值 |
| | | # thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | # thresh_hold_money = int(thresh_hold_money * 2.5) |
| | | min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code)))) |
| | | # 统计净涨停买的数量 |
| | | not_cancel_indexes = [] |
| | | re_start_index = start_index |
| | | MAX_COUNT = 5 |
| | | for j in range(start_index, end_index): |
| | | data = total_datas[j] |
| | | val = data['val'] |
| | | if float(val['price']) * val['num'] > 100 * 100: |
| | | has_big_num = True |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | |
| | | if val["num"] < min_num: |
| | | continue |
| | | |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, |
| | | j, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | not_cancel_indexes.append(j) |
| | | if not_cancel_indexes: |
| | | temp_count = len(not_cancel_indexes) |
| | | # 取后1/3的数据 |
| | | if temp_count >= 30: |
| | | temp_index = int(temp_count * 5 / 6) |
| | | re_start_index = not_cancel_indexes[temp_index] |
| | | MAX_COUNT = len(not_cancel_indexes[temp_index:]) |
| | | elif temp_count >= 5: |
| | | re_start_index = not_cancel_indexes[-5] |
| | | else: |
| | | re_start_index = not_cancel_indexes[0] |
| | | MIN_MONEYS = [300, 200, 100, 50] |
| | | watch_indexes = set() |
| | | for min_money in MIN_MONEYS: |
| | | for i in range(end_index, re_start_index, -1): |
| | | try: |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | # 小金额过滤 |
| | | if float(val['price']) * val['num'] < min_money * 100: |
| | | continue |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( |
| | | code, |
| | | i, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | watch_indexes.add(i) |
| | | if len(watch_indexes) >= MAX_COUNT: |
| | | break |
| | | except Exception as e: |
| | | logger_l2_l_cancel.error(f"{code}: 范围: {start_index}-{end_index} 位置:{i}") |
| | | logger_l2_l_cancel.exception(e) |
| | | if len(watch_indexes) >= MAX_COUNT: |
| | | break |
| | | if not has_big_num: |
| | | # 无大单,需要找大单 |
| | | for i in range(re_start_index, start_index, -1): |
| | | if watch_indexes: |
| | | ##判断监听的数据中是否有大单## |
| | | has_big_num = False |
| | | for i in watch_indexes: |
| | | # 是否有大单 |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | # 涨停买,且未撤单 |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | # 小金额过滤 |
| | | if float(val['price']) * val['num'] < 100 * 100: |
| | | continue |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, |
| | | i, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | watch_indexes.add(i) |
| | | if float(val['price']) * val['num'] > 100 * 100: |
| | | has_big_num = True |
| | | break |
| | | self.__set_watch_indexes(code,buy_single_index, watch_indexes) |
| | | l2_log.l_cancel_debug(code, f"设置监听范围, 数据范围:{re_start_index}-{end_index} 监听范围-{watch_indexes}") |
| | | if not has_big_num: |
| | | # 无大单,需要找大单 |
| | | for i in range(re_start_index, start_index, -1): |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | # 涨停买,且未撤单 |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | # 小金额过滤 |
| | | if float(val['price']) * val['num'] < 100 * 100: |
| | | continue |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( |
| | | code, |
| | | i, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | watch_indexes.add(i) |
| | | break |
| | | self.__set_watch_indexes(code, buy_single_index, watch_indexes) |
| | | l2_log.l_cancel_debug(code, f"设置监听范围, 数据范围:{re_start_index}-{end_index} 监听范围-{watch_indexes}") |
| | | except Exception as e: |
| | | l2_log.l_cancel_debug(code, f"计算L后囊括范围出错:{str(e)}") |
| | | async_log_util.exception(logger_l2_l_cancel, e) |
| | | |
| | | # 设置真实下单位置 |
| | | def set_real_place_order_index(self, code, index, buy_single_index=None): |
| | | l2_log.l_cancel_debug(code, f"设置真实下单位-{index},buy_single_index-{buy_single_index}") |
| | | self.__real_place_order_index_dict[code] = index |
| | | if buy_single_index: |
| | | self.compute_watch_index(code, buy_single_index, buy_single_index, index) |
| | | if self.__last_trade_progress_dict.get(code): |
| | | self.__compute_trade_progress_near_by_indexes(code,buy_single_index, self.__last_trade_progress_dict.get(code) + 1, index) |
| | | self.__compute_trade_progress_near_by_indexes(code, buy_single_index, |
| | | self.__last_trade_progress_dict.get(code) + 1, index) |
| | | else: |
| | | self.__compute_trade_progress_near_by_indexes(code, buy_single_index, buy_single_index, index) |
| | | |
| | |
| | | if code not in self.__real_place_order_index_dict: |
| | | return |
| | | if code not in self.__last_l_up_compute_info or time.time() - self.__last_l_up_compute_info[code][0] >= 3: |
| | | self.__compute_trade_progress_near_by_indexes(code,buy_single_index, self.__last_trade_progress_dict.get(code) + 1, |
| | | self.__compute_trade_progress_near_by_indexes(code, buy_single_index, |
| | | self.__last_trade_progress_dict.get(code) + 1, |
| | | self.__real_place_order_index_dict.get(code)) |
| | | |
| | | # 计算范围内的成交位临近未撤大单 |
| | |
| | | # 保存数据 |
| | | if changed: |
| | | l2_log.l_cancel_debug(code, f"设置成交位临近撤单监控范围:{watch_indexes} 计算范围:{start_index}-{end_index}") |
| | | self.__set_near_by_trade_progress_indexes(code,buy_single_index, watch_indexes) |
| | | self.__set_near_by_trade_progress_indexes(code, buy_single_index, watch_indexes) |
| | | self.__last_l_up_compute_info[code] = (time.time(), watch_indexes) |
| | | |
| | | # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化 |
| | |
| | | self.__last_trade_progress_dict[code] = index |
| | | |
| | | # 重新计算成交位置临近大单撤单 |
| | | self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1, self.__real_place_order_index_dict.get(code)) |
| | | self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1, |
| | | self.__real_place_order_index_dict.get(code)) |
| | | |
| | | # 成交进度与L下撤无关 |
| | | # try: |
| | |
| | | def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code): |
| | | watch_indexes = self.__get_watch_indexes_cache(code) |
| | | if not watch_indexes: |
| | | |
| | | return False, None |
| | | watch_indexes = set([int(i) for i in watch_indexes]) |
| | | # 计算监听的总条数 |
| | |
| | | if len(watch_indexes) >= MAX_COUNT: |
| | | break |
| | | # 保存数据 |
| | | l2_log.f_cancel_debug(code,f"监听范围:{watch_indexes} 计算起始点:{c_start_index}") |
| | | l2_log.f_cancel_debug(code, f"监听范围:{watch_indexes} 计算起始点:{c_start_index}") |
| | | self.__set_watch_indexes(code, watch_indexes) |
| | | |
| | | def set_trade_progress(self, code, index): |