Administrator
2023-10-17 05a02dbd657804f2e1e392f36a57e1cf5c6c3b2f
修复09:30:00之前开盘啦精选板块可能没有加载的bug
6个文件已修改
83 ■■■■■ 已修改文件
l2/l2_transaction_data_manager.py 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_api.py 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api_server.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_data_update.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_server.py 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_manager.py
@@ -80,16 +80,17 @@
                async_log_util.info(logger_l2_trade_buy_queue, "获取成交位置成功: code-{} index-{}", code,
                                    buy_progress_index)
                limit_up_price = gpcode_manager.get_limit_up_price(code)
                if buy_exec_index and buy_exec_index > -1:
                    m_base_val = L2PlaceOrderParamsManager.get_base_m_val(code)
                    need_cancel, msg = DCancelBigNumComputer().set_trade_progress(code,
                                                                                  buy_progress_index,
                                                                                  buy_exec_index,
                                                                                  total_datas,
                                                                                  m_base_val,
                                                                                  limit_up_price)
                    if need_cancel:
                        L2TradeDataProcessor.cancel_buy(code, f"D撤:{msg}", source="d_cancel")
                # 注释掉D撤单
                # if buy_exec_index and buy_exec_index > -1:
                #     m_base_val = L2PlaceOrderParamsManager.get_base_m_val(code)
                #     need_cancel, msg = DCancelBigNumComputer().set_trade_progress(code,
                #                                                                   buy_progress_index,
                #                                                                   buy_exec_index,
                #                                                                   total_datas,
                #                                                                   m_base_val,
                #                                                                   limit_up_price)
                #     if need_cancel:
                #         L2TradeDataProcessor.cancel_buy(code, f"D撤:{msg}", source="d_cancel")
                LCancelBigNumComputer().set_trade_progress(code, buy_progress_index, total_datas)
                SecondCancelBigNumComputer().set_transaction_index(
third_data/code_plate_key_manager.py
@@ -7,12 +7,12 @@
import constant
from db.redis_manager_delegate import RedisUtils
from third_data import kpl_block_util
from third_data import kpl_block_util, kpl_api
from utils import global_util, tool
from log_module import log
from log_module import log, async_log_util
from db import redis_manager_delegate as redis_manager
from log_module.log import logger_kpl_limit_up, logger_kpl_block_can_buy, logger_kpl_debug
from log_module.log import logger_kpl_limit_up, logger_kpl_block_can_buy
from third_data.kpl_util import KPLPlatManager
from trade import trade_manager, l2_trade_util
@@ -77,6 +77,26 @@
            return self.__code_by_blocks.get(code)
        else:
            return self.__code_blocks.get(code)
    # 从网络上加载精选板块
    def load_jx_blocks(self, code, buy_1_price, limit_up_price):
        if limit_up_price and buy_1_price:
            # 处理买1,卖1信息
            pre_close_price = round(float(limit_up_price) / 1.1, 2)
            # 如果涨幅大于7%就读取板块
            price_rate = (buy_1_price - pre_close_price) / pre_close_price
            if price_rate > 0.07:
                if not self.get_jx_blocks_cache(code):
                    blocks = kpl_api.getCodeJingXuanBlocks(code)
                    self.save_jx_blocks(code, blocks)
                    async_log_util.info(logger_kpl_block_can_buy,f"{code}:获取到精选板块-{blocks}")
            elif price_rate > 0.03:
                # 添加备用板块
                if not self.get_jx_blocks_cache(code, by=True):
                    blocks = kpl_api.getCodeJingXuanBlocks(code)
                    self.save_jx_blocks(code, blocks, by=True)
                    async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(备用)-{blocks}")
# 开盘啦禁止交易板块管理
@@ -291,11 +311,9 @@
    @classmethod
    def is_in_top(cls, keys):
        reasons = cls.get_can_buy_key_set()
        log.logger_kpl_debug.debug("市场流入前5:{}", reasons)
        forbidden_plates = cls.__KPLPlateForbiddenManager.list_all_cache()
        reasons = reasons - forbidden_plates
        temp_set = keys & reasons
        log.logger_kpl_debug.debug("市场流入前5匹配结果:{}", temp_set)
        if temp_set:
            return True, temp_set
        else:
@@ -317,7 +335,6 @@
        self.__history_limit_up_reason_dict[code] = set(reasons)
        RedisUtils.setex(self.__get_redis(), f"kpl_his_limit_up_reason-{code}", tool.get_expire(),
                         json.dumps(list(reasons)))
        logger_kpl_debug.debug(f"设置历史涨停原因:{code}-{reasons}")
    # 如果返回值不为None表示已经加载过历史原因了
    def get_history_limit_up_reason(self, code):
@@ -519,7 +536,7 @@
                keys |= k4
                keys = keys - constant.KPL_INVALID_BLOCKS
        log.logger_kpl_debug.info("{}最终关键词:{}", code, keys)
        # log.logger_kpl_debug.info("{}最终关键词:{}", code, keys)
        # 涨停列表中匹配关键词,返回(板块:代码集合),代码集合中已经排除自身
        if not keys:
third_data/kpl_api.py
@@ -118,7 +118,8 @@
    data = f"a=GetStockIDPlate&apiv=w32&Type=2&c=StockL2Data&StockID={code}&PhoneOSNew=1&UserID=0&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&VerSion=5.8.0.2&Token=0&"
    result = __base_request("https://apphq.longhuvip.com/w1/api/index.php", data=data)
    result = json.loads(result)
    return result.get("ListJX")
    print(result)
    return result.get("ListJX") if result.get("ListJX") else result.get("List")
# 获取自由流通市值
@@ -132,7 +133,4 @@
if __name__ == "__main__":
    datas = json.loads(getLimitUpInfo())
    for d in datas["list"]:
        print(d[0], d[1])
    print(len(datas["list"]))
    getCodeJingXuanBlocks("002316")
trade/huaxin/huaxin_trade_api_server.py
@@ -16,6 +16,7 @@
from l2.huaxin import huaxin_target_codes_manager
from log_module.log import logger_system, logger_l2_codes_subscript
from third_data import block_info
from third_data.code_plate_key_manager import KPLCodeJXBlockManager
from third_data.history_k_data_util import HistoryKDatasUtils, JueJinApi
from third_data.kpl_data_manager import KPLDataManager
from third_data.kpl_util import KPLDataType
@@ -449,6 +450,10 @@
                    root_data = socket_util.encryp_client_params_sign(root_data)
                    pipe_l2.send(json.dumps(root_data))
                    print("设置L2代码结束")
                    # 如果在9:24-9:30 需要加载板块
                    if int("092400") < int(tool.get_now_time_str().replace(":", "")) < int("093000"):
                        for d in datas:
                            KPLCodeJXBlockManager().load_jx_blocks(d[0], gpcode_manager.get_price(d[0]), float(d[2]))
                    logger_l2_codes_subscript.info("({})发送到华鑫L2代码处理队列:数量-{}", request_id, len(datas))
        except Exception as e:
            logging.exception(e)
trade/huaxin/huaxin_trade_data_update.py
@@ -29,7 +29,7 @@
                delay = data.get("delay")
                if delay and delay > 0:
                    time.sleep(delay)
                hx_logger_trade_debug.info(f"获取交易数据开始:{type_}")
                async_log_util.info(hx_logger_trade_debug, f"获取交易数据开始:{type_}")
                try:
                    if type_ == "delegate_list":
                        dataJSON = huaxin_trade_api.get_delegate_list(can_cancel=False, timeout=10)
@@ -104,7 +104,7 @@
                        if dataJSON["code"] == 0:
                            data = dataJSON["data"]
                            huaxin_trade_record_manager.PositionManager.add(data)
                    hx_logger_trade_debug.info(f"获取交易数据成功:{type_}")
                    async_log_util.info(hx_logger_trade_debug, f"获取交易数据成功:{type_}")
                except Exception as e1:
                    # if str(e1).find("超时") >= 0:
                    #     # 读取结果超时需要重新请求
trade/huaxin/huaxin_trade_server.py
@@ -325,19 +325,7 @@
            code_price_manager.Buy1PriceManager().process(code, buy_1_price, time_str,
                                                          limit_up_price,
                                                          sell_1_price, sell_1_volume // 100)
            pre_close_price = round(float(limit_up_price) / 1.1, 2)
            # 如果涨幅大于7%就读取板块
            price_rate = (buy_1_price - pre_close_price) / pre_close_price
            if price_rate > 0.07:
                if not cls.__KPLCodeJXBlockManager.get_jx_blocks_cache(code):
                    blocks = kpl_api.getCodeJingXuanBlocks(code)
                    cls.__KPLCodeJXBlockManager.save_jx_blocks(code, blocks)
            elif price_rate > 0.03:
                # 添加备用板块
                if not cls.__KPLCodeJXBlockManager.get_jx_blocks_cache(code, by=True):
                    blocks = kpl_api.getCodeJingXuanBlocks(code)
                    cls.__KPLCodeJXBlockManager.save_jx_blocks(code, blocks, by=True)
            cls.__KPLCodeJXBlockManager.load_jx_blocks(code,buy_1_price,limit_up_price)
            # 更新板块信息
            yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes()
            CodePlateKeyBuyManager.update_can_buy_blocks(code,