|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求求各位大神帮帮忙~
我的程序非常的慢,能不能让它变快,谢谢!
各位大神请多多指教!
import baostock as bs
import pandas as pd
from datetime import date, timedelta
import time
today = date.today()
to = str(today)
startTime = time.time()
times = int(5307)
yd1 = date.today() - timedelta(1)
yd = str(yd1)
#### 登陆系统 ####
lg = bs.login()
print('login respond error_code:'+lg.error_code)
print('login respond error_msg:'+lg.error_msg)
#### 获取证券信息 ####
rs = bs.query_all_stock(day=yd)
print('query_all_stock respond error_code:'+rs.error_code)
print('query_all_stock respond error_msg:'+rs.error_msg)
#### 打印结果集 ####
data_list = []
while (rs.error_code == '0') & rs.next():
# 获取一条记录,将记录合并在一起
data_list.append(rs.get_row_data())
result = pd.DataFrame(data_list, columns=rs.fields)
#### 结果集输出到csv文件 ####
result.to_csv("Today_stock_info.csv", encoding="gbk", index=False)
print(result)
f = open('Today_stock_info.csv', 'r')
stock_c = f.readlines()
while times:
startTime = time.time()
c = stock_c[times]
co = str(c[0:9])
print(co)
# 显示登陆返回信息
print(lg.error_code)
print(lg.error_msg)
# 详细指标参数,参见“历史行情指标参数”章节
rs1 = bs.query_all_stock(day=to)
rs = bs.query_history_k_data(co,
"date,code,open,high,low,close,volume,amount,adjustflag",
start_date='2022-05-11', end_date=to,
frequency="d", adjustflag="3")
print(rs.error_code)
print(rs.error_msg)
# 获取具体的信息
result_list = []
while (rs.error_code == '0') & rs.next():
# 分页查询,将每页信息合并在一起
result_list.append(rs.get_row_data())
result = pd.DataFrame(result_list, columns=rs.fields)
filename = str(co+".csv")
result.to_csv(filename, encoding="gbk", index=False)
executionTime = (time.time() - startTime)
print('Execution time in seconds: ' + str(executionTime))
times -= 1
#### 登出系统 ####
bs.logout()
executionTime = (time.time() - startTime)
print('Execution time in seconds: ' + str(executionTime))
谢谢大家的帮助! |
|