| | |
| | | # threshold_rate = max(threshold_rate, 0.79) |
| | | threshold_rate = constant.L_CANCEL_RATE |
| | | if constant.CAN_AUTO_L_DOWN_RATE_CHANGE: |
| | | # TODO 最长涨停时间超过1分钟 |
| | | try: |
| | | if MaxPriceInfoManager().get_max_limit_up_time(code) > 60: |
| | | deal_big_order_info = radical_buy_data_manager.get_total_deal_big_order_info(code, |
| | | gpcode_manager.get_limit_up_price_as_num( |
| | | code)) |
| | | if deal_big_order_info: |
| | | if deal_big_order_info and deal_big_order_info[5]>5000e4: |
| | | temp_rate = round(deal_big_order_info[1] / deal_big_order_info[5], 2) |
| | | threshold_rate = min(max(temp_rate, 0.3), 0.9) |
| | | except: |
| | |
| | | not_deal_indexes] |
| | | return all_money_list, deal_money_list, canceled_money_list, not_deal_money_list |
| | | |
| | | def statistic_total_big_order_info(self, code): |
| | | """ |
| | | 统计L后的大单信息 |
| | | @param code: |
| | | @return: 囊括金额列表, 成交金额列表, 撤单金额列表, 待成交列表 |
| | | """ |
| | | trade_index, is_default = TradeBuyQueue().get_traded_index(code) |
| | | if trade_index is None: |
| | | trade_index = 0 |
| | | real_place_order_index_info = self.__real_place_order_index_dict.get(code) |
| | | if not real_place_order_index_info: |
| | | return None |
| | | total_datas = local_today_datas.get(code) |
| | | # 统计囊括,已成,已撤,待成交 |
| | | all_indexes = set() |
| | | deal_indexes = set() |
| | | canceled_indexes = set() |
| | | not_deal_indexes = set() |
| | | big_money_threshold = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code), tool.is_ge_code(code)) |
| | | big_num_threshold = int(big_money_threshold/gpcode_manager.get_limit_up_price_as_num(code)/100) |
| | | for index in range(0,total_datas[-1]): |
| | | data = total_datas[index] |
| | | val = data["val"] |
| | | if val['num']<big_num_threshold: |
| | | continue |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | all_indexes.add(index) |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, |
| | | index, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count == 0: |
| | | canceled_indexes.add(index) |
| | | continue |
| | | if index < trade_index: |
| | | deal_indexes.add(index) |
| | | continue |
| | | not_deal_indexes.add(index) |
| | | all_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | all_indexes] |
| | | deal_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | deal_indexes] |
| | | canceled_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | canceled_indexes] |
| | | not_deal_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | not_deal_indexes] |
| | | return all_money_list, deal_money_list, canceled_money_list, not_deal_money_list |
| | | # def statistic_total_big_order_info(self, code): |
| | | # """ |
| | | # 统计L后的大单信息 |
| | | # @param code: |
| | | # @return: 囊括金额列表, 成交金额列表, 撤单金额列表, 待成交列表 |
| | | # """ |
| | | # trade_index, is_default = TradeBuyQueue().get_traded_index(code) |
| | | # if trade_index is None: |
| | | # trade_index = 0 |
| | | # real_place_order_index_info = self.__real_place_order_index_dict.get(code) |
| | | # if not real_place_order_index_info: |
| | | # return None |
| | | # total_datas = local_today_datas.get(code) |
| | | # # 统计囊括,已成,已撤,待成交 |
| | | # all_indexes = set() |
| | | # deal_indexes = set() |
| | | # canceled_indexes = set() |
| | | # not_deal_indexes = set() |
| | | # big_money_threshold = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code), tool.is_ge_code(code)) |
| | | # big_num_threshold = int(big_money_threshold/gpcode_manager.get_limit_up_price_as_num(code)/100) |
| | | # for index in range(0,total_datas[-1]): |
| | | # data = total_datas[index] |
| | | # val = data["val"] |
| | | # if val['num']<big_num_threshold: |
| | | # continue |
| | | # if not L2DataUtil.is_limit_up_price_buy(val): |
| | | # continue |
| | | # all_indexes.add(index) |
| | | # left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, |
| | | # index, |
| | | # total_datas, |
| | | # local_today_canceled_buyno_map.get( |
| | | # code)) |
| | | # if left_count == 0: |
| | | # canceled_indexes.add(index) |
| | | # continue |
| | | # if index < trade_index: |
| | | # deal_indexes.add(index) |
| | | # continue |
| | | # not_deal_indexes.add(index) |
| | | # all_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | # all_indexes] |
| | | # deal_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | # deal_indexes] |
| | | # canceled_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | # canceled_indexes] |
| | | # not_deal_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in |
| | | # not_deal_indexes] |
| | | # return all_money_list, deal_money_list, canceled_money_list, not_deal_money_list |
| | | |
| | | def statistic_l_down_watch_indexes_info(self, code): |
| | | """ |
| | |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_debug |
| | | from log_module.log import logger_debug, logger_limit_up_record |
| | | from utils import global_util, tool |
| | | |
| | | |
| | |
| | | tool.CodeDataCacheUtil.set_cache(self.__max_price_info_cache, code, price_info) |
| | | RedisUtils.setex_async( |
| | | self.__db, "max_price_info-{}".format(code), tool.get_expire(), json.dumps(price_info)) |
| | | async_log_util.info(logger_debug, f"最大现价:{code}-{price_info}") |
| | | # async_log_util.info(logger_debug, f"最大现价:{code}-{price_info}") |
| | | if self.__is_limit_up(code, price, sell1_info): |
| | | if code not in self.__limit_up_latest_info_cache: |
| | | self.__limit_up_latest_info_cache[code] = time |
| | |
| | | if code not in self.__limit_up_records_cache: |
| | | self.__limit_up_records_cache[code] = [] |
| | | if code in self.__limit_up_latest_info_cache: |
| | | self.__limit_up_records_cache[code].append((self.__limit_up_latest_info_cache.get(code), time)) |
| | | limit_up_info = (self.__limit_up_latest_info_cache.get(code), time) |
| | | self.__limit_up_records_cache[code].append(limit_up_info) |
| | | self.__limit_up_latest_info_cache.pop(code) |
| | | async_log_util.info(logger_limit_up_record, f"{code}-{limit_up_info}") |
| | | |
| | | def get_max_limit_up_time(self, code): |
| | | """ |
| | |
| | | max_space_time = 0 |
| | | if code in self.__limit_up_latest_info_cache: |
| | | max_space_time = tool.trade_time_sub(tool.get_now_time_str(), self.__limit_up_latest_info_cache[code]) |
| | | if code in self.__limit_up_records_cache: |
| | | if self.__limit_up_records_cache.get(code): |
| | | max_item = max(self.__limit_up_records_cache[code], key=lambda x: tool.trade_time_sub(x[1], x[0])) |
| | | max_space_time_his = tool.trade_time_sub(max_item[1], max_item[0]) |
| | | if max_space_time_his > max_space_time: |
| | | max_space_time = max_space_time_his |
| | | return max_space_time |
| | | except Exception as e: |
| | | async_log_util.error(logger_debug, f"获取最大涨停时间出错:{str(e)}") |
| | | async_log_util.error(logger_debug, f"获取最大涨停时间出错:{code}-{str(e)}") |
| | | return 0 |
| | | |
| | | def get_price_info_cache(self, code): |
| | |
| | | if b[0] > fdata[0][7]: |
| | | # 买单在卖单之后 |
| | | big_buy_order_count += 1 |
| | | |
| | | cls.__callback.OnTradeSingle(code, big_buy_order_count, cls.TYPE_PASSIVE, cls.__latest_sell_data_dict[code]) |
| | | |
| | | @classmethod |
| | |
| | | filter=lambda record: record["extra"].get("name") == "kpl_new_blocks", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | |
| | | |
| | | logger.add(self.get_path("kpl", "kpl_debug"), |
| | | filter=lambda record: record["extra"].get("name") == "kpl_debug", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | |
| | | |
| | | logger.add(self.get_path("profile", "profile"), |
| | | filter=lambda record: record["extra"].get("name") == "profile", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_path("limit_up", "limit_up_record"), |
| | | filter=lambda record: record["extra"].get("name") == "limit_up_record", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | ################################华鑫日志################################ |
| | |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_local_huaxin_path("l2", "transaction_accurate_big_order"), |
| | | filter=lambda record: record["extra"].get("name") == "local_huaxin_transaction_for_accurate_big_order", |
| | | filter=lambda record: record["extra"].get( |
| | | "name") == "local_huaxin_transaction_for_accurate_big_order", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_local_huaxin_path("l2", "orderdetail"), |
| | |
| | | # 开盘啦市场强度 |
| | | logger_kpl_market_strong = __mylogger.get_logger("kpl_market_strong") |
| | | |
| | | |
| | | |
| | | logger_plate_special_codes = __mylogger.get_logger("plate_special_codes") |
| | | |
| | | logger_plate_code_plates = __mylogger.get_logger("plate_code_plates") |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | logger_limit_up_record = __mylogger.get_logger("limit_up_record") |
| | | |
| | | logger_kp_msg = __mylogger.get_logger("kp_msg") |
| | | |
| | |
| | | # -------------------------------华鑫本地日志--------------------------------- |
| | | logger_local_huaxin_l2_transaction = __mylogger.get_logger("local_huaxin_transaction") |
| | | logger_local_huaxin_l2_transaction_big_order = __mylogger.get_logger("local_huaxin_transaction_for_big_order") |
| | | logger_local_huaxin_l2_transaction_accurate_big_order = __mylogger.get_logger("local_huaxin_transaction_for_accurate_big_order") |
| | | logger_local_huaxin_l2_transaction_accurate_big_order = __mylogger.get_logger( |
| | | "local_huaxin_transaction_for_accurate_big_order") |
| | | logger_local_huaxin_l2_orderdetail = __mylogger.get_logger("local_huaxin_orderdetail") |
| | | logger_local_huaxin_l2_upload = __mylogger.get_logger("local_huaxin_upload") |
| | | logger_local_huaxin_l2_error = __mylogger.get_logger("local_huaxin_error") |
| | |
| | | # 收盘价日志 |
| | | logger_pre_close_price = __mylogger.get_logger("pre_close_price") |
| | | logger_codes_zyltgb = __mylogger.get_logger("codes_zyltgb") |
| | | |
| | | |
| | | |
| | | def close_print(): |
| | |
| | | import inited_data |
| | | from api import low_suction_data_pusher |
| | | from code_attribute.code_l1_data_manager import L1DataManager |
| | | from code_attribute.gpcode_manager import BlackListCodeManager, HumanRemoveForbiddenManager, CodePrePriceManager |
| | | from code_attribute.gpcode_manager import BlackListCodeManager, HumanRemoveForbiddenManager, CodePrePriceManager, \ |
| | | HumanForbiddenManager |
| | | from l2.code_price_manager import CurrentPriceManager |
| | | from l2.huaxin import huaxin_target_codes_manager |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager |
| | |
| | | from trade.buy_strategy import OpenLimitUpGoodBlocksBuyStrategy |
| | | from trade.buy_radical.radical_buy_data_manager import RadicalBuyBlockManager, BeforeSubDealBigOrderManager |
| | | from trade.huaxin import huaxin_trade_record_manager |
| | | from trade.order_statistic import DealAndDelegateWithBuyModeDataManager |
| | | from trade.trade_data_manager import RadicalBuyDealCodesManager |
| | | from utils import global_util, tool, data_export_util, init_data_util, huaxin_util |
| | | from code_attribute import gpcode_manager, code_nature_analyse |
| | |
| | | # 拉取最近成交信息 |
| | | fdatas = [] |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | deal_codes = DealAndDelegateWithBuyModeDataManager().get_deal_codes() |
| | | for code in codes: |
| | | try: |
| | | if code in yesterday_codes: |
| | | continue |
| | | if l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | |
| | | if l2_trade_util.is_in_forbidden_trade_codes(code) and code not in deal_codes: |
| | | # 拉黑但是没成交 |
| | | continue |
| | | |
| | | # 人为拉黑的需要移除 |
| | | if HumanForbiddenManager().is_in_cache(code): |
| | | continue |
| | | |
| | | # (代码,名称,涨停时间,涨幅,现手,自由市值,现价) |
| | |
| | | zyltgb = zylt_volume * limit_up_price |
| | | if latest_transaction_data: |
| | | data.append( |
| | | (latest_transaction_data[2] // 100, latest_transaction_data[6] - latest_transaction_data[7])) |
| | | (latest_transaction_data[2] // 100, |
| | | latest_transaction_data[6] - latest_transaction_data[7])) |
| | | else: |
| | | data.append(("--", 0)) |
| | | data.append(output_util.money_desc(zyltgb) if zyltgb else '--') |
| | |
| | | # 显示代码板块身位 |
| | | block_rank_info = None |
| | | # 获取当前板块 |
| | | blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) |
| | | try: |
| | | if limit_up_time: |
| | | # 涨停过的数据才有身位 |
| | | blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) |
| | | |
| | | if blocks: |
| | | blocks_info = [] |
| | | for b in blocks: |
| | | info = radical_buy_data_manager.RadicalBuyBlockManager.get_history_index(code, b, |
| | | info = radical_buy_data_manager.RadicalBuyBlockManager.get_history_index(code, |
| | | b, |
| | | yesterday_codes) |
| | | blocks_info.append((b, info[0], info[2])) |
| | | max_info = max(blocks_info, key=lambda x: x[2]) |
| | | block_rank_info = max_info |
| | | except: |
| | | pass |
| | | data.append(block_rank_info) |
| | | data.append((block_rank_info, blocks)) |
| | | # 交易状态: |
| | | trade_state = trade_manager.CodesTradeStateManager().get_trade_state(code) |
| | | data.append(trade_state) |
| | | |
| | | fdatas.append(data) |
| | | except Exception as e1: |
| | | logger_debug.exception(e1) |
| | |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | elif url.path == "/get_l2_down_watch_index_overview": |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | code = ps_dict.get('code') |
| | | # 大单概览 |
| | | l2_down_data = LCancelBigNumComputer().statistic_l_down_watch_indexes_of_big_order_info(code) |
| | | total_big_order_info = LCancelBigNumComputer().statistic_total_big_order_info(code) |
| | | response_data = json.dumps({"code": 0, "data": {"l_down":l2_down_data,"total":total_big_order_info}}) |
| | | try: |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |
| | | code = ps_dict.get('code') |
| | | # 大单概览 |
| | | l2_down_data = LCancelBigNumComputer().statistic_l_down_watch_indexes_of_big_order_info(code) |
| | | # total_big_order_info = LCancelBigNumComputer().statistic_total_big_order_info(code) |
| | | response_data = json.dumps({"code": 0, "data": {"l_down": l2_down_data}}) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | |
| | | async_log_util.info(logger_request_api, f"结束请求{tool.get_thread_id()}-{url}") |
| | | self.send_response(200) |
| | |
| | | @param data: |
| | | @return: |
| | | """ |
| | | l2_log.debug(code, "最近涨停卖被吃掉{}, {}", code, f"{data}") |
| | | # 暂时不处理 |
| | | if True: |
| | | return |
| | | # 只处理深证的票 |
| | | try: |
| | | # 判断是否下单 |
| | | state = CodesTradeStateManager().get_trade_state_cache(code) |
| | | if state == trade_constant.TRADE_STATE_BUY_DELEGATED or state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or state == trade_constant.TRADE_STATE_BUY_SUCCESS: |
| | | # 已经下单了 |
| | | return |
| | | |
| | | l2_log.debug(code, "成交触发买入计算 触发模式:{} 大单数量:{}", _type, big_buy_order_count) |
| | | |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | |
| | | mode_descs = [] |
| | | # if big_buy_order_count > 0: |
| | | # mode_descs.append("300w") |
| | | if l2_data_manager_new.L2TradeDataProcessor.get_active_buy_blocks(code): |
| | | mode_descs.append("身位") |
| | | |
| | | current_total_sell_data = L2MarketSellManager().get_current_total_sell_data(code) |
| | | sell_info = None |
| | | if current_total_sell_data: |
| | | sell_info = (current_total_sell_data[0], current_total_sell_data[1]) |
| | | |
| | | if _type == L2TradeSingleDataManager.TYPE_PASSIVE and mode_descs: |
| | | # 可以激进下单且必须是首次下单才能激进 |
| | | place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) |
| | | if tool.is_sz_code(code) and place_order_count == 0 and current_total_sell_data[ |
| | | 1] > 500 * 10000 and global_util.zyltgb_map.get( |
| | | code) < 50 * 100000000: |
| | | # 首次下单,自由流通50亿以下,总卖额500w才能激进下单 |
| | | mode_descs.insert(0, "成交触发") |
| | | last_index = total_datas[-1]["index"] |
| | | volume_rate = code_volumn_manager.CodeVolumeManager().get_volume_rate(code) |
| | | order_begin_pos = OrderBeginPosInfo(buy_single_index=last_index, |
| | | buy_exec_index=last_index, |
| | | buy_compute_index=last_index, |
| | | num=0, count=1, |
| | | max_num_set=set(), |
| | | buy_volume_rate=volume_rate, |
| | | mode=OrderBeginPosInfo.MODE_ACTIVE, |
| | | mode_desc=",".join(mode_descs), |
| | | sell_info=sell_info, |
| | | threshold_money=0) |
| | | l2_data_manager_new.L2TradeDataProcessor.save_order_begin_data(code, order_begin_pos) |
| | | l2_log.debug(code, "积极下单,获取到买入执行位置:{} 成交数据触发模式:{} 大单数量:{}", |
| | | order_begin_pos.buy_exec_index, |
| | | _type, big_buy_order_count) |
| | | l2_data_manager_new.L2TradeDataProcessor.start_buy(code, total_datas[-1], total_datas[-1]["index"], |
| | | True, None) |
| | | else: |
| | | l2_log.debug(code, "积极下单,不满足扫入下单条件,无法扫入") |
| | | else: |
| | | if not tool.is_sz_code(code): |
| | | return |
| | | # 找到最近的大买单 |
| | | for i in range(len(total_datas) - 1, -1, -1): |
| | | d = total_datas[i] |
| | | val = d['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | if val['num'] * float(val['price']) < 5000: |
| | | continue |
| | | if val['orderNo'] < data[0][6]: |
| | | continue |
| | | result = L2TradeSingleDataManager.is_can_place_order(code, d) |
| | | if result and result[0]: |
| | | volume_rate = code_volumn_manager.CodeVolumeManager().get_volume_rate(code) |
| | | order_begin_pos = OrderBeginPosInfo(buy_single_index=i, |
| | | buy_exec_index=i, |
| | | buy_compute_index=i, |
| | | num=0, count=1, |
| | | max_num_set=set(), |
| | | buy_volume_rate=volume_rate, |
| | | mode=OrderBeginPosInfo.MODE_FAST, |
| | | mode_desc="成交触发", |
| | | sell_info=sell_info, |
| | | threshold_money=0) |
| | | l2_data_manager_new.L2TradeDataProcessor.save_order_begin_data(code, order_begin_pos) |
| | | l2_log.debug(code, "非激进下单,获取到买入执行位置:{} 成交数据触发模式:{}", |
| | | order_begin_pos.buy_exec_index, |
| | | _type) |
| | | l2_data_manager_new.L2TradeDataProcessor.start_buy(code, total_datas[-1], |
| | | total_datas[-1]["index"], |
| | | True, None) |
| | | break |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | self.process_limit_up_active_buy(code, [data[0]], is_last_sell_deal=True) |
| | | |
| | | def process_limit_up_active_buy(self, code, transaction_datas, is_almost_open_limit_up=False, |
| | | l2_market_time_str='', no_left_limit_up_sell=False): |
| | | l2_market_time_str='', no_left_limit_up_sell=False, is_last_sell_deal=False): |
| | | """ |
| | | 处理涨停主动买 |
| | | @param is_last_sell_deal: 是否最近一笔涨停卖被吃 |
| | | @param no_left_limit_up_sell: 是否还有剩余涨停卖尚未成交 |
| | | @param code: |
| | | @param transaction_datas: |
| | |
| | | return True |
| | | |
| | | # -----根据成交比例判断是否可买------ |
| | | result_by_volume = radical_buy_strategy.process_limit_up_active_buy_deal(code, transaction_datas, |
| | | if not is_last_sell_deal: |
| | | result_by_volume = radical_buy_strategy.process_limit_up_active_buy_deal(code, transaction_datas, |
| | | is_almost_open_limit_up, |
| | | no_left_limit_up_sell=no_left_limit_up_sell) |
| | | else: |
| | | result_by_volume = radical_buy_strategy.BUY_MODE_BY_L2, f"最后一笔涨停卖成交" |
| | | l2_log.info(code, logger_l2_radical_buy, f"量买入结果判断:{code}, 结果:{result_by_volume} 板块:{buy_blocks}") |
| | | in_blocks = RealTimeKplMarketData.get_top_market_jingxuan_blocks() |
| | | buy_blocks_with_money = [(b, RealTimeKplMarketData.get_jx_block_in_money(b), |