用BaoStock判断一只股票昨天是否涨停~~
1.首先,必要安装好BaoStock.
相信用pycharm的人从较多吧,等我找到pycharm安装库的教程再贴在这里吧~~
2.调用前先引用库:
import baostock as bstock
3. 具体实现代码:
stock_code = “600519”
yesterday = "2025-01-08" #要据你的需要定义
print("Baostock: ", end="")
bstock.login()
print("Checking stock limit up status of " + yesterday)
bstock_code = GetExchange(stock_code) + "." + stock_code
rs = bstock.query_history_k_data_plus(bstock_code, "preclose,close,isST", start_date=yesterday, end_date=yesterday)
while (rs.error_code == '0') & rs.next():
rdata = rs.get_row_data() # string array
preclose = float(rdata[0])
close = float(rdata[1])
isST = True if rdata[2]=='1' else False
limit_rate = GetLimitUpRate(stock_code, isST)
upperlimit = round(preclose * limit_rate, 2) # keep %.2f
if (close >= upperlimit): # yesterday limit up
print(f"{MAGENTA}Warning: The stock hit the daily limit up yesterday{RESET}")
# endif
# end while
print("Baostock: ", end="")
bstock.logout()
代码中用到的GetExchange函数,请参见前篇博文: Get exchange string for BaoStock-CSDN博客