Files
MoFin/venv/lib/python3.12/site-packages/tushare/util/conns.py
T
知微 fa45d8aa5f fix: 小果地址统一node122(兼容LAN+EasyTier)
- health_checklist.json: 192.168.1.122→node122
- ocr_client.py: docstring IP→node122
- docs/market-data-requirements.md: IP→node122
- 所有API调用通过ProxyHandler({})绕过系统代理
  Privoxy对node122:18003返回500,直连正常
2026-06-30 02:56:35 +08:00

62 lines
1.4 KiB
Python

# -*- coding:utf-8 -*-
"""
connection for api
Created on 2017/09/23
@author: Jimmy Liu
@group : waditu
@contact: jimmysoa@sina.cn
"""
from tushare.stock import cons as ct
def api(retry_count=3):
from pytdx.hq import TdxHq_API
for _ in range(retry_count):
try:
api = TdxHq_API(heartbeat=True)
api.connect(ct._get_server(), ct.T_PORT)
except Exception as e:
print(e)
else:
return api
raise IOError(ct.NETWORK_URL_ERROR_MSG)
def xapi(retry_count=3):
from pytdx.exhq import TdxExHq_API
for _ in range(retry_count):
try:
api = TdxExHq_API(heartbeat=True)
api.connect(ct._get_xserver(), ct.X_PORT)
except Exception as e:
print(e)
else:
return api
raise IOError(ct.NETWORK_URL_ERROR_MSG)
def xapi_x(retry_count=3):
from pytdx.exhq import TdxExHq_API
for _ in range(retry_count):
try:
api = TdxExHq_API(heartbeat=True)
api.connect(ct._get_xxserver(), ct.X_PORT)
except Exception as e:
print(e)
else:
return api
raise IOError(ct.NETWORK_URL_ERROR_MSG)
def get_apis():
return api(), xapi()
def close_apis(conn):
api, xapi = conn
try:
api.disconnect()
xapi.disconnect()
except Exception as e:
print(e)