提交 fa60e8b9 编写于 作者: python_swhite's avatar python_swhite

生产代码片段

上级 2eebcf6c
print('欢迎来到 InsCode')
\ No newline at end of file
import requests
import json
def get_stock_data(stock_code, start_date, end_date):
url = 'http://push2his.eastmoney.com/api/qt/stock/kline/get'
params = {
'secid': f'0.{stock_code}',
'ut': 'fa5fd1943c7b386f172d6893dbfba10b',
'fields1': 'f1,f2,f3,f4,f5,f6',
'fields2': 'f51,f52,f53,f54,f55,f56,f57,f58',
'klt': 101,
'fqt': 0,
'beg': start_date.replace('-', ''),
'end': end_date.replace('-', ''),
'smplmt': 1,
'lmt': 1000,
'_=': 1620662320228
}
response = requests.get(url, params=params)
data = json.loads(response.text)
if data['data']['klines']:
stock_data = []
for item in data['data']['klines']:
stock_data.append(item.split(','))
return stock_data
return None
# 示例用法
stock_code = '600000' # 股票代码
start_date = '2021-01-01' # 开始日期
end_date = '2021-12-31' # 结束日期
data = get_stock_data(stock_code, start_date, end_date)
if data:
for item in data:
print(item)
else:
print('获取数据失败')
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册