扫过的单可继续扫/扫了未成交遵循顺位机制/唯一涨停原因的高位板要计算其身位
| | |
| | | cancel_shadow = data.get("cancel_shadow") |
| | | if cancel_shadow is None: |
| | | cancel_shadow = True |
| | | if shadow_volume is None: |
| | | shadow_volume = constant.SHADOW_ORDER_VOLUME |
| | | |
| | | if direction == 1: |
| | | async_log_util.info(logger_trade, f"{code}华鑫本地开始下单") |
| | |
| | | # threading.Thread(target=lambda: self.__tradeSimpleApi.buy(code, volume, price, sinfo, order_ref), |
| | | # daemon=True).start() |
| | | self.trade_thread_pool.submit(self.__tradeSimpleApi.buy, code, volume, price, sinfo, order_ref, |
| | | shadow_price, cancel_shadow) |
| | | shadow_price, cancel_shadow, shadow_volume) |
| | | async_log_util.info(logger_trade, f"{code}华鑫本地下单线程结束") |
| | | except Exception as e: |
| | | send_response(json.dumps({"code": 1, "msg": str(e)}), TYPE_ORDER, client_id, |
| | |
| | | |
| | | # 下单临时信息 |
| | | class OrderBeginPosInfo(object): |
| | | MODE_NORMAL = 0 |
| | | MODE_NORMAL = 0 # 普通下单 |
| | | MODE_FAST = 1 |
| | | MODE_ACTIVE = 2 |
| | | MODE_RADICAL = 3 |
| | | MODE_ACTIVE = 2 # 积极动买 |
| | | MODE_RADICAL = 3 # 扫入 |
| | | MODE_OPEN_LIMIT_UP = 4 # 排1 |
| | | |
| | | # mode: 0-普通交易 1-快速交易 |
| | | def __init__(self, buy_single_index=None, buy_exec_index=-1, buy_compute_index=None, num=0, count=0, |
| | |
| | | from l2.place_order_single_data_manager import L2TradeSingleDataProcessor |
| | | from log_module import async_log_util, log_export |
| | | from third_data import kpl_data_manager, block_info |
| | | from third_data.kpl_data_constant import LimitUpDataConstant |
| | | from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager |
| | | from utils import global_util, ths_industry_util, tool, buy_condition_util, buy_strategy_util, trade_util |
| | | import l2_data_util |
| | | from db import redis_manager_delegate as redis_manager |
| | | from third_data.code_plate_key_manager import CodePlateKeyBuyManager, KPLCodeJXBlockManager |
| | | from trade import trade_manager, trade_queue_manager, l2_trade_factor, l2_trade_util, \ |
| | | trade_result_manager, current_price_process_manager, trade_data_manager, trade_huaxin, trade_record_log_util, \ |
| | | trade_constant |
| | | trade_constant, buy_open_limit_up_strategy, radical_buy_data_manager |
| | | from l2 import l2_data_manager, l2_log, l2_data_source_util, code_price_manager, \ |
| | | transaction_progress, cancel_buy_strategy, place_order_single_data_manager |
| | | from l2.cancel_buy_strategy import DCancelBigNumComputer, \ |
| | |
| | | # place_order_index = add_datas[-1]["index"] |
| | | # cls.set_real_place_order_index(code, place_order_index, order_begin_pos.buy_single_index) |
| | | else: |
| | | # ------------09:30:00之前处理排1的问题-------------- |
| | | if int(add_datas[-1]["val"]["time"].replace(":", "")) < 93000: |
| | | # 获取是否下单 |
| | | buy_info = buy_open_limit_up_strategy.BuyOpenLimitupDataManager().get_place_order_info(code) |
| | | # 设置虚拟下单信息 |
| | | if buy_info: |
| | | try: |
| | | buy_single_index, buy_exec_index, buy_exec_index = add_datas[0]["index"], \ |
| | | add_datas[0]["index"], \ |
| | | add_datas[0]["index"] |
| | | buy_volume_rate = 0 |
| | | sell_info = ("09:15:00", 0) |
| | | threshold_money = 0 |
| | | order_begin_pos_info = OrderBeginPosInfo(buy_single_index=buy_single_index, |
| | | buy_exec_index=buy_exec_index, |
| | | buy_compute_index=buy_exec_index, |
| | | num=1, count=1, |
| | | max_num_set=set(), |
| | | buy_volume_rate=buy_volume_rate, |
| | | mode=OrderBeginPosInfo.MODE_RADICAL, |
| | | mode_desc=f"排1下单", |
| | | sell_info=sell_info, |
| | | threshold_money=threshold_money) |
| | | cls.__save_order_begin_data(code, order_begin_pos_info) |
| | | # 设置下单信息 |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | shadow_price = tool.get_shadow_price(limit_up_price) |
| | | huaxin_delegate_postion_manager.place_order(code, limit_up_price, buy_info[0], |
| | | buy_exec_index, |
| | | add_datas[0], buy_info[2], |
| | | shadow_price=shadow_price, |
| | | shadow_volume=buy_info[1]) |
| | | cls.__place_order_success(code, order_begin_pos_info) |
| | | except Exception as e: |
| | | logger_l2_error.exception(e) |
| | | finally: |
| | | buy_open_limit_up_strategy.BuyOpenLimitupDataManager().remove_place_order_info(code) |
| | | |
| | | # 获取下单位置 |
| | | place_order_index, order_info, compute_type = huaxin_delegate_postion_manager.get_l2_place_order_position( |
| | | code, float( |
| | |
| | | |
| | | @classmethod |
| | | def start_buy(cls, code, last_data, last_data_index, is_first_code): |
| | | cls.__buy(code, 0, last_data, last_data_index, is_first_code) |
| | | return cls.__buy(code, 0, last_data, last_data_index, is_first_code) |
| | | |
| | | @classmethod |
| | | def get_active_buy_blocks(cls, code): |
| | |
| | | if tool.trade_time_sub(tool.get_now_time_str(), "10:00:00") <= 0: |
| | | return ["独苗"] |
| | | return None |
| | | |
| | | @classmethod |
| | | def __place_order_success(cls, code, order_begin_pos): |
| | | ################下单成功处理################ |
| | | trade_result_manager.real_buy_success(code, cls.__TradePointManager) |
| | | l2_log.debug(code, "处理买入成功1") |
| | | cancel_buy_strategy.set_real_place_position(code, local_today_datas.get(code)[-1]["index"], |
| | | order_begin_pos.buy_single_index, is_default=True) |
| | | l2_log.debug(code, "处理买入成功2") |
| | | params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc() |
| | | l2_log.debug(code, params_desc) |
| | | ############记录下单时的数据############ |
| | | try: |
| | | jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache( |
| | | code), KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) |
| | | if jx_blocks: |
| | | jx_blocks = jx_blocks[0] |
| | | if jx_blocks_by: |
| | | jx_blocks_by = jx_blocks_by[0] |
| | | |
| | | info = cls.__trade_log_placr_order_info_dict[code] |
| | | info.mode = order_begin_pos.mode |
| | | info.mode_desc = order_begin_pos.mode_desc |
| | | info.set_buy_index(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | info.set_sell_info(order_begin_pos.sell_info) |
| | | if jx_blocks: |
| | | info.set_kpl_blocks(list(jx_blocks)) |
| | | elif jx_blocks_by: |
| | | info.set_kpl_blocks(list(jx_blocks_by)) |
| | | else: |
| | | info.set_kpl_blocks([]) |
| | | can_buy_result = CodePlateKeyBuyManager.can_buy(code) |
| | | if can_buy_result: |
| | | if not can_buy_result[0] and can_buy_result[1]: |
| | | info.set_kpl_match_blocks(["独苗"]) |
| | | elif not can_buy_result[0] and not can_buy_result[1]: |
| | | info.set_kpl_match_blocks(["非独苗不满足身位"]) |
| | | else: |
| | | temps = [] |
| | | temps.extend([f"{x[0]}" for x in can_buy_result[0]]) |
| | | if can_buy_result[5]: |
| | | temps.append(f"积极买入:{can_buy_result[5]}") |
| | | info.set_kpl_match_blocks(temps) |
| | | trade_record_log_util.add_place_order_log(code, info) |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_error, f"加入买入记录日志出错:{str(e)}") |
| | | |
| | | @classmethod |
| | | def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code): |
| | |
| | | trade_manager.start_buy(code, capture_timestamp, last_data, |
| | | last_data_index, order_begin_pos.mode, order_begin_pos.buy_exec_index) |
| | | l2_log.debug(code, "执行买入成功") |
| | | ################下单成功处理################ |
| | | trade_result_manager.real_buy_success(code, cls.__TradePointManager) |
| | | l2_log.debug(code, "处理买入成功1") |
| | | cancel_buy_strategy.set_real_place_position(code, local_today_datas.get(code)[-1]["index"], |
| | | order_begin_pos.buy_single_index, is_default=True) |
| | | l2_log.debug(code, "处理买入成功2") |
| | | params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc() |
| | | l2_log.debug(code, params_desc) |
| | | ############记录下单时的数据############ |
| | | try: |
| | | jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache( |
| | | code), KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) |
| | | if jx_blocks: |
| | | jx_blocks = jx_blocks[0] |
| | | if jx_blocks_by: |
| | | jx_blocks_by = jx_blocks_by[0] |
| | | |
| | | info = cls.__trade_log_placr_order_info_dict[code] |
| | | info.mode = order_begin_pos.mode |
| | | info.mode_desc = order_begin_pos.mode_desc |
| | | info.set_buy_index(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | info.set_sell_info(order_begin_pos.sell_info) |
| | | if jx_blocks: |
| | | info.set_kpl_blocks(list(jx_blocks)) |
| | | elif jx_blocks_by: |
| | | info.set_kpl_blocks(list(jx_blocks_by)) |
| | | else: |
| | | info.set_kpl_blocks([]) |
| | | can_buy_result = CodePlateKeyBuyManager.can_buy(code) |
| | | if can_buy_result: |
| | | if not can_buy_result[0] and can_buy_result[1]: |
| | | info.set_kpl_match_blocks(["独苗"]) |
| | | elif not can_buy_result[0] and not can_buy_result[1]: |
| | | info.set_kpl_match_blocks(["非独苗不满足身位"]) |
| | | else: |
| | | temps = [] |
| | | temps.extend([f"{x[0]}" for x in can_buy_result[0]]) |
| | | if can_buy_result[5]: |
| | | temps.append(f"积极买入:{can_buy_result[5]}") |
| | | info.set_kpl_match_blocks(temps) |
| | | trade_record_log_util.add_place_order_log(code, info) |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_error, f"加入买入记录日志出错:{str(e)}") |
| | | |
| | | |
| | | cls.__place_order_success(code, order_begin_pos) |
| | | |
| | | except Exception as e: |
| | | async_log_util.exception(logger_l2_error, e) |
| | |
| | | order_begin_pos.threshold_money, |
| | | 0, |
| | | True, False) |
| | | return ordered |
| | | |
| | | @classmethod |
| | | def __start_compute_buy(cls, code, compute_start_index, compute_end_index, threshold_money, capture_time, |
| | |
| | | sell_info=sell_info, |
| | | threshold_money=threshold_money) |
| | | order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code) |
| | | cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index) |
| | | ordered = cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index) |
| | | if ordered: |
| | | radical_buy_data_manager.BlockPlaceOrderRecordManager().add_record(code, radical_result[2]) |
| | | return |
| | | |
| | | # 获取买入信号计算起始位置 |
| | |
| | | @param code: |
| | | @param start_index: |
| | | @param end_index: |
| | | @return: (是否获取到信号, 信号位置, 消息) |
| | | @return: (是否获取到信号, 信号位置, 扫入板块/消息) |
| | | """ |
| | | |
| | | # 激进买信号的时间 |
| | |
| | | return False, None, "无大单" |
| | | |
| | | radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code) |
| | | record_codes = radical_buy_data_manager.BlockPlaceOrderRecordManager().get_codes() |
| | | # 是否扫入过 |
| | | is_radical_buy = code in record_codes |
| | | |
| | | if not radical_data: |
| | | return False, None, "不满足激进买的条件" |
| | | if t.time() > radical_data[0]: |
| | | if t.time() > radical_data[0] and not is_radical_buy: |
| | | # 没扫入过才需要判断时间 |
| | | return False, None, "超过生效时间" |
| | | result = __can_order() |
| | | l2_log.debug(code, f"L2扫入判断:{result}") |
| | | if result[0]: |
| | | return True, result[1], f"扫入板块:{radical_data[2]}" |
| | | # 已经扫入下过单的就需要判断板上放量的距离 |
| | | if is_radical_buy: |
| | | is_limit_up_buy = cls.__is_at_limit_up_buy(code) |
| | | if is_limit_up_buy: |
| | | # 判断成交进度到当前数据的笔数,如果少于10笔且还有未成交的大单(>=299)就可以下单 |
| | | trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code) |
| | | if trade_index is None: |
| | | trade_index = 0 |
| | | can_place_order, msg = buy_strategy_util.is_near_by_trade_index(code, trade_index) |
| | | if not can_place_order: |
| | | return False, result[1], "扫入过的代码板上放量距离远" |
| | | else: |
| | | # 判断该板块前排是否已经有成交 |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | for b in radical_data[2]: |
| | | temp_deal_codes = radical_buy_data_manager.get_deal_codes_by_block(b, deal_codes) |
| | | if len(temp_deal_codes) > 0: |
| | | max_count = RadicalBuyBlockCodeCountManager().get_block_code_count(b) |
| | | if len(temp_deal_codes) > max_count: |
| | | return False, result[1], f"前排代码成交数量足够多:{temp_deal_codes}" |
| | | # 前排代码才会继续买 |
| | | limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code) |
| | | if not limit_up_timestamp: |
| | | limit_up_timestamp = t.time() |
| | | front_infos = [] |
| | | for _code in temp_deal_codes: |
| | | temp_limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(_code) |
| | | if temp_limit_up_timestamp and limit_up_timestamp > temp_limit_up_timestamp: |
| | | front_infos.append((_code, temp_limit_up_timestamp)) |
| | | if len(front_infos) >= max_count: |
| | | return False, result[1], f"前排代码已经成交:{front_infos}" |
| | | return True, result[1], radical_data[2] |
| | | return result |
| | | |
| | | @classmethod |
| | |
| | | return |
| | | radical_buy_data_manager.ExcludeIndexComputeCodesManager.remove_code(code) |
| | | |
| | | |
| | | if result_by_volume[0] == radical_buy_strategy.BUY_MODE_DIRECT: |
| | | refer_sell_data = L2MarketSellManager().get_refer_sell_data(code, |
| | | l2_huaxin_util.convert_time( |
| | |
| | | sell_info=sell_info, |
| | | threshold_money=threshold_money) |
| | | L2TradeDataProcessor.save_order_begin_data(code, order_begin_pos_info) |
| | | L2TradeDataProcessor.start_buy(code, total_datas[-1], total_datas[-1]["index"], True) |
| | | buy_result = L2TradeDataProcessor.start_buy(code, total_datas[-1], total_datas[-1]["index"], |
| | | True) |
| | | if buy_result: |
| | | # 下单成功 |
| | | radical_buy_data_manager.BlockPlaceOrderRecordManager().add_record(code, buy_blocks) |
| | | else: |
| | | RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict[code] = ( |
| | | time.time() + 2, transaction_datas[-1][6], buy_blocks) |
| | |
| | | try: |
| | | volume = tool.get_buy_volume_by_money(limit_up_price, constant.AVAILABLE_BUY_MONEYS[0]) |
| | | result = huaxin_trade_api.order(huaxin_trade_api.TRADE_DIRECTION_BUY, code, volume, limit_up_price, |
| | | blocking=True, |
| | | blocking=False, |
| | | shadow_price=shadow_price, shadow_volume=volume) |
| | | async_log_util.info(logger_trade, f"{code}下单结束:{result}") |
| | | buy_open_limit_up_strategy.BuyOpenLimitupDataManager().set_place_order_info(code, volume, volume) |
| | | buy_open_limit_up_strategy.BuyOpenLimitupDataManager().set_place_order_info(code, volume, volume, |
| | | result.get("order_ref")) |
| | | except Exception as e: |
| | | pass |
| | | |
| | |
| | | from third_data.third_blocks_manager import BlockMapManager, CodeThirdBlocksManager |
| | | from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager |
| | | from trade.order_statistic import DealAndDelegateWithBuyModeDataManager |
| | | from trade.radical_buy_data_manager import RadicalBuyDataManager |
| | | from trade.radical_buy_data_manager import RadicalBuyDataManager, BlockPlaceOrderRecordManager |
| | | from trade.trade_data_manager import RadicalBuyDealCodesManager |
| | | from utils import global_util, tool, buy_condition_util |
| | | from log_module import log, async_log_util |
| | | from db import redis_manager_delegate as redis_manager |
| | |
| | | kpl_data_constant.open_limit_up_code_dict_for_radical_buy = temp_dict |
| | | |
| | | @classmethod |
| | | def __get_current_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None, limit_up_time=None): |
| | | def __get_current_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None, limit_up_time=None, |
| | | ignore_open_limit_up=True): |
| | | """ |
| | | 获取当前涨停身位 |
| | | 获取当前涨停身位 |
| | | @param code: |
| | | @param block: |
| | | @param yesterday_limit_up_codes: |
| | | @param exclude_codes: |
| | | @param limit_up_time: |
| | | @param ignore_open_limit_up: 是否忽略开1的代码 |
| | | @return: 索引,前排代码信息([(代码, 涨停时间)]) |
| | | """ |
| | | if exclude_codes is None: |
| | |
| | | limit_up_time = time.time() |
| | | for k in LimitUpDataConstant.current_limit_up_datas: |
| | | _code = k[0] |
| | | # 剔除4板以上的板 |
| | | if kpl_util.get_high_level_count(k[4]) >= 4: |
| | | continue |
| | | |
| | | if _code in exclude_codes: |
| | | continue |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | | if not blocks: |
| | | blocks = set() |
| | | blocks = BlockMapManager().filter_blocks(blocks) |
| | | if _code == code: |
| | | # 获取当前代码涨停时间 |
| | | limit_up_time = int(k[2]) |
| | |
| | | # 不是这个板块 |
| | | if block not in blocks: |
| | | continue |
| | | |
| | | # 剔除4板以上的板 |
| | | if kpl_util.get_high_level_count(k[4]) >= 4 and len(blocks) > 1: |
| | | continue |
| | | |
| | | if not tool.is_can_buy_code(_code): |
| | | continue |
| | | # 剔除开1的数据 |
| | | if timestamp_start <= int(k[2]) < timestamp_end: |
| | | if ignore_open_limit_up and timestamp_start <= int(k[2]) < timestamp_end: |
| | | continue |
| | | # 剔除高位板 |
| | | if _code in yesterday_limit_up_codes: |
| | |
| | | return current_index, before_codes_info |
| | | |
| | | @classmethod |
| | | def __get_history_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None): |
| | | def __get_history_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None, ignore_open_limit_up=True): |
| | | """ |
| | | 获取历史涨停身位 |
| | | @param code: |
| | | @param block: |
| | | @param current_limit_up_datas: 昨日涨停代码 |
| | | @param current_limit_up_codes: 目前的涨停代码 |
| | | @param yesterday_limit_up_codes: |
| | | @param exclude_codes: |
| | | @param ignore_open_limit_up: 是否忽略开1代码 |
| | | @return: |
| | | """ |
| | | if exclude_codes is None: |
| | |
| | | limit_up_space_ge_60s_codes = set() |
| | | for k in LimitUpDataConstant.history_limit_up_datas: |
| | | _code = k[3] |
| | | |
| | | # 剔除4板以上的板 |
| | | if kpl_util.get_high_level_count(k[12]) >= 4: |
| | | continue |
| | | |
| | | if _code in exclude_codes: |
| | | continue |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | | if _code == code: |
| | | # 获取当前代码涨停时间 |
| | | limit_up_time = int(k[5]) |
| | | continue |
| | | |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | | # 不是这个板块 |
| | | if block not in blocks: |
| | | continue |
| | | # 剔除4板以上且板块数量大于1个 |
| | | if kpl_util.get_high_level_count(k[12]) >= 4 and len(blocks) > 1: |
| | | continue |
| | | |
| | | if not tool.is_can_buy_code(_code): |
| | | continue |
| | | # 剔除开1的数据 |
| | | if timestamp_start <= int(k[5]) < timestamp_end: |
| | | if ignore_open_limit_up and timestamp_start <= int(k[5]) < timestamp_end: |
| | | continue |
| | | # 剔除高位板 |
| | | if _code in yesterday_limit_up_codes: |
| | |
| | | if history_index == 1: |
| | | # 当前代码为老2,要判断老大是否可买 |
| | | if RadicalBuyDataManager.is_code_can_buy(history_before_codes_info[0][0], |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes(), is_refered=True)[0]: |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes(), |
| | | is_refered=True)[0]: |
| | | return False, f"开1数量:{count},前排代码可买:{history_before_codes_info[0]}" |
| | | return True, f"开1数量:{count},前排代码不可买:{history_before_codes_info[0]},历史前排-{history_before_codes_info},开1代码-{open_limit_up_block_codes}" |
| | | return True, f"开1数量:{count},历史-{history_index + 1} 实时-{current_index + 1}, 前排代码-{current_before_codes_info}, 开1代码-{open_limit_up_block_codes}" |
| | |
| | | return index, before_codes_info |
| | | temp_index = index |
| | | temp_before_codes_info = [] |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | for b in before_codes_info: |
| | | # 当作目标票获取扫入板块 |
| | | code_ = b[0] |
| | |
| | | if not need_delete: |
| | | if radical_buy_data_manager.ExcludeIndexComputeCodesManager.is_in_cache(code_): |
| | | need_delete = True |
| | | # 判断是不是扫了没有扫进入 |
| | | if not need_delete: |
| | | if code_ in BlockPlaceOrderRecordManager().get_codes() and code_ not in deal_codes: |
| | | need_delete = True |
| | | |
| | | if need_delete: |
| | | temp_index -= 1 |
| | | else: |
| | |
| | | |
| | | if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'), |
| | | tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60: |
| | | return False, f"距离上个代码涨停已过去10分钟({current_before_codes_info[0]})" |
| | | return False, f"距离上个代码涨停已过去10分钟({current_before_codes_info[-1]})" |
| | | |
| | | # 包含高位板的整体排序 |
| | | all_history_index, all_history_before_codes_info = cls.__get_history_index(code, block, set()) |
| | |
| | | # 前两个代码是否有炸板 |
| | | dif_codes = set(all_history_before_codes[:2]) - set(current_before_codes[:2]) |
| | | if dif_codes: |
| | | return False, f"前2代码有炸板:{dif_codes}" |
| | | return False, f"前2代码有炸板:{dif_codes}, 前排代码:{all_history_before_codes}" |
| | | # 前排代码炸板不能>=2个 |
| | | dif_codes = set(all_history_before_codes) - set(current_before_codes) |
| | | if len(dif_codes) >= 2: |
| | |
| | | pre_code = history_before_codes_info[0][0] |
| | | # pre_code不能买,才能买 |
| | | if RadicalBuyDataManager.is_code_can_buy(pre_code, |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes(), is_refered=True)[0]: |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes(), |
| | | is_refered=True)[0]: |
| | | return False, f"前排代码可买:{pre_code}" |
| | | # 前面一个代码不能买,前一个代码必须与前前个代码涨停时间相差15分钟内 |
| | | for i in range(len(all_history_before_codes_info) - 1, -1, -1): |
| | |
| | | val = json.loads(val) |
| | | cls.__place_order_info_dict[code] = val |
| | | |
| | | def set_place_order_info(self, code, volume, shadow_volume): |
| | | def set_place_order_info(self, code, volume, shadow_volume, order_ref): |
| | | """ |
| | | @param order_ref: 下单索引 |
| | | @param code: |
| | | @param volume: |
| | | @param shadow_volume: |
| | | @return: |
| | | """ |
| | | self.__place_order_info_dict[code] = (volume, shadow_volume) |
| | | self.__place_order_info_dict[code] = (volume, shadow_volume, order_ref) |
| | | RedisUtils.set_async(self.__db, f"buy_open_limit_up_placing_orderinfo-{code}", tool.get_expire(), |
| | | json.dumps(self.__place_order_info_dict[code])) |
| | | |
| | |
| | | """ |
| | | 获取下单信息 |
| | | @param code: |
| | | @return:(下单量, 影子单量) |
| | | @return:(下单量, 影子单量, 订单索引) |
| | | """ |
| | | return self.__place_order_info_dict.get(code) |
| | | |
| | | def remove_place_order_info(self, code): |
| | | if code in self.__place_order_info_dict: |
| | | self.__place_order_info_dict.pop(code) |
| | | RedisUtils.delete_async(self.__db, f"buy_open_limit_up_placing_orderinfo-{code}") |
| | | |
| | |
| | | """ |
| | | 激进买数据管理 |
| | | """ |
| | | 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的比例 |
| | |
| | | """ |
| | | 根据开盘价判断是否可买 |
| | | @param code: |
| | | @param open_price: |
| | | @param open_price: 开盘价没获取到就不判断 |
| | | @return: |
| | | """ |
| | | if tool.get_now_time_as_int() < int("093500"): |
| | | if tool.get_now_time_as_int() < int("093500") and open_price: |
| | | async_log_util.info(logger_l2_radical_buy, f"开盘价:{code}-{open_price}") |
| | | pre_price = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) |
| | | if pre_price: |