JQdata是什么?
JQdata*
pip install jqdatasdk # *pip install -U jqdatasdk # 升级
JQData简单使用
from jqdatasdk import * # 导入jqdata的包import pandas as pdimport json# 获取沪深300指数的日行情def get_hs300_index():df = get_price("000300.XSHG", start_date="2011-01-01", end_date="2019-01-01", fq=None)
df.to_csv(r"data_files\HS300_None.csv")# 获取沪深300指数期货2011-2018年所有合约的日行情def get_hs300_future():info = pd.read_csv(r"data_files\future\hs300_future_info.csv", index_col=0)for contract in info["name"]:
df = get_price(contract ".CCFX", start_date="2011-01-01", end_date="2019-01-01", fq=None)
df.to_csv(r"data_files\future\%s.csv" % contract)# 获取所有期货的信息,之后再筛选出沪深300指数期货的信息def get_future_info():df = get_all_securities(types=['futures'])
df.to_csv(r"data_files\future\info.csv", encoding="gbk")# 获取沪深300指数2011-2019不同时期的成分股并保存本地def get_hs300_stock_info():path = r"data_files\stock\hs300_stocks.json"stocks = {}for year in range(2011, 2019):
first = "%d-03-01" % year
second = "%d-09-01" % year
stocks[first] = get_index_stocks('000300.XSHG', first)
stocks[second] = get_index_stocks('000300.XSHG', second)with open(path, "w") as f:
json.dump(stocks, f)# 根据保存的沪深300成分股信息,获取这些股票2011-2019年的日行情def get_hs300_stock_quote():code_path = r"data_files\stock\hs300_stocks.json"store_path = r"data_files\stock\quote\%s.csv"with open(code_path, "r") as f:
stocks = json.load(f)
stock_set = set()for value in stocks.values():
stock_set.update(value)
print(len(stock_set))for stock in stock_set:
df = get_price(stock, start_date="2011-01-01", end_date="2019-01-01", fq=None)
df.to_csv(store_path % stock)# 查询剩余数量def get_remain():print(get_query_count())if __name__ == "__main__":
auth("account", "password") # 用户密码身份验证# get_hs300_future()# get_future_info()# get_hs300_index()# get_hs300_stock_info()get_hs300_stock_quote()
get_remain()