Administrator
2024-03-27 87103d9325be0601b6f33eab737fc541b56e9577
bug修复
7个文件已修改
108 ■■■■■ 已修改文件
l2/cancel_buy_strategy.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_manager.py 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
log_module/log_export.py 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/l2_trade_test.py 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test_sell.py 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_api.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_data_manager.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -1730,6 +1730,8 @@
            # 不能是默认下单位置
            return
        trade_index = self.__trade_progress_index_dict.get(code)
        if trade_index is None:
            trade_index = 0
        # 下单15s之后才会重新触发
        total_datas = local_today_datas.get(code)
l2/l2_transaction_data_manager.py
@@ -95,6 +95,9 @@
    # 大卖单的卖单号->卖单信息映射
    __big_sell_order_info_dict = {}
    # 大单列表
    __big_sell_order_info_list_dict = {}
    # 最近的卖单, 格式{code:[卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)]}
    __latest_sell_order_dict = {}
@@ -110,6 +113,10 @@
            cls.__big_sell_order_ids_dict[code] = set()
        if code not in cls.__big_sell_order_info_dict:
            cls.__big_sell_order_info_dict[code] = {}
        if code not in cls.__big_sell_order_info_list_dict:
            cls.__big_sell_order_info_list_dict[code] = []
        for d in datas:
            cls.__latest_sell_order_info_list_dict[code].append(d)
            if code not in cls.__latest_sell_order_dict:
@@ -129,13 +136,14 @@
                        l2_log.info(code, hx_logger_l2_transaction_sell_order, f"{cls.__latest_sell_order_dict[code]}")
                        cls.__big_sell_order_ids_dict[code].add(info[0])
                        cls.__big_sell_order_info_dict[code][info[0]] = info
                        cls.__big_sell_order_info_list_dict[code].append(info)
                    cls.__latest_sell_order_dict[code] = [d[7], d[2], d[1], (d[3], d[6]), (d[3], d[6])]
        latest_time = l2_huaxin_util.convert_time(datas[-1][3], with_ms=True)
        min_time = tool.trade_time_add_millionsecond(latest_time, -1000)
        min_time_int = int(min_time.replace(":", "").replace(".", ""))
        # 计算最近1s的大单成交
        total_datas = cls.__latest_sell_order_info_list_dict.get(code)
        total_big_sell_datas = cls.__big_sell_order_info_list_dict.get(code)
        start_index = 0
        total_sell_info = [0, None]  # 总资金,开始成交信息,结束成交信息
@@ -144,16 +152,18 @@
        # print("大卖单", big_sell_order_ids)
        big_sell_orders = []
        temp_sell_order_ids = set()
        for i in range(len(datas) - 1, -1, -1):
            d = datas[i]
            if d[7] != latest_sell_order_info[0]:
        # 统计已经结算出的大单
        print(f"总大单数量:{len(total_big_sell_datas)}")
        for i in range(len(total_big_sell_datas) - 1, -1, -1):
            bd = total_big_sell_datas[i]
            if bd[0] != latest_sell_order_info[0]:
                # 不是最近的成交且不是大单直接过滤
                if d[7] not in big_sell_order_ids:
                if bd[0] not in big_sell_order_ids:
                    continue
                else:
                    if d[7] not in temp_sell_order_ids:
                        big_sell_orders.append(cls.__big_sell_order_info_dict[code].get(d[7]))
                        temp_sell_order_ids.add(d[7])
                    if bd[0] not in temp_sell_order_ids:
                        big_sell_orders.append(cls.__big_sell_order_info_dict[code].get(bd[0]))
                        temp_sell_order_ids.add(bd[0])
            else:
                # 是最近的但不是大单需要过滤
                if latest_sell_order_info[1] * latest_sell_order_info[2] < 500000:
@@ -163,11 +173,18 @@
                        big_sell_orders.append(latest_sell_order_info)
                        temp_sell_order_ids.add(latest_sell_order_info[0])
            if min_time_int > int(l2_huaxin_util.convert_time(d[3], with_ms=True).replace(":", "").replace(".", "")):
            if min_time_int > int(
                    l2_huaxin_util.convert_time(bd[3][0], with_ms=True).replace(":", "").replace(".", "")):
                start_index = i
                break
            # 统计最近1s的大卖单数据
            total_sell_info[0] += int(d[1] * d[2])
            total_sell_info[0] += int(bd[1] * bd[2])
        # 统计最近的大单
        if latest_sell_order_info[1] * latest_sell_order_info[2] >= 500000:
            if latest_sell_order_info[0] not in temp_sell_order_ids:
                big_sell_orders.append(latest_sell_order_info)
                temp_sell_order_ids.add(latest_sell_order_info[0])
        big_sell_orders.reverse()
        total_sell_info[1] = big_sell_orders
        cls.__latest_sell_order_info_list_dict[code] = cls.__latest_sell_order_info_list_dict[code][start_index:]
log_module/log_export.py
@@ -436,7 +436,7 @@
# 加载华鑫成交的卖单
def load_huaxin_transaction_sell_no(code=None,date = tool.get_now_date_str()):
def load_huaxin_transaction_sell_no(code=None, date=tool.get_now_date_str()):
    path = f"{constant.get_path_prefix()}/logs/huaxin/l2/transaction_sell_order.{date}.log"
    fdatas = {}
    if os.path.exists(path):
@@ -449,7 +449,7 @@
                        data = data[data.find("]") + 1:].strip()
                    data = data.split("code=")[1]
                    code_ = data[:6]
                    if code and code !=code_:
                    if code and code != code_:
                        continue
                    data = data[6:].strip()
                    if code_ not in fdatas:
@@ -501,8 +501,8 @@
# 读取系统日志
def load_huaxin_transaction_map():
    path = f"{constant.get_path_prefix()}/logs/huaxin/l2/transaction.{tool.get_now_date_str()}.log"
def load_huaxin_transaction_map(date=tool.get_now_date_str()):
    path = f"{constant.get_path_prefix()}/logs/huaxin/l2/transaction.{date}.log"
    fdatas = {}
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
test/l2_trade_test.py
@@ -251,22 +251,14 @@
                                                     kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reason_codes_dict())
        # l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, None)
    def test_transaction_orders(self):
    def test_add_transaction_orders(self):
        code = "603359"
        l2.l2_data_util.load_l2_data(code)
        total_datas = l2.l2_data_util.local_today_datas.get(code)
        total_datas = total_datas[:90]
        l2.l2_data_util.local_today_datas[code] = total_datas
        datas = [('603359', 5.85, 224224, 9320665, 6, 286791, 695423, 711926, 'N'),
                 ('603359', 5.85, 512600, 9320665, 6, 286792, 695424, 711926, 'N'),
                 ('603359', 5.85, 300, 9320665, 6, 286793, 695428, 711926, 'N'),
                 ('603359', 5.85, 142876, 9320665, 6, 286794, 695429, 711926, 'N')]
        big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, datas)
        order_begin_pos = l2.l2_data_manager.OrderBeginPosInfo(buy_single_index=4, buy_exec_index=11)
        index = 77
        l2.cancel_buy_strategy.FCancelBigNumComputer().set_real_order_index(code, index, False)
        TradeBuyQueue().set_traded_index(code, 4)
        l2.cancel_buy_strategy.FCancelBigNumComputer().need_cancel_for_p(code, big_sell_order_info, order_begin_pos)
        date = "2024-03-14"
        data_map = log_export.load_huaxin_transaction_map(date=date)
        for code in data_map:
            datas = data_map[code]
            for d in datas:
                big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, d)
    @unittest.skip("跳过此单元测试")
    def test_transaction(self):
test/test_sell.py
@@ -1,7 +1,31 @@
from trade.sell import sell_manager
from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager
from log_module import log_export, async_log_util
from utils import tool
def load_sell_info():
    date = tool.get_now_date_str()
    data_map = log_export.load_huaxin_transaction_map(date=date)
    for code in data_map:
        if code != '002562':
            continue
        datas = data_map[code]
        for d in datas:
            big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, d)
    async_log_util.run_sync()
def test_sell_order_info():
    code = "002562"
    date = tool.get_now_date_str()
    data_map = log_export.load_huaxin_transaction_map(date=date)
    datas = data_map.get(code)
    for d in datas:
        big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, d)
        if big_sell_order_info[0] < 50 * 10000:
            continue
        print(big_sell_order_info)
if __name__ == '__main__':
    code = "000333"
    __HumanSellManager = sell_manager.HumanSellManager()
    f = __HumanSellManager.distribute_sell_volume(code, 2000)
    print(f)
    test_sell_order_info()
third_data/kpl_api.py
@@ -261,4 +261,4 @@
if __name__ == "__main__":
    print(getCodeBlocks("002350"))
    print(getLimitUpInfoNew())
third_data/kpl_data_manager.py
@@ -417,7 +417,7 @@
    def get_limit_up():
        while True:
            if (tool.is_trade_time() and int(tool.get_now_time_str().replace(':', '')) > int("092530")):
            if (tool.is_trade_time() and int(tool.get_now_time_str().replace(':', '')) > int("092530")) or True:
                try:
                    results = kpl_api.getLimitUpInfoNew()
                    result = json.loads(results)
@@ -425,6 +425,7 @@
                    __upload_data("limit_up", result)
                except Exception as e:
                    logging.exception(e)
                    logger_debug.exception(e)
            time.sleep(3)
    def get_bidding_money():