| | |
| | | __real_place_order_index_dict = {} |
| | | __trade_progress_index_dict = {} |
| | | __watch_indexes_dict = {} |
| | | __watch_indexes_by_dict = {} |
| | | |
| | | __instance = None |
| | | |
| | |
| | | start_index = buy_single_index |
| | | if code in self.__trade_progress_index_dict: |
| | | start_index = self.__trade_progress_index_dict.get(code) |
| | | self.__commpute_watch_indexes(code, start_index, index) |
| | | self.__commpute_watch_indexes(code, start_index, index, from_real_order_index_changed=True) |
| | | |
| | | def clear(self, code=None): |
| | | if code: |
| | |
| | | self.__real_place_order_index_dict.pop(code) |
| | | if code in self.__watch_indexes_dict: |
| | | self.__watch_indexes_dict.pop(code) |
| | | if code in self.__watch_indexes_by_dict: |
| | | self.__watch_indexes_by_dict.pop(code) |
| | | if code in self.__trade_progress_index_dict: |
| | | self.__trade_progress_index_dict.pop(code) |
| | | |
| | | else: |
| | | self.__real_place_order_index_dict.clear() |
| | | self.__watch_indexes_dict.clear() |
| | | self.__trade_progress_index_dict.clear() |
| | | self.__watch_indexes_by_dict.clear() |
| | | |
| | | def __commpute_watch_indexes(self, code, traded_index, real_order_index): |
| | | def __commpute_watch_indexes(self, code, traded_index, real_order_index, from_real_order_index_changed=False): |
| | | if traded_index is None or real_order_index is None: |
| | | return |
| | | origin_watch_index = self.__watch_indexes_dict.get(code) |
| | | if origin_watch_index is None: |
| | | origin_watch_index = set() |
| | | origin_watch_index_by = self.__watch_indexes_by_dict.get(code) |
| | | if origin_watch_index_by is None: |
| | | origin_watch_index_by = set() |
| | | |
| | | start_index = traded_index |
| | | if traded_index in origin_watch_index or traded_index in origin_watch_index_by: |
| | | start_index = traded_index + 1 |
| | | |
| | | total_datas = local_today_datas.get(code) |
| | | watch_indexes = set() |
| | | for i in range(traded_index, real_order_index): |
| | | for i in range(start_index, real_order_index): |
| | | # 判断是否有未撤的大单 |
| | | data = total_datas[i] |
| | | val = data["val"] |
| | |
| | | code)) |
| | | if left_count > 0: |
| | | watch_indexes.add(i) |
| | | if not watch_indexes: |
| | | if watch_indexes: |
| | | # 还有300万以上的大单没有撤单 |
| | | if from_real_order_index_changed: |
| | | # 真实下单位改变后才会更新 |
| | | final_watch_indexes = origin_watch_index | watch_indexes |
| | | self.__watch_indexes_dict[code] = final_watch_indexes |
| | | else: |
| | | # 没有300万以上的大单了,计算备用 |
| | | # 只有备用单成交了或者没有备用单,才会再次寻找备用单 |
| | | need_find_by = False |
| | | if not origin_watch_index_by: |
| | | need_find_by = True |
| | | else: |
| | | # 备用单是否成交 |
| | | need_find_by = True |
| | | for i in origin_watch_index_by: |
| | | if i >= start_index: |
| | | # 在成交位置之后 |
| | | need_find_by = False |
| | | break |
| | | if need_find_by: |
| | | temp_list = [] |
| | | for i in range(traded_index, real_order_index): |
| | | for i in range(start_index, real_order_index): |
| | | data = total_datas[i] |
| | | val = data["val"] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | |
| | | temp_list.sort(key=lambda x: x[0], reverse=True) |
| | | if temp_list: |
| | | watch_indexes.add(temp_list[0][1]["index"]) |
| | | self.__watch_indexes_dict[code] = watch_indexes |
| | | self.__watch_indexes_by_dict[code] = origin_watch_index_by | watch_indexes |
| | | |
| | | def set_trade_progress(self, code, buy_single_index, index): |
| | | if self.__trade_progress_index_dict.get(code) != index: |
| | |
| | | watch_indexes = self.__watch_indexes_dict.get(code) |
| | | if watch_indexes is None: |
| | | watch_indexes = set() |
| | | watch_indexes_by = self.__watch_indexes_by_dict.get(code) |
| | | if watch_indexes_by is None: |
| | | watch_indexes_by = set() |
| | | |
| | | for i in range(start_index, end_index + 1): |
| | | data = total_datas[i] |
| | |
| | | buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(data, |
| | | local_today_buyno_map.get( |
| | | code)) |
| | | if buy_index is not None and buy_index < real_place_order_index and buy_index in watch_indexes: |
| | | if buy_index is not None and buy_index < real_place_order_index and (buy_index in watch_indexes or buy_index in watch_indexes_by): |
| | | return True, data, "" |
| | | return False, None, "" |
| | | |