admin
2025-02-24 58f36a5e3fde42f3290c8ec871de9e9929ba26d1
bug修改
4个文件已修改
98 ■■■■■ 已修改文件
strategy/account_management.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/data_cache.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/instant_time_market.py 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/kpl_api.py 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/account_management.py
@@ -25,11 +25,11 @@
    if account_finance is not None and account_finance['code'] == 0:
        data_cache.account_finance_dict = account_finance['data']
        logger.info(f"data_cache.account_finance_dict==={data_cache.account_finance_dict}")
        usefulMoney = data_cache.account_finance_dict[0]['usefulMoney']  # 可用资金
        data_cache.usefulMoney = data_cache.account_finance_dict[0]['usefulMoney']  # 可用资金
        frozenCash = data_cache.account_finance_dict[0]['frozenCash']  # 冻结的资金
        fetchLimit = data_cache.account_finance_dict[0]['fetchLimit']  # 可取资金
        preDeposit = data_cache.account_finance_dict[0]['preDeposit']  # 上日结存
        print(f"可用资金==={usefulMoney}")
        print(f"可用资金==={data_cache.usefulMoney}")
        print(f"冻结的资金==={frozenCash}")
        print(f"可取资金==={fetchLimit}")
        print(f"上日结存==={preDeposit}")
strategy/data_cache.py
@@ -180,6 +180,8 @@
# 为当前账户全部【资金信息】创建字典
account_finance_dict = {}
# 为当前账户可用资金创建一个变量
usefulMoney = 0
# 为当前账户全部【持仓信息】创建列表
account_positions_dict = {}
# 为持仓代码创建一个初始集合
strategy/instant_time_market.py
@@ -6,8 +6,7 @@
import time
import datetime
import utils
# 引入掘金API
from utils import huaxin_util
# 引入华鑫API(小辉整理)
from strategy import l1_data_api
from strategy import data_cache
@@ -20,58 +19,38 @@
# 获取logger实例
logger = get_logger()
# 获取tick数据
def on_tick(context, tick):
    pass
    __process(context, tick)
    print(f"启动on_tick")
    print(f"tick-===={tick}")
# 驱动调用所有以current数据为核心策略的函数
def __process(context, current_data):
    pass
    # print(f"current_data===={current_data}")
    # 调用交易策略模块中的涨幅视界策略
    # buying_strategy.growth_horizon_strategy(context, current_data)
    # selling_strategy.instantaneous_increase_strategy(context, current_data)
#
# # 获取掘金current数据
# def get_current_data():
#     logging.info(f"get_current_data进入")
#     while True:
#         try:
#             now_start = time.time()
#             current_datas = current(symbols=data_cache.DataCache().min_stocks,
#                                     fields='open,high,low,symbol,price,created_at,cum_volume,cum_amount,last_volume,quotes')
#             # current_datas = l1_data_api.get_current_info()
#             # print(f"l1_data_current_datas===={current_datas}")
#             # print(f"current_datas====={current_datas}")
#             now_end = time.time()
#             now_start_to_end = now_end - now_start
#             # index = 0
#             for current_data in current_datas:
#                 # index+=1
#                 try:
#                     __process(data_cache.context, current_data)
#                     # if index == 100:
#                     #     print(current_data)
#                     # print(f"第几个{index}")
#                 except Exception as error:
#                     logging.exception(error)
#                     print("异常:", current_data)
#             print(f"运行中=={round(now_start_to_end, 2)}秒")
#             # logger.info(f"运行中=={round(now_start_to_end, 2)}秒")
#         except Exception as error:
#             logging.exception(error)
#         finally:
#             time.sleep(1)
'''
创建一个函数来对主要指数的实时行情作处理
'''
def index_market_trend(current_info):
    if current_info is not None:
        pass
        # 设定当前时间点
        # now_time = datetime.datetime.now().strftime("%H:%M:%S")
        symbol_code = current_info[0]  # 券商接口为纯数字编号
        symbol = basic_methods.format_stock_symbol(symbol_code)  # 掘金数据来源的股票代码
        # symbol_code = symbol.split('.')[1]  # 将掘金格式的股票代码转化为纯数字类型
        # pre_close = current_info[1]  # 昨日收盘价
        current_price = current_info[2]  # 获取当前最新价
        current_open = get_symbol_current_open(symbol)  # 当日开盘价
        current_high = get_symbol_current_high(symbol)  # 当日当时最高价
        current_low = get_symbol_current_low(symbol)  # 当日当时最低价
        current_volume = current_info[3]  # 当日当时的总成交量
        # current_last_volume = update_symbol_volume(symbol, current_volume)  # 获取瞬时交易量
        # current_amount = current_info[4]  # 当日当时的总成交额
        current_quotes_buy = current_info[5]  # 买5档数据
        current_quotes_sell = current_info[6]  # 卖5档数据
        # current_quotes_buy == [[23.25, 800], [23.24, 1100], [23.23, 1100], [23.22, 2200], [23.21, 2300]]
        # current_quotes_sell == [[23.27, 500], [23.29, 200], [23.3, 6900], [23.31, 500], [23.32, 200]]
        current_created_at = current_info[7]  # 当前信息创建时间
        if type(current_created_at) == int:
            current_created_at = huaxin_util.convert_time(current_created_at)
        if symbol_code == '000001':
            print(f"000001   current_price==={current_price}")
"""
另外创建一个线程来驱动拉取华鑫l1数据 给各个策略模块
创建一个线程来驱动拉取华鑫l1数据 给各个策略模块
"""
@@ -79,7 +58,11 @@
def strategic_thread_manager(current_info):
    if current_info is not None:
        # 调用交易策略模块中的涨幅视界策略
        # 指数行情调用
        # 买入策略调用
        buying_strategy.growth_view_strategy(current_info)
        # 卖出策略调用
        selling_strategy.instantaneous_change_strategy(current_info)
        # pass
strategy/kpl_api.py
@@ -728,10 +728,13 @@
                #     data_cache.have_plate_buy_money = 1000
                #     data_cache.have_strength_buy_money = 1000
                # 获取计算今天新增的持仓数量
                addition_position_number = len(data_cache.addition_position_symbols_set)
                # 定义一个今日的剩余新增持仓数量的变量
                Unfinished_opening_plan_number = 3 - addition_position_number
                # 根据账户可用金额 计算今日计划下单金额
                # (账户可用金额/今日最大新增持仓票数) * (大盘综合强度份数 * 0.01)
                # data_cache.today_planned_order_amount = (200000 / 3) * (data_cache.real_time_market_strong * 0.01)  # 测试是不是可用资金没有更新的原因
                data_cache.today_planned_order_amount = (usefulMoney / 3) * (data_cache.real_time_market_strong * 0.01)
                data_cache.today_planned_order_amount = (usefulMoney / Unfinished_opening_plan_number) * (data_cache.real_time_market_strong * 0.01)
        except Exception as error:
            logger.error(f"获取实时大盘行情情绪综合强度[分数] 函数报错: {error}")
        finally: