| | |
| | | total_num += val["num"] |
| | | |
| | | # 卖金额>=均大单才触发重新囊括 |
| | | THRESHOLD_MONEY, is_temp_threshold_money = radical_buy_data_manager.BeforeSubDealBigOrderManager().get_big_order_threshold_info( |
| | | code) |
| | | THRESHOLD_MONEY = radical_buy_data_manager.BeforeSubDealBigOrderManager().get_big_sell_order_threshold(code) |
| | | if total_deal_money >= THRESHOLD_MONEY: |
| | | l2_log.l_cancel_debug(code, "准备更新L后囊括(大卖单)") |
| | | start_order_no = big_sell_order_info[1][-1][4][1] |
New file |
| | |
| | | """ |
| | | 数据回调全局变量 |
| | | """ |
| | | |
| | | # L2交易信号回调 |
| | | from l2.place_order_single_data_manager import L2TradeSingleCallback |
| | | |
| | | l2_trade_single_callback:L2TradeSingleCallback = None |
| | |
| | | |
| | | # 统计所有的成交量 |
| | | __deal_volume_list_dict = {} |
| | | # 统计涨停主动买的成交量 |
| | | __deal_active_buy_volume_list_dict = {} |
| | | |
| | | @classmethod |
| | | def statistic_total_deal_volume(cls, code, fdatas, limit_up_price): |
| | | def statistic_active_sell_deal_volume(cls, code, fdatas, limit_up_price): |
| | | """ |
| | | 统计总共的成交量 |
| | | 统计主动卖成交 |
| | | @param code: |
| | | @param fdatas: [(数据本身, 是否主动买, 是否涨停, 总成交额, 不含ms时间,含ms时间)] |
| | | @param limit_up_price: |
| | |
| | | # 只统计被动买 |
| | | if code not in cls.__deal_volume_list_dict: |
| | | cls.__deal_volume_list_dict[code] = [] |
| | | |
| | | # 为了加速处理,如果第一条数据和最后一条数据都是主动买就返回 |
| | | if fdatas[0][1] and fdatas[-1][1]: |
| | | return |
| | | for d in fdatas: |
| | | # 只统计被动买 |
| | | if d[1]: |
| | |
| | | # 删除超过5条数据 |
| | | if len(cls.__deal_volume_list_dict[code]) > 5: |
| | | cls.__deal_volume_list_dict[code] = cls.__deal_volume_list_dict[code][-5:] |
| | | |
| | | try: |
| | | # 统计主动买的成交量 |
| | | if code not in cls.__deal_active_buy_volume_list_dict: |
| | | cls.__deal_active_buy_volume_list_dict[code] = [] |
| | | for d in fdatas: |
| | | # 只统计主动买 |
| | | if not d[1]: |
| | | continue |
| | | # 只统计涨停买 |
| | | if not d[2]: |
| | | continue |
| | | time_str = d[4] |
| | | if cls.__deal_active_buy_volume_list_dict[code]: |
| | | if cls.__deal_active_buy_volume_list_dict[code][-1][0] == time_str: |
| | | # 如果是同一秒 |
| | | cls.__deal_active_buy_volume_list_dict[code][-1][1] += d[0][2] |
| | | else: |
| | | # 不是同一秒 |
| | | cls.__deal_active_buy_volume_list_dict[code].append([time_str, d[0][2]]) |
| | | else: |
| | | cls.__deal_active_buy_volume_list_dict[code].append([time_str, d[0][2]]) |
| | | # 删除超过10条数据 |
| | | if len(cls.__deal_active_buy_volume_list_dict[code]) > 10: |
| | | cls.__deal_active_buy_volume_list_dict[code] = cls.__deal_active_buy_volume_list_dict[code][-10:] |
| | | except: |
| | | pass |
| | | |
| | | @classmethod |
| | | def get_latest_3s_continue_deal_volumes(cls, code): |
| | |
| | | fdatas.append(deal_list[i]) |
| | | return fdatas |
| | | |
| | | @classmethod |
| | | def get_latest_6s_active_buy_deal_volumes(cls, code): |
| | | """ |
| | | 获取最近6s的主动买成交 |
| | | @param code: |
| | | @return: [(时间,量)] |
| | | """ |
| | | deal_list = cls.__deal_active_buy_volume_list_dict.get(code) |
| | | if not deal_list: |
| | | return [] |
| | | latest_time = deal_list[-1][0] |
| | | fdatas = [] |
| | | # 从倒数第二个数据计算 |
| | | for i in range(len(deal_list) - 1, -1, -1): |
| | | if tool.trade_time_sub(latest_time, deal_list[i][0]) < 6: |
| | | fdatas.append(deal_list[i]) |
| | | return fdatas |
| | | |
| | | @classmethod |
| | | def clear_latest_deal_volume(cls, code): |
| | |
| | | |
| | | # 返回最近1s的大单卖:(总卖金额,[(卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)),...]) |
| | | @classmethod |
| | | def add_transaction_datas(cls, code, fdatas, limit_up_price=None): |
| | | def statistic_continue_limit_up_sell_transaction_datas(cls, code, fdatas, limit_up_price=None): |
| | | """ |
| | | 统计连续涨停卖成交的数据 |
| | | @param code: |
| | | @param fdatas: [(数据本身, 是否主动买, 是否涨停, 总成交额, 不含ms时间,含ms时间)] |
| | | @param limit_up_price: |
| | |
| | | |
| | | __start_time = time.time() |
| | | # 是否还有涨停卖剩下 |
| | | no_left_limit_up_sell = L2TradeSingleDataProcessor.process_passive_limit_up_sell_data(code, fdatas, |
| | | limit_up_price) |
| | | no_left_limit_up_sell = L2TradeSingleDataProcessor.process_passive_limit_up_sell_data(code, fdatas) |
| | | use_time = time.time() - __start_time |
| | | __start_time = time.time() |
| | | use_time_list.append(("处理涨停卖", use_time)) |
| | |
| | | from cancel_strategy.s_l_h_cancel_strategy import LCancelBigNumComputer, LCancelRateManager |
| | | from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer |
| | | from code_attribute import gpcode_manager |
| | | from l2 import l2_data_util, l2_data_manager, transaction_progress, l2_log |
| | | from l2 import l2_data_util, l2_data_manager, transaction_progress, l2_log, data_callback |
| | | from l2.cancel_buy_strategy import FCancelBigNumComputer, \ |
| | | NewGCancelBigNumComputer, \ |
| | | NBCancelBigNumComputer |
| | |
| | | from l2.l2_data_util import L2DataUtil |
| | | from l2.l2_limitup_sell_data_manager import L2LimitUpSellDataManager |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager, BigOrderDealManager |
| | | from l2.place_order_single_data_manager import L2TradeSingleDataProcessor |
| | | from log_module import async_log_util |
| | | from log_module.log import hx_logger_l2_debug, logger_l2_trade_buy_queue, logger_debug, hx_logger_l2_upload |
| | | from trade import current_price_process_manager, trade_constant |
| | |
| | | |
| | | # 计算成交进度 |
| | | @classmethod |
| | | def __compute_latest_trade_progress(cls, code, buyno_map, fdatas): |
| | | def __compute_latest_trade_progress(cls, code, fdatas): |
| | | buyno_map = l2_data_util.local_today_buyno_map.get(code) |
| | | if not buyno_map: |
| | | return None |
| | | buy_progress_index = None |
| | | for i in range(len(fdatas) - 1, -1, -1): |
| | | d = fdatas[i] |
| | |
| | | f2 = statistic_big_sell_data() |
| | | dask_result = statistic_big_data(f1, f2) |
| | | buy_datas, sell_datas = dask_result.compute() |
| | | if buy_datas or sell_datas: |
| | | buy_money = BigOrderDealManager().get_total_buy_money(code) |
| | | sell_money = BigOrderDealManager().get_total_sell_money(code) |
| | | LCancelRateManager.set_big_num_deal_info(code, buy_money, sell_money) |
| | | # L撤的比例与买卖大单无直接关系了 |
| | | # if buy_datas or sell_datas: |
| | | # buy_money = BigOrderDealManager().get_total_buy_money(code) |
| | | # sell_money = BigOrderDealManager().get_total_sell_money(code) |
| | | # LCancelRateManager.set_big_num_deal_info(code, buy_money, sell_money) |
| | | |
| | | @classmethod |
| | | def process_huaxin_transaction_datas(cls, code, o_datas): |
| | | # TODO 整形数据,格式:[(数据本身, 是否主动买, 是否涨停, 总成交额, 不含ms时间,含ms时间)] |
| | | # 整形数据,格式:[(数据本身, 是否主动买, 是否涨停, 总成交额, 不含ms时间,含ms时间)] |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'], |
| | | # data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], |
| | |
| | | is_placed_order = l2_data_manager.TradePointManager.is_placed_order(order_begin_pos) |
| | | |
| | | _start_time = time.time() |
| | | # 设置涨停卖成交数据 |
| | | L2LimitUpSellDataManager.set_deal_datas(code, fdatas) |
| | | use_time_list.append(("统计涨停卖成交", time.time() - _start_time)) |
| | | _start_time = time.time() |
| | |
| | | use_time_list.append(("统计大单数据", time.time() - _start_time)) |
| | | _start_time = time.time() |
| | | |
| | | big_sell_order_info = None |
| | | try: |
| | | # 统计上板时间 |
| | | try: |
| | |
| | | break |
| | | except: |
| | | pass |
| | | |
| | | big_sell_order_info = None |
| | | # 统计卖单 |
| | | big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, fdatas, limit_up_price) |
| | | big_sell_order_info = HuaXinSellOrderStatisticManager.statistic_continue_limit_up_sell_transaction_datas( |
| | | code, fdatas, |
| | | limit_up_price) |
| | | |
| | | use_time_list.append(("处理卖单成交数据", time.time() - _start_time)) |
| | | _start_time = time.time() |
| | |
| | | use_time_list.append(("处理卖单相关撤数据", time.time() - _start_time)) |
| | | _start_time = time.time() |
| | | # 统计涨停卖成交 |
| | | HuaXinSellOrderStatisticManager.statistic_total_deal_volume(code, fdatas, limit_up_price) |
| | | HuaXinSellOrderStatisticManager.statistic_active_sell_deal_volume(code, fdatas, limit_up_price) |
| | | use_time_list.append(("统计成交量数据", time.time() - _start_time)) |
| | | except Exception as e: |
| | | async_log_util.error(logger_debug, f"卖单统计异常:{big_sell_order_info}") |
| | |
| | | # if big_money_count > 0: |
| | | # LCancelRateManager.compute_big_num_deal_rate(code) |
| | | |
| | | buy_progress_index = cls.__compute_latest_trade_progress(code, buyno_map, fdatas) |
| | | buy_progress_index = cls.__compute_latest_trade_progress(code, fdatas) |
| | | |
| | | if buy_progress_index is not None: |
| | | buy_progress_index_changed = cls.__TradeBuyQueue.set_traded_index(code, buy_progress_index, |
| | |
| | | l2_log.info(code, hx_logger_l2_upload, |
| | | f"{code}处理成交用时:{use_time} 数据数量:{len(fdatas)} 详情:{use_time_list}") |
| | | |
| | | @classmethod |
| | | def process_huaxin_transaction_datas_v2(cls, code, o_datas): |
| | | """ |
| | | 新版处理华鑫成交数据: |
| | | 尚未下单的时候异步统计成交,同步遍历获取最后一个涨停卖委托数据,当最后一个涨停卖成交的时候就是下单时机 |
| | | @param code: |
| | | @param o_datas: |
| | | @return: |
| | | """ |
| | | |
| | | def __process_placed_order(): |
| | | """ |
| | | 处理处于下单状态的数据 |
| | | @return: |
| | | """ |
| | | try: |
| | | cls.statistic_big_order_infos(code, fdatas, order_begin_pos) |
| | | except Exception as e: |
| | | async_log_util.error(hx_logger_l2_debug, f"统计大单出错:{str(e)}") |
| | | # 统计连续的卖单数据,用于撤单,只有当下单之后才会执行 |
| | | big_sell_order_info = HuaXinSellOrderStatisticManager.statistic_continue_limit_up_sell_transaction_datas( |
| | | code, fdatas, |
| | | limit_up_price) |
| | | LCancelBigNumComputer().set_big_sell_order_info(code, big_sell_order_info) |
| | | need_cancel, cancel_msg = False, "" |
| | | cancel_type = None |
| | | if not need_cancel: |
| | | need_cancel, cancel_msg = FCancelBigNumComputer().need_cancel_for_p(code, |
| | | order_begin_pos) |
| | | cancel_type = trade_constant.CANCEL_TYPE_P |
| | | if need_cancel: |
| | | L2TradeDataProcessor.cancel_buy(code, cancel_msg, cancel_type=cancel_type) |
| | | # 统计涨停主动卖成交,为了F撤准备数据 |
| | | HuaXinSellOrderStatisticManager.statistic_active_sell_deal_volume(code, fdatas, limit_up_price) |
| | | # 计算成交进度 |
| | | buy_progress_index = cls.__compute_latest_trade_progress(code, fdatas) |
| | | if buy_progress_index is not None: |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | buy_progress_index_changed = cls.__TradeBuyQueue.set_traded_index(code, buy_progress_index, |
| | | total_datas) |
| | | async_log_util.info(logger_l2_trade_buy_queue, "获取成交位置成功: code-{} index-{}", code, |
| | | buy_progress_index) |
| | | if is_placed_order: |
| | | LCancelBigNumComputer().set_trade_progress(code, order_begin_pos.buy_single_index, |
| | | buy_progress_index, |
| | | total_datas) |
| | | cancel_result = FCancelBigNumComputer().need_cancel_for_deal_fast(code, buy_progress_index) |
| | | if cancel_result[0]: |
| | | L2TradeDataProcessor.cancel_buy(code, f"F撤:{cancel_result[1]}", |
| | | cancel_type=trade_constant.CANCEL_TYPE_F) |
| | | |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | # =====格式化数据===== |
| | | # 整形数据,格式:[(数据本身, 是否主动买, 是否涨停, 总成交额, 不含ms时间,含ms时间)] |
| | | fdatas = [ |
| | | [d, d[6] > d[7], limit_up_price == d[1], d[1] * d[2], '', ''] |
| | | for d in o_datas] |
| | | temp_time_dict = {} |
| | | for d in fdatas: |
| | | if d[0][3] not in temp_time_dict: |
| | | temp_time_dict[d[0][3]] = l2_huaxin_util.convert_time(d[0][3], with_ms=True) |
| | | d[5] = temp_time_dict.get(d[0][3]) |
| | | d[4] = d[5][:8] |
| | | temp_time_dict.clear() |
| | | |
| | | try: |
| | | |
| | | # ======需要同步处理的数据======== |
| | | # 设置成交价 |
| | | try: |
| | | current_price_process_manager.set_trade_price(code, fdatas[-1][0][1]) |
| | | if limit_up_price > fdatas[-1][0][1]: |
| | | # 没有涨停 |
| | | EveryLimitupBigDealOrderManager.open_limit_up(code, f"最新成交价:{fdatas[-1][0][1]}") |
| | | radical_buy_strategy.clear_data(code) |
| | | except: |
| | | pass |
| | | |
| | | # 统计上板时间 |
| | | try: |
| | | last_data = fdatas[-1] |
| | | if last_data[1] and last_data[2]: |
| | | # 涨停主动买 |
| | | current_price_process_manager.set_latest_not_limit_up_time(code, last_data[5]) |
| | | elif not last_data[1] and last_data[2]: |
| | | # 涨停主动卖 |
| | | if last_data[2]: |
| | | L2LimitUpSellDataManager.clear_data(code) |
| | | except: |
| | | pass |
| | | |
| | | # ==========处于委托状态就同步处理数据,没有下过单就异步处理数据========== |
| | | order_begin_pos = l2_data_manager.TradePointManager().get_buy_compute_start_data_cache(code) |
| | | is_placed_order = l2_data_manager.TradePointManager.is_placed_order(order_begin_pos) |
| | | if is_placed_order: |
| | | # 下过单了 |
| | | __process_placed_order() |
| | | else: |
| | | filter_datas = L2TradeSingleDataProcessor.filter_last_limit_up_sell_data(code, fdatas) |
| | | # 回调数据 |
| | | if filter_datas: |
| | | data_callback.l2_trade_single_callback.OnLastLimitUpSellDeal(code, filter_datas[0]) |
| | | |
| | | # 如果是被动买就更新成交进度 |
| | | if not fdatas[-1][1]: |
| | | buy_progress_index = cls.__compute_latest_trade_progress(code, fdatas) |
| | | if buy_progress_index is not None: |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | cls.__TradeBuyQueue.set_traded_index(code, buy_progress_index, |
| | | total_datas) |
| | | # 如果数据量大于20条就采用线程池更新数据 |
| | | if len(fdatas) >= 20: |
| | | cls.__statistic_thread_pool.submit(cls.statistic_big_order_infos, code, fdatas, order_begin_pos) |
| | | else: |
| | | cls.statistic_big_order_infos(code, fdatas, order_begin_pos) |
| | | except Exception as e: |
| | | hx_logger_l2_debug.exception(e) |
| | |
| | | """ |
| | | __latest_sell_data = {} |
| | | |
| | | # 最近的涨停卖委托列表 |
| | | __latest_limit_up_sell_list_dict = {} |
| | | |
| | | __latest_limit_up_sell_order_no_set_dict = {} |
| | |
| | | return len(sell_list) |
| | | |
| | | @classmethod |
| | | def process_passive_limit_up_sell_data(cls, code, fdatas, limit_up_price): |
| | | def process_passive_limit_up_sell_data(cls, code, fdatas): |
| | | """ |
| | | 添加涨停被动卖成交数据 |
| | | @param fdata: 数据格式:(data['SecurityID'], data['TradePrice'], data['TradeVolume'], |
| | |
| | | sell_list = cls.__latest_limit_up_sell_list_dict.get(code) |
| | | if not sell_list: |
| | | return False |
| | | sell_info = sell_list[-1] |
| | | last_sell_info = sell_list[-1] |
| | | for data in fdatas: |
| | | # 过滤被动买 |
| | | if not data[1]: |
| | |
| | | # 排除主动卖/非涨停卖 |
| | | continue |
| | | sell_no = data[0][7] |
| | | if sell_no != sell_info['val']['orderNo']: |
| | | if sell_no != last_sell_info['val']['orderNo']: |
| | | continue |
| | | # 需要判断当前单是否已经成交完成 |
| | | if code not in cls.__latest_sell_data: |
| | |
| | | cls.__latest_sell_data[code][1] += data[0][2] |
| | | else: |
| | | cls.__latest_sell_data[code] = [sell_no, data[0][2]] |
| | | sell_info_num = sell_info['val']['num'] |
| | | sell_info_num = last_sell_info['val']['num'] |
| | | deal_num = cls.__latest_sell_data[code][1] // 100 |
| | | if sell_info_num == deal_num: |
| | | use_time = round((time.time() - start_time) * 1000, 3) |
| | | l2_log.info(code, logger_l2_trade_buy, |
| | | f"找到最近的被动涨停卖单数据:{sell_info['val']['orderNo']}, 成交数据:{data} 计算耗时:{use_time}ms, 可以触发下单") |
| | | f"找到最近的被动涨停卖单数据:{last_sell_info['val']['orderNo']}, 成交数据:{data} 计算耗时:{use_time}ms, 可以触发下单") |
| | | |
| | | # 将历史大单列表与最近的大单加入列表 |
| | | big_buy_order_datas = [] |
| | |
| | | # 涨停主动卖已经被吃完,可以清除 |
| | | return True |
| | | break |
| | | # l2_log.info(code, logger_l2_trade_buy, f"找到最近的被动涨停卖单数据:{data['val']['orderNo']}, 可以触发下单") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | return False |
| | | |
| | | @classmethod |
| | | def filter_last_limit_up_sell_data(cls, code, fdatas): |
| | | """ |
| | | 筛选出最后一条涨停卖成交数据 |
| | | @param code: |
| | | @param fdatas: |
| | | @return: (成交数据, 卖单数据) |
| | | """ |
| | | sell_list = cls.__latest_limit_up_sell_list_dict.get(code) |
| | | if not sell_list: |
| | | return None |
| | | last_sell_info = sell_list[-1] |
| | | for data in fdatas: |
| | | if not data[2]: |
| | | # 排除主动卖/非涨停卖 |
| | | continue |
| | | sell_no = data[0][7] |
| | | if sell_no != last_sell_info['val']['orderNo']: |
| | | continue |
| | | # 需要判断当前单是否已经成交完成 |
| | | if code not in cls.__latest_sell_data: |
| | | cls.__latest_sell_data[code] = [sell_no, data[0][2]] |
| | | else: |
| | | if cls.__latest_sell_data[code][0] == sell_no: |
| | | cls.__latest_sell_data[code][1] += data[0][2] |
| | | else: |
| | | cls.__latest_sell_data[code] = [sell_no, data[0][2]] |
| | | sell_info_num = last_sell_info['val']['num'] |
| | | deal_num = cls.__latest_sell_data[code][1] // 100 |
| | | if sell_info_num == deal_num: |
| | | # 最后一笔涨停卖已经成交完成 |
| | | l2_log.info(code, logger_l2_trade_buy, |
| | | f"找到最近的被动涨停卖单数据:{last_sell_info}, 成交数据:{data} 可以触发下单") |
| | | return data, last_sell_info |
| | | return None |
| | | |
| | | @classmethod |
| | | def add_active_limit_up_sell_data(cls, data): |
| | |
| | | @return: |
| | | """ |
| | | |
| | | def OnLastLimitUpSellDeal(self, code, data): |
| | | """ |
| | | 最后一笔涨停卖成交 |
| | | @param code: 代码 |
| | | @param data: 成交的数据 |
| | | @return: |
| | | """ |
| | | |
| | | |
| | | class L2TradeSingleDataManager: |
| | | __callback = None |
| | |
| | | from huaxin_client import l2_data_transform_protocol |
| | | from huaxin_client.trade_transform_protocol import TradeResponse |
| | | from l2 import l2_data_manager_new, l2_log, code_price_manager, l2_data_util, transaction_progress, \ |
| | | l2_data_source_util, l2_data_log |
| | | l2_data_source_util, l2_data_log, data_callback |
| | | from l2.cancel_buy_strategy import GCancelBigNumComputer, \ |
| | | DCancelBigNumComputer, RDCancelBigNumComputer |
| | | from l2.code_price_manager import Buy1PriceManager |
| | |
| | | from log_module import async_log_util, log_export |
| | | from log_module.log import hx_logger_contact_debug, hx_logger_trade_callback, \ |
| | | hx_logger_l2_orderdetail, hx_logger_l2_market_data, logger_l2_g_cancel, logger_debug, \ |
| | | logger_system, logger_trade, logger_l2_radical_buy, logger_l2_not_buy_reasons |
| | | logger_system, logger_trade, logger_l2_radical_buy |
| | | from third_data import block_info, kpl_data_manager, history_k_data_manager, huaxin_l1_data_manager, kpl_api, kpl_util |
| | | from third_data.code_plate_key_manager import KPLCodeJXBlockManager, CodePlateKeyBuyManager, RealTimeKplMarketData, \ |
| | | from third_data.code_plate_key_manager import KPLCodeJXBlockManager, RealTimeKplMarketData, \ |
| | | KPLPlateForbiddenManager |
| | | from third_data.history_k_data_util import JueJinApi, HistoryKDatasUtils |
| | | from third_data.kpl_limit_up_data_manager import LatestLimitUpBlockManager |
| | | from trade import l2_trade_util, \ |
| | | trade_data_manager, trade_constant, buy_open_limit_up_strategy |
| | | from trade.buy_radical import radical_buy_data_manager, radical_buy_strategy |
| | |
| | | def l2_transaction(cls, code, datas): |
| | | # async_log_util.info(hx_logger_l2_transaction, f"{code}#{datas}") |
| | | if datas: |
| | | HuaXinTransactionDatasProcessor().process_huaxin_transaction_datas(code, datas) |
| | | HuaXinTransactionDatasProcessor().process_huaxin_transaction_datas_v2(code, datas) |
| | | |
| | | @classmethod |
| | | def l2_market_data(cls, code, data): |
| | |
| | | l2_log.info(code, logger_debug, f"扫入处理时长:{code}-{use_time}") |
| | | |
| | | def OnLimitUpActiveBuy(self, code, transaction_datas, no_left_limit_up_sell): |
| | | can_clear_before_data = self.process_limit_up_active_buy(code, transaction_datas, |
| | | no_left_limit_up_sell=no_left_limit_up_sell) |
| | | if can_clear_before_data: |
| | | # 清除 |
| | | EveryLimitupBigDealOrderManager.clear(code, "处理涨停成交数据") |
| | | # can_clear_before_data = self.process_limit_up_active_buy(code, transaction_datas, |
| | | # no_left_limit_up_sell=no_left_limit_up_sell) |
| | | # if can_clear_before_data: |
| | | # # 清除 |
| | | # EveryLimitupBigDealOrderManager.clear(code, "处理涨停成交数据") |
| | | pass |
| | | |
| | | def OnLastLimitUpSellDeal(self, code, data): |
| | | """ |
| | | 最后一笔涨停卖数据成交 |
| | | @param code: |
| | | @param data: (data['SecurityID'], data['TradePrice'], data['TradeVolume'], data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], data['SellNo'], data['ExecType']) |
| | | @return: |
| | | """ |
| | | if data[6] < data[7]: |
| | | # 非主动买 |
| | | return |
| | | # 根据板块判断是否可买 |
| | | state = CodesTradeStateManager().get_trade_state_cache(code) |
| | | if not trade_util.is_can_order_by_state(state): |
| | | # 不处于可下单状态 |
| | | return |
| | | |
| | | l2_log.info(code, logger_l2_radical_buy, f"最后一笔涨停卖被吃:{code}-{data}") |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | # 判断今日扫入的代码数量是否大于阈值 |
| | | radical_buy_setting = BuyMoneyAndCountSetting().get_radical_buy_setting() |
| | | MAX_COUNT = 4 if radical_buy_setting is None else radical_buy_setting[0] |
| | | if not WantBuyCodesManager().is_in_cache(code): |
| | | # 加绿不判断板块是否成交 |
| | | if len(deal_codes) >= MAX_COUNT: |
| | | l2_log.info(code, logger_l2_radical_buy, f"扫入成交代码个数大于{MAX_COUNT}个:{code}-{deal_codes}") |
| | | return |
| | | if code in deal_codes: |
| | | l2_log.info(code, logger_l2_radical_buy, f"该代码已经成交:{code}") |
| | | return |
| | | |
| | | # 单票是否可买 |
| | | can_buy_result = RadicalBuyDataManager.is_code_can_buy(code) |
| | | if not can_buy_result[0]: |
| | | return |
| | | # 获取激进买的板块 |
| | | f_buy_blocks, orgin_buy_blocks = radical_buy_strategy.compute_can_radical_buy_blocks(code, deal_codes) |
| | | if not orgin_buy_blocks: |
| | | l2_log.info(code, logger_l2_radical_buy, f"没有可扫入的板块:{code}") |
| | | return |
| | | |
| | | if not f_buy_blocks: |
| | | return |
| | | # 买入的板块 |
| | | buy_blocks = f_buy_blocks |
| | | # 判断当前时间段是否可以买入 |
| | | mode = OrderBeginPosInfo.MODE_RADICAL |
| | | can_buy, money, msg = BuyMoneyUtil.get_buy_data(tool.get_now_time_str(), mode, |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes_info( |
| | | mode), |
| | | DealAndDelegateWithBuyModeDataManager().get_delegates_codes_info( |
| | | mode)) |
| | | if not can_buy: |
| | | l2_log.info(code, logger_l2_radical_buy, f"当前时间段已不能扫入:{code}-{msg}") |
| | | return |
| | | |
| | | in_blocks = RealTimeKplMarketData.get_top_market_jingxuan_blocks() |
| | | buy_blocks_with_money = [(b, RealTimeKplMarketData.get_jx_block_in_money(b), |
| | | in_blocks.index(b) if b in in_blocks else -1) for b in buy_blocks] |
| | | if not WantBuyCodesManager().is_in_cache(code): |
| | | # 判断是否开得太高 |
| | | open_price = L1DataManager.get_open_price(code) |
| | | if not radical_buy_strategy.is_can_buy_with_open_price(code, open_price): |
| | | l2_log.info(code, logger_l2_radical_buy, f"开得太高:{code}") |
| | | radical_buy_data_manager.ExcludeIndexComputeCodesManager.add_code(code) |
| | | return |
| | | radical_buy_data_manager.ExcludeIndexComputeCodesManager.remove_code(code) |
| | | |
| | | # 根据L2下单 |
| | | latest_buy_no = data[6] |
| | | latest_deal_time = l2_huaxin_util.convert_time(data[3]) |
| | | |
| | | RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict[code] = ( |
| | | time.time() + 1, latest_buy_no, buy_blocks, |
| | | latest_deal_time, buy_blocks_with_money, False) |
| | | |
| | | |
| | | # 回调 |
| | |
| | | # L2成交信号回调 |
| | | global l2_trade_single_callback |
| | | l2_trade_single_callback = MyL2TradeSingleCallback() |
| | | data_callback.l2_trade_single_callback = l2_trade_single_callback |
| | | |
| | | L2TradeSingleDataManager.set_callback(l2_trade_single_callback) |
| | | # 加载自由流通量 |