是免费的的数据获取接口,不需要注册。
import qstock as qs
from datetime import datetime, timedelta
import time
def get_stock_data(stock_code,days):
current_dt = time.strftime("%Y-%m-%d", time.localtime())
current_dt = datetime.strptime(current_dt, "%Y-%m-%d")
start_date = current_dt - timedelta(days=int(days / 5 *7))
start_date = start_date.strftime("%Y-%m-%d")
df = qs.get_data(stock_code, start=start_date, end=None, freq="d", fqt=1)
# print(df.tail(days))
# print(df.columns)
return df.tail(days)
if __name__ == "__main__":
get_stock_data("牧原股份",3)
实时数据获取如下:
def get_current_price(stock_code):
df = qs.realtime_data(code = stock_code)
current_price = df.loc[0,"最新"]
return current_price
文章为作者独立观点,不代表股票交易接口观点