Administrator
2023-07-31 5840eb38afbbc909bacc2996738b859ad29ddf22
bug修复
10个文件已修改
159 ■■■■ 已修改文件
code_attribute/code_nature_analyse.py 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/gpcode_manager.py 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 64 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test_profile.py 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/block_info.py 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_data_manager.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/bidding_money_manager.py 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/first_code_score_manager.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/trade_api_server.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/code_nature_analyse.py
@@ -15,6 +15,8 @@
class CodeNatureRecordManager:
    __redisManager = RedisManager(0)
    __k_format_cache={}
    __nature_cache={}
    @classmethod
    def __get_redis(cls):
@@ -32,6 +34,15 @@
            return json.loads(val)
        return None
    @classmethod
    def get_k_format_cache(cls, code):
        if code in cls.__k_format_cache:
            return cls.__k_format_cache[code]
        val = cls.get_k_format(code)
        if val:
            cls.__k_format_cache[code] = val
        return val
    # 保存股性
    @classmethod
    def save_nature(cls, code, natures):
@@ -44,6 +55,16 @@
            return json.loads(val)
        return None
    @classmethod
    def get_nature_cache(cls, code):
        if code in cls.__nature_cache:
            return cls.__nature_cache[code]
        val = cls.get_nature(code)
        if val:
            cls.__nature_cache[code] = val
        return val
# 设置历史K线
def set_record_datas(code, limit_up_price, record_datas):
code_attribute/gpcode_manager.py
@@ -408,6 +408,19 @@
    return None
__price_pre_cache = {}
# 获取缓存
def get_price_pre_cache(code):
    if code in __price_pre_cache:
        return __price_pre_cache[code]
    val = get_price_pre(code)
    if val:
        __price_pre_cache[code] = val
    return val
# 设置收盘价
def set_price_pre(code, price, force=False):
    codes = get_gp_list()
@@ -583,7 +596,9 @@
        # 获取健康状态
        available_positions_health_states = l2_listen_pos_health_manager.list_health_state(available_positions)
        # 尽量不分配第一个位置
        available_positions_new = sorted(available_positions, key=lambda x: (available_positions_health_states[x], 0 if x[1] ==0 else 1), reverse=True)
        available_positions_new = sorted(available_positions,
                                         key=lambda x: (available_positions_health_states[x], 0 if x[1] == 0 else 1),
                                         reverse=True)
        # available_positions.sort(key=lambda x: available_positions_health_states[x], reverse=True)
        # 取第1个数据
        return available_positions_new[0][0], available_positions_new[0][1]
l2/cancel_buy_strategy.py
@@ -825,7 +825,7 @@
        watch_indexes = cls.__get_watch_indexes(code)
        if not watch_indexes:
            return False, None
        watch_indexes = set([int(i) for i in watch_indexes])
        # 计算监听的总条数
        total_count = 0
        for wi in watch_indexes:
l2/l2_data_manager_new.py
@@ -29,7 +29,6 @@
from line_profiler import LineProfiler
import dask
from trade.trade_manager import TradeTargetCodeModeManager
@@ -244,15 +243,18 @@
                logger_l2_process.info("code:{} 获取到下单真实位置:{}", code, place_order_index)
                DCancelBigNumComputer.set_real_order_index(code, place_order_index)
            __start_time = round(t.time() * 1000)
            if len(datas) > 0:
            cls.process_add_datas(code, datas, 0, __start_time)
            # lp = LineProfiler()
            # lp_wrap = lp(cls.process_add_datas)
            # lp_wrap(code, datas, 0, __start_time)
            # output = io.StringIO()
            # lp.print_stats(stream=output)
            # with open(f"/home/logs/profile/{code}_{round(t.time() * 1000)}.txt",'w') as f:
            #     f.write(output.getvalue())
            else:
                lp = LineProfiler()
                lp.enable()
                lp_wrap = lp(cls.process_add_datas)
                lp_wrap(code, datas, 0, __start_time)
                output = io.StringIO()
                lp.print_stats(stream=output)
                lp.disable()
                with open(f"/home/logs/profile/{code}_{datas[0]['index']}_{datas[-1]['index']}.txt", 'w') as f:
                    f.write(output.getvalue())
            # lp.dump_stats(f"/home/logs/profile/{code}_{round(t.time() * 1000)}.txt")
        except Exception as e:
            print("huaxin L2数据处理异常", code, str(e))
@@ -268,7 +270,6 @@
    def process_add_datas(cls, code, add_datas, capture_timestamp, __start_time):
        now_time_str = tool.get_now_time_str()
        if len(add_datas) > 0:
            print(id(local_today_datas))
            # 拼接数据
            local_today_datas[code].extend(add_datas)
            l2.l2_data_util.load_num_operate_map(local_today_num_operate_map, code, add_datas)
@@ -298,7 +299,21 @@
            limit_up_time = limit_up_time_manager.get_limit_up_time(code)
            if limit_up_time is None:
                limit_up_time = tool.get_now_time_str()
            score = None
            if len(add_datas) < 10:
            score = first_code_score_manager.get_score(code, volume_rate, limit_up_time, True)
            else:
                lp = LineProfiler()
                lp.enable()
                lp_wrap = lp(first_code_score_manager.get_score)
                score = lp_wrap(code, volume_rate, limit_up_time, True)
                output = io.StringIO()
                lp.print_stats(stream=output)
                lp.disable()
                with open(
                        f"/home/logs/profile/{code}_get_score_{add_datas[0]['index']}_{add_datas[-1]['index']}.txt",
                        'w') as f:
                    f.write(output.getvalue())
            cls.__l2PlaceOrderParamsManagerDict[code] = l2_trade_factor.L2PlaceOrderParamsManager(code, is_first_code,
                                                                                                  volume_rate,
                                                                                                  volume_rate_index,
@@ -319,11 +334,26 @@
                end_index = len(total_datas) - 1
                if state == trade_manager.TRADE_STATE_BUY_DELEGATED or state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or state == trade_manager.TRADE_STATE_BUY_SUCCESS:
                    # 已挂单
                    if len(add_datas) < 10:
                    cls.__process_order(code, start_index, end_index, capture_timestamp, is_first_code)
                    else:
                        lp = LineProfiler()
                        lp.enable()
                        lp_wrap = lp(cls.__process_order)
                        lp_wrap(code, start_index, end_index, capture_timestamp, is_first_code)
                        output = io.StringIO()
                        lp.print_stats(stream=output)
                        lp.disable()
                        with open(
                                f"/home/logs/profile/{code}_process_order_{add_datas[0]['index']}_{add_datas[-1]['index']}.txt",
                                'w') as f:
                            f.write(output.getvalue())
                else:
                    # 未挂单,时间相差不大才能挂单
                    if l2.l2_data_util.L2DataUtil.is_same_time(now_time_str, latest_time):
                        cls.__process_not_order(code, start_index, end_index, capture_timestamp, is_first_code)
            logger_l2_process.info("code:{} 处理数据范围: {}-{} 处理时间:{} 截图时间戳:{}", code, add_datas[0]["index"],
                                   add_datas[-1]["index"], round(t.time() * 1000) - __start_time,
@@ -340,8 +370,20 @@
        if round(t.time() * 1000) - __start_time > 10:
            __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
                                               "获取m值数据耗时")
        if end_index - start_index < 10:
        cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time, is_first_code)
        else:
            lp = LineProfiler()
            lp.enable()
            lp_wrap = lp(cls.__start_compute_buy)
            lp_wrap(code, start_index, end_index, threshold_money, capture_time, is_first_code)
            output = io.StringIO()
            lp.print_stats(stream=output)
            lp.disable()
            with open(
                    f"/home/logs/profile/{code}_start_compute_buy_{start_index}_{end_index}.txt",
                    'w') as f:
                f.write(output.getvalue())
    # 测试专用
    @classmethod
test/test_profile.py
@@ -1,11 +1,21 @@
import pstats
import io
import time
from line_profiler import LineProfiler
def test1(args):
    print(args)
    time.sleep(2)
    return 1
if __name__ == "__main__":
    # pr = cProfile.Profile()
    # pr.enable()
    # jingxuan_ranks = KPLDataManager().get_from_file(kpl_util.KPLDataType.JINGXUAN_RANK, tool.get_now_date_str())
    # pr.disable()
    # pr.dump_stats(r"D:/logs/test.log")
    p = pstats.Stats('/home/hexiaohui/logs/605228_1690440269940.log')
    p.sort_stats('time').print_stats()  # 按照时间排序显示其内容,也可按照其他列显示
    p.print_stats()  # 不按时间排序,直接显示内容
    lp = LineProfiler()
    lp_wrap = lp(test1)
    result = lp_wrap("123123")
    print(result)
    output = io.StringIO()
    lp.print_stats(stream=output)
    with open(f"test.txt", 'w') as f:
        f.write(output.getvalue())
third_data/block_info.py
@@ -18,9 +18,8 @@
def __load_before_block(code):
    if code not in __before_block_dict:
        blocks = KPLLimitUpDataRecordManager.get_latest_blocks(code)
        blocks = KPLLimitUpDataRecordManager.get_latest_blocks_set(code)
        if blocks:
            blocks = blocks[0].split(',')
            __before_block_dict[code] = blocks
    return __before_block_dict.get(code)
@@ -245,6 +244,10 @@
def init():
    # 加载数据到内存中
    kpl_data_manager.get_current_limit_up_data_records(10)
    # 加载最近数据到内存中
    limit_up_datas = kpl_data_manager.KPLDataManager().get_data(kpl_util.KPLDataType.LIMIT_UP)
    if limit_up_datas:
        kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas = limit_up_datas
def init_code(code):
third_data/kpl_data_manager.py
@@ -157,7 +157,6 @@
            wheres.append(f"hb.`_hot_block_name` != '{b}'")
        wheres = " and ".join(wheres)
        sql = f"SELECT GROUP_CONCAT(_hot_block_name) FROM (SELECT hb.`_hot_block_name`,hb.`_day` FROM `kpl_limit_up_record` hb WHERE hb.`_code`='{code}' AND {wheres} ORDER BY hb.`_day` DESC LIMIT 2) a  GROUP BY a._day ORDER BY a._day DESC LIMIT 1"
        print(sql)
        mysqldb = mysql_data.Mysqldb()
        return mysqldb.select_one(sql)
trade/bidding_money_manager.py
@@ -39,6 +39,18 @@
    return None
bidding_money_cache = {}
# 设置缓存(缓存到内存中)
def get_bidding_money_cache(code):
    if code in bidding_money_cache:
        return bidding_money_cache[code]
    else:
        bm = get_bidding_money(code)
        bidding_money_cache[code] = bm
if __name__ == "__main__":
    # datas = [('002229', '10.92亿'), ('000977', '2592万'), ('000829', '2294万'), ('002467', '1869万'), ('002217', '1546万')]
    # set_bidding_money(datas)
trade/first_code_score_manager.py
@@ -225,13 +225,13 @@
    source_datas.append(limit_price)
    # 竞价金额
    bidding_money = bidding_money_manager.get_bidding_money(code)
    bidding_money = bidding_money_manager.get_bidding_money_cache(code)
    source_datas.append(bidding_money)
    bidding = False
    if bidding_money and bidding_money >= 5000:
        bidding = True
    k_form = code_nature_analyse.CodeNatureRecordManager.get_k_format(code)
    k_form = code_nature_analyse.CodeNatureRecordManager.get_k_format_cache(code)
    if k_form is None:
        k_form = [(True, ''), (False, ''), (False, ''), (False, ''), (False, ''), (False, ''), (True, ''), (1, 1)]
    today_volume = code_volumn_manager.get_today_volumn(code)
@@ -249,7 +249,7 @@
    source_datas.append(k_form)
    code_nature = code_nature_analyse.CodeNatureRecordManager.get_nature(code)
    code_nature = code_nature_analyse.CodeNatureRecordManager.get_nature_cache(code)
    source_datas.append(code_nature)
    hot_block = block_info.get_info(code)
trade/huaxin/trade_api_server.py
@@ -150,6 +150,7 @@
                                    l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤销")
                                    return_str = json.dumps({"code": 0})
                                except Exception as e:
                                    logging.exception(e)
                                    return_str = json.dumps({"code": 2, "msg": str(e)})
                            else:
                                return_str = json.dumps({"code": 1, "msg": "未处于可撤单状态"})