| | |
| | | import time as t |
| | | |
| | | import big_money_num_manager |
| | | import data_process |
| | | import code_data_util |
| | | import global_util |
| | | import gpcode_manager |
| | | import l2_data_log |
| | |
| | | import l2_trade_factor |
| | | import l2_trade_test |
| | | import limit_up_time_manager |
| | | import log |
| | | import redis_manager |
| | | import ths_industry_util |
| | | import tool |
| | |
| | | local_today_num_operate_map, L2LimitUpMoneyStatisticUtil |
| | | from log import logger_l2_trade, logger_l2_trade_cancel, logger_l2_trade_buy, logger_l2_process |
| | | |
| | | |
| | | # TODO l2数据管理 |
| | | from trade_data_manager import CodeActualPriceProcessor |
| | | |
| | | |
| | | class L2DataManager: |
| | | # 格式化数据 |
| | | def format_data(self, datas): |
| | |
| | | unreal_buy_dict = {} |
| | | random_key = {} |
| | | l2BigNumForMProcessor = L2BigNumForMProcessor() |
| | | __codeActualPriceProcessor = CodeActualPriceProcessor() |
| | | |
| | | @classmethod |
| | | def debug(cls, code, content, *args): |
| | |
| | | try: |
| | | if len(datas) > 0: |
| | | # 判断价格区间是否正确 |
| | | if not data_process.is_same_code_with_price(code, float(datas[0]["val"]["price"])): |
| | | 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"])) |
| | | # 加载历史数据 |
| | |
| | | # 拼接数据 |
| | | 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) |
| | | # 第1条数据是否为09:30:00 |
| | | if add_datas[0]["val"]["time"] == "09:30:00": |
| | | if global_util.cuurent_prices.get(code): |
| | | price_data = global_util.cuurent_prices.get(code) |
| | | if price_data[1]: |
| | | # 当前涨停价,设置涨停时间 |
| | | logger_l2_process.info("开盘涨停:{}", code) |
| | | # 保存涨停时间 |
| | | limit_up_time_manager.save_limit_up_time(code, "09:30:00") |
| | | |
| | | total_datas = local_today_datas[code] |
| | | __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "l2数据预处理时间") |
| | | if len(add_datas) > 0: |
| | | |
| | | _start_time = round(t.time() * 1000) |
| | | latest_time = add_datas[len(add_datas) - 1]["val"]["time"] |
| | | # 时间差不能太大才能处理 |
| | |
| | | @classmethod |
| | | def __process_not_order(cls, code, start_index, end_index, capture_time): |
| | | # 获取阈值 |
| | | threshold_money = cls.__get_threshmoney(code) |
| | | threshold_money, msg = cls.__get_threshmoney(code) |
| | | cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time) |
| | | |
| | | @classmethod |
| | |
| | | # 是否可以买 |
| | | @classmethod |
| | | def __can_buy(cls, code): |
| | | |
| | | limit_up_time = limit_up_time_manager.get_limit_up_time(code) |
| | | if limit_up_time is not None and l2_data_manager.L2DataUtil.get_time_as_second( |
| | | limit_up_time) >= l2_data_manager.L2DataUtil.get_time_as_second( |
| | |
| | | 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): |
| | | # 水下捞且板块中的票小于21不能买 |
| | | if 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)) |
| | | |
| | | # 13:00后涨停,本板块中涨停票数<29不能买 |
| | | limit_up_time = limit_up_time_manager.get_limit_up_time(code) |
| | | if limit_up_time is not None: |
| | | if int(limit_up_time.replace(":", "")) >= 130000 and global_util.industry_hot_num.get(industry) is not None: |
| | | if global_util.industry_hot_num.get(industry) < 29: |
| | | return False, "13:00后涨停,本板块中涨停票数<29不能买" |
| | | # 老二,本板块中涨停票数<29 不能买 |
| | | if codes_index.get(code) is not None and codes_index.get(code) == 1 and global_util.industry_hot_num.get( |
| | | industry) is not None: |
| | | if global_util.industry_hot_num.get(industry) < 29: |
| | | return False, "老二,本板块中涨停票数<29不能买" |
| | | |
| | | if codes_index.get(code) is not None and codes_index.get(code) == 1: |
| | | # 如果老大已经买成功了,老二就不需要买了 |
| | | first_codes = [] |
| | | for key in codes_index: |
| | | if codes_index.get(key) == 0: |
| | | first_codes.append(key) |
| | | |
| | | for key in first_codes: |
| | | state = trade_manager.get_trade_state(key) |
| | | if state == trade_manager.TRADE_STATE_BUY_SUCCESS: |
| | | # 老大已经买成功了 |
| | | return False, "老大{}已经买成功,老二无需购买".format(key) |
| | | |
| | | # 有9点半涨停的老大才能买老二,不然不能买 |
| | | # 获取老大的涨停时间 |
| | | for key in first_codes: |
| | | # 找到了老大 |
| | | time_ = limit_up_time_manager.get_limit_up_time(key) |
| | | if time_ == "09:30:00": |
| | | return True, "9:30涨停的老大,老二可以下单" |
| | | return False, "老大非9:30涨停,老二不能下单" |
| | | |
| | | # 过时 老二,本板块中涨停票数<29 不能买 |
| | | # if codes_index.get(code) is not None and codes_index.get(code) == 1 and global_util.industry_hot_num.get( |
| | | # industry) is not None: |
| | | # if global_util.industry_hot_num.get(industry) < 29: |
| | | # return False, "老二,本板块中涨停票数<29不能买" |
| | | # 可以下单 |
| | | return True, None |
| | | |
| | |
| | | # 计算m值大单 |
| | | cls.l2BigNumForMProcessor.process(code, max(buy_single_index, compute_start_index), compute_end_index, |
| | | gpcode_manager.get_limit_up_price(code)) |
| | | threshold_money = cls.__get_threshmoney(code) |
| | | threshold_money, msg = cls.__get_threshmoney(code) |
| | | # 买入纯买额统计 |
| | | compute_index, buy_nums, buy_count, rebegin_buy_pos = cls.__sum_buy_num_for_order_3(code, max(buy_single_index, |
| | | compute_start_index), |
| | |
| | | count, threshold_money, |
| | | buy_single_index, |
| | | capture_time) |
| | | cls.debug(code, "m值-{} m值因子-{}", threshold_money, msg) |
| | | |
| | | # 买入信号位与计算位置间隔2s及以上了 |
| | | if rebegin_buy_pos is not None: |
| | | # 需要重新计算纯买额 |