| | |
| | | from db.mysql_data_delegate import Mysqldb |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_trade |
| | | from log_module.log import logger_trade, logger_debug |
| | | from strategy.data_analyzer import KPLLimitUpDataAnalyzer |
| | | from strategy.low_suction_strategy import LowSuctionOriginDataExportManager |
| | | from strategy.strategy_params_settings import StrategyParamsSettingsManager |
| | |
| | | """ |
| | | |
| | | def __init__(self, day, script_name="strategy_script_v6.py", |
| | | settings=StrategyParamsSettingsManager().get_settings()): |
| | | settings=StrategyParamsSettingsManager().get_settings(), need_load_data=False): |
| | | self.now_day = day |
| | | # 买大单:{代码:[大单数据]} |
| | | self.big_order_buy = {} |
| | |
| | | # 历史日K数据 |
| | | self.kline_data = {} |
| | | # 历史涨停数据 |
| | | self.limit_up_record_data = {} |
| | | self.limit_up_record_data_dict = {} |
| | | self.limit_up_record_data_list = {} |
| | | # 历史数据 |
| | | self.timeline_data = {} |
| | | # 今日数据 |
| | |
| | | self.scripts = scripts |
| | | self.settings = settings |
| | | |
| | | self.data_loader = DataLoader(self.now_day, cache_path=f"{constant.get_path_prefix()}/datas") |
| | | self.data_loader = DataLoader(self.now_day) |
| | | self.__LowSuctionOriginDataExportManager = LowSuctionOriginDataExportManager(self.now_day) |
| | | self.load_data() |
| | | if need_load_data: |
| | | self.load_data() |
| | | |
| | | def load_data(self): |
| | | # 加载历史数据 |
| | |
| | | trade_days = self.data_loader.trade_days |
| | | # 加载历史数据 |
| | | self.kline_data = self.data_loader.load_kline_data() |
| | | self.limit_up_record_data = self.data_loader.load_limit_up_data() |
| | | self.limit_up_record_data_list = self.data_loader.load_limit_up_data() |
| | | for d in self.limit_up_record_data_list: |
| | | if d[0] not in self.limit_up_record_data_dict: |
| | | self.limit_up_record_data_dict[d[0]] = [] |
| | | self.limit_up_record_data_dict[d[0]].append(d) |
| | | self.next_trade_day = self.data_loader.load_next_trade_day() |
| | | if not trade_days: |
| | | raise Exception("交易日历获取失败") |
| | | if not self.kline_data: |
| | | raise Exception("历史日K获取失败") |
| | | if not self.limit_up_record_data: |
| | | if not self.limit_up_record_data_list: |
| | | raise Exception("历史涨停获取失败") |
| | | |
| | | def __load_current_date_data_by_timeline(self): |
| | |
| | | return |
| | | stock_variables = StrategyVariableFactory.create_from_history_data( |
| | | self.kline_data.get(code_), None, |
| | | self.limit_up_record_data.get(code_), self.data_loader.trade_days) |
| | | self.limit_up_record_data_dict.get(code_), self.data_loader.trade_days) |
| | | |
| | | # 加载今日涨停价 |
| | | pre_close = self.kline_data.get(code_)[0]["close"] |
| | |
| | | days = self.data_loader.trade_days[:day] |
| | | stock_variables.__setattr__(f"日出现的板块_{day}", |
| | | KPLLimitUpDataAnalyzer.get_limit_up_reasons( |
| | | self.limit_up_record_data, min_day=days[-1], |
| | | self.limit_up_record_data_list, min_day=days[-1], |
| | | max_day=days[0])) |
| | | stock_variables.连续老题材 = KPLLimitUpDataAnalyzer.get_continuous_limit_up_reasons( |
| | | self.limit_up_record_data, self.data_loader.trade_days[:2]) |
| | | self.limit_up_record_data_list, self.data_loader.trade_days[:2]) |
| | | |
| | | # 加载Tick信息 |
| | | open_price_info = TickSummaryDataManager().open_price_info_dict.get(code_) |
| | |
| | | @param big_orders: [(代码, 买/卖, [订单号,量,金额,最后时间戳,最后价格, 初始时间戳, 初始价格])] 如:[ ('002741', 0, [475820, 91600, 1610328, 92500000, 17.58, 92500000, 17.58])] |
| | | @return: |
| | | """ |
| | | codes = [] |
| | | for d in big_orders: |
| | | code = d[0] |
| | | if d[1] == 0: |
| | | # 买单 |
| | | if code not in self.big_order_buy: |
| | | self.big_order_buy[code] = [] |
| | | self.big_order_buy[code].append(d[2]) |
| | | else: |
| | | # 卖单 |
| | | if code not in self.big_order_sell: |
| | | self.big_order_sell[code] = [] |
| | | self.big_order_sell[code].append(d[2]) |
| | | # 驱动下单 |
| | | try: |
| | | code = d[0] |
| | | # 只计算200w以上的买单 |
| | | if d[2][2] < 200e4: |
| | | continue |
| | | if d[1] == 0: |
| | | # 买单 |
| | | if code not in self.big_order_buy: |
| | | self.big_order_buy[code] = [] |
| | | self.big_order_buy[code].append(d[2]) |
| | | else: |
| | | # 卖单 |
| | | if code not in self.big_order_sell: |
| | | self.big_order_sell[code] = [] |
| | | self.big_order_sell[code].append(d[2]) |
| | | if code not in codes: |
| | | codes.append(code) |
| | | except Exception as e: |
| | | logger_debug.error(f"{d}") |
| | | # 驱动下单 |
| | | for code in codes: |
| | | self.__run(code, self.stock_variables_dict.get(code)) |
| | | |
| | | def add_ticks(self, ticks): |
| | | """ |
| | |
| | | self.current_block_in_datas = _block_in_datas |
| | | |
| | | def __run(self, code, sv: StockVariables): |
| | | if not sv: |
| | | return |
| | | # 运行代码 |
| | | # 注入大单 |
| | | sv.今日大单数据 = self.big_order_buy.get(code) |