Skip to content

Commit

Permalink
modify get_kline for index
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Aug 2, 2019
1 parent 2649942 commit 50c5f0f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions chan/a/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tushare as ts


def get_kline(ts_code, start_date, end_date, freq='30min'):
def get_kline(ts_code, start_date, end_date, freq='30min', asset='E'):
"""获取指定级别的前复权K线
:param ts_code: str
Expand All @@ -14,16 +14,19 @@ def get_kline(ts_code, start_date, end_date, freq='30min'):
日期,如 20190601
:param end_date: str
日期,如 20190610
:param asset: str
交易资产类型,可选值 E股票 I沪深指数 C数字货币 FT期货 FD基金 O期权 CB可转债(v1.2.39),默认E
:return: pd.DataFrame
columns = ["symbol", "dt", "open", "close", "high", "low", "vol"]
example:
>>> from chan.a.utils import get_kline
>>> get_kline(ts_code='600122.SH', start_date='20190601', end_date='20190610', freq='30min')
"""
# https://tushare.pro/document/2?doc_id=109
df = ts.pro_bar(ts_code=ts_code, freq=freq,
start_date=start_date, end_date=end_date,
adj='qfq', asset='E')
adj='qfq', asset=asset)

# 统一 k 线数据格式为 6 列,分别是 ["symbol", "dt", "open", "close", "high", "low", "vr"]
if "min" in freq:
Expand All @@ -43,13 +46,12 @@ def get_kline(ts_code, start_date, end_date, freq='30min'):


def get_realtime_kline(ts_code, freq="5min"):
"""实时获取分钟K线
"""实时获取分钟K线(仅适用于A股股票)
:param ts_code: str
tushare 股票代码,如 600122.SH
:param freq: str
K线周期,分钟级别,可选值 5min 15min 30min 60min
:return: pd.DataFrame
columns = ["symbol", "dt", "open", "close", "high", "low", "vol"]
Expand Down

0 comments on commit 50c5f0f

Please sign in to comment.