通信インターフェース

https://blog.csdn.net/chang1976272446/article/details/83618539

标准行情可以设置全局超时
import socket
socket.setdefaulttimeout(20)

# 导入库

from pytdx.hq import TdxHq_API
1 连接标准行情接口
standard_api = TdxHq_API(auto_retry=True, raise_exception=False)
while True:
    try:
        is_tdx_standard_connect = standard_api.connect('119.147.212.81', 7709, time_out=30)
    except Exception as e:
        logger.error('time out to connect to pytdx')
        logger.error(e)
        time.sleep(3)
        continue
        pass
    if is_tdx_standard_connect is not False:# 失败了返回False,成功了返回地址
        logger.info('connect to pytdx standard api successful')
        break
    else:
        time.sleep(3)
        continue
        pass
    pass


扩展行情导入库

from pytdx.exhq import TdxExHq_API, TDXParams
1连接扩展行情接口

ex_api = TdxExHq_API(auto_retry=True, raise_exception=False)
while True:
    try:
        is_tdx_ex_connect = ex_api.connect('121.14.110.210', 7727, time_out=30)
    except Exception as e:
        logger.error('time out to connect to pytdx')
        logger.error(e)
        time.sleep(3)
        continue
        pass
    if is_tdx_ex_connect is not False:# 失败了返回False,成功了返回地址
        logger.info('connect to pytdx extend api successful')
        break
    else:
        time.sleep(3)
        continue
        pass
    pass

関連リンクhttps://blog.csdn.net/chang1976272446/article/details/83618539

公式ウェブサイトAPIhttps  ://rainx.gitbooks.io/pytdx/content/pytdx_hq.html

おすすめ

転載: blog.csdn.net/weixin_42322206/article/details/102533259