本文整理汇总了Python中pytdx.hq.TdxHq_API.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python TdxHq_API.disconnect方法的具体用法?Python TdxHq_API.disconnect怎么用?Python TdxHq_API.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytdx.hq.TdxHq_API
的用法示例。
在下文中一共展示了TdxHq_API.disconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import disconnect [as 别名]
def __call__(self):
total_count = 0
try:
connect = sqlite3.connect(self.sqlitefile)
except Exception as e:
#self.queue.put([self.msg_name, str(e), -1, 0, total_count])
self.queue.put([self.msg_name, 'INFO', str(e), 0, 0])
self.queue.put([self.msg_name, '', 0, None, total_count])
return
try:
download_dir = self.dest_dir + "/downloads"
if not os.path.lexists(download_dir):
os.makedirs(download_dir)
self.queue.put([self.msg_name, '正在下载钱龙权息信息...', 0, 0, 0])
net_file = urllib.request.urlopen('http://www.qianlong.com.cn/download/history/weight.rar', timeout=60)
buffer = net_file.read()
self.queue.put([self.msg_name, '钱龙权息信息下载完成,正在校验是否存在更新...', 0, 0, 0])
new_md5 = hashlib.md5(buffer).hexdigest()
dest_filename = download_dir + '/weight.rar'
old_md5 = None
if os.path.exists(dest_filename):
with open(dest_filename, 'rb') as oldfile:
old_md5 = hashlib.md5(oldfile.read()).hexdigest()
#如果没变化不需要解压导入
if new_md5 != old_md5:
with open(dest_filename, 'wb') as file:
file.write(buffer)
self.queue.put([self.msg_name, '正在解压钱龙权息信息...', 0, 0, 0])
x = os.system('unrar x -o+ -inul {} {}'.format(dest_filename, download_dir))
if x != 0:
raise Exception("无法找到unrar命令!")
self.queue.put([self.msg_name, '正在导入钱龙权息数据...', 0, 0, 0])
total_count = qianlong_import_weight(connect, download_dir + '/weight', 'SH')
total_count += qianlong_import_weight(connect, download_dir + '/weight', 'SZ')
self.queue.put([self.msg_name, '导入钱龙权息数据完毕!', 0, 0, total_count])
else:
self.queue.put([self.msg_name, '钱龙权息数据无变化', 0, 0, 0])
hosts = search_best_tdx()
api = TdxHq_API()
api.connect(hosts[0][2], hosts[0][3])
self.queue.put([self.msg_name, '下载通达信权息信息(上证)...', 0, 0, 0])
x = pytdx_import_finance(connect, api, "SH")
self.queue.put([self.msg_name, '下载通达信权息信息(深证)...', 0, 0, 0])
x += pytdx_import_finance(connect, api, "SZ")
self.queue.put([self.msg_name, '导入通达信权息信息完毕!', 0, 0, x])
api.disconnect()
except Exception as e:
#self.queue.put([self.msg_name, str(e), -1, 0, total_count])
self.queue.put([self.msg_name, 'INFO', str(e), 0, 0])
finally:
connect.commit()
connect.close()
self.queue.put([self.msg_name, '', 0, None, total_count])
示例2: open
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import disconnect [as 别名]
net_file = urllib.request.urlopen('http://www.qianlong.com.cn/download/history/weight.rar', timeout=60)
dest_filename = dest_dir + '/weight.rar'
with open(dest_filename, 'wb') as file:
file.write(net_file.read())
print("下载完成,正在解压...")
os.system('unrar x -o+ -inul {} {}'.format(dest_filename, dest_dir))
print("解压完成,正在导入...")
add_count = qianlong_import_weight(connect, dest_dir + '/weight', 'SH')
add_count += qianlong_import_weight(connect, dest_dir + '/weight', 'SZ')
print("导入数量:", add_count)
print("\n导入上证分笔数据")
#add_count = import_trans(connect, 'SH', quotations, api, dest_dir, max_days=2, progress=ProgressBar)
print("\n导入数量:", add_count)
print("\n导入上证分时数据")
add_count = import_time(connect, 'SZ', quotations, api, dest_dir, max_days=3, progress=ProgressBar)
print("\n导入数量:", add_count)
"""
api.disconnect()
connect.close()
endtime = time.time()
print("\nTotal time:")
print("%.2fs" % (endtime - starttime))
print("%.2fm" % ((endtime - starttime) / 60))