| | |
| | | from db import redis_manager_delegate as redis_manager |
| | | 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 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="低吸脚本_辨识度_v6.py", settings=StrategyParamsSettingsManager().get_settings()): |
| | | def __init__(self, day, script_name="strategy_script_v6.py", |
| | | settings=StrategyParamsSettingsManager().get_settings(), need_load_data = False): |
| | | self.now_day = day |
| | | # 买大单:{代码:[大单数据]} |
| | | self.big_order_buy = {} |
| | |
| | | self.current_block_in_datas = [] |
| | | |
| | | # 加载策略脚本文件 |
| | | with open(script_name if constant.is_windows() else f'{constant.get_path_prefix()}/{script_name}', mode='r', encoding='utf-8') as f: |
| | | with open(script_name if constant.is_windows() else f'{constant.get_path_prefix()}/{script_name}', mode='r', |
| | | encoding='utf-8') as f: |
| | | lines = f.readlines() |
| | | scripts = "\n".join(lines) |
| | | # 注释掉里面的import与变量 |
| | |
| | | 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): |
| | | # 加载历史数据 |
| | |
| | | """ |
| | | if code_ in self.stock_variables_dict: |
| | | 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) |
| | |
| | | @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_sell: |
| | | self.big_order_sell[code] = [] |
| | | self.big_order_sell[code].append(d[2]) |
| | | # 驱动下单 |
| | | if code not in codes: |
| | | codes.append(code) |
| | | # 驱动下单 |
| | | 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) |
| | |
| | | # 判断是否可以买 |
| | | for b in compute_result[3]: |
| | | DealCodesManager().place_order(b, code) |
| | | async_log_util.info(logger_trade, f"{code}下单,板块:{compute_result[3]}") |
| | | |
| | | |
| | | # 当前的低吸策略对象 |
| | | low_suction_strtegy = LowSuctionStrategy(tool.get_now_date_str()) |
| | | low_suction_strtegy = None |