Administrator
2023-08-17 16db33c161f5dbbb423f2d84199b3f7723e9b2ad
bug修改
7个文件已修改
104 ■■■■■ 已修改文件
constant.py 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
log_module/log_analyse.py 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
output/code_info_output.py 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/l2_trade_test.py 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/huaxin_util.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constant.py
@@ -21,10 +21,10 @@
# redis设置
REDIS_CONFIG = {
    "host": "127.0.0.1",
    "port": 6379,
    "host": "gz-crs-6l6xbc4j.sql.tencentcdb.com",
    "port": 29994,
    "db": 0,
    "pwd": "123456"
    "pwd": "Yeshi2016@"
} if is_windows() else {
    "host": "172.16.32.15",
    "port": 6379,
@@ -38,12 +38,12 @@
}
MYSQL_CONFIG = {
    "host": "127.0.0.1",
    "port": 3306,
    "host": "gz-cdb-r13d0yi9.sql.tencentcdb.com",
    "port": 62929,
    "database": "gp",
    "charset": "utf8",
    "user": "root",
    "passwd": "123456"
    "passwd": "Yeshi2016@"
} if is_windows() else {
    "host": "172.16.16.17",
    "port": 3306,
@@ -128,7 +128,7 @@
TRADE_WAY = TRADE_WAY_JUEJIN
########华鑫配置########
if not is_windows():
if not is_windows() or True:
    # 下单1手
    BUY_MONEY_PER_CODE = 100
    L2_SOURCE_TYPE = L2_SOURCE_TYPE_HUAXIN
l2/l2_data_manager_new.py
@@ -584,7 +584,7 @@
            if need_clear_data:
                trade_result_manager.real_cancel_success(code, buy_single_index, buy_exec_index,
                                                         local_today_datas.get(code))
            return
            return False
        else:
            l2_log.debug(code, "可以下单,原因:{}", reason)
@@ -607,7 +607,9 @@
                l2_log.debug(code, "执行买入异常:{}", str(e))
                pass
            finally:
                l2_log.debug(code, "m值影响因子:{}", l2_trade_factor.L2TradeFactorUtil.factors_to_string(code))
                # l2_log.debug(code, "m值影响因子:{}", l2_trade_factor.L2TradeFactorUtil.factors_to_string(code))
                pass
            return True
    # 是否可以取消
    @classmethod
@@ -880,21 +882,21 @@
            # with open(f"{constant.get_path_prefix()}/logs/profile/{code}_can_buy_first.txt", 'w') as f:
            #     f.write(output.getvalue())
            # return results
            return cls.can_buy_first(code, limit_up_price, score_index, score, score_info, cls.volume_rate_info[code])
            return cls.can_buy_first(code, limit_up_price)
        else:
            return True, False, "在想买名单中"
    @classmethod
    def can_buy_first(cls, code, limit_up_price, score_index, score, score_info, volume_rate_info):
        def is_has_k_format(score_info):
            # (15个交易日涨幅是否大于24.9%,是否破前高,是否超跌,是否接近前高,是否N,是否V,是否有形态,天量大阳信息,是否具有辨识度)
            if score_info[1][3][6][0] and not score_info[1][3][3][0]:
                return True
            if score_info[1][3][7][0]:
                return True
            return False
    def can_buy_first(cls, code, limit_up_price):
        # def is_has_k_format(score_info):
        #     # (15个交易日涨幅是否大于24.9%,是否破前高,是否超跌,是否接近前高,是否N,是否V,是否有形态,天量大阳信息,是否具有辨识度)
        #
        #     if score_info[1][3][6][0] and not score_info[1][3][3][0]:
        #         return True
        #     if score_info[1][3][7][0]:
        #         return True
        #     return False
        if float(limit_up_price) >= constant.MAX_CODE_PRICE:
            return False, True, f"股价大于{constant.MAX_CODE_PRICE}块"
@@ -1074,11 +1076,15 @@
            cls.__TradePointManager.delete_buy_cancel_point(code)
            l2_log.debug(code, "delete_buy_cancel_point")
            # 直接下单
            cls.__buy(code, capture_time, total_datas[compute_index], compute_index, is_first_code)
            ordered = cls.__buy(code, capture_time, total_datas[compute_index], compute_index, is_first_code)
            # 数据是否处理完毕
            if compute_index < compute_end_index:
                cls.__process_order(code, compute_index + 1, compute_end_index, capture_time, is_first_code, False)
                if ordered:
                    cls.__process_order(code, compute_index + 1, compute_end_index, capture_time, is_first_code, False)
                else:
                    cls.__start_compute_buy(code, compute_index + 1, compute_end_index, threshold_money, capture_time,
                                            is_first_code)
        else:
            # 未达到下单条件,保存纯买额,设置纯买额
            # 记录买入信号位置
log_module/log_analyse.py
@@ -42,5 +42,22 @@
    return dict_
# 获取华鑫的委托数据
def load_huaxin_delegate_datas():
    file_path = "{}/logs/gp/kpl/kpl_block_can_buy.{}.log".format(constant.get_path_prefix(), tool.get_now_date_str())
    dict_ = {}
    if os.path.exists(file_path):
        with open(file_path, encoding="utf-8") as f:
            line = f.readline()
            while line:
                if True:
                    code = line.split("code=")[1][:6]
                    time_ = line.split("|")[0].split(" ")[1][:12]
                    reason = line.split(f"code={code}:")[1].strip()
                    dict_[code] = (time_, reason.replace("可以下单", ""))
                    # print(time_, code, reason)
                line = f.readline()
if __name__ == "__main__":
    print(get_kpl_can_buy_reasons_dict())
output/code_info_output.py
@@ -255,13 +255,7 @@
                                                                                    (score, score_list),
                                                                                    score_source_list))
        # 是否可以买入的信息
        can_buy_info = l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, limit_up_price,
                                                                                 __L2PlaceOrderParamsManager.score_index,
                                                                                 __L2PlaceOrderParamsManager.score,
                                                                                 __L2PlaceOrderParamsManager.score_info,
                                                                                 (volume_rate,
                                                                                  code_volumn_manager.get_volume_rate_index(
                                                                                      volume_rate)))
        can_buy_info = l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, limit_up_price)
        params["trade_data"]["can_buy_info"] = can_buy_info
        __base_L2PlaceOrderParamsManager = l2_trade_factor.L2PlaceOrderParamsManager(code, False, volume_rate,
test/l2_trade_test.py
@@ -2,6 +2,7 @@
# 清除交易数据
import decimal
import json
import multiprocessing
import random
import time
import unittest
@@ -11,6 +12,7 @@
from code_attribute import big_money_num_manager, gpcode_manager
from db.redis_manager_delegate import RedisUtils
from log_module import log, log_export
from trade.huaxin import huaxin_trade_api
from utils import tool
from db import redis_manager_delegate as redis_manager
from l2 import l2_log, l2_data_manager, transaction_progress
@@ -19,7 +21,7 @@
from third_data import kpl_util
from third_data.code_plate_key_manager import RealTimeKplMarketData, LimitUpCodesPlateKeyManager
from third_data.kpl_data_manager import KPLDataManager
from trade import trade_data_manager
from trade import trade_data_manager, current_price_process_manager
from trade.trade_queue_manager import THSBuy1VolumnManager
import l2.l2_data_manager_new, l2.l2_data_manager, l2.l2_data_util, l2.cancel_buy_strategy
@@ -90,7 +92,7 @@
    # @unittest.skip("跳过此单元测试")
    def test_trade(self):
        code = "002213"
        code = "000826"
        clear_trade_data(code)
        l2.l2_data_util.load_l2_data(code)
        total_datas = deepcopy(l2.l2_data_util.local_today_datas[code])
@@ -140,18 +142,23 @@
        LimitUpCodesPlateKeyManager().set_today_limit_up(
            KPLDataManager().get_from_file(kpl_util.KPLDataType.LIMIT_UP, tool.get_now_date_str()))
        current_price_process_manager.set_trade_price(code, round(float(gpcode_manager.get_limit_up_price(code)), 2))
        pss_server, pss_strategy = multiprocessing.Pipe()
        huaxin_trade_api.set_pipe_trade(pss_server)
        for indexs in pos_list:
            l2_log.threadIds[code] = mock.Mock(
                return_value=random.randint(0, 100000))
            # 设置封单额,获取买1量
            for i in range(0, 100):
                time_ = total_datas[indexs[0]]["val"]["time"]
                time_s = tool.get_time_as_second(time_) - i - 1
                volumn = THSBuy1VolumnManager().get_buy_1_volumn(code, tool.time_seconds_format(time_s))
                if volumn is not None:
                    l2.cancel_buy_strategy.L2LimitUpMoneyStatisticUtil().verify_num(code, int(volumn),
                                                                                    tool.time_seconds_format(time_s))
                    break
            # for i in range(0, 100):
            #     time_ = total_datas[indexs[0]]["val"]["time"]
            #     time_s = tool.get_time_as_second(time_) - i - 1
            #     volumn = THSBuy1VolumnManager().get_buy_1_volumn(code, tool.time_seconds_format(time_s))
            #     if volumn is not None:
            #         l2.cancel_buy_strategy.L2LimitUpMoneyStatisticUtil().verify_num(code, int(volumn),
            #                                                                         tool.time_seconds_format(time_s))
            #         break
            # 设置委买队列
            for i in range(0, len(buy_queues)):
                if tool.trade_time_sub(buy_queues[i][1], total_datas[indexs[0]]["val"]["time"]) > 0:
third_data/code_plate_key_manager.py
@@ -505,7 +505,7 @@
    def can_buy(cls, code, current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes,
                before_blocks_dict):
        if constant.TEST:
            return True, "", cls.BLOCK_TYPE_NONE
            return True, cls.BLOCK_TYPE_NONE
        blocks, block_msg = cls.get_can_buy_block(code, current_limit_up_datas,
                                                  limit_up_record_datas, yesterday_current_limit_up_codes,
utils/huaxin_util.py
@@ -34,3 +34,5 @@
    if state == TORA_TSTP_OST_Cached or state == TORA_TSTP_OST_Unknown or state == TORA_TSTP_OST_Accepted or state == TORA_TSTP_OST_PartTraded:
        return True
    return False