New file |
| | |
| | | """ |
| | | 自动加想策略 |
| | | """ |
| | | import time |
| | | |
| | | from code_attribute import gpcode_manager, code_nature_analyse |
| | | from code_attribute.code_volumn_manager import CodeVolumeManager |
| | | from log_module.log import logger_debug |
| | | from third_data import kpl_data_manager |
| | | from third_data.history_k_data_manager import HistoryKDataManager |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | | from third_data.kpl_data_constant import LimitUpDataConstant |
| | | from trade import l2_trade_util, trade_record_log_util |
| | | from utils import tool, global_util, init_data_util |
| | | |
| | | |
| | | def run(): |
| | | while True: |
| | | try: |
| | | if not tool.is_trade_time(): |
| | | continue |
| | | excute() |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | finally: |
| | | time.sleep(3) |
| | | |
| | | |
| | | def excute(): |
| | | """ |
| | | 执行自动加想策略 |
| | | @return: |
| | | """ |
| | | codes = LimitUpDataConstant.get_history_limit_up_codes() |
| | | if not codes: |
| | | return |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | |
| | | dates = HistoryKDatasUtils.get_latest_trading_date_cache(5) |
| | | latest_trading_date = None |
| | | if dates: |
| | | latest_trading_date = dates[0] |
| | | |
| | | for code in codes: |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | # 只加首板 |
| | | if limit_up_price < 3 or limit_up_price > 100: |
| | | continue |
| | | if code in yesterday_codes: |
| | | continue |
| | | if l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | continue |
| | | if gpcode_manager.WantBuyCodesManager().is_in_cache(code): |
| | | continue |
| | | limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code) |
| | | if not limit_up_timestamp: |
| | | continue |
| | | limit_up_time = tool.to_time_str(limit_up_timestamp) |
| | | if limit_up_time <= '09:30:00': |
| | | continue |
| | | zylg = global_util.zyltgb_map.get(code) |
| | | if not zylg or zylg < 10e8: |
| | | continue |
| | | volumes_data = HistoryKDataManager().get_history_bars(code, latest_trading_date) |
| | | if not volumes_data: |
| | | continue |
| | | # 6个交易日内股价长得太高 |
| | | if code_nature_analyse.is_price_too_high_in_days(code, volumes_data, limit_up_price)[0]: |
| | | continue |
| | | days_count = 15 |
| | | volumes_data = volumes_data[:days_count] |
| | | max_price = max(volumes_data, key=lambda x: x['high'])['high'] |
| | | if max_price > limit_up_price: |
| | | # 非15日突破 |
| | | continue |
| | | volumes = init_data_util.parse_max_volume_new(code, volumes_data) |
| | | max_volume, max_volume_day = init_data_util.parse_max_volume_in_days(volumes_data, days_count) |
| | | # 最大量,今日量 |
| | | today_volume = CodeVolumeManager().get_today_volumn_cache(code) |
| | | if today_volume / max_volume < 0.3: |
| | | continue |
| | | logger_debug.info("自动加想") |
| | | gpcode_manager.WantBuyCodesManager().add_code(code) |
| | | trade_record_log_util.add_want_buy(code, "自动加") |