| | |
| | | @classmethod |
| | | def process_add_datas(cls, code, add_datas, capture_timestamp, __start_time): |
| | | if len(add_datas) > 0: |
| | | now_time_str = datetime.datetime.now().strftime("%H:%M:%S") |
| | | now_time_str = tool.get_now_time_str() |
| | | # 拼接数据 |
| | | local_today_datas[code].extend(add_datas) |
| | | l2_data_util.load_num_operate_map(l2_data_manager.local_today_num_operate_map, code, add_datas) |
| | |
| | | if end_index < start_index: |
| | | return |
| | | # 获取买入信号起始点 |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos( |
| | | code) |
| | | |
| | | # 撤单计算,只看买1 |
| | |
| | | trade_data_manager.placeordercountmanager.place_order(code) |
| | | # 获取买入位置信息 |
| | | try: |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos( |
| | | code) |
| | | SecondAverageBigNumComputer.place_order_success(code, buy_single_index, buy_exec_index) |
| | | AverageBigNumComputer.place_order_success(code, buy_single_index, buy_exec_index) |
| | |
| | | # if abs(float(buy1_price) - float(limit_up_price)) >= 0.01: |
| | | # return False, "买1价不为涨停价,买1价-{} 涨停价-{}".format(buy1_price, limit_up_price) |
| | | # 从买入信号起始点到当前数据末尾的纯买手数与当前的卖1做比较,如果比卖1小则不能买入 |
| | | total_datas = local_today_datas[code] |
| | | try: |
| | | sell1_time, sell1_price, sell1_volumn = cls.__ths_l2_trade_queue_manager.get_sell1_info(code) |
| | | cls.buy_debug(code, "卖1信息为:({},{},{})", sell1_time, sell1_price, sell1_volumn) |
| | | if sell1_time is not None and sell1_volumn > 0: |
| | | # 获取执行位信息 |
| | | total_datas = local_today_datas[code] |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( |
| | | |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos( |
| | | code) |
| | | buy_nums = num |
| | | for i in range(buy_exec_index + 1, total_datas[-1]["index"] + 1): |
| | |
| | | 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, "同一板块中老三,老四,...不能买" |
| | | |
| | | if cls.__codeActualPriceProcessor.is_under_water(code): |
| | | if cls.__codeActualPriceProcessor.is_under_water(code,total_datas[-1]["val"]["time"]): |
| | | # 水下捞且板块中的票小于16不能买 |
| | | if global_util.industry_hot_num.get(industry) is not None and global_util.industry_hot_num.get( |
| | | industry) <= 16: |
| | | return False, "水下捞,板块中的票小于2只,为{}".format(global_util.industry_hot_num.get(industry)) |
| | | |
| | | # if global_util.industry_hot_num.get(industry) is not None and global_util.industry_hot_num.get( |
| | | # industry) <= 16: |
| | | # return False, "水下捞,板块中的票小于2只,为{}".format(global_util.industry_hot_num.get(industry)) |
| | | # 水下捞自由流通市值大于老大的不要买 |
| | | if codes_index.get(code) != 0: |
| | | return False, "水下捞,不是老大,是老{}".format(codes_index.get(code)) |
| | | # 获取老大的市值 |
| | | 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, "水下捞,不是老大,且自由流通市值大于老大" |
| | | |
| | | # 13:30后涨停,本板块中涨停票数<29不能买 |
| | | if limit_up_time is not None: |
| | | if int(limit_up_time.replace(":", "")) >= 133000 and global_util.industry_hot_num.get(industry) is not None: |
| | | if global_util.industry_hot_num.get(industry) < 16: |
| | | return False, "13:30后涨停,本板块中涨停票数<16不能买" |
| | | # if limit_up_time is not None: |
| | | # if int(limit_up_time.replace(":", "")) >= 133000 and global_util.industry_hot_num.get(industry) is not None: |
| | | # if global_util.industry_hot_num.get(industry) < 16: |
| | | # return False, "13:30后涨停,本板块中涨停票数<16不能买" |
| | | |
| | | if codes_index.get(code) is not None and codes_index.get(code) == 1: |
| | | # 如果老大已经买成功了, 老二就不需要买了 |
| | |
| | | # 是否是交易队列触发 |
| | | if source == "trade_queue": |
| | | # 交易队列触发的需要下单后5s |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos( |
| | | code) |
| | | total_datas = local_today_datas[code] |
| | | if buy_exec_index is not None and buy_exec_index > 0: |
| | | now_time_str = datetime.datetime.now().strftime("%H:%M:%S") |
| | | now_time_str = tool.get_now_time_str() |
| | | if tool.trade_time_sub(now_time_str, total_datas[buy_exec_index]["val"]["time"]) < 5: |
| | | return False |
| | | |
| | |
| | | _start_time = round(t.time() * 1000) |
| | | total_datas = local_today_datas[code] |
| | | # 获取买入信号计算起始位置 |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos( |
| | | code) |
| | | |
| | | # 是否为新获取到的位置 |
| | |
| | | |
| | | threshold_money, msg = cls.__get_threshmoney(code) |
| | | # 买入纯买额统计 |
| | | compute_index, buy_nums, buy_count, rebegin_buy_pos, max_num_index_new = cls.__sum_buy_num_for_order_3(code, |
| | | max( |
| | | buy_single_index, |
| | | compute_start_index), |
| | | compute_end_index, |
| | | num, |
| | | count, |
| | | threshold_money, |
| | | buy_single_index, |
| | | max_num_index) |
| | | compute_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new = cls.__sum_buy_num_for_order_3(code, max(buy_single_index,compute_start_index),compute_end_index,num,count,threshold_money,buy_single_index,max_num_set) |
| | | _start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "纯买额统计时间") |
| | | |
| | | cls.debug(code, "m值-{} m值因子-{}", threshold_money, msg) |
| | |
| | | total_datas[compute_index]) |
| | | # 记录买入信号位置 |
| | | cls.__save_order_begin_data(code, buy_single_index, compute_index, compute_index, buy_nums, buy_count, |
| | | max_num_index_new) |
| | | max_num_set_new) |
| | | # 如果是今天第一次有下单执行信号,涨停时间(买入执行位时间) |
| | | limit_up_time_manager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"]) |
| | | # 虚拟下单 |
| | |
| | | # 未达到下单条件,保存纯买额,设置纯买额 |
| | | # 记录买入信号位置 |
| | | cls.__save_order_begin_data(code, buy_single_index, -1, compute_end_index, buy_nums, buy_count, |
| | | max_num_index_new) |
| | | max_num_set_new) |
| | | print("保存大单时间", round((t.time() - _start_time) * 1000)) |
| | | _start_time = t.time() |
| | | pass |
| | |
| | | # 获取下单起始信号 |
| | | @classmethod |
| | | def __get_order_begin_pos(cls, code): |
| | | buy_single_index, buy_exec_index, compute_index, num, count, max_num_index = l2_data_manager.TradePointManager.get_buy_compute_start_data( |
| | | buy_single_index, buy_exec_index, compute_index, num, count, max_num_set = l2_data_manager.TradePointManager.get_buy_compute_start_data( |
| | | code) |
| | | return buy_single_index, buy_exec_index, compute_index, num, count, max_num_index |
| | | return buy_single_index, buy_exec_index, compute_index, num, count, max_num_set |
| | | |
| | | # 保存下单起始信号 |
| | | @classmethod |
| | | def __save_order_begin_data(self, code, buy_single_index, buy_exec_index, compute_index, num, count, max_num_index): |
| | | def __save_order_begin_data(self, code, buy_single_index, buy_exec_index, compute_index, num, count, max_num_set): |
| | | TradePointManager.set_buy_compute_start_data(code, buy_single_index, buy_exec_index, compute_index, num, count, |
| | | max_num_index) |
| | | max_num_set) |
| | | |
| | | # 计算下单起始信号 |
| | | # compute_data_count 用于计算的l2数据数量 |
| | |
| | | # 统计买入净买量,不计算在买入信号之前的买撤单 |
| | | @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_index): |
| | | threshold_money, buy_single_index, max_num_set): |
| | | def get_threshold_count(): |
| | | count = threshold_count - sub_threshold_count |
| | | if count < 3: |
| | |
| | | max_space_time = pow(3, place_order_count + 1) - 1 |
| | | # 最大买量 |
| | | max_buy_num = 0 |
| | | max_buy_num_index = max_num_index |
| | | if max_num_index > -1: |
| | | max_buy_num = int(total_datas[max_num_index]["val"]["num"]) |
| | | max_buy_num_set = set(max_num_set) |
| | | for i in range(compute_start_index, compute_end_index + 1): |
| | | data = total_datas[i] |
| | | _val = total_datas[i]["val"] |
| | |
| | | TradePointManager.delete_buy_point(code) |
| | | if i == compute_end_index: |
| | | # 数据处理完毕 |
| | | return None, buy_nums, buy_count, None, max_buy_num_index |
| | | return None, buy_nums, buy_count, None, max_buy_num_set |
| | | 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, max_buy_num_index |
| | | return None, buy_nums, buy_count, ii, max_buy_num_set |
| | | # 涨停买 |
| | | if L2DataUtil.is_limit_up_price_buy(_val): |
| | | if cls.__is_big_money(limit_up_price, _val): |
| | | sub_threshold_count += int(total_datas[i]["re"]) |
| | | max_buy_num_set.add(i) |
| | | if round(int(_val["num"]) * float(_val["price"])) >= 5900: |
| | | if int(_val["num"]) > max_buy_num: |
| | | max_buy_num = int(_val["num"]) |
| | | max_buy_num_index = i |
| | | trigger_buy = True |
| | | # 只统计59万以上的金额 |
| | | buy_nums += int(_val["num"]) * int(total_datas[i]["re"]) |
| | |
| | | cls.buy_debug(code, "位置-{},总手数:{},目标手数:{}", i, |
| | | buy_nums, threshold_num) |
| | | # 有撤单信号,且小于阈值 |
| | | if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy and max_buy_num_index > -1 and cls.__is_big_money( |
| | | limit_up_price, total_datas[max_buy_num_index]["val"]): |
| | | return i, buy_nums, buy_count, None, max_buy_num_index |
| | | if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy and len(max_buy_num_set)>1: |
| | | return i, buy_nums, buy_count, None, max_buy_num_set |
| | | |
| | | cls.buy_debug(code, "尚未获取到买入执行点,起始计算位置:{} 统计纯买手数:{} 目标纯买手数:{} 统计纯买单数:{} 目标纯买单数:{} 大单数量:{}", |
| | | compute_start_index, |
| | | buy_nums, |
| | | threshold_num, buy_count, get_threshold_count(), sub_threshold_count) |
| | | |
| | | return None, buy_nums, buy_count, None, max_buy_num_index |
| | | return None, buy_nums, buy_count, None, max_buy_num_set |
| | | |
| | | @classmethod |
| | | def test(cls): |
| | |
| | | total_data = local_today_datas[code] |
| | | latest_index = total_data[-1]["index"] |
| | | end_index = total_data[-1]["index"] |
| | | if end_index >= 434: |
| | | print("测试") |
| | | |
| | | start_index = buy_exec_index |
| | | if tool.trade_time_sub(total_data[end_index]["val"]["time"], total_data[buy_exec_index]["val"]["time"]) < 3: |
| | | return |