-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from 1nchaos/dev
Dev
- Loading branch information
Showing
11 changed files
with
179 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
Release History | ||
=============== | ||
|
||
**A Data** | ||
![logo](/favicon.ico)[AData](https://github.com/1nchaos/adata) | ||
|
||
master | ||
------ | ||
开放、纯净、持续 | ||
|
||
专注股票量化数据,为Ai(爱)发电,向阳而生。 | ||
|
||
0.0.27b0 (2023-07-10) | ||
------------------ | ||
1. 新增代理设置,可设置代理ip进行数据获取。 | ||
2. 部分函数增加,单个请求等待时间的设置,可避免限流封控。 | ||
|
||
0.0.26b0 (2023-07-08) | ||
------------------ | ||
1. 优化交易日历,增加缓存数据 | ||
2. 增加行情测试用例 | ||
3. 修复指数代码转换问题 | ||
|
||
...... | ||
------------------ | ||
|
||
0.0.1b0 (2023-04-05) | ||
------------------ | ||
清明时节雨纷纷 | ||
第一个测试预览版本 | ||
第一个测试预览版本 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@desc: readme | ||
@author: yinchao | ||
@time: 2023/7/24 | ||
@log: change log | ||
""" | ||
json_headers = { | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0', | ||
'Accept': '*/*', | ||
'Content-Type': 'text/plain;charset=UTF-8', | ||
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2', | ||
'Accept-Encoding': 'gzip, deflate, br', | ||
'HOST': 'datacenter-web.eastmoney.com', | ||
'Connection': 'keep-alive', | ||
'Referer': 'https://data.eastmoney.com/rzrq/total.html', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@desc: | ||
融资融券数据 | ||
同花顺 | ||
http://data.10jqka.com.cn/market/rzrq/ | ||
http://data.10jqka.com.cn/market/rzrq/board/getRzrqPage/page/2/ajax/1/ | ||
东方财富 | ||
https://data.eastmoney.com/rzrq/total.html | ||
https://datacenter-web.eastmoney.com/api/data/v1/get?reportName=RPTA_RZRQ_LSHJ&columns=ALL&source=WEB&sortColumns=dim_date&sortTypes=-1&pageNumber=2&pageSize=50&filter=&pageNo=2&p=2&pageNum=2&_=1690176931022 | ||
@author: 1nchaos | ||
@time: 2023/7/24 | ||
@log: change log | ||
""" | ||
from datetime import datetime | ||
|
||
import pandas as pd | ||
|
||
from adata.common import requests | ||
from adata.common.headers import east_headers | ||
|
||
|
||
class SecuritiesMargin(object): | ||
__SECURITIES_MARGIN_COLUMN = ['trade_date', 'rzye', 'rqye', 'rzrqye', 'rzrqyecz'] | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
def securities_margin(self, start_date=None): | ||
""" | ||
查询开始时间到现在的融资融券余额数据,默认:查询最近一年的数据 | ||
:return: ['trade_date', 'rzye', 'rqye', 'rzrqye', 'rzrqyecz'] | ||
trade_date: 交易日 | ||
rzye: 融资余额(元) | ||
rqye: 融券余额(元) | ||
rzrqye: 融资融券余额(元) | ||
rzrqyecz: 融资融券余额差值(元) | ||
""" | ||
return self.__securities_margin_east(start_date=start_date) | ||
|
||
def __securities_margin_east(self, start_date=None): | ||
""" | ||
https://datacenter-web.eastmoney.com/api/data/v1/get?reportName=RPTA_RZRQ_LSHJ&columns=ALL&source=WEB&sortColumns=dim_date&sortTypes=-1&pageNumber=1&pageSize=250&_=1690176931022 | ||
:param start_date: 开始时间 | ||
:return: | ||
""" | ||
|
||
# 1. url拼接页码等参数 | ||
data = [] | ||
total_pages = 1 | ||
curr_page = 1 | ||
page_size = 250 | ||
start_date_str = start_date | ||
if start_date: | ||
start_date = datetime.strptime(start_date, '%Y-%m-%d') | ||
while curr_page <= total_pages: | ||
api_url = f"https://datacenter-web.eastmoney.com/api/data/v1/get?" \ | ||
f"reportName=RPTA_RZRQ_LSHJ&columns=ALL&source=WEB&sortColumns=dim_date&sortTypes=-1&" \ | ||
f"pageNumber={curr_page}&pageSize={page_size}&_=1690176931022" | ||
|
||
res = requests.request(method='get', url=api_url, headers=east_headers.json_headers, proxies={}) | ||
# 2. 判断请求是否成功 | ||
if res.status_code != 200: | ||
continue | ||
res_json = res.json() | ||
if not res_json['success']: | ||
continue | ||
if curr_page == 1: | ||
total_pages = res_json['result']['pages'] | ||
res_json = res_json['result']['data'] | ||
# 2.1 日期范围判断 | ||
data.extend(res_json) | ||
if not start_date: | ||
break | ||
if start_date: | ||
date_min = datetime.strptime(res_json[-1]['DIM_DATE'], '%Y-%m-%d %H:%M:%S') | ||
if start_date >= date_min: | ||
break | ||
curr_page += 1 | ||
|
||
# 3. 解析数据 | ||
result_df = pd.DataFrame(data=data) | ||
rename_columns = {'RZYE': 'rzye', 'RQYE': 'rqye', 'RZRQYE': 'rzrqye', 'RZRQYECZ': 'rzrqyecz', | ||
'DIM_DATE': 'trade_date'} | ||
result_df = result_df.rename(columns=rename_columns)[self.__SECURITIES_MARGIN_COLUMN] | ||
|
||
# 4. 数据清洗 | ||
result_df['trade_date'] = pd.to_datetime(result_df['trade_date']).dt.strftime('%Y-%m-%d') | ||
result_df = result_df[result_df['trade_date'] > start_date_str] | ||
return result_df | ||
|
||
|
||
if __name__ == '__main__': | ||
print(SecuritiesMargin().securities_margin('2022-01-01')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters