-
Notifications
You must be signed in to change notification settings - Fork 233
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 #68 from 1nchaos/dev
Dev
- Loading branch information
Showing
13 changed files
with
261 additions
and
42 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
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
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,62 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@desc: 新浪 | ||
https://vip.stock.finance.sina.com.cn/mkt/#hskzz_z | ||
@author: 1nchaos | ||
@time:2023/4/5 | ||
@log: | ||
""" | ||
import pandas as pd | ||
|
||
from adata.bond.market.bond_market_template import BondMarketTemplate | ||
from adata.common.utils import requests | ||
|
||
|
||
class BondMarketSina(BondMarketTemplate): | ||
"""bond 行情""" | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
def list_market_current(self, code_list=None): | ||
""" | ||
获取新浪的最新可转债行情 | ||
url : http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeDataSimple | ||
:param code_list: 可转债代码列表 | ||
:return: 最新行情数据 | ||
""" | ||
# 0.进行参数拼接处理 | ||
api_url = f"http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeDataSimple" | ||
|
||
# 2.循环请求 | ||
data = [] | ||
for i in range(100): | ||
# 1.请求接口 | ||
params = {"page": {i+1}, "num": "80", "sort": "symbol", | ||
"asc": "1", "node": "hskzz_z", "_s_r_a": "page"} | ||
res = requests.request('get', api_url, params=params) | ||
res = res.json() | ||
data.extend(res) | ||
if len(res) < 80: | ||
break | ||
# 3. 结果筛选 | ||
if code_list is not None: | ||
new_data = [] | ||
for d in data: | ||
if d['code'] in code_list: | ||
new_data.append(d) | ||
data = new_data | ||
# 4. 封装数据 | ||
rename = {'code': 'bond_code', 'name': 'bond_name', 'pricechange': 'change', 'changepercent': 'change_pct', | ||
'settlement': 'pre_close', 'ticktime': 'time', 'trade': 'price'} | ||
result_df = pd.DataFrame(data=data).rename(columns=rename) | ||
columns_to_convert = ['price', 'open', 'high', 'low', 'pre_close', 'change', 'change_pct', 'volume', 'amount'] | ||
result_df[columns_to_convert] = result_df[columns_to_convert].astype(float) | ||
result_df_unique = result_df.drop_duplicates(keep='last', subset=['bond_code']) | ||
return result_df_unique[self._MARKET_CURRENT_COLUMNS] | ||
|
||
|
||
if __name__ == '__main__': | ||
df = BondMarketSina().list_market_current(code_list=['110044', '127103']) | ||
print(df) |
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,24 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@desc: readme | ||
@author: 1nchaos | ||
@time: 2024/05/05 | ||
@log: change log | ||
""" | ||
|
||
|
||
class BondMarketTemplate(object): | ||
""" | ||
债券行情 | ||
""" | ||
_MARKET_CURRENT_COLUMNS = ['bond_code', 'bond_name', 'price', 'open', 'high', 'low', 'pre_close', 'change', | ||
'change_pct', 'volume', 'amount', 'time'] | ||
|
||
def list_market_current(self, code_list=None): | ||
""" | ||
获取多个可转债的最新行情信息 | ||
:param code_list: 可转债代码 | ||
:return: 当前最新的行情价格信息 | ||
_MARKET_CURRENT_COLUMNS | ||
""" | ||
pass |
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,103 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@desc: 热点榜单 TODO | ||
同花顺热点榜单 | ||
https://eq.10jqka.com.cn/frontend/thsTopRank/index.html?fontzoom=no&client_userid=ceZLR&share_hxapp=gsc&share_action=webpage_share.hot_list_1714369375634&back_source=wxhy#/ | ||
@author: 1nchaos | ||
@time: 2024/4/29 | ||
@log: change log | ||
""" | ||
import pandas as pd | ||
|
||
from adata.common.base.base_ths import BaseThs | ||
from adata.common.headers import ths_headers | ||
from adata.common.utils import requests | ||
|
||
|
||
class Hot(BaseThs): | ||
"""热门榜单""" | ||
|
||
# 东方财富人气榜 | ||
def pop_rank_100_east(self): | ||
""" | ||
东方财富人气榜100 | ||
http://guba.eastmoney.com/rank/ | ||
""" | ||
# 1.url | ||
url = "https://emappdata.eastmoney.com/stockrank/getAllCurrentList" | ||
|
||
# 2. 请求数据 | ||
params = {"appId": "appId01", "globalId": "786e4c21-70dc-435a-93bb-38", | ||
"marketType": "", "pageNo": 1, "pageSize": 100, } | ||
res = requests.request(method='post', url=url, json=params).json() | ||
df = pd.DataFrame(res["data"]) | ||
|
||
df["mark"] = ["0" + "." + item[2:] if "SZ" in item else "1" + "." + item[2:] | ||
for item in df["sc"]] | ||
",".join(df["mark"]) + "?v=08926209912590994" | ||
params = {"ut": "f057cbcbce2a86e2866ab8877db1d059", | ||
"fltt": "2", "invt": "2", "fields": "f14,f3,f12,f2", | ||
"secids": ",".join(df["mark"]) + ",?v=08926209912590994", } | ||
url = "https://push2.eastmoney.com/api/qt/ulist.np/get" | ||
res = requests.request(method='get', url=url, params=params) | ||
|
||
# 3. 解析封装数据 | ||
data = res.json()["data"]["diff"] | ||
rename = {'f2': 'price', 'f3': 'change_pct', 'f12': 'stock_code', 'f14': 'short_name', } | ||
rank_df = pd.DataFrame(data).rename(columns=rename) | ||
rank_df["change_pct"] = pd.to_numeric(rank_df["change_pct"], errors="coerce") | ||
rank_df["price"] = pd.to_numeric(rank_df["price"], errors="coerce") | ||
rank_df["change"] = rank_df["price"] * rank_df["change_pct"] / 100 | ||
rank_df["rank"] = range(1, len(rank_df) + 1) | ||
return rank_df[["rank", "stock_code", "short_name", "price", "change", "change_pct"]] | ||
|
||
def hot_rank_100_ths(self): | ||
""" | ||
同花顺热股100 | ||
https://dq.10jqka.com.cn/fuyao/hot_list_data/out/hot_list/v1/stock?stock_type=a&type=hour&list_type=normal | ||
""" | ||
api_url = 'https://dq.10jqka.com.cn/fuyao/hot_list_data/out/hot_list/v1/stock?stock_type=a&type=hour&list_type=normal' | ||
headers = ths_headers.json_headers | ||
headers['Host'] = 'dq.10jqka.com.cn' | ||
res = requests.request(method='get', url=api_url, params={}, headers=headers) | ||
data = res.json()['data']['stock_list'] | ||
data_list = [] | ||
for d in data: | ||
d['concept_tag'] = ";".join(d['tag']['concept_tag']) | ||
if 'popularity_tag' in d['tag']: | ||
d['pop_tag'] = d['tag']['popularity_tag'].replace('\n', '') | ||
data_list.append(d) | ||
rename = {'order': 'rank', 'rise_and_fall': 'change_pct', 'code': 'stock_code', 'name': 'short_name', | ||
'rate': 'hot_value', 'concept_tag': 'concept_tag'} | ||
rank_df = pd.DataFrame(data).rename(columns=rename) | ||
rank_df = rank_df[["rank", "stock_code", "short_name", "change_pct", "hot_value", "pop_tag", "concept_tag"]] | ||
return rank_df | ||
|
||
def hot_concept_20_ths(self, plate_type=1): | ||
""" | ||
同花热门概念板块 | ||
:param plate_type: 1.概念板块,2.行业板块;默认:概念板块 | ||
""" | ||
plate_type = 'concept' if plate_type == 1 else 'industry' | ||
api_url = f'https://dq.10jqka.com.cn/fuyao/hot_list_data/out/hot_list/v1/plate?type={plate_type}' | ||
headers = ths_headers.json_headers | ||
headers['Host'] = 'dq.10jqka.com.cn' | ||
res = requests.request(method='get', url=api_url, params={}, headers=headers) | ||
data = res.json()['data']['plate_list'] | ||
data_list = [] | ||
for d in data: | ||
data_list.append(d) | ||
rename = {'order': 'rank', 'rise_and_fall': 'change_pct', 'rate': 'hot_value', 'code': 'concept_code', | ||
'name': 'concept_name'} | ||
rank_df = pd.DataFrame(data).rename(columns=rename) | ||
rank_df = rank_df[["rank", "concept_code", "concept_name", "change_pct", "hot_value", "hot_tag"]] | ||
return rank_df | ||
|
||
|
||
if __name__ == '__main__': | ||
print(Hot().hot_rank_100_ths()) | ||
print(Hot().pop_rank_100_east()) | ||
print(Hot().hot_concept_20_ths(plate_type=1)) | ||
print(Hot().hot_concept_20_ths(plate_type=2)) |
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
Oops, something went wrong.