Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Ashare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json,requests,datetime; import pandas as pd #

#腾讯日线
def get_price_day_tx(code, end_date='', count=10, frequency='1d'): #日线获取
def _get_price_day_tx(code, end_date='', count=10, frequency='1d'): #日线获取
unit='week' if frequency in '1w' else 'month' if frequency in '1M' else 'day' #判断日线,周线,月线
if end_date: end_date=end_date.strftime('%Y-%m-%d') if isinstance(end_date,datetime.date) else end_date.split(' ')[0]
end_date='' if end_date==datetime.datetime.now().strftime('%Y-%m-%d') else end_date #如果日期今天就变成空
Expand All @@ -14,7 +14,7 @@ def get_price_day_tx(code, end_date='', count=10, frequency='1d'): #日线
return df

#腾讯分钟线
def get_price_min_tx(code, end_date=None, count=10, frequency='1d'): #分钟线获取
def _get_price_min_tx(code, end_date=None, count=10, frequency='1d'): #分钟线获取
ts=int(frequency[:-1]) if frequency[:-1].isdigit() else 1 #解析K线周期数
if end_date: end_date=end_date.strftime('%Y-%m-%d') if isinstance(end_date,datetime.date) else end_date.split(' ')[0]
URL=f'http://ifzq.gtimg.cn/appstock/app/kline/mkline?param={code},m{ts},,{count}'
Expand All @@ -28,7 +28,7 @@ def get_price_min_tx(code, end_date=None, count=10, frequency='1d'): #分钟


#sina新浪全周期获取函数,分钟线 5m,15m,30m,60m 日线1d=240m 周线1w=1200m 1月=7200m
def get_price_sina(code, end_date='', count=10, frequency='60m'): #新浪全周期获取函数
def _get_price_sina(code, end_date='', count=10, frequency='60m'): #新浪全周期获取函数
frequency=frequency.replace('1d','240m').replace('1w','1200m').replace('1M','7200m'); mcount=count
ts=int(frequency[:-1]) if frequency[:-1].isdigit() else 1 #解析K线周期数
if (end_date!='') & (frequency in ['240m','1200m','7200m']):
Expand All @@ -48,13 +48,13 @@ def get_price(code, end_date='',count=10, frequency='1d', fields=[]): #
xcode='sh'+xcode if ('XSHG' in code) else 'sz'+xcode if ('XSHE' in code) else code

if frequency in ['1d','1w','1M']: #1d日线 1w周线 1M月线
try: return get_price_sina( xcode, end_date=end_date,count=count,frequency=frequency) #主力
except: return get_price_day_tx(xcode,end_date=end_date,count=count,frequency=frequency) #备用
try: return _get_price_sina( xcode, end_date=end_date,count=count,frequency=frequency) #主力
except: return _get_price_day_tx(xcode,end_date=end_date,count=count,frequency=frequency) #备用

if frequency in ['1m','5m','15m','30m','60m']: #分钟线 ,1m只有腾讯接口 5分钟5m 60分钟60m
if frequency in '1m': return get_price_min_tx(xcode,end_date=end_date,count=count,frequency=frequency)
try: return get_price_sina( xcode,end_date=end_date,count=count,frequency=frequency) #主力
except: return get_price_min_tx(xcode,end_date=end_date,count=count,frequency=frequency) #备用
if frequency in '1m': return _get_price_min_tx(xcode,end_date=end_date,count=count,frequency=frequency)
try: return _get_price_sina( xcode,end_date=end_date,count=count,frequency=frequency) #主力
except: return _get_price_min_tx(xcode,end_date=end_date,count=count,frequency=frequency) #备用

if __name__ == '__main__':
df=get_price('sh000001',frequency='1d',count=10) #支持'1d'日, '1w'周, '1M'月
Expand Down
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .Ashare import get_price