| | |
| | | # if code.find('60') == 0: |
| | | # 激进买 |
| | | continue_count = 1 |
| | | has_single, _index, sell_info = cls.__compute_active_order_begin_pos(code, continue_count, |
| | | compute_start_index, compute_end_index) |
| | | has_single, _index, sell_info, single_msg = cls.__compute_active_order_begin_pos(code, continue_count, |
| | | compute_start_index, |
| | | compute_end_index) |
| | | fast_msg = None |
| | | if has_single: |
| | | order_begin_pos.mode = OrderBeginPosInfo.MODE_ACTIVE |
| | |
| | | # 总卖额的1倍 |
| | | order_begin_pos.threshold_money = int(sell_info[1] * 1.0) |
| | | |
| | | l2_log.debug(code, "获取到买入信号起始点:{} ,计算范围:{}-{} ,量比:{},是否板上买:{},数据:{} 模式:{}({})", buy_single_index, |
| | | l2_log.debug(code, "获取到买入信号起始点:{} ,计算范围:{}-{} ,量比:{},是否板上买:{},数据:{} 模式:{}({}) 信号类型:{}", |
| | | buy_single_index, |
| | | compute_start_index, |
| | | compute_end_index, cls.volume_rate_info[code], order_begin_pos.at_limit_up, |
| | | total_datas[buy_single_index], |
| | | order_begin_pos.mode, fast_msg) |
| | | order_begin_pos.mode, fast_msg, single_msg) |
| | | |
| | | # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "下单信号计算时间") |
| | | |
| | |
| | | return True, i, [refer_sell_data[0], threshold_money] |
| | | return False, None, None |
| | | |
| | | @classmethod |
| | | def __get_active_single_start_index(cls, code, start_index, end_index, continue_count, valid_single=False): |
| | | """ |
| | | 获取主动买的信号起始索引 |
| | | @param code: |
| | | @param start_index: |
| | | @param end_index: |
| | | @param continue_count: |
| | | @param valid_single: 是否验证成交买入信号 |
| | | @return: |
| | | """ |
| | | total_datas = local_today_datas[code] |
| | | last_index = None |
| | | count = 0 |
| | | start = None |
| | | for i in range(start_index, end_index + 1): |
| | | _val = total_datas[i]["val"] |
| | | if L2DataUtil.is_limit_up_price_buy(_val): |
| | | # 时间要>=09:30:00 |
| | | if tool.trade_time_sub(_val["time"], "09:30:00") < 0: |
| | | continue |
| | | # 金额要大于50万 |
| | | if _val["num"] * float(_val["price"]) < 5000: |
| | | continue |
| | | if last_index is None or ( |
| | | total_datas[last_index]["val"]["time"] == total_datas[i]["val"]["time"]): |
| | | # 深证非板上放量需要判断是否有信号 |
| | | if valid_single: |
| | | _single = place_order_single_data_manager.L2TradeSingleDataManager.get_valid_trade_single( |
| | | code, |
| | | tool.to_time_with_ms( |
| | | _val['time'], |
| | | _val['tms'])) |
| | | if not _single: |
| | | continue |
| | | if start is None: |
| | | start = i |
| | | last_index = i |
| | | count += total_datas[i]["re"] |
| | | if count >= continue_count: |
| | | return start |
| | | else: |
| | | # 本条数据作为起点 |
| | | last_index = i |
| | | count = total_datas[i]["re"] |
| | | start = i |
| | | elif not L2DataUtil.is_sell(_val) and not L2DataUtil.is_sell_cancel(_val): |
| | | # 剔除卖与卖撤 |
| | | last_index = None |
| | | count = 0 |
| | | start = None |
| | | return None |
| | | |
| | | # 计算激进买的下单信号 |
| | | @classmethod |
| | | def __compute_active_order_begin_pos(cls, code, continue_count, start_index, end_index): |
| | | total_datas = local_today_datas[code] |
| | | start_time_str = total_datas[start_index]["val"]["time"] |
| | | if end_index - start_index + 1 < continue_count: |
| | | return False, -1, "信号不连续", '' |
| | | # 获取最近的总卖信息 |
| | | # (time_str, round(money), volume, sell_1_info) |
| | | refer_sell_data = cls.__L2MarketSellManager.get_refer_sell_data(code, start_time_str) |
| | |
| | | # 金额要大于50万 |
| | | if _val["num"] * float(_val["price"]) < 5000: |
| | | continue |
| | | return True, i, [refer_sell_data[0], refer_sell_data[1]] |
| | | return False, -1, "未获取到激进买的起始信号" |
| | | return True, i, [refer_sell_data[0], 0], '上证买入' |
| | | return False, -1, "未获取到激进买的起始信号", '' |
| | | else: |
| | | # 深证 |
| | | if refer_sell_data is None: |
| | | return False, -1, "总卖为空" |
| | | return False, -1, "总卖为空", '' |
| | | if refer_sell_data is None: |
| | | refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0)) |
| | | l2_log.debug(code, f"丢失总卖额,设置默认为0,计算范围:{start_index}-{end_index}") |
| | |
| | | is_limit_up = True |
| | | if refer_sell_data[1] > 0 or single or not is_limit_up: |
| | | # 不是板上放量 |
| | | pass |
| | | # 判断最近有没有涨停卖数据 |
| | | limit_up_sell_count = L2TradeSingleDataProcessor.get_latest_limit_up_sell_order_count(code) |
| | | if limit_up_sell_count == 0 and not single: |
| | | # 如果没有涨停卖数据而且还没有成交买入信号,就按照原来的总卖额计算 |
| | | threshold_money, sell_1_price = refer_sell_data[1], refer_sell_data[3][0] |
| | | for i in range(start_index - 1, -1, -1): |
| | | val = total_datas[i]["val"] |
| | | if tool.compare_time(val["time"], refer_sell_data[0]) < 0: |
| | | # 将本s的计算上去 |
| | | break |
| | | if L2DataUtil.is_sell(val): |
| | | threshold_money += val["num"] * int(float(val["price"]) * 100) |
| | | elif L2DataUtil.is_sell_cancel(val): |
| | | threshold_money -= val["num"] * int(float(val["price"]) * 100) |
| | | elif L2DataUtil.is_buy(val): |
| | | # 判断价格(大于卖1) 被买吃掉 |
| | | if round(float(val["price"]), 2) - sell_1_price >= 0: |
| | | threshold_money -= val["num"] * int(float(val["price"]) * 100) |
| | | buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count, |
| | | valid_single=False) |
| | | if buy_single_index is not None: |
| | | return True, buy_single_index, [refer_sell_data[0], threshold_money], "上板无涨停卖" |
| | | |
| | | else: |
| | | # 按照成交买入信号计算 |
| | | buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count, |
| | | valid_single=True) |
| | | if buy_single_index is not None: |
| | | return True, buy_single_index, [refer_sell_data[0], 0], "上板有成交买入信号" |
| | | else: |
| | | # 板上放量 |
| | | pass |
| | | # 板上放量:只需要一笔涨停买可作为信号 |
| | | buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count, |
| | | valid_single=False) |
| | | if buy_single_index is not None: |
| | | return True, buy_single_index, [refer_sell_data[0], 0], "板上放量" |
| | | |
| | | # 获取当前是否可激进买 |
| | | # 获取板块是否可以激进买 |
| | | # 可买的板块, 是否独苗, 消息, 可买的强势板块, 关键词, 激进买的板块 |
| | | can_buy_result = CodePlateKeyBuyManager.can_buy(code) |
| | | if (can_buy_result and can_buy_result[0] and can_buy_result[5]) or constant.ALL_ACTIVE_BUY: |
| | | # 有可买板块,有激进买板块 |
| | | # 第一步: 计算总卖额 |
| | | threshold_money, sell_1_price = refer_sell_data[1], refer_sell_data[3][0] |
| | | # 第二步:计算起始信号 |
| | | second_930 = 9 * 3600 + 30 * 60 + 0 |
| | | total_datas = local_today_datas.get(code) |
| | | if end_index - start_index + 1 < continue_count: |
| | | return False, -1, "信号不连续" |
| | | last_index = None |
| | | count = 0 |
| | | start = None |
| | | for i in range(start_index, end_index + 1): |
| | | _val = total_datas[i]["val"] |
| | | time_s = L2DataUtil.get_time_as_second(_val["time"]) |
| | | # 时间要>=09:30:00 |
| | | if time_s < second_930: |
| | | continue |
| | | if L2DataUtil.is_limit_up_price_buy(_val): |
| | | # 金额要大于50万 |
| | | if _val["num"] * float(_val["price"]) < 5000: |
| | | continue |
| | | if last_index is None or ( |
| | | total_datas[last_index]["val"]["time"] == total_datas[i]["val"]["time"]): |
| | | if code.find("00") == 0 and threshold_money > 0: |
| | | # 深证非板上放量需要判断是否有信号 |
| | | single = place_order_single_data_manager.L2TradeSingleDataManager.get_valid_trade_single( |
| | | code, |
| | | tool.to_time_with_ms( |
| | | _val['time'], |
| | | _val['tms'])) |
| | | if not single: |
| | | continue |
| | | if start is None: |
| | | start = i |
| | | last_index = i |
| | | count += total_datas[i]["re"] |
| | | if count >= continue_count: |
| | | return True, start, [refer_sell_data[0], threshold_money] |
| | | else: |
| | | # 本条数据作为起点 |
| | | last_index = i |
| | | count = total_datas[i]["re"] |
| | | start = i |
| | | return False, -1, "未获取到激进买的起始信号", '' |
| | | |
| | | elif not L2DataUtil.is_sell(_val) and not L2DataUtil.is_sell_cancel(_val): |
| | | # 剔除卖与卖撤 |
| | | last_index = None |
| | | count = 0 |
| | | start = None |
| | | return False, -1, "未获取到激进买的起始信号" |
| | | @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) |
| | | |
| | | @classmethod |
| | | def __get_threshmoney(cls, code): |
| | |
| | | raise Exception("涨停价无法获取") |
| | | limit_up_price = float(limit_up_price) |
| | | |
| | | is_at_limit_up = False |
| | | current_sell_data = cls.__L2MarketSellManager.get_current_total_sell_data(code) |
| | | if current_sell_data and current_sell_data[1] ==0: |
| | | # 板上放量买 |
| | | is_at_limit_up = True |
| | | |
| | | |
| | | threshold_money = threshold_money_origin |
| | | # 目标手数 |
| | | threshold_num = 0 # round(threshold_money / (limit_up_price * 100)) |
| | | threshold_num = round(threshold_money / (limit_up_price * 100)) |
| | | bigger_threshold_num = round(5000 / (limit_up_price)) |
| | | |
| | | # buy_single_time_seconds = L2DataUtil.get_time_as_second(total_datas[buy_single_index]["val"]["time"]) |
| | |
| | | trigger_buy = True |
| | | # 间隔最大时间为3s |
| | | max_space_time_ms = 3 * 1000 |
| | | if code.find("00") == 0 and threshold_money > 0: |
| | | if code.find("00") == 0 and not is_at_limit_up: |
| | | # 深证非板上放量 |
| | | max_space_time_ms = 1 * 1000 |
| | | # 不看纯买额 |
| | | threshold_num = 0 |
| | | |
| | | # 不下单的信息 |
| | | not_buy_msg = "" |