“沪深A股历史K线数据”的版本间的差异
来自www.baostock.com
(创建页面,内容为“__NOTOC__ == 沪深A股历史K线数据 示例 == 通过query_history_k_data()获取数据。 <pre> import baostock as bs import pandas as pd #### 登陆系统 ###…”) |
|||
| 第1行: | 第1行: | ||
__NOTOC__ | __NOTOC__ | ||
| + | 通过query_history_k_data()获取数据。 | ||
== 沪深A股历史K线数据 示例 == | == 沪深A股历史K线数据 示例 == | ||
| − | |||
<pre> | <pre> | ||
| 第95行: | 第95行: | ||
|涨跌幅 | |涨跌幅 | ||
|精度:小数点后6位 | |精度:小数点后6位 | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|- | |- | ||
|isST | |isST | ||
2018年2月22日 (四) 10:19的版本
通过query_history_k_data()获取数据。
沪深A股历史K线数据 示例
import baostock as bs
import pandas as pd
#### 登陆系统 ####
lg = bs.login(user_id="anonymous", password="123456")
# 显示登陆返回信息
print('login respond error_code:'+lg.error_code)
print('login respond error_msg:'+lg.error_msg)
#### 获取沪深A股历史K线数据 ####
# 详细指标参数,参见“历史行情指标参数”章节
rs = bs.query_history_k_data("sh.600000",
"date,code,open,high,low,close,volume,amount,adjustflag,turn,tradestatus,pctChg,isST",
start_date='2017-07-01', end_date='2017-12-31',
frequency="d", adjustflag="3")
print('query_history_k_data respond error_code:'+rs.error_code)
print('query_history_k_data respond error_msg:'+rs.error_msg)
#### 打印结果集 ####
result = pd.DataFrame(columns=["date","code","open","high","low","close","volume","amount","adjustflag","turn","tradestatus","pctChg","isST"])
while (rs.error_code == '0') & rs.next():
# 分页查询,将每页信息合并在一起
result = result.append(rs.get_row_data(), ignore_index=True)
#### 结果集输出到csv文件 ####
result.to_csv("D:\\history_A_stock_k_data.csv", index=False)
print(result)
#### 登出系统 ####
bs.logout()
| 参数名称 | 参数描述 | 说明 |
| date | 交易所行情日期 | 格式:YYYY-MM-DD |
| code | 证券代码 | 格式:sh.600000。sh:上海,sz:深圳 |
| open | 今开盘价格 | 精度:小数点后4位;单位:人民币元 |
| high | 最高价 | 精度:小数点后4位;单位:人民币元 |
| low | 最低价 | 精度:小数点后4位;单位:人民币元 |
| close | 今收盘价 | 精度:小数点后4位;单位:人民币元 |
| preclose | 昨日收盘价 | 精度:小数点后4位;单位:人民币元 |
| volume | 成交数量 | 单位:股 |
| amount | 成交金额 | 精度:小数点后4位;单位:人民币元 |
| adjustflag | 复权状态 | 不复权、前复权、后复权 |
| turn | 换手率 | 精度:小数点后6位;单位:% |
| tradestatus | 交易状态 | 1:正常交易 0:停牌 |
| pctChg | 涨跌幅 | 精度:小数点后6位 |
| isST | 是否ST | 1是,0否 |
广告位:
与某某机构合作、服务量化投资者。
与某某机构合作、服务量化投资者。