Administrator
2023-09-04 858c30ff646ecd8dd4defc8ccec4334e3fedd847
异步日志加入时间
3个文件已修改
43 ■■■■■ 已修改文件
huaxin_client/trade_client.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
log_module/async_log_util.py 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/trade_client.py
@@ -14,6 +14,7 @@
# 正式账号
from huaxin_client.trade_transform_protocol import TradeRequest, TradeResponse
from log_module import async_log_util
from log_module.log import logger_local_huaxin_trade_debug, logger_system
UserID = '388000013349'
@@ -1010,9 +1011,9 @@
        if local_order_id:
            if local_order_id not in cls.local_order_id_map and orderSystemId:
                cls.local_order_id_map[local_order_id] = orderSystemId
                logger_local_huaxin_trade_debug.info(f"本地订单号与系统订单号映射,{code}:{local_order_id} {orderSystemId}")
                async_log_util.info( logger_local_huaxin_trade_debug, f"本地订单号与系统订单号映射,{code}:{local_order_id} {orderSystemId}")
            if local_order_id in cls.not_canceled_local_order_ids:
                logger_local_huaxin_trade_debug.info(f"执行等待撤单,{code}:{local_order_id} {orderSystemId}")
                async_log_util.info(logger_local_huaxin_trade_debug,f"执行等待撤单,{code}:{local_order_id} {orderSystemId}")
                # 执行撤单
                cls.not_canceled_local_order_ids.discard(local_order_id)
                for i in range(3):
l2/cancel_buy_strategy.py
@@ -1092,7 +1092,7 @@
                        data = total_data[i]
                        val = data['val']
                        total_num += val['num'] * data['re']
                    if total_num >  threshold_num:
                    if total_num > threshold_num:
                        return
        self.__last_trade_progress_dict[code] = index
@@ -1109,14 +1109,16 @@
            # 判断当前订单是否已经撤单
            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code, i, total_data,
                                                                                                  local_today_num_operate_map.get(code))
                                                                                                  local_today_num_operate_map.get(
                                                                                                      code))
            if left_count > 0:
                watch_indexes.add(i)
                total_num += val['num'] * data['re']
                if len(watch_indexes) >= constant.L_CANCEL_MIN_WATCH_COUNT and total_num > threshold_num:
                    break
        l2_log.l_cancel_debug(code, f"设置监听范围,成交进度-{index} , 数据范围:{start_index}-{end_index} 监听范围-{watch_indexes} 纯买手数:{total_num}/{threshold_num}")
        l2_log.l_cancel_debug(code,
                              f"设置监听范围,成交进度-{index} , 数据范围:{start_index}-{end_index} 监听范围-{watch_indexes} 纯买手数:{total_num}/{threshold_num}")
        # 数据维护
        add_indexes = watch_indexes - old_watch_indexes
        delete_indexes = old_watch_indexes - watch_indexes
@@ -1124,7 +1126,7 @@
        self.__del_watch_indexes(code, delete_indexes)
    def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data,
                              local_today_num_operate_map, is_first_code):
                              _local_today_num_operate_map, is_first_code):
        watch_indexes = self.__get_watch_indexes_cache(code)
        if not watch_indexes:
            return False, None
@@ -1141,7 +1143,7 @@
            if L2DataUtil.is_limit_up_price_buy_cancel(val):
                # 查询买入位置
                buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, data,
                                                                                                 local_today_num_operate_map)
                                                                                                 _local_today_num_operate_map)
                if buy_index is not None and buy_index in watch_indexes:
                    need_compute = True
                    break
@@ -1152,7 +1154,7 @@
                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code,
                                                                                                      wi,
                                                                                                      total_data,
                                                                                                      local_today_num_operate_map)
                                                                                                      _local_today_num_operate_map)
                canceled_num += (total_data[wi]["re"] - left_count) * int(total_data[wi]["val"]["num"])
            rate = round(canceled_num / total_num, 3)
            l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},已撤单比例:{rate}")
@@ -1161,7 +1163,7 @@
        return False, None
    def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, local_today_num_operate_map,
    def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, _local_today_num_operate_map,
                    is_first_code):
        time_space = tool.trade_time_sub(total_data[start_index]["val"]["time"],
                                         total_data[buy_exec_index]["val"]["time"])
@@ -1169,7 +1171,7 @@
        if time_space <= constant.L_CANCEL_START_TIME or int(tool.get_now_time_str().replace(":", "")) > int("145000"):
            return False, None
        can_cancel, cancel_data = self.__compute_need_cancel(code, buy_exec_index, start_index, end_index, total_data,
                                                             local_today_num_operate_map, is_first_code)
                                                             _local_today_num_operate_map, is_first_code)
        if can_cancel:
            # 判断成交进度位置到当前位置的净买入
            try:
@@ -1199,9 +1201,9 @@
                        if left_count > 0:
                            buy_nums += left_count * data["val"]["num"]
                            if buy_nums > threshold_num:
                                l2_log.l_cancel_debug(code, f"LX阻断L撤撤单:{buy_nums}/{threshold_num}")
                                l2_log.l_cancel_debug(code, f"LX阻断L撤撤单:{buy_nums}/{threshold_num}  成交位置-{transaction_index} 真实下单位置-{place_order_index}")
                                return False, "LX阻断L撤撤单"
                l2_log.l_cancel_debug(code, f"LX尚未阻断L撤撤单:{buy_nums}/{threshold_num}")
                l2_log.l_cancel_debug(code, f"LX尚未阻断L撤撤单:{buy_nums}/{threshold_num} 成交位置-{transaction_index} 真实下单位置-{place_order_index}")
                return can_cancel, cancel_data
            except Exception as e:
                l2_log.l_cancel_debug(code, f"LX撤单计算异常:{str(e)}")
log_module/async_log_util.py
@@ -2,14 +2,16 @@
异步日志管理器
"""
import queue
import time
from log_module.log import logger_debug
from utils import tool
log_queue = queue.Queue()
def __add_log(logger, method, *args):
    log_queue.put_nowait((logger, method, args))
    log_queue.put_nowait((logger, time.time(), method, args))
def debug(logger, *args):
@@ -37,14 +39,18 @@
    while True:
        try:
            val = log_queue.get()
            cmd = val[1]
            time_s = val[1]
            cmd = val[2]
            method = getattr(val[0], cmd)
            method(*val[2])
            d = list(val[3])
            d[0] = f"[{tool.to_time_str(int(time_s))}.{str(time_s).split('.')[1][:3]}] " + d[0]
            d = tuple(d)
            method(*d)
        except:
            pass
if __name__ == "__main__":
    logger_debug.warning()
    info(logger_debug, "*-{}", "test")
    # info(logger_debug, "*-{}", "test")
    info(logger_debug, "123123")
    run_sync()