strategy/basic_methods.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/buying_strategy.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/index_market_trend_strategy.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/instant_time_market.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/kpl_api.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/selling_strategy.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
strategy/basic_methods.py
@@ -53,28 +53,28 @@ # print(f"open_growth=={open_growth}") # 计算瞬时涨幅公式 # 初始化历史价格 price_history = {} # # 计算瞬时涨幅公式 # # 初始化历史价格 # price_history = {} # # # def calculate_growth(symbol, price): # try: # if symbol not in price_history: # return 0 # 不足两个历史价格,无法计算涨幅 # last_price = price_history[symbol] # # print(f"price_history[symbol]~~~~~~~~~{price_history[symbol]}") # if last_price != 0: # growth = (price - last_price) / last_price * 100 # 计算涨幅百分比 # return growth # finally: # price_history[symbol] = price # # print(f"price======={price}") # # print(f"price_history=={price_history}") # # print(f"price_history[symbol]=={price_history[symbol]}") def calculate_growth(symbol, price): try: if symbol not in price_history: return 0 # 不足两个历史价格,无法计算涨幅 last_price = price_history[symbol] # print(f"price_history[symbol]~~~~~~~~~{price_history[symbol]}") if last_price != 0: growth = (price - last_price) / last_price * 100 # 计算涨幅百分比 return growth finally: price_history[symbol] = price # print(f"price======={price}") # print(f"price_history=={price_history}") # print(f"price_history[symbol]=={price_history[symbol]}") # 计算tick涨幅公式【为卖出策略单独创建函数】 # # 计算瞬时间隔涨幅公式【为卖出策略单独创建函数】 # 初始化历史价格 history_price = {} strategy/buying_strategy.py
@@ -125,7 +125,7 @@ # print(f"current_created_at type====={type(current_created_at)}") # 调用涨幅公式计算对应的股票tick瞬时涨幅 tick_growth = basic_methods.calculate_growth(symbol, current_price) tick_growth = basic_methods.tick_growth(symbol, current_price) # 在字典K线下的查询当前个股的K线并赋值以便使用 k_line_data = data_cache.all_stocks_all_K_line_property_dict.get(symbol, None) if k_line_data is not None: strategy/index_market_trend_strategy.py
@@ -28,33 +28,36 @@ Shanghai_index = Shanghai_index_data[0] # 上证指数 Shanghai_index_volume = round(Shanghai_index_data[1]/100000000, 2) # 上证指数 当日当时成交量 Shanghai_index_turnover = round(Shanghai_index_data[2]/100000000, 2) # 上证指数 当日当时成交额度 # print( # f"上证 指数------------{Shanghai_index} 成交量------------{Shanghai_index_volume}亿 手 成交额------------{Shanghai_index_turnover}亿 元" # ) Shanghai_Yesterday_closing_index = round(Shanghai_index_data[3], 2) # 上证指数 昨日收盘指数 logger.info(f"上证 指数:{Shanghai_index} 昨日收盘指数:{Shanghai_Yesterday_closing_index} 成交量------------{Shanghai_index_volume}亿 手 成交额------------{Shanghai_index_turnover}亿 元") # 深证指数数据 Shenzhen_index_data = current_info.get('399001') Shenzhen_index = Shenzhen_index_data[0] # 深证指数 Shenzhen_index_volume = round(Shenzhen_index_data[1]/100000000, 2) # 深证指数 当日当时成交量 Shenzhen_index_turnover = round(Shenzhen_index_data[2]/100000000, 2) # 深证指数 当日当时成交额度 # print( # f"深证 指数------------{Shenzhen_index} 成交量------------{Shenzhen_index_volume}亿 手 成交额------------{Shenzhen_index_turnover}亿 元" # ) Shenzhen_Yesterday_closing_index = round(Shenzhen_index_data[3], 2) # 深证指数 昨日收盘指数 logger.info(f"深证 指数:{Shenzhen_index} 昨日收盘指数:{Shenzhen_Yesterday_closing_index} 成交量------------{Shenzhen_index_volume}亿 手 成交额------------{Shenzhen_index_turnover}亿 元") # 创业板指数数据 TSXV_index_data = current_info.get('399006') TSXV_index = TSXV_index_data[0] # 创业板指 TSXV_index_volume = round(TSXV_index_data[1]/100000000, 2) # 创业板指 当日当时成交量 TSXV_index_turnover = round(TSXV_index_data[2]/100000000, 2) # 创业板指 当日当时成交额度 # print( # f"创业板 指数------------{TSXV_index} 成交量------------{TSXV_index_volume}亿 手 成交额------------{TSXV_index_turnover}亿 元" # ) # # 调用涨幅公式计算对应的股票tick瞬时涨幅 # Shanghai_tick_growth = basic_methods.calculate_growth('000001', Shanghai_index) # print(f"Shanghai_tick_growth ==== {round(Shanghai_tick_growth, 4)}") # # 调用涨幅公式计算对应的股票tick瞬时涨幅 # Shenzhen_tick_growth = basic_methods.calculate_growth('399001', Shanghai_index) # print(f"Shenzhen_tick_growth ==== {round(Shenzhen_tick_growth, 4)}") # # 调用涨幅公式计算对应的股票tick瞬时涨幅 # TSXV_tick_growth = basic_methods.calculate_growth('399006', Shanghai_index) # print(f"TSXV_tick_growth ==== {round(TSXV_tick_growth, 4)}") TSXV_Yesterday_closing_index = round(TSXV_index_data[3], 2) # 深证指数 昨日收盘指数 logger.info(f"创业板 指数:{TSXV_index} 昨日收盘指数:{TSXV_Yesterday_closing_index} 成交量------------{TSXV_index_volume}亿 手 成交额------------{TSXV_index_turnover}亿 元") # 调用涨幅公式计算对应的股票tick瞬时涨幅 Shanghai_tick_growth = basic_methods.tick_growth('000001', Shanghai_index) Shanghai_today_growth = basic_methods.intraday_growth(Shanghai_index, Shanghai_Yesterday_closing_index) logger.info(f"上证指数 瞬时涨幅 ---- {round(Shanghai_tick_growth, 4)}%") logger.info(f"上证指数 今日涨幅 ==== {round(Shanghai_today_growth, 4)}%") # 调用涨幅公式计算对应的股票tick瞬时涨幅 Shenzhen_tick_growth = basic_methods.tick_growth('399001', Shanghai_index) Shenzhen_today_growth = basic_methods.intraday_growth(Shenzhen_index, Shenzhen_Yesterday_closing_index) logger.info(f"深证指数 瞬时涨幅 ---- {round(Shenzhen_tick_growth, 4)}%") logger.info(f"深证指数 今日涨幅 ==== {round(Shenzhen_today_growth, 4)}%") # 调用涨幅公式计算对应的股票tick瞬时涨幅 TSXV_tick_growth = basic_methods.tick_growth('399006', Shanghai_index) TSXV_today_growth = basic_methods.intraday_growth(TSXV_index, TSXV_Yesterday_closing_index) logger.info(f"创业板指 瞬时涨幅 ---- {round(TSXV_tick_growth, 4)}%") logger.info(f"创业板指 今日涨幅 ==== {round(TSXV_today_growth, 4)}%") strategy/instant_time_market.py
@@ -32,13 +32,13 @@ # 在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: if len(stock_index_dict) == 0 and data_cache.L1_data_start_time < now_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) time.sleep(1) """ strategy/kpl_api.py
@@ -703,27 +703,28 @@ while True: try: if data_cache.position_automatic_management_switch is True: # 初始化分时市场情绪分数列表数据列表 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}元") # 低迷情绪比例 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 * low_emotion_mood_emotion / Unfinished_opening_plan_number) * (data_cache.real_time_market_strong * 0.01) logger.info(f"低迷情绪比例===={low_emotion_mood_emotion}") now_time = datetime.datetime.now().strftime("%H:%M:%S") if data_cache.server_restart_time < now_time < data_cache.update_data_time: # 获取大盘综合强度分数 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}元") # 低迷情绪比例 low_emotion_mood_emotion = 1 if data_cache.real_time_market_strong <= 33: low_emotion_mood_emotion = 0.1 logger.info(f"低迷情绪比例===={low_emotion_mood_emotion}") # 获取计算今天新增的持仓数量 addition_position_number = len(data_cache.addition_position_symbols_set) # 定义一个今日的剩余新增持仓数量的变量 Unfinished_opening_plan_number = 3 - addition_position_number if Unfinished_opening_plan_number != 0: # 根据账户可用金额 计算今日计划下单金额 # (账户可用金额/今日最大新增持仓票数) * (大盘综合强度分数 * 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) except Exception as error: logger.error(f"获取实时大盘行情情绪综合强度[分数] 函数报错: {error}") finally: strategy/selling_strategy.py
@@ -376,7 +376,7 @@ order_methods.sell_order_by_part_volume(0.1, symbol, position_volume_yesterday, current_price, k_line_data[0]['sec_name'], index) if tick_growth < -0.1 and today_growth < 0 and current_price <= current_low: if tick_growth < -1 and today_growth < 0 and current_price <= current_low: logger.info( f"【开盘临机】【浮动盈亏当前亏】【瞬时跌幅 <-1%】【当日当时涨幅 <0%】【当日新低】【{k_line_data[0]['sec_name']}】,设定委卖数量【全仓】,【瞬时跌幅:{round(tick_growth, 2)}%】,当日当时涨幅:{today_growth}。最新价::{current_price},昨日收盘价:{k_line_data[0]['close']}") order_methods.sell_order_by_part_volume(1, symbol, position_volume_yesterday, @@ -422,7 +422,7 @@ current_price, k_line_data[0]['sec_name'], index) if tick_growth < -0.1 and today_growth < 0 and current_price <= current_low: if tick_growth < -1 and today_growth < 0 and current_price <= current_low: logger.info( f"【开盘临机】【浮动盈亏当前亏】【瞬时跌幅 <-1%】【当日当时涨幅小于0%】【当日新低】【{k_line_data[0]['sec_name']}】,设定委卖数量【全仓】,【瞬时跌幅:{round(tick_growth, 2)}%】,当日当时涨幅:{today_growth}。最新价::{current_price},昨日收盘价:{k_line_data[0]['close']}") order_methods.sell_order_by_part_volume(1, symbol,