| | |
| | | self.__del_real_order_index(code) |
| | | |
| | | # 设置成交位 |
| | | def set_trade_progress(self, code, index, buy_exec_index, total_data, local_today_num_operate_map, m_value, |
| | | def set_trade_progress(self, code, index, buy_exec_index, total_data, local_today_num_operate_map, m_base_value, |
| | | limit_up_price): |
| | | # 离下单执行位2分钟内的有效 |
| | | sub_time = tool.trade_time_sub(total_data[-1]['val']['time'], total_data[buy_exec_index]['val']['time']) |
| | |
| | | local_today_num_operate_map) |
| | | left_num += val['num'] * left_count |
| | | # 剩下的不足动态M值的1/2 |
| | | rate = round(float(limit_up_price) * left_num * 100 / m_value, 3) |
| | | rate = round(float(limit_up_price) * left_num * 100 / m_base_value, 3) |
| | | logger_l2_d_cancel.info( |
| | | f"{code}成交进度({index})到下单位置({real_order_index})的剩余笔数:{left_num},撤单比例:{rate},m值:{m_value}") |
| | | f"{code}成交进度({index})到下单位置({real_order_index})的剩余笔数:{left_num},撤单比例:{rate},m值:{m_base_value}") |
| | | if rate < constant.D_CANCEL_RATE: |
| | | l2_log.cancel_debug(code, "D撤撤单,比例为:{},目标比例{}", rate, constant.D_CANCEL_RATE) |
| | | return True, f"D撤比例为:{rate}" |
| | |
| | | __last_trade_progress_dict = {} |
| | | __real_place_order_index_dict = {} |
| | | __cancel_watch_index_cache = {} |
| | | # 成交位附近临近大单索引 |
| | | __near_by_trade_progress_big_num_index_cache = {} |
| | | |
| | | __SecondCancelBigNumComputer = SecondCancelBigNumComputer() |
| | | |
| | | __instance = None |
| | |
| | | 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_near_by_big_num_index-*") |
| | | for k in keys: |
| | | code = k.split("-")[-1] |
| | | val = RedisUtils.get(__redis, k) |
| | | val = int(val) |
| | | CodeDataCacheUtil.set_cache(cls.__near_by_trade_progress_big_num_index_cache, code, val) |
| | | finally: |
| | | RedisUtils.realse(__redis) |
| | | |
| | |
| | | if cache_result[0]: |
| | | return cache_result[1] |
| | | return set() |
| | | |
| | | def __set_near_by_big_num_index(self, code, index): |
| | | self.__near_by_trade_progress_big_num_index_cache[code] = index |
| | | RedisUtils.setex_async(self.__db, f"l_cancel_near_by_big_num_index-{code}", tool.get_expire(), index) |
| | | |
| | | def __get_near_by_big_num_index(self, code): |
| | | val = RedisUtils.get(self.__get_redis(), f"l_cancel_near_by_big_num_index-{code}") |
| | | if val is None: |
| | | return None |
| | | return int(val) |
| | | |
| | | def __get_near_by_big_num_index_cache(self, code): |
| | | cache_result = CodeDataCacheUtil.get_cache(self.__near_by_trade_progress_big_num_index_cache, code) |
| | | if cache_result[0]: |
| | | return cache_result[1] |
| | | return None |
| | | |
| | | def del_watch_index(self, code): |
| | | CodeDataCacheUtil.clear_cache(self.__cancel_watch_index_cache, code) |
| | |
| | | if buy_single_index: |
| | | self.compute_watch_index(code, buy_single_index, index) |
| | | |
| | | # 计算范围内的成交位临近未撤大单 |
| | | def __compute_near_by_big_num_index(self, code, start_index, end_index, total_datas): |
| | | MIN_MONEYS = [300, 200, 100, 50] |
| | | for min_money in MIN_MONEYS: |
| | | final_index = None |
| | | for i in range(start_index, end_index): |
| | | 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(code, i, |
| | | total_datas, |
| | | local_today_num_operate_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | final_index = i |
| | | break |
| | | if final_index: |
| | | self.__near_by_trade_progress_big_num_index_cache[code] = final_index |
| | | break |
| | | |
| | | # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化 |
| | | def set_trade_progress(self, code, index, total_data): |
| | | def set_trade_progress(self, code, index, total_datas): |
| | | # 临近撤先撤单 |
| | | # 如果成交位置并未该改变且没有没有找到成交位置临近大单 |
| | | # need_compute_big = False |
| | | # if self.__last_trade_progress_dict.get( |
| | | # code) == index and code not in self.__near_by_trade_progress_big_num_index_cache: |
| | | # need_compute_big = True |
| | | # elif self.__last_trade_progress_dict.get(code) != index: |
| | | # need_compute_big = True |
| | | # |
| | | # # 设置成交位置临近大单监听 |
| | | # real_place_order = self.__real_place_order_index_dict.get(code) |
| | | # # 真实下单位置 |
| | | # end_index = real_place_order |
| | | # if not end_index: |
| | | # end_index = total_datas[-1]["index"] |
| | | # |
| | | # if need_compute_big: |
| | | # self.__compute_near_by_big_num_index(code, index+1, end_index, total_datas) |
| | | |
| | | if self.__last_trade_progress_dict.get(code) == index: |
| | | return |
| | | |
| | | try: |
| | | # 已经有计算的无法触发计算 |
| | | old_watch_indexes = self.__get_watch_indexes_cache(code) |