Welcome to fintie’s documentation!

fintie

https://img.shields.io/pypi/v/fintie.svg https://img.shields.io/travis/qytz/cn_stock_daily.svg Documentation Status Updates

A powerful data tool

Features

  • 支持异步调用(可与`finchan`结合使用)接口;

  • 支持同步调用(研究)接口;

  • 支持命令行模式;

使用方法

使用说明

Installation

Stable release

To install fintie, run this command in your terminal:

$ pip install fintie

This is the preferred method to install fintie, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for fintie can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/qytz/fintie

Or download the tarball:

$ curl  -OL https://github.com/qytz/fintie/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

命令行模式

类似于其他的 Linux 命令行,具体使用见帮助:

➜  ~ fintie stock list-quotes
配置文件(~/.config/fintie)不存在,配置设置为空
                amount change    code current hasexist   high high52w    low low52w      marketcapital  name percent   pettm type     volume
symbol
SZ002703   1.9345087E7   0.36  002703    3.93    false   3.93   11.04   3.56   3.15    3.10330341948E9  浙江世宝   10.08           11    5012710
SH601162   5.0454054E7   0.46  601162    5.03    false   5.03    5.03   5.03   2.15         2.60554E10  天风证券   10.07   66.71   11   10030627
SZ002725   3.1738561E7   0.68  002725    7.44    false   7.44   14.29   6.89    6.1          1.90464E9  跃岭股份   10.06   85.69   11    4370724
SH603508   2.3323164E7   1.75  603508   31.75    false  32.98   54.81  30.83  29.52             5.08E9  思维列控    5.83   30.73   11     728995
...                ...    ...     ...     ...      ...    ...     ...    ...    ...                ...   ...     ...     ...  ...        ...
SZ002563    5.519006E7  -0.87  002563    7.82    false   8.02    14.9   7.82   6.94    2.1112809014E10  森马服饰  -10.01   15.11   11    7026634
SZ002668      378777.0  -1.18  002668   10.61    false  10.61   21.25  10.61  10.37  1.150242225108E10  奥马电器  -10.01   24.99   11      35700
SZ002766   7.2889188E7  -0.68  002766    6.11    false   6.47   18.44   6.11   5.76    2.57691702554E9  索菱股份  -10.01   25.98   11   11736800
SZ000691   5.2487015E7   -0.4  000691    3.58    false    3.8    8.13   3.58   2.91        1.1573066E9  亚太实业  -10.05  118.18   11   14362700

[5524 rows x 15 columns]
(ms) ➜  ~ fintie stock picker-xq areacode=CN440000 pct=0_1 eps.20180630=ALL
配置文件(~/.config/fintie)不存在,配置设置为空
{'areacode': 'CN440000', 'pct': '0_1', 'eps.20180630': 'ALL'}
          current                  eps exchange  hasExist                        id   name   pct   volume
symbol
SZ300738    39.50    {'20180630': 0.4}       SZ     False  5a61ca9ce4b0ccdd7efc66b1   奥飞数据  0.38     4.88
SZ300737     8.72   {'20180630': 0.22}       SZ     False  5a69b3cfe4b0ccdd7efc66b6   科顺股份  0.35    20.01
SZ300735    14.43   {'20180630': 0.25}       SZ     False  5a461aa2e4b085b00b16fbd0   光弘科技  0.21    31.53
SZ300716    12.47   {'20180630': 0.19}       SZ     False  5a042fd3e4b0b3a1533e0d36   国立科技  0.65    24.93
...           ...                  ...      ...       ...                       ...    ...   ...      ...
SH600428     3.27   {'20180630': 0.03}       SH     False  52dce039e4b0413d505ca423   中远海特  0.00    84.98
SH600242    13.00   {'20180630': 0.09}       SH     False  52dcdf35e4b0413d505ca2fd   中昌数据  0.08     8.62
SH600036    28.03   {'20180630': 1.77}       SH     False  52dcde02e4b0413d505ca1a0   招商银行  0.65  1561.79
SH600030    16.68   {'20180630': 0.46}       SH     False  52dcddfae4b0413d505ca199   中信证券  0.18  2179.21

[158 rows x 8 columns]
(ms) ➜  ~

研究模式

ipython 中导入 fintie 后使用,需使用封装过的同步接口,具体支持的数据见文档:

➜  ~ ipython
Python 3.7.0 | packaged by conda-forge | (default, Jul 23 2018, 21:39:36)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from datetime import datetime, timedelta, date

In [2]: from fintie import stock
配置文件(~/.config/fintie)不存在,配置设置为空

In [3]: filter_dict = {'current': "ALL", "fmc":"ALL", "eps.20180630":"ALL", "bps.20180630": "ALL", "roediluted.20180630": "ALL", "volume":"ALL"}

In [4]: df = stock.pick_stocks(filter_dict=filter_dict)

In [5]: print(df[:3])
                         bps  current                 eps exchange      fmc  hasExist                        id  name   pct          roediluted  volume
symbol
SZ300749  {'20180630': 4.37}    27.60  {'20180630': 0.28}       SZ   7.8660     False  5baa116ce4b07f0b4a739de8  顶固集创 -5.15  {'20180630': 6.72}  190.68
SZ300748  {'20180630': 2.23}    22.95  {'20180630': 0.14}       SZ   9.5472     False  5ba4cb54e4b07f0b4a739de5  金力永磁 -4.10  {'20180630': 6.38}  296.39
SZ300694   {'20180630': 4.1}    23.10  {'20180630': 0.36}       SZ  12.4347     False  5bc46fa9c1362b7c0e7cc120  蠡湖股份 -0.22  {'20180630': 9.29}  383.60

In [6]: df = stock.get_list_quotes()

In [7]: print(df[:3])
               amount change    code current hasexist  high high52w   low low52w    marketcapital  name percent  pettm type   volume
symbol
SZ002703    1.86383E7   0.36  002703    3.93    false  3.93   11.04  3.56   3.15  3.10330341948E9  浙江世宝   10.08          11  4832866
SH601162  4.9397754E7   0.46  601162    5.03    false  5.03    5.03  5.03   2.15       2.60554E10  天风证券   10.07  66.71   11  9820627
SZ002725  3.1498993E7   0.68  002725    7.44    false  7.44   14.29  6.89    6.1        1.90464E9  跃岭股份   10.06  85.69   11  4338524

In [8]: df = stock.get_live_info("SZ002353")

In [9]: df
Out[9]:
{'market': {'status_id': 5,
  'region': 'CN',
  'status': '交易中',
  'time_zone': 'Asia/Shanghai'},
 'quote': {'symbol': 'SZ002353',
  'code': '002353',
  'high52w': 23.34,
  'avg_price': 19.77,
  'type': 11,
  ...
  'exchange': 'SZ',
  'pe_forecast': 39.072,
  'time': 1540865460000,
  'total_shares': 957853992,
  'open': 20.1,
  'status': 1},
 'others': {'pankou_ratio': 46.41},
 'tags': [{'description': '深港通', 'value': 3},
  {'description': '融', 'value': 6},
  {'description': '空', 'value': 7}]}

In [10]: df = stock.get_fhsp?
Signature: stock.get_fhsp(*args, **kwargs)
Docstring:
从雪球获取分红送配股数据

:param session: `aiohttp.ClientSession` 对象,同步接口不需要传
:param symbol: 股票代码
:param data_path: 数据保存路径
:param return_df: 是否返回 `pandas.DataFrame` 对象,False 返回原始数据

:returns: 原始数据或 `pandas.DataFrame` 对象,见 return_df 参数,
          失败则返回 `None`
File:      /workstation/osc/qytz/fintie/fintie/stock/fenhong.py
Type:      function

In [11]: df = stock.get_fhsp("SZ002353")

In [12]: print(df)
  bonusimpdate bonusskaccday bonussklistdate bonusskratio bonusyear  cdividend      ...      symbol taxcdividend taxfdividendbh tranaddskaccday  tranaddsklistdate tranaddskraio
0     20180504          None            None         None      2017        1.2      ...        None        1.200            0.0            None               None           NaN
1     20170602          None            None         None      2016        0.3      ...        None        0.300            0.0            None               None           NaN
2     20160513          None            None         None      2015        0.3      ...        None        0.300            0.0            None               None           NaN
3     20150520          None            None         None      2014        2.0      ...        None        1.900            0.0            None               None           NaN
4     20140531          None            None         None      2013        2.5      ...        None        2.375            0.0        20140609           20140609           5.0
5     20130522          None            None         None      2012        2.5      ...        None        2.375            0.0        20130528           20130528           3.0
6     20120410          None            None         None      2011        3.0      ...        None        2.700            0.0        20120417           20120417          10.0
7     20110414          None            None         None      2010        8.0      ...        None        7.200            0.0        20110421           20110421          10.0
8     20100603          None            None         None      2009        6.0      ...        None        5.400            0.0            None               None           NaN

[9 rows x 20 columns]

In [13]:

Notebook 使用

根据 Async Notebook 的问题 ,需要升级到最新版本的 Notebook ,并使用异步数据获取接口。

使用Notebook的例子

实时分析模式

在你的分析框架中直接通过导入 fintie 后调用 api 来获取数据并分析。

fintie.stock

fintie.stock.hist_quotes

行情获取模块

本模块负责获取股票的历史交易行情信息。

获取通道包括:

Get https://stock.xueqiu.com/v5/stock/chart/kline.json

params:

"symbol": 代码
"begin": 时间戳
"period": 频率,
"type": 复权类型,
"count": 数量,
"indicator": "kline,ma,macd,kdj,boll,rsi,wr,bias,cci,psy",

加载:

from pathlib import Path
import pandas as pd

with Path('data.json').open(encoding="utf-8") as f:
    quotes = json.load(f)

df = pd.DataFrame(data=quotes['item'], column=quotes['column'])
df.timestamp = pd.to_datetime(df.timestamp, unit='ms')
df.set_index('timestamp', inplace=True)

TODO

async fintie.stock.hist_quotes.async_get_hist_quotes(session, symbol, ref_dt, count=100, freq='1m', fq_type='before', data_path=None, return_df=True)[源代码]

小于 day 频率的数据,会有时间限制,只能取最近的数据,请谨慎使用

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码,如 SZ002353

  • ref_dt – 行情数据参考日期,count 传负是截止日期,传正为开始日期

  • count – 要取的行情数据的条数

  • freq – 数据频率:1m/5m/15m/30m/60m/120m/day/week/month/quarter/year

  • fq_type – before/after/normal 前复权、后复权、不复权

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

行情原始数据或带有行情数据的 pandas.DataFrame 对象,见 return_df 参数

fintie.stock.hist_quotes.get_hist_quotes(*args, **kwargs)[源代码]

小于 day 频率的数据,会有时间限制,只能取最近的数据,请谨慎使用

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码,如 SZ002353

  • ref_dt – 行情数据参考日期,count 传负是截止日期,传正为开始日期

  • count – 要取的行情数据的条数

  • freq – 数据频率:1m/5m/15m/30m/60m/120m/day/week/month/quarter/year

  • fq_type – before/after/normal 前复权、后复权、不复权

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

行情原始数据或带有行情数据的 pandas.DataFrame 对象,见 return_df 参数

fintie.stock.list_quotes

获取市场行情一览

信息获取通道包括:

加载已保存的数据:

import pandas as pd
from pathlib import Path

df = pd.read_json(Path('20181018165415.json')
df.set_index(["symbol"], inplace=True)
# df.drop_duplicates(inplace=True)
df.apply(pd.to_numeric, errors="coerce") # convert to numertic types

# df['day'] = date.today()
# df["day"] = datetime.now().replace(hour=16, minute=0, second=0, microsecond=0)
# set index
# df.set_index(["symbol", "day"], inplace=True)
async fintie.stock.list_quotes.async_get_list_qutes(session, data_type='stock', data_path=None, return_df=True)[源代码]

获取每日行情概览信息,只能获取当天的 返回一个 pd.DataFrame 出错,返回 None

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_type – stock: 沪深股票 cb: 可转债 eft: ETF基金 fenji: 分级基金

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

行情原始数据或带有行情数据的 pandas.DataFrame 对象,见 return_df 参数

fintie.stock.list_quotes.get_list_quotes(*args, **kwargs)[源代码]

获取每日行情概览信息,只能获取当天的 返回一个 pd.DataFrame 出错,返回 None

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_type – stock: 沪深股票 cb: 可转债 eft: ETF基金 fenji: 分级基金

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

行情原始数据或带有行情数据的 pandas.DataFrame 对象,见 return_df 参数

fintie.stock.live_quotes

本模块负责获取股票的历史交易行情信息。

获取通道包括:

数据加载

trades:

import json
from pathlib import Path

import pandas as pd

with Path('SZ002353-trade-20181019201938.json').open(encoding="utf-8") as f:
    quotes = json.load(f)

df = pd.DataFrame(data=quotes["items"])
df.timestamp = pd.to_datetime(df.timestamp, unit="ms")
df.set_index("timestamp", inplace=True)

TODO:

  • add default http headers

    headers = {“X-Forwarded-For”: ipAddress}

async fintie.stock.live_quotes.async_get_trade_info(session, symbol, data_path=None, return_df=True)[源代码]

获取最近的交易记录

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

行情原始数据或带有行情数据的 pandas.DataFrame 对象,见 return_df 参数

async fintie.stock.live_quotes.async_get_pankou(session, symbol, data_path=None)[源代码]

获取最新的盘口数据 :param session: aiohttp.ClientSession 对象,同步接口不需要传 :param symbol: 股票代码 :param data_path: 数据保存路径

返回

盘口数据 dict

async fintie.stock.live_quotes.async_get_live_info(session, symbol, data_path=None)[源代码]

获取最新的基本信息,包括最新价格市值等

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

返回

基本信息数据 dict

fintie.stock.live_quotes.get_trade_info(*args, **kwargs)[源代码]

获取最近的交易记录

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

行情原始数据或带有行情数据的 pandas.DataFrame 对象,见 return_df 参数

fintie.stock.live_quotes.get_pankou(*args, **kwargs)[源代码]

获取最新的盘口数据 :param session: aiohttp.ClientSession 对象,同步接口不需要传 :param symbol: 股票代码 :param data_path: 数据保存路径

返回

盘口数据 dict

fintie.stock.live_quotes.get_live_info(*args, **kwargs)[源代码]

获取最新的基本信息,包括最新价格市值等

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

返回

基本信息数据 dict

fintie.stock.fundamentals

本模块负责获取上市公司财务数据,包含利润、资产负债、现金流量三大表及摘要和主要财务指标。

信息获取通道包括:

加载已保存数据:

import pandas as pd
from pathlib import Path
df = pd.read_csv(Path("xxx.json"), index_col=0)
async fintie.stock.fundamentals.async_get_funda_tab(session, symbol, tab_name, return_df=True)[源代码]

获取某表的财务数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • tab_name – lrb/zcfzb/xjllb/cwbbzy/zycwzb

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始财务数数据或带有财务数据的 pandas.DataFrame 对象,见 return_df 参数

async fintie.stock.fundamentals.async_get_fundamentals(session, symbols, data_path)[源代码]

获取财务数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

返回

Nothing

fintie.stock.fundamentals.get_funda_tab(*args, **kwargs)[源代码]

获取某表的财务数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • tab_name – lrb/zcfzb/xjllb/cwbbzy/zycwzb

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始财务数数据或带有财务数据的 pandas.DataFrame 对象,见 return_df 参数

fintie.stock.fundamentals.get_fundamentals(*args, **kwargs)[源代码]

获取财务数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

返回

Nothing

fintie.stock.fundamentals_xq

提供股本信息查询

信息获取通道包括:

加载已保存的数据:

# 主要财务指标/单季财务指标/综合损益表/资产负债表/现金流量表

import pandas as pd
from pathlib import Path

df = pd.read_json(Path('xxx.json')
# optional, set index
if "reportdate" if df:
    df.set_index("reportdate", inplace=True)
else:
    df.set_index("enddate", inplace=True)
    or
    df.set_index("begindate", inplace=True)

# 当日财务指标/股票收益率指标
import json

from pathlib import Path
with Path("xxx.json").open(encoding="utf-8") as f:
    data = json.load(f)
async fintie.stock.fundamentals_xq.async_get_funda(session, symbol, table, data_path=None, return_df=True)[源代码]

从雪球获取财务数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • table

    财务数据类型

    MRCWZB # 当日财务指标 GPSYLZB # 股票收益率指标 ZYCWZB # 主要财务指标 DJCWZB # 单季财务指标 GSLRB # 综合损益表 ZCFZB # 资产负债表 XJLLB # 现金流量表

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 如果是 MRCWZB/GPSYLZB table,直接返回字典,reture_df 参数无效 失败则返回 None

fintie.stock.fundamentals_xq.get_funda(*args, **kwargs)[源代码]

从雪球获取财务数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • table

    财务数据类型

    MRCWZB # 当日财务指标 GPSYLZB # 股票收益率指标 ZYCWZB # 主要财务指标 DJCWZB # 单季财务指标 GSLRB # 综合损益表 ZCFZB # 资产负债表 XJLLB # 现金流量表

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 如果是 MRCWZB/GPSYLZB table,直接返回字典,reture_df 参数无效 失败则返回 None

fintie.stock.mkt_calendar

每日市场事件

获取每日市场事件,事件类型包括:

  • 停牌、复牌

  • 首发新股上市

  • 首发新股招股书刊登

  • 首发新股网上发行

  • 中签率公告

  • 授予股份上市

  • 股东资格登记

  • 股东大会召开

  • 网络投票开始、网络投票结束

  • 分红转增股权登记、分红转增除权除息、分红转增红利发放、分红转增股份上市

  • 增发新股招股书刊登

等,信息获取通道包括:

加载已保存的数据:

import json

from pathlib import Path
with Path("xxx.json").open(encoding="utf-8") as f:
    data = json.load(f)
async fintie.stock.mkt_calendar.async_get_market_events(session, start, end, data_path=None)[源代码]

从巨潮信息网获取某天的交易日历

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • start – 日历数据开始时间

  • end – 日历数据结束时间

  • data_path – 数据保存路径

返回

日历数据 dict

fintie.stock.mkt_calendar.get_market_events(*args, **kwargs)[源代码]

从巨潮信息网获取某天的交易日历

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • start – 日历数据开始时间

  • end – 日历数据结束时间

  • data_path – 数据保存路径

返回

日历数据 dict

fintie.stock.picker_xq

提供选股器接口

信息获取通道包括:

沪深选股参数说明

对于不需要过滤但需要返回的字段请传递 field=ALL ,否则对应字段的值也不会返回

加载已保存的数据:

import pandas as pd
from pathlib import Path

df = pd.read_json(Path('20181018165415.json')
df.set_index(["symbol"], inplace=True)
# df.drop_duplicates(inplace=True)
df.apply(pd.to_numeric, errors="coerce") # convert to numertic types

# df['day'] = date.today()
# df["day"] = datetime.now().replace(hour=16, minute=0, second=0, microsecond=0)
# set index
# df.set_index(["symbol", "day"], inplace=True)
async fintie.stock.picker_xq.async_get_field_values(session, field, return_df=True)[源代码]

https://xueqiu.com/stock/screener/values.json?category=SH&field=pettm&_=1540617201640 获取该字段值的列表

async fintie.stock.picker_xq.async_pick_stocks(session, filter_dict=None, data_path=None, return_df=True)[源代码]

雪球选股器接口,此接口支持的参数较多,具体请参考 API 文档

返回一个 pd.DataFrame 出错,返回 None

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • filter_dict – 需要的字段及过滤条件,支持的字段名见 API 文档

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

行情原始数据或带有行情数据的 pandas.DataFrame 对象,见 return_df 参数

取值方法 GET https://xueqiu.com/stock/screener/screen.json

filter_dict:

  • category: SH/US – 沪深/美股 required

  • orderby:symbol – 排序字段 required

  • oder:desc – 升降排序 required

  • exchange: SH/SZ – 沪市/深市

  • areacode: 地域板块

  • indcode: 行业

  • filter_fileds: min_max

  • current:ALL 当前价

  • pct:ALL 本日涨跌幅

  • volume:ALL 本日成交量

  • page:1

  • size: 30

  • _:timestamp

fintie.stock.picker_xq.pick_stocks(*args, **kwargs)[源代码]

雪球选股器接口,此接口支持的参数较多,具体请参考 API 文档

返回一个 pd.DataFrame 出错,返回 None

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • filter_dict – 需要的字段及过滤条件,支持的字段名见 API 文档

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

行情原始数据或带有行情数据的 pandas.DataFrame 对象,见 return_df 参数

取值方法 GET https://xueqiu.com/stock/screener/screen.json

filter_dict:

  • category: SH/US – 沪深/美股 required

  • orderby:symbol – 排序字段 required

  • oder:desc – 升降排序 required

  • exchange: SH/SZ – 沪市/深市

  • areacode: 地域板块

  • indcode: 行业

  • filter_fileds: min_max

  • current:ALL 当前价

  • pct:ALL 本日涨跌幅

  • volume:ALL 本日成交量

  • page:1

  • size: 30

  • _:timestamp

fintie.stock.fenhong

提供分红送配股信息查询

信息获取通道包括:

加载已保存的数据:

import pandas as pd
from pathlib import Path

df = pd.read_json(Path('xxx.json')
async fintie.stock.fenhong.async_get_fhsp(session, symbol, data_path=None, return_df=True)[源代码]

从雪球获取分红送配股数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.fenhong.get_fhsp(*args, **kwargs)[源代码]

从雪球获取分红送配股数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.guben

提供分红送配股信息查询

信息获取通道包括:

加载已保存的数据:

import pandas as pd
from pathlib import Path

df = pd.read_json(Path('xxx.json')
async fintie.stock.guben.async_get_guben(session, symbol, data_path=None, return_df=True)[源代码]

从雪球获取分红送配股数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.guben.get_guben(*args, **kwargs)[源代码]

从雪球获取分红送配股数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.gudong

提供股东信息查询

信息获取通道包括:

加载已保存的数据:

import json
import pandas as pd
from pathlib import Path

with Path('xxx.json').open(encoding="utf-8") as f:
    data = json.load(f)

# 股东户数统计
df = pd.read_json(Path('xxx.json')
async fintie.stock.gudong.async_get_gudong_count(session, symbol, data_path=None, return_df=True)[源代码]

从雪球获取股东户数数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

async fintie.stock.gudong.async_get_gudong(session, symbol, gd_type, data_path=None)[源代码]

从雪球获取股东数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • gd_type

    股东类型

    • main 主要股东

    • public 流通股东

    • limit 限售股东

  • data_path – 数据保存路径

返回

原始数据 dict 失败则返回 None

fintie.stock.gudong.get_gudong(*args, **kwargs)[源代码]

从雪球获取股东数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • gd_type

    股东类型

    • main 主要股东

    • public 流通股东

    • limit 限售股东

  • data_path – 数据保存路径

返回

原始数据 dict 失败则返回 None

fintie.stock.gudong.get_gudong_count(*args, **kwargs)[源代码]

从雪球获取股东户数数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.zengfa

提供分红送配股信息查询

信息获取通道包括:

加载已保存的数据:

import pandas as pd
from pathlib import Path

df = pd.read_json(Path('xxx.json')
async fintie.stock.zengfa.async_get_zengfa(session, symbol, data_path=None, return_df=True)[源代码]

从雪球获取增发数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.zengfa.get_zengfa(*args, **kwargs)[源代码]

从雪球获取增发数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.insider

提供内部交易信息查询

信息获取通道包括:

加载已保存的数据:

import pandas as pd
from pathlib import Path

df = pd.read_json(Path('xxx.json')
async fintie.stock.insider.async_get_inside_trade(session, symbol, data_path=None, return_df=True)[源代码]

从雪球获取内部交易数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.insider.get_inside_trade(*args, **kwargs)[源代码]

从雪球获取内部交易数据

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • data_path – 数据保存路径

  • return_df – 是否返回 pandas.DataFrame 对象,False 返回原始数据

返回

原始数据或 pandas.DataFrame 对象,见 return_df 参数, 失败则返回 None

fintie.stock.announcement

本模块负责获取上市公司公告文件

信息获取通道:

post http://www.cninfo.com.cn/cninfo-new/announcement/query

post form:

category: category_ndbg_szsh;category_bndbg_szsh;
column:
limit:
pageNum: 1
pageSize: 30
searchkey: // 搜索关键字
seDate: // 查询日期: 2018-07-28 或者 2018-03-13+~+2018-07-28
sortName:
sortType:
stock: 300121
tabName: fulltext

category 类型

  • name=”category_ndbg_szsh” title=”年度报告”

  • name=”category_bndbg_szsh” title=”半年度报告”

  • name=”category_yjdbg_szsh” title=”一季度报告”

  • name=”category_sjdbg_szsh” title=”三季度报告”

  • name=”category_scgkfx_szsh” title=”首次公开发行及上市”

  • name=”category_pg_szsh” title=”配股”

  • name=”category_zf_szsh” title=”增发”

  • name=”category_kzhz_szsh” title=”可转换债券”

  • name=”category_qzxg_szsh” title=”权证相关公告”

  • name=”category_qtrz_szsh” title=”其他融资”

  • name=”category_qyfpxzcs_szsh” title=”权益及限制出售股份”

  • name=”category_gqbd_szsh” title=”股权变动”

  • name=”category_jy_szsh” title=”交易”

  • name=”category_gddh_szsh” title=”股东大会”

  • name=”category_cqfxyj_szsh” title=”澄清风险业绩预告”

  • name=”category_tbclts_szsh” title=”特别处理和退市”

  • name=”category_bcgz_szsh” title=”补充及更正”

  • name=”category_zjjg_szsh” title=”中介机构报告”

  • name=”category_ssgszd_szsh” title=”上市公司制度”

  • name=”category_zqgg_szsh” title=”债券公告”

  • name=”category_qtzdsx_szsh” title=”其它重大事项”

  • name=”category_tzzgx_szsh” title=”投资者关系信息”

  • name=”category_dshgg_szsh” title=”董事会公告”

  • name=”category_jshgg_szsh” title=”监事会公告”

加载已保存的数据:

import json

from pathlib import Path
with Path("xxx.json").open(encoding="utf-8") as f:
    data = json.load(f)
async fintie.stock.announcement.async_get_announcements(session, symbol, categories, data_path, start_date=None, end_date=None, search_key='')[源代码]

获取公告文件

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • categories – 公告文件类别

  • data_path – 数据保存路径

  • start_date – 公共查询起始时间

  • end_date – 公告查询截止时间

  • search_key – 公告查询搜索关键字

返回

None 接口用于下载公告原文进行人工分析,不返回任何数据

catetories:

all         所有类别
ndbg        年度报告
bndbg       半年度报告
yjdbg       一季度报告
sjdbg       三季度报告
scgkfx      首次公开发行及上市
pg          配股
zf          增发
kzhz        可转换债券
qzxg        权证相关公告
qtrz        其他融资
qyfpxzcs    权益及限制出售股份
gqbd        股权变动
jy          交易
gddh        股东大会
cqfxyj      澄清风险业绩预告
tbclts      特别处理和退市
bcgz        补充及更正
zjjg        中介机构报告
ssgszd      上市公司制度
zqgg        债券公告
qtzdsx      其它重大事项
tzzgx       投资者关系信息
dshgg       董事会公告
jshgg       监事会公告
fintie.stock.announcement.get_announcements(*args, **kwargs)[源代码]

获取公告文件

参数
  • sessionaiohttp.ClientSession 对象,同步接口不需要传

  • symbol – 股票代码

  • categories – 公告文件类别

  • data_path – 数据保存路径

  • start_date – 公共查询起始时间

  • end_date – 公告查询截止时间

  • search_key – 公告查询搜索关键字

返回

None 接口用于下载公告原文进行人工分析,不返回任何数据

catetories:

all         所有类别
ndbg        年度报告
bndbg       半年度报告
yjdbg       一季度报告
sjdbg       三季度报告
scgkfx      首次公开发行及上市
pg          配股
zf          增发
kzhz        可转换债券
qzxg        权证相关公告
qtrz        其他融资
qyfpxzcs    权益及限制出售股份
gqbd        股权变动
jy          交易
gddh        股东大会
cqfxyj      澄清风险业绩预告
tbclts      特别处理和退市
bcgz        补充及更正
zjjg        中介机构报告
ssgszd      上市公司制度
zqgg        债券公告
qtzdsx      其它重大事项
tzzgx       投资者关系信息
dshgg       董事会公告
jshgg       监事会公告

fintie.stock.utils

fintie.stock.utils.filter_by_symbol(df, symbol_type='ALL', market='ALL')[源代码]

根据 symbol 过滤返回符合条件的数据

df 至少应包含 symbol 列,该列类型为字符串,内容规则如下:

  • SHxxxxxx 上海股票交易所代码

  • SZxxxxxx 深圳股票交易所代码

symbol_type: ASTOCKS/BSTOCKS/INDEX/ETF/CB/ALL

  • ASTOCKS: A股股票

  • BSTOCKS: B股股票

  • INDEX: 指数

  • ETF: ETF基金

  • CB: CONVERTIBLE BONDS,可转债

market: SZ/SH/ALL

  • SZ: 深圳股票交易所

  • SH: 上海股票交易所

  • ALL: 所有

股票代码

  • 上海证券交易所

    首位代码

    产品定义

    0

    国债/指数

    00

    上证指数、沪深300指数、中证指数

    债券

    回购

    期货

    备用

    基金/权证

    A股

    非交易业务(发行、权益分配)

    备用

    B股

  • 深圳证券交易所

    首位代码

    产品定义

    00

    A股证券

    002~004

    中小板

    1

    债券

    2

    B股

    30

    创业板证券

    39

    综合指数、成份指数

fintie.utils

fintie.utils.convert_number(num_str, cls=<class 'int'>)[源代码]

带逗号格式的数值字符串转为数值类型

Params num_str

数值字符串

Params cls

数值类型,默认为 int

返回

cls 类型的数值

fintie.utils.iter_dt(start_dt, end_dt, include_start=True, include_end=False, **kwargs)[源代码]

按步进值迭代一个日期范围的 Generator ,默认步进值是一天

NOTICE 如果需要迭代的步进值小于一天,请传递 datetime 类型

Params start_date

开始日期

Params end_date

结束日期

Params include_start

是否包含开始时间

Params include_end

是否包含结束时间

Params kwargs

传递给 dateutil.relativedelta 的参数,用于计算步进值

fintie.utils.parse_dt(date_str, return_date=False)[源代码]

解析字符串为 Date 类型,失败报 TypeError/ValueError 异常

Params date_str

要解析的时间日期字符串

Params return_date

如果为 True 返回 datetime.date 类型,否则返回 datetime.datetime

返回

datetime 如果 return_date 是 False ,否则返回 date

fintie.utils.async2sync_run(*aws, return_exceptions=True)[源代码]

将异步函数转为同步函数

Params aws

异步协程列表

Params return_exceptions

是否运行返回异常,不 允许的话任何一个协程异常都会导致本函数异常

返回

一个列表包含了所有协程的返回值

fintie.utils.fetch_http_data(func, *args, **kwargs)[源代码]

将异步的http取数据接口转为同步方式

fintie.utils.add_doc(doc)[源代码]

一个给函数添加文档字符串的装饰器函数

TODO

股票停复牌数据

queryType1 – 所有停牌信息 其他 type 未知

curl 'http://www.cninfo.com.cn/cninfo-new/memo-2?queryDate=2017-06-14&queryType=queryType1' -H 'Host: www.cninfo.com.cn' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: http://www.cninfo.com.cn/cninfo-new/memo-2' -H 'Cookie: JSESSIONID=74E33FB2153B4B12DE227654C18AA7CF; JSESSIONID=62A5434F4C65CBE37E5582D131F49576; cninfo_search_record_cookie=%E8%B4%B5%E5%B7%9E%E8%8C%85%E5%8F%B0' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1'

股票行业、概念数据

沪深港通成交统计信息

上市公司更名数据获取

融资融券成交统计信息

限售解禁信息获取

券商研报

期货数据

宏观数据

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/msgroup/fintie/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.

  • Any details about your local setup that might be helpful in troubleshooting.

  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

fintie could always use more documentation, whether as part of the official fintie docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/qytz/fintie/issues.

If you are proposing a feature:

  • Explain in detail how it would work.

  • Keep the scope as narrow as possible, to make it easier to implement.

  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up fintie for local development.

  1. Fork the fintie repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/fintie.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv fintie
    $ cd fintie/
    $ python setup.py develop
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ flake8 fintie tests
    $ python setup.py test or py.test
    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  7. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.

  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.

  3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check https://travis-ci.org/qytz/fintie/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ python -m unittest tests.test_fintie

AUTHORS

fintie is written and maintained by qytz and various contributors:

Development Lead

Patches and Suggestions

None yet. Why not be the first?

RELEASE LOG

0.1.3(2018-11-11)

  • 修复 setup.py 文件,支持windows安装

  • 修复打开文件操作,传递 encoding 参数,支持非英文 windows 使用

  • 修复配置文件警告,非命令行模式不再读取配置文件

0.1.2(2018-10-30)

  • 优化雪球选股器,修改接口传入方式,补充文档

  • 修复新版研究中使用

  • 完善使用文档

  • 修复 setup.py 依赖

0.1.1(2018-10-27)

  • 搭建程序框架

  • 支持如下股票数据获取:

    • 历史行情

    • 实时市场行情一览

    • 单股票实时行情(包括最近的盘口、成交记录、实时的部分指标)

    • 从网易财经获取的财报

    • 从雪球获取的财报及其他财务指标

    • 巨潮信息的日历事件

    • 雪球选股器

    • 分红送配数据

    • 股本结构数据

    • 股东数据

    • 股票增发

    • 股票内部交易

    • 公告原文获取

Indices and tables