| | |
| | | from code_attribute import gpcode_manager, code_volumn_manager, zyltgb_util |
| | | from code_attribute.code_data_util import ZYLTGBUtil |
| | | from code_attribute.code_l1_data_manager import L1DataManager |
| | | from code_attribute.gpcode_manager import CodePrePriceManager, CodesNameManager, WantBuyCodesManager |
| | | from code_attribute.gpcode_manager import CodePrePriceManager, CodesNameManager, WantBuyCodesManager, \ |
| | | HumanRemoveForbiddenManager |
| | | from db import mysql_data_delegate as mysql_data, redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from huaxin_client import l1_subscript_codes_manager |
| | |
| | | if code_list_type == outside_api_command_manager.CODE_LIST_WANT: |
| | | if operate == outside_api_command_manager.OPERRATE_SET: |
| | | gpcode_manager.WantBuyCodesManager().add_code(code) |
| | | # 加想买单要从黑名单移除 |
| | | l2_trade_util.remove_from_forbidden_trade_codes(code) |
| | | if l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | l2_trade_util.remove_from_forbidden_trade_codes(code) |
| | | # 加想买单要从黑名单移除 |
| | | HumanRemoveForbiddenManager().add_code(code) |
| | | name = gpcode_manager.get_code_name(code) |
| | | if not name: |
| | | results = HistoryKDatasUtils.get_gp_codes_names([code]) |
| | |
| | | cancel_type=trade_constant.CANCEL_TYPE_HUMAN) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | l2_trade_util.forbidden_trade(code, msg="手动加入 trade_server") |
| | | l2_trade_util.forbidden_trade(code, msg="手动加入 trade_server", force=True) |
| | | WantBuyCodesManager().remove_code(code) |
| | | HumanRemoveForbiddenManager().remove_code(code) |
| | | name = gpcode_manager.get_code_name(code) |
| | | if not name: |
| | | results = HistoryKDatasUtils.get_gp_codes_names([code]) |
| | |
| | | gpcode_manager.CodesNameManager.add_first_code_name(code, results[code]) |
| | | elif operate == outside_api_command_manager.OPERRATE_DELETE: |
| | | l2_trade_util.remove_from_forbidden_trade_codes(code) |
| | | WantBuyCodesManager().add_code(code) |
| | | HumanRemoveForbiddenManager().add_code(code) |
| | | elif operate == outside_api_command_manager.OPERRATE_GET: |
| | | codes = gpcode_manager.BlackListCodeManager().list_codes_cache() |
| | | datas = [] |
| | |
| | | return self.__want_buy_codes_cache |
| | | |
| | | |
| | | @tool.singleton |
| | | class HumanRemoveForbiddenManager: |
| | | """ |
| | | 认为移黑管理 |
| | | """ |
| | | __db = 0 |
| | | redisManager = redis_manager.RedisManager(0) |
| | | __redis_key = "human_remove_forbidden_codes" |
| | | |
| | | __codes_cache = set() |
| | | |
| | | def __init__(self): |
| | | self.__load_data() |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.redisManager.getRedis() |
| | | |
| | | def __load_data(self): |
| | | self.__codes_cache = RedisUtils.smembers(self.__get_redis(), self.__redis_key) |
| | | if self.__codes_cache is None: |
| | | self.__codes_cache = set() |
| | | |
| | | def add_code(self, code): |
| | | self.__codes_cache.add(code) |
| | | RedisUtils.sadd_async(self.__db, self.__redis_key, code) |
| | | RedisUtils.expire_async(self.__db, self.__redis_key, tool.get_expire()) |
| | | |
| | | def remove_code(self, code): |
| | | self.__codes_cache.discard(code) |
| | | RedisUtils.srem_async(self.__db, self.__redis_key, code) |
| | | |
| | | def is_in_cache(self, code): |
| | | return code in self.__codes_cache |
| | | |
| | | |
| | | # 暂停下单代码管理 |
| | | # 与黑名单的区别是暂停交易代码只是不交易,不能移除L2监控位 |
| | | class PauseBuyCodesManager: |
| | |
| | | RedisUtils.delete(redis_instance, "first_code_record", auto_free=False) |
| | | RedisUtils.delete(redis_instance, "first_code_limited_up_record", auto_free=False) |
| | | finally: |
| | | RedisUtils.realse(redis_instance) |
| | | |
| | | RedisUtils.realse(redis_instance) |
| | |
| | | if not is_normal: |
| | | # print("历史数据异常:", code) |
| | | # 数据不正常需要禁止交易 |
| | | l2_trade_util.forbidden_trade(code, msg="L2历史数据异常") |
| | | l2_trade_util.forbidden_trade(code, msg="L2历史数据异常", force=True) |
| | | # 纠正数据 |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS: |
| | | # 同花顺需要纠正数据,其他渠道不需要 |
| | |
| | | is_normal = l2.l2_data_util.l2_data_is_normal(code) |
| | | if not is_normal: |
| | | # 数据不正常需要禁止交易 |
| | | l2_trade_util.forbidden_trade(code, msg="L2历史数据异常") |
| | | l2_trade_util.forbidden_trade(code, msg="L2历史数据异常", force=True) |
| | | # 转换数据格式 |
| | | _start_index = 0 |
| | | total_datas = local_today_datas.get(code) |
| | |
| | | data = json.loads(_str) |
| | | codes = data["data"]["codes"] |
| | | for code in codes: |
| | | l2_trade_util.forbidden_trade(code, msg="手动加入") |
| | | l2_trade_util.forbidden_trade(code, msg="手动加入",force= true) |
| | | name = gpcode_manager.get_code_name(code) |
| | | if not name: |
| | | results = HistoryKDatasUtils.get_gp_codes_names([code]) |
| | |
| | | @param is_refered: 是否是参考票 |
| | | @param code: 代码 |
| | | @param total_sell_volume: 总卖量 |
| | | @return: 是否可以买, 原因 |
| | | @return: 是否可以买, 原因, 是否可拉黑 |
| | | """ |
| | | if WantBuyCodesManager().is_in_cache(code): |
| | | return True, "已加想" |
| | | return True, "已加想", False |
| | | |
| | | k_format = None |
| | | if not constant.TEST: |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if k_format: |
| | | if not k_format[13]: |
| | | return False, "近60个交易日无涨停" |
| | | return False, "近60个交易日无涨停", True |
| | | if k_format[14]: |
| | | # 昨天炸板,一律不买 |
| | | return False, f"昨日炸板" |
| | | return False, f"昨日炸板", True |
| | | # 获取涨停价 |
| | | price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | if not price: |
| | |
| | | price = L1DataManager.get_l1_current_price(code) |
| | | if price: |
| | | if price < constant.MIN_CODE_RADICAL_BUY_PRICE or price > constant.MAX_CODE_RADICAL_BUY_PRICE: |
| | | return False, "价格不满足需求" |
| | | return False, "价格不满足需求", True |
| | | # 判断自由流通股本 |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb: |
| | |
| | | zylt_can_buy = True |
| | | break |
| | | if not zylt_can_buy: |
| | | return False, "自由流通市值/价格不满足扫的范围" |
| | | return False, "自由流通市值/价格不满足扫的范围", True |
| | | # 判断昨日是否跌幅过大 |
| | | if k_format and len(k_format) > 12 and k_format[12]: |
| | | return False, "上个交易日跌幅过大" |
| | | return False, "上个交易日跌幅过大", True |
| | | |
| | | if gpcode_manager.BlackListCodeManager().is_in_cache(code): |
| | | if deal_codes is not None and code in deal_codes: |
| | | pass |
| | | else: |
| | | # 拉黑且不是已经买入性质的拉黑 |
| | | return False, "已拉黑" |
| | | return False, "已拉黑", False |
| | | |
| | | if is_refered: |
| | | # 参考票没有大单 |
| | |
| | | if not constant.TEST: |
| | | big_order_deal_enough = is_big_order_deal_enough(code, volume_rate, 0) |
| | | if not big_order_deal_enough[0] and big_order_deal_enough[2]: |
| | | return False, "交易前两分钟大单不足" |
| | | return False, "交易前两分钟大单不足", False |
| | | |
| | | jx_out_blocks = RealTimeKplMarketData.get_top_market_jingxuan_out_blocks() |
| | | if jx_out_blocks: |
| | | blocks = RadicalBuyBlockManager.get_code_blocks(code)[0] |
| | | same_blocks = blocks & set(jx_out_blocks) |
| | | if same_blocks: |
| | | return False, f"【{same_blocks}】板块精选流出" |
| | | return False, f"【{same_blocks}】板块精选流出", False |
| | | |
| | | return True, "" |
| | | return True, "", False |
| | | |
| | | @classmethod |
| | | def big_order_deal(cls, code): |
| | |
| | | """ |
| | | THRESHOLD_MONEY = BeforeSubDealBigOrderManager().get_big_order_threshold(code) |
| | | TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT = round( |
| | | code_volumn_manager.CodeVolumeManager().get_max_volume_in_5days(code) * limit_up_price / 1e8, 2) |
| | | code_volumn_manager.CodeVolumeManager().get_max_volume_in_5days(code) * limit_up_price / 1e8, 2) * 1.2 |
| | | if tool.is_ge_code(code): |
| | | TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT *= 3.3 |
| | | |
| | |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | result = RadicalBuyDataManager().is_code_can_buy(code, deal_codes) |
| | | if not result[0]: |
| | | if len(result) > 2 and result[2]: |
| | | # 可以拉黑 |
| | | l2_trade_util.forbidden_trade(code, result[1]) |
| | | return -1 |
| | | |
| | | # 想买单 |
| | |
| | | need_add = True |
| | | else: |
| | | # 检查是否在想买单中 |
| | | if gpcode_manager.WantBuyCodesManager().is_in_cache(code): |
| | | if gpcode_manager.HumanRemoveForbiddenManager().is_in_cache(code): |
| | | # 人为移除黑,不可再拉黑 |
| | | need_add = False |
| | | else: |
| | | need_add = True |