Skip to content

Commit

Permalink
Date (#4035)
Browse files Browse the repository at this point in the history
* add version

* add symbol

* add symbol

* fix get_cffex_rank_table

* fix futures_spot_price

* update date
  • Loading branch information
albertandking authored Aug 8, 2023
1 parent c5e9c0f commit 9b58967
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 82 deletions.
3 changes: 2 additions & 1 deletion akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2492,9 +2492,10 @@
1.10.75 add: add macro_china_urban_unemployment interface
1.10.76 fix: fix stock_notice_report interface
1.10.77 add: add bond_cb_profile_sina interface
1.10.78 fix: fix get_cffex_rank_table interface
"""

__version__ = "1.10.77"
__version__ = "1.10.78"
__author__ = "AKFamily"

import sys
Expand Down
49 changes: 20 additions & 29 deletions akshare/futures/cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
}

# zh_sina_spot
zh_subscribe_exchange_symbol_url = "http://vip.stock.finance.sina.com.cn/quotes_service/view/js/qihuohangqing.js"
zh_subscribe_exchange_symbol_url = (
"http://vip.stock.finance.sina.com.cn/quotes_service/view/js/qihuohangqing.js"
)
zh_match_main_contract_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQFuturesData"
zh_match_main_contract_payload = {
"page": "1",
Expand Down Expand Up @@ -91,21 +93,17 @@
QHKC_INDEX_PROFIT_LOSS_URL = "https://qhkch.com/ajax/indexes_profit_loss.php"
QHKC_FUND_BS_URL = "https://qhkch.com/ajax/fund_bs_pie.php"
QHKC_FUND_POSITION_URL = "https://qhkch.com/ajax/fund_position_pie.php"
QHKC_FUND_POSITION_CHANGE_URL = (
"https://qhkch.com/ajax/fund_position_chge_pie.php"
)
QHKC_FUND_POSITION_CHANGE_URL = "https://qhkch.com/ajax/fund_position_chge_pie.php"
QHKC_FUND_DEAL_URL = "https://qhkch.com/ajax/fund_deal_pie.php"
QHKC_FUND_BIG_CHANGE_URL = "https://qhkch.com/ajax/fund_big_chge.php"
QHKC_TOOL_FOREIGN_URL = "https://qhkch.com/ajax/toolbox_foreign.php"
QHKC_TOOL_GDP_URL = "https://qhkch.com/dist/views/toolbox/gdp.html?v=1.10.7.1"

BOND_BANK_URL = (
"http://zhuce.nafmii.org.cn/fans/publicQuery/releFileProjDataGrid"
)
BOND_BANK_URL = "http://zhuce.nafmii.org.cn/fans/publicQuery/releFileProjDataGrid"

# 键值对: 键为交易所代码, 值为具体合约代码
market_exchange_symbols = {
"cffex": ["IF", "IC", "IM", "IH", "T", "TF", "TS"],
"cffex": ["IF", "IC", "IM", "IH", "T", "TF", "TS", "TL"],
"dce": [
"C",
"CS",
Expand Down Expand Up @@ -185,8 +183,9 @@
"LU",
"BC",
"AO",
"BR",
],
"gfex": ["SI"],
"gfex": ["SI", "LC"],
}

contract_symbols = []
Expand Down Expand Up @@ -241,32 +240,28 @@
SYS_SPOT_PRICE_LATEST_URL = "http://www.100ppi.com/sf/"

SHFE_VOL_RANK_URL = "http://www.shfe.com.cn/data/dailydata/kx/pm%s.dat"
CFFEX_VOL_RANK_URL = "http://www.cffex.com.cn/fzjy/ccpm/%s/%s/%s_1.csv"
CFFEX_VOL_RANK_URL = "http://www.cffex.com.cn/sj/ccpm/%s/%s/%s_1.csv"
DCE_VOL_RANK_URL_1 = "http://www.dce.com.cn/publicweb/quotesdata/exportMemberDealPosiQuotesData.html?memberDealPosiQuotes.variety=%s&memberDealPosiQuotes.trade_type=0&contract.contract_id=%s&contract.variety_id=%s&year=%s&month=%s&day=%s&exportFlag=txt"
DCE_VOL_RANK_URL_2 = "http://www.dce.com.cn/publicweb/quotesdata/memberDealPosiQuotes.html?memberDealPosiQuotes.variety=%s&memberDealPosiQuotes.trade_type=0&contract.contract_id=all&contract.variety_id=%s&year=%s&month=%s&day=%s"
CZCE_VOL_RANK_URL_1 = "http://www.czce.com.cn/cn/exchange/jyxx/pm/pm%s.html"
CZCE_VOL_RANK_URL_2 = (
"http://www.czce.com.cn/cn/exchange/%s/datatradeholding/%s.htm"
CZCE_VOL_RANK_URL_2 = "http://www.czce.com.cn/cn/exchange/%s/datatradeholding/%s.htm"
CZCE_VOL_RANK_URL_3 = (
"http://www.czce.com.cn/cn/DFSStaticFiles/Future/%s/%s/FutureDataHolding.htm"
)
CZCE_VOL_RANK_URL_3 = "http://www.czce.com.cn/cn/DFSStaticFiles/Future/%s/%s/FutureDataHolding.htm"

DCE_RECEIPT_URL = (
"http://www.dce.com.cn/publicweb/quotesdata/wbillWeeklyQuotes.html"
)
DCE_RECEIPT_URL = "http://www.dce.com.cn/publicweb/quotesdata/wbillWeeklyQuotes.html"

SHFE_RECEIPT_URL_1 = "http://www.shfe.com.cn/data/dailydata/%sdailystock.html"
SHFE_RECEIPT_URL_2 = "http://www.shfe.com.cn/data/dailydata/%sdailystock.dat"
CZCE_RECEIPT_URL_1 = (
"http://www.czce.com.cn/cn/exchange/jyxx/sheet/sheet%s.html"
)
CZCE_RECEIPT_URL_1 = "http://www.czce.com.cn/cn/exchange/jyxx/sheet/sheet%s.html"
CZCE_RECEIPT_URL_2 = "http://www.czce.com.cn/cn/exchange/%s/datawhsheet/%s.htm"
CZCE_RECEIPT_URL_3 = "http://www.czce.com.cn/cn/DFSStaticFiles/Future/%s/%s/FutureDataWhsheet.htm"
CZCE_RECEIPT_URL_3 = (
"http://www.czce.com.cn/cn/DFSStaticFiles/Future/%s/%s/FutureDataWhsheet.htm"
)

CFFEX_DAILY_URL = "http://www.cffex.com.cn/fzjy/mrhq/{}/{}/{}_1.csv"
SHFE_DAILY_URL = "http://www.shfe.com.cn/data/dailydata/kx/kx%s.dat"
SHFE_V_WAP_URL = (
"http://www.shfe.com.cn/data/dailydata/ck/%sdailyTimePrice.dat"
)
SHFE_V_WAP_URL = "http://www.shfe.com.cn/data/dailydata/ck/%sdailyTimePrice.dat"
DCE_DAILY_URL = "http://www.dce.com.cn//publicweb/quotesdata/dayQuotesCh.html"
CZCE_DAILY_URL_1 = "http://www.czce.com.cn/cn/exchange/jyxx/hq/hq%s.html"
CZCE_DAILY_URL_2 = "http://www.czce.com.cn/cn/exchange/%s/datadaily/%s.txt"
Expand Down Expand Up @@ -459,9 +454,7 @@ def get_json_path(name, module_file):
:param module_file: filename
:return: str json_file_path
"""
module_folder = os.path.abspath(
os.path.dirname(os.path.dirname(module_file))
)
module_folder = os.path.abspath(os.path.dirname(os.path.dirname(module_file)))
module_json_path = os.path.join(module_folder, "file_fold", name)
return module_json_path

Expand All @@ -473,9 +466,7 @@ def get_pk_path(name, module_file):
:param module_file: filename
:return: str json_file_path
"""
module_folder = os.path.abspath(
os.path.dirname(os.path.dirname(module_file))
)
module_folder = os.path.abspath(os.path.dirname(os.path.dirname(module_file)))
module_json_path = os.path.join(module_folder, "file_fold", name)
return module_json_path

Expand Down
107 changes: 60 additions & 47 deletions akshare/futures/cot.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2023/7/12 17:06
Date: 2023/8/8 17:00
Desc: 期货-中国-交易所-会员持仓数据接口
大连商品交易所、上海期货交易所、郑州商品交易所、中国金融期货交易所
大连商品交易所、上海期货交易所、郑州商品交易所、中国金融期货交易所、广州期货交易所(交易所未提供)
采集前 20 会员持仓数据;
建议下午 16:30 以后采集当天数据, 避免交易所数据更新不稳定;
郑州商品交易所格式分为三类
Expand All @@ -20,7 +20,6 @@
import warnings
import zipfile
from io import BytesIO
from io import StringIO

import pandas as pd
import requests
Expand Down Expand Up @@ -709,9 +708,10 @@ def get_dce_rank_table(
return big_dict


def get_cffex_rank_table(date="20200427", vars_list=cons.contract_symbols):
def get_cffex_rank_table(date: str = "20190805", vars_list=cons.contract_symbols):
"""
中国金融期货交易所前 20 会员持仓排名数据明细
http://www.cffex.com.cn/ccpm/
注:该交易所既公布品种排名,也公布标的排名
:param date: 日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象 为空时为当天
:param vars_list: 合约品种如RB、AL等列表 为空时为所有商品, 数据从20100416开始,每交易日16:30左右更新数据
Expand All @@ -737,11 +737,14 @@ def get_cffex_rank_table(date="20200427", vars_list=cons.contract_symbols):
cons.convert_date(date) if date is not None else datetime.date.today()
)
if date < datetime.date(2010, 4, 16):
print(Exception("cffex数据源开始日期为20100416,跳过"))
print(Exception("CFFEX 数据源开始日期为 20100416,跳过"))
return {}
if date.strftime("%Y%m%d") not in calendar:
warnings.warn("%s非交易日" % date.strftime("%Y%m%d"))
return {}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
}
big_dict = {}
for var in vars_list:
# print(var)
Expand All @@ -751,26 +754,36 @@ def get_cffex_rank_table(date="20200427", vars_list=cons.contract_symbols):
date.strftime("%d"),
var,
)
r = requests_link(url, encoding="gbk")
if not r:
return False
if "网页错误" not in r.text:
# url = 'http://www.cffex.com.cn/sj/ccpm/201908/05/IF_1.csv'
# url = 'http://www.cffex.com.cn/sj/ccpm/202308/08/IF_1.csv'
r = requests.get(url, headers=headers)
# 20200316 开始数据结构变化,统一格式
if r.status_code == 200:
try:
temp_chche = StringIO(r.text.split("\n交易日,")[1])
# 当所需要的合约没有数据时
temp_df = pd.read_table(BytesIO(r.content), encoding="gbk", header=None)
except:
temp_chche = StringIO(
r.text.split("\n交易日,")[0][4:]
) # 20200316开始数据结构变化,统一格式
table = pd.read_csv(temp_chche)
table = table.dropna(how="any")
table = table.applymap(
lambda x: x.strip() if isinstance(x, str) else x
)
for symbol in set(table["合约"]):
table_cut = table[table["合约"] == symbol]
table_cut.columns = ["symbol", "rank"] + rank_columns
table_cut = _table_cut_cal(pd.DataFrame(table_cut), symbol)
big_dict[symbol] = table_cut.reset_index(drop=True)
continue
need_index = temp_df.iloc[:, 0].str.contains("交易日")
if sum(need_index) > 2:
table = temp_df.iloc[temp_df[need_index].index[1]:, 0].str.split(",", expand=True)
table.columns = table.iloc[0,:]
table = table.iloc[2:, :].copy()
table.reset_index(inplace=True, drop=True)
else:
table = pd.read_csv(BytesIO(r.content), encoding="gbk")
else:
return
table = table.dropna(how="any")
table = table.applymap(
lambda x: x.strip() if isinstance(x, str) else x
)
del table['交易日']
for symbol in set(table["合约"]):
table_cut = table[table["合约"] == symbol]
table_cut.columns = ["symbol", "rank"] + rank_columns
table_cut = _table_cut_cal(pd.DataFrame(table_cut), symbol)
big_dict[symbol] = table_cut.reset_index(drop=True)
return big_dict


Expand Down Expand Up @@ -1121,30 +1134,30 @@ def futures_dce_position_rank_other(date: str = "20160104"):


if __name__ == "__main__":
# # 郑州商品交易所
# get_czce_rank_table_first_df = get_czce_rank_table(date="20210525")
# print(get_czce_rank_table_first_df)
#
# get_czce_rank_table_first_df = get_czce_rank_table(date="20201026")
# print(get_czce_rank_table_first_df)
#
# # 中国金融期货交易所
# get_cffex_rank_table_df = get_cffex_rank_table(date="20200325")
# print(get_cffex_rank_table_df)
#
# # 上海期货交易所
# get_shfe_rank_table_df = get_shfe_rank_table(date="20230705")
# print(get_shfe_rank_table_df)
#
# # 大连商品交易所
# get_dce_rank_table_first_df = get_dce_rank_table(date="20131227")
# print(get_dce_rank_table_first_df)
#
# get_dce_rank_table_second_df = get_dce_rank_table(date="20171227")
# print(get_dce_rank_table_second_df)
#
# get_dce_rank_table_third_df = get_dce_rank_table(date="20200929")
# print(get_dce_rank_table_third_df)
# 郑州商品交易所
get_czce_rank_table_first_df = get_czce_rank_table(date="20210525")
print(get_czce_rank_table_first_df)

get_czce_rank_table_first_df = get_czce_rank_table(date="20201026")
print(get_czce_rank_table_first_df)

# 中国金融期货交易所
get_cffex_rank_table_df = get_cffex_rank_table(date="20100810")
print(get_cffex_rank_table_df)

# 上海期货交易所
get_shfe_rank_table_df = get_shfe_rank_table(date="20230808")
print(get_shfe_rank_table_df)

# 大连商品交易所
get_dce_rank_table_first_df = get_dce_rank_table(date="20131227")
print(get_dce_rank_table_first_df)

get_dce_rank_table_second_df = get_dce_rank_table(date="20171227")
print(get_dce_rank_table_second_df)

get_dce_rank_table_third_df = get_dce_rank_table(date="20200929")
print(get_dce_rank_table_third_df)

get_dce_rank_table_third_df = get_dce_rank_table(date="20230706")
print(get_dce_rank_table_third_df)
Expand Down
4 changes: 2 additions & 2 deletions akshare/futures/futures_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ def futures_spot_price_previous(date: str = "20220209") -> pd.DataFrame:
)
print(futures_spot_price_daily_df)

futures_spot_price_df = futures_spot_price("20200510")
futures_spot_price_df = futures_spot_price("20230807")
print(futures_spot_price_df)

futures_spot_price_previous_df = futures_spot_price_previous('20220209')
futures_spot_price_previous_df = futures_spot_price_previous('20230807')
print(futures_spot_price_previous_df)
8 changes: 6 additions & 2 deletions akshare/futures/symbol_var.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2019/9/30 13:58
Desc:
Date: 2023/8/8 20:58
Desc: 期货品种映射表
"""
import re

Expand Down Expand Up @@ -156,6 +156,8 @@ def chinese_to_english(chinese_var: str):
'花生',
'工业硅',
'氧化铝',
'丁二烯橡胶',
'碳酸锂',
]
english_list = [
"RU",
Expand Down Expand Up @@ -263,6 +265,8 @@ def chinese_to_english(chinese_var: str):
"PK",
"SI",
"AO",
"BR",
"LC",
]
pos = chinese_list.index(chinese_var)
return english_list[pos]
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@

## 更新说明详情

1.10.78 fix: fix get_cffex_rank_table interface

1. 修复 get_cffex_rank_table 接口
2. 修复 futures_spot_price 接口

1.10.77 add: add bond_cb_profile_sina interface

1. 新增 bond_cb_profile_sina 接口
Expand Down Expand Up @@ -2730,6 +2735,8 @@

## 版本更新说明

1.10.78 fix: fix get_cffex_rank_table interface

1.10.77 add: add bond_cb_profile_sina interface

1.10.76 fix: fix stock_notice_report interface
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
**风险提示:[AKShare](https://github.com/akfamily/akshare) 开源财经数据接口库所采集的数据皆来自公开的数据源,不涉及任何个人隐私数据和非公开数据。
同时本项目提供的数据接口及相关数据仅用于学术研究,任何个人、机构及团体使用本项目的数据接口及相关数据请注意商业风险。**

1. 本文档更新时间:**2023-08-07**
1. 本文档更新时间:**2023-08-08**
2. 如有 [AKShare](https://github.com/akfamily/akshare) 库、文档及数据的相关问题,请在 [AKShare Issues](https://github.com/akfamily/akshare/issues) 中提 Issues;
3. 欢迎关注 **数据科学实战** 微信公众号:<div><img src="https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/readme/qrcode/ds.png"></div>;
4. 如果您的问题未能在文档中找到答案,您也可以加入 **AKShare-VIP QQ 群**: 为了提高问答质量,此群为收费群(一杯咖啡钱即可入群,赠送[《AKShare-初阶-使用教学》](https://zmj.xet.tech/s/wck86)视频课),可以添加 **AKShare-小助手** QQ:1254836886,由小助手邀请入群! ![](https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/readme/qrcode/qr_code_1254836886.jpg)
Expand Down

0 comments on commit 9b58967

Please sign in to comment.