| | |
| | | |
| | | # 成交位置 |
| | | __transaction_progress_index_dict = {} |
| | | # 成交位置更新时间 |
| | | __transaction_progress_index_updatetime_dict = {} |
| | | # 缓存 |
| | | __cancel_watch_indexs_cache = {} |
| | | |
| | |
| | | def set_transaction_index(self, code, buy_single_index, index): |
| | | try: |
| | | if index == self.__transaction_progress_index_dict.get(code): |
| | | if code in self.__transaction_progress_index_updatetime_dict and time.time() - self.__transaction_progress_index_updatetime_dict.get( |
| | | code) < 3: |
| | | return |
| | | self.__transaction_progress_index_dict[code] = index |
| | | self.__transaction_progress_index_updatetime_dict[code] = time.time() |
| | | if self.__need_compute_watch_indexes(code, index): |
| | | self.__compute_watch_index(code, buy_single_index) |
| | | except Exception as e: |
| | |
| | | code = k.split("-")[-1] |
| | | val = RedisUtils.smembers(__redis, k) |
| | | CodeDataCacheUtil.set_cache(cls.__cancel_watch_index_cache, code, val) |
| | | |
| | | keys = RedisUtils.keys(__redis, "l_cancel_real_place_order_index-*") |
| | | for k in keys: |
| | | code = k.split("-")[-1] |
| | | val = RedisUtils.get(__redis, k) |
| | | val = int(val) |
| | | CodeDataCacheUtil.set_cache(cls.__real_place_order_index_dict, code, val) |
| | | |
| | | keys = RedisUtils.keys(__redis, "l_cancel_near_by_index-*") |
| | | for k in keys: |
| | | code = k.split("-")[-1] |
| | |
| | | self.del_watch_index(code) |
| | | if code in self.__real_place_order_index_dict: |
| | | self.__real_place_order_index_dict.pop(code) |
| | | RedisUtils.delete_async(self.__db, f"l_cancel_real_place_order_index-{code}") |
| | | else: |
| | | keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_watch_index-*") |
| | | for k in keys: |
| | |
| | | if code in self.__real_place_order_index_dict: |
| | | self.__real_place_order_index_dict.pop(code) |
| | | self.del_watch_index(code) |
| | | keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_real_place_order_index-*") |
| | | for k in keys: |
| | | RedisUtils.delete(self.__get_redis(), k) |
| | | |
| | | # 计算观察索引,倒序计算 |
| | | def compute_watch_index(self, code, buy_single_index, start_index, end_index): |
| | |
| | | # thresh_hold_money = int(thresh_hold_money * 2.5) |
| | | min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code)))) |
| | | # 统计净涨停买的数量 |
| | | not_cancel_indexes = [] |
| | | not_cancel_indexes_with_num = [] |
| | | re_start_index = start_index |
| | | MAX_COUNT = 5 |
| | | for j in range(start_index, end_index): |
| | |
| | | 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) |
| | | not_cancel_indexes_with_num.append((j, val["num"])) |
| | | min_num = 0 |
| | | if not_cancel_indexes_with_num: |
| | | temp_count = len(not_cancel_indexes_with_num) |
| | | # 取后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] |
| | | re_start_index = not_cancel_indexes_with_num[temp_index][0] |
| | | MAX_COUNT = len(not_cancel_indexes_with_num[temp_index:]) |
| | | else: |
| | | re_start_index = not_cancel_indexes[0] |
| | | not_cancel_indexes_with_num.sort(key=lambda x: x[1]) |
| | | if temp_count >= 10: |
| | | # 获取中位数 |
| | | min_num = not_cancel_indexes_with_num[temp_count // 2][1] |
| | | MIN_MONEYS = [300, 200, 100, 50] |
| | | watch_indexes = set() |
| | | for min_money in MIN_MONEYS: |
| | |
| | | # 小金额过滤 |
| | | if float(val['price']) * val['num'] < min_money * 100: |
| | | continue |
| | | |
| | | if val['num'] < min_num: |
| | | continue |
| | | |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( |
| | | code, |
| | | i, |
| | |
| | | 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: |
| | | RedisUtils.setex_async(self.__db, f"l_cancel_real_place_order_index-{code}", tool.get_expire(), index) |
| | | if buy_single_index is not None: |
| | | 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, |