| | |
| | | """ |
| | | 激进买数据管理 |
| | | """ |
| | | import json |
| | | |
| | | import constant |
| | | import l2_data_util |
| | | from code_attribute import code_nature_analyse, code_volumn_manager, gpcode_manager |
| | | from code_attribute.code_l1_data_manager import L1DataManager |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2.l2_transaction_data_manager import BigOrderDealManager, HuaXinBuyOrderManager |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_l2_radical_buy |
| | |
| | | return code in cls.__codes_cache |
| | | |
| | | |
| | | class BlockPlaceOrderRecordManager: |
| | | """ |
| | | 板块下单记录 |
| | | """ |
| | | __db = 2 |
| | | __redis_manager = redis_manager.RedisManager(2) |
| | | __instance = None |
| | | # 下单板块的代码记录 |
| | | __block_record_codes_dict = {} |
| | | __codes = set() |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(BlockPlaceOrderRecordManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_data() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.__redis_manager.getRedis() |
| | | |
| | | @classmethod |
| | | def __load_data(cls): |
| | | val = RedisUtils.get(cls.__get_redis(), "radical_place_order_block_records") |
| | | if val: |
| | | val = json.loads(val) |
| | | for v in val: |
| | | cls.__block_record_codes_dict[v[0]] = set(v[1]) |
| | | cls.__codes |= set(v[1]) |
| | | |
| | | def add_record(self, code, blocks): |
| | | """ |
| | | 添加下单记录 |
| | | @param code: |
| | | @param blocks: |
| | | @return: |
| | | """ |
| | | if blocks: |
| | | for b in blocks: |
| | | if b not in self.__block_record_codes_dict: |
| | | self.__block_record_codes_dict[b] = set() |
| | | self.__block_record_codes_dict[b].add(code) |
| | | datas = [(b, list(self.__block_record_codes_dict[b])) for b in self.__block_record_codes_dict] |
| | | RedisUtils.set_async(self.__db, "radical_place_order_block_records", tool.get_expire(), json.dumps(datas)) |
| | | self.__codes.add(code) |
| | | |
| | | def get_block_codes(self, block): |
| | | """ |
| | | 获取板块下过单的代码 |
| | | @param block: |
| | | @return: |
| | | """ |
| | | if block in self.__block_record_codes_dict: |
| | | return self.__block_record_codes_dict[block] |
| | | return set() |
| | | |
| | | def get_codes(self): |
| | | return self.__codes |
| | | |
| | | |
| | | def is_big_order_deal_enough(code, volume_rate): |
| | | """ |
| | | 大单成交是否足够 |
| | |
| | | return 0 |
| | | |
| | | |
| | | def __get_deal_reasons(code): |
| | | """ |
| | | 获取成交的原因 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | reasons = set() |
| | | # 当前的涨停原因 |
| | | limit_up_reason = kpl_data_manager.LimitUpDataConstant.get_limit_up_reason_with_history(code) |
| | | if limit_up_reason and limit_up_reason in constant.KPL_INVALID_BLOCKS: |
| | | limit_up_reason = None |
| | | # 如果涨停原因为空就需要获取上次激进买的原因 |
| | | if limit_up_reason: |
| | | reasons.add(limit_up_reason) |
| | | if not limit_up_reason: |
| | | radical_buy_deal_blocks = RadicalBuyDealCodesManager.radical_buy_blocks_dict.get(code) |
| | | if radical_buy_deal_blocks: |
| | | reasons |= radical_buy_deal_blocks |
| | | return reasons |
| | | |
| | | def is_block_can_radical_buy(code, radical_buy_blocks, deal_codes): |
| | | """ |
| | | 板块是否还能买入 |
| | | @param code: |
| | | @param radical_buy_blocks: 板块 |
| | | @param deal_codes: 成交的代码 |
| | | @return: |
| | | """ |
| | | # 原因下面的代码个数 |
| | | deal_reason_codes = {} |
| | | |
| | | for dc in deal_codes: |
| | | # 获取涨停原因 |
| | | reasons = set() |
| | | # 当前的涨停原因 |
| | | limit_up_reason = kpl_data_manager.LimitUpDataConstant.get_limit_up_reason_with_history(dc) |
| | | if limit_up_reason and limit_up_reason in constant.KPL_INVALID_BLOCKS: |
| | | limit_up_reason = None |
| | | # 如果涨停原因为空就需要获取上次激进买的原因 |
| | | if limit_up_reason: |
| | | reasons.add(limit_up_reason) |
| | | if not limit_up_reason: |
| | | radical_buy_deal_blocks = RadicalBuyDealCodesManager.radical_buy_blocks_dict.get(dc) |
| | | if radical_buy_deal_blocks: |
| | | reasons |= radical_buy_deal_blocks |
| | | reasons = __get_deal_reasons(dc) |
| | | for r in reasons: |
| | | if r not in deal_reason_codes: |
| | | deal_reason_codes[r] = set() |
| | |
| | | return f_buy_blocks |
| | | |
| | | |
| | | def get_deal_codes_by_block(block, deal_codes): |
| | | """ |
| | | 获取板块成交的代码 |
| | | @param block: |
| | | @param deal_codes: |
| | | @return: |
| | | """ |
| | | codes = set() |
| | | for dc in deal_codes: |
| | | # 获取涨停原因 |
| | | reasons = __get_deal_reasons(dc) |
| | | if block in reasons: |
| | | codes.add(block) |
| | | return codes |
| | | |
| | | |
| | | def get_volume_rate_threshold(code, volume_rate): |
| | | """ |
| | | 获取吃卖1的比例 |