| | |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2.huaxin import l2_huaxin_util, huaxin_delegate_postion_manager |
| | | from l2.l2_sell_manager import L2MarketSellManager |
| | | from l2.transaction_progress import TradeBuyQueue |
| | | from log_module import async_log_util, log_export |
| | | from third_data import kpl_data_manager, block_info |
| | | from utils import global_util, ths_industry_util, tool |
| | |
| | | class L2TradeDataProcessor: |
| | | unreal_buy_dict = {} |
| | | volume_rate_info = {} |
| | | # 最近的闪电下单位置,格式为{code:(总卖时间,总卖额)} |
| | | __latest_fast_place_order_info_dict = {} |
| | | __codeActualPriceProcessor = CodeActualPriceProcessor() |
| | | __ths_l2_trade_queue_manager = trade_queue_manager.thsl2tradequeuemanager() |
| | | __thsBuy1VolumnManager = trade_queue_manager.THSBuy1VolumnManager() |
| | |
| | | cls.unreal_buy_dict[code] = (buy_exec_index, capture_time) |
| | | trade_result_manager.virtual_buy_success(code) |
| | | |
| | | # 是否是在板上买 |
| | | @classmethod |
| | | def __is_at_limit_up_buy(cls, code_): |
| | | # 总卖为0,当前成交价为涨停价就判断为板上买 |
| | | current_sell_data = cls.__L2MarketSellManager.get_current_total_sell_data(code_) |
| | | if current_sell_data and tool.trade_time_sub(tool.get_now_time_str(), current_sell_data[0]) < 5: |
| | | # 5s内的数据才有效 |
| | | if current_sell_data[1] <= 0: |
| | | # 总卖为0 |
| | | trade_price = current_price_process_manager.get_trade_price(code_) |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code_) |
| | | if trade_price and limit_up_price and abs(float(trade_price) - float(limit_up_price)) <= 0.001: |
| | | # 当前成交价为涨停价 |
| | | return True |
| | | return False |
| | | |
| | | @classmethod |
| | | def __start_compute_buy(cls, code, compute_start_index, compute_end_index, threshold_money, capture_time, |
| | | is_first_code, |
| | | new_add=True): |
| | | |
| | | if compute_end_index < compute_start_index: |
| | | return |
| | | |
| | |
| | | _index = None |
| | | buy_single_index = _index |
| | | if has_single: |
| | | # 判断是否是板上买 |
| | | order_begin_pos.at_limit_up = cls.__is_at_limit_up_buy(code) |
| | | # -------------计算信号位到成交位的纯买额(过远则为无效位置)------------------- |
| | | if order_begin_pos.at_limit_up: |
| | | # 获取成交进度位置 |
| | | trade_index, is_default = TradeBuyQueue().get_traded_index(code) |
| | | if trade_index and not is_default: |
| | | m_base_val = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | thresh_hold_num = m_base_val // (float(gpcode_manager.get_limit_up_price(code)) * 100) |
| | | # 真实下单位到成交位置的纯买额 |
| | | total_num = 0 |
| | | for i in range(trade_index + 1, order_begin_pos.buy_single_index): |
| | | data = total_datas[i] |
| | | val = data["val"] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( |
| | | code, |
| | | data["index"], |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | total_num += left_count * val["num"] |
| | | if total_num > thresh_hold_num: |
| | | break |
| | | if total_num > thresh_hold_num: |
| | | # 距离成交进度位置过远 |
| | | l2_log.debug(code, |
| | | f"获取的信号位无效(板上买,范围:{trade_index + 1}-{order_begin_pos.buy_single_index} 未成交总手{total_num}/阈值{thresh_hold_num})") |
| | | return None |
| | | |
| | | cls.__last_buy_single_dict[code] = buy_single_index |
| | | new_get_single = True |
| | | order_begin_pos.num = 0 |
| | |
| | | # 暂时打8折 |
| | | order_begin_pos.threshold_money = int(sell_info[1] * 0.8) |
| | | # 深证总卖大于1000万的票,m值打5折 |
| | | if code.find('00')==0 and sell_info[1] > 1000*10000: |
| | | if code.find('00') == 0 and sell_info[1] > 1000 * 10000: |
| | | order_begin_pos.threshold_money = int(sell_info[1] * 0.5) |
| | | l2_log.debug(code, "获取到买入信号起始点:{} ,计算范围:{}-{} ,量比:{},数据:{} 模式:{}({})", buy_single_index, |
| | | l2_log.debug(code, "获取到买入信号起始点:{} ,计算范围:{}-{} ,量比:{},是否板上买:{},数据:{} 模式:{}({})", buy_single_index, |
| | | compute_start_index, |
| | | compute_end_index, cls.volume_rate_info[code], total_datas[buy_single_index], |
| | | compute_end_index, cls.volume_rate_info[code], order_begin_pos.at_limit_up, |
| | | total_datas[buy_single_index], |
| | | order_begin_pos.mode, fast_msg) |
| | | |
| | | # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "下单信号计算时间") |
| | |
| | | order_begin_pos.count, |
| | | threshold_money, |
| | | order_begin_pos.buy_single_index, |
| | | order_begin_pos.max_num_set) |
| | | order_begin_pos.max_num_set, |
| | | order_begin_pos.at_limit_up) |
| | | l2_log.debug(code, "m值-{} 量比:{} rebegin_buy_pos:{}", threshold_money, cls.volume_rate_info[code][0], |
| | | rebegin_buy_pos) |
| | | |
| | |
| | | return |
| | | |
| | | if new_buy_exec_index is not None: |
| | | l2_log.debug(code, "获取到买入执行位置:{} m值:{} 纯买手数:{} 纯买单数:{} 数据:{} ,量比:{} ,下单模式:{}", new_buy_exec_index, |
| | | l2_log.debug(code, "获取到买入执行位置:{} m值:{} 纯买手数:{} 纯买单数:{} 是否板上买:{} 数据:{} ,量比:{} ,下单模式:{}", new_buy_exec_index, |
| | | threshold_money, |
| | | buy_nums, |
| | | buy_count, total_datas[new_buy_exec_index], cls.volume_rate_info[code], order_begin_pos.mode) |
| | | buy_count, order_begin_pos.at_limit_up, total_datas[new_buy_exec_index], cls.volume_rate_info[code], order_begin_pos.mode) |
| | | cls.__save_order_begin_data(code, OrderBeginPosInfo(buy_single_index=buy_single_index, |
| | | buy_exec_index=new_buy_exec_index, |
| | | buy_compute_index=new_buy_exec_index, |
| | |
| | | l2_log.debug(code, "delete_buy_cancel_point") |
| | | # 直接下单 |
| | | ordered = cls.__buy(code, capture_time, total_datas[-1], total_datas[-1]["index"], is_first_code) |
| | | |
| | | # 保存闪电下单的买入信息 |
| | | if order_begin_pos.mode == OrderBeginPosInfo.MODE_FAST: |
| | | cls.__latest_fast_place_order_info_dict[code] = (order_begin_pos.sell_info[0], order_begin_pos.sell_info[1]) |
| | | |
| | | # 数据是否处理完毕 |
| | | if new_buy_exec_index < compute_end_index: |
| | |
| | | # 统计买入净买量,不计算在买入信号之前的买撤单 |
| | | @classmethod |
| | | def __sum_buy_num_for_order_3(cls, code, compute_start_index, compute_end_index, origin_num, origin_count, |
| | | threshold_money, buy_single_index, max_num_set): |
| | | threshold_money, buy_single_index, max_num_set, at_limit_up=False): |
| | | _start_time = t.time() |
| | | total_datas = local_today_datas[code] |
| | | # is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code) |
| | |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if limit_up_price is None: |
| | | raise Exception("涨停价无法获取") |
| | | # 目标手数 |
| | | threshold_num = round(threshold_money / (limit_up_price * 100)) |
| | | |
| | | threshold_num = None |
| | | # 大目标手数(满足这个就不需要看安全笔数) |
| | | threshold_max_num = int(threshold_num * 1.2) |
| | | threshold_max_num = None |
| | | # ----------------调整板上下单的m值与安全笔数---------------- |
| | | if at_limit_up: |
| | | # 板上买,获取最近一次闪电下单的总卖额 |
| | | sell_data = cls.__latest_fast_place_order_info_dict.get(code) |
| | | if sell_data: |
| | | # 有过闪电下单 |
| | | # 总卖的一半作为m值 |
| | | threshold_num = int(sell_data[1] / (limit_up_price * 100)) // 2 |
| | | threshold_max_num = 0 |
| | | |
| | | if not threshold_num: |
| | | # 目标手数 |
| | | threshold_num = round(threshold_money / (limit_up_price * 100)) |
| | | if not threshold_max_num: |
| | | threshold_max_num = int(threshold_num * 1.2) |
| | | |
| | | # place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) |
| | | # 目标订单数量 |