| | |
| | | from log_module.log import logger_l2_trade_buy, logger_l2_process, logger_l2_error, logger_debug, \ |
| | | logger_l2_not_buy_reasons, logger_real_place_order_position, logger_l2_trade_buy_queue |
| | | |
| | | from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager, AccountMoneyManager |
| | | from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager, AccountMoneyManager, \ |
| | | RadicalBuyDealCodesManager |
| | | |
| | | from trade.trade_manager import TradeTargetCodeModeManager |
| | | |
| | |
| | | # 不处于可下单状态 |
| | | return False |
| | | __start_time = tool.get_now_timestamp() |
| | | order_begin_pos = cls.__get_order_begin_pos( |
| | | code) |
| | | |
| | | if order_begin_pos.MODE_RADICAL == order_begin_pos.mode: |
| | | # 激进下单不判断条件 |
| | | can, need_clear_data, reason, is_valid_exec_index = True, False, "激进下单", True |
| | | else: |
| | | can, need_clear_data, reason, is_valid_exec_index = cls.__can_buy_first(code) |
| | | |
| | | # __start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - __start_time, "最后判断是否能下单", force=True) |
| | | # 删除虚拟下单 |
| | | if code in cls.unreal_buy_dict: |
| | | cls.unreal_buy_dict.pop(code) |
| | | |
| | | order_begin_pos = cls.__get_order_begin_pos( |
| | | code) |
| | | if not can: |
| | | if not is_valid_exec_index: |
| | | if cls.__latest_exec_indexes.get(code) and cls.__latest_exec_indexes[code][ |
| | |
| | | return True, "" |
| | | |
| | | @classmethod |
| | | def __is_on_limit_up_buy(cls, code, buy_exec_index): |
| | | total_data = local_today_datas.get(code) |
| | | latest_exec_indexes = cls.__latest_exec_indexes[code] |
| | | if not latest_exec_indexes: |
| | | latest_exec_indexes = [] |
| | | # 判断是否是炸开后买入 |
| | | last_exec_index = 0 |
| | | if len(latest_exec_indexes) > 1: |
| | | last_exec_index = latest_exec_indexes[-2] |
| | | # 获取最近的非涨停价成交时间 |
| | | not_limit_up_trade_time_with_ms = current_price_process_manager.get_trade_not_limit_up_time_with_ms( |
| | | code) |
| | | is_limit_up_buy = True |
| | | if not_limit_up_trade_time_with_ms: |
| | | t1 = int( |
| | | L2DataUtil.get_time_with_ms(total_data[last_exec_index]["val"]).replace(":", "").replace(".", |
| | | "")) |
| | | t2 = int(not_limit_up_trade_time_with_ms.replace(":", "").replace(".", "")) |
| | | t3 = int(L2DataUtil.get_time_with_ms(total_data[buy_exec_index]["val"]).replace(":", "").replace( |
| | | ".", "")) |
| | | if t1 < t2 <= t3: |
| | | # 炸板时间在两次下单时间中间 |
| | | is_limit_up_buy = False |
| | | return is_limit_up_buy |
| | | |
| | | @classmethod |
| | | def __can_buy_first(cls, code): |
| | | """ |
| | | 是否可以下单 |
| | |
| | | # 1.当前成交价为涨停价 |
| | | # 2.距离最近的非板上成交的时间大于一个阈值 |
| | | if abs(limit_up_price - float(trade_price)) < 0.001: |
| | | latest_exec_indexes = cls.__latest_exec_indexes[code] |
| | | if not latest_exec_indexes: |
| | | latest_exec_indexes = [] |
| | | # 判断是否是炸开后买入 |
| | | last_exec_index = 0 |
| | | if len(latest_exec_indexes) > 1: |
| | | last_exec_index = latest_exec_indexes[-2] |
| | | is_limit_up_buy = cls.__is_on_limit_up_buy(code, order_begin_pos.buy_exec_index) |
| | | if is_limit_up_buy: |
| | | # 板上买且非加绿 |
| | | # 获取最近的非涨停价成交时间 |
| | | not_limit_up_trade_time_with_ms = current_price_process_manager.get_trade_not_limit_up_time_with_ms( |
| | | code) |
| | | |
| | | is_limit_up_buy = True |
| | | if not_limit_up_trade_time_with_ms: |
| | | t1 = int( |
| | | L2DataUtil.get_time_with_ms(total_data[last_exec_index]["val"]).replace(":", "").replace(".", |
| | | "")) |
| | | t2 = int(not_limit_up_trade_time_with_ms.replace(":", "").replace(".", "")) |
| | | t3 = int(L2DataUtil.get_time_with_ms(total_data[order_begin_pos.buy_exec_index]["val"]).replace(":", |
| | | "").replace( |
| | | ".", "")) |
| | | if t1 < t2 <= t3: |
| | | # 炸板时间在两次下单时间中间 |
| | | is_limit_up_buy = False |
| | | if is_limit_up_buy: |
| | | # 板上买且非加绿 |
| | | |
| | | # 判断成交进度到当前数据的笔数,如果少于10笔且还有未成交的大单(>=299)就可以下单 |
| | | trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code) |
| | | if trade_index is None: |
| | |
| | | start = None |
| | | return None |
| | | |
| | | # 计算激进买的下单信号 |
| | | # 计算积极买的下单信号 |
| | | @classmethod |
| | | def __compute_active_order_begin_pos(cls, code, continue_count, start_index, end_index): |
| | | """ |
| | |
| | | |
| | | return False, -1, "未获取到激进买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL |
| | | |
| | | # 计算激进买的下单信号 |
| | | @classmethod |
| | | def __compute_radical_order_begin_pos(cls, code, start_index, end_index): |
| | | """ |
| | | 计算激进买入信号: |
| | | 1.非板上放量 |
| | | 2.检测到299万大单买入 |
| | | @param code: |
| | | @param start_index: |
| | | @param end_index: |
| | | @return: (是否获取到信号, 信号位置) |
| | | """ |
| | | # 激进买信号的时间 |
| | | |
| | | |
| | | radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code) |
| | | if not radical_data: |
| | | return False, None, "不满足激进买的条件" |
| | | if t.time() > radical_data[0]: |
| | | return False, None, "超过生效时间" |
| | | |
| | | |
| | | # 判断是否是板上放量 |
| | | if cls.__is_on_limit_up_buy(code, start_index): |
| | | return False, None, "板上放量" |
| | | total_datas = local_today_datas[code] |
| | | min_num = int(29900 / gpcode_manager.get_limit_up_price_as_num(code)) |
| | | single_index = None |
| | | for i in range(start_index, end_index + 1): |
| | | data = total_datas[i] |
| | | val = data["val"] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | if val["num"] < min_num: |
| | | continue |
| | | if int(val["orderNo"]) <= radical_data[1]: |
| | | # 主动买单后的数据不算 |
| | | continue |
| | | single_index = i |
| | | break |
| | | if single_index is not None: |
| | | return True, single_index, "有大单" |
| | | return False, None, "无大单" |
| | | |
| | | @classmethod |
| | | def test__compute_active_order_begin_pos(cls, code, continue_count, start_index, end_index): |
| | | return cls.__compute_active_order_begin_pos(code, continue_count, start_index, end_index) |