修改为使用新浪财经数据 https://vip.stock.finance.sina.com.cn/mkt/#hs_s
This commit is contained in:
@@ -3,8 +3,7 @@ from db_config import DatabaseManager, DatabaseConfig
|
||||
from loguru import logger
|
||||
from datetime import datetime
|
||||
import akshare as ak
|
||||
from index_downloader import get_all_stock_index
|
||||
from em_index_sport import get_index_latest_data
|
||||
|
||||
import schedule
|
||||
import time
|
||||
import traceback
|
||||
@@ -19,28 +18,10 @@ secret = "SEC43a0fa0b29717f98637a119b92a0bd5f7b2b6da671bdd2bd1279ed8323454d5e"
|
||||
dingtalk = DingTalkBot(webhook, secret)
|
||||
|
||||
|
||||
def set_proxy():
|
||||
url = "http://v2.api.juliangip.com/company/postpay/getips?auto_white=1&num=1&pt=1&result_type=json&trade_no=6735165951220899&sign=bd763049a68b4b817608520dad35ea25"
|
||||
r = requests.get(url)
|
||||
data = r.json()
|
||||
logger.info(data)
|
||||
proxy = data["data"]["proxy_list"][0]
|
||||
os.environ["https_proxy"] = f"http://{proxy}"
|
||||
os.environ["http_proxy"] = f"http://{proxy}"
|
||||
|
||||
|
||||
@retry(tries=3, delay=10)
|
||||
def get_latest_index_kline_date():
|
||||
# df = pd.read_csv(
|
||||
# "/Users/aszer/Documents/vscode/etf/index_all_stock.csv", encoding="utf-8-sig"
|
||||
# )
|
||||
# index_hist_df = pd.read_csv(
|
||||
# "/Users/aszer/Documents/vscode/etf/data/index_history_data/000001.csv",
|
||||
# encoding="utf-8-sig",
|
||||
# )
|
||||
set_proxy()
|
||||
df = get_all_stock_index()
|
||||
# df = get_index_latest_data()
|
||||
|
||||
df = ak.stock_zh_index_spot_sina()
|
||||
column_mapping = {
|
||||
"date": "date",
|
||||
"代码": "code",
|
||||
@@ -50,37 +31,13 @@ def get_latest_index_kline_date():
|
||||
"最新价": "close",
|
||||
"成交量": "volume",
|
||||
}
|
||||
|
||||
df["date"] = None
|
||||
df = df.rename(columns=column_mapping)
|
||||
df['code'] = df['code'].str.extract(r'(\d+)')[0]
|
||||
df = df[column_mapping.values()]
|
||||
df = df.drop_duplicates(subset=["code"])
|
||||
|
||||
# 获取上证指数最近30天的数据
|
||||
code = "000001" # 用来获取当前最新k线数据的日期,参考 上证指数
|
||||
latest = df[df["code"] == code].to_dict(orient="records")[0]
|
||||
h, l, o, c = latest["high"], latest["low"], latest["open"], latest["close"]
|
||||
cur_date = datetime.now().strftime("%Y%m%d")
|
||||
seven_days_ago = (datetime.now() - pd.Timedelta(days=30)).strftime("%Y%m%d")
|
||||
index_hist_df = ak.index_zh_a_hist(
|
||||
symbol=code,
|
||||
period="daily",
|
||||
start_date=seven_days_ago,
|
||||
end_date=cur_date,
|
||||
)
|
||||
|
||||
index_hist_df = index_hist_df.sort_values(
|
||||
by="日期", ascending=False
|
||||
) # 按时间降序排列
|
||||
index_hist_df = index_hist_df[
|
||||
(index_hist_df["最高"] == h)
|
||||
& (index_hist_df["最低"] == l)
|
||||
& (index_hist_df["开盘"] == o)
|
||||
& (index_hist_df["收盘"] == c)
|
||||
]
|
||||
index_hist = index_hist_df.to_dict(orient="records")[0]
|
||||
hist_date = index_hist["日期"]
|
||||
df["date"] = hist_date
|
||||
df["date"] = cur_date
|
||||
df.dropna(how="any", inplace=True)
|
||||
# df.to_csv(f"aaaa.csv", index=False, encoding="utf-8-sig")
|
||||
return df
|
||||
|
||||
Reference in New Issue
Block a user