Administrator
2023-11-23 3f8499a0b83304132facd8758acc1a99a1008c69
bug修复
13个文件已修改
86 ■■■■ 已修改文件
code_attribute/code_volumn_manager.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/first_target_code_data_processor.py 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inited_data.py 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/l2_huaxin_util.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_sell_manager.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/l2_trade_test.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/data_server.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_server.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/sell_rule_manager.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_data_manager.py 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_result_manager.py 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/data_export_util.py 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/code_volumn_manager.py
@@ -85,12 +85,13 @@
# 获取量比(今日量/max(60天最大量,昨日量))
def get_volume_rate(code, with_info=False):
# 将总卖量计算在内
def get_volume_rate(code, total_sell_volume=0, with_info=False):
    today = get_today_volumn(code)
    max60, yesterday = get_histry_volumn(code)
    if today is None or max60 is None or yesterday is None:
        raise Exception("获取量失败")
    rate = round(int(today) / max(int(max60[0]), int(yesterday)), 2)
    rate = round((int(today) + total_sell_volume) / max(int(max60[0]), int(yesterday)), 2)
    if not with_info:
        return rate
    return rate, (today, max(int(max60[0]), int(yesterday)))
code_attribute/first_target_code_data_processor.py
@@ -218,12 +218,6 @@
        prices.append(
            {"code": code, "time": limit_up_time, "rate": rate,
             "limit_up": is_limit_up})
        if code in new_add_codes:
            if is_limit_up:
                place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(
                    code)
                if place_order_count == 0:
                    trade_data_manager.PlaceOrderCountManager().place_order(code)
    gpcode_first_screen_manager.process_ticks(prices)
    logger_l2_codes_subscript.info(f"({request_id})l2代码相关数据加载完成")
inited_data.py
@@ -30,7 +30,7 @@
from trade import l2_trade_util, trade_manager
from l2.cancel_buy_strategy import L2LimitUpSellStatisticUtil, LCancelBigNumComputer, DCancelBigNumComputer
from log_module.log import logger_juejin_tick, logger_system
from trade.trade_data_manager import CodeActualPriceProcessor
from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager
from trade.trade_queue_manager import JueJinBuy1VolumnManager
redisManager = redis_manager.RedisManager(0)
@@ -108,6 +108,8 @@
        HighIncreaseCodeManager().clear()
        # 股性清除
        CodeNatureRecordManager().clear()
        # 下单次数清除
        PlaceOrderCountManager().clear()
# 每日初始化
l2/huaxin/l2_huaxin_util.py
@@ -10,6 +10,7 @@
def convert_time(time_str, with_ms=False):
    time_str = str(time_str)
    if time_str.startswith("9"):
        time_str = f"0{time_str}"
    ms = "{:0<3}".format(time_str[6:])
l2/l2_data_manager_new.py
@@ -29,7 +29,7 @@
import l2.l2_data_util
from log_module.log import logger_l2_trade_buy, logger_l2_process, logger_l2_error, logger_debug
from trade.trade_data_manager import CodeActualPriceProcessor
from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager
from trade.trade_manager import TradeTargetCodeModeManager, AccountAvailableMoneyManager
@@ -236,6 +236,7 @@
    __LatestCancelIndexManager = LatestCancelIndexManager()
    __L2MarketSellManager = L2MarketSellManager()
    __L2LimitUpSellManager = L2LimitUpSellManager()
    __PlaceOrderCountManager = PlaceOrderCountManager()
    # 获取代码评分
    @classmethod
@@ -382,7 +383,11 @@
            # 是否为首板代码
            is_first_code = True  # gpcode_manager.FirstCodeManager().is_in_first_record(code)
            # 计算量
            volume_rate = code_volumn_manager.get_volume_rate(code)
            current_sell = cls.__L2MarketSellManager.get_current_total_sell_data(code)
            total_sell_volume = 0
            if current_sell and len(current_sell) > 2:
                total_sell_volume = current_sell[2]
            volume_rate = code_volumn_manager.get_volume_rate(code, total_sell_volume=total_sell_volume)
            volume_rate_index = code_volumn_manager.get_volume_rate_index(volume_rate)
            # 计算分值
            limit_up_time = cls.__LimitUpTimeManager.get_limit_up_time_cache(code)
@@ -831,14 +836,33 @@
            HighIncreaseCodeManager().add_code(code)
            return False, True, f"股价大于{constant.MAX_CODE_PRICE}块"
        place_order_count = cls.__PlaceOrderCountManager.get_place_order_count(code)
        if place_order_count and place_order_count >= 10:
            l2_trade_util.forbidden_trade(code, msg="当日下单次数已达10次")
            return False, True, f"当日下单次数已达10次"
        # -------量的约束--------
        if cls.volume_rate_info[code][0] < 0.2:
            return False, True, f"当日量比({cls.volume_rate_info[code][0]})小于0.2"
        k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code)
        if k_format and (k_format[1][0] or k_format[3][0]):
            # 股价创新高或者逼近前高
            if cls.volume_rate_info[code][0] < 0.3:
                return False, True, f"股价创新高或者逼近前高,当日量比({cls.volume_rate_info[code][0]})小于0.3"
        if code_nature_analyse.LatestMaxVolumeManager().is_latest_max_volume(code):
            # 最近几天有最大量,判断量比是否大于60%
            if cls.volume_rate_info[code][0] < 0.6:
                HighIncreaseCodeManager().add_code(code)
                return False, True, f"近日出现最大量,当日量比({cls.volume_rate_info[code][0]})小于0.6"
        # ------自由流通市值约束------
        zyltgb = global_util.zyltgb_map.get(code)
        if zyltgb:
            if zyltgb < 10 * 100000000:
                return False, True, f"自由流通小于10亿({zyltgb})"
        total_data = local_today_datas.get(code)
        if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN:
            total_data = local_today_datas.get(code)
            trade_price = current_price_process_manager.get_trade_price(code)
            if trade_price is None:
                return False, True, f"尚未获取到当前成交价"
@@ -907,7 +931,7 @@
            return False, True, f"炸板后最低价跌至5%以下"
        # 回封的票,下13:15买入需要判断板块是否为独苗
        if open_limit_up_lowest_price and int(tool.get_now_time_str().replace(":", "")) > 131500:
        if open_limit_up_lowest_price and int(total_data[-1]["val"]["time"].replace(":", "")) > 131500:
            # 获取当前票的涨停原因
            if code in LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict:
                limit_up_reason = kpl_data_manager.KPLLimitUpDataRecordManager.get_current_block(code)
l2/l2_sell_manager.py
@@ -66,12 +66,12 @@
            RedisUtils.delete_async(self.__db, k)
    # 设置当前的总卖
    def set_current_total_sell_data(self, code, time_str, money):
    def set_current_total_sell_data(self, code, time_str, money, volume):
        # 记录日志
        async_log_util.info(logger_l2_market_sell, f"{code}: {time_str}-{money}")
        if code in self.__current_total_sell_data_cache:
            self.__last_total_sell_data_cache[code] = self.__current_total_sell_data_cache.get(code)
        self.__current_total_sell_data_cache[code] = (time_str, round(money))
        self.__current_total_sell_data_cache[code] = (time_str, round(money), volume)
    def get_current_total_sell_data(self, code):
        return self.__current_total_sell_data_cache.get(code)
test/l2_trade_test.py
@@ -89,7 +89,7 @@
    def test_trade(self):
        trade_manager.TradeStateManager().open_buy()
        threading.Thread(target=async_log_util.run_sync, daemon=True).start()
        code = "002528"
        code = "002848"
        clear_trade_data(code)
        l2.l2_data_util.load_l2_data(code)
        total_datas = deepcopy(l2.l2_data_util.local_today_datas[code])
@@ -185,7 +185,7 @@
                    time_str = time_str[:6]
                    time_str = f"{time_str[0:2]}:{time_str[2:4]}:{time_str[4:6]}"
                    L2MarketSellManager().set_current_total_sell_data(code, time_str,
                                                                      l2_m["totalAskVolume"] * l2_m["avgAskPrice"])
                                                                      l2_m["totalAskVolume"] * l2_m["avgAskPrice"], l2_m["totalAskVolume"])
                    break
            for tp in trade_progress_list:
@@ -229,6 +229,7 @@
                                                     yesterday_codes,
                                                     block_info.get_before_blocks_dict())
    @unittest.skip("跳过此单元测试")
    def test_transaction(self):
        threading.Thread(target=async_log_util.run_sync, daemon=True).start()
        code = "003019"
third_data/data_server.py
@@ -84,7 +84,8 @@
            (k, len(limit_up_reason_dict[k]), limit_up_reason_want_count_dict.get(k), limit_up_reason_dict[k][0][5]) for
            k in
            limit_up_reason_dict]
        limit_up_reason_statistic_info.sort(key=lambda x: int(x[3]))
        limit_up_reason_statistic_info.sort(key=lambda x: int(x[1]))
        limit_up_reason_statistic_info.reverse()
        codes_set = set([d[3] for d in total_datas])
        # 判断是龙几,判断是否涨停,判断是否炸板,加载分数
trade/huaxin/huaxin_trade_server.py
@@ -384,7 +384,7 @@
        async_log_util.info(hx_logger_l2_market_data, f"{code}#{data}")
        L2MarketSellManager().set_current_total_sell_data(code, time_str,
                                                          data["totalAskVolume"] * data["avgAskPrice"])
                                                          data["totalAskVolume"] * data["avgAskPrice"], data["totalAskVolume"])
    @classmethod
    def trading_order_canceled(cls, code, order_no):
trade/sell_rule_manager.py
@@ -45,7 +45,7 @@
        return cls.__instance
    def __load_datas(self):
        rules = self.__list_rules()
        rules = self.list_rules()
        self.__sell_rules_dict_cache.clear()
        for rule in rules:
            self.__sell_rules_dict_cache[rule.id_] = rule
trade/trade_data_manager.py
@@ -478,6 +478,12 @@
        key = "place_order_count-{}".format(code)
        RedisUtils.delete_async(self.__db, key)
    def clear(self):
        self.__place_order_count_cache.clear()
        keys = RedisUtils.keys(self.__get_redis(), "place_order_count-*")
        for k in keys:
            RedisUtils.delete(self.__get_redis(), k)
if __name__ == "__main__":
    processor = CodeActualPriceProcessor()
trade/trade_result_manager.py
@@ -8,6 +8,7 @@
from l2.l2_data_util import local_today_datas, local_today_num_operate_map
from l2.l2_sell_manager import L2MarketSellManager
from log_module.log import logger_l2_error
from trade.trade_data_manager import PlaceOrderCountManager
from trade.trade_queue_manager import THSBuy1VolumnManager
__thsBuy1VolumnManager = THSBuy1VolumnManager()
@@ -79,6 +80,8 @@
        # 记录卖盘统计时间被用
        L2MarketSellManager().set_sell_time_used(code, order_begin_pos.sell_info[0])
        FastCancelBigNumComputer().set_trade_progress(code, order_begin_pos.buy_exec_index)
    # 下单成功
    PlaceOrderCountManager().place_order(code)
# 真实撤成功
utils/data_export_util.py
@@ -26,7 +26,11 @@
    process_indexs = log_export.get_l2_process_position(code, date)
    trade_indexs = log_export.get_l2_trade_position(code, date)
    real_position_indexes = log_export.get_real_place_order_positions(code, date)
    fdatas = export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes)
    deal_list = log_export.load_huaxin_deal_record(code)
    deal_list_dict = {}
    for d in deal_list:
        deal_list_dict[d[0]] = d
    fdatas = export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes, deal_list_dict)
    __save_l2_datas(code, fdatas)
@@ -156,12 +160,13 @@
            # 买
            if cancel_data:
                try:
                    cancel_info = "{}-{}".format(cancel_data["index"], f"{cancel_data['val']['time']}.{cancel_data['val']['tms']}")
                    cancel_info = "{}-{}".format(cancel_data["index"],f"{cancel_data['val']['time']}") + (f".{cancel_data['val']['tms']}" if "tms" in cancel_data["val"] else '')
                except Exception as e:
                    logging.exception(e)
            else:
                if int(data["val"].get("orderNo")) in deal_list_dict:
                    cancel_info = l2_huaxin_util.convert_time(deal_list_dict[int(data["val"].get("orderNo"))][3])
                    cancel_info = l2_huaxin_util.convert_time(deal_list_dict[int(data["val"].get("orderNo"))][3],
                                                              with_ms=True)
        format_data.append(cancel_info)
        cancel_order_info = None
        if trade_info:
@@ -280,6 +285,6 @@
if __name__ == "__main__":
    try:
        export_l2_excel("605218")
        export_l2_excel("000536")
    except Exception as e:
        logging.exception(e)