main.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/index_market_trend_strategy.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/instant_time_market.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/kpl_api.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
main.py
@@ -80,6 +80,9 @@ # 实时检测是否拉取K线线程 threading.Thread(target=lambda: all_K_line.check_time_and_data_date(), daemon=True).start() # print(f"all_stocks_all_K_line_property_dict== {type(data_cache.all_stocks_all_K_line_property_dict)}") # 获取实时大盘指数行情线程 threading.Thread(target=lambda: instant_time_market.index_market_current(), daemon=True).start() # instant_time_market.index_market_trend() # 开盘啦的涨停概念的回调函数 def kpl_limit_up_process(datas): strategy/index_market_trend_strategy.py
New file @@ -0,0 +1,66 @@ """ 该模块下进行指数行情策略的编写 """ # import decimal import datetime from log_module.log import logger_common # import time # 引入掘金API # from gm.api import * from strategy import basic_methods from strategy import data_cache # import account_management from strategy import order_methods # 获取logger实例 logger = logger_common # 指数行情策略函数 def instant_trend_strategy(current_info): len_current_info = len(current_info) if current_info is not None and len_current_info > 0: print(f"current_info------------{current_info}") # 上证指数数据 Shanghai_index_data = current_info.get('000001') Shanghai_index = Shanghai_index_data[0] # 上证指数 Shanghai_index_volume = Shanghai_index_data[1] # 上证指数 当日当时成交量 Shanghai_index_turnover = Shanghai_index_data[2] # 上证指数 当日当时成交额度 print( f"上证 指数------------{Shanghai_index}" f"上指 成交量------------{Shanghai_index_volume}" f"上指 成交额------------{Shanghai_index_turnover}" ) # 深证指数数据 Shenzhen_index_data = current_info.get('399001') Shenzhen_index = Shenzhen_index_data[0] # 深证指数 Shenzhen_index_volume = Shenzhen_index_data[1] # 深证指数 当日当时成交量 Shenzhen_index_turnover = Shenzhen_index_data[2] # 深证指数 当日当时成交额度 print( f"深证 指数------------{Shenzhen_index}" f"深证 成交量------------{Shenzhen_index_volume}" f"深证 成交额------------{Shenzhen_index_turnover}" ) # 创业板指数数据 TSXV_index_data = current_info.get('399006') TSXV_index = TSXV_index_data[0] # 创业板指 TSXV_index_volume = TSXV_index_data[1] # 创业板指 当日当时成交量 TSXV_index_turnover = TSXV_index_data[2] # 创业板指 当日当时成交额度 print( f"创业板 指数------------{TSXV_index}" f"创业板指 成交量------------{TSXV_index_volume}" f"创业板指 成交额------------{TSXV_index_turnover}" ) # 调用涨幅公式计算对应的股票tick瞬时涨幅 Shanghai_tick_growth = basic_methods.calculate_growth('000001', Shanghai_index) print(f"Shanghai_tick_growth ==== {Shanghai_tick_growth}") # 调用涨幅公式计算对应的股票tick瞬时涨幅 Shenzhen_tick_growth = basic_methods.calculate_growth('399001', Shanghai_index) print(f"Shenzhen_tick_growth ==== {Shenzhen_tick_growth}") # 调用涨幅公式计算对应的股票tick瞬时涨幅 TSXV_tick_growth = basic_methods.calculate_growth('399006', Shanghai_index) print(f"TSXV_tick_growth ==== {TSXV_tick_growth}") strategy/instant_time_market.py
@@ -12,8 +12,8 @@ from strategy import l1_data_api from strategy import data_cache from strategy import basic_methods from strategy import buying_strategy from strategy import selling_strategy from strategy import buying_strategy, selling_strategy, index_market_trend_strategy # from low_suction.shared_memory_util import SharedMemoryObj # 获取logger实例 @@ -22,31 +22,22 @@ ''' 创建一个函数来对主要指数的实时行情作处理 ''' 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}") # 获取实时指数行情函数 def index_market_current(): logging.info(f"index_market_trend进入") while True: try: # 在data_cache中获取到推送过来的实时指数行情数据 stock_index_dict = data_cache.stock_index_dict now_time = datetime.datetime.now().strftime("%H:%M:%S") if len(stock_index_dict) == 0 and now_time > data_cache.L1_data_start_time: print(f"9:15后 实时指数数据为空=stock_index_dict===={stock_index_dict}") index_judge_thread_manager(stock_index_dict) except Exception as error: logging.exception(error) finally: time.sleep(0.5) """ @@ -58,13 +49,20 @@ 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 # 调用以指数行情信息为核心策略的函数 def index_judge_thread_manager(index_market_info): if index_market_info is not None: # 调用交易策略模块中的涨幅视界策略 # 指数行情调用 index_market_trend_strategy.instant_trend_strategy(index_market_info) # 生成所有个股的开盘价字典 def get_all_stocks_current_open(current_infos): @@ -263,44 +261,7 @@ else: return None # def process_current_infos(): # """ # 处理现价 # :param current_infos: # :return: # """ # while True: # try: # now_start = time.time() # current_infos = l1_data_api.get_current_info() # now_time = datetime.datetime.now().strftime("%H:%M:%S") # if len(current_infos) == 0 and now_time > data_cache.L1_data_start_time: # print(f"9:15后 l1数据为空=l1_data_current_infos===={current_infos}") # for i in current_infos: # if i[0] == '000001': # print(f"i===={i}") # # # get_all_stocks_current_open(current_infos) # get_all_stocks_current_high_and_low(current_infos) # for current_info in current_infos: # try: # if current_info is not None: # strategic_thread_manager(current_info) # except Exception as error: # logging.exception(error) # print("异常:", current_info) # now_end: float = time.time() # start_to_end = now_end - now_start # print(f"运行中=={round(start_to_end, 2)} 秒") # # logger.info(f"运行中=={round(start_to_end, 2)}秒") # except Exception as error: # logging.exception(error) # finally: # time.sleep(0.5) # 获取当前L1行情数据 def get_current_info(): logging.info(f"get_current_info进入") # shm = SharedMemoryObj(name="l1_data_shared_memory", size=5 * 1024 * 1024) strategy/kpl_api.py
@@ -695,7 +695,7 @@ print(f"写入精选板块文件完成!::{now_time}") # 获取实时大盘行情情绪综合强度 [分数] 函数 # 获取实时大盘行情情绪综合强度 [分数] 函数 并 计算当日计划持仓数量 def get_real_time_market_strong(): while True: try: @@ -703,35 +703,24 @@ # 初始化分时市场情绪分数列表数据列表 time_sharing_market_strong_dirt = {} now = datetime.datetime.now() # 获取本机时间 # 获取大盘综合强度分数 data_cache.real_time_market_strong = get_market_strong() # data_cache.time_sharing_market_strong_dirt = time_sharing_market_strong_dirt.update({now: data_cache.real_time_market_strong}) logger.info(f"大盘行情情绪综合强度 [分数]==={data_cache.real_time_market_strong}分") usefulMoney = data_cache.account_finance_dict[0].get('usefulMoney', 0) logger.info(f"账户可用资金==={usefulMoney}元") # 机械版 # if data_cache.real_time_market_strong >= 70: # data_cache.have_plate_buy_money = 30000 # data_cache.have_strength_buy_money = 30000 # elif 60 <= data_cache.real_time_market_strong < 70: # data_cache.have_plate_buy_money = 20000 # data_cache.have_strength_buy_money = 20000 # elif 50 <= data_cache.real_time_market_strong < 60: # data_cache.have_plate_buy_money = 10000 # data_cache.have_strength_buy_money = 10000 # elif 30 <= data_cache.real_time_market_strong < 50: # data_cache.have_plate_buy_money = 3000 # data_cache.have_strength_buy_money = 3000 # elif data_cache.real_time_market_strong < 30: # data_cache.have_plate_buy_money = 1000 # data_cache.have_strength_buy_money = 1000 # 低迷情绪比例 low_emotion_mood_emotion = 1 if data_cache.real_time_market_strong <= 33: low_emotion_mood_emotion = 0.1 # 获取计算今天新增的持仓数量 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 = (usefulMoney / Unfinished_opening_plan_number) * (data_cache.real_time_market_strong * 0.01) # (账户可用金额/今日最大新增持仓票数) * (大盘综合强度分数 * 0.01) data_cache.today_planned_order_amount = (usefulMoney * low_emotion_mood_emotion / Unfinished_opening_plan_number) * (data_cache.real_time_market_strong * 0.01) logger.info(f"低迷情绪比例===={low_emotion_mood_emotion}") except Exception as error: logger.error(f"获取实时大盘行情情绪综合强度[分数] 函数报错: {error}") finally: