| | |
| | | from code_attribute import gpcode_manager |
| | | from log_module import log, log_analyse, log_export |
| | | from l2 import code_price_manager, l2_data_util, l2_data_manager_new, cancel_buy_strategy, transaction_progress |
| | | from l2.cancel_buy_strategy import HourCancelBigNumComputer |
| | | from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer, LCancelRateManager |
| | | from output.limit_up_data_filter import IgnoreCodeManager |
| | | from third_data import kpl_util, kpl_data_manager, kpl_api, block_info |
| | | from third_data.code_plate_key_manager import RealTimeKplMarketData, KPLPlateForbiddenManager, CodePlateKeyBuyManager |
| | |
| | | from urllib.parse import parse_qs |
| | | from output import code_info_output, limit_up_data_filter, output_util, kp_client_msg_manager |
| | | |
| | | from trade import bidding_money_manager, trade_manager, l2_trade_util, trade_record_log_util |
| | | from trade import bidding_money_manager, trade_manager, l2_trade_util, trade_record_log_util, trade_constant |
| | | import concurrent.futures |
| | | |
| | | # 禁用http.server的日志输出 |
| | |
| | | trade_progress, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code) |
| | | # 获取正在成交, 计算成交进度 |
| | | dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code) |
| | | percent = 0 |
| | | percent = 100 |
| | | if dealing_info: |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | if str(total_datas[trade_progress]['val']["orderNo"]) == str(dealing_info[0]): |
| | |
| | | for d in record_limit_up_datas: |
| | | if kpl_util.filter_block(d[2]) != plate: |
| | | continue |
| | | # 代码,名称,涨停时间,是否炸板,是否想买,是否已经下过单 |
| | | # 代码,名称,涨停时间,是否炸板,是否想买,是否已经下过单,涨停时间,自由流通市值,是否在黑名单里面 |
| | | codes_info.append( |
| | | [d[3], d[4], tool.to_time_str(int(d[5])), 1 if d[3] not in now_limit_up_codes else 0, 0, 0, d[12], |
| | | output_util.money_desc(d[13]), 1]) |
| | | output_util.money_desc(d[13]), 1, 1 if l2_trade_util.is_in_forbidden_trade_codes(d[3]) else 0]) |
| | | |
| | | for d in record_limit_up_datas: |
| | | if kpl_util.filter_block(d[2]) == plate: |
| | | continue |
| | | if plate not in [kpl_util.filter_block(k) for k in d[6].split("、")]: |
| | | continue |
| | | # 代码,名称,涨停时间,是否炸板,是否想买,是否已经下过单 |
| | | # 代码,名称,涨停时间,是否炸板,是否想买,是否已经下过单,涨停时间,自由流通市值,是否在黑名单里面 |
| | | codes_info.append( |
| | | [d[3], d[4], tool.to_time_str(int(d[5])), 1 if d[3] not in now_limit_up_codes else 0, 0, 0, d[12], |
| | | output_util.money_desc(d[13]), 0]) |
| | | output_util.money_desc(d[13]), 0, 1 if l2_trade_util.is_in_forbidden_trade_codes(d[3]) else 0]) |
| | | |
| | | codes_info.sort(key=lambda x: x[2]) |
| | | # 查询是否为想买单 |
| | |
| | | code_info[4] = 1 if code_info[0] in want_codes else 0 |
| | | # 获取代码状态 |
| | | if trade_manager.CodesTradeStateManager().get_trade_state_cache( |
| | | code_info[0]) != trade_manager.TRADE_STATE_NOT_TRADE: |
| | | code_info[0]) != trade_constant.TRADE_STATE_NOT_TRADE: |
| | | code_info[5] = 1 |
| | | |
| | | response_data = json.dumps({"code": 0, "data": codes_info}) |
| | |
| | | statistic = {} |
| | | for result in results: |
| | | for c in result[1]: |
| | | if not tool.is_shsz_code(c): |
| | | if not tool.is_can_buy_code(c): |
| | | continue |
| | | if code and code != c: |
| | | continue |
| | |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | |
| | | trade_state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code) |
| | | if trade_state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_manager.TRADE_STATE_BUY_DELEGATED or trade_state == trade_manager.TRADE_STATE_BUY_SUCCESS: |
| | | if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED or trade_state == trade_constant.TRADE_STATE_BUY_SUCCESS: |
| | | hcancel_datas_dict, cancel_indexes_set = HourCancelBigNumComputer().get_watch_index_dict(code) |
| | | # 根据日志读取实时的计算数据 |
| | | h_cancel_latest_compute_info = log_export.get_h_cancel_compute_info(code) |
| | |
| | | |
| | | def __process_kpl_data(self, data_origin): |
| | | def do_limit_up(result_list_): |
| | | if result_list_: |
| | | # 保存涨停时间 |
| | | codes_set = set() |
| | | limit_up_reasons = {} |
| | | for d in result_list_: |
| | | code = d[0] |
| | | limit_up_reasons[code] = d[5] |
| | | codes_set.add(code) |
| | | if tool.is_shsz_code(code): |
| | | limit_up_time = time.strftime("%H:%M:%S", time.localtime(d[2])) |
| | | code_price_manager.Buy1PriceManager().set_limit_up_time(code, limit_up_time) |
| | | add_codes = codes_set - self.__latest_limit_up_codes_set |
| | | self.__latest_limit_up_codes_set = codes_set |
| | | try: |
| | | if result_list_: |
| | | # 保存涨停时间 |
| | | codes_set = set() |
| | | limit_up_reasons = {} |
| | | for d in result_list_: |
| | | code = d[0] |
| | | limit_up_reasons[code] = d[5] |
| | | codes_set.add(code) |
| | | if tool.is_can_buy_code(code): |
| | | limit_up_time = time.strftime("%H:%M:%S", time.localtime(d[2])) |
| | | code_price_manager.Buy1PriceManager().set_limit_up_time(code, limit_up_time) |
| | | add_codes = codes_set - self.__latest_limit_up_codes_set |
| | | self.__latest_limit_up_codes_set = codes_set |
| | | |
| | | if limit_up_reasons: |
| | | # 统计涨停原因的票的个数 |
| | | limit_up_reason_code_dict = {} |
| | | for code in limit_up_reasons: |
| | | b = limit_up_reasons[code] |
| | | if b not in limit_up_reason_code_dict: |
| | | limit_up_reason_code_dict[b] = set() |
| | | limit_up_reason_code_dict[b].add(code) |
| | | cancel_buy_strategy.LCancelRateManager.set_block_limit_up_count(limit_up_reason_code_dict) |
| | | if limit_up_reasons: |
| | | # 统计涨停原因的票的个数 |
| | | limit_up_reason_code_dict = {} |
| | | for code in limit_up_reasons: |
| | | b = limit_up_reasons[code] |
| | | if b not in limit_up_reason_code_dict: |
| | | limit_up_reason_code_dict[b] = set() |
| | | limit_up_reason_code_dict[b].add(code) |
| | | LCancelRateManager.set_block_limit_up_count(limit_up_reason_code_dict) |
| | | |
| | | if add_codes: |
| | | for code in add_codes: |
| | | # 根据涨停原因判断是否可以买 |
| | | if tool.is_shsz_code(code): |
| | | try: |
| | | # 判断是否下单 |
| | | trade_state = trade_manager.CodesTradeStateManager().get_trade_state(code) |
| | | if trade_state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_manager.TRADE_STATE_BUY_DELEGATED: |
| | | # 委托中的订单,判断是否需要撤单 |
| | | if not gpcode_manager.WantBuyCodesManager().is_in_cache(code): |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, before_blocks_dict = kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas, kpl_data_manager.KPLLimitUpDataRecordManager.total_datas, yesterday_codes, block_info.get_before_blocks_dict() |
| | | if not current_limit_up_datas: |
| | | current_limit_up_datas = [] |
| | | if not limit_up_record_datas: |
| | | limit_up_record_datas = [] |
| | | # 买绝对老大 |
| | | # 中途不能撤单 |
| | | # if CodePlateKeyBuyManager.is_need_cancel(code, limit_up_reasons.get(code), |
| | | # current_limit_up_datas, |
| | | # limit_up_record_datas, |
| | | # yesterday_current_limit_up_codes, |
| | | # before_blocks_dict): |
| | | # l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, |
| | | # f"涨停原因({limit_up_reasons.get(code)})不是老大撤单", |
| | | # "板块撤") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(), result_list_) |
| | | self.__kplDataManager.save_data(type_, result_list_) |
| | | |
| | | if add_codes: |
| | | for code in add_codes: |
| | | # 根据涨停原因判断是否可以买 |
| | | if tool.is_can_buy_code(code): |
| | | try: |
| | | # 判断是否下单 |
| | | trade_state = trade_manager.CodesTradeStateManager().get_trade_state(code) |
| | | if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED: |
| | | # 委托中的订单,判断是否需要撤单 |
| | | if not gpcode_manager.WantBuyCodesManager().is_in_cache(code): |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, before_blocks_dict = kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas, kpl_data_manager.KPLLimitUpDataRecordManager.total_datas, yesterday_codes, block_info.get_before_blocks_dict() |
| | | if not current_limit_up_datas: |
| | | current_limit_up_datas = [] |
| | | if not limit_up_record_datas: |
| | | limit_up_record_datas = [] |
| | | # 买绝对老大 |
| | | # 中途不能撤单 |
| | | # if CodePlateKeyBuyManager.is_need_cancel(code, limit_up_reasons.get(code), |
| | | # current_limit_up_datas, |
| | | # limit_up_record_datas, |
| | | # yesterday_current_limit_up_codes, |
| | | # before_blocks_dict): |
| | | # l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, |
| | | # f"涨停原因({limit_up_reasons.get(code)})不是老大撤单", |
| | | # "板块撤") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(), result_list_) |
| | | self.__kplDataManager.save_data(type_, result_list_) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | # 将"概念"二字替换掉 |
| | | data = data_origin |
| | | type_ = data["type"] |
| | |
| | | def run(addr, port): |
| | | # 运行看盘消息采集 |
| | | # kp_client_msg_manager.run_capture() |
| | | kpl_data_manager.run_pull_task() |
| | | kpl_data_manager.PullTask.run_pull_task() |
| | | |
| | | handler = DataServer |
| | | # httpd = socketserver.TCPServer((addr, port), handler) |