AKLite
Key Features
A super-fast request engine built in HTTPX and accelerated with Asyncio.
The ability to fetch multiple stocks with ease.
Access to historical data from main stream data source.
With AKLite, you’ll have all the tools you need to fetch data. Start using AKLite today and take your working to the next level!
A Quick Example
Get a glimpse of what fetching with AKLite looks like with these code snippets:
Fetching Stock Data:
import aklite as ai
stock_zh_a_hist_obj = ai.stock_zh_a_hist(symbols=["000001", "000002"],
period="daily",
start_date="20220101",
end_date="20230601",
adjust="hfq",
timeout=5,
proxies={})
print(stock_zh_a_hist_obj.data)
print(stock_zh_a_hist_obj.columns)
print(stock_zh_a_hist_obj.url)
print(stock_zh_a_hist_obj.desc)
print(stock_zh_a_hist_obj.symbols)
print(stock_zh_a_hist_obj.start_date)
print(stock_zh_a_hist_obj.end_date)
print(stock_zh_a_hist_obj.adjust)
To learn how to use AKLite, see the notebooks under the User Guide:
Getting Started with Data Fetching
Welcome to AKlite! The best place to start is to learn about stock data fetch!
Import package
we should import aklite firstly, just like import akshare as ak
, we will call ai
short for aklite
[1]:
import aklite as ai
then, we can fetch stock data by our specific parameters: 1. we can set symbols, which is a list or str contains many stocks or just one; 2. we can set timeout and proxies for httpx timeout and proxies
[2]:
stock_zh_a_hist_obj = ai.stock_zh_a_hist(symbols=["000001", "000002"],
period="daily",
start_date="20220101",
end_date="20230601",
adjust="hfq",
timeout=5,
proxies={})
Print data
we can print data here, stock_zh_a_hist_obj
is the object, which contains many attributes, we can get the data calling obj.data
.
[3]:
# 获取数据
print(stock_zh_a_hist_obj.data)
date symbol open close high low volume \
0 2022-01-04 000001 2847.30 2876.56 2876.56 2798.54 1169259
1 2022-01-05 000001 2863.55 2956.19 2967.57 2858.68 1961998
2 2022-01-06 000001 2949.69 2951.32 2975.70 2931.82 1107885
3 2022-01-07 000001 2948.07 2964.32 2977.32 2941.57 1126631
4 2022-01-10 000001 2978.95 2962.70 3000.08 2936.69 909774
.. ... ... ... ... ... ... ...
677 2023-05-26 000002 2932.56 2941.72 2945.65 2915.54 407754
678 2023-05-29 000002 2936.49 2918.16 2937.79 2914.23 443019
679 2023-05-30 000002 2912.92 2961.36 2961.36 2871.03 881969
680 2023-05-31 000002 2946.96 2945.65 2957.43 2922.09 451251
681 2023-06-01 000002 2932.56 2914.23 2940.41 2911.61 466628
turnover amplitude price_change_rate price_change turnover_rate
0 1.918887e+09 2.74 1.03 29.26 0.60
1 3.344125e+09 3.79 2.77 79.63 1.01
2 1.896536e+09 1.48 -0.16 -4.87 0.57
3 1.937711e+09 1.21 0.44 13.00 0.58
4 1.563415e+09 2.14 -0.05 -1.62 0.47
.. ... ... ... ... ...
677 5.767348e+08 1.02 0.09 2.62 0.42
678 6.224551e+08 0.80 -0.80 -23.56 0.46
679 1.230122e+09 3.10 1.48 43.20 0.91
680 6.389365e+08 1.19 -0.53 -15.71 0.46
681 6.566527e+08 0.98 -1.07 -31.42 0.48
[682 rows x 12 columns]
[4]:
# 获取中文字段名
print(stock_zh_a_hist_obj.columns)
['日期', '股票代码', '开盘', '收盘', '最高', '最低', '成交量', '成交额', '振幅', '涨跌幅', '涨跌额', '换手率']
[5]:
# 获取目标网站链接
print(stock_zh_a_hist_obj.url)
https://quote.eastmoney.com/sh601658.html
[6]:
# 获取数据描述
print(stock_zh_a_hist_obj.desc)
东方财富-股票行情-日行情
[7]:
# 获取相关接口信息
print(stock_zh_a_hist_obj.symbols)
print(stock_zh_a_hist_obj.period)
print(stock_zh_a_hist_obj.start_date)
print(stock_zh_a_hist_obj.end_date)
print(stock_zh_a_hist_obj.adjust)
['000001', '000002']
daily
20220101
20230601
hfq
Recommended Reading
The following is a list of essential books that provide background information on quantitative finance and algorithmic trading:
Lingjie Ma, Quantitative Investing: From Theory to Industry
Timothy Masters, Testing and Tuning Market Trading Systems: Algorithms in C++
Stefan Jansen, Machine Learning for Algorithmic Trading, 2nd Edition
Ernest P. Chan, Machine Trading: Deploying Computer Algorithms to Conquer the Markets
Perry J. Kaufman, Trading Systems and Methods, 6th Edition