| | |
| | | RedisUtils.realse(__redis) |
| | | |
| | | # 保存成交位置到执行位置的揽括范围数据 |
| | | def __save_watch_index_set(self, code, indexes): |
| | | def __save_watch_index_set(self, code, buy_single_index, indexes): |
| | | trade_record_log_util.add_cancel_watch_indexes_log(code, |
| | | trade_record_log_util.CancelWatchIndexesInfo( |
| | | trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_H, |
| | | buy_single_index, |
| | | list(indexes))) |
| | | CodeDataCacheUtil.set_cache(self.__cancel_watch_indexs_cache, code, indexes) |
| | | key = f"h_cancel_watch_indexs-{code}" |
| | |
| | | |
| | | # 计算观察索引,倒序计算 |
| | | |
| | | def __compute_watch_index(self, code): |
| | | def __compute_watch_index(self, code, buy_single_index): |
| | | if self.__cancel_watch_indexs_cache.get(code): |
| | | return |
| | | real_place_order_index = self.__SecondCancelBigNumComputer.get_real_place_order_index_cache(code) |
| | |
| | | |
| | | if watch_indexes or watch_indexes_up: |
| | | watch_indexes |= watch_indexes_up |
| | | self.__save_watch_index_set(code, 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}") |
| | | # 设置真实下单位置 |
| | | |
| | |
| | | return True |
| | | |
| | | # 设置成交进度 |
| | | def set_transaction_index(self, code, index): |
| | | def set_transaction_index(self, code, buy_single_index, index): |
| | | try: |
| | | if index == self.__transaction_progress_index_dict.get(code): |
| | | return |
| | | self.__transaction_progress_index_dict[code] = index |
| | | if self.__need_compute_watch_indexes(code, index): |
| | | self.__compute_watch_index(code) |
| | | self.__compute_watch_index(code, buy_single_index) |
| | | except Exception as e: |
| | | l2_log.h_cancel_debug(code, "设置成交进度位置出错:{}", str(e)) |
| | | logger_l2_h_cancel.exception(e) |
| | |
| | | break |
| | | if need_compute: |
| | | if self.__need_compute_watch_indexes(code, self.__transaction_progress_index_dict.get(code)): |
| | | self.__compute_watch_index(code) |
| | | self.__compute_watch_index(code, buy_single_index) |
| | | watch_index_set = self.__get_watch_index_set_cache(code) |
| | | if not watch_index_set: |
| | | return False, "没有监听索引" |
| | |
| | | total_data, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | |
| | | cancel_num += val['num'] * (data['re'] - left_count) |
| | | rate = round(cancel_num / total_num, 4) |
| | | if rate >= constant.H_CANCEL_RATE: |
| | |
| | | self.__cancel_watch_index_cache[code].discard(index) |
| | | RedisUtils.srem_async(self.__db, f"l_cancel_watch_index-{code}", index) |
| | | |
| | | def __set_watch_indexes(self, code, indexes): |
| | | def __set_watch_indexes(self, code, buy_single_index, indexes): |
| | | self.__cancel_watch_index_cache[code] = indexes |
| | | RedisUtils.delete_async(self.__db, f"l_cancel_watch_index-{code}") |
| | | for index in indexes: |
| | |
| | | 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, |
| | | trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN,buy_single_index, |
| | | list(indexes))) |
| | | |
| | | def __get_watch_indexes(self, code): |
| | |
| | | return cache_result[1] |
| | | return set() |
| | | |
| | | def __set_near_by_trade_progress_indexes(self, code, indexes): |
| | | def __set_near_by_trade_progress_indexes(self, code, buy_single_index, indexes): |
| | | 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, |
| | | 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(), |
| | |
| | | self.del_watch_index(code) |
| | | |
| | | # 计算观察索引,倒序计算 |
| | | def compute_watch_index(self, code, start_index, end_index): |
| | | 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值 |
| | |
| | | if left_count > 0: |
| | | watch_indexes.add(i) |
| | | break |
| | | self.__set_watch_indexes(code, watch_indexes) |
| | | self.__set_watch_indexes(code,buy_single_index, watch_indexes) |
| | | l2_log.l_cancel_debug(code, f"设置监听范围, 数据范围:{re_start_index}-{end_index} 监听范围-{watch_indexes}") |
| | | |
| | | # 设置真实下单位置 |
| | | def set_real_place_order_index(self, code, index, buy_single_index=None): |
| | | self.__real_place_order_index_dict[code] = index |
| | | if buy_single_index: |
| | | self.compute_watch_index(code, buy_single_index, 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, 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, index) |
| | | self.__compute_trade_progress_near_by_indexes(code, buy_single_index, buy_single_index, index) |
| | | |
| | | # 重新计算L上 |
| | | def re_compute_l_up_watch_indexes(self, code): |
| | | def re_compute_l_up_watch_indexes(self, code, buy_single_index): |
| | | if code not in self.__last_trade_progress_dict: |
| | | return |
| | | 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, 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)) |
| | | |
| | | # 计算范围内的成交位临近未撤大单 |
| | | def __compute_trade_progress_near_by_indexes(self, code, start_index, end_index): |
| | | def __compute_trade_progress_near_by_indexes(self, code, buy_single_index, start_index, end_index): |
| | | if start_index is None or end_index is None: |
| | | return |
| | | total_datas = local_today_datas.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, 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) |
| | | |
| | | # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化 |
| | | def set_trade_progress(self, code, index, total_datas): |
| | | def set_trade_progress(self, code, buy_single_index, index, total_datas): |
| | | if self.__last_trade_progress_dict.get(code) == index: |
| | | return |
| | | self.__last_trade_progress_dict[code] = index |
| | | |
| | | # 重新计算成交位置临近大单撤单 |
| | | self.__compute_trade_progress_near_by_indexes(code, 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]) |
| | | # 计算监听的总条数 |