| | |
| | | |
| | | def cancel_success(self, code): |
| | | self.clear(code) |
| | | # 撤单成功之后就清除当前的成交 |
| | | HuaXinSellOrderStatisticManager.clear_latest_deal_volume(code) |
| | | |
| | | def __get_fast_deal_threshold_value(self, code, place_order_time_str): |
| | | """ |
| | |
| | | try: |
| | | if code in self.__max_buy_order_num_cache: |
| | | max_num = self.__max_buy_order_num_cache[code] |
| | | total_num, details = HuaXinSellOrderStatisticManager.get_latest_2s_continue_deal_volume(code) |
| | | if total_num // 100 > max_num * 0.6: |
| | | return True, f"连续两秒抛压过大:{total_num // 100}/{max_num}手" |
| | | details = HuaXinSellOrderStatisticManager.get_latest_3s_continue_deal_volumes(code) |
| | | threshold_num = int(max_num * 0.5 * 100) |
| | | count = 0 |
| | | for d in details: |
| | | if d[1] > threshold_num: |
| | | count += 1 |
| | | if count >= 2: |
| | | return True, f"连续3秒有2s抛压过大:{details} 最大值:{max_num}" |
| | | except Exception as e: |
| | | l2_log.f_cancel_debug(code,f"大抛压撤单计算出错:{str(e)}") |
| | | l2_log.f_cancel_debug(code, f"大抛压撤单计算出错:{str(e)}") |
| | | |
| | | # 查询最近2秒成交是否超过阈值 |
| | | |
| | |
| | | |
| | | # 是否是下单3分钟内 |
| | | sub_time = tool.trade_time_sub(total_datas[-1]['val']['time'], total_datas[real_order_index]['val']['time']) |
| | | if sub_time > 180: |
| | | return False, "下单超过180s" |
| | | if sub_time > 30: |
| | | return False, "下单超过30s" |
| | | |
| | | if sub_time < 2: |
| | | if sub_time <= 2: |
| | | return False, "下单在2s内" |
| | | |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | |
| | | 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, L2LimitUpSellManager |
| | | from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager |
| | | from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager, BigOrderDealManager |
| | | 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 |
| | |
| | | cls.__process_order(code, start_index, end_index, capture_timestamp, is_first_code) |
| | | else: |
| | | # 未挂单,时间相差不大才能挂单 |
| | | if tool.trade_time_sub(latest_time, "09:32:00") < 0 or l2.l2_data_util.L2DataUtil.is_same_time( |
| | | # tool.trade_time_sub(latest_time, "09:32:00") < 0 |
| | | if l2.l2_data_util.L2DataUtil.is_same_time( |
| | | now_time_str, latest_time): |
| | | cls.__process_not_order(code, start_index, end_index, capture_timestamp, is_first_code) |
| | | l2_log.info(code, logger_l2_process, "code:{} 处理数据范围: {}-{} 处理时间:{} 线程ID:{}", code, |
| | |
| | | now_time_int = int(tool.get_now_time_str().replace(":", "")) |
| | | if now_time_int >= 145700: |
| | | return False, True, f"14:57后不能交易" |
| | | if 130100 >= now_time_int >= 112900 or now_time_int<93100: |
| | | if 130100 >= now_time_int >= 112900 or now_time_int < 93100: |
| | | return False, True, f"09:31:00之前,11:29:00-13:01:00不能交易" |
| | | |
| | | # place_order_count = cls.__PlaceOrderCountManager.get_place_order_count(code) |
| | |
| | | not_cancel_money = not_cancel_num * 100 * float(gpcode_manager.get_limit_up_price(code)) |
| | | if m_base_val > not_cancel_money: |
| | | return False, False, f"成交位置距离当前位置纯买额({not_cancel_money})小于m值({m_base_val})" |
| | | else: |
| | | # 判断买1价格档位 |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb is None: |
| | | global_data_loader.load_zyltgb() |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | |
| | | if zyltgb >= 200 * 100000000: |
| | | buy1_price = cls.__Buy1PriceManager.get_buy1_price(code) |
| | | if buy1_price is None: |
| | | return False, True, f"尚未获取到买1价" |
| | | dif = float(limit_up_price) - float(buy1_price) |
| | | # 大于10档 |
| | | if dif > 0.10001: |
| | | return False, True, f"自由流通200亿以上,买1剩余档数大于10档,买一({buy1_price})涨停({limit_up_price})" |
| | | # 上证下单需要有成交大单(包含主动买与被动买)或者挂买的大单 |
| | | if code.find("60") == 0: |
| | | deal_big_order_count = BigOrderDealManager().get_total_buy_count(code) |
| | | if deal_big_order_count < 1: |
| | | # 统计挂买大单 |
| | | trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code) |
| | | if trade_index is None: |
| | | trade_index = 0 |
| | | limit_up_price = round(float(gpcode_manager.get_limit_up_price(code)), 2) |
| | | # 从成交进度位到截至位置计算大单 |
| | | min_money = l2_data_util.get_big_money_val(limit_up_price) |
| | | left_count, left_money = cancel_buy_strategy.L2DataComputeUtil.compute_left_buy_order(code, trade_index, total_data[-1]["index"], |
| | | limit_up_price, |
| | | min_money=min_money) |
| | | if left_count < 1: |
| | | return False, False, f"没有已挂或者成交的大单" |
| | | |
| | | open_limit_up_lowest_price = cls.__Buy1PriceManager.get_open_limit_up_lowest_price(code) |
| | | # price_pre_close = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) |
| | | # if open_limit_up_lowest_price and ( |
| | | # float(open_limit_up_lowest_price) - price_pre_close) / price_pre_close < 0.05: |
| | | # return False, True, f"炸板后最低价跌至5%以下" |
| | | |
| | | # 回封的票,下13:15买入需要判断板块是否为独苗 |
| | | # if open_limit_up_lowest_price and int(total_data[-1]["val"]["time"].replace(":", "")) > 131500: |
| | | # # 获取当前票的涨停原因 |
| | | # if code in LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict: |
| | | # limit_up_reason = kpl_data_manager.KPLLimitUpDataRecordManager.get_current_block(code) |
| | | # if limit_up_reason and limit_up_reason not in constant.KPL_INVALID_BLOCKS: |
| | | # # 判断是否是独苗 |
| | | # codes = kpl_data_manager.KPLLimitUpDataRecordManager.get_current_codes_by_block(limit_up_reason) |
| | | # if codes: |
| | | # codes = copy.deepcopy(codes) |
| | | # codes.discard(code) |
| | | # if not codes: |
| | | # return False, True, f"13:15以后炸板之后下单,({limit_up_reason}) 为独苗" |
| | | |
| | | # 暂时注释想买单功能 |
| | | if not cls.__WantBuyCodesManager.is_in_cache(code): |
| | | # if cls.__TradeTargetCodeModeManager.get_mode_cache() == TradeTargetCodeModeManager.MODE_ONLY_BUY_WANT_CODES: |
| | |
| | | |
| | | @classmethod |
| | | def can_buy_first_new(cls, code, limit_up_price): |
| | | if 1>0: |
| | | return True, False, "买所有" |
| | | |
| | | now_timestamp = int(tool.get_now_time_str().replace(":", "")) |
| | | # 判断板块 |
| | |
| | | zylt_threshold_as_yi = buy_condition_util.get_zyltgb_threshold(situation) |
| | | zyltgb_as_yi = round(global_util.zyltgb_map.get(code) / 100000000, 2) |
| | | |
| | | if zyltgb_as_yi >= zylt_threshold_as_yi[1]: |
| | | return False, True, f"{zylt_threshold_as_yi[1]}亿以上的都不买({zyltgb_as_yi})" |
| | | |
| | | if zyltgb_as_yi < zylt_threshold_as_yi[0]: |
| | | return False, True, f"{zylt_threshold_as_yi[0]}亿以下的都不买({zyltgb_as_yi})" |
| | | |
| | | if 1 > 0: |
| | | return True, False, "买所有" |
| | | |
| | | if zyltgb_as_yi >= zylt_threshold_as_yi[1]: |
| | | return False, True, f"{zylt_threshold_as_yi[1]}亿以上的都不买({zyltgb_as_yi})" |
| | | |
| | | msg_list = [] |
| | | if is_in_strong_time_30: |
| | |
| | | # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "m值阈值计算") |
| | | |
| | | # 设置为总卖额 |
| | | new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg = cls.__sum_buy_num_for_order_active( |
| | | new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg, clear_buy_single = cls.__sum_buy_num_for_order_active( |
| | | code, |
| | | start_process_index, |
| | | compute_end_index, |
| | |
| | | threshold_money = threshold_money_new |
| | | order_begin_pos.threshold_money = threshold_money |
| | | |
| | | l2_log.debug(code, "m值-{} 量比:{} rebegin_buy_pos:{}", threshold_money, cls.volume_rate_info[code][0], |
| | | rebegin_buy_pos) |
| | | l2_log.debug(code, "范围:{}-{} m值-{} 量比:{} rebegin_buy_pos:{} clear_buy_single:{}", compute_start_index, compute_end_index, |
| | | threshold_money, cls.volume_rate_info[code][0], |
| | | rebegin_buy_pos, clear_buy_single) |
| | | |
| | | # 买入信号位与计算位置间隔2s及以上了 |
| | | if rebegin_buy_pos is not None: |
| | |
| | | else: |
| | | # 未达到下单条件,保存纯买额,设置纯买额 |
| | | # 记录买入信号位置 |
| | | cls.__save_order_begin_data(code, OrderBeginPosInfo(buy_single_index=buy_single_index, buy_exec_index=-1, |
| | | buy_compute_index=compute_end_index, num=buy_nums, |
| | | count=buy_count, |
| | | mode_desc=order_begin_pos.mode_desc, |
| | | max_num_set=max_num_set_new, mode=order_begin_pos.mode, |
| | | sell_info=order_begin_pos.sell_info, |
| | | threshold_money=threshold_money)) |
| | | # 记录没下单原因 |
| | | async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{not_buy_msg}") |
| | | _start_time = t.time() |
| | | if not clear_buy_single: |
| | | # 没有清除信号位置就保存下单位置信息 |
| | | cls.__save_order_begin_data(code, OrderBeginPosInfo(buy_single_index=buy_single_index, buy_exec_index=-1, |
| | | buy_compute_index=compute_end_index, num=buy_nums, |
| | | count=buy_count, |
| | | mode_desc=order_begin_pos.mode_desc, |
| | | max_num_set=max_num_set_new, mode=order_begin_pos.mode, |
| | | sell_info=order_begin_pos.sell_info, |
| | | threshold_money=threshold_money)) |
| | | # 记录没下单原因 |
| | | async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{not_buy_msg}") |
| | | _start_time = t.time() |
| | | |
| | | # 获取下单起始信号 |
| | | @classmethod |
| | |
| | | trigger_buy = False |
| | | # 必须为连续2秒内的数据 |
| | | if L2DataUtil.time_sub_as_ms(_val, total_datas[buy_single_index]["val"]) > max_space_time_ms: |
| | | # 清除买点数据 |
| | | cls.__TradePointManager.delete_buy_point(code) |
| | | if i == compute_end_index: |
| | | # 数据处理完毕 |
| | | return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms" |
| | | return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms", True |
| | | else: |
| | | # 计算买入信号,不能同一时间开始计算 |
| | | for ii in range(buy_single_index + 1, compute_end_index + 1): |
| | | if total_datas[buy_single_index]["val"]["time"] != total_datas[ii]["val"]["time"]: |
| | | return None, buy_nums, buy_count, ii, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms" |
| | | return None, buy_nums, buy_count, ii, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms", True |
| | | # if L2DataUtil.is_sell(_val): |
| | | # threshold_money += _val["num"] * int(float(_val["price"]) * 100) |
| | | # threshold_num = round(threshold_money / (limit_up_price * 100)) |
| | |
| | | async_log_util.error(logger_l2_error, f"记录交易因子出错:{str(e)}") |
| | | l2_log.buy_debug(code, f"激进买主动卖手数:{sell_order_num}") |
| | | |
| | | return i, buy_nums, buy_count, None, threshold_money, max_buy_num_set, "可以下单" |
| | | return i, buy_nums, buy_count, None, threshold_money, max_buy_num_set, "可以下单", False |
| | | |
| | | l2_log.buy_debug(code, "尚未获取到买入执行点(激进买入),起始计算位置:{} 统计纯买手数:{} 目标纯买手数:{} 统计纯买单数:{} ", |
| | | compute_start_index, |
| | | buy_nums, |
| | | threshold_num, buy_count) |
| | | |
| | | return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, not_buy_msg |
| | | return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, not_buy_msg, False |
| | | |
| | | |
| | | def test_trade_record(): |
| | |
| | | def is_same_time(cls, time1, time2): |
| | | if constant.TEST: |
| | | return True |
| | | time1_s = time1.split(":") |
| | | time1_second = int(time1_s[0]) * 3600 + int(time1_s[1]) * 60 + int(time1_s[2]) |
| | | time2_s = time2.split(":") |
| | | time2_second = int(time2_s[0]) * 3600 + int(time2_s[1]) * 60 + int(time2_s[2]) |
| | | if abs(time2_second - time1_second) < 3: |
| | | if abs(tool.trade_time_sub(time1, time2)) < 3: |
| | | return True |
| | | else: |
| | | return False |
| | |
| | | """ |
| | | import json |
| | | |
| | | import l2_data_util |
| | | from db import redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2 import l2_log |
| | |
| | | |
| | | class BigOrderDealManager: |
| | | """ |
| | | 大单成交管理 |
| | | 成交大单管理 |
| | | """ |
| | | __total_buy_datas_dict = {} |
| | | __total_sell_datas_dict = {} |
| | |
| | | return 0 |
| | | return int(sum([x[2] for x in self.__total_buy_datas_dict[code]])) |
| | | |
| | | def get_total_buy_count(self, code): |
| | | """ |
| | | 获取大单成交的笔数 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if code not in self.__total_buy_datas_dict: |
| | | return 0 |
| | | return len(self.__total_buy_datas_dict[code]) |
| | | |
| | | def get_total_buy_money_list(self, code): |
| | | """ |
| | | 获取大单列表 |
| | |
| | | if code not in self.__total_buy_datas_dict: |
| | | return 0 |
| | | return [x[2] for x in self.__total_buy_datas_dict[code]] |
| | | |
| | | |
| | | def get_total_sell_money(self, code): |
| | | """ |
| | |
| | | return cls.__dealing_order_info_dict.get(code) |
| | | |
| | | @classmethod |
| | | def statistic_big_buy_data(cls, code, datas): |
| | | def statistic_big_buy_data(cls, code, datas, limit_up_price): |
| | | """ |
| | | 统计大单买 |
| | | @param code: |
| | |
| | | """ |
| | | big_buy_datas = [] |
| | | normal_buy_datas = [] |
| | | # 大单阈值 |
| | | threshold_big_money = l2_data_util.get_big_money_val(limit_up_price) |
| | | for data in datas: |
| | | # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'], |
| | | # data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], |
| | |
| | | deal_info = cls.__dealing_order_info_dict[code] |
| | | cls.__latest_deal_order_info_dict[code] = deal_info |
| | | # 是否为大买单 |
| | | if deal_info[2] >= 2990000: |
| | | if deal_info[2] >= threshold_big_money: |
| | | big_buy_datas.append(deal_info) |
| | | if deal_info[2] >= 500000: |
| | | normal_buy_datas.append(deal_info) |
| | |
| | | time_dict.clear() |
| | | |
| | | @classmethod |
| | | def get_latest_2s_continue_deal_volume(cls, code): |
| | | def get_latest_3s_continue_deal_volumes(cls, code): |
| | | """ |
| | | 获取最近连续2s的成交量 |
| | | 获取最近3s的成交量分布 |
| | | @param code: |
| | | @return: 成交量,详细信息 |
| | | @return: [(时间,量)] |
| | | """ |
| | | deal_list = cls.__deal_volume_list_dict.get(code) |
| | | if not deal_list: |
| | | return 0, None |
| | | if len(deal_list) == 0: |
| | | return deal_list[0][1], deal_list |
| | | if tool.trade_time_sub(deal_list[-1][0], deal_list[-2][0]) > 1: |
| | | return deal_list[-1][1], deal_list |
| | | else: |
| | | return deal_list[-1][1] + deal_list[-2][1], deal_list |
| | | fdatas = [deal_list[-1]] |
| | | # 从倒数第二个数据计算 |
| | | for i in range(len(deal_list) - 2, -1, -1): |
| | | if tool.trade_time_sub(fdatas[0][0], deal_list[i][0]) < 3: |
| | | fdatas.append(deal_list[i]) |
| | | return fdatas |
| | | |
| | | @classmethod |
| | | def clear_latest_deal_volume(cls, code): |
| | | if code in cls.__deal_volume_list_dict: |
| | | cls.__deal_volume_list_dict.pop(code) |
| | | |
| | | # 返回最近1s的大单卖:(总卖金额,[(卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)),...]) |
| | | @classmethod |
| | |
| | | @param datas: |
| | | @return: |
| | | """ |
| | | buy_datas, bigger_buy_datas = HuaXinBuyOrderManager.statistic_big_buy_data(code, datas) |
| | | limit_up_price = round(float(gpcode_manager.get_limit_up_price(code)), 2) |
| | | buy_datas, bigger_buy_datas = HuaXinBuyOrderManager.statistic_big_buy_data(code, datas, limit_up_price) |
| | | if buy_datas: |
| | | BigOrderDealManager().add_buy_datas(code, buy_datas) |
| | | try: |
| | |
| | | limit_up_price = round(float(limit_up_price), 2) |
| | | # 设置成交价 |
| | | try: |
| | | current_price_process_manager.set_trade_price(code, datas[-1][1], l2_huaxin_util.convert_time( datas[-1][3]), limit_up_price) |
| | | current_price_process_manager.set_trade_price(code, datas[-1][1], l2_huaxin_util.convert_time(datas[-1][3]), |
| | | limit_up_price) |
| | | except: |
| | | pass |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | |
| | | L2TradeDataProcessor.cancel_buy(code, f"W撤:{cancel_result[1]}") |
| | | except: |
| | | pass |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | SCancelBigNumComputer().set_transaction_index(code, order_begin_pos.buy_single_index, |
| | | buy_progress_index) |