| | |
| | | |
| | | from db import redis_manager_delegate as redis_manager, mysql_data_delegate as mysql_data |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import log_export |
| | | from log_module.log import hx_logger_l2_transaction, logger_debug, logger_request_api |
| | | from strategy import data_cache |
| | | from strategy.trade_setting import TradeSetting |
| | |
| | | response_data = json.dumps(result) |
| | | except Exception as e: |
| | | response_data = json.dumps({"code": 1, "msg": str(e)}) |
| | | elif url.path == "/get_kpl_stock_of_markets_plate": |
| | | # 获取开盘啦流入板块详细信息 |
| | | time_str = params_dict.get("time") |
| | | if not time_str: |
| | | time_str = tool.get_now_time_str() |
| | | datas = log_export.load_stock_of_markets_plate() |
| | | fdatas = [] |
| | | for data in datas: |
| | | # (发生时间,[净流入板块], {"板块":(代码, 名称, 涨幅)}) |
| | | fdatas.append((data[0], [x[1] for x in data[1][0]], |
| | | {p: [(xx[0], xx[1], xx[6]) for xx in data[1][1][p]] for p in data[1][1]})) |
| | | response_data = json.dumps({"code": 1, "msg": "暂无内容"}) |
| | | for i in range(len(fdatas) - 1, -1, -1): |
| | | if fdatas[i][0] <= time_str: |
| | | response_data = json.dumps({"code": 0, "data": fdatas[i]}) |
| | | break |
| | | elif url.path == "/get_kpl_market_strong_records": |
| | | # 获取开盘啦市场强度记录 |
| | | time_str = params_dict.get("time") |
| | | if not time_str: |
| | | time_str = tool.get_now_time_str() |
| | | datas = log_export.load_kpl_market_strong() |
| | | fdatas = [] |
| | | for data in datas: |
| | | # (距离09:15:00的秒数, 时间, 强度) |
| | | fdatas.append((tool.trade_time_sub(data[0], "09:15:00"), data[0], data[1])) |
| | | response_data = json.dumps({"code": 0, "data": fdatas}) |
| | | |
| | | self.send_response(200) |
| | | # 发给请求客户端的响应数据 |
| | |
| | | pass |
| | | return fdatas |
| | | |
| | | |
| | | def load_kpl_market_strong(date=tool.get_now_date_str()): |
| | | """ |
| | | 获取开盘啦历史强度 |
| | | :param date: |
| | | :return: [("时间","分数")] |
| | | """ |
| | | path = f"{constant.get_path_prefix()}/low_suction_log/gp/kpl/Overall_market_strength_score.{date}.log" |
| | | fdatas = [] |
| | | if os.path.exists(path): |
| | | with open(path, 'r', encoding="utf-8") as f: |
| | | lines = f.readlines() |
| | | for line in lines: |
| | | if line: |
| | | time_str = __get_async_log_time(line) |
| | | try: |
| | | data = line.split(" - ")[1].strip() |
| | | if data.startswith("["): |
| | | data = data[data.find("]") + 1:].strip() |
| | | fdatas.append((time_str, int(data))) |
| | | except: |
| | | pass |
| | | return fdatas |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | load_stock_of_markets_plate() |
| | | datas = load_kpl_market_strong() |
| | | fdatas = [] |
| | | for data in datas: |
| | | # (距离09:15:00的秒数, 时间, 强度) |
| | | if "11:30:00"<= data[0]<="13:00:00": |
| | | continue |
| | | fdatas.append([tool.trade_time_sub(data[0], "09:15:00"), data[0], data[1]]) |
| | | print(fdatas) |
| | |
| | | 账户管理模块【管理账户下面的资金管理方法及仓位管理方法等】 |
| | | """ |
| | | from log_module.log import logger_common |
| | | # import time |
| | | # import datetime |
| | | # import decimal |
| | | from trade import huaxin_trade_api |
| | | |
| | | # import logging |
| | | # import threading |
| | | # 引入全局变量模块 |
| | | from strategy import data_cache |
| | | |
| | |
| | | logger.info(f"冻结的资金==={frozenCash}") |
| | | logger.info(f"可取资金==={fetchLimit}") |
| | | logger.info(f"上日结存==={preDeposit}") |
| | | |
| | | |
| | | # finance_management() |
| | | |
| | | # 构造循环请求资金管理线程 |
| | | # def finance_management_process(): |
| | | # while True: |
| | | # try: |
| | | # # now_start = time.time() |
| | | # # print(f"finance_management开始{now_start}") |
| | | # finance_management() |
| | | # # now_end = time.time() |
| | | # # print(f"finance_management完成一下{now_end}") |
| | | # except Exception as error: |
| | | # print(f"获取资金管理线程报错An error occurred: {error}") |
| | | # finally: |
| | | # time.sleep(1) |
| | | |
| | | |
| | | # 仓位管理函数 |
| | |
| | | logger.info( |
| | | f"今日新增持仓数量====================================【{len(data_cache.addition_position_symbols_set)}】") |
| | | |
| | | # position_management() |
| | | |
| | | # # 构造循环请求仓位管理线程 |
| | | # def position_management_process(): |
| | | # while True: |
| | | # try: |
| | | # # now_start = time.time() |
| | | # # print(f"position_management开始{now_start}") |
| | | # position_management() |
| | | # # now_end = time.time() |
| | | # # print(f"position_management完成一下{now_end}") |
| | | # except Exception as error: |
| | | # print(f"获取仓位管理线程报错An error occurred: {error}") |
| | | # finally: |
| | | # time.sleep(1) |
| | |
| | | if current_volume < k_line_data[0]['volume'] * ratios: |
| | | logger.info( |
| | | f"【不利】今日成交量 < 昨日的{ratios}倍,不买!!公司名称:{k_line_data[0]['sec_name']},今日目前成交量为昨日的{round(current_volume / k_line_data[0]['volume'], 2)}") |
| | | elif buying_strong is not True and current_volume <= k_line_data[0][ |
| | | 'volume'] * ratios and now_time > data_cache.MORN_MARKET_TIME: |
| | | elif buying_strong is not True and current_volume <= k_line_data[0]['volume'] * ratios and now_time > data_cache.MORN_MARKET_TIME: |
| | | logger.info( |
| | | f"【不利】买一量小于卖一量 且 挂买总量小于挂卖总量 且 当日量不足 (9:35后实施)!不买!!公司名称:{k_line_data[0]['sec_name']},自由市值:{free_market_value} 亿,最新价: {current_price}") |
| | | # logger.info( |
| | |
| | | # print(f"非ST, 退市, 退, XD, N==={basic_info['sec_name']} 继续判断") |
| | | no_k_line_stocks.append(i['symbol']) |
| | | # 将列表推导式移出循环 过滤出昨日收盘价在2-30元的股票 |
| | | min_instruments = [stock for stock in instruments if 2 < stock['pre_close'] < 30] |
| | | min_instruments = [stock for stock in instruments if 3 < stock['pre_close'] < 30] |
| | | # print(f"min_instruments 数量==={len(min_instruments)}") |
| | | # 使用 get 方法安全地获取 symbol 字段的值 |
| | | self.min_stocks = [stock.get('symbol') for stock in min_instruments if stock.get('symbol') is not None] |
| | |
| | | |
| | | # 大盘指数趋势预期函数(用于对大盘开盘后短期内的趋势预测) |
| | | def index_trend_expectation(): |
| | | index_trend_expectation_score = 0 |
| | | index_trend_expectation_score = 100 |
| | | # 判断三大指数开盘涨幅 预期 |
| | | if data_cache.Shanghai_open_growth > 0 and data_cache.Shenzhen_open_growth > 0 and data_cache.TSXV_open_growth > 0: |
| | | index_composite_open_increase = '三大指数:高开' |
| | |
| | | if len(data_cache.all_index_k_line_property_dict) > 0 or data_cache.all_index_k_line_property_dict is not None: |
| | | logger.info(f"指数带属性K线数据的昨日是否为空:{data_cache.all_index_k_line_property_dict['SHSE.000001'][0]}") |
| | | # print(f"指数带属性K线数据的昨日是否为空:{data_cache.all_index_k_line_property_dict['SHSE.000001'][0]['open']}") |
| | | if index_trend_expectation_score > 100: |
| | | index_trend_expectation_score = 100 |
| | | return index_trend_expectation_score |
| | | |
| | | |
| | |
| | | # logger.info(f"【没有】在集合竞价内启动,采用【掘金数据】记录") |
| | | print(f"【没有】在开盘前内启动,采用【掘金数据】记录 开盘价") |
| | | data_cache.record_current_open_execution = True |
| | | current_datas = utils.juejin_api.JueJinApi.get_codes_open(data_cache.DataCache().filtered_stocks, fields='symbol,open') |
| | | current_datas = utils.juejin_api.JueJinApi.get_codes_open(data_cache.DataCache().min_stocks, fields='symbol,open') |
| | | # print(f"current_datas=={current_datas}") |
| | | for current_data in current_datas: |
| | | # print(f"current_data=={current_data}") |
| | |
| | | # print(f"当前时间更新时间:{now_time}") |
| | | if not __current_high_or_low_dict: |
| | | # 还没初始化 |
| | | # current_datas = current(symbols=data_cache.DataCache().filtered_stocks, fields='symbol,high,low') |
| | | # current_datas = current(symbols=data_cache.DataCache().min_stocks, fields='symbol,high,low') |
| | | current_datas = utils.juejin_api.JueJinApi.get_codes_high_and_low( |
| | | data_cache.DataCache().filtered_stocks, fields='symbol,high,low') |
| | | data_cache.DataCache().min_stocks, fields='symbol,high,low') |
| | | # print(f"current_datas=={current_datas}") |
| | | for current_data in current_datas: |
| | | symbol, high, low = current_data['symbol'], current_data['high'], current_data['low'] |
| | |
| | | for current_info in current_infos: |
| | | # print(f"开始循环current_infos") |
| | | symbol = basic_methods.format_stock_symbol(current_info[0]) |
| | | if symbol not in data_cache.DataCache().filtered_stocks: |
| | | if symbol not in data_cache.DataCache().min_stocks: |
| | | continue |
| | | # if symbol.find("300810") > 0: |
| | | # print(f"开始循环current_infos:"+symbol) |
| | |
| | | # 初始化 |
| | | # current_datas = current(symbols=[symbol], fields='symbol,high,low') |
| | | current_datas = utils.juejin_api.JueJinApi.get_codes_high_and_low( |
| | | data_cache.DataCache().filtered_stocks, fields='symbol,high,low') |
| | | data_cache.DataCache().min_stocks, fields='symbol,high,low') |
| | | current_data = current_datas[0] |
| | | # print(f"开始实例化对象") |
| | | symbol, high, low = current_data['symbol'], current_data['high'], current_data['low'] |
| | |
| | | log_datas[b] = r[b] |
| | | now_time = tool.get_now_time_str() |
| | | if data_cache.L1_DATA_START_TIME < now_time < data_cache.CLOSING_TIME: |
| | | logger.info(f"精选板块股票强度数据更新 == {market_sift_plate_stock_dict}") |
| | | # logger.info(f"精选板块股票强度数据更新 == {market_sift_plate_stock_dict}") |
| | | # 只在盘中时间获取 |
| | | async_log_util.info(logger_stock_of_markets_plate, f"{(market_sift_plate['list'], log_datas)}") |
| | | |
| | |
| | | |
| | | data_cache.index_trend_expectation_score = index_trend_expectation() |
| | | logger.info(f"大盘指数情绪预期分数==={data_cache.index_trend_expectation_score}分") |
| | | # print(f"大盘指数情绪预期分数==={data_cache.index_trend_expectation_score}分") |
| | | # 目前大盘指数情绪预期分数 尚不科学 强制设置为初始0值 |
| | | index_trend_expectation_score = 0 |
| | | |
| | |
| | | # 如果GUI看盘上没有手动设置具体的下单金额,就按照评分策略的金额下单,否则就按照GUI设置的金额下单。 |
| | | if data_cache.BUY_MONEY_PER_CODE < 0: |
| | | # 根据账户可用金额 计算今日计划下单金额 |
| | | # ((大盘综合强度分数 + 大盘指数情绪预期分数) * 0.01) * (账户可用金额 * 极端低迷情绪比例 / 今日最大新增持仓票数) |
| | | data_cache.today_planned_order_amount = (( |
| | | data_cache.real_time_market_strong + index_trend_expectation_score) * 0.01) * ( |
| | | usefulMoney * low_emotion_mood_ratio / Unfinished_opening_plan_number) |
| | | # 账户可用金额 默认乘以0.9,永远留一点钱,一方面也冗余一些计算误差 |
| | | # ((大盘综合强度分数 + 大盘指数情绪预期分数) * 0.01) * (账户可用金额 * 0.9 * 极端低迷情绪比例 / 今日最大新增持仓票数) |
| | | # data_cache.today_planned_order_amount = ((data_cache.real_time_market_strong + index_trend_expectation_score) * 0.01) * ( |
| | | # usefulMoney * 0.9 * low_emotion_mood_ratio / Unfinished_opening_plan_number) |
| | | data_cache.today_planned_order_amount = (index_trend_expectation_score * 0.01) * (usefulMoney * 0.9 * low_emotion_mood_ratio / Unfinished_opening_plan_number) |
| | | else: |
| | | data_cache.today_planned_order_amount = data_cache.BUY_MONEY_PER_CODE |
| | | |