| | |
| | | import time |
| | | import concurrent.futures |
| | | |
| | | |
| | | from code_attribute import target_codes_manager |
| | | from code_attribute.history_k_data_util import JueJinApi, JueJinHttpApi |
| | | from huaxin_client import command_manager |
| | |
| | | market_code_dict = {} |
| | | |
| | | |
| | | |
| | | |
| | | class Lev2MdSpi(lev2mdapi.CTORATstpLev2MdSpi): |
| | | special_code_volume_for_order_dict = {} |
| | | # 已经订阅的代码 |
| | |
| | | szse_codes = [] |
| | | sse_codes = [] |
| | | for code in codes: |
| | | if code.find("00") == 0 or code.find("30") == 0: |
| | | market_type = tool.get_market_type(code) |
| | | if market_type == tool.MARKET_TYPE_SZSE: |
| | | szse_codes.append(code.encode()) |
| | | elif code.find("60") == 0 or code.find("68") == 0: |
| | | elif market_type == tool.MARKET_TYPE_SSE: |
| | | sse_codes.append(code.encode()) |
| | | return sse_codes, szse_codes |
| | | |
| | |
| | | rate = round( |
| | | (pDepthMarketData['LastPrice'] - pDepthMarketData['PreClosePrice']) / pDepthMarketData['PreClosePrice'], |
| | | 4) |
| | | # 代码, 最近的价格, 涨幅, 买1价, 买1量, 成交总量, 委托买入总量, 委托卖出总量 |
| | | |
| | | market_call_back_queue.put_nowait((pDepthMarketData['SecurityID'], pDepthMarketData['LastPrice'], rate, |
| | | pDepthMarketData['BidPrice1'], pDepthMarketData['BidVolume1'], |
| | | pDepthMarketData['TotalVolumeTrade'], pDepthMarketData['TotalBidVolume'], pDepthMarketData['TotalAskVolume'])) |
| | | code = pDepthMarketData['SecurityID'] |
| | | if code.find("00") == 0 or code.find("60") == 0: |
| | | if rate >= 0.05: |
| | | self.__high_rate_codes.add(code) |
| | | else: |
| | | self.__high_rate_codes.discard(code) |
| | | elif code.find("11") == 0 or code.find("12") == 0: |
| | | # 过滤可转债 |
| | | pass |
| | | else: |
| | | if rate >= 0.10: |
| | | self.__high_rate_codes.add(code) |
| | |
| | | 初始化数据 |
| | | :return: |
| | | """ |
| | | codes = [] |
| | | market_codes = [] |
| | | # 获取目标代码 |
| | | for i in range(3): |
| | | try: |
| | | codes = target_codes_manager.get_subscript_codes() |
| | | if codes: |
| | | underlying_codes = target_codes_manager.get_subscript_underlying_codes() |
| | | cb_codes = target_codes_manager.get_subscript_cb_codes() |
| | | if underlying_codes and cb_codes: |
| | | market_codes.extend(underlying_codes) |
| | | market_codes.extend(cb_codes) |
| | | break |
| | | except Exception as e: |
| | | logger_system.exception(e) |
| | | time.sleep(5) |
| | | logger_system.info(f'可转债正股数量:{len(codes)}') |
| | | if codes: |
| | | logger_system.info(f'订阅行情数量:{len(market_codes)}') |
| | | if market_codes: |
| | | # 获取目标代码的收盘价 |
| | | pre_price_dict = {} |
| | | for i in range(3): |
| | | try: |
| | | pre_price_dict = get_pre_price(codes) |
| | | pre_price_dict = get_pre_price(market_codes) |
| | | if pre_price_dict: |
| | | break |
| | | except Exception as e: |
| | | logger_system.exception(e) |
| | | time.sleep(5) |
| | | logger_system.info(f'可转债正股昨日收盘价数量:{len(codes)}') |
| | | logger_system.info(f'昨日收盘价数量:{len(market_codes)}') |
| | | if pre_price_dict: |
| | | for k in pre_price_dict: |
| | | if k.find("00") == 0 or k.find("60") == 0: |
| | |
| | | else: |
| | | limit_up_price = tool.to_price(decimal.Decimal(str(pre_price_dict[k])) * decimal.Decimal("1.2")) |
| | | Lev2MdSpi.limit_up_price_dict[k] = round(float(limit_up_price), 2) |
| | | return codes |
| | | return market_codes |
| | | |
| | | |
| | | def start_sub_high_price(): |
| | |
| | | time.sleep(3) |
| | | |
| | | |
| | | def run(trade_call_back_queue_: multiprocessing.Queue) -> None: |
| | | def run(trade_call_back_queue_: multiprocessing.Queue, market_call_back_queue_: multiprocessing.Queue) -> None: |
| | | """ |
| | | 先订阅所有的L2market行情数据,筛选出比较大的涨幅(主板>5%,科创板/创业板>10%)的票,然后订阅其交成交L2数据 |
| | | :param trade_call_back_queue_: 添加的内容格式为:(代码,交易时间) |
| | |
| | | try: |
| | | # log.close_print() |
| | | # 初始化 |
| | | global trade_call_back_queue |
| | | global trade_call_back_queue, market_call_back_queue |
| | | trade_call_back_queue = trade_call_back_queue_ |
| | | market_call_back_queue = market_call_back_queue_ |
| | | codes = __init_data() |
| | | __init_l2(codes) |
| | | |