| | |
| | | return |
| | | close_price = round(pMarketDataField.UpperLimitPrice / out_tool.get_limit_up_rate(pMarketDataField.SecurityID), |
| | | 2) |
| | | rate = round((pMarketDataField.LastPrice - close_price) * 100 / close_price, 2) |
| | | try: |
| | | # 测试L1数据 |
| | | if pMarketDataField.SecurityID == '600636' or pMarketDataField.SecurityID == '002430' or pMarketDataField.SecurityID == '300466': |
| | | d = {"SecurityID": pMarketDataField.SecurityID, "PreClosePrice": pMarketDataField.PreClosePrice, |
| | | "LastPrice": pMarketDataField.LastPrice, "BidPrice1": pMarketDataField.BidPrice1, |
| | | "BidVolume1": pMarketDataField.BidVolume1, "AskVolume1": pMarketDataField.AskVolume1, |
| | | "AskPrice1": pMarketDataField.AskPrice1, "UpperLimitPrice": pMarketDataField.UpperLimitPrice, |
| | | "UpdateTime": pMarketDataField.UpdateTime, "UpdateMillisec": pMarketDataField.UpdateMillisec} |
| | | logger_local_huaxin_l1.info(f"L1数据:{d}") |
| | | except: |
| | | pass |
| | | |
| | | lastPrice = pMarketDataField.LastPrice |
| | | if pMarketDataField.BidPrice1: |
| | | lastPrice = pMarketDataField.BidPrice1 |
| | | rate = round((lastPrice - close_price) * 100 / close_price, 2) |
| | | if out_tool.get_limit_up_rate(pMarketDataField.SecurityID) > 1.1001: |
| | | # 涨停板20%以上的打折 |
| | | rate = rate / 2 |
| | |
| | | logger_local_huaxin_l1.info(f"({request_id})新增加订阅的代码:{add_codes}") |
| | | |
| | | |
| | | is_re_subscript = False |
| | | |
| | | |
| | | # 重新订阅代码 |
| | | def re_subscript(spi: MdSpi): |
| | | try: |
| | | global is_re_subscript |
| | | if is_re_subscript: |
| | | return |
| | | is_re_subscript = True |
| | | codes_sh, codes_sz = l1_subscript_codes_manager.request_l1_subscript_target_codes() |
| | | if len(codes_sh) > 100 and len(codes_sz) > 100: |
| | | logger_local_huaxin_l1.info(f"重新订阅 sh-{len(codes_sh)} sz-{len(codes_sz)}") |
| | |
| | | pass |
| | | finally: |
| | | time.sleep(1) |
| | | |
| | | |
| | | def __run_subscript_task(spi): |
| | | """ |
| | | 运行订阅任务,在9:19到9:29之间开始订阅 |
| | | @return: |
| | | """ |
| | | is_re_subscript = False |
| | | while True: |
| | | try: |
| | | # 判断是否需要重新订阅 |
| | | if tool.is_pre_trade_time(): |
| | | re_subscript(spi) |
| | | is_re_subscript = True |
| | | if is_re_subscript: |
| | | break |
| | | except: |
| | | pass |
| | | finally: |
| | | time.sleep(3) |
| | | |
| | | |
| | | def run(queue_l1_w_strategy_r, queue_l1_r_strategy_w): |
| | |
| | | # "002292", 8.06, 9.96, 969500 * 100, time.time()) |
| | | |
| | | threading.Thread(target=__read_from_strategy, args=(queue_l1_r_strategy_w,), daemon=True).start() |
| | | |
| | | threading.Thread(target=__run_subscript_task, args=(spi,), daemon=True).start() |
| | | |
| | | # 等待程序结束 |
| | | while True: |
| | | print("数量", len(level1_data_dict)) |
| | |
| | | logging.exception(e) |
| | | finally: |
| | | time.sleep(3) |
| | | try: |
| | | # 判断是否需要重新订阅 |
| | | if tool.is_pre_trade_time(): |
| | | re_subscript(spi) |
| | | else: |
| | | global is_re_subscript |
| | | is_re_subscript = False |
| | | except: |
| | | pass |
| | | |
| | | # 释放接口对象 |
| | | api.Release() |