Skip to content

Commit

Permalink
更改函数名称,添加十大流通股东信息获取功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Micro-sheep committed Jun 15, 2021
1 parent c0e2113 commit 732d0ca
Show file tree
Hide file tree
Showing 16 changed files with 341 additions and 180 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Folders
*/__pycache__/*
efinance/__pycache__/*
efinance.egg-info
build
dist
# Files

# Files
*.pyc
*.csv
*.xlsx
*.xlsx
*.zip
*.ipynb
4 changes: 3 additions & 1 deletion efinance/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from efinance.api import Stock,Fund,Futures
from efinance.api import (stock,
fund,
futures)
8 changes: 5 additions & 3 deletions efinance/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import efinance.stock as Stock
import efinance.fund as Fund
import efinance.futures as Futures
import efinance.stock as stock
import efinance.fund as fund
import efinance.futures as futures


11 changes: 9 additions & 2 deletions efinance/fund/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
from .getter import (get_base_info, get_fund_codes, get_increase_rate, get_inverst_postion,
get_types_persentage, get_period_change, get_public_dates, get_industry_distributing, get_k_history)
from .getter import (get_base_info,
get_fund_codes,
get_realtime_increase_rate,
get_inverst_postion,
get_types_persentage,
get_period_change,
get_public_dates,
get_industry_distributing,
get_qoute_history)
43 changes: 7 additions & 36 deletions efinance/fund/config.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
EastmoneyKlines = {
'f51': '日期',
'f52': '开盘',
'f53': '收盘',
'f54': '最高',
'f55': '最低',
'f56': '成交量',
'f57': '成交额',
'f58': '振幅',
'f59': '涨跌幅',
'f60': '涨跌额',
'f61': '换手率',


}
EastmoneyRank = {
'f12': '代码',
'f14': '名称',
Expand All @@ -23,22 +9,7 @@
'f6': '成交额',
'f18': '昨日收盘'
}
EastmoneyBills = {
'f51': '日期',
'f52': '主力净流入',
'f53': '小单净流入',
'f54': '中单净流入',
'f55': '大单净流入',
'f56': '超大单净流入',
'f57': '主力净流入占比',
'f58': '小单流入净占比',
'f59': '中单流入净占比',
'f60': '大单流入净占比',
'f61': '超大单流入净占比',
'f62': '收盘价',
'f63': '涨跌幅'

}
EastmoneyHeaders = {
'Host': '19.push2.eastmoney.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko',
Expand All @@ -47,10 +18,10 @@
'Referer': 'http://quote.eastmoney.com/center/gridlist.html',
}
EastmoneyFundHeaders = {
'User-Agent': 'EMProjJijin/6.2.8 (iPhone; iOS 13.6; Scale/2.00)',
'GTOKEN': '98B423068C1F4DEF9842F82ADF08C5db',
'clientInfo': 'ttjj-iPhone10,1-iOS-iOS13.6',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'fundmobapi.eastmoney.com',
'Referer': 'https://mpservice.com/516939c37bdb4ba2b1138c50cf69a2e1/release/pages/FundHistoryNetWorth',
}
'User-Agent': 'EMProjJijin/6.2.8 (iPhone; iOS 13.6; Scale/2.00)',
'GTOKEN': '98B423068C1F4DEF9842F82ADF08C5db',
'clientInfo': 'ttjj-iPhone10,1-iOS-iOS13.6',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'fundmobapi.eastmoney.com',
'Referer': 'https://mpservice.com/516939c37bdb4ba2b1138c50cf69a2e1/release/pages/FundHistoryNetWorth',
}
14 changes: 7 additions & 7 deletions efinance/fund/getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .config import EastmoneyFundHeaders


def get_k_history(fund_code: str, pz: int = 40000) -> pd.DataFrame:
def get_qoute_history(fund_code: str, pz: int = 40000) -> pd.DataFrame:
'''
根据基金代码和要获取的页码抓取基金净值信息
Expand Down Expand Up @@ -67,7 +67,7 @@ def get_k_history(fund_code: str, pz: int = 40000) -> pd.DataFrame:



def get_increase_rate(fund_codes: Union[List[str], str]) -> pd.DataFrame:
def get_realtime_increase_rate(fund_codes: Union[List[str], str]) -> pd.DataFrame:
'''
获取基金实时预期涨跌幅度
Expand Down Expand Up @@ -358,12 +358,12 @@ def get_types_persentage(fund_code: str, dates:Union[List[str],str,None]=None) -
params.append(('DATE', date))
params = tuple(params)
json_response = requests.get(
'https://fundmobapi.eastmoney.com/FundMNewApi/FundMNAssetAllocationNew', headers=EastmoneyFundHeaders, params=params).json()
'https://fundmobapi.eastmoney.com/FundMNewApi/FundMNAssetAllocationNew', params=params).json()

if len(json_response['Datas']) == 0:
continue
_df = pd.DataFrame(json_response['Datas'])
_df = df[list(columns.keys())].rename(columns=columns)
_df = pd.DataFrame(json_response['Datas'])[columns.keys()]
_df = _df.rename(columns=columns)
df = pd.concat([df,_df],axis=0)
df.insert(0,'基金代码',[fund_code for _ in range(len(df))])
return df
Expand Down Expand Up @@ -458,7 +458,7 @@ def get_industry_distributing(fund_code: str, dates: Union[str, List[str]] = Non
]
if date is not None:
params.append(('DATE', date))
params = tuple(params)

response = requests.get('https://fundmobapi.eastmoney.com/FundMNewApi/FundMNSectorAllocation',
headers=EastmoneyFundHeaders, params=params)
datas = response.json()['Datas']
Expand Down
27 changes: 0 additions & 27 deletions efinance/fund/utils.py
Original file line number Diff line number Diff line change
@@ -1,27 +0,0 @@
from threading import Thread


def gen_secid(rawcode: str) -> str:
'''
生成东方财富专用的secid
'''
if rawcode[0] != '6':
return f'0.{rawcode}'
return f'1.{rawcode}'


def threadmethod(func, *args, cores: int = 30, **kwargs):
def thread(*args, **kwargs):
threads = []
for _ in range(cores):
t = Thread(target=func, args=args, kwargs=kwargs)
t.setDaemon(True)
threads.append(t)
for t in threads:
t.start()
for t in threads:
t.join()

return 1

return thread
4 changes: 3 additions & 1 deletion efinance/futures/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from efinance.futures.getter import get_futures_base_info,get_k_history
from .getter import (get_futures_base_info,
get_qoute_history)

5 changes: 3 additions & 2 deletions efinance/futures/getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_futures_base_info() -> pd.DataFrame:
return df


def get_k_history(secid: str, beg: str = '19000101', end: str = '20500101', klt: int = 101, fqt: int = 1) -> pd.DataFrame:
def get_qoute_history(secid: str, beg: str = '19000101', end: str = '20500101', klt: int = 101, fqt: int = 1) -> pd.DataFrame:
'''
获取k线数据
Expand All @@ -67,10 +67,11 @@ def get_k_history(secid: str, beg: str = '19000101', end: str = '20500101', klt:
DateFrame : 包含股票k线数据
'''

fields = list(EastmoneyKlines.keys())
columns = list(EastmoneyKlines.values())
fields2 = ",".join(fields)


params = (
('fields1', 'f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13'),
Expand Down
1 change: 1 addition & 0 deletions efinance/share.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
QOUTE_SAVE_PATH = 'qoutes.csv'
7 changes: 6 additions & 1 deletion efinance/stock/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from efinance.stock.getter import get_history_bill, get_k_historys, get_real_rank, get_today_bill, get_latest_stock_info, get_k_history
from .getter import (get_history_bill,
get_today_bill,
get_latest_stock_info,
get_quote_history,
get_realtime_quotes,
get_top10_stock_holder_info)
12 changes: 8 additions & 4 deletions efinance/stock/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@


}
EastmoneyRank = {
'f12': '代码',
'f14': '名称',

EastmoneyQuotes = {
'f12': '股票代码',
'f13': '沪/深',
'f14': '股票名称',
'f3': '涨跌幅',
'f15': '最新价',
'f4': '涨跌额',
'f5': '成交量',
'f6': '成交额',
'f18': '昨日收盘'
'f18': '昨日收盘',
'f20': '总市值',
'f21': '流通市值'
}
EastmoneyBills = {
'f51': '日期',
Expand Down
Loading

0 comments on commit 732d0ca

Please sign in to comment.