It’s easy to use because most of the data returned are pandas DataFrame objects
We have our own data server, efficient and stable operation
Free china stock market data
Friendly to machine learning and data mining
Target Users
China Financial Market Analyst
Financial data analysis enthusiasts
Quanters who are interested in china stock market
Installation
pip install baostock
Upgrade
pip install baostock –upgrade
Quick Start
import baostock as bs
import pandas as pd
# 登陆系统
lg = bs.login(user_id="anonymous", password="123456")
# 显示登陆返回信息
print(lg.error_code)
print(lg.error_msg)
# 详细指标参数,参见“历史行情指标参数”章节
rs = bs.query_history_k_data("sh.601398",
"date,code,open,high,low,close,volume,amount,adjustflag",
start_date='2017-01-01', end_date='2017-01-31',
frequency="d", adjustflag="3")
print(rs.error_code)
print(rs.error_msg)
# 获取具体的信息
result = pd.DataFrame(columns=["date","code","open","high","low","close","volume","amount","adjustflag"])
while (rs.error_code == '0') & rs.next():
# 分页查询,将每页信息合并在一起
result = result.append(rs.get_row_data(), ignore_index=True)
result.to_csv("D:\history_k_data.csv", index=False)
print(result)
# 登出系统
bs.logout()
return:
date code open high low close preclose volume
0 2017-01-03 sh.601398 4.4000 4.4300 4.3900 4.4300 4.4100 104161632
1 2017-01-04 sh.601398 4.4200 4.4400 4.4100 4.4300 4.4300 118923425
2 2017-01-05 sh.601398 4.4300 4.4500 4.4200 4.4400 4.4300 87356137
3 2017-01-06 sh.601398 4.4400 4.4500 4.4300 4.4400 4.4400 87008191
4 2017-01-09 sh.601398 4.4500 4.4800 4.4300 4.4600 4.4400 117454094
5 2017-01-10 sh.601398 4.4500 4.4700 4.4400 4.4600 4.4600 63663257
6 2017-01-11 sh.601398 4.4600 4.4800 4.4500 4.4700 4.4600 52395427
7 2017-01-12 sh.601398 4.4600 4.4700 4.4400 4.4700 4.4700 62166279
amount adjustflag turn tradestatus
0 460087744.0000 3 0.038634 1
1 526408816.0000 3 0.044109 1
2 387580736.0000 3 0.032401 1
3 386138112.0000 3 0.032272 1
4 523539392.0000 3 0.043564 1
5 283646224.0000 3 0.023613 1
6 233898107.0000 3 0.019434 1
7 277258304.0000 3 0.023058 1
Metadata
Release files for baostock 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| baostock-0.6.1.tar.gz | 9.7 kB | Without provenance | Details for baostock-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| baostock-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for baostock-0.6.1-py3-none-any.whl |
Total release size: 28.1 kB
Release files / baostock-0.6.1.tar.gz
| Download URL | baostock-0.6.1.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8e7072176baf19365cc8bf13864e60763ec607f54ed1cb8d1e20c8660e6036a
|
|
BLAKE2b-256 checksum How to use checksums |
4bafd181c40ce72b413be630cf38eae0a87a621c5009313ca53f1458fa9de947
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / baostock-0.6.1-py3-none-any.whl
| Download URL | baostock-0.6.1-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db29a39055b2072e2a65b7c25bf10c9821fbcd2ee7c53d1ca64e8db10564ca3b
|
|
BLAKE2b-256 checksum How to use checksums |
8b063f4a8b889f938e7106984db457c53d4caef471b33dd15ab3ca4e56308f71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for baostock 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.