| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- # -*- 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 ak.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_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"])
- if temp_df.empty:
- return temp_df
- 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
- if __name__ == "__main__":
- bond_cov_issue_cninfo_df = bond_cov_issue_cninfo(
- start_date="20250101", end_date="20250131"
- )
- print(bond_cov_issue_cninfo_df)
|