admin
2025-03-25 b534dbe6573a4ad048987bab670b8159dc73fe11
bug修改
7个文件已修改
171 ■■■■■ 已修改文件
main.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/L2_data_analysis.py 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/account_management.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/all_K_line.py 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/buying_strategy.py 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/index_market_trend_strategy.py 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/order_methods.py 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.py
@@ -100,7 +100,8 @@
    #  开盘啦的涨停概念的回调函数
    def kpl_limit_up_process(datas):
        # print(f"回调成功==={datas}")
        data_cache.limit_up_block_names = datas
        if datas is not None and len(datas) > 0:
            data_cache.limit_up_block_names = datas
    # # 计算当前线程数量
    # get_current_thread_count()
strategy/L2_data_analysis.py
@@ -65,11 +65,6 @@
        # print(f"没有找到这个货:{code}")
# 测试的时候可以调用一下
find_L2_big_order_of_code('002384')
# # 如果你需要将解析后的日志保存到新文件中,可以使用以下代码:
# output_file_path = 'path/to/your/parsed_logfile.txt'
# with open(output_file_path, 'w', encoding='utf-8') as output_file:
#     for log in parsed_logs:
#         output_file.write(log + '\n')
if __name__ == '__main__':
    # 测试的时候可以调用一下
    find_L2_big_order_of_code('002384')
strategy/account_management.py
@@ -92,9 +92,9 @@
                else:
                    data_cache.available_symbols_set.add(securityID)
                    if historyPosFrozen != 0:
                        logger.info(f"昨日持仓==={securityName}==挂单中》》挂单数量:{historyPosFrozen}")
                    else:
                        logger.info(f"昨日持仓==={securityName}===持仓可用:{availablePosition}")
                        logger.info(f"昨日持仓==={securityName}  挂单中》》 挂单数量:{historyPosFrozen}")
                    if availablePosition != 0:
                        logger.info(f"昨日持仓==={securityName}  持仓可用:{availablePosition}")
        # todo 自主的计算持仓数量 管用 还是 服务端即时查询同步有用 有待验证
        logger.info(f"今日可用持仓数量====================================【{len(data_cache.available_symbols_set)}】")
strategy/all_K_line.py
@@ -209,8 +209,7 @@
                current_count = 0
                start = None
            #  确保不会出现除以零的报错
            if current_yesterday_volume == 0:
                current_yesterday_volume = 1
            if current_yesterday_volume != 0:
                if round(current_today_volume / current_yesterday_volume, 2) > 1.1:
                    # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【放量】")
                    if current_today_growth > 0:
@@ -234,17 +233,19 @@
                    else:
                        it_K_line[i]['today_volume_shape'] = 'decreases_balance'
                        # print(f"i=={i}  {it_K_line[i]['bob']}   【缩量平收】")
            else:
                # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【平量】")
                if current_today_growth > 0:
                    it_K_line[i]['today_volume_shape'] = 'remained_up'
                    # print(f"i=={i}  {it_K_line[i]['bob']}   【平量上涨】")
                elif current_today_growth < 0:
                    it_K_line[i]['today_volume_shape'] = 'remained_down'
                    # print(f"i=={i}  {it_K_line[i]['bob']}   【平量下跌】")
                else:
                    it_K_line[i]['today_volume_shape'] = 'remained_balance'
                    # print(f"i=={i}  {it_K_line[i]['bob']}   【平量平收】")
                    # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【平量】")
                    if current_today_growth > 0:
                        it_K_line[i]['today_volume_shape'] = 'remained_up'
                        # print(f"i=={i}  {it_K_line[i]['bob']}   【平量上涨】")
                    elif current_today_growth < 0:
                        it_K_line[i]['today_volume_shape'] = 'remained_down'
                        # print(f"i=={i}  {it_K_line[i]['bob']}   【平量下跌】")
                    else:
                        it_K_line[i]['today_volume_shape'] = 'remained_balance'
                        # print(f"i=={i}  {it_K_line[i]['bob']}   【平量平收】")
            else:
                logger.info(f"{symbol} 的 昨日成交量 为 0,报错!!")
            if current_open - previous_close > 0:
                # print(f"i=={i}  {it_K_line[i]['bob']} 成交总量:{today_volume},,,成交总金额:{today_amount}")
strategy/buying_strategy.py
@@ -335,12 +335,22 @@
                                            order_methods.buy_order_by_value(symbol, data_cache.today_planned_order_amount,
                                                                             k_line_data[0]['sec_name'],
                                                                             current_price)
                                            # 将有概念买入次数自加1
                                            data_cache.have_plate_buy_times += 1
                                            # 将买入个股的当时概念添加到全局变量中存储
                                            data_cache.bought_plate.extend(limit_up_plate_included_list)
                                            # 查看一下该股有无大单
                                            L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                            # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
                                            for i in data_cache.account_positions_dict:
                                                # print(i)
                                                if i['securityID'] == symbol_code:
                                                    # print(i['currentPosition'])
                                                    if i['currentPosition'] == 0:
                                                        logger.info(f"【{i['securityName']}】交易失败~")
                                                    else:
                                                        # 将有概念买入次数自加1
                                                        data_cache.have_plate_buy_times += 1
                                                        # 将买入个股的当时概念添加到全局变量中存储
                                                        data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                        logger.info(f"【{i['securityName']}】交易成功!")
                                    # 有概念无强度视界
@@ -418,12 +428,25 @@
                                                # order_methods.buy_order_by_value(symbol, 1000,
                                                #                                  k_line_data[0]['sec_name'],
                                                #                                  current_price)
                                                # 将有概念买入次数自加1
                                                data_cache.have_plate_buy_times += 1
                                                # 将买入个股的当时概念添加到全局变量中存储
                                                data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                # 查看一下该股有无大单
                                                # # 将有概念买入次数自加1
                                                # data_cache.have_plate_buy_times += 1
                                                # # 将买入个股的当时概念添加到全局变量中存储
                                                # data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                # # 查看一下该股有无大单
                                                L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
                                                for i in data_cache.account_positions_dict:
                                                    # print(i)
                                                    if i['securityID'] == symbol_code:
                                                        # print(i['currentPosition'])
                                                        if i['currentPosition'] == 0:
                                                            logger.info(f"【{i['securityName']}】交易失败~")
                                                        else:
                                                            # 将有概念买入次数自加1
                                                            data_cache.have_plate_buy_times += 1
                                                            # 将买入个股的当时概念添加到全局变量中存储
                                                            data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                            logger.info(f"【{i['securityName']}】交易成功!")
                                '''
                                无概念 有强度视界
@@ -505,12 +528,25 @@
                                                                                     data_cache.today_planned_order_amount,
                                                                                     k_line_data[0]['sec_name'],
                                                                                     current_price)
                                                    # 将有强度买入次数自加1
                                                    data_cache.have_strength_buy_times += 1
                                                    # 将买入个股的当时概念添加到全局变量中存储
                                                    data_cache.bought_plate.extend(strength_plate)
                                                    # # 将有强度买入次数自加1
                                                    # data_cache.have_strength_buy_times += 1
                                                    # # 将买入个股的当时概念添加到全局变量中存储
                                                    # data_cache.bought_plate.extend(strength_plate)
                                                    # 查看一下该股有无大单
                                                    L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                    # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
                                                    for i in data_cache.account_positions_dict:
                                                        # print(i)
                                                        if i['securityID'] == symbol_code:
                                                            # print(i['currentPosition'])
                                                            if i['currentPosition'] == 0:
                                                                logger.info(f"【{i['securityName']}】交易失败~")
                                                            else:
                                                                # 将有概念买入次数自加1
                                                                data_cache.have_strength_buy_times += 1
                                                                # 将买入个股的当时概念添加到全局变量中存储
                                                                data_cache.bought_plate.extend(strength_plate)
                                                                logger.info(f"【{i['securityName']}】交易成功!")
                                '''
                                无概念无强度 有小量换大涨幅度视界
                                '''
@@ -603,12 +639,25 @@
                                                    order_methods.buy_order_by_value(symbol, 1000,
                                                                                     k_line_data[0]['sec_name'],
                                                                                     current_price)
                                                    # 将有小量换大涨幅买入次数自加1
                                                    data_cache.have_small_turn_large_buy_times += 1
                                                    # 将买入个股的当时概念添加到全局变量中存储
                                                    data_cache.bought_plate.append(k_line_data[0]['sec_name'])
                                                    # # 将有小量换大涨幅买入次数自加1
                                                    # data_cache.have_small_turn_large_buy_times += 1
                                                    # # 将买入个股的当时概念添加到全局变量中存储
                                                    # data_cache.bought_plate.append(k_line_data[0]['sec_name'])
                                                    # 查看一下该股有无大单
                                                    L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                    # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
                                                    for i in data_cache.account_positions_dict:
                                                        # print(i)
                                                        if i['securityID'] == symbol_code:
                                                            # print(i['currentPosition'])
                                                            if i['currentPosition'] == 0:
                                                                logger.info(f"【{i['securityName']}】交易失败~")
                                                            else:
                                                                # 将有概念买入次数自加1
                                                                data_cache.have_small_turn_large_buy_times += 1
                                                                # 将买入个股的当时概念添加到全局变量中存储
                                                                data_cache.bought_plate.extend(k_line_data[0]['sec_name'])
                                                                logger.info(f"【{i['securityName']}】交易成功!")
                                '''
                                昨日涨停视界,今日连板预期盯视界
                                '''
@@ -720,15 +769,3 @@
        # 如果K线数据为空,则不进入后续判断
        # print(f"代码:{symbol},k_line_data is None,未get到该股的K线属性,或为新股、次新股第一天的时候确实没有历史K线")
# 委托状态更新事件
def on_order_status(context, order):
    # 可在后面执行其他处理逻辑
    logger.info(f"买入策略context====t————{context}")
    logger.info(f"买入策略order====t————{order}")
# 委托执行回报事件
def on_execution_report(context, execrpt):
    logger.info(f"买入策略context===={context}")
    logger.info(f"execrpt========{execrpt}")
strategy/index_market_trend_strategy.py
@@ -208,7 +208,7 @@
        it_K_line[0].update(new_properties)
        # 计算大振幅的日期并添加到大振幅日期列表中
        if not (-4 < it_K_line[i]['today_growth'] < 4):
        if not (-1 < it_K_line[i]['today_growth'] < 1):
            large_amplitude_day.append(it_K_line[i]['bob'])
        # 判断K线图形风险位置 及 高低时间点
@@ -282,8 +282,7 @@
            current_count = 0
            start = None
        #  确保不会出现除以零的报错
        if current_yesterday_volume == 0:
            current_yesterday_volume = 1
        if current_yesterday_volume != 0:
            if round(current_today_volume / current_yesterday_volume, 2) > 1.1:
                # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【放量】")
                if current_today_growth > 0:
@@ -307,17 +306,19 @@
                else:
                    it_K_line[i]['today_volume_shape'] = 'decreases_balance'
                    # print(f"i=={i}  {it_K_line[i]['bob']}   【缩量平收】")
        else:
            # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【平量】")
            if current_today_growth > 0:
                it_K_line[i]['today_volume_shape'] = 'remained_up'
                # print(f"i=={i}  {it_K_line[i]['bob']}   【平量上涨】")
            elif current_today_growth < 0:
                it_K_line[i]['today_volume_shape'] = 'remained_down'
                # print(f"i=={i}  {it_K_line[i]['bob']}   【平量下跌】")
            else:
                it_K_line[i]['today_volume_shape'] = 'remained_balance'
                # print(f"i=={i}  {it_K_line[i]['bob']}   【平量平收】")
                # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【平量】")
                if current_today_growth > 0:
                    it_K_line[i]['today_volume_shape'] = 'remained_up'
                    # print(f"i=={i}  {it_K_line[i]['bob']}   【平量上涨】")
                elif current_today_growth < 0:
                    it_K_line[i]['today_volume_shape'] = 'remained_down'
                    # print(f"i=={i}  {it_K_line[i]['bob']}   【平量下跌】")
                else:
                    it_K_line[i]['today_volume_shape'] = 'remained_balance'
                    # print(f"i=={i}  {it_K_line[i]['bob']}   【平量平收】")
        else:
            logger.info(f"{symbol} 的 昨日成交量 为 0,报错!!")
        if current_open - previous_close > 0:
            # print(f"i=={i}  {it_K_line[i]['bob']} 成交总量:{today_volume},,,成交总金额:{today_amount}")
@@ -358,6 +359,7 @@
                # 长期低幅度震荡下跌
                it_K_line[0]['long_term_amplitude'] = 'low_amplitude_oscillation_and_decline'
# 将加入属性值的指数K线下入到本地文件中
def all_index_k_line_dict_write():
    all_index_K_line_dict = get_index_K_line()
strategy/order_methods.py
@@ -51,6 +51,9 @@
        # 调用资金查询函数 查看资金变化
        account_management.finance_management()
        logger.info(f"更新的资金数据data_cache.account_finance_dict=={data_cache.account_finance_dict}")
        if symbol[-6:] in data_cache.account_positions_dict:
            pass
        # 因为上面的更新持仓数据函数会计算 今日新增持仓数量,所以如果再手动新增持仓数据会重复计算【考虑到持仓函数有可能会有延迟,这也可能是同时运行一段时间没有出现BUG的原因,先暂时保留以下这段代码,只是注释】
        # # 买票后添加 持仓代码集合