Administrator
2023-08-17 64e3a7e0ff73f1c9e5cba442a86254de4242a7ac
删除redis日志与时间日志
8个文件已修改
198 ■■■■■ 已修改文件
code_attribute/limit_up_time_manager.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/redis_manager_delegate.py 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager.py 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 104 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_util.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test.py 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_manager.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/limit_up_time_manager.py
@@ -37,9 +37,8 @@
        if not cache_result[0] or cache_result[1] is None:
            global_util.limit_up_time[code] = time
            tool.CodeDataCacheUtil.set_cache(self.__limit_up_time_cache, code, time)
            # TODO 测试
            # RedisUtils.setex_async(
            #     self.__db, "limit_up_time-{}".format(code), tool.get_expire(), time)
            RedisUtils.setex_async(
                self.__db, "limit_up_time-{}".format(code), tool.get_expire(), time)
    def get_limit_up_time(self, code):
        time = global_util.limit_up_time.get(code)
db/redis_manager_delegate.py
@@ -40,7 +40,8 @@
        try:
            return lamada_method()
        finally:
            logger_redis_debug.info("{}({}):{}", method_name, round((time.time() - __start_time) * 1000, 3), key)
            # logger_redis_debug.info("{}({}):{}", method_name, round((time.time() - __start_time) * 1000, 3), key)
            pass
    @classmethod
    def __request(cls, db, cmd, key, args=None):
@@ -49,7 +50,7 @@
            "cmd": cmd,
            "key": key,
        }
        if args:
        if args is not None:
            data["args"] = args
        fdata = middle_api_protocol.load_redis_cmd(data)
        result = middle_api_protocol.request(fdata)
@@ -74,7 +75,7 @@
    @classmethod
    def delete_async(cls, db, key, auto_free=True):
        cls.add_async_task(db, "delete", (key))
        logger_redis_debug.info("delete_async({}):{}", 0, key)
        # logger_redis_debug.info("delete_async({}):{}", 0, key)
    @classmethod
    def keys(cls, redis_, key, auto_free=True):
@@ -91,7 +92,7 @@
    @classmethod
    def setex_async(cls, db, key, expire, val, auto_free=True):
        cls.add_async_task(db, "setex", (key, expire, val))
        logger_redis_debug.info("setex_async({}):{}", 0, key)
        # logger_redis_debug.info("setex_async({}):{}", 0, key)
    @classmethod
    def setnx(cls, redis_, key, val, auto_free=True):
@@ -104,7 +105,7 @@
    @classmethod
    def expire_async(cls, db, key, expire, auto_free=True):
        cls.add_async_task(db, "expire", (key, expire))
        logger_redis_debug.info("expire_async({}):{}", 0, key)
        # logger_redis_debug.info("expire_async({}):{}", 0, key)
    @classmethod
    def sadd(cls, redis_, key, val, auto_free=True):
@@ -113,7 +114,7 @@
    @classmethod
    def sadd_async(cls, db, key, val, auto_free=True):
        cls.add_async_task(db, "sadd", (key, val))
        logger_redis_debug.info("sadd_async({}):{}", 0, key)
        # logger_redis_debug.info("sadd_async({}):{}", 0, key)
    @classmethod
    def sismember(cls, redis_, key, val, auto_free=True):
@@ -133,7 +134,7 @@
    @classmethod
    def srem_async(cls, db, key, val, auto_free=True):
        cls.add_async_task(db, "srem", (key, val))
        logger_redis_debug.info("srem_async({}):{}", 0, key)
        # logger_redis_debug.info("srem_async({}):{}", 0, key)
    @classmethod
    def incrby(cls, redis_, key, num, auto_free=True, _async=False):
@@ -142,7 +143,7 @@
    @classmethod
    def incrby_async(cls, db, key, num, auto_free=True):
        cls.add_async_task(db, "incrby", (key, num))
        logger_redis_debug.info("incrby_async({}):{}", 0, key)
        # logger_redis_debug.info("incrby_async({}):{}", 0, key)
    @classmethod
    def lpush(cls, redis_, key, val, auto_free=True):
l2/cancel_buy_strategy.py
@@ -1376,9 +1376,9 @@
            process_end_index = cancel_index
        # 保存最新累计金额
        # cls.__set_l2_latest_money_record(code, process_end_index, total_num)
        l2_data_log.l2_time(code, round(time.time() * 1000) - start_time,
                            "l2数据封单额计算时间",
                            False)
        # l2_data_log.l2_time(code, round(time.time() * 1000) - start_time,
        #                     "l2数据封单额计算时间",
        #                     False)
        if cancel_index:
            l2_log.cancel_debug(code, "数据处理位置:{}-{},{},最终买1为:{}", start_index, end_index, record_msg,
                                total_num)
l2/l2_data_manager.py
@@ -109,7 +109,6 @@
                code)
            data_ = (_buy_single_index, buy_exec_index, compute_index, nums, count, list(max_num_sets),
                     volume_rate)
        logger_debug.info(f"保存买入执行位置信息{code}:{data_}")
        CodeDataCacheUtil.set_cache(self.__buy_compute_index_info_cache, code, data_)
        RedisUtils.setex_async(self.__db, _key, expire, json.dumps(data_))
@@ -140,8 +139,7 @@
    # 删除买撤点数据
    def delete_buy_cancel_point(self, code):
        tool.CodeDataCacheUtil.clear_cache(self.__buy_cancel_single_pos_cache, code)
        # TODO 测试
        # RedisUtils.delete_async(self.__db, "buy_cancel_single_pos-{}".format(code))
        RedisUtils.delete_async(self.__db, "buy_cancel_single_pos-{}".format(code))
# 清除l2数据
l2/l2_data_manager_new.py
@@ -271,9 +271,9 @@
                    # 保存数据
                    __start_time = round(t.time() * 1000)
                    l2.l2_data_util.save_l2_data(code, datas, add_datas)
                    __start_time = l2_data_log.l2_time(code,
                                                       round(t.time() * 1000) - __start_time,
                                                       "保存数据时间({})".format(len(add_datas)))
                    # __start_time = l2_data_log.l2_time(code,
                    #                                    round(t.time() * 1000) - __start_time,
                    #                                    "保存数据时间({})".format(len(add_datas)))
        finally:
            if code in cls.unreal_buy_dict:
                cls.unreal_buy_dict.pop(code)
@@ -325,9 +325,10 @@
            logger_l2_error.exception(f"code:{code}")
            logger_l2_error.exception(e)
        finally:
            l2_data_log.l2_time(code, round(t.time() * 1000) - origin_start_time,
                                "l2数据处理总耗时",
                                True)
            # l2_data_log.l2_time(code, round(t.time() * 1000) - origin_start_time,
            #                     "l2数据处理总耗时",
            #                     True)
            pass
            if datas:
                l2.l2_data_util.save_l2_data(code, None, datas)
@@ -351,8 +352,8 @@
                        limit_up_time_manager.LimitUpTimeManager().save_limit_up_time(code, "09:30:00")
        total_datas = local_today_datas[code]
        __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
                                           "l2数据预处理时间")
        # __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
        #                                    "l2数据预处理时间")
        if len(add_datas) > 0:
            # 是否为首板代码
@@ -376,8 +377,8 @@
            latest_time = add_datas[len(add_datas) - 1]["val"]["time"]
            __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
                                               "l2数据准备时间")
            # __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
            #                                    "l2数据准备时间")
            # 时间差不能太大才能处理
            if not l2_trade_util.is_in_forbidden_trade_codes(code):
                # 判断是否已经挂单
@@ -409,8 +410,8 @@
            logger_l2_process.info("code:{} 处理数据范围: {}-{} 处理时间:{} 截图时间戳:{}", code, add_datas[0]["index"],
                                   add_datas[-1]["index"], round(t.time() * 1000) - __start_time,
                                   capture_timestamp)
            __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
                                               "l2数据处理时间")
            # __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
            #                                    "l2数据处理时间")
    # 处理未挂单
    @classmethod
@@ -418,9 +419,9 @@
        __start_time = round(t.time() * 1000)
        # 获取阈值
        threshold_money, msg = cls.__get_threshmoney(code)
        if round(t.time() * 1000) - __start_time > 10:
            __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
                                               "获取m值数据耗时")
        # if round(t.time() * 1000) - __start_time > 10:
        #     __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
        #                                        "获取m值数据耗时")
        if True:  # end_index - start_index < 10:
            cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time, is_first_code)
        else:
@@ -457,8 +458,8 @@
            cls.__buyL2SafeCountManager.compute_left_rate(code, start_index, end_index, total_data,
                                                          local_today_num_operate_map.get(code))
            l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
                                "已下单-获取买入信息耗时")
            # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
            #                     "已下单-获取买入信息耗时")
            return None, ""
        @dask.delayed
@@ -468,8 +469,8 @@
            # 计算m值大单
            cls.l2BigNumForMProcessor.process(code, max(buy_single_index, start_index), end_index,
                                              gpcode_manager.get_limit_up_price(code))
            l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
                                "已下单-m值大单计算")
            # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
            #                     "已下单-m值大单计算")
            return None, ""
        # 买1撤计算
@@ -481,8 +482,8 @@
                                                                                 end_index,
                                                                                 buy_single_index, buy_exec_index)
            l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
                                "已下单-买1统计耗时")
            # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
            #                     "已下单-买1统计耗时")
            # 买1不会触发撤单
            return None, ""
            # return cancel_data, cancel_msg
@@ -508,8 +509,9 @@
                logger_l2_error.error(f"参数:buy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index}")
                logger_l2_error.exception(e)
            finally:
                l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
                                    "已下单-s级大单估算")
                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
                #                     "已下单-s级大单估算")
                pass
            return None, ""
        # H撤
@@ -533,7 +535,8 @@
                logger_l2_error.error(f"参数:buy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index}")
                logger_l2_error.exception(e)
            finally:
                l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-H撤大单计算")
                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-H撤大单计算")
                pass
            return None, ""
        # L撤
@@ -553,7 +556,8 @@
                logger_l2_error.error(f"参数:buy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index}")
                logger_l2_error.exception(e)
            finally:
                l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-L撤大单计算")
                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-L撤大单计算")
                pass
            return None, ""
        # 板上卖撤
@@ -569,7 +573,8 @@
            except Exception as e:
                logging.exception(e)
            finally:
                l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-板上卖耗时")
                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-板上卖耗时")
                pass
            return None, ""
        # 是否需要撤销
@@ -618,19 +623,19 @@
        if not cancel_data:
            cancel_data, cancel_msg = l_cancel(buy_single_index, buy_exec_index)
        l2_log.debug(code, "撤单计算结束")
        _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                                          "已下单-撤单 判断是否需要撤单")
        # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
        #                                   "已下单-撤单 判断是否需要撤单")
        if cancel_data:
            l2_log.debug(code, "触发撤单,撤单位置:{} ,撤单原因:{}", cancel_data["index"], cancel_msg)
            l2_log.trade_record(code, "撤单", "'index':{} , 'msg':'{}'", cancel_data["index"], cancel_msg)
            # 撤单
            if cls.cancel_buy(code, cancel_msg):
                _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                                                  "已下单-撤单 耗时")
                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                #                                   "已下单-撤单 耗时")
                # 撤单成功,继续计算下单
                cls.__process_not_order(code, cancel_data["index"] + 1, end_index, capture_time, is_first_code)
                _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                                                  "处理剩余数据 耗时")
                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                #                                   "处理剩余数据 耗时")
            else:
                # 撤单尚未成功
                pass
@@ -653,8 +658,8 @@
                # lp.disable()
                # logger_profile.info(output.getvalue())
                _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                                                  "已虚拟下单-执行真实下单 外部耗时")
                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                #                                   "已虚拟下单-执行真实下单 外部耗时")
    @classmethod
    def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code):
@@ -665,7 +670,7 @@
        else:
            can, need_clear_data, reason = cls.__can_buy_first(code)
        __start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - __start_time, "最后判断是否能下单", force=True)
        # __start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - __start_time, "最后判断是否能下单", force=True)
        # 删除虚拟下单
        if code in cls.unreal_buy_dict:
            cls.unreal_buy_dict.pop(code)
@@ -864,7 +869,8 @@
            # 可以下单
            return True, False, None
        finally:
            l2_data_log.l2_time(code, round((t.time() - __start_time) * 1000), "是否可以下单计算")
            # l2_data_log.l2_time(code, round((t.time() - __start_time) * 1000), "是否可以下单计算")
            pass
    @classmethod
    def __can_buy_first(cls, code):
@@ -1111,7 +1117,7 @@
                # 如果是今天第一次有下单开始信号,需要设置大单起始点
                cls.l2BigNumForMProcessor.set_begin_pos(code, buy_single_index)
        _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "下单信号计算时间")
        # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "下单信号计算时间")
        if buy_single_index is None:
            # 未获取到买入信号,终止程序
@@ -1127,11 +1133,11 @@
                                          compute_end_index,
                                          gpcode_manager.get_limit_up_price(code))
        _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "计算m值大单")
        # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "计算m值大单")
        threshold_money, msg = cls.__get_threshmoney(code)
        _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "m值阈值计算")
        # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "m值阈值计算")
        # 买入纯买额统计
        compute_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new = cls.__sum_buy_num_for_order_3(code,
@@ -1141,7 +1147,7 @@
                                                                                                             threshold_money,
                                                                                                             buy_single_index,
                                                                                                             max_num_set)
        _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "纯买额统计时间")
        # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "纯买额统计时间")
        l2_log.debug(code, "m值-{} 量比:{} rebegin_buy_pos:{}", threshold_money, cls.volume_rate_info[code][0],
                     rebegin_buy_pos)
@@ -1192,10 +1198,10 @@
            #                                          buy_single_index,
            #                                          buy_exec_index, False)
            l2_log.debug(code, "记录执行买入数据结束")
            # l2_log.debug(code, "记录执行买入数据结束")
            _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                                              "记录执行买入数据", force=True)
            # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
            #                                   "记录执行买入数据", force=True)
            # 数据是否处理完毕
            if compute_index >= compute_end_index:
@@ -1206,8 +1212,8 @@
                                                                                        cls.volume_rate_info[code][1],
                                                                                        cls.volume_rate_info[code][1],
                                                                                        True)
                _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                                                  "S级大单处理耗时", force=True)
                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                #                                   "S级大单处理耗时", force=True)
                l2_log.debug(code, "数据处理完毕,下单, 数据截图时间-{}", capture_time)
                # 数据已经处理完毕,如果还没撤单就实际下单
                if need_cancel:
@@ -1223,8 +1229,8 @@
                                                             cls.volume_rate_info[code][1], False)
                l2_log.debug(code, "S级大单处理")
                _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                                                  "S级大单处理耗时", force=True)
                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                #                                   "S级大单处理耗时", force=True)
                # 数据尚未处理完毕,进行下一步处理
                l2_log.debug(code, "数据尚未处理完毕,进行下一步处理,处理进度:{} end_index:{}", compute_index, compute_end_index)
                # 处理撤单步骤
@@ -1238,8 +1244,8 @@
                # lp.disable()
                # logger_profile.info(output.getvalue())
                _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                                                  f"处理撤单步骤耗时,范围:{compute_index + 1}-{compute_end_index}", force=True)
                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                #                                   f"处理撤单步骤耗时,范围:{compute_index + 1}-{compute_end_index}", force=True)
        else:
            # 未达到下单条件,保存纯买额,设置纯买额
            # 记录买入信号位置
l2/l2_data_util.py
@@ -153,7 +153,7 @@
        __start_time = round(time.time() * 1000)
        if datas:
            RedisUtils.setex_async(_redisManager.getRedis(), "l2-data-latest-{}".format(code), tool.get_expire(), json.dumps(datas))
            l2_data_log.l2_time(code, round(time.time() * 1000) - __start_time, "保存最近l2数据用时")
            # l2_data_log.l2_time(code, round(time.time() * 1000) - __start_time, "保存最近l2数据用时")
            # 设置进内存
            local_latest_datas[code] = datas
            set_l2_data_latest_count(code, len(datas))
test/test.py
@@ -1,4 +1,56 @@
from log_module.log import logger_l2_process_time
import logging
import threading
import time
from log_module.log import logger_l2_process_time, logger_debug
class TestInstance:
    __instance = None
    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            cls.__instance = super(TestInstance, cls).__new__(cls, *args, **kwargs)
            print(cls.__instance)
        return cls.__instance
    def test(self):
        i=2
        i+=1
_dict = {}
def test_time(instance, i):
    start = time.time()
    instance.test()
    logger_debug.info(f"开始:{i}")
    time.time()
    # round(time.time() * 1000) - round(start * 1000)
    logger_debug.info(f"结束:{i}")
    if len(_dict.keys()) == 99:
        total = 0
        for k in _dict:
            total += _dict[k]
        print(total / len(_dict))
if __name__ == "__main__":
    logger_l2_process_time.info("test123")
    # for k in range(1):
    #     _dict.clear()
    #     for i in range(0, 100):
    #         threading.Thread(target=lambda: test_time(TestInstance(), i), daemon=True).start()
    #     time.sleep(2)
    print(time.time())
    for i in range(1000):
        # logger_debug.debug("结束")
        TestInstance().test()
        pass
    print(time.time())
    for i in range(1000):
        logger_debug.debug("结束")
        pass
    print(time.time())
    input()
trade/trade_manager.py
@@ -434,9 +434,9 @@
    print("开始买入")
    logger_trade.info("{}开始买入".format(code))
    CodesTradeStateManager().set_trade_state(code, TRADE_STATE_BUY_PLACE_ORDER)
    _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "买入判断时间", force=True)
    # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "买入判断时间", force=True)
    __buy(code, price, trade_state, capture_timestamp, last_data, last_data_index)
    l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "异步买入时间", force=True)
    # l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "异步买入时间", force=True)
# 中断买入