| | |
| | | # 炸板时间在两次下单时间中间 |
| | | is_limit_up_buy = False |
| | | if is_limit_up_buy: |
| | | # 板上买且非加绿 |
| | | |
| | | # 判断成交进度到当前数据的笔数,如果少于10笔且还有未成交的大单(>=299)就可以下单 |
| | | trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code) |
| | | if trade_index is None: |
| | |
| | | total_datas[-1]["index"], |
| | | limit_up_price, min_money) |
| | | if left_count < 1: |
| | | return False, False, f"第{place_order_count + 1}下单无待成交的大单", False |
| | | return False, False, f"第{place_order_count + 1}次下单无待成交的大单", False |
| | | |
| | | # -------判断是否是量化下单,如果是就不跟到下单-------- |
| | | # 重要:量化下单会增加下单次数,板块下单中有下单次数的使用,所以板块需要在量化判断之前 |
| | |
| | | if range_indexes: |
| | | # 是否是量化单 |
| | | is_quantization_result = buy_strategy_util.is_quantization(code, range_indexes[0], range_indexes[1]) |
| | | if is_quantization_result[0]: |
| | | if is_quantization_result[0] and not gpcode_manager.GreenListCodeManager().is_in_cache(code): |
| | | # 量化单且没有加绿 |
| | | cls.__next_buy_time_dict[code] = is_quantization_result[1] |
| | | return False, True, is_quantization_result[2], True |
| | | return True, False, "满足下单条件", True |
| | |
| | | for code in sell_order_map: |
| | | cls.__total_sell_datas_dict[code] = sell_order_map[code] |
| | | |
| | | |
| | | def add_buy_datas(self, code, datas): |
| | | """ |
| | | 添加大买单数据 |
| | | @param code: 代码 |
| | | @param datas:[(买单号,总股数,总成交额)] |
| | | @param datas:[(买单号,总股数,总成交额,成交开始时间,成交结束时间)] |
| | | @return: |
| | | """ |
| | | if not datas: |
| | |
| | | return [] |
| | | return [x[2] for x in self.__total_buy_datas_dict[code]] |
| | | |
| | | def get_total_buy_data_list(self, code): |
| | | """ |
| | | 获取所有的买单数据列表 |
| | | @param code: |
| | | @return:[(买单号,总股数,总成交额,成交开始时间,成交结束时间)] |
| | | """ |
| | | return self.__total_buy_datas_dict.get(code) |
| | | |
| | | def get_total_sell_money(self, code): |
| | | """ |
| | | 获取总共的大单卖金额 |
| | |
| | | date = ps_dict.get('date') |
| | | time_str = ps_dict.get('time') |
| | | end_index = ps_dict.get('end_index') |
| | | if end_index: |
| | | end_index = int(end_index) |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | if not total_datas: |
| | | total_datas = [] |
| | |
| | | pass |
| | | try: |
| | | OpenLimitUpGoodBlocksBuyStrategy.set_current_limit_up_data(result_list_) |
| | | RadicalBuyBlockManager.compute_open_limit_up_code_dict_for_radical_buy(result_list_) |
| | | RadicalBuyBlockManager.set_current_limit_up_datas(result_list_) |
| | | except: |
| | | pass |
| | | |
| | |
| | | from log_module import log, async_log_util |
| | | from db import redis_manager_delegate as redis_manager |
| | | |
| | | from log_module.log import logger_kpl_block_can_buy |
| | | from log_module.log import logger_kpl_block_can_buy, logger_debug |
| | | from third_data.kpl_util import KPLPlatManager |
| | | from trade import trade_manager, l2_trade_util, trade_constant |
| | | |
| | |
| | | 激进买板块管理 |
| | | """ |
| | | __TargetCodePlateKeyManager = TargetCodePlateKeyManager() |
| | | # 上次的涨停代码 |
| | | __last_limit_up_codes = set() |
| | | # 记录代码的涨停时间 |
| | | __limit_up_time_dict = {} |
| | | # 炸板代码的总涨停时间 |
| | | __total_limit_up_space_dict = {} |
| | | |
| | | # 当前涨停的代码 |
| | | __current_limit_up_codes = set() |
| | | |
| | | @classmethod |
| | | def set_current_limit_up_datas(cls, current_limit_up_datas): |
| | | # 查询当前的涨停代码集合 |
| | | codes = set([d[0] for d in current_limit_up_datas]) |
| | | cls.__current_limit_up_codes = codes |
| | | try: |
| | | # 炸板代码 |
| | | break_limit_up_codes = cls.__last_limit_up_codes - codes |
| | | # 新涨停的代码 |
| | | new_limit_up_codes = codes - cls.__last_limit_up_codes |
| | | if new_limit_up_codes: |
| | | for code in new_limit_up_codes: |
| | | if code not in cls.__limit_up_time_dict: |
| | | cls.__limit_up_time_dict[code] = time.time() |
| | | if break_limit_up_codes: |
| | | # 记录总涨停时间 |
| | | for bc in break_limit_up_codes: |
| | | if bc in cls.__limit_up_time_dict: |
| | | space = tool.trade_time_sub(tool.get_now_time_str(), |
| | | tool.to_time_str(cls.__limit_up_time_dict[bc])) |
| | | if bc not in cls.__total_limit_up_space_dict: |
| | | cls.__total_limit_up_space_dict[bc] = 0 |
| | | cls.__total_limit_up_space_dict[bc] = cls.__total_limit_up_space_dict[bc] + space |
| | | logger_debug.info(f"炸板代码涨停时间:{bc}-{cls.__total_limit_up_space_dict[bc]}") |
| | | cls.__limit_up_time_dict.pop(bc) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | finally: |
| | | cls.__last_limit_up_codes = codes |
| | | cls.compute_open_limit_up_code_dict_for_radical_buy(current_limit_up_datas) |
| | | |
| | | @classmethod |
| | | def compute_open_limit_up_code_dict_for_radical_buy(cls, current_limit_up_datas): |
| | |
| | | 获取历史涨停身位 |
| | | @param code: |
| | | @param block: |
| | | @param current_limit_up_datas: |
| | | @param current_limit_up_datas: 昨日涨停代码 |
| | | @param current_limit_up_codes: 目前的涨停代码 |
| | | @return: |
| | | """ |
| | | history_index = 0 |
| | | block_codes_infos = [] |
| | | # 开1时间范围 |
| | | timestamp_start, timestamp_end = kpl_block_util.open_limit_up_time_range |
| | | limit_up_time = time.time() |
| | | for k in LimitUpDataConstant.history_limit_up_datas: |
| | |
| | | # 剔除高位板 |
| | | if _code in yesterday_limit_up_codes: |
| | | continue |
| | | # 代码.涨停时间 |
| | | # 剔除炸板代码持续涨停时间小于1分钟的代码 |
| | | if _code not in cls.__current_limit_up_codes and _code in cls.__total_limit_up_space_dict and cls.__total_limit_up_space_dict[_code] < 60: |
| | | continue |
| | | # 代码,涨停时间 |
| | | block_codes_infos.append((_code, int(k[5]))) |
| | | block_codes_infos.append((code, limit_up_time)) |
| | | block_codes_infos.sort(key=lambda x: x[1]) |
| | |
| | | else: |
| | | return JueJinHttpApi.get_exchanges_codes(exchanges=exchanges, sec_types=[1], skip_suspended=skip_suspended, |
| | | skip_st=skip_st, |
| | | fields="symbol,sec_type,sec_id,sec_name,listed_date,sec_level,is_suspended,pre_close") |
| | | fields="symbol,sec_type,sec_id,sec_name,listed_date,sec_level," |
| | | "is_suspended,pre_close") |
| | | |
| | | @classmethod |
| | | def get_history_instruments(cls, symbols, start_date, end_date, fields=None): |
| | |
| | | @classmethod |
| | | def get_previous_trading_date(cls, date): |
| | | if constant.JUEJIN_LOCAL_API: |
| | | account_id, s_id, token = cls.getJueJinAccountInfo() |
| | | gmapi.set_token(token) |
| | | return gmapi.get_previous_trading_date("SHSE", date) |
| | | # account_id, s_id, token = cls.getJueJinAccountInfo() |
| | | # gmapi.set_token(token) |
| | | # return gmapi.get_previous_trading_date("SHSE", date) |
| | | pass |
| | | else: |
| | | return JueJinHttpApi.get_previous_trading_date("SHSE", date) |
| | | |
| | |
| | | from code_attribute import gpcode_manager |
| | | import l2.l2_data_util |
| | | from l2.huaxin import l2_huaxin_util |
| | | from l2.l2_transaction_data_manager import BigOrderDealManager |
| | | from log_module import log, log_export |
| | | from l2 import l2_data_source_util, l2_data_util |
| | | from log_module.log import logger_debug |
| | |
| | | if datas[i]["index"] == end_index: |
| | | datas = datas[:i] |
| | | break |
| | | # 成交的大单信息[(买单号,总股数,总成交额,成交开始时间,成交结束时间)] |
| | | deal_big_buy_order_list = copy.deepcopy(BigOrderDealManager().get_total_buy_data_list(code)) |
| | | deal_big_buy_order_no_dict = {} |
| | | if deal_big_buy_order_list: |
| | | for d in deal_big_buy_order_list: |
| | | deal_big_buy_order_no_dict[d[0]] = d |
| | | |
| | | fdatas = export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes, deal_list_dict, sell_nos, |
| | | active_sell_set, cancel_reasons) |
| | | active_sell_set, cancel_reasons, deal_big_buy_order_no_dict) |
| | | return fdatas |
| | | |
| | | |
| | |
| | | |
| | | |
| | | def export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes, deal_list_dict, sell_nos, |
| | | active_sell_nos, cancel_reasons): |
| | | active_sell_nos, cancel_reasons, deal_big_buy_order_no_dict): |
| | | def find_process_index(index): |
| | | for i in range(0, len(process_indexs)): |
| | | if process_indexs[i][0] <= index <= process_indexs[i][1]: |
| | |
| | | # 最新的一条数据 |
| | | latest_data = datas[-1] |
| | | latest_time_str_with_ms = l2.l2_data_util.L2DataUtil.get_time_with_ms(latest_data["val"]) |
| | | |
| | | |
| | | # 数据预处理 |
| | | num_operate_map = {} |
| | |
| | | if data['val']['orderNo'] in active_sell_nos: |
| | | # 过滤主动卖 |
| | | continue |
| | | |
| | | # 移除成交大单在L2中已有的订单 |
| | | if l2.l2_data_util.L2DataUtil.is_limit_up_price_buy(data["val"]): |
| | | if int(data['val']['orderNo']) in deal_big_buy_order_no_dict: |
| | | deal_big_buy_order_no_dict.pop(int(data['val']['orderNo'])) |
| | | |
| | | trade_info = find_trade_index(data["index"]) |
| | | if not trade_info: |
| | |
| | | # 成交时间不能比当前索引时间大 |
| | | cancel_info = l2_huaxin_util.convert_time(deal_info[4], |
| | | with_ms=True) |
| | | if tool.trade_time_sub_with_ms(cancel_info , latest_time_str_with_ms) > 0: |
| | | if tool.trade_time_sub_with_ms(cancel_info, latest_time_str_with_ms) > 0: |
| | | cancel_info = None |
| | | format_data.append(cancel_info) |
| | | cancel_order_info = None |
| | |
| | | format_data.append(cancel_order_info) |
| | | format_data.append(data["val"].get("orderNo")) |
| | | fdatas.append((style_int, trade_info, format_data)) |
| | | |
| | | if tool.is_sh_code(code) and deal_big_buy_order_no_dict: |
| | | # 上证,有主动成交的大单 |
| | | active_deal_list = [deal_big_buy_order_no_dict[order_no] for order_no in deal_big_buy_order_no_dict] |
| | | active_deal_list.sort(key=lambda x: x[3]) |
| | | for i in range(len(active_deal_list)): |
| | | d = active_deal_list[i] |
| | | format_data = [0] |
| | | format_data.append(l2_huaxin_util.convert_time(d[3], with_ms=True)) |
| | | format_data.append('') |
| | | format_data.append(f"{round(d[2] / 10000, 1)}万") |
| | | format_data.append(round(d[2] / d[1], 2)) |
| | | format_data.append(d[1] // 100) |
| | | format_data.append('买') |
| | | format_data.append(1) |
| | | format_data.append(l2_huaxin_util.convert_time(d[4], with_ms=True)) |
| | | format_data.append(d[0]) |
| | | fdatas.insert(i, (0, None, format_data)) |
| | | logger_debug.info("循环组装数据完成") |
| | | return fdatas |
| | | |