| | |
| | | # 缓存 |
| | | __cancel_watch_indexs_cache = {} |
| | | |
| | | # L撤触发的代码 |
| | | __l_cancel_triggered_codes = set() |
| | | |
| | | __instance = None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | |
| | | CodeDataCacheUtil.clear_cache(self.__cancel_watch_indexs_cache, code) |
| | | CodeDataCacheUtil.clear_cache(self.__transaction_progress_index_dict, code) |
| | | CodeDataCacheUtil.clear_cache(self.__start_compute_index_dict, code) |
| | | self.__l_cancel_triggered_codes.discard(code) |
| | | ks = [f"h_cancel_watch_indexs-{code}", f"h_cancel_transaction_index-{code}"] |
| | | for key in ks: |
| | | RedisUtils.delete_async(self.__db, key) |
| | |
| | | # 计算观察索引,倒序计算 |
| | | |
| | | def __compute_watch_index(self, code, buy_single_index): |
| | | """ |
| | | @param code: |
| | | @param buy_single_index: |
| | | @return: |
| | | """ |
| | | if buy_single_index is None: |
| | | return |
| | | if self.__cancel_watch_indexs_cache.get(code): |
| | |
| | | start_compute_index = transaction_index + 1 # max(transaction_index + 1, start_compute_index) |
| | | total_datas = local_today_datas.get(code) |
| | | |
| | | # h撤计算必须超过5s |
| | | if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[buy_single_index]["val"]["time"]) < 5: |
| | | l2_log.h_cancel_debug(code, "5s内囊括计算H撤") |
| | | # h撤计算必须超过3分钟 |
| | | if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[real_place_order_index]["val"]["time"]) < 180: |
| | | l2_log.h_cancel_debug(code, "180s内囊括计算H撤") |
| | | return |
| | | # -----------------计算H上------------------- |
| | | watch_indexes_up = set() |
| | |
| | | if left_count > 0: |
| | | watch_indexes_up.add(i) |
| | | if len(watch_indexes_up) >= 3: |
| | | # 最多取3笔 |
| | | break |
| | | |
| | | # ------------------计算H下----------------------- |
| | |
| | | total_num = 0 |
| | | # 获取m值数据 |
| | | thresh_hold_money = Buy1PriceManager().get_latest_buy1_money(code) |
| | | thresh_hold_money = thresh_hold_money |
| | | # 封单额的1/10 |
| | | thresh_hold_money = thresh_hold_money/10 |
| | | thresh_hold_num = thresh_hold_money // (float(limit_up_price) * 100) |
| | | end_index = real_place_order_index + 1 |
| | | watch_indexes = set() |
| | |
| | | # 设置真实下单位置 |
| | | |
| | | def __need_compute_watch_indexes(self, code, transaction_index): |
| | | """ |
| | | 1.成交进度位距离真实下单位置<=5笔触发囊括 |
| | | 2.成交到(下单那一刻的成交进度位)到(真实下单位置)的后1/10处也要触发囊括 |
| | | 3.L撤无法生效触发囊括 |
| | | @param code: |
| | | @param transaction_index: |
| | | @return: |
| | | """ |
| | | |
| | | start_compute_index = self.__start_compute_index_dict.get(code) |
| | | if start_compute_index is None: |
| | | return False |
| | |
| | | code)) |
| | | cancel_num += val['num'] * (data['re'] - left_count) |
| | | rate = round(cancel_num / total_num, 4) |
| | | must_buy_cancel_rate = constant.H_CANCEL_RATE |
| | | must_buy_cancel_rate = constant.H_CANCEL_RATE_WITH_LDOWN_CANT_INVALID if code in self.__l_cancel_triggered_codes else constant.H_CANCEL_RATE |
| | | try: |
| | | temp_rate = gpcode_manager.MustBuyCodesManager().get_cancel_rate_cache(code) |
| | | if temp_rate: |
| | |
| | | return {}, set() |
| | | |
| | | def start_compute_watch_indexes(self, code, buy_single_index): |
| | | """ |
| | | L后撤无法生效触发的囊括 |
| | | @param code: |
| | | @param buy_single_index: |
| | | @return: |
| | | """ |
| | | self.__l_cancel_triggered_codes.add(code) |
| | | self.__compute_watch_index(code, buy_single_index) |
| | | |
| | | |
| | |
| | | self.__commpute_watch_indexes(code, index, self.__real_place_order_index_dict.get(code)) |
| | | |
| | | def need_cancel(self, code, buy_exec_index, start_index, end_index): |
| | | if 1>0: |
| | | return False, None, "G撤被注释掉" |
| | | |
| | | if code not in self.__real_place_order_index_dict: |
| | | return False, None, "没有找到真实下单位" |
| | | expire_time = self.__expire_time_dict.get(code) |