| | |
| | | __redis_manager = redis_manager.RedisManager(0) |
| | | __sCancelParamsManager = l2_trade_factor.SCancelParamsManager |
| | | __s_big_num_cancel_compute_data_cache = {} |
| | | __s_cancel_real_place_order_index_cache = {} |
| | | |
| | | __instance = None |
| | | |
| | |
| | | val = RedisUtils.get(__redis, k) |
| | | val = json.loads(val) |
| | | tool.CodeDataCacheUtil.set_cache(cls.__s_big_num_cancel_compute_data_cache, code, val) |
| | | |
| | | keys = RedisUtils.keys(__redis, "s_cancel_real_place_order_index-*") |
| | | for k in keys: |
| | | code = k.split("-")[-1] |
| | | val = RedisUtils.get(__redis, k) |
| | | val = int(val) |
| | | tool.CodeDataCacheUtil.set_cache(cls.__s_cancel_real_place_order_index_cache, code, val) |
| | | finally: |
| | | RedisUtils.realse(__redis) |
| | | |
| | |
| | | return cache_result[1] |
| | | return -1, 0, 0 |
| | | |
| | | # 设置真实下单位置 |
| | | def __save_real_place_order_index(self, code, index): |
| | | CodeDataCacheUtil.set_cache(self.__s_cancel_real_place_order_index_cache, code, index) |
| | | key = "s_cancel_real_place_order_index-{}".format(code) |
| | | RedisUtils.setex_async(self.__db, key, tool.get_expire(), index) |
| | | |
| | | def __get_real_place_order_index(self, code): |
| | | key = "s_cancel_real_place_order_index-{}".format(code) |
| | | val = RedisUtils.get(self.__get_redis(), key) |
| | | if val is None: |
| | | return None |
| | | return int(val) |
| | | |
| | | def __get_real_place_order_index_cache(self, code): |
| | | cache_result = CodeDataCacheUtil.get_cache(self.__s_cancel_real_place_order_index_cache, code) |
| | | if cache_result[0]: |
| | | return cache_result[1] |
| | | return None |
| | | |
| | | def __clear_data(self, code): |
| | | CodeDataCacheUtil.clear_cache(self.__s_big_num_cancel_compute_data_cache, code) |
| | | ks = ["s_big_num_cancel_compute_data-{}".format(code)] |
| | | CodeDataCacheUtil.clear_cache(self.__s_cancel_real_place_order_index_cache, code) |
| | | ks = ["s_big_num_cancel_compute_data-{}".format(code), "s_cancel_real_place_order_index-{}".format(code)] |
| | | for key in ks: |
| | | RedisUtils.delete_async(self.__db, key) |
| | | |
| | | # 设置真实下单位置 |
| | | def set_real_place_order_index(self, code, index): |
| | | self.__save_real_place_order_index(code, index) |
| | | |
| | | def clear_data(self): |
| | | ks = ["s_big_num_cancel_compute_data-*"] |
| | | ks = ["s_big_num_cancel_compute_data-*", "s_cancel_real_place_order_index-*"] |
| | | for key in ks: |
| | | keys = RedisUtils.keys(self.__get_redis(), key) |
| | | for k in keys: |
| | | code = k.replace("s_big_num_cancel_compute_data-", "") |
| | | code = k.split("-")[1] |
| | | self.__clear_data(code) |
| | | |
| | | # 计算净大单 |
| | |
| | | # 需要查询买入信号之前的同1s是否有涨停撤的数据 |
| | | process_index = process_index_old |
| | | |
| | | if buy_single_index == start_index: |
| | | if process_index_old == -1: |
| | | # 第1次计算需要计算买入信号-执行位的净值 |
| | | left_big_num = self.__compute_left_big_num(code, buy_single_index, buy_single_index, buy_exec_index, |
| | | total_data, volume_rate_index) |
| | | buy_num += left_big_num |
| | | # 设置买入信号-买入执行位的数据不需要处理 |
| | | start_index = end_index + 1 |
| | | process_index = end_index |
| | | # for i in range(buy_single_index - 1, 0, -1): |
| | | # data = total_data[i] |
| | | # val = data["val"] |
| | | # if val["time"] != total_data[buy_single_index]["val"]["time"]: |
| | | # break |
| | | # if L2DataUtil.is_limit_up_price_buy_cancel(val) and int(val["cancelTime"]) == 0: |
| | | # # 涨停买撤销且撤销的间隔时间为0 |
| | | # # 查询买入信号,如果无法查询到或者是买入位置比买入信号小就不算 |
| | | # buy_index, buy_data = l2_data_util.get_buy_data_with_cancel_data(data, |
| | | # local_today_num_operate_map.get( |
| | | # code)) |
| | | # if buy_index is not None and a_start_index <= buy_index <= a_end_index: |
| | | # # 在买入信号之后 |
| | | # cls.__save_cancel_data(code, i) |
| | | range_seconds = self.__sCancelParamsManager.get_buy_time_range(buy_volume_rate_index) |
| | | process_index = buy_exec_index |
| | | # 强制固定为1s |
| | | range_seconds = 1 # self.__sCancelParamsManager.get_buy_time_range(buy_volume_rate_index) |
| | | # 获取真实下单位置 |
| | | place_order_index = self.__get_real_place_order_index_cache(code) |
| | | |
| | | cancel_rate_threshold = self.__sCancelParamsManager.get_cancel_rate(volume_rate_index) |
| | | try: |
| | | for i in range(start_index, end_index + 1): |
| | |
| | | continue |
| | | |
| | | if L2DataUtil.is_limit_up_price_buy(val): |
| | | |
| | | if place_order_index is not None and place_order_index < data["index"]: |
| | | # 不能比下单位置后 |
| | | continue |
| | | # 如果在囊括时间范围内就可以计算买 |
| | | if tool.trade_time_sub(val["time"], buy_exec_time) <= range_seconds: |
| | | buy_num += data["re"] * int(val["num"]) |
| | |
| | | local_today_num_operate_map.get( |
| | | code)) |
| | | if buy_index is not None and buy_single_index <= buy_index: |
| | | if place_order_index and place_order_index >= buy_index: |
| | | cancel_num += total_data[buy_index]["re"] * int(total_data[buy_index]["val"]["num"]) |
| | | # 买入时间在囊括范围内 |
| | | if tool.trade_time_sub(tool.trade_time_add_second(buy_exec_time, range_seconds), |
| | | total_data[buy_index]["val"]["time"]) >= 0: |
| | | elif tool.trade_time_sub(tool.trade_time_add_second(buy_exec_time, range_seconds), |
| | | total_data[buy_index]["val"]["time"]) >= 0: |
| | | cancel_num += total_data[buy_index]["re"] * int(total_data[buy_index]["val"]["num"]) |
| | | elif buy_index is None: |
| | | # 有部分撤销从而导致的无法溯源,这时就需要判断预估买入时间是否在a_start_index到a_end_index的时间区间 |