stock-tracker

This commit is contained in:
C菌
2026-07-04 00:17:11 +08:00
commit 6087341a48
6463 changed files with 1929869 additions and 0 deletions
@@ -0,0 +1,6 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2019/9/30 13:58
Desc:
"""
@@ -0,0 +1,234 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2025/4/5 17:30
Desc: 东方财富网-行情中心-债券市场-质押式回购
https://quote.eastmoney.com/center/gridlist.html#bond_sz_buyback
"""
import pandas as pd
import requests
def bond_sh_buy_back_em() -> pd.DataFrame:
"""
东方财富网-行情中心-债券市场-上证质押式回购
https://quote.eastmoney.com/center/gridlist.html#bond_sh_buyback
:return: 上证质押式回购
:rtype: pandas.DataFrame
"""
url = "https://push2.eastmoney.com/api/qt/clist/get"
params = {
"np": "1",
"fltt": "1",
"invt": "2",
"fs": "m:1+b:MK0356",
"fields": "f12,f13,f14,f1,f2,f4,f3,f152,f17,f18,f15,f16,f5,f6",
"fid": "f6",
"pn": "1",
"pz": "20",
"po": "1",
"dect": "1",
"wbp2u": "|0|0|0|web",
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"]["diff"])
temp_df.reset_index(inplace=True)
temp_df["index"] = temp_df["index"] + 1
temp_df.rename(
columns={
"index": "序号",
"f2": "最新价",
"f3": "涨跌幅",
"f4": "涨跌额",
"f5": "成交量",
"f6": "成交额",
"f12": "代码",
"f14": "名称",
"f15": "最高",
"f16": "最低",
"f17": "今开",
"f18": "昨收",
},
inplace=True,
)
temp_df = temp_df[
[
"序号",
"代码",
"名称",
"最新价",
"涨跌额",
"涨跌幅",
"今开",
"最高",
"最低",
"昨收",
"成交量",
"成交额",
]
]
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce") / 1000
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce") / 100
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce") / 1000
temp_df["今开"] = pd.to_numeric(temp_df["今开"], errors="coerce") / 1000
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce") / 1000
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce") / 1000
temp_df["昨收"] = pd.to_numeric(temp_df["昨收"], errors="coerce") / 1000
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
return temp_df
def bond_sz_buy_back_em() -> pd.DataFrame:
"""
东方财富网-行情中心-债券市场-深证质押式回购
https://quote.eastmoney.com/center/gridlist.html#bond_sz_buyback
:return: 深证质押式回购
:rtype: pandas.DataFrame
"""
url = "https://push2.eastmoney.com/api/qt/clist/get"
params = {
"np": "1",
"fltt": "1",
"invt": "2",
"fs": "m:0+b:MK0356",
"fields": "f12,f13,f14,f1,f2,f4,f3,f152,f17,f18,f15,f16,f5,f6",
"fid": "f6",
"pn": "1",
"pz": "20",
"po": "1",
"dect": "1",
"wbp2u": "|0|0|0|web",
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"]["diff"])
temp_df.reset_index(inplace=True)
temp_df["index"] = temp_df["index"] + 1
temp_df.rename(
columns={
"index": "序号",
"f2": "最新价",
"f3": "涨跌幅",
"f4": "涨跌额",
"f5": "成交量",
"f6": "成交额",
"f12": "代码",
"f14": "名称",
"f15": "最高",
"f16": "最低",
"f17": "今开",
"f18": "昨收",
},
inplace=True,
)
temp_df = temp_df[
[
"序号",
"代码",
"名称",
"最新价",
"涨跌额",
"涨跌幅",
"今开",
"最高",
"最低",
"昨收",
"成交量",
"成交额",
]
]
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce") / 1000
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce") / 100
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce") / 1000
temp_df["今开"] = pd.to_numeric(temp_df["今开"], errors="coerce") / 1000
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce") / 1000
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce") / 1000
temp_df["昨收"] = pd.to_numeric(temp_df["昨收"], errors="coerce") / 1000
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
return temp_df
def bond_buy_back_hist_em(symbol: str = "204001"):
"""
东方财富网-行情中心-债券市场-质押式回购-历史数据
https://quote.eastmoney.com/center/gridlist.html#bond_sh_buyback
:param symbol: 质押式回购代码
:type symbol: str
:return: 历史数据
:rtype: pandas.DataFrame
"""
if symbol.startswith("1"):
market_id = "0"
else:
market_id = "1"
url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
params = {
"secid": f"{market_id}.{symbol}",
"klt": "101",
"fqt": "1",
"lmt": "10000",
"end": "20500000",
"iscca": "1",
"fields1": "f1,f2,f3,f4,f5,f6,f7,f8",
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64",
"forcect": "1",
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["klines"]])
temp_df.columns = [
"日期",
"开盘",
"收盘",
"最高",
"最低",
"成交量",
"成交额",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
]
temp_df = temp_df[
[
"日期",
"开盘",
"收盘",
"最高",
"最低",
"成交量",
"成交额",
]
]
temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"], errors="coerce")
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
return temp_df
if __name__ == "__main__":
bond_sh_buy_back_em_df = bond_sh_buy_back_em()
print(bond_sh_buy_back_em_df)
bond_sz_buy_back_em_df = bond_sz_buy_back_em()
print(bond_sz_buy_back_em_df)
bond_buy_back_hist_em_df = bond_buy_back_hist_em(symbol="204001")
print(bond_buy_back_hist_em_df)
bond_buy_back_hist_em_df = bond_buy_back_hist_em(symbol="131810")
print(bond_buy_back_hist_em_df)
@@ -0,0 +1,58 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
"""
Date: 2023/9/12 16:50
Desc: 新浪财经-债券-可转债
https://money.finance.sina.com.cn/bond/info/sz128039.html
"""
from io import StringIO
import pandas as pd
import requests
def bond_cb_profile_sina(symbol: str = "sz128039") -> pd.DataFrame:
"""
新浪财经-债券-可转债-详情资料
https://money.finance.sina.com.cn/bond/info/sz128039.html
:param symbol: 带市场标识的转债代码
:type symbol: str
:return: 可转债-详情资料
:rtype: pandas.DataFrame
"""
url = f"https://money.finance.sina.com.cn/bond/info/{symbol}.html"
r = requests.get(url)
temp_df = pd.read_html(StringIO(r.text))[0]
temp_df.columns = ["item", "value"]
return temp_df
def bond_cb_summary_sina(symbol: str = "sh155255") -> pd.DataFrame:
"""
新浪财经-债券-可转债-债券概况
https://money.finance.sina.com.cn/bond/quotes/sh155255.html
:param symbol: 带市场标识的转债代码
:type symbol: str
:return: 可转债-债券概况
:rtype: pandas.DataFrame
"""
url = f"https://money.finance.sina.com.cn/bond/quotes/{symbol}.html"
r = requests.get(url)
temp_df = pd.read_html(StringIO(r.text))[10]
part1 = temp_df.iloc[:, 0:2].copy()
part1.columns = ["item", "value"]
part2 = temp_df.iloc[:, 2:4].copy()
part2.columns = ["item", "value"]
part3 = temp_df.iloc[:, 4:6].copy()
part3.columns = ["item", "value"]
big_df = pd.concat(objs=[part1, part2, part3], ignore_index=True)
return big_df
if __name__ == "__main__":
bond_cb_profile_sina_df = bond_cb_profile_sina(symbol="sz128039")
print(bond_cb_profile_sina_df)
bond_cb_summary_sina_df = bond_cb_summary_sina(symbol="sh155255")
print(bond_cb_summary_sina_df)
@@ -0,0 +1,93 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
"""
Date: 2024/8/14 11:30
Desc: 同花顺-数据中心-可转债
https://data.10jqka.com.cn/ipo/bond/
"""
import pandas as pd
import requests
def bond_zh_cov_info_ths() -> pd.DataFrame:
"""
同花顺-数据中心-可转债
https://data.10jqka.com.cn/ipo/bond/
:return: 可转债行情
:rtype: pandas.DataFrame
"""
url = "https://data.10jqka.com.cn/ipo/kzz/"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/89.0.4389.90 Safari/537.36",
}
r = requests.get(url, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["list"])
temp_df.rename(
columns={
"sub_date": "申购日期",
"bond_code": "债券代码",
"bond_name": "债券简称",
"code": "正股代码",
"name": "正股简称",
"sub_code": "申购代码",
"share_code": "原股东配售码",
"sign_date": "中签公布日",
"plan_total": "计划发行量",
"issue_total": "实际发行量",
"issue_price": "-",
"success_rate": "中签率",
"listing_date": "上市日期",
"expire_date": "到期时间",
"price": "转股价格",
"quota": "每股获配额",
"number": "中签号",
"market_id": "-",
"stock_market_id": "-",
},
inplace=True,
)
temp_df = temp_df[
[
"债券代码",
"债券简称",
"申购日期",
"申购代码",
"原股东配售码",
"每股获配额",
"计划发行量",
"实际发行量",
"中签公布日",
"中签号",
"上市日期",
"正股代码",
"正股简称",
"转股价格",
"到期时间",
"中签率",
]
]
temp_df["申购日期"] = pd.to_datetime(
temp_df["申购日期"], format="%Y-%m-%d", errors="coerce"
).dt.date
temp_df["中签公布日"] = pd.to_datetime(
temp_df["中签公布日"], format="%Y-%m-%d", errors="coerce"
).dt.date
temp_df["上市日期"] = pd.to_datetime(
temp_df["上市日期"], format="%Y-%m-%d", errors="coerce"
).dt.date
temp_df["到期时间"] = pd.to_datetime(
temp_df["到期时间"], format="%Y-%m-%d", errors="coerce"
).dt.date
temp_df["每股获配额"] = pd.to_numeric(temp_df["每股获配额"], errors="coerce")
temp_df["计划发行量"] = pd.to_numeric(temp_df["计划发行量"], errors="coerce")
temp_df["实际发行量"] = pd.to_numeric(temp_df["实际发行量"], errors="coerce")
temp_df["转股价格"] = pd.to_numeric(temp_df["转股价格"], errors="coerce")
return temp_df
if __name__ == "__main__":
bond_zh_cov_info_ths_df = bond_zh_cov_info_ths()
print(bond_zh_cov_info_ths_df)
@@ -0,0 +1,296 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
"""
Date: 2026/4/10 19:00
Desc: 中国债券信息网-中债指数-中债指数族系-总指数-综合类指数
"""
import pandas as pd
import requests
from akshare.bond.cons import INDEX_MAPPING, PERIOD_MAPPING, INDICATOR_MAPPING
def bond_available_index_cbond():
"""
中国债券信息网-中债指数-中债指数族系 当中, 非指定期限部分
https://yield.chinabond.com.cn/cbweb-mn/indices/singleIndexQueryResult
:return: 可选项列表
:rtype: list
"""
temp_df = pd.DataFrame(list(INDEX_MAPPING.keys()))
temp_df.reset_index(inplace=True)
temp_df['index'] = temp_df['index'] + 1
temp_df.columns = ['index', 'value']
return temp_df
def bond_index_general_cbond(
index_category: str = "新综合指数", indicator: str = "全价", period: str = "总值"
):
"""
中国债券信息网-中债指数-中债指数族系
https://yield.chinabond.com.cn/cbweb-mn/indices/singleIndexQueryResult
:param index_category: see result of available_bond_index()
:type index_category: str
:param indicator: choice of {"全价", "净价", "财富", "平均市值法久期", "平均现金流法久期", "平均市值法凸性", "平均现金流法凸性", "平均现金流法到期收益率", "平均市值法到期收益率", "平均基点价值", "平均待偿期", "平均派息率", "指数上日总市值", "财富指数涨跌幅", "全价指数涨跌幅", "净价指数涨跌幅", "现券结算量"}
:type indicator: str
:param period: choice of {"总值", "1年以下", "1-3年", "3-5年", "5-7年", "7-10年", "10年以上", "0-3个月", "3-6个月", "6-9个月", "9-12个月", "0-6个月", "6-12个月"}
:type period: str
:return: 指定指数的指定指标的指定期限分段数据
:rtype: pandas.DataFrame
"""
url = "https://yield.chinabond.com.cn/cbweb-mn/indices/singleIndexQueryResult"
params = {
"indexid": INDEX_MAPPING[index_category],
"qxlxt": PERIOD_MAPPING[period],
"ltcslx": "",
"zslxt": INDICATOR_MAPPING[indicator],
"zslxt1": INDICATOR_MAPPING[indicator],
"lx": "1",
"locale": "zh_CN",
}
r = requests.post(url, params=params)
raw_json = r.json()
key_col_map = {f"{INDICATOR_MAPPING[indicator]}_{p_code}": freq_col for p_code, freq_col in
raw_json['dqcName'].items()}
data_json = {key: raw_json[key] for key in key_col_map}
temp_df = pd.DataFrame.from_dict(data_json, orient="columns")
temp_df.index = pd.to_datetime(pd.to_numeric(temp_df.index), unit="ms", utc=True).tz_convert("Asia/Shanghai")
temp_df.index.name = "date"
temp_df.rename(columns=key_col_map, inplace=True)
temp_df.reset_index(inplace=True)
temp_df.columns = ["date", "value"]
temp_df['date'] = pd.to_datetime(temp_df['date'], errors="coerce").dt.date
return temp_df
def bond_treasury_index_cbond(
indicator: str = "财富", period: str = "5Y"
) -> pd.DataFrame:
"""
中国债券信息网-中债指数-中债指数族系-总指数-综合类指数-中债-国债指数
https://yield.chinabond.com.cn/cbweb-mn/indices/single_index_query
:param indicator: choice of {"全价", "净价", "财富"}
:type indicator: str
:param period: choice of {'0-1Y', '0-3Y', '0-5Y', '0-10Y', '1-3Y', '1-5Y', '1-10Y',
'3-5Y', '5Y', '7Y', '7-10Y', '10Y', '30Y'}
:type period: str
:return: 国债指数
:rtype: pandas.DataFrame
"""
mapping = {
"0-1Y": "8a8b2cef70bc61380170be069828032b",
"0-3Y": "61f69682dc3ec18fe9664ff59308314a",
"0-5Y": "0beafb51867009998c2f4932bf22ede3",
"0-10Y": "8a8b2cef7832f8920178350801470014",
"1-3Y": "cc1cfe89b0cbd0800420a0e037026407",
"1-5Y": "7c3110e5305f9301482517066427a554",
"1-10Y": "a5d90802e3259978a027267de651106d",
"3-5Y": "8a8b2ca04bf69582014c10b60f376c77",
"5Y": "8a8b2ca03a3feea1013a44b98fc533f5",
"7Y": "2c9081e50e8767dc010e87b6e26c0080",
"7-10Y": "8a8b2c8f5a492a01015a4ac986480043",
"10Y": "8a8b2ca04b666362014b723482bc4f49",
"30Y": "8a8b2cef77b239980177b485d20a6379",
}
url = "https://yield.chinabond.com.cn/cbweb-mn/indices/singleIndexQueryResult"
params = {
"indexid": mapping[period],
"qxlxt": "00",
"ltcslx": "",
"zslxt": INDICATOR_MAPPING[indicator],
"zslxt1": INDICATOR_MAPPING[indicator],
"lx": "1",
"locale": "zh_CN",
}
r = requests.post(url, params=params)
raw_json = r.json()
key_col_map = {f"{INDICATOR_MAPPING[indicator]}_{p_code}": freq_col for p_code, freq_col in
raw_json['dqcName'].items()}
data_json = {key: raw_json[key] for key in key_col_map}
temp_df = pd.DataFrame.from_dict(data_json, orient="columns")
temp_df.index = pd.to_datetime(pd.to_numeric(temp_df.index), unit="ms", utc=True).tz_convert("Asia/Shanghai")
temp_df.index.name = "date"
temp_df.rename(columns=key_col_map, inplace=True)
temp_df.reset_index(inplace=True)
temp_df.columns = ["date", "value"]
temp_df['date'] = pd.to_datetime(temp_df['date'], errors="coerce").dt.date
return temp_df
def bond_new_composite_index_cbond(
indicator: str = "财富", period: str = "总值"
) -> pd.DataFrame:
"""
中国债券信息网-中债指数-中债指数族系-总指数-综合类指数-中债-新综合指数
https://yield.chinabond.com.cn/cbweb-mn/indices/single_index_query
:param indicator: choice of {"全价", "净价", "财富", "平均市值法久期", "平均现金流法久期", "平均市值法凸性",
"平均现金流法凸性", "平均现金流法到期收益率", "平均市值法到期收益率", "平均基点价值", "平均待偿期", "平均派息率",
"指数上日总市值", "财富指数涨跌幅", "全价指数涨跌幅", "净价指数涨跌幅", "现券结算量"}
:type indicator: str
:param period: choice of {"总值", "1年以下", "1-3年", "3-5年", "5-7年", "7-10年", "10年以上", "0-3个月",
"3-6个月", "6-9个月", "9-12个月", "0-6个月", "6-12个月"}
:type period: str
:return: 新综合指数
:rtype: pandas.DataFrame
"""
indicator_map = {
"全价": "QJZS",
"净价": "JJZS",
"财富": "CFZS",
"平均市值法久期": "PJSZFJQ",
"平均现金流法久期": "PJXJLFJQ",
"平均市值法凸性": "PJSZFTX",
"平均现金流法凸性": "PJXJLFTX",
"平均现金流法到期收益率": "PJDQSYL",
"平均市值法到期收益率": "PJSZFDQSYL",
"平均基点价值": "PJJDJZ",
"平均待偿期": "PJDCQ",
"平均派息率": "PJPXL",
"指数上日总市值": "ZSZSZ",
"财富指数涨跌幅": "CFZSZDF",
"全价指数涨跌幅": "QJZSZDF",
"净价指数涨跌幅": "JJZSZDF",
"现券结算量": "XQJSL",
}
period_map = {
"总值": "00",
"1年以下": "01",
"1-3年": "02",
"3-5年": "03",
"5-7年": "04",
"7-10年": "05",
"10年以上": "06",
"0-3个月": "07",
"3-6个月": "08",
"6-9个月": "09",
"9-12个月": "10",
"0-6个月": "11",
"6-12个月": "12",
}
url = "https://yield.chinabond.com.cn/cbweb-mn/indices/singleIndexQuery"
params = {
"indexid": "8a8b2ca0332abed20134ea76d8885831",
"": "", # noqa: F601
"qxlxt": period_map[period],
"": "", # noqa: F601
"ltcslx": "",
"": "", # noqa: F601
"zslxt": indicator_map[indicator], # noqa: F601
"": "", # noqa: F601
"zslxt": indicator_map[indicator], # noqa: F601
"": "", # noqa: F601
"lx": "1",
"": "", # noqa: F601
"locale": "",
}
r = requests.post(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame.from_dict(
data_json[f"{indicator_map[indicator]}_{period_map[period]}"],
orient="index",
)
temp_df.reset_index(inplace=True)
temp_df.columns = ["date", "value"]
temp_df["date"] = temp_df["date"].astype(float)
temp_df["date"] = (
pd.to_datetime(temp_df["date"], unit="ms", errors="coerce", utc=True)
.dt.tz_convert("Asia/Shanghai")
.dt.date
)
temp_df["value"] = pd.to_numeric(temp_df["value"], errors="coerce")
return temp_df
def bond_composite_index_cbond(
indicator: str = "财富", period: str = "总值"
) -> pd.DataFrame:
"""
中国债券信息网-中债指数-中债指数族系-总指数-综合类指数-中债-综合指数
https://yield.chinabond.com.cn/cbweb-mn/indices/single_index_query
:param indicator: choice of {"全价", "净价", "财富", "平均市值法久期", "平均现金流法久期", "平均市值法凸性",
"平均现金流法凸性", "平均现金流法到期收益率", "平均市值法到期收益率", "平均基点价值", "平均待偿期", "平均派息率",
"指数上日总市值", "财富指数涨跌幅", "全价指数涨跌幅", "净价指数涨跌幅", "现券结算量"}
:type indicator: str
:param period: choice of {"总值", "1年以下", "1-3年", "3-5年", "5-7年", "7-10年", "10年以上", "0-3个月",
"3-6个月", "6-9个月", "9-12个月", "0-6个月", "6-12个月"}
:type period: str
:return: 新综合指数
:rtype: pandas.DataFrame
"""
indicator_map = {
"全价": "QJZS",
"净价": "JJZS",
"财富": "CFZS",
"平均市值法久期": "PJSZFJQ",
"平均现金流法久期": "PJXJLFJQ",
"平均市值法凸性": "PJSZFTX",
"平均现金流法凸性": "PJXJLFTX",
"平均现金流法到期收益率": "PJDQSYL",
"平均市值法到期收益率": "PJSZFDQSYL",
"平均基点价值": "PJJDJZ",
"平均待偿期": "PJDCQ",
"平均派息率": "PJPXL",
"指数上日总市值": "ZSZSZ",
"财富指数涨跌幅": "CFZSZDF",
"全价指数涨跌幅": "QJZSZDF",
"净价指数涨跌幅": "JJZSZDF",
"现券结算量": "XQJSL",
}
period_map = {
"总值": "00",
"1年以下": "01",
"1-3年": "02",
"3-5年": "03",
"5-7年": "04",
"7-10年": "05",
"10年以上": "06",
"0-3个月": "07",
"3-6个月": "08",
"6-9个月": "09",
"9-12个月": "10",
"0-6个月": "11",
"6-12个月": "12",
}
url = "https://yield.chinabond.com.cn/cbweb-mn/indices/singleIndexQuery"
params = {
"indexid": "2c90818811afed8d0111c0c672b31578",
"": "", # noqa: F601
"qxlxt": period_map[period],
"": "", # noqa: F601
"zslxt": indicator_map[indicator],
"": "", # noqa: F601
"lx": "1",
"": "", # noqa: F601
"locale": "",
}
r = requests.post(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame.from_dict(
data_json[f"{indicator_map[indicator]}_{period_map[period]}"],
orient="index",
)
temp_df.reset_index(inplace=True)
temp_df.columns = ["date", "value"]
temp_df["date"] = pd.to_datetime(temp_df["date"].astype(int), errors="coerce", unit="ms").dt.date
temp_df["value"] = pd.to_numeric(temp_df["value"], errors="coerce")
return temp_df
if __name__ == "__main__":
bond_new_composite_index_cbond_df = bond_new_composite_index_cbond(
indicator="财富", period="总值"
)
print(bond_new_composite_index_cbond_df)
bond_composite_index_cbond_df = bond_composite_index_cbond(
indicator="财富", period="总值"
)
print(bond_composite_index_cbond_df)
bond_index_general_cbond_df = bond_index_general_cbond(index_category="新综合指数", indicator="全价", period="总值")
print(bond_index_general_cbond_df)
bond_treasury_index_cbond_df = bond_treasury_index_cbond(indicator="财富", period="5Y")
print(bond_treasury_index_cbond_df)
@@ -0,0 +1,190 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2024/10/1 17:00
Desc: 中国外汇交易中心暨全国银行间同业拆借中心
中国外汇交易中心暨全国银行间同业拆借中心-市场数据-债券市场行情-现券市场做市报价
中国外汇交易中心暨全国银行间同业拆借中心-市场数据-债券市场行情-现券市场成交行情
https://www.chinamoney.com.cn/chinese/mkdatabond/
"""
from io import StringIO
import pandas as pd
import requests
from akshare.bond.bond_china_money import bond_china_close_return_map
from akshare.utils.cons import headers
def bond_spot_quote() -> pd.DataFrame:
"""
中国外汇交易中心暨全国银行间同业拆借中心-市场数据-债券市场行情-现券市场做市报价
https://www.chinamoney.com.cn/chinese/mkdatabond/
:return: 现券市场做市报价
:rtype: pandas.DataFrame
"""
bond_china_close_return_map()
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbMktMakQuot"
payload = {
"flag": "1",
"lang": "cn",
}
r = requests.post(url=url, data=payload, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
temp_df.columns = [
"_",
"_",
"报价机构",
"_",
"_",
"_",
"债券简称",
"_",
"_",
"_",
"_",
"买入/卖出收益率",
"_",
"买入/卖出净价",
"_",
"_",
"_",
]
temp_df = temp_df[
[
"报价机构",
"债券简称",
"买入/卖出净价",
"买入/卖出收益率",
]
]
temp_df["买入净价"] = (
temp_df["买入/卖出净价"].str.split("/", expand=True).iloc[:, 0]
)
temp_df["卖出净价"] = (
temp_df["买入/卖出净价"].str.split("/", expand=True).iloc[:, 1]
)
temp_df["买入收益率"] = (
temp_df["买入/卖出收益率"].str.split("/", expand=True).iloc[:, 0]
)
temp_df["卖出收益率"] = (
temp_df["买入/卖出收益率"].str.split("/", expand=True).iloc[:, 1]
)
del temp_df["买入/卖出净价"]
del temp_df["买入/卖出收益率"]
temp_df["买入净价"] = pd.to_numeric(temp_df["买入净价"], errors="coerce")
temp_df["卖出净价"] = pd.to_numeric(temp_df["卖出净价"], errors="coerce")
temp_df["买入收益率"] = pd.to_numeric(temp_df["买入收益率"], errors="coerce")
temp_df["卖出收益率"] = pd.to_numeric(temp_df["卖出收益率"], errors="coerce")
return temp_df
def bond_spot_deal() -> pd.DataFrame:
"""
中国外汇交易中心暨全国银行间同业拆借中心-市场数据-债券市场行情-现券市场成交行情
https://www.chinamoney.com.cn/chinese/mkdatabond/
:return: 现券市场成交行情
:rtype: pandas.DataFrame
"""
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbtPri"
payload = {
"flag": "1",
"lang": "cn",
"bondName": "",
}
r = requests.post(url=url, data=payload, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
temp_df.columns = [
"_",
"_",
"债券简称",
"_",
"_",
"_",
"_",
"涨跌",
"_",
"_",
"_",
"加权收益率",
"成交净价",
"_",
"_",
"最新收益率",
"-",
"交易量",
"_",
"_",
"_",
"_",
]
temp_df = temp_df[
[
"债券简称",
"成交净价",
"最新收益率",
"涨跌",
"加权收益率",
"交易量",
]
]
temp_df["成交净价"] = pd.to_numeric(temp_df["成交净价"], errors="coerce")
temp_df["最新收益率"] = pd.to_numeric(temp_df["最新收益率"], errors="coerce")
temp_df["涨跌"] = pd.to_numeric(temp_df["涨跌"], errors="coerce")
temp_df["加权收益率"] = pd.to_numeric(temp_df["加权收益率"], errors="coerce")
temp_df["交易量"] = pd.to_numeric(temp_df["交易量"], errors="coerce")
return temp_df
def bond_china_yield(
start_date: str = "20200204", end_date: str = "20210124"
) -> pd.DataFrame:
"""
中国债券信息网-国债及其他债券收益率曲线
https://www.chinabond.com.cn/
https://yield.chinabond.com.cn/cbweb-pbc-web/pbc/historyQuery?startDate=2019-02-07&endDate=2020-02-04&gjqx=0&qxId=ycqx&locale=cn_ZH
注意: end_date - start_date 应该小于一年
:param start_date: 需要查询的日期, 返回在该日期之后一年内的数据
:type start_date: str
:param end_date: 需要查询的日期, 返回在该日期之前一年内的数据
:type end_date: str
:return: 返回在指定日期之间之前一年内的数据
:rtype: pandas.DataFrame
"""
url = "https://yield.chinabond.com.cn/cbweb-pbc-web/pbc/historyQuery"
params = {
"startDate": "-".join([start_date[:4], start_date[4:6], start_date[6:]]),
"endDate": "-".join([end_date[:4], end_date[4:6], end_date[6:]]),
"gjqx": "0",
"qxId": "ycqx",
"locale": "cn_ZH",
}
res = requests.get(url, params=params, headers=headers)
data_text = res.text.replace("&nbsp", "")
data_df = pd.read_html(StringIO(data_text), header=0)[1]
data_df["日期"] = pd.to_datetime(data_df["日期"], errors="coerce").dt.date
data_df["3月"] = pd.to_numeric(data_df["3月"], errors="coerce")
data_df["6月"] = pd.to_numeric(data_df["6月"], errors="coerce")
data_df["1年"] = pd.to_numeric(data_df["1年"], errors="coerce")
data_df["3年"] = pd.to_numeric(data_df["3年"], errors="coerce")
data_df["5年"] = pd.to_numeric(data_df["5年"], errors="coerce")
data_df["7年"] = pd.to_numeric(data_df["7年"], errors="coerce")
data_df["10年"] = pd.to_numeric(data_df["10年"], errors="coerce")
data_df["30年"] = pd.to_numeric(data_df["30年"], errors="coerce")
data_df.sort_values(by="日期", inplace=True)
data_df.reset_index(inplace=True, drop=True)
return data_df
if __name__ == "__main__":
bond_spot_quote_df = bond_spot_quote()
print(bond_spot_quote_df)
bond_spot_deal_df = bond_spot_deal()
print(bond_spot_deal_df)
bond_china_yield_df = bond_china_yield(start_date="20210201", end_date="20220201")
print(bond_china_yield_df)
@@ -0,0 +1,390 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2024/6/27 16:00
Desc: 收盘收益率曲线历史数据
https://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1
"""
from functools import lru_cache
import pandas as pd
import requests
from akshare.utils.tqdm import get_tqdm
def __bond_register_service() -> requests.Session:
"""
将服务注册到网站中,则该 IP 在 24 小时内可以直接访问
https://www.chinamoney.com.cn
:return: 访问过的 Session
:rtype: requests.Session
"""
session = requests.Session()
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/108.0.0.0 Safari/537.36",
}
session.get(
url="https://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1",
headers=headers,
)
cookies_dict = session.cookies.get_dict()
cookies_str = "; ".join(f"{k}={v}" for k, v in cookies_dict.items())
# 此处需要通过未访问的游览器,首次打开
# https://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1
# 页面进行人工获取
data = {"key": "TThwSjc2NWkzV0VSOVRzOA=="}
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Length": "22",
"Cookie": cookies_str,
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Host": "www.chinamoney.com.cn",
"Origin": "https://www.chinamoney.com.cn",
"Pragma": "no-cache",
"Referer": "https://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/108.0.0.0 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
session.post(
url="https://www.chinamoney.com.cn/dqs/rest/cm-u-rbt/apply",
data=data,
headers=headers,
)
# 20231127 新增部分 https://github.com/akfamily/akshare/issues/4299
cookies_dict = session.cookies.get_dict()
cookies_str = "; ".join(f"{k}={v}" for k, v in cookies_dict.items())
headers = {
"Accept": "application/json, text/javascript, /; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en",
"Connection": "keep-alive",
"Content-Length": "0",
"Cookie": cookies_str,
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Host": "www.chinamoney.com.cn",
"Origin": "https://www.chinamoney.com.cn",
"Referer": "https://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/108.0.0.0 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
session.post(
url="https://www.chinamoney.com.cn/lss/rest/cm-s-account/getSessionUser",
headers=headers,
)
return session
@lru_cache()
def bond_china_close_return_map() -> pd.DataFrame:
"""
收盘收益率曲线历史数据
https://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1
:return: 收盘收益率曲线历史数据
:rtype: pandas.DataFrame
"""
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Length": "0",
"Host": "www.chinamoney.com.cn",
"Origin": "https://www.chinamoney.com.cn",
"Pragma": "no-cache",
"Referer": "https://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/108.0.0.0 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bk-currency/ClsYldCurvCurvGO"
try:
r = requests.get(url, headers=headers)
data_json = r.json()
except: # noqa: E722
session = __bond_register_service()
r = session.get(url, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
return temp_df
def bond_china_close_return(
symbol: str = "国债",
period: str = "1",
start_date: str = "20231101",
end_date: str = "20231101",
) -> pd.DataFrame:
"""
收盘收益率曲线历史数据
https://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1
:param symbol: 需要获取的指标
:type period: choice of {'0.1', '0.5', '1'}
:param period: 期限间隔
:type symbol: str
:param start_date: 开始日期, 结束日期和开始日期不要超过 1 个月
:type start_date: str
:param end_date: 结束日期, 结束日期和开始日期不要超过 1 个月
:type end_date: str
:return: 收盘收益率曲线历史数据
:rtype: pandas.DataFrame
"""
name_code_df = bond_china_close_return_map()
symbol_code = name_code_df[name_code_df["cnLabel"] == symbol]["value"].values[0]
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bk-currency/ClsYldCurvHis"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/108.0.0.0 Safari/537.36",
}
params = {
"lang": "CN",
"reference": "1,2,3",
"bondType": symbol_code,
"startDate": "-".join([start_date[:4], start_date[4:6], start_date[6:]]),
"endDate": "-".join([end_date[:4], end_date[4:6], end_date[6:]]),
"termId": period,
"pageNum": "1",
"pageSize": "50",
}
r = requests.get(url, params=params, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
del temp_df["newDateValue"]
temp_df.columns = [
"日期",
"期限",
"到期收益率",
"即期收益率",
"远期收益率",
]
temp_df = temp_df[
[
"日期",
"期限",
"到期收益率",
"即期收益率",
"远期收益率",
]
]
temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
temp_df["期限"] = pd.to_numeric(temp_df["期限"], errors="coerce")
temp_df["到期收益率"] = pd.to_numeric(temp_df["到期收益率"], errors="coerce")
temp_df["即期收益率"] = pd.to_numeric(temp_df["即期收益率"], errors="coerce")
temp_df["远期收益率"] = pd.to_numeric(temp_df["远期收益率"], errors="coerce")
return temp_df
def macro_china_swap_rate(
start_date: str = "20231101", end_date: str = "20231204"
) -> pd.DataFrame:
"""
FR007 利率互换曲线历史数据; 只能获取近一年的数据
https://www.chinamoney.com.cn/chinese/bkcurvfxhis/?cfgItemType=72&curveType=FR007
:param start_date: 开始日期, 开始和结束日期不得超过一个月
:type start_date: str
:param end_date: 结束日期, 开始和结束日期不得超过一个月
:type end_date: str
:return: FR007利率互换曲线历史数据
:rtype: pandas.DataFrame
"""
bond_china_close_return_map()
start_date = "-".join([start_date[:4], start_date[4:6], start_date[6:]])
end_date = "-".join([end_date[:4], end_date[4:6], end_date[6:]])
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bk-shibor/IfccHis"
params = {
"cfgItemType": "72",
"interestRateType": "0",
"startDate": start_date,
"endDate": end_date,
"bidAskType": "",
"lang": "CN",
"quoteTime": "全部",
"pageSize": "5000",
"pageNum": "1",
}
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Length": "0",
"Host": "www.chinamoney.com.cn",
"Origin": "https://www.chinamoney.com.cn",
"Pragma": "no-cache",
"Referer": "https://www.chinamoney.com.cn/chinese/bkcurvfxhis/?cfgItemType=72&curveType=FR007",
"sec-ch-ua": '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/107.0.0.0 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
r = requests.post(url, data=params, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
temp_df.columns = [
"日期",
"_",
"_",
"时刻",
"_",
"_",
"_",
"_",
"_",
"价格类型",
"_",
"曲线名称",
"_",
"_",
"_",
"_",
"data",
]
price_df = pd.DataFrame([item for item in temp_df["data"]])
price_df.columns = [
"1M",
"3M",
"6M",
"9M",
"1Y",
"2Y",
"3Y",
"4Y",
"5Y",
"7Y",
"10Y",
]
big_df = pd.concat(objs=[temp_df, price_df], axis=1)
big_df = big_df[
[
"日期",
"曲线名称",
"时刻",
"价格类型",
"1M",
"3M",
"6M",
"9M",
"1Y",
"2Y",
"3Y",
"4Y",
"5Y",
"7Y",
"10Y",
]
]
big_df["日期"] = pd.to_datetime(big_df["日期"], errors="coerce").dt.date
big_df["1M"] = pd.to_numeric(big_df["1M"], errors="coerce")
big_df["3M"] = pd.to_numeric(big_df["3M"], errors="coerce")
big_df["6M"] = pd.to_numeric(big_df["6M"], errors="coerce")
big_df["9M"] = pd.to_numeric(big_df["9M"], errors="coerce")
big_df["1Y"] = pd.to_numeric(big_df["1Y"], errors="coerce")
big_df["2Y"] = pd.to_numeric(big_df["2Y"], errors="coerce")
big_df["3Y"] = pd.to_numeric(big_df["3Y"], errors="coerce")
big_df["4Y"] = pd.to_numeric(big_df["4Y"], errors="coerce")
big_df["5Y"] = pd.to_numeric(big_df["5Y"], errors="coerce")
big_df["7Y"] = pd.to_numeric(big_df["7Y"], errors="coerce")
big_df["10Y"] = pd.to_numeric(big_df["10Y"], errors="coerce")
big_df.sort_values(["日期"], inplace=True, ignore_index=True)
return big_df
def macro_china_bond_public() -> pd.DataFrame:
"""
中国-债券信息披露-债券发行
https://www.chinamoney.com.cn/chinese/xzjfx/
:return: 债券发行
:rtype: pandas.DataFrame
"""
bond_china_close_return_map()
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bond-an/bnBondEmit"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/107.0.0.0 Safari/537.36",
}
payload = {
"enty": "",
"bondType": "",
"bondNameCode": "",
"leadUnderwriter": "",
"pageNo": "1",
"pageSize": "10",
"limit": "1",
}
r = requests.post(url, data=payload, headers=headers)
data_json = r.json()
total_page = int(data_json["data"]["pageTotalSize"]) + 1
big_df = pd.DataFrame()
tqdm = get_tqdm()
for page in tqdm(range(1, total_page), leave=False):
payload.update({"pageNo": page})
r = requests.post(url, data=payload, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
big_df.columns = [
"债券全称",
"债券类型",
"-",
"发行日期",
"-",
"计息方式",
"-",
"债券期限",
"-",
"债券评级",
"-",
"价格",
"计划发行量",
]
big_df = big_df[
[
"债券全称",
"债券类型",
"发行日期",
"计息方式",
"价格",
"债券期限",
"计划发行量",
"债券评级",
]
]
big_df["价格"] = pd.to_numeric(big_df["价格"], errors="coerce")
big_df["计划发行量"] = pd.to_numeric(big_df["计划发行量"], errors="coerce")
return big_df
if __name__ == "__main__":
bond_china_close_return_df = bond_china_close_return(
symbol="同业存单(AAA)", period="1", start_date="20240607", end_date="20240607"
)
print(bond_china_close_return_df)
macro_china_swap_rate_df = macro_china_swap_rate(
start_date="20251010", end_date="20251208"
)
print(macro_china_swap_rate_df)
macro_china_bond_public_df = macro_china_bond_public()
print(macro_china_bond_public_df)
@@ -0,0 +1,344 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2025/5/16 19:00
Desc: 债券-集思录-可转债
集思录:https://www.jisilu.cn/data/cbnew/#cb
"""
from io import StringIO
import pandas as pd
import requests
import time
from akshare.utils import demjson
def bond_cb_index_jsl() -> pd.DataFrame:
"""
首页-可转债-集思录可转债等权指数
https://www.jisilu.cn/web/data/cb/index
:return: 集思录可转债等权指数
:rtype: pandas.DataFrame
"""
url = "https://www.jisilu.cn/webapi/cb/index_history/"
r = requests.get(url)
data_dict = demjson.decode(r.text)["data"]
temp_df = pd.DataFrame(data_dict)
return temp_df
def bond_cb_jsl(cookie: str = None) -> pd.DataFrame:
"""
集思录可转债
https://www.jisilu.cn/data/cbnew/#cb
:param cookie: 输入获取到的游览器 cookie
:type cookie: str
:return: 集思录可转债
:rtype: pandas.DataFrame
"""
url = "https://www.jisilu.cn/data/cbnew/cb_list_new/"
headers = {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
"cache-control": "no-cache",
"content-length": "220",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"cookie": cookie,
"origin": "https://www.jisilu.cn",
"pragma": "no-cache",
"referer": "https://www.jisilu.cn/data/cbnew/",
"sec-ch-ua": '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/91.0.4472.164 Safari/537.36",
"x-requested-with": "XMLHttpRequest",
}
params = {
"___jsl": f"LST___t={int(time.time() * 1000)}",
}
payload = {
"fprice": "",
"tprice": "",
"curr_iss_amt": "",
"volume": "",
"svolume": "",
"premium_rt": "",
"ytm_rt": "",
"market": "",
"rating_cd": "",
"is_search": "N",
"market_cd[]": "shmb", # noqa: F601
"market_cd[]": "shkc", # noqa: F601
"market_cd[]": "szmb", # noqa: F601
"market_cd[]": "szcy", # noqa: F601
"btype": "",
"listed": "Y",
"qflag": "N",
"sw_cd": "",
"bond_ids": "",
"rp": "50",
}
r = requests.post(url, params=params, json=payload, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame([item["cell"] for item in data_json["rows"]])
temp_df.rename(
columns={
"bond_id": "代码",
"bond_nm": "转债名称",
"price": "现价",
"increase_rt": "涨跌幅",
"stock_id": "正股代码",
"stock_nm": "正股名称",
"sprice": "正股价",
"sincrease_rt": "正股涨跌",
"pb": "正股PB",
"convert_price": "转股价",
"convert_value": "转股价值",
"premium_rt": "转股溢价率",
"dblow": "双低",
"rating_cd": "债券评级",
"put_convert_price": "回售触发价",
"force_redeem_price": "强赎触发价",
"convert_amt_ratio": "转债占比",
"maturity_dt": "到期时间",
"year_left": "剩余年限",
"curr_iss_amt": "剩余规模",
"volume": "成交额",
"turnover_rt": "换手率",
"ytm_rt": "到期税前收益",
},
inplace=True,
)
temp_df = temp_df[
[
"代码",
"转债名称",
"现价",
"涨跌幅",
"正股代码",
"正股名称",
"正股价",
"正股涨跌",
"正股PB",
"转股价",
"转股价值",
"转股溢价率",
"债券评级",
"回售触发价",
"强赎触发价",
"转债占比",
"到期时间",
"剩余年限",
"剩余规模",
"成交额",
"换手率",
"到期税前收益",
"双低",
]
]
temp_df["到期时间"] = pd.to_datetime(temp_df["到期时间"], errors="coerce").dt.date
temp_df["现价"] = pd.to_numeric(temp_df["现价"], errors="coerce")
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
temp_df["正股价"] = pd.to_numeric(temp_df["正股价"], errors="coerce")
temp_df["正股涨跌"] = pd.to_numeric(temp_df["正股涨跌"], errors="coerce")
temp_df["正股PB"] = pd.to_numeric(temp_df["正股PB"], errors="coerce")
temp_df["转股价"] = pd.to_numeric(temp_df["转股价"], errors="coerce")
temp_df["转股价值"] = pd.to_numeric(temp_df["转股价值"], errors="coerce")
temp_df["转股溢价率"] = pd.to_numeric(temp_df["转股溢价率"], errors="coerce")
temp_df["回售触发价"] = pd.to_numeric(temp_df["回售触发价"], errors="coerce")
temp_df["强赎触发价"] = pd.to_numeric(temp_df["强赎触发价"], errors="coerce")
temp_df["转债占比"] = pd.to_numeric(temp_df["转债占比"], errors="coerce")
temp_df["剩余年限"] = pd.to_numeric(temp_df["剩余年限"], errors="coerce")
temp_df["剩余规模"] = pd.to_numeric(temp_df["剩余规模"], errors="coerce")
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
temp_df["到期税前收益"] = pd.to_numeric(temp_df["到期税前收益"], errors="coerce")
return temp_df
def bond_cb_redeem_jsl() -> pd.DataFrame:
"""
集思录可转债-强赎
https://www.jisilu.cn/data/cbnew/#redeem
:return: 集思录可转债-强赎
:rtype: pandas.DataFrame
"""
url = "https://www.jisilu.cn/data/cbnew/redeem_list/"
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Length": "5",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Host": "www.jisilu.cn",
"Origin": "https://www.jisilu.cn",
"Pragma": "no-cache",
"Referer": "https://www.jisilu.cn/data/cbnew/",
"sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/101.0.4951.67 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
params = {
"___jsl": "LST___t=1653394005966",
}
payload = {
"rp": "50",
}
r = requests.post(url, params=params, json=payload, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame([item["cell"] for item in data_json["rows"]])
temp_df.rename(
columns={
"bond_id": "代码",
"bond_nm": "名称",
"price": "现价",
"stock_id": "正股代码",
"stock_nm": "正股名称",
"margin_flg": "-",
"btype": "-",
"orig_iss_amt": "规模",
"curr_iss_amt": "剩余规模",
"convert_dt": "转股起始日",
"convert_price": "转股价",
"next_put_dt": "-",
"redeem_dt": "-",
"force_redeem": "-",
"redeem_flag": "-",
"redeem_price": "-",
"redeem_price_ratio": "强赎触发比",
"real_force_redeem_price": "强赎价",
"redeem_remain_days": "-",
"redeem_real_days": "-",
"redeem_total_days": "-",
"recount_dt": "-",
"redeem_count_days": "-",
"redeem_tc": "强赎条款",
"sprice": "正股价",
"delist_dt": "最后交易日",
"maturity_dt": "到期日",
"redeem_icon": "强赎状态",
"redeem_orders": "-",
"at_maturity": "-",
"redeem_count": "强赎天计数",
"after_next_put_dt": "-",
"force_redeem_price": "强赎触发价",
},
inplace=True,
)
temp_df = temp_df[
[
"代码",
"名称",
"现价",
"正股代码",
"正股名称",
"规模",
"剩余规模",
"转股起始日",
"最后交易日",
"到期日",
"转股价",
"强赎触发比",
"强赎触发价",
"正股价",
"强赎价",
"强赎天计数",
"强赎条款",
"强赎状态",
]
]
temp_df["现价"] = pd.to_numeric(temp_df["现价"], errors="coerce")
temp_df["规模"] = pd.to_numeric(temp_df["规模"], errors="coerce")
temp_df["剩余规模"] = pd.to_numeric(temp_df["剩余规模"], errors="coerce")
temp_df["转股起始日"] = pd.to_datetime(
temp_df["转股起始日"], errors="coerce"
).dt.date
temp_df["最后交易日"] = pd.to_datetime(
temp_df["最后交易日"], errors="coerce"
).dt.date
temp_df["到期日"] = pd.to_datetime(temp_df["到期日"], errors="coerce").dt.date
temp_df["转股价"] = pd.to_numeric(temp_df["转股价"], errors="coerce")
temp_df["强赎触发比"] = pd.to_numeric(
temp_df["强赎触发比"].str.strip("%"), errors="coerce"
)
temp_df["强赎触发价"] = pd.to_numeric(temp_df["强赎触发价"], errors="coerce")
temp_df["正股价"] = pd.to_numeric(temp_df["正股价"], errors="coerce")
temp_df["强赎价"] = pd.to_numeric(temp_df["强赎价"], errors="coerce")
temp_df["强赎天计数"] = temp_df["强赎天计数"].replace(
r"^.*?(\d{1,2}\/\d{1,2} \| \d{1,2}).*?$", r"\1", regex=True
)
temp_df["强赎状态"] = temp_df["强赎状态"].map(
{
"R": "已公告强赎",
"O": "公告要强赎",
"G": "公告不强赎",
"B": "已满足强赎条件",
"": "",
}
)
return temp_df
def bond_cb_adj_logs_jsl(symbol: str = "128013") -> pd.DataFrame:
"""
集思录-可转债转股价-调整记录
https://www.jisilu.cn/data/cbnew/#cb
:param symbol: 可转债代码
:type symbol: str
:return: 转股价调整记录
:rtype: pandas.DataFrame
"""
url = f"https://www.jisilu.cn/data/cbnew/adj_logs/?bond_id={symbol}"
r = requests.get(url)
data_text = r.text
if "</table>" not in data_text:
# 1. 该可转债没有转股价调整记录,服务端返回文本 '暂无数据'
# 2. 无效可转债代码,服务端返回 {"timestamp":1639565628,"isError":1,"msg":"无效代码格式"}
# 以上两种情况,返回空的 DataFrame
return pd.DataFrame()
else:
temp_df = pd.read_html(StringIO(data_text), parse_dates=True)[0]
temp_df.columns = [item.replace(" ", "") for item in temp_df.columns]
temp_df["下修前转股价"] = pd.to_numeric(
temp_df["下修前转股价"], errors="coerce"
)
temp_df["下修后转股价"] = pd.to_numeric(
temp_df["下修后转股价"], errors="coerce"
)
temp_df["下修底价"] = pd.to_numeric(temp_df["下修底价"], errors="coerce")
temp_df["股东大会日"] = pd.to_datetime(
temp_df["股东大会日"], format="%Y-%m-%d", errors="coerce"
).dt.date
temp_df["新转股价生效日期"] = pd.to_datetime(
temp_df["新转股价生效日期"], format="%Y-%m-%d", errors="coerce"
).dt.date
return temp_df
if __name__ == "__main__":
bond_cb_index_jsl_df = bond_cb_index_jsl()
print(bond_cb_index_jsl_df)
bond_cb_jsl_df = bond_cb_jsl(cookie="")
print(bond_cb_jsl_df)
bond_cb_redeem_jsl_df = bond_cb_redeem_jsl()
print(bond_cb_redeem_jsl_df)
bond_cb_adj_logs_jsl_df = bond_cb_adj_logs_jsl(symbol="128013")
print(bond_cb_adj_logs_jsl_df)
@@ -0,0 +1,147 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2025/4/5 17:00
Desc: 东方财富网-数据中心-经济数据-中美国债收益率
https://data.eastmoney.com/cjsj/zmgzsyl.html
"""
import pandas as pd
import requests
from akshare.utils.tqdm import get_tqdm
def bond_zh_us_rate(start_date: str = "19901219") -> pd.DataFrame:
"""
东方财富网-数据中心-经济数据-中美国债收益率
https://data.eastmoney.com/cjsj/zmgzsyl.html
:param start_date: 开始统计时间
:type start_date: str
:return: 中美国债收益率
:rtype: pandas.DataFrame
"""
url = "https://datacenter.eastmoney.com/api/data/get"
params = {
"type": "RPTA_WEB_TREASURYYIELD",
"sty": "ALL",
"st": "SOLAR_DATE",
"sr": "-1",
"token": "894050c76af8597a853f5b408b759f5d",
"p": "1",
"ps": "500",
"pageNo": "1",
"pageNum": "1",
}
r = requests.get(url, params=params)
data_json = r.json()
total_page = data_json["result"]["pages"]
big_df = pd.DataFrame()
tqdm = get_tqdm()
for page in tqdm(range(1, total_page + 1), leave=False):
params = {
"type": "RPTA_WEB_TREASURYYIELD",
"sty": "ALL",
"st": "SOLAR_DATE",
"sr": "-1",
"token": "894050c76af8597a853f5b408b759f5d",
"p": page,
"ps": "500",
"pageNo": page,
"pageNum": page,
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["result"]["data"])
for col in temp_df.columns:
if temp_df[col].isnull().all(): # 检查列是否包含 None 或 NaN
temp_df[col] = pd.to_numeric(temp_df[col], errors="coerce")
if big_df.empty:
big_df = temp_df
else:
big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
temp_date_list = pd.to_datetime(big_df["SOLAR_DATE"]).dt.date.to_list()
if pd.to_datetime(start_date) in pd.date_range(
temp_date_list[-1], temp_date_list[0]
):
break
big_df.rename(
columns={
"SOLAR_DATE": "日期",
"EMM00166462": "中国国债收益率5年",
"EMM00166466": "中国国债收益率10年",
"EMM00166469": "中国国债收益率30年",
"EMM00588704": "中国国债收益率2年",
"EMM01276014": "中国国债收益率10年-2年",
"EMG00001306": "美国国债收益率2年",
"EMG00001308": "美国国债收益率5年",
"EMG00001310": "美国国债收益率10年",
"EMG00001312": "美国国债收益率30年",
"EMG01339436": "美国国债收益率10年-2年",
"EMM00000024": "中国GDP年增率",
"EMG00159635": "美国GDP年增率",
},
inplace=True,
)
big_df = big_df[
[
"日期",
"中国国债收益率2年",
"中国国债收益率5年",
"中国国债收益率10年",
"中国国债收益率30年",
"中国国债收益率10年-2年",
"中国GDP年增率",
"美国国债收益率2年",
"美国国债收益率5年",
"美国国债收益率10年",
"美国国债收益率30年",
"美国国债收益率10年-2年",
"美国GDP年增率",
]
]
big_df["日期"] = pd.to_datetime(big_df["日期"], errors="coerce")
big_df["中国国债收益率2年"] = pd.to_numeric(
big_df["中国国债收益率2年"], errors="coerce"
)
big_df["中国国债收益率5年"] = pd.to_numeric(
big_df["中国国债收益率5年"], errors="coerce"
)
big_df["中国国债收益率10年"] = pd.to_numeric(
big_df["中国国债收益率10年"], errors="coerce"
)
big_df["中国国债收益率30年"] = pd.to_numeric(
big_df["中国国债收益率30年"], errors="coerce"
)
big_df["中国国债收益率10年-2年"] = pd.to_numeric(
big_df["中国国债收益率10年-2年"], errors="coerce"
)
big_df["中国GDP年增率"] = pd.to_numeric(big_df["中国GDP年增率"], errors="coerce")
big_df["美国国债收益率2年"] = pd.to_numeric(
big_df["美国国债收益率2年"], errors="coerce"
)
big_df["美国国债收益率5年"] = pd.to_numeric(
big_df["美国国债收益率5年"], errors="coerce"
)
big_df["美国国债收益率10年"] = pd.to_numeric(
big_df["美国国债收益率10年"], errors="coerce"
)
big_df["美国国债收益率30年"] = pd.to_numeric(
big_df["美国国债收益率30年"], errors="coerce"
)
big_df["美国国债收益率10年-2年"] = pd.to_numeric(
big_df["美国国债收益率10年-2年"], errors="coerce"
)
big_df["美国GDP年增率"] = pd.to_numeric(big_df["美国GDP年增率"], errors="coerce")
big_df.sort_values("日期", inplace=True)
big_df.set_index(["日期"], inplace=True)
big_df = big_df[pd.to_datetime(start_date) :]
big_df.reset_index(inplace=True)
big_df["日期"] = pd.to_datetime(big_df["日期"]).dt.date
return big_df
if __name__ == "__main__":
bond_zh_us_rate_df = bond_zh_us_rate(start_date="19901219")
print(bond_zh_us_rate_df)
@@ -0,0 +1,104 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2026/2/4 17:00
Desc: 新浪财经-债券-中国/美国国债收益率
https://vip.stock.finance.sina.com.cn/mkt/#hs_z
"""
import pandas as pd
import requests
def bond_gb_zh_sina(symbol: str = "中国10年期国债") -> pd.DataFrame:
"""
新浪财经-债券-中国国债收益率行情数据
https://stock.finance.sina.com.cn/forex/globalbd/cn10yt.html
:param symbol: choice of {"中国1年期国债", "中国2年期国债", "中国3年期国债", "中国5年期国债", "中国7年期国债", "中国10年期国债", "中国15年期国债", "中国20年期国债", "中国30年期国债"}
:type symbol: str
:return: 中国国债收益率行情数据
:rtype: pandas.DataFrame
"""
symbol_map = {
"中国1年期国债": "CN1YT",
"中国2年期国债": "CN2YT",
"中国3年期国债": "CN3YT",
"中国5年期国债": "CN5YT",
"中国7年期国债": "CN7YT",
"中国10年期国债": "CN10YT",
"中国15年期国债": "CN15YT",
"中国20年期国债": "CN20YT",
"中国30年期国债": "CN30YT",
}
url = f"https://bond.finance.sina.com.cn/hq/gb/daily?symbol={symbol_map[symbol]}"
r = requests.get(url)
data_json = r.json()
temp_df = pd.DataFrame(data_json["result"]["data"])
temp_df.columns = [
"date",
"open",
"high",
"low",
"close",
"volume",
]
temp_df["date"] = pd.to_datetime(temp_df["date"], errors="coerce").dt.date
temp_df["open"] = pd.to_numeric(temp_df["open"], errors="coerce")
temp_df["high"] = pd.to_numeric(temp_df["high"], errors="coerce")
temp_df["low"] = pd.to_numeric(temp_df["low"], errors="coerce")
temp_df["close"] = pd.to_numeric(temp_df["close"], errors="coerce")
temp_df["volume"] = pd.to_numeric(temp_df["volume"], errors="coerce")
return temp_df
def bond_gb_us_sina(symbol: str = "美国10年期国债") -> pd.DataFrame:
"""
新浪财经-债券-美国国债收益率行情数据
https://stock.finance.sina.com.cn/forex/globalbd/cn10yt.html
:param symbol: choice of {"美国1月期国债", "美国2月期国债", "美国3月期国债", "美国4月期国债", "美国6月期国债", "美国1年期国债", "美国2年期国债", "美国3年期国债", "美国5年期国债", "美国7年期国债", "美国10年期国债", "美国20年期国债", "美国30年期国债"}
:type symbol: str
:return: 美国国债收益率行情数据
:rtype: pandas.DataFrame
"""
symbol_map = {
"美国1月期国债": "US1MT",
"美国2月期国债": "US2MT",
"美国3月期国债": "US3MT",
"美国4月期国债": "US4MT",
"美国6月期国债": "US6MT",
"美国1年期国债": "US1YT",
"美国2年期国债": "US2YT",
"美国3年期国债": "US3YT",
"美国5年期国债": "US5YT",
"美国7年期国债": "US7YT",
"美国10年期国债": "US10YT",
"美国20年期国债": "US20YT",
"美国30年期国债": "US30YT",
}
url = f"https://bond.finance.sina.com.cn/hq/gb/daily?symbol={symbol_map[symbol]}"
r = requests.get(url)
data_json = r.json()
temp_df = pd.DataFrame(data_json["result"]["data"])
temp_df.columns = [
"date",
"open",
"high",
"low",
"close",
"volume",
]
temp_df["date"] = pd.to_datetime(temp_df["date"], errors="coerce").dt.date
temp_df["open"] = pd.to_numeric(temp_df["open"], errors="coerce")
temp_df["high"] = pd.to_numeric(temp_df["high"], errors="coerce")
temp_df["low"] = pd.to_numeric(temp_df["low"], errors="coerce")
temp_df["close"] = pd.to_numeric(temp_df["close"], errors="coerce")
temp_df["volume"] = pd.to_numeric(temp_df["volume"], errors="coerce")
return temp_df
if __name__ == "__main__":
bond_gb_zh_sina_df = bond_gb_zh_sina(symbol="中国10年期国债")
print(bond_gb_zh_sina_df)
bond_gb_us_sina_df = bond_gb_us_sina(symbol="美国10年期国债")
print(bond_gb_us_sina_df)
@@ -0,0 +1,231 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2024/5/10 14:00
Desc: 中国外汇交易中心暨全国银行间同业拆借中心
https://www.chinamoney.com.cn/chinese/scsjzqxx/
"""
import functools
import pandas as pd
import requests
from akshare.bond.bond_china import bond_china_close_return_map
from akshare.utils.tqdm import get_tqdm
@functools.lru_cache()
def bond_info_cm_query(symbol: str = "评级等级") -> pd.DataFrame:
"""
中国外汇交易中心暨全国银行间同业拆借中心-查询相关指标的参数
https://www.chinamoney.com.cn/chinese/scsjzqxx/
:param symbol: choice of {"主承销商", "债券类型", "息票类型", "发行年份", "评级等级"}
:type symbol: str
:return: 查询相关指标的参数
:rtype: pandas.DataFrame
"""
bond_china_close_return_map()
if symbol == "主承销商":
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bond-md/EntyFullNameSearchCondition"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/109.0.0.0 Safari/537.36"
}
r = requests.post(url, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"]["enty"])
temp_df.columns = ["code", "name"]
temp_df = temp_df[["name", "code"]]
return temp_df
else:
symbol_map = {
"债券类型": "bondType",
"息票类型": "couponType",
"发行年份": "issueYear",
"评级等级": "bondRtngShrt",
}
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bond-md/BondBaseInfoSearchCondition"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/109.0.0.0 Safari/537.36"
}
r = requests.post(url, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"][f"{symbol_map[symbol]}"])
if temp_df.shape[1] == 1:
temp_df.columns = ["name"]
temp_df["code"] = temp_df["name"]
temp_df.columns = ["code", "name"]
temp_df = temp_df[["name", "code"]]
return temp_df
@functools.lru_cache()
def bond_info_cm(
bond_name: str = "",
bond_code: str = "",
bond_issue: str = "",
bond_type: str = "",
coupon_type: str = "",
issue_year: str = "",
underwriter: str = "",
grade: str = "",
) -> pd.DataFrame:
"""
中国外汇交易中心暨全国银行间同业拆借中心-数据-债券信息-信息查询
https://www.chinamoney.com.cn/chinese/scsjzqxx/
:param bond_name: 债券名称
:type bond_name: str
:param bond_code: 债券代码
:type bond_code: str
:param bond_issue: 发行人/受托机构
:type bond_issue: str
:param bond_type: 债券类型
:type bond_type: str
:param coupon_type: 息票类型
:type coupon_type: str
:param issue_year: 发行年份
:type issue_year: str
:param underwriter: 主承销商
:type underwriter: str
:param grade: 评级等级
:type grade: str
:return: 信息查询结果
:rtype: pandas.DataFrame
"""
bond_china_close_return_map()
if bond_type:
bond_type_df = bond_info_cm_query(symbol="债券类型")
bond_type_df_value = bond_type_df[bond_type_df["name"] == bond_type][
"code"
].values[0]
else:
bond_type_df_value = ""
if coupon_type:
coupon_type_df = bond_info_cm_query(symbol="息票类型")
coupon_type_df_value = coupon_type_df[coupon_type_df["name"] == coupon_type][
"code"
].values[0]
else:
coupon_type_df_value = ""
if underwriter:
underwriter_df = bond_info_cm_query(symbol="主承销商")
underwriter_value = underwriter_df[underwriter_df["name"] == underwriter][
"code"
].values[0]
else:
underwriter_value = ""
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bond-md/BondMarketInfoList2"
payload = {
"pageNo": "1",
"pageSize": "15",
"bondName": bond_name,
"bondCode": bond_code,
"issueEnty": bond_issue,
"bondType": bond_type_df_value if bond_type_df_value else "",
"bondSpclPrjctVrty": "",
"couponType": coupon_type_df_value if coupon_type_df_value else "",
"issueYear": issue_year,
"entyDefinedCode": underwriter_value if underwriter_value else "",
"rtngShrt": grade,
}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/109.0.0.0 Safari/537.36"
}
r = requests.post(url, data=payload, headers=headers)
data_json = r.json()
total_page = data_json["data"]["pageTotal"]
big_df = pd.DataFrame()
tqdm = get_tqdm()
for page in tqdm(range(1, total_page + 1), leave=False):
payload.update({"pageNo": page})
r = requests.post(url, data=payload, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"]["resultList"])
big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
big_df.rename(
columns={
"bondDefinedCode": "查询代码",
"bondName": "债券简称",
"bondCode": "债券代码",
"issueStartDate": "发行日期",
"issueEndDate": "-",
"bondTypeCode": "-",
"bondType": "债券类型",
"entyFullName": "发行人/受托机构",
"entyDefinedCode": "-",
"debtRtng": "最新债项评级",
"isin": "-",
"inptTp": "-",
},
inplace=True,
)
big_df = big_df[
[
"债券简称",
"债券代码",
"发行人/受托机构",
"债券类型",
"发行日期",
"最新债项评级",
"查询代码",
]
]
return big_df
@functools.lru_cache()
def bond_info_detail_cm(symbol: str = "淮安农商行CDSD2022021012") -> pd.DataFrame:
"""
中国外汇交易中心暨全国银行间同业拆借中心-数据-债券信息-信息查询-债券详情
https://www.chinamoney.com.cn/chinese/zqjc/?bondDefinedCode=egfjh08154
:param symbol: 债券简称
:type symbol: str
:return: 债券详情
:rtype: pandas.DataFrame
"""
bond_china_close_return_map()
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bond-md/BondDetailInfo"
inner_bond_info_cm_df = bond_info_cm(bond_name=symbol)
bond_code = inner_bond_info_cm_df["查询代码"].values[0]
payload = {"bondDefinedCode": bond_code}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/109.0.0.0 Safari/537.36",
"host": "www.chinamoney.com.cn",
"origin": "https://www.chinamoney.com.cn",
"referer": "https://www.chinamoney.com.cn/chinese/zqjc/?bondDefinedCode=egfjh08154",
}
r = requests.post(url, data=payload, headers=headers)
data_json = r.json()
data_dict = data_json["data"]["bondBaseInfo"]
if data_dict["creditRateEntyList"]:
del data_dict["creditRateEntyList"]
if data_dict["exerciseInfoList"]:
del data_dict["exerciseInfoList"]
temp_df = pd.DataFrame.from_dict(data_dict, orient="index")
temp_df.reset_index(inplace=True)
temp_df.columns = ["name", "value"]
return temp_df
if __name__ == "__main__":
bond_info_cm_df = bond_info_cm(
bond_name="",
bond_code="",
bond_issue="",
bond_type="短期融资券",
coupon_type="零息式",
issue_year="2019",
grade="A-1",
underwriter="重庆农村商业银行股份有限公司",
)
print(bond_info_cm_df)
bond_info_detail_cm_df = bond_info_detail_cm(symbol="19渝机电CP002")
print(bond_info_detail_cm_df)
@@ -0,0 +1,574 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
"""
Date: 2024/6/19 22:00
Desc: 巨潮资讯-数据中心-专题统计-债券报表-债券发行
http://webapi.cninfo.com.cn/#/thematicStatistics
"""
import pandas as pd
import requests
import py_mini_racer
from akshare.datasets import get_ths_js
def _get_file_content_cninfo(file: str = "cninfo.js") -> str:
"""
获取 JS 文件的内容
:param file: JS 文件名
:type file: str
:return: 文件内容
:rtype: str
"""
setting_file_path = get_ths_js(file)
with open(setting_file_path, encoding="utf-8") as f:
file_data = f.read()
return file_data
def bond_treasure_issue_cninfo(
start_date: str = "20210910", end_date: str = "20211109"
) -> pd.DataFrame:
"""
巨潮资讯-数据中心-专题统计-债券报表-债券发行-国债发行
http://webapi.cninfo.com.cn/#/thematicStatistics
:param start_date: 开始统计时间
:type start_date: str
:param end_date: 结束统计数据
:type end_date: str
:return: 国债发行
:rtype: pandas.DataFrame
"""
url = "http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1120"
js_code = py_mini_racer.MiniRacer()
js_content = _get_file_content_cninfo("cninfo.js")
js_code.eval(js_content)
mcode = js_code.call("getResCode1")
headers = {
"Accept": "*/*",
"Accept-Enckey": mcode,
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Content-Length": "0",
"Host": "webapi.cninfo.com.cn",
"Origin": "http://webapi.cninfo.com.cn",
"Pragma": "no-cache",
"Proxy-Connection": "keep-alive",
"Referer": "http://webapi.cninfo.com.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/93.0.4577.63 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
params = {
"sdate": "-".join([start_date[:4], start_date[4:6], start_date[6:]]),
"edate": "-".join([end_date[:4], end_date[4:6], end_date[6:]]),
}
r = requests.post(url, headers=headers, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
temp_df.rename(
columns={
"F009D": "缴款日",
"SECNAME": "债券简称",
"DECLAREDATE": "公告日期",
"F004D": "发行起始日",
"F003D": "发行终止日",
"F008N": "单位面值",
"SECCODE": "债券代码",
"F007N": "发行价格",
"F006N": "计划发行总量",
"F005N": "实际发行总量",
"F028N": "增发次数",
"BONDNAME": "债券名称",
"F014V": "发行对象",
"F002V": "交易市场",
"F013V": "发行方式",
},
inplace=True,
)
temp_df = temp_df[
[
"债券代码",
"债券简称",
"发行起始日",
"发行终止日",
"计划发行总量",
"实际发行总量",
"发行价格",
"单位面值",
"缴款日",
"增发次数",
"交易市场",
"发行方式",
"发行对象",
"公告日期",
"债券名称",
]
]
temp_df["发行起始日"] = pd.to_datetime(
temp_df["发行起始日"], errors="coerce"
).dt.date
temp_df["发行终止日"] = pd.to_datetime(
temp_df["发行终止日"], errors="coerce"
).dt.date
temp_df["缴款日"] = pd.to_datetime(temp_df["缴款日"], errors="coerce").dt.date
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"], errors="coerce").dt.date
temp_df["计划发行总量"] = pd.to_numeric(temp_df["计划发行总量"], errors="coerce")
temp_df["实际发行总量"] = pd.to_numeric(temp_df["实际发行总量"], errors="coerce")
temp_df["发行价格"] = pd.to_numeric(temp_df["发行价格"], errors="coerce")
temp_df["单位面值"] = pd.to_numeric(temp_df["单位面值"], errors="coerce")
temp_df["增发次数"] = pd.to_numeric(temp_df["增发次数"], errors="coerce")
return temp_df
def bond_local_government_issue_cninfo(
start_date: str = "20210911", end_date: str = "20211110"
) -> pd.DataFrame:
"""
巨潮资讯-数据中心-专题统计-债券报表-债券发行-地方债发行
http://webapi.cninfo.com.cn/#/thematicStatistics
:param start_date: 开始统计时间
:type start_date: str
:param end_date: 开始统计时间
:type end_date: str
:return: 地方债发行
:rtype: pandas.DataFrame
"""
url = "http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1121"
js_code = py_mini_racer.MiniRacer()
js_content = _get_file_content_cninfo("cninfo.js")
js_code.eval(js_content)
mcode = js_code.call("getResCode1")
headers = {
"Accept": "*/*",
"Accept-Enckey": mcode,
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Content-Length": "0",
"Host": "webapi.cninfo.com.cn",
"Origin": "http://webapi.cninfo.com.cn",
"Pragma": "no-cache",
"Proxy-Connection": "keep-alive",
"Referer": "http://webapi.cninfo.com.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/93.0.4577.63 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
params = {
"sdate": "-".join([start_date[:4], start_date[4:6], start_date[6:]]),
"edate": "-".join([end_date[:4], end_date[4:6], end_date[6:]]),
}
r = requests.post(url, headers=headers, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
temp_df.rename(
columns={
"F009D": "缴款日",
"SECNAME": "债券简称",
"DECLAREDATE": "公告日期",
"F004D": "发行起始日",
"F003D": "发行终止日",
"F008N": "单位面值",
"SECCODE": "债券代码",
"F007N": "发行价格",
"F006N": "计划发行总量",
"F005N": "实际发行总量",
"F028N": "增发次数",
"BONDNAME": "债券名称",
"F014V": "发行对象",
"F002V": "交易市场",
"F013V": "发行方式",
},
inplace=True,
)
temp_df = temp_df[
[
"债券代码",
"债券简称",
"发行起始日",
"发行终止日",
"计划发行总量",
"实际发行总量",
"发行价格",
"单位面值",
"缴款日",
"增发次数",
"交易市场",
"发行方式",
"发行对象",
"公告日期",
"债券名称",
]
]
temp_df["发行起始日"] = pd.to_datetime(
temp_df["发行起始日"], errors="coerce"
).dt.date
temp_df["发行终止日"] = pd.to_datetime(
temp_df["发行终止日"], errors="coerce"
).dt.date
temp_df["缴款日"] = pd.to_datetime(temp_df["缴款日"], errors="coerce").dt.date
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"], errors="coerce").dt.date
temp_df["计划发行总量"] = pd.to_numeric(temp_df["计划发行总量"], errors="coerce")
temp_df["实际发行总量"] = pd.to_numeric(temp_df["实际发行总量"], errors="coerce")
temp_df["发行价格"] = pd.to_numeric(temp_df["发行价格"], errors="coerce")
temp_df["单位面值"] = pd.to_numeric(temp_df["单位面值"], errors="coerce")
temp_df["增发次数"] = pd.to_numeric(temp_df["增发次数"], errors="coerce")
return temp_df
def bond_corporate_issue_cninfo(
start_date: str = "20210911", end_date: str = "20211110"
) -> pd.DataFrame:
"""
巨潮资讯-数据中心-专题统计-债券报表-债券发行-企业债发行
http://webapi.cninfo.com.cn/#/thematicStatistics
:param start_date: 开始统计时间
:type start_date: str
:param end_date: 开始统计时间
:type end_date: str
:return: 企业债发行
:rtype: pandas.DataFrame
"""
url = "http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1122"
js_code = py_mini_racer.MiniRacer()
js_content = _get_file_content_cninfo("cninfo.js")
js_code.eval(js_content)
mcode = js_code.call("getResCode1")
headers = {
"Accept": "*/*",
"Accept-Enckey": mcode,
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Content-Length": "0",
"Host": "webapi.cninfo.com.cn",
"Origin": "http://webapi.cninfo.com.cn",
"Pragma": "no-cache",
"Proxy-Connection": "keep-alive",
"Referer": "http://webapi.cninfo.com.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/93.0.4577.63 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
params = {
"sdate": "-".join([start_date[:4], start_date[4:6], start_date[6:]]),
"edate": "-".join([end_date[:4], end_date[4:6], end_date[6:]]),
}
r = requests.post(url, headers=headers, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
temp_df.rename(
columns={
"SECNAME": "债券简称",
"DECLAREDATE": "公告日期",
"F004D": "交易所网上发行终止日",
"F003D": "交易所网上发行起始日",
"F008N": "发行面值",
"SECCODE": "债券代码",
"F007N": "发行价格",
"F006N": "实际发行总量",
"F005N": "计划发行总量",
"F022N": "最小认购单位",
"F017V": "承销方式",
"F052N": "最低认购额",
"F015V": "发行范围",
"BONDNAME": "债券名称",
"F014V": "发行对象",
"F013V": "发行方式",
"F023V": "募资用途说明",
},
inplace=True,
)
temp_df = temp_df[
[
"债券代码",
"债券简称",
"公告日期",
"交易所网上发行起始日",
"交易所网上发行终止日",
"计划发行总量",
"实际发行总量",
"发行面值",
"发行价格",
"发行方式",
"发行对象",
"发行范围",
"承销方式",
"最小认购单位",
"募资用途说明",
"最低认购额",
"债券名称",
]
]
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"], errors="coerce").dt.date
temp_df["交易所网上发行起始日"] = pd.to_datetime(
temp_df["交易所网上发行起始日"], errors="coerce"
).dt.date
temp_df["交易所网上发行终止日"] = pd.to_datetime(
temp_df["交易所网上发行终止日"], errors="coerce"
).dt.date
temp_df["计划发行总量"] = pd.to_numeric(temp_df["计划发行总量"], errors="coerce")
temp_df["实际发行总量"] = pd.to_numeric(temp_df["实际发行总量"], errors="coerce")
temp_df["发行面值"] = pd.to_numeric(temp_df["发行面值"], errors="coerce")
temp_df["发行价格"] = pd.to_numeric(temp_df["发行价格"], errors="coerce")
temp_df["最小认购单位"] = pd.to_numeric(temp_df["最小认购单位"], errors="coerce")
temp_df["最低认购额"] = pd.to_numeric(temp_df["最低认购额"], errors="coerce")
return temp_df
def bond_cov_issue_cninfo(
start_date: str = "20210913", end_date: str = "20211112"
) -> pd.DataFrame:
"""
巨潮资讯-数据中心-专题统计-债券报表-债券发行-可转债发行
http://webapi.cninfo.com.cn/#/thematicStatistics
:param start_date: 开始统计时间
:type start_date: str
:param end_date: 开始统计时间
:type end_date: str
:return: 可转债发行
:rtype: pandas.DataFrame
"""
url = "http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1123"
js_code = py_mini_racer.MiniRacer()
js_content = _get_file_content_cninfo("cninfo.js")
js_code.eval(js_content)
mcode = js_code.call("getResCode1")
headers = {
"Accept": "*/*",
"Accept-Enckey": mcode,
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Content-Length": "0",
"Host": "webapi.cninfo.com.cn",
"Origin": "http://webapi.cninfo.com.cn",
"Pragma": "no-cache",
"Proxy-Connection": "keep-alive",
"Referer": "http://webapi.cninfo.com.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/93.0.4577.63 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
params = {
"sdate": "-".join([start_date[:4], start_date[4:6], start_date[6:]]),
"edate": "-".join([end_date[:4], end_date[4:6], end_date[6:]]),
}
r = requests.post(url, headers=headers, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
temp_df.rename(
columns={
"F029D": "发行起始日",
"SECNAME": "债券简称",
"F027D": "转股开始日期",
"F003D": "发行终止日",
"F007N": "发行面值",
"F053D": "转股终止日期",
"F005N": "计划发行总量",
"F051D": "网上申购日期",
"F026N": "初始转股价格",
"F066N": "网上申购数量下限",
"F052N": "发行价格",
"BONDNAME": "债券名称",
"F014V": "发行对象",
"F002V": "交易市场",
"F032V": "网上申购简称",
"F086V": "转股代码",
"DECLAREDATE": "公告日期",
"F028D": "债权登记日",
"F004D": "优先申购日",
"F068D": "网上申购中签结果公告日及退款日",
"F054D": "优先申购缴款日",
"F008N": "网上申购数量上限",
"SECCODE": "债券代码",
"F006N": "实际发行总量",
"F067N": "网上申购单位",
"F065N": "配售价格",
"F017V": "承销方式",
"F015V": "发行范围",
"F013V": "发行方式",
"F021V": "募资用途说明",
"F031V": "网上申购代码",
},
inplace=True,
)
temp_df = temp_df[
[
"债券代码",
"债券简称",
"公告日期",
"发行起始日",
"发行终止日",
"计划发行总量",
"实际发行总量",
"发行面值",
"发行价格",
"发行方式",
"发行对象",
"发行范围",
"承销方式",
"募资用途说明",
"初始转股价格",
"转股开始日期",
"转股终止日期",
"网上申购日期",
"网上申购代码",
"网上申购简称",
"网上申购数量上限",
"网上申购数量下限",
"网上申购单位",
"网上申购中签结果公告日及退款日",
"优先申购日",
"配售价格",
"债权登记日",
"优先申购缴款日",
"转股代码",
"交易市场",
"债券名称",
]
]
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"], errors="coerce").dt.date
temp_df["发行起始日"] = pd.to_datetime(
temp_df["发行起始日"], errors="coerce"
).dt.date
temp_df["发行终止日"] = pd.to_datetime(
temp_df["发行终止日"], errors="coerce"
).dt.date
temp_df["转股开始日期"] = pd.to_datetime(
temp_df["转股开始日期"], errors="coerce"
).dt.date
temp_df["转股终止日期"] = pd.to_datetime(
temp_df["转股终止日期"], errors="coerce"
).dt.date
temp_df["转股终止日期"] = pd.to_datetime(
temp_df["转股终止日期"], errors="coerce"
).dt.date
temp_df["网上申购日期"] = pd.to_datetime(
temp_df["网上申购日期"], errors="coerce"
).dt.date
temp_df["网上申购中签结果公告日及退款日"] = pd.to_datetime(
temp_df["网上申购中签结果公告日及退款日"], errors="coerce"
).dt.date
temp_df["债权登记日"] = pd.to_datetime(
temp_df["债权登记日"], errors="coerce"
).dt.date
temp_df["优先申购日"] = pd.to_datetime(
temp_df["优先申购日"], errors="coerce"
).dt.date
temp_df["优先申购缴款日"] = pd.to_datetime(
temp_df["优先申购缴款日"], errors="coerce"
).dt.date
temp_df["计划发行总量"] = pd.to_numeric(temp_df["计划发行总量"], errors="coerce")
temp_df["实际发行总量"] = pd.to_numeric(temp_df["实际发行总量"], errors="coerce")
temp_df["发行面值"] = pd.to_numeric(temp_df["发行面值"], errors="coerce")
temp_df["发行价格"] = pd.to_numeric(temp_df["发行价格"], errors="coerce")
temp_df["初始转股价格"] = pd.to_numeric(temp_df["初始转股价格"], errors="coerce")
temp_df["网上申购数量上限"] = pd.to_numeric(
temp_df["网上申购数量上限"], errors="coerce"
)
temp_df["网上申购数量下限"] = pd.to_numeric(
temp_df["网上申购数量下限"], errors="coerce"
)
temp_df["网上申购单位"] = pd.to_numeric(temp_df["网上申购单位"], errors="coerce")
temp_df["配售价格"] = pd.to_numeric(temp_df["配售价格"], errors="coerce")
return temp_df
def bond_cov_stock_issue_cninfo() -> pd.DataFrame:
"""
巨潮资讯-数据中心-专题统计-债券报表-债券发行-可转债转股
http://webapi.cninfo.com.cn/#/thematicStatistics
:return: 可转债转股
:rtype: pandas.DataFrame
"""
url = "http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1124"
js_code = py_mini_racer.MiniRacer()
js_content = _get_file_content_cninfo("cninfo.js")
js_code.eval(js_content)
mcode = js_code.call("getResCode1")
headers = {
"Accept": "*/*",
"Accept-Enckey": mcode,
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Content-Length": "0",
"Host": "webapi.cninfo.com.cn",
"Origin": "http://webapi.cninfo.com.cn",
"Pragma": "no-cache",
"Proxy-Connection": "keep-alive",
"Referer": "http://webapi.cninfo.com.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/93.0.4577.63 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
r = requests.post(url, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["records"])
temp_df.rename(
columns={
"F003N": "转股价格",
"SECNAME": "债券简称",
"DECLAREDATE": "公告日期",
"F005D": "自愿转换期终止日",
"F004D": "自愿转换期起始日",
"F017V": "标的股票",
"BONDNAME": "债券名称",
"F002V": "转股简称",
"F001V": "转股代码",
"SECCODE": "债券代码",
},
inplace=True,
)
temp_df = temp_df[
[
"债券代码",
"债券简称",
"公告日期",
"转股代码",
"转股简称",
"转股价格",
"自愿转换期起始日",
"自愿转换期终止日",
"标的股票",
"债券名称",
]
]
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"], errors="coerce").dt.date
temp_df["自愿转换期起始日"] = pd.to_datetime(
temp_df["自愿转换期起始日"], errors="coerce"
).dt.date
temp_df["自愿转换期终止日"] = pd.to_datetime(
temp_df["自愿转换期终止日"], errors="coerce"
).dt.date
temp_df["转股价格"] = pd.to_numeric(temp_df["转股价格"], errors="coerce")
return temp_df
if __name__ == "__main__":
bond_treasure_issue_cninfo_df = bond_treasure_issue_cninfo(
start_date="20210910", end_date="20211109"
)
print(bond_treasure_issue_cninfo_df)
bond_local_government_issue_cninfo_df = bond_local_government_issue_cninfo(
start_date="20210911", end_date="20211110"
)
print(bond_local_government_issue_cninfo_df)
bond_corporate_issue_cninfo_df = bond_corporate_issue_cninfo(
start_date="20210911", end_date="20211110"
)
print(bond_corporate_issue_cninfo_df)
bond_cov_issue_cninfo_df = bond_cov_issue_cninfo(
start_date="20210913", end_date="20211112"
)
print(bond_cov_issue_cninfo_df)
bond_cov_stock_issue_cninfo_df = bond_cov_stock_issue_cninfo()
print(bond_cov_stock_issue_cninfo_df)
@@ -0,0 +1,70 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2024/3/16 9:00
Desc:中国银行间市场交易商协会(https://www.nafmii.org.cn/)
孔雀开屏(http://zhuce.nafmii.org.cn/fans/publicQuery/manager)的债券基本信息数据
"""
import pandas as pd
import requests
def bond_debt_nafmii(page: str = "1") -> pd.DataFrame:
"""
中国银行间市场交易商协会-非金融企业债务融资工具注册信息系统
http://zhuce.nafmii.org.cn/fans/publicQuery/manager
:param page: 输入数字页码
:type page: int
:return: 指定 sector 和 indicator 的数据
:rtype: pandas.DataFrame
"""
url = "http://zhuce.nafmii.org.cn/fans/publicQuery/releFileProjDataGrid"
payload = {
"regFileName": "",
"itemType": "",
"startTime": "",
"endTime": "",
"entityName": "",
"leadManager": "",
"regPrdtType": "",
"page": page,
"rows": 50,
}
payload.update({"page": page})
r = requests.post(url, data=payload)
data_json = r.json() # 数据类型为 json 格式
temp_df = pd.DataFrame(data_json["rows"])
temp_df.rename(
columns={
"firstIssueAmount": "金额",
"isReg": "注册或备案",
"regFileName": "债券名称",
"regNoticeNo": "注册通知书文号",
"regPrdtType": "品种",
"releaseTime": "更新日期",
"projPhase": "项目状态",
},
inplace=True,
)
if "注册通知书文号" not in temp_df.columns:
temp_df["注册通知书文号"] = pd.NA
temp_df = temp_df[
[
"债券名称",
"品种",
"注册或备案",
"金额",
"注册通知书文号",
"更新日期",
"项目状态",
]
]
temp_df["金额"] = pd.to_numeric(temp_df["金额"], errors="coerce")
temp_df["更新日期"] = pd.to_datetime(temp_df["更新日期"], errors="coerce").dt.date
return temp_df
if __name__ == "__main__":
bond_debt_nafmii_df = bond_debt_nafmii(page="1")
print(bond_debt_nafmii_df)
@@ -0,0 +1,92 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2022/3/5 12:55
Desc: 上登债券信息网-债券成交概览
http://bond.sse.com.cn/data/statistics/overview/turnover/
"""
from io import BytesIO
import pandas as pd
import requests
def bond_cash_summary_sse(date: str = "20210111") -> pd.DataFrame:
"""
上登债券信息网-市场数据-市场统计-市场概览-债券现券市场概览
http://bond.sse.com.cn/data/statistics/overview/bondow/
:param date: 指定日期
:type date: str
:return: 债券成交概览
:rtype: pandas.DataFrame
"""
url = "http://query.sse.com.cn/commonExcelDd.do"
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Referer": "http://bond.sse.com.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
}
params = {
"sqlId": "COMMON_SSEBOND_SCSJ_SCTJ_SCGL_ZQXQSCGL_CX_L",
"TRADE_DATE": f"{date[:4]}-{date[4:6]}-{date[6:]}",
}
r = requests.get(url, params=params, headers=headers)
temp_df = pd.read_excel(BytesIO(r.content), engine="xlrd")
temp_df.columns = [
"债券现货",
"托管只数",
"托管市值",
"托管面值",
"数据日期",
]
temp_df["托管只数"] = pd.to_numeric(temp_df["托管只数"])
temp_df["托管市值"] = pd.to_numeric(temp_df["托管市值"])
temp_df["托管面值"] = pd.to_numeric(temp_df["托管面值"])
temp_df["数据日期"] = pd.to_datetime(temp_df["数据日期"]).dt.date
return temp_df
def bond_deal_summary_sse(date: str = "20210104") -> pd.DataFrame:
"""
上登债券信息网-市场数据-市场统计-市场概览-债券成交概览
http://bond.sse.com.cn/data/statistics/overview/turnover/
:param date: 指定日期
:type date: str
:return: 债券成交概览
:rtype: pandas.DataFrame
"""
url = "http://query.sse.com.cn/commonExcelDd.do"
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Referer": "http://bond.sse.com.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
}
params = {
"sqlId": "COMMON_SSEBOND_SCSJ_SCTJ_SCGL_ZQCJGL_CX_L",
"TRADE_DATE": f"{date[:4]}-{date[4:6]}-{date[6:]}",
}
r = requests.get(url, params=params, headers=headers)
temp_df = pd.read_excel(BytesIO(r.content))
temp_df.columns = [
"债券类型",
"当日成交笔数",
"当日成交金额",
"当年成交笔数",
"当年成交金额",
"数据日期",
]
temp_df["当日成交笔数"] = pd.to_numeric(temp_df["当日成交笔数"])
temp_df["当日成交金额"] = pd.to_numeric(temp_df["当日成交金额"])
temp_df["当年成交笔数"] = pd.to_numeric(temp_df["当年成交笔数"])
temp_df["当年成交金额"] = pd.to_numeric(temp_df["当年成交金额"])
temp_df["数据日期"] = pd.to_datetime(temp_df["数据日期"]).dt.date
return temp_df
if __name__ == "__main__":
bond_cash_summary_sse_df = bond_cash_summary_sse(date="20210111")
print(bond_cash_summary_sse_df)
bond_summary_sse_df = bond_deal_summary_sse(date="20210111")
print(bond_summary_sse_df)
@@ -0,0 +1,714 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2025/7/4 15:00
Desc: 新浪财经-债券-沪深可转债-实时行情数据和历史行情数据
https://vip.stock.finance.sina.com.cn/mkt/#hskzz_z
"""
import datetime
import re
import pandas as pd
import py_mini_racer
import requests
from akshare.bond.cons import (
zh_sina_bond_hs_cov_count_url,
zh_sina_bond_hs_cov_payload,
zh_sina_bond_hs_cov_url,
zh_sina_bond_hs_cov_hist_url,
)
from akshare.stock.cons import hk_js_decode
from akshare.utils import demjson
from akshare.utils.func import fetch_paginated_data
from akshare.utils.tqdm import get_tqdm
def _get_zh_bond_hs_cov_page_count() -> int:
"""
新浪财经-行情中心-债券-沪深可转债的总页数
https://vip.stock.finance.sina.com.cn/mkt/#hskzz_z
:return: 总页数
:rtype: int
"""
params = {
"node": "hskzz_z",
}
r = requests.get(zh_sina_bond_hs_cov_count_url, params=params)
page_count = int(re.findall(re.compile(r"\d+"), r.text)[0]) / 80
if isinstance(page_count, int):
return page_count
else:
return int(page_count) + 1
def bond_zh_hs_cov_spot() -> pd.DataFrame:
"""
新浪财经-债券-沪深可转债的实时行情数据; 大量抓取容易封IP
https://vip.stock.finance.sina.com.cn/mkt/#hskzz_z
:return: 所有沪深可转债在当前时刻的实时行情数据
:rtype: pandas.DataFrame
"""
big_df = pd.DataFrame()
page_count = _get_zh_bond_hs_cov_page_count()
zh_sina_bond_hs_payload_copy = zh_sina_bond_hs_cov_payload.copy()
tqdm = get_tqdm()
for page in tqdm(range(1, page_count + 1), leave=False):
zh_sina_bond_hs_payload_copy.update({"page": page})
res = requests.get(zh_sina_bond_hs_cov_url, params=zh_sina_bond_hs_payload_copy)
data_json = demjson.decode(res.text)
big_df = pd.concat(objs=[big_df, pd.DataFrame(data_json)], ignore_index=True)
return big_df
def bond_zh_hs_cov_daily(symbol: str = "sh010107") -> pd.DataFrame:
"""
新浪财经-债券-沪深可转债的历史行情数据, 大量抓取容易封 IP
https://vip.stock.finance.sina.com.cn/mkt/#hskzz_z
:param symbol: 沪深可转债代码; e.g., sh010107
:type symbol: str
:return: 指定沪深可转债代码的日 K 线数据
:rtype: pandas.DataFrame
"""
r = requests.get(
zh_sina_bond_hs_cov_hist_url.format(
symbol, datetime.datetime.now().strftime("%Y_%m_%d")
)
)
js_code = py_mini_racer.MiniRacer()
js_code.eval(hk_js_decode)
dict_list = js_code.call(
"d", r.text.split("=")[1].split(";")[0].replace('"', "")
) # 执行js解密代码
data_df = pd.DataFrame(dict_list)
data_df["date"] = pd.to_datetime(data_df["date"]).dt.date
return data_df
def _code_id_map() -> dict:
"""
东方财富-股票和市场代码
https://quote.eastmoney.com/center/gridlist.html#hs_a_board
:return: 股票和市场代码
:rtype: dict
"""
url = "https://80.push2.eastmoney.com/api/qt/clist/get"
params = {
"pn": "1",
"pz": "100",
"po": "1",
"np": "1",
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
"fltt": "2",
"invt": "2",
"fid": "f12",
"fs": "m:1 t:2,m:1 t:23",
"fields": "f3,f12",
}
temp_df = fetch_paginated_data(url, params)
temp_df["market_id"] = 1
temp_df.rename(columns={"f12": "sh_code", "market_id": "sh_id"}, inplace=True)
code_id_dict = dict(zip(temp_df["sh_code"], temp_df["sh_id"]))
params = {
"pn": "1",
"pz": "100",
"po": "1",
"np": "1",
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
"fltt": "2",
"invt": "2",
"fid": "f3",
"fs": "m:0 t:6,m:0 t:80",
"fields": "f3,f12",
}
temp_df_sz = fetch_paginated_data(url, params)
temp_df_sz["sz_id"] = 0
code_id_dict.update(dict(zip(temp_df_sz["f12"], temp_df_sz["sz_id"])))
return code_id_dict
def bond_zh_hs_cov_min(
symbol: str = "sz128039",
period: str = "15",
adjust: str = "",
start_date: str = "1979-09-01 09:32:00",
end_date: str = "2222-01-01 09:32:00",
) -> pd.DataFrame:
"""
东方财富网-可转债-分时行情
https://quote.eastmoney.com/concept/sz128039.html
:param symbol: 转债代码
:type symbol: str
:param period: choice of {'1', '5', '15', '30', '60'}
:type period: str
:param adjust: choice of {'', 'qfq', 'hfq'}
:type adjust: str
:param start_date: 开始日期
:type start_date: str
:param end_date: 结束日期
:type end_date: str
:return: 分时行情
:rtype: pandas.DataFrame
"""
market_type = {"sh": "1", "sz": "0"}
if period == "1":
url = "https://push2.eastmoney.com/api/qt/stock/trends2/get"
params = {
"secid": f"{market_type[symbol[:2]]}.{symbol[2:]}",
"fields1": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58",
"iscr": "0",
"iscca": "0",
"ut": "f057cbcbce2a86e2866ab8877db1d059",
"ndays": "1",
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(
[item.split(",") for item in data_json["data"]["trends"]]
)
temp_df.columns = [
"时间",
"开盘",
"收盘",
"最高",
"最低",
"成交量",
"成交额",
"最新价",
]
temp_df.index = pd.to_datetime(temp_df["时间"])
temp_df = temp_df[start_date:end_date]
temp_df.reset_index(drop=True, inplace=True)
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"], errors="coerce")
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(
str
) # show datatime here
return temp_df
else:
adjust_map = {
"": "0",
"qfq": "1",
"hfq": "2",
}
url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
params = {
"secid": f"{market_type[symbol[:2]]}.{symbol[2:]}",
"klt": period,
"fqt": adjust_map[adjust],
"lmt": "66",
"end": "20500000",
"iscca": "1",
"fields1": "f1,f2,f3,f4,f5",
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",
"ut": "7eea3edcaed734bea9cbfc24409ed989",
"forcect": "1",
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(
[item.split(",") for item in data_json["data"]["klines"]]
)
temp_df.columns = [
"时间",
"开盘",
"收盘",
"最高",
"最低",
"成交量",
"成交额",
"振幅",
"涨跌幅",
"涨跌额",
"换手率",
]
temp_df.index = pd.to_datetime(temp_df["时间"])
temp_df = temp_df[start_date:end_date]
temp_df.reset_index(drop=True, inplace=True)
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"], errors="coerce")
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
temp_df["振幅"] = pd.to_numeric(temp_df["振幅"], errors="coerce")
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
temp_df = temp_df[
[
"时间",
"开盘",
"收盘",
"最高",
"最低",
"涨跌幅",
"涨跌额",
"成交量",
"成交额",
"振幅",
"换手率",
]
]
return temp_df
def bond_zh_hs_cov_pre_min(symbol: str = "sh113570") -> pd.DataFrame:
"""
东方财富网-可转债-分时行情-盘前
https://quote.eastmoney.com/concept/sz128039.html
:param symbol: 转债代码
:type symbol: str
:return: 分时行情-盘前
:rtype: pandas.DataFrame
"""
market_type = {"sh": "1", "sz": "0"}
url = "https://push2.eastmoney.com/api/qt/stock/trends2/get"
params = {
"fields1": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58",
"ndays": "1",
"iscr": "1",
"iscca": "0",
"secid": f"{market_type[symbol[:2]]}.{symbol[2:]}",
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["trends"]])
temp_df.columns = [
"时间",
"开盘",
"收盘",
"最高",
"最低",
"成交量",
"成交额",
"最新价",
]
temp_df.index = pd.to_datetime(temp_df["时间"])
temp_df.reset_index(drop=True, inplace=True)
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"], errors="coerce")
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
return temp_df
def bond_zh_cov() -> pd.DataFrame:
"""
东方财富网-数据中心-新股数据-可转债数据
https://data.eastmoney.com/kzz/default.html
:return: 可转债数据
:rtype: pandas.DataFrame
"""
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
params = {
"sortColumns": "PUBLIC_START_DATE",
"sortTypes": "-1",
"pageSize": "500",
"pageNumber": "1",
"reportName": "RPT_BOND_CB_LIST",
"columns": "ALL",
"quoteColumns": "f2~01~CONVERT_STOCK_CODE~CONVERT_STOCK_PRICE,"
"f235~10~SECURITY_CODE~TRANSFER_PRICE,f236~10~SECURITY_CODE~TRANSFER_VALUE,"
"f2~10~SECURITY_CODE~CURRENT_BOND_PRICE,f237~10~SECURITY_CODE~TRANSFER_PREMIUM_RATIO,"
"f239~10~SECURITY_CODE~RESALE_TRIG_PRICE,f240~10~SECURITY_CODE~REDEEM_TRIG_PRICE,"
"f23~01~CONVERT_STOCK_CODE~PBV_RATIO",
"source": "WEB",
"client": "WEB",
}
r = requests.get(url, params=params)
data_json = r.json()
total_page = data_json["result"]["pages"]
big_df = pd.DataFrame()
tqdm = get_tqdm()
for page in tqdm(range(1, total_page + 1), leave=False):
params.update({"pageNumber": page})
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["result"]["data"])
big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
big_df.columns = [
"债券代码",
"_",
"_",
"债券简称",
"_",
"上市时间",
"正股代码",
"_",
"信用评级",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"发行规模",
"申购上限",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"申购代码",
"_",
"申购日期",
"_",
"_",
"中签号发布日",
"原股东配售-股权登记日",
"正股简称",
"原股东配售-每股配售额",
"_",
"中签率",
"-",
"_",
"_",
"_",
"_",
"_",
"正股价",
"转股价",
"转股价值",
"债现价",
"转股溢价率",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
"_",
]
big_df = big_df[
[
"债券代码",
"债券简称",
"申购日期",
"申购代码",
"申购上限",
"正股代码",
"正股简称",
"正股价",
"转股价",
"转股价值",
"债现价",
"转股溢价率",
"原股东配售-股权登记日",
"原股东配售-每股配售额",
"发行规模",
"中签号发布日",
"中签率",
"上市时间",
"信用评级",
]
]
big_df["申购上限"] = pd.to_numeric(big_df["申购上限"], errors="coerce")
big_df["正股价"] = pd.to_numeric(big_df["正股价"], errors="coerce")
big_df["转股价"] = pd.to_numeric(big_df["转股价"], errors="coerce")
big_df["转股价值"] = pd.to_numeric(big_df["转股价值"], errors="coerce")
big_df["债现价"] = pd.to_numeric(big_df["债现价"], errors="coerce")
big_df["转股溢价率"] = pd.to_numeric(big_df["转股溢价率"], errors="coerce")
big_df["原股东配售-每股配售额"] = pd.to_numeric(
big_df["原股东配售-每股配售额"], errors="coerce"
)
big_df["发行规模"] = pd.to_numeric(big_df["发行规模"], errors="coerce")
big_df["中签率"] = pd.to_numeric(big_df["中签率"], errors="coerce")
big_df["中签号发布日"] = pd.to_datetime(
big_df["中签号发布日"], errors="coerce"
).dt.date
big_df["上市时间"] = pd.to_datetime(big_df["上市时间"], errors="coerce").dt.date
big_df["申购日期"] = pd.to_datetime(big_df["申购日期"], errors="coerce").dt.date
big_df["原股东配售-股权登记日"] = pd.to_datetime(
big_df["原股东配售-股权登记日"], errors="coerce"
).dt.date
big_df["债现价"] = big_df["债现价"].fillna(100)
return big_df
def bond_cov_comparison() -> pd.DataFrame:
"""
东方财富网-行情中心-债券市场-可转债比价表
https://quote.eastmoney.com/center/fullscreenlist.html#convertible_comparison
:return: 可转债比价表数据
:rtype: pandas.DataFrame
"""
url = "https://16.push2.eastmoney.com/api/qt/clist/get"
params = {
"pn": "1",
"pz": "100",
"po": "1",
"np": "1",
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
"fltt": "2",
"invt": "2",
"fid": "f243",
"fs": "b:MK0354",
"fields": "f1,f152,f2,f3,f12,f13,f14,f227,f228,f229,f230,f231,f232,f233,f234,"
"f235,f236,f237,f238,f239,f240,f241,f242,f26,f243",
}
temp_df = fetch_paginated_data(url, params)
temp_df.columns = [
"序号",
"_",
"转债最新价",
"转债涨跌幅",
"转债代码",
"_",
"转债名称",
"上市日期",
"_",
"纯债价值",
"_",
"正股最新价",
"正股涨跌幅",
"_",
"正股代码",
"_",
"正股名称",
"转股价",
"转股价值",
"转股溢价率",
"纯债溢价率",
"回售触发价",
"强赎触发价",
"到期赎回价",
"开始转股日",
"申购日期",
]
temp_df = temp_df[
[
"序号",
"转债代码",
"转债名称",
"转债最新价",
"转债涨跌幅",
"正股代码",
"正股名称",
"正股最新价",
"正股涨跌幅",
"转股价",
"转股价值",
"转股溢价率",
"纯债溢价率",
"回售触发价",
"强赎触发价",
"到期赎回价",
"纯债价值",
"开始转股日",
"上市日期",
"申购日期",
]
]
return temp_df
def bond_zh_cov_info(
symbol: str = "123121", indicator: str = "基本信息"
) -> pd.DataFrame:
"""
https://data.eastmoney.com/kzz/detail/123121.html
东方财富网-数据中心-新股数据-可转债详情
:param symbol: 可转债代码
:type symbol: str
:param indicator: choice of {"基本信息", "中签号", "筹资用途", "重要日期"}
:type indicator: str
:return: 可转债详情
:rtype: pandas.DataFrame
"""
indicator_map = {
"基本信息": "RPT_BOND_CB_LIST",
"中签号": "RPT_CB_BALLOTNUM",
"筹资用途": "RPT_BOND_BS_OPRFINVESTITEM",
"重要日期": "RPT_CB_IMPORTANTDATE",
}
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
params = {
"reportName": "RPT_BOND_CB_LIST",
"columns": "ALL",
"quoteColumns": "f2~01~CONVERT_STOCK_CODE~CONVERT_STOCK_PRICE,f235~10~SECURITY_CODE~TRANSFER_PRICE,"
"f236~10~SECURITY_CODE~TRANSFER_VALUE,f2~10~SECURITY_CODE~CURRENT_BOND_PRICE,"
"f237~10~SECURITY_CODE~TRANSFER_PREMIUM_RATIO,f239~10~SECURITY_CODE~RESALE_TRIG_PRICE,"
"f240~10~SECURITY_CODE~REDEEM_TRIG_PRICE,f23~01~CONVERT_STOCK_CODE~PBV_RATIO",
"quoteType": "0",
"source": "WEB",
"client": "WEB",
"filter": f'(SECURITY_CODE="{symbol}")',
}
if indicator == "基本信息":
params.update(
{
"reportName": indicator_map[indicator],
"quoteColumns": "f2~01~CONVERT_STOCK_CODE~CONVERT_STOCK_PRICE,f235~10~SECURITY_CODE~TRANSFER_PRICE,"
"f236~10~SECURITY_CODE~TRANSFER_VALUE,f2~10~SECURITY_CODE~CURRENT_BOND_PRICE,"
"f237~10~SECURITY_CODE~TRANSFER_PREMIUM_RATIO,f239~10~SECURITY_CODE~RESALE_TRIG_PRICE,"
"f240~10~SECURITY_CODE~REDEEM_TRIG_PRICE,f23~01~CONVERT_STOCK_CODE~PBV_RATIO",
}
)
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame.from_dict(data_json["result"]["data"])
return temp_df
elif indicator == "中签号":
params.update(
{
"reportName": indicator_map[indicator],
"quoteColumns": "",
}
)
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame.from_dict(data_json["result"]["data"])
return temp_df
elif indicator == "筹资用途":
params.update(
{
"reportName": indicator_map[indicator],
"quoteColumns": "",
"sortColumns": "SORT",
"sortTypes": "1",
}
)
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame.from_dict(data_json["result"]["data"])
return temp_df
elif indicator == "重要日期":
params.update(
{
"reportName": indicator_map[indicator],
"quoteColumns": "",
}
)
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame.from_dict(data_json["result"]["data"])
return temp_df
else:
return pd.DataFrame()
def bond_zh_cov_value_analysis(symbol: str = "113527") -> pd.DataFrame:
"""
https://data.eastmoney.com/kzz/detail/113527.html
东方财富网-数据中心-新股数据-可转债数据-价值分析-溢价率分析
:param symbol: 可转债代码
:type symbol: str
:return: 可转债价值分析
:rtype: pandas.DataFrame
"""
url = "https://datacenter-web.eastmoney.com/api/data/get"
params = {
"sty": "ALL",
"token": "894050c76af8597a853f5b408b759f5d",
"st": "date",
"sr": "1",
"source": "WEB",
"type": "RPTA_WEB_KZZ_LS",
"filter": f'(zcode="{symbol}")',
"p": "1",
"ps": "8000",
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["result"]["data"])
temp_df.columns = [
"日期",
"-",
"-",
"转股价值",
"纯债价值",
"纯债溢价率",
"转股溢价率",
"收盘价",
"-",
"-",
"-",
"-",
"-",
]
temp_df = temp_df[
[
"日期",
"收盘价",
"纯债价值",
"转股价值",
"纯债溢价率",
"转股溢价率",
]
]
temp_df["收盘价"] = pd.to_numeric(temp_df["收盘价"], errors="coerce")
temp_df["纯债价值"] = pd.to_numeric(temp_df["纯债价值"], errors="coerce")
temp_df["转股价值"] = pd.to_numeric(temp_df["转股价值"], errors="coerce")
temp_df["纯债溢价率"] = pd.to_numeric(temp_df["纯债溢价率"], errors="coerce")
temp_df["转股溢价率"] = pd.to_numeric(temp_df["转股溢价率"], errors="coerce")
temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
return temp_df
if __name__ == "__main__":
bond_zh_hs_cov_min_df = bond_zh_hs_cov_min(
symbol="sz128039",
period="1",
adjust="hfq",
start_date="1979-09-01 09:32:00",
end_date="2222-01-01 09:32:00",
)
print(bond_zh_hs_cov_min_df)
bond_zh_hs_cov_pre_min_df = bond_zh_hs_cov_pre_min(symbol="sz128039")
print(bond_zh_hs_cov_pre_min_df)
bond_zh_hs_cov_daily_df = bond_zh_hs_cov_daily(symbol="sz128039")
print(bond_zh_hs_cov_daily_df)
bond_zh_hs_cov_spot_df = bond_zh_hs_cov_spot()
print(bond_zh_hs_cov_spot_df)
bond_zh_cov_df = bond_zh_cov()
print(bond_zh_cov_df)
bond_cov_comparison_df = bond_cov_comparison()
print(bond_cov_comparison_df)
bond_zh_cov_info_df = bond_zh_cov_info(symbol="123121", indicator="基本信息")
print(bond_zh_cov_info_df)
bond_zh_cov_value_analysis_df = bond_zh_cov_value_analysis(symbol="113527")
print(bond_zh_cov_value_analysis_df)
@@ -0,0 +1,151 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2024/6/18 18:30
Desc: 新浪财经-债券-沪深债券-实时行情数据和历史行情数据
https://vip.stock.finance.sina.com.cn/mkt/#hs_z
"""
import datetime
import re
import pandas as pd
import requests
import py_mini_racer
from akshare.bond.cons import (
zh_sina_bond_hs_count_url,
zh_sina_bond_hs_payload,
zh_sina_bond_hs_url,
zh_sina_bond_hs_hist_url,
)
from akshare.stock.cons import hk_js_decode
from akshare.utils import demjson
from akshare.utils.tqdm import get_tqdm
def get_zh_bond_hs_page_count() -> int:
"""
行情中心首页-债券-沪深债券的总页数
https://vip.stock.finance.sina.com.cn/mkt/#hs_z
:return: 总页数
:rtype: int
"""
params = {
"node": "hs_z",
}
res = requests.get(zh_sina_bond_hs_count_url, params=params)
page_count = int(re.findall(re.compile(r"\d+"), res.text)[0]) / 80
if isinstance(page_count, int):
return page_count
else:
return int(page_count) + 1
def bond_zh_hs_spot(start_page: str = "1", end_page: str = "10") -> pd.DataFrame:
"""
新浪财经-债券-沪深债券-实时行情数据, 大量抓取容易封IP
https://vip.stock.finance.sina.com.cn/mkt/#hs_z
:param start_page: 分页起始页
:type start_page: str
:param end_page: 分页结束页
:type end_page: str
:return: 所有沪深债券在当前时刻的实时行情数据
:rtype: pandas.DataFrame
"""
page_count = get_zh_bond_hs_page_count()
page_count = int(page_count)
zh_sina_bond_hs_payload_copy = zh_sina_bond_hs_payload.copy()
tqdm = get_tqdm()
big_df = pd.DataFrame()
start_page = int(start_page)
end_page = int(end_page) + 1 if int(end_page) + 1 <= page_count else page_count
for page in tqdm(range(start_page, end_page), leave=False):
zh_sina_bond_hs_payload_copy.update({"page": page})
r = requests.get(zh_sina_bond_hs_url, params=zh_sina_bond_hs_payload_copy)
data_json = demjson.decode(r.text)
temp_df = pd.DataFrame(data_json)
big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
big_df.columns = [
"代码",
"-",
"名称",
"最新价",
"涨跌额",
"涨跌幅",
"买入",
"卖出",
"昨收",
"今开",
"最高",
"最低",
"成交量",
"成交额",
"-",
"-",
"-",
"-",
"-",
"-",
]
big_df = big_df[
[
"代码",
"名称",
"最新价",
"涨跌额",
"涨跌幅",
"买入",
"卖出",
"昨收",
"今开",
"最高",
"最低",
"成交量",
"成交额",
]
]
big_df["买入"] = pd.to_numeric(big_df["买入"], errors="coerce")
big_df["卖出"] = pd.to_numeric(big_df["卖出"], errors="coerce")
big_df["昨收"] = pd.to_numeric(big_df["昨收"], errors="coerce")
big_df["今开"] = pd.to_numeric(big_df["今开"], errors="coerce")
big_df["最高"] = pd.to_numeric(big_df["最高"], errors="coerce")
big_df["最低"] = pd.to_numeric(big_df["最低"], errors="coerce")
big_df["最新价"] = pd.to_numeric(big_df["最新价"], errors="coerce")
return big_df
def bond_zh_hs_daily(symbol: str = "sh010107") -> pd.DataFrame:
"""
新浪财经-债券-沪深债券-历史行情数据, 大量抓取容易封 IP
https://vip.stock.finance.sina.com.cn/mkt/#hs_z
:param symbol: 沪深债券代码; e.g., sh010107
:type symbol: str
:return: 指定沪深债券代码的日 K 线数据
:rtype: pandas.DataFrame
"""
r = requests.get(
zh_sina_bond_hs_hist_url.format(
symbol, datetime.datetime.now().strftime("%Y_%m_%d")
)
)
js_code = py_mini_racer.MiniRacer()
js_code.eval(hk_js_decode)
dict_list = js_code.call(
"d", r.text.split("=")[1].split(";")[0].replace('"', "")
) # 执行 js 解密代码
data_df = pd.DataFrame(dict_list)
data_df["date"] = pd.to_datetime(data_df["date"], errors="coerce").dt.date
data_df["open"] = pd.to_numeric(data_df["open"], errors="coerce")
data_df["high"] = pd.to_numeric(data_df["high"], errors="coerce")
data_df["low"] = pd.to_numeric(data_df["low"], errors="coerce")
data_df["close"] = pd.to_numeric(data_df["close"], errors="coerce")
return data_df
if __name__ == "__main__":
bond_zh_hs_spot_df = bond_zh_hs_spot(start_page="1", end_page="5")
print(bond_zh_hs_spot_df)
bond_zh_hs_daily_df = bond_zh_hs_daily(symbol="sh010107")
print(bond_zh_hs_daily_df)
@@ -0,0 +1,408 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2026/4/10 10:21
Desc: 债券配置文件
"""
INDEX_MAPPING: dict[str, str] = {
"新综合指数": "8a8b2ca0332abed20134ea76d8885831",
"高等级科技创新债券综合指数": "4d4aa3607fb4ba663b4587de4a624b24",
"长江养老年金基金债券指数": "5846dca288299ac125539d6600c07853",
"中信证券挂钩DR浮动利率政策性银行债活跃券指数": "11c92fe0df3940c3ea172bfec5126593",
"股份制商业银行同业存单指数": "1398633fe32c4076f596530652d2f9bb",
"金融高质量发展主题信用债指数": "20e35c92ef7b9a439fcaa8fce5835ea5",
"交易所国债指数": "2c9081e50e8767dc010e87a4bdd20041",
"进出口行债券总指数": "8a8b2ca054ef4e4e0154f0c515eb0002",
"市场隐含评级AA信用债指数": "8a8b2cef6ab893c2016aba4c8ee7009f",
"房地产行业信用债指数": "8a8b2cef73b68e6a0173b92f5e1774c5",
"重庆市地方政府债指数": "8a8b2cef744be6d401744ebe4e6568c2",
"甘肃省地方政府债指数": "8a8b2cef74608045017461d9115400c8",
"公司信用类科技创新债券指数": "8641b0cb4c1f39c372dbcf5516b9c615",
"长三角绿色债券指数": "8a8b2c8364aa0bb20164abfd957f000f",
"企业债AA-指数": "8a8b2ca0406a93470140800885d20b7f",
"中国高等级债券指数": "8a8b2ca047bd1dfe0147d317b62e2158",
"中高等级公司信用类债券指数": "ef82cc4ba2540191dcdce19559153a3d",
"系统重要性银行债券指数": "928c2552e9b15d784f02b13b53392d53",
"红利现金流高等级股债金波动率控制1.5%指数": "b6b0f49ce87604657e97133968cb85bc",
"中高等级粤港澳大湾区绿色债券指数": "cc2b58ce2230e6097b7b32447406c783",
"投资级公司信用债综合指数": "4e808b033318be271f9b2063693a12ef",
"中高等级绿色金融债券指数": "562d8e2d9d331c99a7a9f9fefded6907",
"高等级科技创新债券指数": "0366fa8fafe2d1b12c62e4ffe11b97fe",
"北京农商银行中高信用等级农村商业银行金融债券指数": "185bb3883f838a1fdfe60e9ca37f4b43",
"货币市场基金可投资债券指数": "2c9081e918ad26f40118e90afbee66ae",
"高信用等级债券指数": "2c9081e91da03927011dcc4fae9f6171",
"非银金融行业信用债指数": "3396aaec56be7ba3378976c9387380f3",
"商业银行无固定期限资本债券市场隐含评级AA指数": "3d75e320abd5c3440ddd156de1ee622e",
"京津冀公司信用类债券指数": "8a8b2cef6d4bc1c2016d4ca23ef4251b",
"京津冀债券综合指数": "8a8b2cef6d4bc1c2016d4caa15e8254a",
"工行关键期限国债指数": "8a8b2cef6e1ee681016e200a8aa50400",
"广东省地方政府债指数": "8a8b2cef7109a09c01710c14d2a74415",
"厦门市地方政府债指数": "8a8b2cef732135fd017322a8e7c80113",
"商业银行无固定期限资本债券AAA指数": "6b12c39d52c331dd5e3d1aabc4d9b5a6",
"粤港澳大湾区绿色债券综合指数": "7fd4e2eda73794d409e592448adb8c25",
"中高等级科技创新绿色普惠主题信用债指数": "865e39d03b6fd073781dbf1477a6cca1",
"红利自由现金流低波股债恒定比例10/90指数": "8961444e141891490cba185d6b59cba2",
"高信用等级企业债指数": "8a8b2ca03e4dd765013e6312d6462a1b",
"农行乡村振兴债券指数": "e8df331cfd44e54f338bf2811716c6da",
"城市商业银行及农村商业银行同业存单AAA指数": "8b8f70506d65f4675233a32c903ad552",
"股债恒定组合10/90指数": "978a5b988dfe640d0d083981803d0675",
"国信证券深圳市国有企业信用债精选指数": "9d895a4e2d56d6829590a5eb3ccf285d",
"商业银行无固定期限资本债券指数": "a096ce5c63c2a1df2240b876c868c3ed",
"银行间碳中和债券指数": "ac478f286376cf14bf6cbc68ca0aa284",
"中高等级信用债综合指数": "b10fd010c80946bf881ca39dca62e49a",
"贵阳银行西部高质量发展信用债精选指数": "c1dc7e964c26475afa239b00594b8275",
"投资优选国际信用评级投资级活跃信用债指数": "d20fbfd3ed04a7261a0572967ffc06c3",
"红利现金流高等级股债金波动率控制1%指数": "188b64de57c782a3b8a9359ff08f113d",
"东方证券科技创新信用债精选指数": "2adeb5d8aa35cbcb0ea4a05614a75a08",
"进出口行新发关键期限债券指数": "2e8da3759b4f83e0f0752147738f7fc9",
"商业银行二级资本债券AAA指数": "3f6da52f1d57886271979d928af5a203",
"粤港澳大湾区信用债指数": "8a8b2cef74b8f0c10174bac93afe436a",
"投资优选信用债指数": "8a8b2cef771ce12601771df60d924fdb",
"科技创新绿色普惠主题信用债指数": "6b227923cd44064bbf239a69f70f09ae",
"中国高等级债券指数(美元)": "8a8b2c8f581cfb2f01581db3fd830001",
"信用债总指数": "8a8b2ca038d716f10138dadde8416adc",
"高等级科技创新及绿色债券指数": "f1df5dcfb61be8a2fbcbc119db98b149",
"中邮理财高等级绿色债券精选指数": "f22aea49f4b11a53bd787b013253d5be",
"平安人寿ESG整合策略信用债指数": "f711877ede9c7aa67bfe326721c2137e",
"战略性新兴产业信用债指数": "f72725181b56144d3f9b55f1b6e60102",
"商业银行债券AAA指数": "9883fcadeac6d8c22204f0c749e4cf08",
"AAA评级债券综合指数": "b017c9c53c7ad6586b3446129c152616",
"高等级黄河流域绿色债券指数": "bfbeeed1994639dcd0e0b94fda306b56",
"高等级公司信用类债券综合指数": "c9a7185542022826b09dcc2ab72be8b1",
"中信证券高等级同业存单指数": "0857793c945697daf6a9873ff42825f4",
"浦银理财新质生产力发展债券指数": "103c0fdb82c06b6b9d7ec09f28b8b615",
"银行间国债指数": "2c9081e50e8767dc010e87b559ee0078",
"交易所高等级科技创新债券指数": "44a33e0c99dffbce14774eb52415a5b0",
"银行间资产支持证券指数": "8a8b2ca055eba5e10155ed6ebc530895",
"中国气候相关债券指数": "8a8b2ca056b9a4450156bb2be8df0002",
"招商银行优选信用债指数": "8a8b2cef6dd6cd77016dd88a7e7d002c",
"福建省地方政府债指数": "8a8b2cef732135fd017322145858008e",
"市场隐含评级AA+及以上信用债指数": "8a8b2cef734f8f3701735061131b014a",
"青海省地方政府债指数": "8a8b2cef74608045017461f9e203012a",
"红利自由现金流低波股债恒定比例25/75指数": "6bae070303eed9cf867fd5011a0e47bb",
"投资优选信用债分散指数": "6dd638194bb5a5f2de90bd7133192953",
"高信用等级城市商业银行及农村商业银行债券指数": "81303c95d362b50182547f7385469b7b",
"金融机构二级资本债券总指数": "8a8b2c8368edcfd70168f08992c6153a",
"新中期票据总指数": "8a8b2ca0375f977f0138c2c322474b06",
"高收益中期票据指数": "8a8b2ca03e29cab5013e3a180e064537",
"商业银行二级资本债券指数": "b379a2dacd92d19ca805021c0d336ee8",
"高信用等级商业银行无固定期限及二级资本债券指数": "ca7f4de2681f726e0d1268fd6f646788",
"银行间科技创新债券指数": "4bde3b669a49e81e8de90e8df7687128",
"金融行业信用债指数": "594b0c6f18d6dd3c6af0830d784058fa",
"高等级科技创新债券行业精选指数": "1287a4c6c7bce84cbe9eab904468b9d5",
"固定利率债券指数": "2c9081e50e8767dc010e87954b780011",
"中信证券挂钩LPR浮动利率政策性银行债活跃券指数": "430f1876233c711f505500edce079236",
"广西壮族自治区公司信用类债券指数": "8a8b2cef6b00accd016b022cffbb0009",
"长三角债券综合指数": "8a8b2cef6b29dfac016b2bc115460040",
"个人住房抵押贷款资产支持证券指数": "8a8b2cef6b96053a016b982c95e7001f",
"青岛市地方政府债指数": "8a8b2cef7307763001730a5c824524ce",
"煤炭行业信用债指数": "8a8b2cef73bbb4c60173bc59a0c90006",
"安徽省公司信用类债券指数": "8a8b2c8367bdf89e0167c05355f201fb",
"企业债AA+指数": "8a8b2ca0408e9fa701409edf078f26c0",
"挂钩DR浮动利率政策性银行债指数": "db78a8ddda8a6ac88bc193055906740a",
"红利自由现金流低波股债恒定比例20/80指数": "e638c5f176c772ddaf59e947af2d052e",
"金融机构科技创新债券指数": "ecac759d61e1c09314d6f2577c20ce6c",
"中豫信增河南省信用债指数": "f7948f9be0732d45e18f1d5c8190757f",
"红利现金流中高等级股债金波动率控制1%指数": "8a9ab2cac146e25febba515cfa08d8cc",
"电力行业优质转型企业信用债指数": "947d07b68357a6e40c93bf839efc2187",
"工行熊猫债30指数": "9eee3a194d1f035ce0cf4307a5b9b69f",
"申万宏源ESG绿色信用债精选指数": "a3dc0ed6ba8ab442783109d769baed5e",
"天府信用增进公司增信债券指数": "aa0b6304e290a57bcda90e1358e13de9",
"京津冀绿色债券综合指数": "d0df76dc4485ecd520c870d81703645c",
"高等级科技创新绿色普惠主题信用债指数": "61c04cb52c2decb1cbba80292ab46ccd",
"高信用等级数字经济产业信用债指数": "373e09025763c56cf01201234a794658",
"中银理财高等级乡村振兴债券指数": "398f40c1c8dd2081f6e1ee478b768dbb",
"国有大型商业银行及股份制商业银行债券指数": "469f1601d2b76750b82945b145e90992",
"民营企业公司信用类债券指数": "8a8b2cef6b4dec2d016b4ebb4ec36c3f",
"湖南省地方政府债指数": "8a8b2cef7132d3800171333ba262010c",
"贵州省地方政府债指数": "8a8b2cef730c9c8f01730e79bade0185",
"新疆维吾尔自治区(新疆生产建设兵团)地方政府债指数": "8a8b2cef7465a6a201746603d1a1005d",
"国寿资产ESG信用债精选指数": "8a8b2cef7a11e7fc017a13fe7446002a",
"中邮理财高等级科技创新债券精选指数": "773ade3d59c36dc1e13146c1866a8ccb",
"平安理财ESG优选绿色债券指数": "89019c1cbbe64a34698165eecc7e7417",
"中高等级公司债利差因子指数": "8a8b2c836393f4480163950643d92795",
"长三角公司信用类债券指数": "8a8b2c83649fbee90164a24dbbc00013",
"中信证券精选高等级资产支持证券指数": "8a8b2c83689643bc0168985a433e000e",
"交易所科技创新债券指数": "963fc157a1f34898dd4071a355ea13bd",
"中银理财高信用等级同业存单指数": "987527eff930a4986a5044a80cadae9e",
"中银绿色债券指数": "abea1402e6dd628d02118bca571783cb",
"国有大型商业银行同业存单指数": "af109288145de0c9a36332a4fb3d06c1",
"中高等级长江经济带绿色债券指数": "d3c82122ac871f08eb5bf877065e5377",
"AAA信用债综合指数": "05d235f4268241c25e36b27e13b13023",
"红利自由现金流低波股债金恒定比例指数": "0ff243f048cbd219f59fb92ab8ae4941",
"申万宏源中小微企业主题优选信用债指数": "1997fbc5e0a91db36e53c4540ae51cdd",
"企业债总指数": "2c90818811d3f4fa01123837e6b30d4a",
"商业银行债券指数": "2c9081e918ad26f401195c3a76a7210f",
"公司债总指数": "8a8b2ca050d9e35d0150da6758462c78",
"长江经济带债券综合指数": "8a8b2cef709854b501709a027fe4002f",
"信用债价值因子权重调整策略指数": "8a8b2cef7422b3f30174234f30fd0005",
"黑龙江省地方政府债指数": "8a8b2cef7456338c017457a55ccc07cc",
"碳中和绿色债券指数": "8a8b2cef7823857e01782469e9210080",
"投资优选政策性金融债指数": "8a8b2cef7a404137017a424e54cb7859",
"中金公司乡村振兴信用债精选指数": "8a8b2cef7a4fb448017a515401a53fc4",
"高等级公司信用类债券指数": "6fb584528c4d4aad6194d5a39a3b93a1",
"京津冀科技创新债券指数": "74bdb50a9cbf9a45903346968a951bd3",
"渤海银行新质生产力主题科技创新债券指数": "81a92ec45e9d90aa8961e9ac278fc435",
"长三角地方政府债指数": "8a8b2c836303c237016304feb2160006",
"AAA科技创新债券指数": "dff644648a8a007efd6a5b94970c0b89",
"投资级中资美元债指数": "8a962d8c69c31e1e016a0f26a9c0010a",
"成渝地区双城经济圈国有企业信用债精选指数": "03ffb378810766ab90ec7e959fadc3c0",
"投资优选活跃信用债指数": "103a161c9927a9ae41e38f0887bbd33e",
"北银理财绿色发展风险平价指数": "2c666b22d481c7eadb52992baa62591c",
"中高等级科技创新债券综合指数": "3b02fa47414f502add64f1e77e9e67b7",
"个人住房抵押贷款资产支持证券精选指数": "3b824a1426bea356799ca15d730ad6d1",
"红利自由现金流低波股债金恒定比例10/85/5指数": "48643ba4f9bd31f07ec8efdc44ebf761",
"高信用等级同业存单指数": "48fc8dfb472c5498c6612cd5151647d8",
"中国绿色债券精选指数": "8a8b2ca053fd435d0153fefc94100001",
"长三角中高等级信用债指数": "8a8b2cef6b4dec2d016b4fc04e286e57",
"江西省地方政府债指数": "8a8b2cef732135fd017321b8405e0005",
"江苏省地方政府债指数": "8a8b2c8368a5b6da0168a6bd29e80017",
"中信证券国债及地方政府债精选指数": "8a8b2c83694a824d01694c5d53d6000a",
"国债及政策性银行债指数": "8a8b2c8f5a62e9ca015a645fe3b60001",
"高信用等级公司信用类债券综合指数": "8a8b2ca038f905c70139b9b3ab9660bb",
"银行间高等级科技创新债券指数": "e4498669d5496afed08bdf7ff8695681",
"公路行业信用债指数": "e65b5cdf6e3e04c7892bdfd1ccc1e2dc",
"投资优选国际信用评级投资级信用债分散指数": "f5517678561c457f03b6d74c06440a3d",
"高信用等级农村商业银行债券优选指数": "f8cbf35f3095aa44006f7fc7c506176d",
"科技创新债券指数": "a485ef64ce0ae0f1f5cc088671e87d8f",
"科技创新债券综合指数": "afb3fe2d59b5165a0175bac95b8c3da0",
"高等级信用债指数": "d04f2fb3e1012c78b8acdecf2c93979f",
"中高等级公司信用类债券综合指数": "5911892524d8b384666a88d75200c9df",
"中高等级京津冀绿色债券指数": "00474c7a00eb73ca32a23a6861b4a418",
"城市商业银行及农村商业银行债券AAA指数": "13fe6e5cd6a84a3038b8a5d46c7a38cb",
"浦发银行绿色低碳股债优选指数": "2bdda0eb4cac30c07217f95a25a7a85f",
"金融债券总指数": "2c9081e50e8767dc010e87a9d5650060",
"离岸人民币中国主权及政策性金融债指数": "8a8b2cef6dcc80c0016dcf2444650bb7",
"安徽省地方政府债指数": "8a8b2cef7311c2e7017312b23a650130",
"AA国有企业信用债优选指数": "6b0d067864ff1675e96f3c49652fb73e",
"中高等级信用债指数": "6cdea6720316fd5d69494b4bc0f8129c",
"工行熊猫债AAA指数": "738751b4c9e76c9b7701fb0c201b70f1",
"国有大型商业银行及股份制商业银行同业存单指数": "78598fc1ac4a8f2d327577e0481b065c",
"黄金保值国开行债券风险平价指数": "806f9278922270298ee3e12c6d624ee5",
"交行长三角ESG优选信用债指数": "ebd9f5ac057709c3fe5a375773e0c62d",
"中信证券ESG优选信用债指数": "ece99ed16ea8c4c9d59befed1175f823",
"数字经济产业信用债指数": "fa87c88adac6b304de5654c29b1569e1",
"投资级公司信用债精选指数": "8d397b018e0ce97d58dedc3ef41ddf36",
"中信证券久期轮动政策性金融债指数": "9c6218292a77139d38f12ac6ef85d138",
"红利自由现金流低波股债恒定比例30/70指数": "d33a29eb4d1e1111af1e4b7097cca597",
"高等级信用债综合指数": "5b78d41604e06e90b720144a6a956c67",
"投资级公司科技创新债券精选指数": "0572b7d527231c98e4fc0de8abe2c7c2",
"交易所信用债AAA指数": "05f743ba6a11b907de8307b89c4fc618",
"高信用等级城市商业银行及农村商业银行同业存单指数": "0bb01422038bb4086e8baa8f648574e8",
"高信用等级商业银行债券指数": "1a985201e4c5ceecdde9610e43a0fd35",
"投资优选科技创新债券指数": "2ac380e3d3d941de8351f1fff8e6bda5",
"固定利率金融债指数": "2c9081e50e8767dc010e87ad08140068",
"银行间高等级碳中和债券指数": "37a60515edb02fe8dab961d9c7035a95",
"同业存单AA+指数": "429c1ff7661c2abacdbcb5718a3cb5f6",
"平安-可投资级信用债指数": "8a8b2ca0515fc8a60151618b84483c9a",
"农发行债券总指数": "8a8b2ca0540790160154091b513d370e",
"浙江省地方政府债指数": "8a8b2cef7109a09c01710c1c2d04478e",
"上海市地方政府债指数": "8a8b2cef7408f4280174096a89a04112",
"陕西省地方政府债指数": "8a8b2cef74510d2f01745168e5670004",
"资产支持证券指数": "8a8b2cef74510d2f0174529d5a9f35b4",
"吉林省地方政府债指数": "8a8b2cef74608045017461ccceff0073",
"海南省地方政府债指数": "8a8b2cef74608045017461fe1768015f",
"ESG优选信用债指数": "8a8b2cef75860ac0017587c644a02fde",
"中金公司绿色资产支持证券指数": "8a8b2cef783d454901783f2c468307ec",
"市场隐含评级AA+信用债指数": "8a8b2c836775df980167784a77520d4b",
"同业存单总指数": "8a8b2c8f611af5db01611cb3586c00f0",
"公司信用类债券指数": "8a8b2ca03a59370a013a676d717923da",
"高收益企业债指数": "8a8b2ca03e88932b013e88b9d6290001",
"企业债AAA指数": "8a8b2ca0408e9fa7014094a20f21001f",
"AAA公司信用类债券综合指数": "e6b1e2fc01692f8fcd22ba50e501231a",
"AAA公司信用类债券指数": "96377056fc894287b4a76ceebaca2808",
"投资优选绿色债券指数": "984c68bfc0b9263aaad7bd9af36888a3",
"系统重要性银行同业存单指数": "a08e1c9454a616491f5bf6431f2591b0",
"投资级主题绿色债券优选指数": "be73e8263fc20359521707abd6db45b3",
"高等级央企信用债精选指数": "cbfd21590b4805df8df7d9de222f8f7d",
"红利现金流中高等级股债波动率控制1.5%指数": "d31602c38de87265603df05d6cf9dd59",
"中高等级科技创新及绿色债券指数": "5ec55de5ac980c543c2d9bf25d6e423b",
"金融高质量发展主题债券综合指数": "60bb107af9b99b8fb7c6a28ef4b171da",
"商业银行无固定期限及二级资本债券指数": "0b96ff2a2948a75625e2319b49446633",
"国开行债券总指数": "2c908188111fac07011125068f91044d",
"综合指数": "2c90818811afed8d0111c0c672b31578",
"固定利率企业债指数": "2c9081e918ad26f40118adb5d6910004",
"中期票据总指数": "2c9081e91ebc9e41011ec8c7c0440001",
"黄金保值债券风险平价指数": "3b9c19a3dd638fd2672c0728fce892a0",
"广西壮族自治区地方政府债指数": "8a8b2cef7311c2e7017313a860bb03dc",
"新疆维吾尔自治区地方政府债指数": "8a8b2cef74510d2f017453365ea0367c",
"天津市地方政府债指数": "8a8b2cef7456338c017458e2e0da3e33",
"投资优选综合指数": "8a8b2cef7682625f0176835c7a840070",
"绿色债券综合指数": "85f86947411dd367018d7f8fde1dc295",
"市场隐含评级AAA信用债指数": "8a8b2c836775df980167785153790d6b",
"中国铁路债券指数": "8a8b2c8f5bea4d1b015bebe640530038",
"企业债AA指数": "8a8b2ca0408e9fa70140949f012d0002",
"地方政府债指数": "8a8b2ca0447ffe14014486b77f2a0002",
"国泰海通陕川渝国企信用增强债券精选指数": "de861828ae11bc5f498a330c650fdf5a",
"银行间高等级绿色债券指数": "9fa9718155dceab39e5149af665f68a7",
"红利现金流高等级股债波动率控制1.5%指数": "a7f952e6f6ad14b1c66f5f950ed476de",
"红利自由现金流低波股债恒定比例5/95指数": "c3bb7afced9999ce291380c0fc4dbca5",
"绿色普惠主题金融债券优选指数": "d69df7413ed6e76fa5b9b20ba9e7c0ec",
"建筑工程行业信用债指数": "0af700ba10feefc9a5191983eaadfc51",
"长三角绿色债券综合指数": "2551cfa3eea577a3ca71d51bceca6f8f",
"银行间债券总指数": "2c9081e50e8767dc010e87a3326c0039",
"交易所AAA科技创新债券指数": "2d90f08c90b2e886bf6f6df549af950c",
"AAA信用债指数": "3a2e8c74d7265e3e9aedfd8d1681836b",
"银行间市场信用债AAA指数": "3c94ebab97ab6edf12ca14e452977115",
"共同富裕主题债券指数": "430a7631f7ea66036a91f37e8b4b1c9c",
"中国绿色债券指数": "8a8b2ca054079016015408674cce0017",
"优选投资级信用债指数": "8a8b2cef771294700177144288381a6c",
"投资优选地方政府债指数": "8a8b2cef7a404137017a4245018a7011",
"湖北省地方政府债指数": "8a8b2c8368e383220168e4bae68500c9",
"兴业绿色债券指数": "8a8b2c8f57df2edc0157e1163014176e",
"银行普通债券AAA指数": "e36b9dc1620a0dc7ee027cca1663c526",
"中期票据AAA指数": "9ced53d3f93b8cb9509a80d294086876",
"黄金保值信用债风险平价指数": "b099abb287eebad09994ab481fe67f24",
"浦发银行ESG精选债券指数": "6357eef4131197707f812ea9a7530a53",
"北银理财京津冀企业高质量发展多元投资指数": "25895ebd4694c235a33aa9d360b04764",
"固定利率国债指数": "2c9081e50e8767dc010e87a6a60b0050",
"浮动利率金融债指数": "2c9081e50e8767dc010e87b3b1d60070",
"AAA公司信用类科技创新债券指数": "3279a06da6f3a8e8a6429d32b0917cb7",
"云南省地方政府债指数": "8a8b2cef7132d3800171330128ec0002",
"辽宁省地方政府债指数": "8a8b2cef73265c58017326e66e310005",
"长江经济带绿色债券综合指数": "7ebdf1292c65a1bcfcdab7546919312c",
"关键期限国债指数": "8a8b2ca04b1e4a5b014b2a23197c72c5",
"红利现金流中高等级股债波动率控制1%指数": "982441730a41cb3f45cf58bf0a21f2ee",
"北京银行高信用等级城市商业银行债券指数": "b9a6d06e9b6458c9062f08a1dc75fd30",
"中信证券个人汽车抵押贷款资产支持证券指数": "5cb7d4be4facd5353ac243620ebf2bde",
"中高等级长三角绿色债券指数": "1432826c10c29fdd3b75258378e45aa1",
"天风国际ESG优选中资美元债指数": "2d3ac1a7ccda4e7aadc605e2b1ca0c9b",
"工行绿色债券指数": "31d4a4934ca82e11892f6bbb9be0ea04",
"红利现金流中高等级股债金波动率控制1.5%指数": "47a631e45ce8b99708de3ecd775b64b7",
"京津冀绿色债券指数": "8a8b2cef6db2c0f4016db432c17f0667",
"河南省地方政府债指数": "8a8b2cef730c9c8f01730d1816ce0066",
"内蒙古自治区地方政府债指数": "8a8b2cef7311c2e701731364881d032a",
"制造行业信用债指数": "8a8b2cef73c6017e0173c882dd1c7801",
"粤港澳大湾区绿色债券指数": "8a8b2cef747519b5017476a72ce653a2",
"科技创新及绿色债券指数": "7dc84c0f21a71b97931fd7abadc78433",
"投资级公司绿色债券精选指数": "80e6aa811418a5b9ac810c93ac381fed",
"市场隐含评级AAA+信用债指数": "8a8b2c836775df9801677851e4360d74",
"高等级公司信用类科技创新债券指数": "eba5e43f73c9d877657d88d3e00ad90c",
"银行间绿色债券指数": "9da7e47f35b11c98cced95e4fb71b596",
"高等级战略性新兴产业信用债指数": "adf7158832226e8e7361b78d0f5e4798",
"红利自由现金流低波股债恒定比例15/85指数": "d0203aedec448bec95845ba349cc9e78",
"电力行业信用债指数": "5cc7a4278c0c1cc0f82dc018c3c15fd1",
"科技创新绿色普惠主题债券综合指数": "5e21777b1e179d595ebd9a78a6b89bf7",
"中高等级战略性新兴产业信用债指数": "05b2d2e9b40a7f2324774c0b32f8cd70",
"浮动利率债券指数": "2c9081e50e8767dc010e8797a5d70019",
"京津冀地方政府债指数": "8a8b2cef6d4bc1c2016d4c96069c24fb",
"宁波市地方政府债指数": "8a8b2cef73077630017307dc4339007c",
"钢铁行业信用债指数": "8a8b2cef73c0db220173c140495c0058",
"北京市地方政府债指数": "8a8b2cef7456338c017456818eba000a",
"山西省地方政府债指数": "8a8b2cef746080450174619484ea000c",
"宁夏回族自治区地方政府债指数": "8a8b2cef7460804501746219b518020a",
"西藏自治区地方政府债指数": "8a8b2cef7465a6a2017465f9dc55000a",
"投资优选国债指数": "8a8b2cef7a35f47f017a37c76654232d",
"挂钩LPR浮动利率政策性银行债指数": "678165887609e2cb84fa87251c33fc08",
"银行金融债券AAA指数": "81d917dad85d7ce95f51bc644484e1ff",
"市场隐含评级AAA-信用债指数": "8a8b2c836775df980167785085850d62",
"国有大型商业银行及股份制商业银行二级资本债券指数": "8a8b2c8367f69e950167f7b549f00005",
"高信用等级中期票据指数": "8a8b2ca03d393e7c013d39c667963351",
"高信用等级银行金融债券指数": "f187fd9f8ee0d88f9a59323d6a709e34",
"同业存单AAA指数": "b15ef8073f38d8962cd7728a857f5cc8",
"中高等级科技创新债券指数": "b7c74a6569cb5a38d7f1ab3ed20ca62b",
"商业银行二级资本债券市场隐含评级AA指数": "c511c7a1a872fb2ca258474e95a45ab8",
"高等级绿色公司信用类债券指数": "d8fbee7a51ae5901ea48aa7948bda83f",
"银行间AAA科技创新债券指数": "571d2417bcf35b5dc808f3c480349090",
"黄河流域绿色债券综合指数": "608e6e23ec091fdc8c879481ac979b19",
"国债总指数": "2c9081e50e8767dc010e879acb220021",
"长江经济带地方政府债指数": "8a8b2cef709d7b1201709f29b09f0084",
"山东省地方政府债指数": "8a8b2cef70eaba740170ed2c79b44c04",
"四川省地方政府债指数": "8a8b2cef7109a09c01710c04f8bb41fd",
"深圳市地方政府债指数": "8a8b2cef7224de5f0172265a948a0089",
"河北省地方政府债指数": "8a8b2cef730c9c8f01730d8ca18b00ee",
"大连市地方政府债指数": "8a8b2cef73265c580173273fe9e2008d",
"信用债价值因子精选策略指数": "8a8b2cef73a1f4f80173a2c0b2a4000e",
"粤港澳大湾区债券综合指数": "8a8b2cef74adbfab0174afbea5434943",
"利差驱动股债稳健指数": "890fcfb97ea76876563dfc1771652a22",
"中债信用增进公司增信债券指数": "8a8b2ca03de1b1db013de91f3a6f2aee",
"银行金融债券指数": "eae41b72f13a22c9b24a0a5887789000",
"乡村振兴债券综合指数": "cec6a61bd8827e306fcba8f195a4903f",
}
INDICATOR_MAPPING = {
"全价": "QJZS",
"净价": "JJZS",
"财富": "CFZS",
"平均市值法久期": "PJSZFJQ",
"平均现金流法久期": "PJXJLFJQ",
"平均市值法凸性": "PJSZFTX",
"平均现金流法凸性": "PJXJLFTX",
"平均现金流法到期收益率": "PJDQSYL",
"平均市值法到期收益率": "PJSZFDQSYL",
"平均基点价值": "PJJDJZ",
"平均待偿期": "PJDCQ",
"平均派息率": "PJPXL",
"指数上日总市值": "ZSZSZ",
"财富指数涨跌幅": "CFZSZDF",
"全价指数涨跌幅": "QJZSZDF",
"净价指数涨跌幅": "JJZSZDF",
"现券结算量": "XQJSL",
}
PERIOD_MAPPING = {
"总值": "00",
"1年以下": "01",
"1-3年": "02",
"3-5年": "03",
"5-7年": "04",
"7-10年": "05",
"10年以上": "06",
"0-3个月": "07",
"3-6个月": "08",
"6-9个月": "09",
"9-12个月": "10",
"0-6个月": "11",
"6-12个月": "12",
}
# bond-cov-sina
zh_sina_bond_hs_cov_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeDataSimple"
zh_sina_bond_hs_cov_count_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeStockCountSimple"
zh_sina_bond_hs_cov_hist_url = (
"https://finance.sina.com.cn/realstock/company/{}/hisdata/klc_kl.js?d={}"
)
zh_sina_bond_hs_cov_payload = {
"page": "1",
"num": "80",
"sort": "symbol",
"asc": "1",
"node": "hskzz_z",
"_s_r_a": "page",
}
# bond-sina
zh_sina_bond_hs_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData"
zh_sina_bond_hs_count_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeStockCountSimple"
zh_sina_bond_hs_hist_url = (
"https://finance.sina.com.cn/realstock/company/{}/hisdata/klc_kl.js?d={}"
)
zh_sina_bond_hs_payload = {
"page": "1",
"num": "80",
"sort": "symbol",
"asc": "1",
"node": "hs_z",
"_s_r_a": "page",
}
# headers
SHORT_HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
}
# quote
MARKET_QUOTE_URL = "http://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbMktMakQuot?flag=1&lang=cn&abdAssetEncdShrtDesc=&emaEntyEncdShrtDesc="
MARKET_QUOTE_PAYLOAD = {
"flag": "1",
"lang": "cn",
"abdAssetEncdShrtDesc": "",
"emaEntyEncdShrtDesc": "",
}
# trade
MARKET_TRADE_URL = (
"http://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbtPri?lang=cn&flag=1&bondName="
)
MARKET_TRADE_PAYLOAD = {"lang": "cn", "flag": "1", "bondName": ""}