| | |
| | | from huaxin_client import tool, constant |
| | | from log_module.log import logger_system, logger_local_huaxin_l1, logger_l2_codes_subscript, logger_debug |
| | | from third_data import custom_block_in_money_manager |
| | | from third_data.custom_block_in_money_manager import BlockInMoneyRankManager, CodeInMoneyManager |
| | | from third_data.history_k_data_util import HistoryKDatasUtils, JueJinApi |
| | | from utils import tool as out_tool |
| | | |
| | | ################B类################## |
| | |
| | | pMarketDataField.SecurityID, pMarketDataField.LastPrice, rate, pMarketDataField.Volume, time.time(), |
| | | pMarketDataField.BidPrice1, pMarketDataField.BidVolume1, pMarketDataField.BidPrice2, |
| | | pMarketDataField.BidVolume2, pMarketDataField.UpdateTime) |
| | | try: |
| | | custom_block_in_money_manager.CodeInMoneyManager.set_market_info(pMarketDataField.SecurityID, lastPrice, |
| | | close_price, pMarketDataField.Turnover) |
| | | except: |
| | | pass |
| | | |
| | | |
| | | __latest_subscript_codes = set() |
| | |
| | | finally: |
| | | time.sleep(3) |
| | | |
| | | def __test_block_in_money(): |
| | | codes = BlockInMoneyRankManager().get_codes() |
| | | page_size = 200 |
| | | total_page = len(codes) // page_size + 1 |
| | | |
| | | for i in range(0, total_page): |
| | | temp_codes = codes[i * page_size: (i + 1) * page_size] |
| | | print(temp_codes) |
| | | # 获取最近的信息 |
| | | latest_infos = HistoryKDatasUtils.get_gp_latest_info(temp_codes, "sec_id,pre_close") |
| | | pre_close_dict = {x["sec_id"]: x["pre_close"] for x in latest_infos} |
| | | |
| | | current_infos = JueJinApi.get_gp_current_info(temp_codes, "symbol,price,cum_amount") |
| | | current_infos = {x["symbol"].split(".")[1]: (x["price"], x["cum_amount"]) for x in |
| | | current_infos} |
| | | |
| | | for code in current_infos: |
| | | if code not in pre_close_dict: |
| | | continue |
| | | CodeInMoneyManager.set_market_info(code, current_infos[code][0], pre_close_dict[code], |
| | | current_infos[code][1]) |
| | | |
| | | |
| | | def run(queue_l1_w_strategy_r, queue_l1_r_strategy_w, queue_custom_block_in_money, fixed_codes=None): |
| | | def run(queue_l1_w_strategy_r, queue_l1_r_strategy_w, fixed_codes=None): |
| | | """ |
| | | 运行l1订阅任务 |
| | | |
| | | @param queue_l1_w_strategy_r: L1方写,策略方读 |
| | | @param queue_l1_r_strategy_w: L1方读,策略方写 |
| | | @param queue_custom_block_in_money: 板块流入流出计算结果 |
| | | @param fixed_codes: 固定要返回数据的代码 |
| | | @return: |
| | | """ |
| | | if fixed_codes is None: |
| | | fixed_codes = set() |
| | | logger_local_huaxin_l1.info("运行l1订阅服务") |
| | | logger_local_huaxin_l1.info(f"运行l1订阅服务,固定代码:{fixed_codes}") |
| | | codes_sh = [] |
| | | codes_sz = [] |
| | | for i in range(15): |
| | |
| | | |
| | | threading.Thread(target=__run_subscript_task, args=(spi,), daemon=True).start() |
| | | |
| | | # 测试 |
| | | __test_block_in_money() |
| | | |
| | | # 等待程序结束 |
| | | while True: |
| | | print("数量", len(level1_data_dict)) |
| | | # print("数量", len(level1_data_dict)) |
| | | try: |
| | | if len(level1_data_dict) < 1: |
| | | continue |
| | |
| | | list_ = [level1_data_dict[k] for k in level1_data_dict] |
| | | flist = [] |
| | | now_time_int = int(tool.get_now_time_str().replace(":", "")) |
| | | threshold_rate = constant.L1_MIN_RATE_PRE if now_time_int < int( |
| | | "094000") else constant.L1_MIN_RATE |
| | | threshold_rate = constant.L1_MIN_RATE |
| | | for d in list_: |
| | | if d[2] >= threshold_rate or d[0] in fixed_codes: |
| | | # 涨幅小于5%的需要删除 |
| | | # 涨幅小于3%的需要删除 |
| | | flist.append(d) |
| | | flist.sort(key=lambda x: x[2], reverse=True) |
| | | # 将固定代码的排在最前 |
| | |
| | | if len(datas) > 0: |
| | | logger_l2_codes_subscript.info("开始#华鑫L1上传代码:数量-{}", len(datas)) |
| | | __upload_codes_info(queue_l1_w_strategy_r, datas) |
| | | # 计算流入流出并上传 |
| | | custom_block_in_money_manager.BlockInMoneyRankManager().compute() |
| | | queue_custom_block_in_money.put_nowait(custom_block_in_money_manager.BlockInMoneyRankManager().get_in_list(), custom_block_in_money_manager.BlockInMoneyRankManager().get_out_list()) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | logger_debug.exception(e) |