Administrator
2023-08-17 090c62e276a49fb5d16438a4a33f06522dbccc1f
删除虚拟下单
4个文件已修改
246 ■■■■ 已修改文件
code_attribute/gpcode_manager.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 224 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test.py 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/current_price_process_manager.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/gpcode_manager.py
@@ -513,7 +513,7 @@
def get_gp_list():
    codes = RedisUtils.smembers(__redisManager.getRedis(), "gp_list")
    first_codes = FirstGPCodesManager().get_first_gp_codes()
    first_codes = FirstGPCodesManager().get_first_gp_codes_cache()
    return set.union(codes, first_codes)
l2/l2_data_manager_new.py
@@ -8,12 +8,13 @@
from db.redis_manager_delegate import RedisUtils
from l2.huaxin import l2_huaxin_util, huaxin_delegate_postion_manager
from third_data import kpl_data_manager, block_info
from trade.deal_big_money_manager import DealComputeProgressManager
from utils import global_util, ths_industry_util, tool
import l2_data_util
from db import redis_manager_delegate as redis_manager
from third_data.code_plate_key_manager import CodePlateKeyBuyManager
from trade import trade_manager, trade_queue_manager, l2_trade_factor, l2_trade_util, \
    trade_result_manager, first_code_score_manager, current_price_process_manager, trade_data_manager
    trade_result_manager, first_code_score_manager, current_price_process_manager, trade_data_manager, trade_huaxin
from l2 import safe_count_manager, l2_data_manager, l2_data_log, l2_log, l2_data_source_util, code_price_manager, \
    transaction_progress
from l2.cancel_buy_strategy import SecondCancelBigNumComputer, HourCancelBigNumComputer, L2LimitUpMoneyStatisticUtil, \
@@ -220,13 +221,20 @@
    __SecondCancelBigNumComputer = SecondCancelBigNumComputer()
    __HourCancelBigNumComputer = HourCancelBigNumComputer()
    __LCancelBigNumComputer = LCancelBigNumComputer()
    __DCancelBigNumComputer = DCancelBigNumComputer()
    __TradeStateManager = trade_manager.TradeStateManager()
    __CodesTradeStateManager = trade_manager.CodesTradeStateManager()
    __PauseBuyCodesManager = gpcode_manager.PauseBuyCodesManager()
    __Buy1PriceManager = code_price_manager.Buy1PriceManager()
    __AccountAvailableMoneyManager = AccountAvailableMoneyManager()
    __TradeBuyDataManager = trade_data_manager.TradeBuyDataManager()
    __LimitUpTimeManager =  limit_up_time_manager.LimitUpTimeManager()
    __LimitUpTimeManager = limit_up_time_manager.LimitUpTimeManager()
    __BlackListCodeManager = l2_trade_util.BlackListCodeManager()
    __WhiteListCodeManager = l2_trade_util.WhiteListCodeManager()
    __WantBuyCodesManager = gpcode_manager.WantBuyCodesManager()
    __TradeTargetCodeModeManager = TradeTargetCodeModeManager()
    __DealComputeProgressManager = DealComputeProgressManager()
    __TradeOrderIdManager = trade_huaxin.TradeOrderIdManager()
    # 获取代码评分
    @classmethod
@@ -304,7 +312,7 @@
            place_order_index = huaxin_delegate_postion_manager.get_l2_place_order_position(code, datas)
            if place_order_index:
                logger_l2_process.info("code:{} 获取到下单真实位置:{}", code, place_order_index)
                DCancelBigNumComputer().set_real_order_index(code, place_order_index)
                cls.__DCancelBigNumComputer.set_real_order_index(code, place_order_index)
            __start_time = round(t.time() * 1000)
            if len(datas) > 0:
                cls.process_add_datas(code, datas, 0, __start_time)
@@ -451,52 +459,14 @@
            return
        cls.__latest_process_unique_keys[code] = unique_key
        # 计算安全笔数
        @dask.delayed
        def compute_safe_count():
            _start_time = round(t.time() * 1000)
            # 处理安全笔数
            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,
            #                     "已下单-获取买入信息耗时")
            return None, ""
        @dask.delayed
        # m值大单计算
        def compute_m_big_num():
            _start_time = round(t.time() * 1000)
            # 计算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值大单计算")
            return None, ""
        # 买1撤计算
        @dask.delayed
        def buy_1_cancel():
            _start_time = round(t.time() * 1000)
            # 撤单计算,只看买1
            cancel_data, cancel_msg = L2LimitUpMoneyStatisticUtil().process_data(code, start_index,
                                                                                 end_index,
                                                                                 buy_single_index, buy_exec_index)
            # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
            #                     "已下单-买1统计耗时")
            # 买1不会触发撤单
            return None, ""
            # return cancel_data, cancel_msg
        # S撤
        # @dask.delayed
        def s_cancel(_buy_single_index,_buy_exec_index):
        def s_cancel(_buy_single_index, _buy_exec_index):
            _start_time = round(t.time() * 1000)
            # S撤单计算,看秒级大单撤单
            try:
                b_need_cancel, b_cancel_data = cls.__SecondCancelBigNumComputer.need_cancel(code, _buy_single_index,
                                                                                            _buy_exec_index, start_index,
                                                                                            _buy_exec_index,
                                                                                            start_index,
                                                                                            end_index, total_data,
                                                                                            code_volumn_manager.get_volume_rate_index(
                                                                                                buy_volume_rate),
@@ -516,8 +486,7 @@
            return None, ""
        # H撤
        # @dask.delayed
        def h_cancel(_buy_single_index,_buy_exec_index):
        def h_cancel(_buy_single_index, _buy_exec_index):
            _start_time = round(t.time() * 1000)
            try:
                b_need_cancel, b_cancel_data = cls.__HourCancelBigNumComputer.need_cancel(code, _buy_single_index,
@@ -541,8 +510,7 @@
            return None, ""
        # L撤
        # @dask.delayed
        def l_cancel(_buy_single_index,_buy_exec_index):
        def l_cancel(_buy_single_index, _buy_exec_index):
            _start_time = round(t.time() * 1000)
            try:
                b_need_cancel, b_cancel_data = cls.__LCancelBigNumComputer.need_cancel(code,
@@ -561,37 +529,6 @@
                pass
            return None, ""
        # 板上卖撤
        @dask.delayed
        def sell_cancel():
            _start_time = round(t.time() * 1000)
            # 统计板上卖
            try:
                cancel_data, cancel_msg = L2LimitUpSellStatisticUtil().process(code, start_index,
                                                                               end_index,
                                                                               buy_exec_index)
                return cancel_data, cancel_msg
            except Exception as e:
                logging.exception(e)
            finally:
                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-板上卖耗时")
                pass
            return None, ""
        # 是否需要撤销
        @dask.delayed
        def is_need_cancel(*args):
            try:
                for i in range(0, len(args)):
                    _cancel_data, _cancel_msg = args[i]
                    if _cancel_data:
                        return _cancel_data, _cancel_msg
            except Exception as e:
                logging.exception(e)
            finally:
                pass
            return None, ""
        if start_index < 0:
            start_index = 0
@@ -602,20 +539,6 @@
        # 获取买入信号起始点
        buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos(
            code)
        # 老版本撤单
        # f1 = compute_safe_count()
        # f2 = compute_m_big_num()
        # f3 = s_cancel()
        # f4 = h_cancel()
        # f5 = buy_1_cancel()
        # f6 = sell_cancel()
        # f7 = l_cancel()
        # dask_result = is_need_cancel(f1, f2, f3, f4, f5, f6, f7)
        # if is_first_code:
        #     dask_result = is_need_cancel(f3, f4, f7)
        # l2_log.debug(code, "撤单计算开始")
        # cancel_data, cancel_msg = dask_result.compute()
        # l2_log.debug(code, "撤单计算结束")
        # 依次处理
        cancel_data, cancel_msg = s_cancel(buy_single_index, buy_exec_index)
@@ -641,26 +564,7 @@
                # 撤单尚未成功
                pass
        else:
            # 如果有虚拟下单需要真实下单
            unreal_buy_info = cls.unreal_buy_dict.get(code)
            if unreal_buy_info is not None:
                l2_log.debug(code, "有虚拟下单,无买撤信号,开始执行买入,执行位置:{},截图时间:{}", unreal_buy_info[0], capture_time)
                # unreal_buy_info 的内容格式为:(触法买操作下标,截图时间)
                # 真实下单
                cls.__buy(code, unreal_buy_info[1], local_today_datas[code][unreal_buy_info[0]],
                          unreal_buy_info[0], is_first_code)
                # lp = LineProfiler()
                # lp.enable()
                # lp_wrap = lp(cls.__buy)
                # lp_wrap(code, unreal_buy_info[1], local_today_datas[code][unreal_buy_info[0]],
                #         unreal_buy_info[0], is_first_code)
                # output = io.StringIO()
                # lp.print_stats(stream=output)
                # lp.disable()
                # logger_profile.info(output.getvalue())
                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                #                                   "已虚拟下单-执行真实下单 外部耗时")
            pass
    @classmethod
    def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code):
@@ -713,7 +617,7 @@
    def __can_cancel(cls, code):
        if constant.TEST:
            return True, ""
        if l2_trade_util.WhiteListCodeManager().is_in_cache(code):
        if cls.__WhiteListCodeManager.is_in_cache(code):
            return False, "代码在白名单中"
        # 暂时注释掉
@@ -802,7 +706,7 @@
            if volumn_rate >= 1.3:
                return False, False, "最大量比超过1.3不能买"
            limit_up_time =cls.__LimitUpTimeManager.get_limit_up_time_cache(code)
            limit_up_time = cls.__LimitUpTimeManager.get_limit_up_time_cache(code)
            if limit_up_time is not None:
                limit_up_time_seconds = l2.l2_data_util.L2DataUtil.get_time_as_second(
                    limit_up_time)
@@ -962,8 +866,8 @@
        #                               cls.__l2PlaceOrderParamsManagerDict[code].score_index,
        #                               cls.__l2PlaceOrderParamsManagerDict[code].score_info)
        if not gpcode_manager.WantBuyCodesManager().is_in_cache(code):
            if TradeTargetCodeModeManager().get_mode_cache() == TradeTargetCodeModeManager.MODE_ONLY_BUY_WANT_CODES:
        if not cls.__WantBuyCodesManager.is_in_cache(code):
            if cls.__TradeTargetCodeModeManager.get_mode_cache() == TradeTargetCodeModeManager.MODE_ONLY_BUY_WANT_CODES:
                return False, True, f"只买想买单中的代码"
            score_index = None  # cls.__l2PlaceOrderParamsManagerDict[code].score_index
            score = None  # cls.__l2PlaceOrderParamsManagerDict[code].score
@@ -1169,82 +1073,48 @@
                                        buy_nums, buy_count, max_num_set_new,
                                        cls.volume_rate_info[code][0])
            l2_log.debug(code, "__save_order_begin_data")
            cls.__LimitUpTimeManager.save_limit_up_time(code,total_datas[compute_index]["val"]["time"])
            cls.__LimitUpTimeManager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"])
            l2_log.debug(code, "save_limit_up_time")
            cls.__virtual_buy(code, buy_single_index, compute_index, capture_time)
            l2_log.debug(code, "__virtual_buy")
            cls.__TradePointManager.delete_buy_cancel_point(code)
            l2_log.debug(code, "delete_buy_cancel_point")
            # 暂时不需要
            # f5 = dask.delayed(L2LimitUpMoneyStatisticUtil.process_data)(code, buy_single_index,
            #                                                             compute_index,
            #                                                             buy_single_index,
            #                                                             buy_exec_index, False)
            # 已被并行处理
            # # 记录买入信号位置
            # cls.__save_order_begin_data(code, buy_single_index, compute_index, compute_index, buy_nums, buy_count,
            #                             max_num_set_new)
            # # 如果是今天第一次有下单执行信号,涨停时间(买入执行位时间)
            # limit_up_time_manager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"])
            # # 虚拟下单
            # cls.__virtual_buy(code, buy_single_index, compute_index, capture_time)
            # # 删除之前的所有撤单信号
            # l2_data_manager.TradePointManager.delete_buy_cancel_point(code)
            #
            # # 涨停封单额计算
            # L2LimitUpMoneyStatisticUtil.process_data(cls.random_key[code], code, buy_single_index, compute_index,
            #                                          buy_single_index,
            #                                          buy_exec_index, False)
            # l2_log.debug(code, "记录执行买入数据结束")
            # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
            #                                   "记录执行买入数据", force=True)
            # 直接下单
            cls.__buy(code, capture_time, total_datas[compute_index], compute_index, is_first_code)
            # 数据是否处理完毕
            if compute_index >= compute_end_index:
                need_cancel, cancel_data = cls.__SecondCancelBigNumComputer.need_cancel(code, buy_single_index,
                                                                                        compute_index,
                                                                                        buy_single_index, compute_index,
                                                                                        total_datas, is_first_code,
                                                                                        cls.volume_rate_info[code][1],
                                                                                        cls.volume_rate_info[code][1],
                                                                                        True)
                # need_cancel, cancel_data = cls.__SecondCancelBigNumComputer.need_cancel(code, buy_single_index,
                #                                                                         compute_index,
                #                                                                         buy_single_index, compute_index,
                #                                                                         total_datas, is_first_code,
                #                                                                         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)
                l2_log.debug(code, "数据处理完毕,下单, 数据截图时间-{}", capture_time)
                # l2_log.debug(code, "数据处理完毕,下单, 数据截图时间-{}", capture_time)
                # 数据已经处理完毕,如果还没撤单就实际下单
                if need_cancel:
                    if cls.cancel_buy(code, "S级大单撤销"):
                        # 执行撤单成功
                        pass
                else:
                    cls.__buy(code, capture_time, total_datas[compute_index], compute_index, is_first_code)
                # if need_cancel:
                #     if cls.cancel_buy(code, "S级大单撤销"):
                #         # 执行撤单成功
                #         pass
                # else:
                # cls.__buy(code, capture_time, total_datas[compute_index], compute_index, is_first_code)
                pass
            else:
                cls.__SecondCancelBigNumComputer.need_cancel(code, buy_single_index, compute_index, buy_single_index,
                                                             compute_index, total_datas, is_first_code,
                                                             cls.volume_rate_info[code][1],
                                                             cls.volume_rate_info[code][1], False)
                l2_log.debug(code, "S级大单处理")
                # cls.__SecondCancelBigNumComputer.need_cancel(code, buy_single_index, compute_index, buy_single_index,
                #                                              compute_index, total_datas, is_first_code,
                #                                              cls.volume_rate_info[code][1],
                #                                              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)
                # 数据尚未处理完毕,进行下一步处理
                l2_log.debug(code, "数据尚未处理完毕,进行下一步处理,处理进度:{} end_index:{}", compute_index, compute_end_index)
                # l2_log.debug(code, "数据尚未处理完毕,进行下一步处理,处理进度:{} end_index:{}", compute_index, compute_end_index)
                # 处理撤单步骤
                cls.__process_order(code, compute_index + 1, compute_end_index, capture_time, is_first_code, False)
                # lp = LineProfiler()
                # lp.enable()
                # lp_wrap = lp(cls.__process_order)
                # lp_wrap(code, compute_index + 1, compute_end_index, capture_time, is_first_code, False)
                # output = io.StringIO()
                # lp.print_stats(stream=output)
                # 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)
        else:
            # 未达到下单条件,保存纯买额,设置纯买额
            # 记录买入信号位置
@@ -1345,7 +1215,7 @@
        _start_time = t.time()
        total_datas = local_today_datas[code]
        is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code)
        # is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code)
        buy_nums = origin_num
        buy_count = origin_count
@@ -1382,7 +1252,7 @@
            trigger_buy = False
            # 必须为连续2秒内的数据
            if L2DataUtil.get_time_as_second(_val["time"]) - buy_single_time_seconds + 1 > max_space_time:
                TradePointManager().delete_buy_point(code)
                cls.__TradePointManager.delete_buy_point(code)
                if i == compute_end_index:
                    # 数据处理完毕
                    return None, buy_nums, buy_count, None, max_buy_num_set
test/test.py
@@ -5,21 +5,23 @@
from log_module.log import logger_l2_process_time, logger_debug
_dict = {}
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 __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
        i=1
        _dict["test"]=i+2
_dict = {}
def test_time(instance, i):
trade/current_price_process_manager.py
@@ -23,7 +23,7 @@
def accept_prices(prices):
    # 获取首板代码
    first_codes = gpcode_manager.FirstGPCodesManager().get_first_gp_codes()
    first_codes = gpcode_manager.FirstGPCodesManager().get_first_gp_codes_cache()
    print("总价格代码数量:", len(prices))