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
官网 api https://rainx.gitbooks.io/pytdx/content/pytdx_hq.html