| | |
| | | from strategy.strategy_variable_factory import DataLoader, StrategyVariableFactory |
| | | import constant |
| | | from third_data import kpl_util |
| | | from trade.trade_manager import DealCodesManager |
| | | from trade.trade_manager import DealCodesManager, PlatePlaceOrderManager |
| | | from utils import huaxin_util, tool |
| | | |
| | | |
| | |
| | | """ |
| | | |
| | | def __init__(self, day, script_name="strategy_script_v6.py", |
| | | settings=StrategyParamsSettingsManager().get_settings(), need_load_data = False): |
| | | 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 = {} |
| | | # 今日数据 |
| | |
| | | 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: |
| | | """ |
| | | big_orders = [x for x in big_orders if x[0] in self.fcodes] |
| | | codes = [] |
| | | for d in big_orders: |
| | | try: |
| | |
| | | self.big_order_sell[code].append(d[2]) |
| | | if code not in codes: |
| | | codes.append(code) |
| | | # 设置现价 |
| | | if code in self.stock_variables_dict: |
| | | self.stock_variables_dict[code].当前价 = d[2][4] |
| | | except Exception as e: |
| | | logger_debug.error(f"{d}") |
| | | # 驱动下单 |
| | |
| | | # 注入板块流入信息 |
| | | if self.current_block_in_datas: |
| | | sv.资金流入板块 = self.current_block_in_datas |
| | | # 注入已成交代码 |
| | | place_order_plate_codes = DealCodesManager().get_place_order_plate_codes() |
| | | # 注入已成交代码,成交代码以委托数据来计算 |
| | | place_order_plate_codes = PlatePlaceOrderManager().get_plate_codes() |
| | | sv.板块成交代码 = place_order_plate_codes |
| | | sv.成交代码 = DealCodesManager().get_deal_codes() |
| | | |
| | | code_sets = [set(lst) for lst in place_order_plate_codes.values()] |
| | | # 2. 使用 set.union() 求并集 |
| | | union_code_sets = set().union(*code_sets) |
| | | sv.成交代码 = union_code_sets |
| | | global_dict = { |
| | | "sv": sv, |
| | | "target_code": code, |
| | |
| | | return |
| | | # 可以下单 |
| | | # 判断是否可以买 |
| | | order_ref = huaxin_util.create_order_ref() |
| | | price = tool.get_buy_max_price(sv.当前价) |
| | | volume = 100 |
| | | DealCodesManager().place_order(set(compute_result[3]), code, order_ref, price, volume) |
| | | for b in compute_result[3]: |
| | | DealCodesManager().place_order(b, code) |
| | | async_log_util.info(logger_trade, f"{code}下单,板块:{compute_result[3]}") |
| | | |
| | | |