| | |
| | | import copy |
| | | import json |
| | | import logging |
| | | import os |
| | | import threading |
| | | import time |
| | |
| | | |
| | | import constant |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import async_log_util |
| | | from utils import tool |
| | | |
| | | # 开盘啦历史涨停数据管理 |
| | | from db import mysql_data_delegate as mysql_data, redis_manager_delegate as redis_manager |
| | | from log_module.log import logger_kpl_limit_up_reason_change, logger_debug |
| | | from log_module.log import logger_kpl_limit_up_reason_change, logger_debug, logger_kpl_limit_up |
| | | from third_data import kpl_util, kpl_api |
| | | from third_data.code_plate_key_manager import LimitUpCodesPlateKeyManager, CodesHisReasonAndBlocksManager |
| | | |
| | |
| | | __kplPlatManager = KPLPlatManager() |
| | | __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() |
| | | __CodesPlateKeysManager = CodesHisReasonAndBlocksManager() |
| | | __current_code_reason_dict = {} |
| | | __current_reason_codes_dict = {} |
| | | |
| | | @classmethod |
| | | def __load_hist_and_blocks(cls, code): |
| | |
| | | if records: |
| | | cls.latest_origin_datas = records |
| | | cls.__LimitUpCodesPlateKeyManager.set_today_limit_up([(r[0], r[5]) for r in records]) |
| | | |
| | | code_reason_dict = {} |
| | | reason_code_dict = {} |
| | | for d in records: |
| | | code_reason_dict[d[0]] = d[5] |
| | | if d[5] not in reason_code_dict: |
| | | reason_code_dict[d[5]] = set() |
| | | reason_code_dict[d[5]].add(d[0]) |
| | | cls.__current_code_reason_dict = code_reason_dict |
| | | cls.__current_reason_codes_dict = reason_code_dict |
| | | |
| | | # 涨停数据记录 |
| | | mysqldb = mysql_data.Mysqldb() |
| | |
| | | results = cls.get_latest_infos(code, 2, False) |
| | | bs = set([b[0] for b in results]) |
| | | return bs |
| | | |
| | | @classmethod |
| | | def get_current_block(cls, code): |
| | | return cls.__current_code_reason_dict.get(code) |
| | | |
| | | @classmethod |
| | | def get_current_codes_by_block(cls, block): |
| | | return cls.__current_reason_codes_dict.get(block) |
| | | |
| | | @classmethod |
| | | def get_current_reason_codes_dict(cls): |
| | | return copy.deepcopy(cls.__current_reason_codes_dict) |
| | | |
| | | @classmethod |
| | | def get_current_reasons(cls): |
| | | if cls.__current_reason_codes_dict: |
| | | return cls.__current_reason_codes_dict.keys() |
| | | return set() |
| | | |
| | | |
| | | class KPLDataManager: |
| | |
| | | |
| | | |
| | | def get_yesterday_limit_up_codes(): |
| | | yesterday_limit_up_data_records = get_current_limit_up_data_records(1)[0][1] |
| | | yesterday_limit_up_data_records = get_yesterday_current_limit_up_records() |
| | | yesterday_codes = set([x[0] for x in yesterday_limit_up_data_records]) |
| | | return yesterday_codes |
| | | |
| | | |
| | | def get_yesterday_current_limit_up_records(): |
| | | yesterday_limit_up_data_records = get_current_limit_up_data_records(1)[0][1] |
| | | return yesterday_limit_up_data_records |
| | | |
| | | |
| | | # 运行拉取任务 |
| | |
| | | requests.post("http://127.0.0.1:9004/upload_kpl_data", json.dumps(root_data)) |
| | | |
| | | def get_limit_up(): |
| | | last_time = 0 |
| | | while True: |
| | | if tool.is_trade_time() or True: |
| | | if tool.is_trade_time(): |
| | | try: |
| | | results = kpl_api.daBanList(kpl_api.DABAN_TYPE_LIMIT_UP) |
| | | results = kpl_api.getLimitUpInfo() |
| | | result = json.loads(results) |
| | | start_time = time.time() |
| | | __upload_data("limit_up", result) |
| | | logger_kpl_limit_up_reason_change.info("上传耗时:{}", time.time() - start_time) |
| | | if start_time - last_time >= 60: |
| | | last_time = time.time() |
| | | # 记录涨停数据 |
| | | logger_kpl_limit_up.info(result) |
| | | # logger_kpl_limit_up_reason_change.info("上传耗时:{}", time.time() - start_time) |
| | | except Exception as e: |
| | | pass |
| | | logging.exception(e) |
| | | time.sleep(3) |
| | | |
| | | def get_bidding_money(): |