Administrator
2024-11-20 967abfe26abe09c26df61fe48bab1d64e2253cef
添加新接口
9个文件已修改
167 ■■■■ 已修改文件
constant.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
log_module/log_export.py 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/data_server.py 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/huaxin_trade_server.py 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/block_special_codes_manager.py 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_record_log_util.py 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constant.py
@@ -184,7 +184,7 @@
########华鑫配置########
if not is_windows() or True:
    # 下单1手
    BUY_MONEY_PER_CODE = 500 if constant.IS_A else 20000
    BUY_MONEY_PER_CODE = 500 if constant.IS_A else 5000
    L2_SOURCE_TYPE = L2_SOURCE_TYPE_HUAXIN
    JUEJIN_LOCAL_API = False
    TRADE_WAY = TRADE_WAY_HUAXIN
l2/l2_data_manager_new.py
@@ -466,7 +466,7 @@
                                                                                add_datas[0], buy_info[2],
                                                                                shadow_price=shadow_price,
                                                                                shadow_volume=buy_info[1])
                                    cls.__place_order_success(code, order_begin_pos_info)
                                    cls.__place_order_success(code, order_begin_pos_info, None)
                                except Exception as e:
                                    logger_l2_error.exception(e)
                                finally:
@@ -778,8 +778,17 @@
        return True, False, f"", False
    @classmethod
    def start_buy(cls, code, last_data, last_data_index, is_first_code):
        return cls.__buy(code, 0, last_data, last_data_index, is_first_code)
    def start_buy(cls, code, last_data, last_data_index, is_first_code, block_info):
        """
        开始买入
        @param code:
        @param last_data:
        @param last_data_index:
        @param is_first_code:
        @param block_info:板块信息:[(板块,流入信息)]
        @return:
        """
        return cls.__buy(code, 0, last_data, last_data_index, is_first_code, block_info=block_info)
    @classmethod
    def get_active_buy_blocks(cls, code):
@@ -812,7 +821,7 @@
        return None
    @classmethod
    def __place_order_success(cls, code, order_begin_pos):
    def __place_order_success(cls, code, order_begin_pos, block_info):
        ################下单成功处理################
        trade_result_manager.real_buy_success(code, cls.__TradePointManager)
        l2_log.debug(code, "处理买入成功1")
@@ -835,6 +844,7 @@
            info.mode_desc = order_begin_pos.mode_desc
            info.set_buy_index(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
            info.set_sell_info(order_begin_pos.sell_info)
            info.set_block_info(block_info)
            if jx_blocks:
                info.set_kpl_blocks(list(jx_blocks))
            elif jx_blocks_by:
@@ -858,7 +868,7 @@
            async_log_util.error(logger_l2_error, f"加入买入记录日志出错:{str(e)}")
    @classmethod
    def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code):
    def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code, block_info=None):
        pre_result = cls.__is_pre_can_buy(code)
        if not pre_result[0]:
            return False
@@ -909,7 +919,7 @@
                                            last_data_index, order_begin_pos.mode, order_begin_pos.buy_exec_index)
                    l2_log.debug(code, "执行买入成功")
                    cls.__place_order_success(code, order_begin_pos)
                    cls.__place_order_success(code, order_begin_pos, block_info)
                except Exception as e:
                    async_log_util.exception(logger_l2_error, e)
@@ -1512,7 +1522,7 @@
        trade_result_manager.virtual_buy_success(code)
    @classmethod
    def __process_with_find_exec_index(cls, code, order_begin_pos: OrderBeginPosInfo, compute_end_index):
    def __process_with_find_exec_index(cls, code, order_begin_pos: OrderBeginPosInfo, compute_end_index, block_info):
        """
        处理找到执行位置
        @return:
@@ -1535,7 +1545,7 @@
            cls.__latest_exec_indexes[code] = cls.__latest_exec_indexes[code][-3:]
        # 直接下单
        ordered = cls.__buy(code, 0, total_datas[-1], total_datas[-1]["index"], True)
        ordered = cls.__buy(code, 0, total_datas[-1], total_datas[-1]["index"], True, block_info=block_info)
        # 数据是否处理完毕
        if order_begin_pos.buy_exec_index < compute_end_index:
@@ -1601,11 +1611,12 @@
                                                     max_num_set=set(),
                                                     buy_volume_rate=buy_volume_rate,
                                                     mode=OrderBeginPosInfo.MODE_RADICAL,
                                                     mode_desc=f"总抛压小扫入:{radical_result[2]}",
                                                     mode_desc=f"大单不足扫入:{radical_result[2]}",
                                                     sell_info=sell_info,
                                                     threshold_money=threshold_money)
            order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code)
            ordered = cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index)
            ordered = cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index,
                                                         block_info=radical_result[3])
            if ordered:
                radical_buy_data_manager.BlockPlaceOrderRecordManager().add_record(code, radical_result[2])
            return
@@ -1718,7 +1729,7 @@
                                                                       mode_desc=order_begin_pos.mode_desc,
                                                                       sell_info=order_begin_pos.sell_info,
                                                                       threshold_money=threshold_money),
                                               compute_end_index)
                                               compute_end_index, block_info=None)
        else:
            # 未达到下单条件,保存纯买额,设置纯买额
            # 记录买入信号位置
@@ -2022,7 +2033,7 @@
        @param code:
        @param start_index:
        @param end_index:
        @return: (是否获取到信号, 信号位置, 扫入板块/消息)
        @return: (是否获取到信号, 信号位置, 扫入板块/消息, 扫入板块大单流入信息)
        """
        # 激进买信号的时间
@@ -2053,7 +2064,7 @@
                THRESHOLD_MONEY = 2990000 * 2
            else:
                THRESHOLD_MONEY = 2990000
            if  total_deal_money >= THRESHOLD_MONEY:
            if total_deal_money >= THRESHOLD_MONEY:
                min_num = int(5000 / limit_up_price)
            # 总委托大单金额
@@ -2132,7 +2143,7 @@
            # 如果板上放量不可买入就需要删除信号
            if not constant.CAN_RADICAL_BUY_AT_LIMIT_UP and code in RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict:
                RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.pop(code)
            return True, result[1], radical_data[2]
            return True, result[1], radical_data[2], radical_data[3]
        return result
    @classmethod
log_module/log_export.py
@@ -389,6 +389,26 @@
    return fdatas
# 加载买入得分记录
def load_trade_recod_by_type(type_, date=tool.get_now_date_str()):
    path = f"{constant.get_path_prefix()}/logs/gp/trade/trade_record.{date}.log"
    fdatas = []
    lines = __load_file_content(path)
    for line in lines:
        data_index = line.find(f"{type_}")
        if data_index > 0:
            line = line.split(" - ")[1]
            time_str = line[line.find("[") + 1:line.find("[") + 9]
            data = line[line.find("]") + 1:].strip()
            data_json = json.loads(data)
            type = data_json["type"]
            code = data_json["code"]
            if type != type_:
                continue
            fdatas.append((time_str,code, type, data_json["data"]))
    return fdatas
def load_cancel_buy_reasons(code, date=tool.get_now_date_str()):
    """
    获取撤单原因
servers/data_server.py
@@ -536,7 +536,8 @@
                # 代码,名称,涨停时间,是否炸板,是否想买,是否已经下过单,涨停时间,自由流通市值,是否在黑名单里面, 是否有辨识度, 大单净额
                codes_info.append(
                    [d[3], d[4], tool.to_time_str(int(d[5])), 1 if d[3] not in now_limit_up_codes else 0, 0, 0, d[12],
                     output_util.money_desc(d[13]), 1, 1 if l2_trade_util.is_in_forbidden_trade_codes(d[3]) else 0, 1 if d[3] in special_codes else 0, CodeInMoneyManager().get_money(d[3])])
                     output_util.money_desc(d[13]), 1, 1 if l2_trade_util.is_in_forbidden_trade_codes(d[3]) else 0,
                     1 if d[3] in special_codes else 0, CodeInMoneyManager().get_money(d[3])])
            codes_info.sort(key=lambda x: x[2])
            # 查询是否为想买单
            green_codes = gpcode_manager.GreenListCodeManager().list_codes_cache()
@@ -767,6 +768,42 @@
                response_data = json.dumps({"code": 0, "data": fdata})
            except Exception as e:
                logger_debug.exception(e)
        elif url.path == "/get_place_order_records":
            # 获取下单记录
            ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()])
            try:
                day = ps_dict.get("day")
                if not day:
                    day = tool.get_now_date_str()
                records = log_export.load_trade_recod_by_type("place_order", date=day)
                fdata = []
                for record in records:
                    print(record)
                    # (下单时间, 代码, 名称, 下单模式, 板块信息)
                    fdata.append((record[0], record[1], gpcode_manager.get_code_name(record[1]), record[3]["mode_desc"],
                                  record[3].get("block_info")))
                response_data = json.dumps({"code": 0, "data": fdata})
            except:
                pass
        elif url.path == "/get_blocks_in_money_info":
            # 获取板块资金流入状况
            ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()])
            type_ = ps_dict.get("type")
            try:
                fdatas = []
                if type_ == 0:
                    fdatas = RealTimeKplMarketData.top_in_list_cache
                    if not fdatas:
                        datas = self.__kplDataManager.get_data(KPLDataType.JINGXUAN_RANK.value)
                        fdatas = datas
                elif type_ == 1:
                    fdatas = RealTimeKplMarketData.top_out_list_cache
                    if not fdatas:
                        datas = self.__kplDataManager.get_data(KPLDataType.JINGXUAN_RANK_OUT.value)
                        fdatas = datas
                response_data = json.dumps({"code": 0, "data": fdatas})
            except:
                pass
        async_log_util.info(logger_request_api, f"结束请求{tool.get_thread_id()}-{url}")
        self.send_response(200)
@@ -793,7 +830,7 @@
                    CodeInMoneyManager().set_money(code, d[code])
            except Exception as e:
                logging.exception(e)
            result_str =json.dumps({"code": 0})
            result_str = json.dumps({"code": 0})
            self.__send_response(result_str)
    def __process_kpl_data(self, data_origin):
servers/huaxin_trade_server.py
@@ -763,7 +763,7 @@
                                 order_begin_pos.buy_exec_index,
                                 _type, big_buy_order_count)
                    l2_data_manager_new.L2TradeDataProcessor.start_buy(code, total_datas[-1], total_datas[-1]["index"],
                                                                       True)
                                                                       True, None)
                else:
                    l2_log.debug(code, "积极下单,不满足扫入下单条件,无法扫入")
            else:
@@ -798,7 +798,7 @@
                                     _type)
                        l2_data_manager_new.L2TradeDataProcessor.start_buy(code, total_datas[-1],
                                                                           total_datas[-1]["index"],
                                                                           True)
                                                                           True, None)
                        break
        except Exception as e:
            logger_debug.exception(e)
@@ -872,6 +872,8 @@
                    # -----根据成交比例判断是否可买------
                    result_by_volume = radical_buy_strategy.process_limit_up_active_buy_deal(code, transaction_datas)
                    async_log_util.info(logger_l2_radical_buy, f"量买入结果判断:{code}, 结果:{result_by_volume} 板块:{buy_blocks}")
                    in_blocks = RealTimeKplMarketData.get_top_market_jingxuan_blocks()
                    buy_blocks_with_money = [(b, RealTimeKplMarketData.get_jx_block_in_money(b),in_blocks.index(b) if b in  in_blocks else -1) for b in buy_blocks]
                    if result_by_volume[0] != radical_buy_strategy.BUY_MODE_NONE:
                        if tool.get_now_time_as_int() < 93200:
                            radical_buy_data_manager.ExcludeIndexComputeCodesManager.add_code(code)
@@ -910,14 +912,15 @@
                                                                     threshold_money=threshold_money)
                            L2TradeDataProcessor.save_order_begin_data(code, order_begin_pos_info)
                            buy_result = L2TradeDataProcessor.start_buy(code, total_datas[-1], total_datas[-1]["index"],
                                                                        True)
                                                                        True, block_info=buy_blocks_with_money)
                            if buy_result:
                                # 下单成功
                                radical_buy_data_manager.BlockPlaceOrderRecordManager().add_record(code, buy_blocks)
                                radical_buy_strategy.clear_latest_deal_active_buy_order(code)
                        else:
                            RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict[code] = (
                                time.time() + 30, transaction_datas[-1][6], buy_blocks, l2_huaxin_util.convert_time(transaction_datas[-1][3]))
                                time.time() + 30, transaction_datas[-1][6], buy_blocks,
                                l2_huaxin_util.convert_time(transaction_datas[-1][3]), buy_blocks_with_money)
                    else:
                        async_log_util.info(logger_l2_radical_buy, f"不能下单:{code}-{result_by_volume}")
                else:
third_data/code_plate_key_manager.py
@@ -330,8 +330,10 @@
# 实时开盘啦市场数据
class RealTimeKplMarketData:
    # 精选前5
    top_5_reason_list = []
    # 流入缓存
    top_in_list_cache = []
    # 流出缓存
    top_out_list_cache = []
    # 行业前5
    top_5_industry_list = []
    #
@@ -342,9 +344,11 @@
    __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager()
    __KPLPlatManager = KPLPlatManager()
    # 精选流入前几
    __top_jx_blocks = set()
    __top_jx_blocks = []
    # 精选流出前几
    __top_jx_out_blocks = set()
    __top_jx_out_blocks = []
    # 精选板块流入金额
    __jx_blocks_in_money_dict = {}
    @classmethod
    def set_market_jingxuan_blocks(cls, datas):
@@ -360,9 +364,12 @@
        #         break
        #     blocks.add(data[1])
        # cls.__top_jx_blocks = blocks
        cls.top_in_list_cache = datas
        blocks = set()
        count = 0
        fblock_money = {}
        for data in datas:
            cls.__jx_blocks_in_money_dict[data[1]] = data[3]
            if data[1] in constant.KPL_INVALID_BLOCKS:
                continue
            if data[3] < 5e7:
@@ -371,12 +378,16 @@
            fb = BlockMapManager().filter_blocks({data[1]})
            if blocks & fb:
                continue
            for b in fb:
                fblock_money[b] = data[3]
            blocks |= fb
            count += 1
            if count >= 10:
                break
        # 记录精选流出日志
        async_log_util.info(logger_kpl_jx_in, f"原数据:{datas[:20]} 板块:{blocks}")
        blocks = list(blocks)
        blocks.sort(key=lambda x: fblock_money.get(x), reverse=True)
        cls.__top_jx_blocks = blocks
    @classmethod
@@ -386,9 +397,11 @@
        @param datas:
        @return:
        """
        cls.top_out_list_cache = datas
        count = 0
        blocks = set()
        for data in datas:
            cls.__jx_blocks_in_money_dict[data[1]] = data[3]
            if data[1] in constant.KPL_INVALID_BLOCKS:
                continue
            if data[3] > -5e7:
@@ -404,7 +417,7 @@
                break
        # 记录精选流出日志
        async_log_util.info(logger_kpl_jx_out, f"原数据:{datas[:10]} 板块:{blocks}")
        cls.__top_jx_out_blocks = blocks
        cls.__top_jx_out_blocks = list(blocks)
    @classmethod
    def get_top_market_jingxuan_blocks(cls):
@@ -456,6 +469,10 @@
        else:
            return False, None
    @classmethod
    def get_jx_block_in_money(cls, block):
        return cls.__jx_blocks_in_money_dict.get(block)
# 代码历史涨停原因与板块管理
class CodesHisReasonAndBlocksManager:
trade/buy_radical/block_special_codes_manager.py
@@ -145,15 +145,13 @@
                continue
            code_info_list = block_codes_dict[b]
            # code_info_list.sort(key=lambda x: x[1], reverse=True)
            # 取自由市值的前1/3
            code_info_list.sort(key=lambda x: float(limit_up_info_map[x[0]][2]), reverse=True)
            max_count = len(code_info_list) // 3
            # code_info_list.sort(key=lambda x: float(limit_up_info_map[x[0]][2]), reverse=True)
            # code_info_list.sort(key=lambda x: code_block_dict[x[0]][b], reverse=True)
            zylt_list = code_info_list[:max_count]
            # 按照涨停次数排序
            zylt_list.sort(key=lambda x: x[1], reverse=True)
            zylt_list = [x[0] for x in zylt_list]
            # fcodes = list(set(count_list) & set(zylt_list))
            # fcodes.sort(key=lambda x: code_block_dict[x][b], reverse=True)
            # ffcodes = fcodes[:5]
            index = 0
            # 获取股价,是否是ST
            if not zylt_list:
@@ -194,4 +192,4 @@
    for d in datas:
        print(d)
    BlockSpecialCodesManager().set_block_codes_list(datas)
    print(datas)
    # print(datas)
trade/buy_radical/radical_buy_data_manager.py
@@ -92,7 +92,7 @@
        jx_out_blocks = RealTimeKplMarketData.get_top_market_jingxuan_out_blocks()
        if jx_out_blocks:
            blocks = RadicalBuyBlockManager.get_code_blocks(code)[0]
            same_blocks = blocks & jx_out_blocks
            same_blocks = blocks & set(jx_out_blocks)
            if same_blocks:
                return False, f"【{same_blocks}】板块精选流出"
@@ -736,7 +736,7 @@
        # 获取精选净流入
        jx_in_blocks = RealTimeKplMarketData.get_top_market_jingxuan_blocks()
        keys_in_jx = keys_ & jx_in_blocks
        keys_in_jx = keys_ & set(jx_in_blocks)
        if not keys_in_jx:
            return set(), f"【{keys_}】板块未在精选流入中"
        keys_ = keys_in_jx
trade/trade_record_log_util.py
@@ -18,7 +18,8 @@
class PlaceOrderInfo(object):
    def __init__(self, buy_single_index=None, buy_exec_index=None, m_val=None, safe_count=None, big_num_indexes=None,
                 kpl_blocks=None, kpl_match_blocks=None, mode=None, mode_desc=None, sell_info=None):
                 kpl_blocks=None, kpl_match_blocks=None, mode=None, mode_desc=None, sell_info=None,
                 block_info=None):
        self.buy_single_index = buy_single_index
        self.buy_exec_index = buy_exec_index
        self.m_val = m_val
@@ -29,6 +30,14 @@
        self.mode = mode
        self.mode_desc = mode_desc
        self.sell_info = sell_info
        self.block_info = block_info
    def set_block_info(self, block_info):
        """
        @param block_info:(板块,流入金额)
        @return:
        """
        self.block_info = block_info
    def set_buy_index(self, buy_single_index, buy_exec_index):
        self.buy_single_index = buy_single_index