| | |
| | | if not code_data_util.is_same_code_with_price(code, float(datas[0]["val"]["price"])): |
| | | raise L2DataException(L2DataException.CODE_PRICE_ERROR, |
| | | "股价不匹配 code-{} price-{}".format(code, datas[0]["val"]["price"])) |
| | | # 加载历史数据 |
| | | l2.l2_data_util.load_l2_data(code) |
| | | # 加载历史数据,返回数据是否正常 |
| | | is_normal = l2.l2_data_util.load_l2_data(code) |
| | | if not is_normal: |
| | | print("历史数据异常:",code) |
| | | # 数据不正常需要禁止交易 |
| | | l2_trade_util.forbidden_trade(code) |
| | | # 纠正数据 |
| | | datas = l2.l2_data_util.L2DataUtil.correct_data(code, local_latest_datas.get(code), datas) |
| | | _start_index = 0 |
| | |
| | | |
| | | l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, |
| | | "已下单-买1统计耗时") |
| | | if constant.TEST: |
| | | # 买1不会触发撤单 |
| | | return None, "" |
| | | return cancel_data, cancel_msg |
| | | # return cancel_data, cancel_msg |
| | | |
| | | # S撤 |
| | | @dask.delayed |
| | |
| | | _start_time = round(t.time() * 1000) |
| | | try: |
| | | b_need_cancel, b_cancel_data = HourCancelBigNumComputer.need_cancel(code, buy_exec_index, start_index, |
| | | end_index, total_data, local_today_num_operate_map.get(code)) |
| | | end_index, total_data, |
| | | local_today_num_operate_map.get( |
| | | code)) |
| | | if b_need_cancel and b_cancel_data: |
| | | return b_cancel_data, "H撤销比例触发阈值" |
| | | except Exception as e: |
| | |
| | | @classmethod |
| | | def __buy(cls, code, capture_timestamp, last_data, last_data_index): |
| | | __start_time = tool.get_now_timestamp() |
| | | can, reason = cls.__can_buy(code) |
| | | can, need_clear_data, reason = cls.__can_buy(code) |
| | | __start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - __start_time, "最后判断是否能下单", force=True) |
| | | # 删除虚拟下单 |
| | | if code in cls.unreal_buy_dict: |
| | |
| | | |
| | | if not can: |
| | | l2_log.debug(code, "不可以下单,原因:{}", reason) |
| | | if not reason.startswith("买1价不为涨停价"): |
| | | if need_clear_data: |
| | | # 中断买入 |
| | | trade_manager.break_buy(code, reason) |
| | | return |
| | |
| | | return True, "" |
| | | |
| | | # 是否可以买 |
| | | # 返回是否可以买,是否需要清除之前的买入信息,原因 |
| | | @classmethod |
| | | def __can_buy(cls, code): |
| | | __start_time = t.time() |
| | | # 判断是否为首板代码 |
| | | is_first = gpcode_manager.FirstCodeManager.is_in_first_record(code) |
| | | if is_first: |
| | | # 首板代码且尚未涨停过的不能下单 |
| | | is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code) |
| | | if not is_limited_up: |
| | | return False, True, "首板代码,且尚未涨停过" |
| | | |
| | | try: |
| | | # 买1价格必须为涨停价才能买 |
| | | # buy1_price = cls.buy1PriceManager.get_price(code) |
| | |
| | | # return False, "买1价不为涨停价,买1价-{} 涨停价-{}".format(buy1_price, limit_up_price) |
| | | # 从买入信号起始点到当前数据末尾的纯买手数与当前的卖1做比较,如果比卖1小则不能买入 |
| | | total_datas = local_today_datas[code] |
| | | if total_datas[-1]["index"] + 1 > len(total_datas): |
| | | return False, True, "L2数据错误" |
| | | |
| | | |
| | | try: |
| | | sell1_time, sell1_price, sell1_volumn = cls.__ths_l2_trade_queue_manager.get_sell1_info(code) |
| | | l2_log.buy_debug(code, "卖1信息为:({},{},{})", sell1_time, sell1_price, sell1_volumn) |
| | |
| | | elif L2DataUtil.is_limit_up_price_buy_cancel(_val): |
| | | buy_nums -= _val["num"] * total_datas[i]["re"] |
| | | if buy_nums < sell1_volumn * 0.49: |
| | | return False, "纯买量({})小于卖1量的49%{} 卖1时间:{}".format(buy_nums, sell1_volumn, sell1_time) |
| | | return False, True, "纯买量({})小于卖1量的49%{} 卖1时间:{}".format(buy_nums, sell1_volumn, sell1_time) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | |
| | | # 量比超过1.3的不能买 |
| | | volumn_rate = l2_trade_factor.L2TradeFactorUtil.get_volumn_rate_by_code(code) |
| | | if volumn_rate >= 1.3: |
| | | return False, "最大量比超过1.3不能买" |
| | | return False, True, "最大量比超过1.3不能买" |
| | | |
| | | limit_up_time = limit_up_time_manager.get_limit_up_time(code) |
| | | if limit_up_time is not None and l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | limit_up_time) >= l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | "14:30:00"): |
| | | return False, "14:30后涨停的不能买,涨停时间为{}".format(limit_up_time) |
| | | return False, True, "14:55后涨停的不能买,涨停时间为{}".format(limit_up_time) |
| | | |
| | | # 同一板块中老二后面的不能买 |
| | | industry, codes = ths_industry_util.get_same_industry_codes(code, gpcode_manager.get_gp_list()) |
| | | if industry is None: |
| | | return True, "没有获取到行业" |
| | | return True, True, "没有获取到行业" |
| | | |
| | | codes_index = industry_codes_sort.sort_codes(codes, code) |
| | | if codes_index is not None and codes_index.get(code) is not None and codes_index.get(code) > 1: |
| | | # 当老大老二当前没涨停 |
| | | return False, "同一板块中老三,老四,...不能买" |
| | | return False, True, "同一板块中老三,老四,...不能买" |
| | | |
| | | if cls.__codeActualPriceProcessor.is_under_water(code, total_datas[-1]["val"]["time"]): |
| | | # 水下捞且板块中的票小于16不能买 |
| | |
| | | # 获取老大的市值 |
| | | for c in codes_index: |
| | | if codes_index.get(c) == 0 and global_util.zyltgb_map.get(code) > global_util.zyltgb_map.get(c): |
| | | return False, "水下捞,不是老大,且自由流通市值大于老大" |
| | | return False, True, "水下捞,不是老大,且自由流通市值大于老大" |
| | | |
| | | # 13:30后涨停,本板块中涨停票数<29不能买 |
| | | # if limit_up_time is not None: |
| | |
| | | # if global_util.industry_hot_num.get(industry) < 29: |
| | | # return False, "老二,本板块中涨停票数<29不能买" |
| | | # 可以下单 |
| | | return True, None |
| | | return True, False, None |
| | | finally: |
| | | l2_data_log.l2_time(code, round((t.time() - __start_time) * 1000), "是否可以下单计算") |
| | | |
| | |
| | | return None |
| | | |
| | | # 开始计算的位置 |
| | | start_process_index = min(buy_single_index, compute_start_index) if new_get_single else max(buy_single_index, |
| | | compute_start_index) |
| | | start_process_index = max(buy_single_index, compute_start_index) |
| | | if new_get_single: |
| | | start_process_index = buy_single_index |
| | | |
| | | # 计算m值大单 |
| | | cls.l2BigNumForMProcessor.process(code, start_process_index, |
| | |
| | | |
| | | _start_time = t.time() |
| | | total_datas = local_today_datas[code] |
| | | is_first_code = gpcode_manager.FirstCodeManager.is_in_first_record(code) |
| | | |
| | | buy_nums = origin_num |
| | | buy_count = origin_count |
| | |
| | | # 目标手数 |
| | | threshold_num = round(threshold_money / (limit_up_price * 100)) |
| | | |
| | | place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(code) |
| | | # 目标订单数量 |
| | | threshold_count = cls.__buyL2SafeCountManager.get_safe_count(code) |
| | | threshold_count = cls.__buyL2SafeCountManager.get_safe_count(code,is_first_code, place_order_count) |
| | | |
| | | buy_single_time_seconds = L2DataUtil.get_time_as_second(total_datas[buy_single_index]["val"]["time"]) |
| | | |
| | | # 可以触发买,当有涨停买信号时才会触发买 |
| | | trigger_buy = True |
| | | place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(code) |
| | | |
| | | if place_order_count > 3: |
| | | place_order_count = 3 |
| | | # 间隔最大时间依次为:3,9,27,81 |
| | |
| | | # 只统计59万以上的金额 |
| | | # 涨停买撤 |
| | | # 判断买入位置是否在买入信号之前 |
| | | buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, total_datas[i], |
| | | buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, |
| | | total_datas[i], |
| | | local_today_num_operate_map.get( |
| | | code)) |
| | | if buy_index is not None: |
| | |
| | | limit_up_time = limit_up_time_manager.get_limit_up_time(code) |
| | | if limit_up_time is not None and l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | limit_up_time) >= l2.l2_data_util.L2DataUtil.get_time_as_second( |
| | | "14:30:00"): |
| | | return False, "14:30后涨停的不能买,涨停时间为{}".format(limit_up_time) |
| | | "14:55:00"): |
| | | return False, "14:55后涨停的不能买,涨停时间为{}".format(limit_up_time) |
| | | |
| | | # 同一板块中老二后面的不能买 |
| | | industry, codes = ths_industry_util.get_same_industry_codes(code, gpcode_manager.get_gp_list()) |