Administrator
2024-02-23 991ab59fb7e6cd2d2691339dc8101831827133c9
华鑫L2一直监听要买的量/H撤Bug修复/大市值不买规则调整
13个文件已修改
115 ■■■■■ 已修改文件
code_attribute/first_target_code_data_processor.py 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_client.py 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_data_manager.py 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_delegate_postion_manager.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_target_codes_manager.py 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
msg/buy_order_msg_manager.py 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/current_price_process_manager.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api_server.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_server.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_manager.py 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/buy_condition_util.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/tool.py 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/first_target_code_data_processor.py
@@ -136,7 +136,8 @@
                    if not is_special:
                        situation = MarketSituationManager().get_situation_cache()
                        zylt_threshold_as_yi = buy_condition_util.get_zyltgb_threshold(situation)
                        if global_util.zyltgb_map.get(code) and global_util.zyltgb_map.get(code) > zylt_threshold_as_yi[1] * 100000000:
                        if global_util.zyltgb_map.get(code) and global_util.zyltgb_map.get(code) > zylt_threshold_as_yi[
                            1] * 100000000:
                            l2_trade_util.forbidden_trade(code,
                                                          f"无辨识度,自由流通市值({global_util.zyltgb_map.get(code) // 100000000})>{zylt_threshold_as_yi[1]}亿")
                            continue
@@ -205,6 +206,9 @@
                    l2_code_operate.L2CodeOperate.get_instance().add_operate(0, lc, "代码被移除")
    # 保存现价
    if dataList:
        situation = MarketSituationManager().get_situation_cache()
        zyltgb_thresholds = buy_condition_util.get_zyltgb_threshold(situation)
        want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache()
        for data in dataList:
            code = data["code"]
            codes.append(code)
@@ -213,6 +217,24 @@
                limit_up_price_dict[code] = limit_up_price
            else:
                temp_codes.append(code)
            # 自由流通市值不符合标准
            if not want_codes or code not in want_codes:
                # 没在想买单
                zyltgb = global_util.zyltgb_map.get(code)
                if zyltgb:
                    zyltgb_as_yi = round(zyltgb / 100000000, 2)
                    if zyltgb_as_yi < zyltgb_thresholds[0] or zyltgb_as_yi > zyltgb_thresholds[6]:
                        # 想买单中的不能排除
                        continue
                    elif zyltgb_as_yi > zyltgb_thresholds[1]:
                        # 比最大可买大的,如果没有短期辨识度就不买
                        k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code)
                        if k_format and k_format[8][0] and k_format[8][1].find("短期") >= 0:
                            pass
                        else:
                            # 无短期辨识度
                            continue
            tick_datas.append({"code": code, "price": data["price"], "volume": data["volume"],
                               "volumeUnit": data["volumeUnit"]})
    # 获取涨停价
huaxin_client/l2_client.py
@@ -134,8 +134,8 @@
        for d in codes_data:
            code = d[0]
            codes.add(code)
            self.codes_volume_and_price_dict[code] = (d[1], d[2], d[3])
            self.l2_data_upload_manager.set_order_fileter_condition(code, d[1], float(d[2]), d[3])
            self.codes_volume_and_price_dict[code] = (d[1], d[2], d[3], d[4])
            self.l2_data_upload_manager.set_order_fileter_condition(code, d[1], float(d[2]), d[3], d[4])
        add_codes = codes - self.subscripted_codes
        del_codes = self.subscripted_codes - codes
        print("add del codes", add_codes, del_codes)
@@ -191,8 +191,8 @@
        # self.special_code_volume_for_order_dict[code] = (volume, time.time() + 3)
        d = self.codes_volume_and_price_dict.get(code)
        if d:
            min_volume, limit_up_price, special_price = d[0], d[1], d[2]
            self.l2_data_upload_manager.set_order_fileter_condition(code, min_volume, limit_up_price,special_price,
            min_volume, limit_up_price, special_price, buy_volume = d[0], d[1], d[2], d[3]
            self.l2_data_upload_manager.set_order_fileter_condition(code, min_volume, limit_up_price, special_price,buy_volume,
                                                                    {volume, constant.SHADOW_ORDER_VOLUME},
                                                                    time.time() + 3)
            huaxin_l2_log.info(logger_local_huaxin_l2_subscript, f"设置下单量监听:{code}-{volume}")
huaxin_client/l2_data_manager.py
@@ -44,16 +44,18 @@
    # 设置订单过滤条件
    # special_price:过滤的1手的价格
    def set_order_fileter_condition(self, code, min_volume, limit_up_price, special_price, special_volumes=None,
    def set_order_fileter_condition(self, code, min_volume, limit_up_price, special_price, buy_volume,
                                    special_volumes=None,
                                    special_volumes_expire_time=None):
        if special_volumes is None:
            special_volumes = set()
        if code in self.filter_order_condition_dict and not special_volumes and not special_volumes_expire_time:
            self.filter_order_condition_dict[code][0] = (min_volume, limit_up_price, special_price)
            self.filter_order_condition_dict[code][0] = (min_volume, limit_up_price, special_price, buy_volume)
            huaxin_l2_log.info(logger_local_huaxin_l2_subscript,
                               f"({code})常规过滤条件设置:{self.filter_order_condition_dict[code]}")
        else:
            self.filter_order_condition_dict[code] = [(min_volume, limit_up_price, special_price), special_volumes,
            self.filter_order_condition_dict[code] = [(min_volume, limit_up_price, special_price, buy_volume),
                                                      special_volumes,
                                                      special_volumes_expire_time]
            huaxin_l2_log.info(logger_local_huaxin_l2_subscript,
                               f"({code})下单后过滤条件设置:{self.filter_order_condition_dict[code]}")
@@ -68,6 +70,10 @@
            # 1手的买单满足价格
            if item[2] == 100 and item[3] == '1' and abs(filter_condition[0][2] - item[1]) < 0.001:
                return item
            # 买量
            if item[2] == filter_condition[0][3] and item[3] == '1':
                return item
            if filter_condition[1] and item[2] in filter_condition[1]:
                if filter_condition[2] and time.time() > filter_condition[2]:
                    # 超时了,需要清除特殊量数据
l2/cancel_buy_strategy.py
@@ -496,7 +496,7 @@
        total_datas = local_today_datas.get(code)
        # h撤计算必须超过5s
        if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[buy_single_index]["val"]) < 5:
        if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[buy_single_index]["val"]["time"]) < 5:
            l2_log.h_cancel_debug(code, "5s内囊括计算H撤")
            return
        # -----------------计算H上-------------------
l2/huaxin/huaxin_delegate_postion_manager.py
@@ -8,6 +8,7 @@
from l2.l2_data_util import L2DataUtil
from log_module import async_log_util
from log_module.log import hx_logger_trade_debug, logger_real_place_order_position
from trade.huaxin import huaxin_trade_record_manager
from utils import tool
_place_order_info_dict = {}
@@ -74,7 +75,10 @@
        if d["index"] <= exec_data["index"]:
            continue
        if L2DataUtil.time_sub_as_ms(val, exec_data['val']) >= 2000:
            continue
            # 不能排除与下单时间一致的订单
            current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates(code)
            if not current_delegates or current_delegates[0]["acceptTime"] != val["time"]:
                continue
        if not L2DataUtil.is_buy(val):
            continue
        shadow_place_order_index = d["index"]
l2/huaxin/huaxin_target_codes_manager.py
@@ -76,9 +76,7 @@
        if not global_util.zyltgb_map:
            global_data_loader.load_zyltgb()
        situation = MarketSituationManager().get_situation_cache()
        zyltgb_thresholds = buy_condition_util.get_zyltgb_threshold(situation)
        want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache()
        for d in datas:
            code = d[0]
            # 格式 (代码,现价,涨幅,量,更新时间,买1价格,买1量)
@@ -109,13 +107,13 @@
                except:
                    pass
            # 自由流通市值不符合标准
            zyltgb = global_util.zyltgb_map.get(code)
            if zyltgb:
                zyltgb_as_yi = round(zyltgb / 100000000, 2)
                if zyltgb_as_yi < zyltgb_thresholds[0] or zyltgb_as_yi > zyltgb_thresholds[1]:
                    if not want_codes or code not in want_codes:
                        # 想买单中的不能排除
                        continue
            # zyltgb = global_util.zyltgb_map.get(code)
            # if zyltgb:
            #     zyltgb_as_yi = round(zyltgb / 100000000, 2)
            #     if zyltgb_as_yi < zyltgb_thresholds[0] or zyltgb_as_yi > zyltgb_thresholds[1]:
            #         if not want_codes or code not in want_codes:
            #             # 想买单中的不能排除
            #             continue
            # 保存今日实时量
            temp_volumns.append((code, d[3]))
msg/buy_order_msg_manager.py
@@ -9,11 +9,12 @@
# 即将成交
def almost_deal(code, real_order_index, trade_index, total_datas):
def almost_deal(code, real_order_index, trade_index):
    total_datas = l2_data_util.local_today_datas.get(code)
    if trade_index > real_order_index:
        return
    # 下单3s过后再提醒
    if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[real_order_index]["val"]["time"]) <= 3:
    if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[real_order_index]["val"]["time"]) <= 5:
        return
    total_left_count = 0
    total_left_money = 0
@@ -36,21 +37,22 @@
    if total_left_count <= 10:
        push_msg_manager.push_order_almost_deal(code, code_name, real_order_index, f"剩余:{total_left_count}笔",
                                                ctype="count")
        async_log_util.info(logger_kp_msg, f"{code}即将成交:trade_index-{trade_index},real_order_index-{real_order_index},剩余:{total_left_count}笔")
        async_log_util.info(logger_kp_msg, f"{code}即将成交:trade_index-{trade_index},real_order_index-{real_order_index},剩余:{total_left_count}笔,结尾:{total_datas[-1]['index']}")
    elif total_left_money < 1500 * 10000:
        push_msg_manager.push_order_almost_deal(code, code_name, real_order_index,
                                                f"剩余:{output_util.money_desc(total_left_money)}", ctype="money")
        async_log_util.info(logger_kp_msg,
                            f"{code}即将成交:trade_index-{trade_index},real_order_index-{real_order_index},剩余:{total_left_money}元")
                            f"{code}即将成交:trade_index-{trade_index},real_order_index-{real_order_index},剩余:{total_left_money}元,结尾:{total_datas[-1]['index']}")
# 真实下单位后面跟单不足
def follow_not_enough(code, buy_exec_index, real_order_index, total_datas):
def follow_not_enough(code, buy_exec_index, real_order_index):
    if buy_exec_index > real_order_index:
        return
    total_datas = l2_data_util.local_today_datas.get(code)
    # 下单3s过后再提醒
    if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[buy_exec_index]["val"]["time"]) <= 3:
    if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[buy_exec_index]["val"]["time"]) <= 5:
        return
    real_place_order_after_count = 0
@@ -80,11 +82,11 @@
                                                    f"剩余:{real_place_order_after_count}笔",
                                                    ctype="count")
        async_log_util.info(logger_kp_msg,
                            f"{code}封单不足:buy_exec_index-{buy_exec_index},real_order_index-{real_order_index},剩余:{real_place_order_after_count}元")
                            f"{code}封单不足:buy_exec_index-{buy_exec_index},real_order_index-{real_order_index},剩余:{real_place_order_after_count}笔,结尾:{total_datas[-1]['index']}")
    if real_place_order_after_money <= 1500 * 10000:
        push_msg_manager.push_delegate_order_danger(code, code_name, buy_exec_index,
                                                    f"剩余:{output_util.money_desc(real_place_order_after_money)}",
                                                    ctype="money")
        async_log_util.info(logger_kp_msg,
                            f"{code}封单不足:buy_exec_index-{buy_exec_index},real_order_index-{real_order_index},剩余:{real_place_order_after_money}元")
                            f"{code}封单不足:buy_exec_index-{buy_exec_index},real_order_index-{real_order_index},剩余:{real_place_order_after_money}元,结尾:{total_datas[-1]['index']}")
trade/current_price_process_manager.py
@@ -146,7 +146,7 @@
                        min_volume = int(round(50 * 10000 / limit_up_price))
                        # 传递笼子价
                        add_datas.append(
                            (d, min_volume, limit_up_price, round(tool.get_shadow_price(limit_up_price), 2)))
                            (d, min_volume, limit_up_price, round(tool.get_shadow_price(limit_up_price), 2),tool.get_buy_volume(limit_up_price)))
                    huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.push(add_datas, request_id)
            except Exception as e:
                logging.exception(e)
trade/huaxin/huaxin_trade_api_server.py
@@ -460,7 +460,7 @@
                                limit_up_price = gpcode_manager.get_limit_up_price(d[0])
                                if limit_up_price:
                                    # 默认设置涨停,量为0
                                    datas.append((code, 0, float(limit_up_price), tool.get_shadow_price(float(limit_up_price))))
                                    datas.append((code, 0, float(limit_up_price), tool.get_shadow_price(float(limit_up_price)),100))
                        except Exception as e:
                            logger_l2_codes_subscript.exception(e)
                    if not datas:
trade/huaxin/huaxin_trade_server.py
@@ -1319,6 +1319,7 @@
                except Exception as e:
                    self.send_response({"code": 1, "msg": str(e)}, client_id, request_id)
            elif ctype == "get_delegated_buy_code_infos":
                account_available_money = trade_manager.AccountAvailableMoneyManager().get_available_money_cache()
                # 获取委托中的代码
                # current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates()
                current_delegates, update_time = huaxin_trade_record_manager.DelegateRecordManager.list_by_day(
@@ -1481,7 +1482,7 @@
                        except Exception as e:
                            logger_debug.exception(e)
                result = {"code": 0, "data": fdatas}
                result = {"code": 0, "data": {"account_available_money":account_available_money ,"delegates":fdatas}}
                self.send_response(result, client_id, request_id)
            elif ctype == "set_real_place_order_index":
                # 设置真实下单位置
trade/trade_manager.py
@@ -540,12 +540,7 @@
    async_log_util.info(logger_trade, "{} trade_manager.__buy 开始".format(code))
    try:
        if constant.API_TRADE_ENABLE:
            count = (constant.BUY_MONEY_PER_CODE // int(round(float(price) * 100))) * 100
            # if mode != 0:
            #     count = 100
            # 最低下单1手
            if count < 100:
                count = 100
            count = tool.get_buy_volume(price)
            if constant.TRADE_WAY == constant.TRADE_WAY_JUEJIN:
                trade_juejin.order_volume(code, price, count)
            elif constant.TRADE_WAY == constant.TRADE_WAY_HUAXIN:
utils/buy_condition_util.py
@@ -7,11 +7,11 @@
# 获取自由流通市值的阈值范围
# (最小流通,最大流通,优秀开始,优秀结束,最优开始,最优结束)
# (最小流通,最大流通,优秀开始,优秀结束,最优开始,最优结束,最大可买)
def get_zyltgb_threshold(market_sitation: int):
    if market_sitation == MarketSituationManager.SITUATION_GOOD:
        return 31, 100, 40, 100, 40, 80
    return 8.9, 31, 8.9, 25, 8.9, 19
        return 31, 100, 40, 100, 40, 80, 100
    return 8.9, 31, 8.9, 25, 8.9, 19, 80
# 获取量比的等级获取量
utils/tool.py
@@ -279,3 +279,10 @@
    except:
        pass
    return None
def get_buy_volume(limit_up_price):
    count = (constant.BUY_MONEY_PER_CODE // int(round(float(limit_up_price) * 100))) * 100
    if count < 100:
        count = 100
    return count