| | |
| | | fresult = {"code": 0, "data": datas} |
| | | elif code_list_type == outside_api_command_manager.CODE_LIST_WHITE: |
| | | if operate == outside_api_command_manager.OPERRATE_SET: |
| | | gpcode_manager.WhiteListCodeManager().add_code(code) |
| | | gpcode_manager.WhiteListCodeManager().add_code(code, is_human=True) |
| | | name = gpcode_manager.get_code_name(code) |
| | | if not name: |
| | | results = HistoryKDatasUtils.get_gp_codes_names([code]) |
| | | if results: |
| | | gpcode_manager.CodesNameManager.add_first_code_name(code, results[code]) |
| | | elif operate == outside_api_command_manager.OPERRATE_DELETE: |
| | | gpcode_manager.WhiteListCodeManager().remove_code(code) |
| | | gpcode_manager.WhiteListCodeManager().remove_code(code, is_human=True) |
| | | elif operate == outside_api_command_manager.OPERRATE_GET: |
| | | codes = gpcode_manager.WhiteListCodeManager().list_codes_cache() |
| | | datas = [] |
| | |
| | | "top_block_count_by_market_strong": constant.RADICAL_BUY_TOP_IN_COUNT_BY_MARKET_STRONG, |
| | | "special_codes_max_block_in_rank": constant.RADICAL_BUY_TOP_IN_INDEX_WITH_SPECIAL, |
| | | "ignore_block_in_money_market_strong": constant.IGNORE_BLOCK_IN_MONEY_MARKET_STRONG, |
| | | "buy_first_limit_up": 1 if constant.CAN_BUY_FIRST_LIMIT_UP else 0 |
| | | "buy_first_limit_up": 1 if constant.CAN_BUY_FIRST_LIMIT_UP else 0, |
| | | "can_auto_add_white": 1 if constant.CAN_AUTO_ADD_WHITE else 0 |
| | | }} |
| | | self.send_response({"code": 0, "data": data, "msg": f""}, |
| | | client_id, |
| | |
| | | if radical_buy.get('buy_first_limit_up') is not None: |
| | | constant.CAN_BUY_FIRST_LIMIT_UP = True if radical_buy.get( |
| | | 'buy_first_limit_up') else False |
| | | if radical_buy.get('can_auto_add_white') is not None: |
| | | constant.CAN_AUTO_ADD_WHITE = True if radical_buy.get( |
| | | 'can_auto_add_white') else False |
| | | |
| | | self.send_response({"code": 0, "data": {}, "msg": f""}, |
| | | client_id, |
| | |
| | | class WhiteListCodeManager: |
| | | __instance = None |
| | | __redis_manager = redis_manager.RedisManager(2) |
| | | __human_remove_codes = set() |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | |
| | | if data: |
| | | self.__white_codes_cache |= data |
| | | |
| | | def add_code(self, code): |
| | | def add_code(self, code, is_human=False): |
| | | |
| | | if not is_human and code in self.__human_remove_codes: |
| | | # 机器加白,且被人为移白了就不能再加白 |
| | | return |
| | | |
| | | self.__white_codes_cache.add(code) |
| | | RedisUtils.sadd(self.__get_redis(), "white_list_codes", code) |
| | | RedisUtils.expire(self.__get_redis(), "white_list_codes", tool.get_expire()) |
| | | |
| | | def remove_code(self, code): |
| | | def remove_code(self, code, is_human=False): |
| | | self.__white_codes_cache.discard(code) |
| | | RedisUtils.srem(self.__get_redis(), "white_list_codes", code) |
| | | if is_human: |
| | | self.human_remove(code) |
| | | |
| | | def is_in(self, code): |
| | | return RedisUtils.sismember(self.__get_redis(), "white_list_codes", code) |
| | |
| | | self.__white_codes_cache.clear() |
| | | RedisUtils.delete(self.__get_redis(), "white_list_codes") |
| | | |
| | | def human_remove(self, code): |
| | | """ |
| | | 人为移白 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | self.__human_remove_codes.add(code) |
| | | |
| | | def clear_huamn_info(self, code): |
| | | """ |
| | | 移除人为干预信息 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if code in self.__human_remove_codes: |
| | | self.__human_remove_codes.discard(code) |
| | | |
| | | |
| | | |
| | | class BlackListCodeManager: |
| | | __instance = None |
| | |
| | | # 是否可买首封 |
| | | CAN_BUY_FIRST_LIMIT_UP = False |
| | | |
| | | # 是否可以自动拉白 |
| | | CAN_AUTO_ADD_WHITE = True |
| | | |
| | | |
New file |
| | |
| | | """ |
| | | 大单成交数据解析器 |
| | | """ |
| | | import os |
| | | import re |
| | | from multiprocessing import Pool |
| | | |
| | | import pandas as pd |
| | | |
| | | from utils import tool |
| | | |
| | | |
| | | class BigOrderDealParser: |
| | | |
| | | @classmethod |
| | | def str_to_float(cls, s): |
| | | try: |
| | | # 移除单位并转换 |
| | | return round(float(s.split("@")[0]), 2) |
| | | except: |
| | | return float("nan") |
| | | |
| | | @classmethod |
| | | def code_format(cls, s): |
| | | try: |
| | | code = "{0:0>6}".format(s) |
| | | return code |
| | | except: |
| | | return '' |
| | | |
| | | |
| | | def __pre_process_transactions_detail(args): |
| | | def first_last(group): |
| | | """ |
| | | 获取第一条数据与最后一条 |
| | | @param group: |
| | | @return: |
| | | """ |
| | | return pd.Series({ |
| | | 'TotalAmount': group['TradeAmount'].sum(), |
| | | 'TotalVolume': group['TradeVolume'].sum(), |
| | | 'StartTime': group['TradeTime'].iloc[0], |
| | | 'StartPrice': group['TradePrice'].iloc[0], |
| | | 'EndTime': group['TradeTime'].iloc[-1], |
| | | 'EndPrice': group['TradePrice'].iloc[-1] |
| | | }) |
| | | |
| | | chunk_index, chunk_data = args[0] |
| | | csv_path = args[1] |
| | | df = chunk_data.copy() |
| | | index = chunk_index + 1 |
| | | children_dir = csv_path.replace(".csv", "") |
| | | if not os.path.exists(children_dir): |
| | | os.makedirs(children_dir) |
| | | child_path = os.path.join(children_dir, f"{index}.csv") |
| | | if os.path.exists(child_path): |
| | | return |
| | | print(f"处理Transaction第{index}批次", os.getpid()) |
| | | df["TradePrice"] = df["TradePrice"].apply(BigOrderDealParser.str_to_float) |
| | | df["SecurityID"] = df["SecurityID"].apply(BigOrderDealParser.code_format) |
| | | df = df[df["SecurityID"].str.startswith(("30", "00", "60"), na=False)] |
| | | # 计算成交金额 |
| | | df['TradeAmount'] = df['TradePrice'] * df['TradeVolume'] |
| | | df = df[df["TradeAmount"] > 0] |
| | | # 判断是否为空 |
| | | # print(df.empty) |
| | | # 按SecurityID和BuyNo分组 |
| | | grouped = df.groupby(['SecurityID', 'BuyNo']) |
| | | # 应用聚合函数 |
| | | chunk_result = grouped.apply(first_last) |
| | | if not df.empty: |
| | | chunk_result = chunk_result.reset_index() |
| | | chunk_result.to_csv(child_path, index=False) |
| | | |
| | | |
| | | def pre_process_transactions(csv_path, process_count=4): |
| | | chunk_size = 200000 |
| | | # 创建DataFrame |
| | | chunks = pd.read_csv(csv_path, chunksize=chunk_size) |
| | | indexed_data = list(enumerate(chunks)) |
| | | args = [(x, csv_path) for x in indexed_data] |
| | | # 新写法 |
| | | with Pool(processes=process_count) as pool: |
| | | pool.map(__pre_process_transactions_detail, args) |
| | | |
| | | |
| | | def __pre_process_ngtsticks(args): |
| | | def first_last(group): |
| | | return pd.Series({ |
| | | 'TotalAmount': group['TradeMoney'].sum(), |
| | | 'TotalVolume': group['Volume'].sum(), |
| | | 'StartTime': group['TickTime'].iloc[0], |
| | | 'StartPrice': group['Price'].iloc[0], |
| | | 'EndTime': group['TickTime'].iloc[-1], |
| | | 'EndPrice': group['Price'].iloc[-1] |
| | | }) |
| | | |
| | | chunk_index, chunk_data = args[0] |
| | | csv_path = args[1] |
| | | |
| | | df = chunk_data.copy() |
| | | index = chunk_index + 1 |
| | | children_dir = csv_path.replace(".csv", "") |
| | | if not os.path.exists(children_dir): |
| | | os.makedirs(children_dir) |
| | | child_path = os.path.join(children_dir, f"{index}.csv") |
| | | if os.path.exists(child_path): |
| | | return |
| | | print(f"处理NGTSTick第{index}批次") |
| | | df = df[df["TickType"] == 'T'] |
| | | df["Price"] = df["Price"].apply(BigOrderDealParser.str_to_float) |
| | | df["SecurityID"] = df["SecurityID"].apply(BigOrderDealParser.code_format) |
| | | df = df[df["SecurityID"].str.startswith(("30", "00", "60"), na=False)] |
| | | # 计算成交金额 |
| | | df['TradeMoney'] = df["TradeMoney"].apply(BigOrderDealParser.str_to_float) |
| | | |
| | | # 按SecurityID和BuyNo分组 |
| | | grouped = df.groupby(['SecurityID', 'BuyNo']) |
| | | # 应用聚合函数 |
| | | chunk_result = grouped.apply(first_last) |
| | | if not df.empty: |
| | | chunk_result = chunk_result.reset_index() |
| | | chunk_result.to_csv(child_path, index=False) |
| | | |
| | | |
| | | def pre_process_ngtsticks(csv_path, process_count=4): |
| | | chunk_size = 200000 |
| | | # 创建DataFrame |
| | | chunks = pd.read_csv(csv_path, chunksize=chunk_size) |
| | | indexed_data = list(enumerate(chunks)) |
| | | args = [(x, csv_path) for x in indexed_data] |
| | | # 新写法 |
| | | with Pool(processes=process_count) as pool: |
| | | pool.map(__pre_process_ngtsticks, args) |
| | | |
| | | |
| | | def __concat_pre_datas(dir_path): |
| | | """ |
| | | 拼接数据 |
| | | @param dir_path: |
| | | @return: |
| | | """ |
| | | combined_path = os.path.join(dir_path, 'combined.csv') |
| | | if os.path.exists(combined_path): |
| | | print("合并的目标文件已存在") |
| | | return |
| | | file_list = os.listdir(dir_path) |
| | | file_list.sort(key=lambda x: int(re.findall(r'\d+', x)[0])) |
| | | df_list = [] |
| | | for file in file_list: |
| | | df = pd.read_csv(os.path.join(dir_path, file)) |
| | | if df.empty: |
| | | continue |
| | | df["SecurityID"] = df["SecurityID"].apply(BigOrderDealParser.code_format) |
| | | df_list.append(df) |
| | | print("准备合并的文件数量:", len(df_list)) |
| | | |
| | | combined_df = pd.concat(df_list, ignore_index=True) |
| | | |
| | | print("合并完成,准备写入文件!") |
| | | # 保存结果 |
| | | combined_df.to_csv(combined_path, index=False) |
| | | print("写入文件完成!") |
| | | |
| | | |
| | | def concat_pre_transactions(dir_path): |
| | | __concat_pre_datas(dir_path) |
| | | |
| | | |
| | | def concat_pre_ngtsticks(dir_path): |
| | | __concat_pre_datas(dir_path) |
| | | |
| | | |
| | | def process_combined_transaction(dir_path): |
| | | """ |
| | | 处理拼接起来的数据 |
| | | @param dir_path: |
| | | @return: |
| | | """ |
| | | combined_path = os.path.join(dir_path, 'combined.csv') |
| | | if not os.path.exists(combined_path): |
| | | print("拼接数据不存在") |
| | | return |
| | | df = pd.read_csv(combined_path) |
| | | df_copy = df.copy() |
| | | grouped = df_copy.groupby(["SecurityID"]) |
| | | # 应用聚合函数 |
| | | chunk_result = grouped.apply(pd.Series({})) |
| | | # chunk_result["SecurityID"] = chunk_result["SecurityID"].apply(BigOrderDealParser.code_format) |
| | | print(chunk_result.to_string( |
| | | index=False, # 不显示索引 |
| | | justify='left', # 左对齐 |
| | | float_format='%.3f' # 浮点数格式 |
| | | )) |
| | | |
| | | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | # pre_process_transactions("E:/测试数据/Transaction_Test.csv") |
| | | # pre_process_ngtsticks("E:/测试数据/NGTSTick_Test.csv") |
| | | # concat_pre_transactions("E:/测试数据/Transaction_Test") |
| | | process_combined_transaction("E:/测试数据/Transaction_Test") |
| | |
| | | order_time = item[4] |
| | | |
| | | if self.accurate_buy: |
| | | self.add_transaction_data_for_accurate(item, big_order_money_threshold=big_order_money_threshold) |
| | | self.add_transaction_data_for_accurate(item, big_order_money_threshold=50e4) |
| | | |
| | | if not self.__latest_buy_order: |
| | | # (买单号, 量, 金额, 时间, 最新成交价格) |
| | |
| | | # mode: 0-普通交易 1-快速交易 |
| | | def __init__(self, buy_single_index=None, buy_exec_index=-1, buy_compute_index=None, num=0, count=0, |
| | | max_num_set=None, buy_volume_rate=None, sell_info=None, threshold_money=None, mode=0, mode_desc=None, |
| | | at_limit_up=False, first_limit_up_buy=False): |
| | | at_limit_up=False, first_limit_up_buy=False, min_order_no = None): |
| | | self.buy_single_index = buy_single_index |
| | | self.buy_exec_index = buy_exec_index |
| | | self.buy_compute_index = buy_compute_index |
| | |
| | | self.at_limit_up = at_limit_up |
| | | # 是否为首封买 |
| | | self.first_limit_up_buy = first_limit_up_buy |
| | | # 统计批次大单成交的最小订单号 |
| | | self.min_order_no = min_order_no |
| | | |
| | | def get_max_num_set(self): |
| | | if self.max_num_set: |
| | |
| | | """ |
| | | if code in cls.__human_radical_buy_mark_info: |
| | | return True |
| | | return False |
| | | |
| | | @classmethod |
| | | def is_valid(cls, code, data): |
| | |
| | | if code not in cls.__human_radical_buy_mark_info: |
| | | return False, "没有人买入信号" |
| | | single_time_ms, space_time_ms, expire_time_ms, _ = cls.__human_radical_buy_mark_info[code] |
| | | if tool.trade_time_sub_with_ms(L2DataUtil.get_time_with_ms(data["val"]), |
| | | now_time_ms = L2DataUtil.get_time_with_ms(data["val"]) |
| | | if tool.trade_time_sub_with_ms(now_time_ms, |
| | | expire_time_ms) > 0: |
| | | cls.__human_radical_buy_mark_info.pop(code) |
| | | async_log_util.info(logger_l2_not_buy_reasons, f"{code}#大单足够,人为下单: 超过信号生效时间-{now_time_ms}/{expire_time_ms}") |
| | | return False, "超过信号生效时间" |
| | | return True, cls.__human_radical_buy_mark_info[code] |
| | | |
| | |
| | | _start_time = tool.get_now_timestamp() |
| | | total_datas = local_today_datas[code] |
| | | |
| | | if not HumanRadicalBuySingleManager.has_single(code): |
| | | # ---------计算激进买入的信号--------- |
| | | radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index) |
| | | else: |
| | | human_radical_result = cls.__compute_human_radical_order_begin_pos(code, compute_start_index, |
| | | compute_end_index) |
| | | if human_radical_result[0]: |
| | | radical_result = list(human_radical_result[2]) |
| | | # 改变执行位置 |
| | | radical_result[1] = human_radical_result[1]["index"] |
| | | else: |
| | | radical_result = None |
| | | # 不需要根据人为下单来下单 |
| | | # if not HumanRadicalBuySingleManager.has_single(code): |
| | | # # ---------计算激进买入的信号--------- |
| | | # radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index) |
| | | # else: |
| | | # human_radical_result = cls.__compute_human_radical_order_begin_pos(code, compute_start_index, |
| | | # compute_end_index) |
| | | # l2_log.debug(code, f"大单足够,人为下单计算结果({compute_start_index}-{compute_end_index}):{human_radical_result}") |
| | | # if human_radical_result[0]: |
| | | # radical_result = list(human_radical_result[2]) |
| | | # # 改变执行位置 |
| | | # radical_result[1] = human_radical_result[1]["index"] |
| | | # else: |
| | | # radical_result = None |
| | | |
| | | radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index) |
| | | if radical_result and radical_result[0]: |
| | | |
| | | if not HumanRadicalBuySingleManager.has_single(code): |
| | | big_order_deal_enough_result = radical_buy_data_manager.is_big_order_deal_enough(code, |
| | | code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days( |
| | | code), 0) |
| | | if big_order_deal_enough_result[6] <= 0: |
| | | HumanRadicalBuySingleManager.add_single(code, total_datas[-1], radical_result) |
| | | async_log_util.info(logger_l2_not_buy_reasons, f"{code}#大单足够,需要根据人为下单") |
| | | return |
| | | # 下单前一步,移除人为下单信号 |
| | | is_human_radical_buy = HumanRadicalBuySingleManager.has_single(code) |
| | | HumanRadicalBuySingleManager.remove_single(code) |
| | | # if not HumanRadicalBuySingleManager.has_single(code): |
| | | # big_order_deal_enough_result = radical_buy_data_manager.is_big_order_deal_enough(code, |
| | | # code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days( |
| | | # code), 0) |
| | | # if big_order_deal_enough_result[6] <= 0: |
| | | # HumanRadicalBuySingleManager.add_single(code, total_datas[-1], radical_result) |
| | | # async_log_util.info(logger_l2_not_buy_reasons, f"{code}#大单足够,需要根据人为下单({compute_start_index}-{compute_end_index}):{radical_result[1]}") |
| | | # return |
| | | # #下单前一步,移除人为下单信号 |
| | | # is_human_radical_buy = HumanRadicalBuySingleManager.has_single(code) |
| | | # HumanRadicalBuySingleManager.remove_single(code) |
| | | |
| | | buy_single_index, buy_exec_index = radical_result[1], radical_result[1] |
| | | buy_volume_rate = cls.volume_rate_info[code][0] |
| | |
| | | max_num_set=set(), |
| | | buy_volume_rate=buy_volume_rate, |
| | | mode=OrderBeginPosInfo.MODE_RADICAL, |
| | | mode_desc=f"大单不足扫入:{radical_result[2]} 是否跟人买入-{is_human_radical_buy}", |
| | | mode_desc=f"大单不足扫入:{radical_result[2]}", |
| | | sell_info=sell_info, |
| | | threshold_money=threshold_money) |
| | | threshold_money=threshold_money, |
| | | min_order_no=radical_result[5] |
| | | ) |
| | | order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code) |
| | | ordered = cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index, |
| | | block_info=radical_result[3]) |
| | |
| | | @param code: |
| | | @param start_index: |
| | | @param end_index: |
| | | @return: (是否获取到信号, 信号位置, 扫入板块/消息, 扫入板块大单流入信息, 需要监听的大单) |
| | | @return: (是否获取到信号, 信号位置, 扫入板块/消息, 扫入板块大单流入信息, 需要监听的大单, 统计上板大单成交的最小订单号) |
| | | """ |
| | | |
| | | # 激进买信号的时间 |
| | | |
| | | def __can_order(): |
| | | # 判断是否是板上放量 |
| | | # if cls.__is_at_limit_up_buy(code, start_index): |
| | |
| | | single_index = i |
| | | break |
| | | if single_index is not None: |
| | | return True, single_index, f"有大单,大单情况:{big_order_deal_enough_result[1]}", watch_indexes |
| | | return False, None, f"大单不足:{trade_index}-{end_index} 缺少的大单-{max(current_lack_money, total_lack_money)} 大单情况:{big_order_deal_enough_result[1]}", watch_indexes |
| | | every_time_big_orders = EveryLimitupBigDealOrderManager.list_big_buy_deal_orders(code) |
| | | if every_time_big_orders: |
| | | min_order_no = min(min(every_time_big_orders, key=lambda e: e[0])[0], radical_data[1]) |
| | | else: |
| | | min_order_no = radical_data[1] |
| | | return True, single_index, f"有大单,大单情况:{big_order_deal_enough_result[1]}", watch_indexes, min_order_no |
| | | return False, None, f"大单不足:{trade_index}-{end_index} 缺少的大单-{max(current_lack_money, total_lack_money)} 大单情况:{big_order_deal_enough_result[1]}", watch_indexes, None |
| | | |
| | | radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code) |
| | | record_codes = radical_buy_data_manager.BlockPlaceOrderRecordManager().get_codes() |
| | |
| | | # 如果板上放量不可买入就需要删除信号 |
| | | if not constant.CAN_RADICAL_BUY_AT_LIMIT_UP and code in RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict: |
| | | RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.pop(code) |
| | | return True, result[1], radical_data[2], radical_data[4], result[3] |
| | | return True, result[1], radical_data[2], radical_data[4], result[3], result[4] |
| | | else: |
| | | async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{result[2]}") |
| | | return result |
| | |
| | | return False, None, "超过信号生效时间" |
| | | is_valid = False |
| | | # 判断距离上个50w买单的时间是否超过了space_time_ms |
| | | for ii in range(i - 1, -1, -1): |
| | | buy_exec_index = radical_result[1] |
| | | for ii in range(i - 1, buy_exec_index, -1): |
| | | data_child = total_datas[ii] |
| | | val_child = data_child["val"] |
| | | if not L2DataUtil.is_limit_up_price_buy(val_child): |
| | |
| | | @param end_index: |
| | | @return: 信号信息(信号位,执行位), 消息, 可买入的板块 |
| | | """ |
| | | if True: |
| | | return None, "此条不生效", None |
| | | if not tool.is_sz_code(code): |
| | | return None, "非深证的票", None |
| | | # 判断抛压是否大于5000w |
| | |
| | | |
| | | import pandas as pd |
| | | |
| | | from data_parser import transaction_big_order_parser |
| | | from db import mysql_data_delegate as mysql_data |
| | | from huaxin_client.l2_client_test import L2TransactionDataManager |
| | | from log_module import log_export |
| | |
| | | print(f"处理完毕,总共{index}批") |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | if __name__ == '__main__1': |
| | | # df = pd.read_csv(f"E:/测试数据/Transaction_Test.csv") |
| | | pre_process_transactions() |
| | | |
| | | # 命令模式 /home/userzjj/app/gp-server/l2_data_parser Transaction 2025-05-08 |
| | | # 解析大单: /home/userzjj/app/gp-server/l2_data_parser ExtractDealBigOrder 2025-05-09 /home/userzjj/最终成交数据20250509.txt 000555 |
| | | if __name__ == '__main__1': |
| | | if __name__ == '__main__': |
| | | if len(sys.argv) > 1: |
| | | params = sys.argv[1:] |
| | | print("接收的参数", params) |
| | |
| | | elif _type == 'MarketData': |
| | | parse_market_data(day) |
| | | elif _type == 'Transaction_New': |
| | | pre_process_transactions(f"/home/userzjj/ftp/{day}/Transaction.csv") |
| | | transaction_big_order_parser.pre_process_transactions(f"/home/userzjj/ftp/{day}/Transaction.csv") |
| | | transaction_big_order_parser.concat_pre_transactions(f"/home/userzjj/ftp/{day}/Transaction") |
| | | elif _type == 'NGTSTick_New': |
| | | pre_process_ngtstick(f"/home/userzjj/ftp/{day}/NGTSTick.csv") |
| | | transaction_big_order_parser.pre_process_ngtsticks(f"/home/userzjj/ftp/{day}/NGTSTick.csv") |
| | | transaction_big_order_parser.concat_pre_ngtsticks(f"/home/userzjj/ftp/{day}/NGTSTick") |
| | | elif _type == 'Transaction_Concat': |
| | | transaction_big_order_parser.concat_pre_transactions(f"/home/userzjj/ftp/{day}/Transaction") |
| | | elif _type == 'NGTSTick_Concat': |
| | | transaction_big_order_parser.concat_pre_ngtsticks(f"/home/userzjj/ftp/{day}/NGTSTick") |
| | | |
| | | |
| | | elif _type == 'ExtractDealBigOrder': |
| | | # 提取所有成交的大单 |
| | | if len(params) > 2: |
| | |
| | | if refer_sell_data: |
| | | sell_info = (refer_sell_data[0], refer_sell_data[1]) |
| | | threshold_money = 0 |
| | | every_deal_orders = EveryLimitupBigDealOrderManager.list_big_buy_deal_orders(code) |
| | | if every_deal_orders: |
| | | min_order_no = min(every_deal_orders, lambda x: x[0])[0] |
| | | else: |
| | | min_order_no = transaction_datas[-1][6] |
| | | |
| | | order_begin_pos_info = OrderBeginPosInfo(buy_single_index=buy_single_index, |
| | | buy_exec_index=buy_exec_index, |
| | | buy_compute_index=buy_exec_index, |
| | |
| | | max_num_set=set(), |
| | | buy_volume_rate=buy_volume_rate, |
| | | mode=OrderBeginPosInfo.MODE_RADICAL, |
| | | mode_desc=f"扫入买入:{buy_blocks}", |
| | | mode_desc=f"扫入买入:{buy_blocks}, 大单成交最小订单号:{min_order_no}", |
| | | sell_info=sell_info, |
| | | threshold_money=threshold_money) |
| | | threshold_money=threshold_money, |
| | | min_order_no= min_order_no |
| | | ) |
| | | L2TradeDataProcessor.save_order_begin_data(code, order_begin_pos_info) |
| | | buy_result = L2TradeDataProcessor.start_buy(code, total_datas[-1], total_datas[-1]["index"], |
| | | True, block_info=buy_blocks_with_money) |
| | |
| | | import constant |
| | | import l2_data_util |
| | | from code_attribute.code_volumn_manager import CodeVolumeManager |
| | | from l2 import l2_data_util as l2_data_util_new, l2_log |
| | | from l2 import l2_data_util as l2_data_util_new, l2_log, l2_data_manager |
| | | from code_attribute import code_nature_analyse, code_volumn_manager, gpcode_manager |
| | | from code_attribute.code_l1_data_manager import L1DataManager |
| | | from code_attribute.gpcode_manager import WantBuyCodesManager |
| | |
| | | @param count: |
| | | @return: |
| | | """ |
| | | cls.__process_add_white(code) |
| | | if gpcode_manager.MustBuyCodesManager().is_in_cache(code): |
| | | return |
| | | total_deal_big_order_result = get_total_deal_big_order_info(code, |
| | |
| | | @classmethod |
| | | def place_order_success(cls, code): |
| | | # 如果是加想,且成交大单足够就加红 |
| | | total_deal_big_order_result = get_total_deal_big_order_info(code, |
| | | gpcode_manager.get_limit_up_price_as_num(code)) |
| | | if WantBuyCodesManager().is_in_cache(code): |
| | | big_order_deal_enough_result = is_big_order_deal_enough(code, |
| | | code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days( |
| | | code), |
| | | 0) |
| | | if big_order_deal_enough_result[6] <= 0: |
| | | if total_deal_big_order_result[0] <= 0: |
| | | # 累计大单足够需要加红 |
| | | gpcode_manager.MustBuyCodesManager().add_code(code) |
| | | trade_record_log_util.add_must_buy(code, "累计成交大单足够") |
| | | cls.__process_add_white(code) |
| | | |
| | | @classmethod |
| | | def __process_add_white(cls, code): |
| | | """ |
| | | 处理加白 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if not constant.CAN_AUTO_ADD_WHITE: |
| | | return |
| | | if gpcode_manager.WhiteListCodeManager().is_in_cache(code): |
| | | return |
| | | try: |
| | | total_deal_big_order_result = get_total_deal_big_order_info(code, |
| | | gpcode_manager.get_limit_up_price_as_num(code)) |
| | | if total_deal_big_order_result[0] <= 0 and total_deal_big_order_result[2] >= 1e8: |
| | | # 1个亿以上的且本批次成交的大单金额大于2倍大单金额就加白 |
| | | order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code) |
| | | is_placed_order = l2_data_manager.TradePointManager.is_placed_order(order_begin_pos) |
| | | if not is_placed_order: |
| | | # 没有下过单 |
| | | return |
| | | if order_begin_pos and order_begin_pos.min_order_no is not None: |
| | | # 在 min_order_no 之后成交的大单金额 |
| | | total_buy_data_list = BigOrderDealManager().get_total_buy_data_list(code) |
| | | min_order_no = order_begin_pos.min_order_no |
| | | if min_order_no is None: |
| | | async_log_util.warning(logger_debug, "处理成交大单足够加白: 最小订单号为空") |
| | | return |
| | | bigger_money = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code), |
| | | tool.is_ge_code(code)) |
| | | deal_money = sum( |
| | | [x[2] for x in total_buy_data_list if x[0] >= min_order_no and x[2] >= bigger_money]) |
| | | # 获取均大单 |
| | | THRESHOLD_MONEY, is_temp_threshold_money = BeforeSubDealBigOrderManager().get_big_order_threshold_info( |
| | | code) |
| | | if deal_money >= 2 * THRESHOLD_MONEY: |
| | | gpcode_manager.WhiteListCodeManager().add_code(code) |
| | | trade_record_log_util.add_common_msg(code, "加白", f"{code}大单成交足够加白, 本批次成交金额-{deal_money}/{THRESHOLD_MONEY * 2} 累计大单金额:{total_deal_big_order_result[1]}/{total_deal_big_order_result[2]}") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | async_log_util.info(logger_debug, f"处理成交大单足够加白的问题:{str(e)}") |
| | | |
| | | @classmethod |
| | | def market_info_change(cls, code): |
| | |
| | | |
| | | @classmethod |
| | | def get_big_buy_deal_order_money_info(cls, code): |
| | | """ |
| | | 获取成交大单的信息 |
| | | @param code: |
| | | @return: (总共大单成交金额, 最近成交大单的最后成交时间) |
| | | """ |
| | | if cls.__deal_big_order_infos_dict.get(code): |
| | | return sum([x[1] for x in cls.__deal_big_order_infos_dict[code]]), l2_huaxin_util.convert_time( |
| | | cls.__deal_big_order_infos_dict[code][-1][2]) |
| | | return None |
| | | |
| | | @classmethod |
| | | def list_big_buy_deal_orders(cls, code): |
| | | """ |
| | | |
| | | @param code: |
| | | @return:[(订单号,金额, 最后成交时间)] |
| | | """ |
| | | return cls.__deal_big_order_infos_dict.get(code, []) |
| | | |
| | | |
| | | class EveryLimitupBigDelegateOrderManager: |
| | | """ |
| | |
| | | left_limit_up_sell_money = selling_num * price |
| | | |
| | | # 每次上板的大单与金额 |
| | | big_order_count = radical_buy_data_manager.EveryLimitupBigDealOrderManager().get_big_buy_deal_order_count(code) |
| | | big_order_money = radical_buy_data_manager.EveryLimitupBigDealOrderManager().get_big_buy_deal_order_money(code) |
| | | big_order_count = radical_buy_data_manager.EveryLimitupBigDealOrderManager.get_big_buy_deal_order_count(code) |
| | | big_order_money = radical_buy_data_manager.EveryLimitupBigDealOrderManager.get_big_buy_deal_order_money(code) |
| | | if big_order_count >= 2: |
| | | average_big_order_money = int(big_order_money / big_order_count) |
| | | # 如果均价涨幅小于7%均大单等于299w |
| | |
| | | from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer |
| | | from cancel_strategy.s_l_h_cancel_strategy import LCancelBigNumComputer |
| | | from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer |
| | | from code_attribute.gpcode_manager import MustBuyCodesManager, GreenListCodeManager, WantBuyCodesManager |
| | | from code_attribute.gpcode_manager import MustBuyCodesManager, GreenListCodeManager, WantBuyCodesManager, \ |
| | | WhiteListCodeManager |
| | | from l2 import l2_data_manager, place_order_single_data_manager |
| | | from l2.cancel_buy_strategy import FCancelBigNumComputer, \ |
| | | NewGCancelBigNumComputer, JCancelBigNumComputer, NBCancelBigNumComputer |
| | |
| | | |
| | | # 如果是扫入下单,下单之后就加红 |
| | | if order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL: |
| | | # 移除人为移白 |
| | | WhiteListCodeManager().clear_huamn_info(code) |
| | | RadicalBuyDataManager.place_order_success(code) |
| | | |
| | | # 清除下单信号 |