Project Icon

finviz

FinViz非官方Python API实现金融数据分析

finviz-api是FinViz金融网站的非官方Python接口,提供股票筛选、投资组合管理和个股分析等功能。支持下载图表、导出数据,并可获取内部交易和分析师目标价信息。数据有15-20分钟延迟,主要用于金融分析和研究,不适合实时交易。使用需遵守FinViz服务条款。

finviz-api ########## Unofficial Python API for FinViz

.. image:: https://badge.fury.io/py/finviz.svg :target: https://badge.fury.io/py/finviz

.. image:: https://img.shields.io/badge/python-3.9-blue.svg :target: https://www.python.org/downloads/release/python-390/

.. image:: https://pepy.tech/badge/finviz :target: https://pepy.tech/project/finviz

Downloading & Installation

$ pip install -U git+https://github.com/mariostoev/finviz

What is Finviz?

FinViz_ aims to make market information accessible and provides a lot of data in visual snapshots, allowing traders and investors to quickly find the stock, future or forex pair they are looking for. The site provides advanced screeners, market maps, analysis, comparative tools, and charts.

.. _FinViz: https://finviz.com/?a=128493348

Important Information

Any quotes data displayed on finviz.com is delayed by 15 minutes for NASDAQ, and 20 minutes for NYSE and AMEX. This API should NOT be used for live trading, it's main purpose is financial analysis, research, and data scraping.

Using Screener

Before using the Screener class, you have to manually go to the website's screener and enter your desired settings. The URL will automatically change every time you add a new setting. After you're done the URL will look something like this:

.. image:: https://i.imgur.com/p8BLt06.png

?v=111&s=ta_newhigh&f=cap_largeover,exch_nasd,fa_fpe_o10&o=-ticker&t=ZM are the extra parameters provided to the screener. Those parameters are a list of key/value pairs separated with the & symbol. Some keys have a clear intent - f=cap_largeover,exch_nasd,fa_fpe_o10 are filters, o=-ticker is order and t=ZM are tickers - yet, some are ambiguous like v=111, which stands for the type of table.

To make matters easier inside the code you won't refer to tables by their number tag, but instead you will use their full name (ex. table=Performance).

.. code:: python

from finviz.screener import Screener

filters = ['exch_nasd', 'idx_sp500']  # Shows companies in NASDAQ which are in the S&P500
stock_list = Screener(filters=filters, table='Performance', order='price')  # Get the performance table and sort it by price ascending

# Export the screener results to .csv 
stock_list.to_csv("stock.csv")

# Create a SQLite database 
stock_list.to_sqlite("stock.sqlite3")

for stock in stock_list[9:19]:  # Loop through 10th - 20th stocks 
    print(stock['Ticker'], stock['Price']) # Print symbol and price

# Add more filters
stock_list.add(filters=['fa_div_high'])  # Show stocks with high dividend yield
# or just stock_list(filters=['fa_div_high'])

# Print the table into the console
print(stock_list)

.. image:: https://i.imgur.com/cb7UdxB.png

Using Portfolio

.. code:: python

from finviz.portfolio import Portfolio

portfolio = Portfolio('<your-email-address>', '<your-password>', '<portfolio-name>')
# Print the portfolio into the console
print(portfolio)

Note that, portfolio name is optional - it would assume your default portfolio (if you have one) if you exclude it. The Portfolio class can also create new portfolio from an existing .csv file. The .csv file must be in the following format:

.. list-table:: :header-rows: 1

    • Ticker
    • Transaction
    • Date (Opt.)
    • Shares
    • Price (Opt.)
    • AAPL
    • 1
    • 05-25-2017
    • 34
    • 141.28
    • NVDA
    • 2
    • 250
    • 243.32
    • WMT
    • 1
    • 01.19.2019
    • 45

Note that, if any optional fields are left empty, the API will assign them today's data.

.. code:: python

portfolio.create_portfolio('<portfolio-name>', '<path-to-csv-file>')

Individual stocks

.. code:: pycon

>>> import finviz
>>> finviz.get_stock('AAPL')
{'Index': 'DJIA S&P500', 'P/E': '12.91', 'EPS (ttm)': '12.15',...
>>> finviz.get_insider('АAPL')
[{'Insider Trading': 'KONDO CHRIS', 'Relationship': 'Principal Accounting Officer', 'Date': 'Nov 19', 'Transaction':            'Sale', 'Cost': '190.00', '#Shares': '3,408', 'Value ($)': '647,520', '#Shares Total': '8,940', 'SEC Form 4': 'Nov 21           06:31 PM'},...
>>> finviz.get_news('AAPL')
[('Chinas Economy Slows to the Weakest Pace Since 2009', 'https://finance.yahoo.com/news/china-economy-slows-weakest-pace-      020040147.html'),...
>>>
>>> finviz.get_analyst_price_targets('AAPL')
[{'date': '2019-10-24', 'category': 'Reiterated', 'analyst': 'UBS', 'rating': 'Buy', 'price_from': 235, 'price_to': 275}, ...

Downloading charts

.. code:: python

# Monthly, Candles, Large, No Technical Analysis
stock_list.get_charts(period='m', chart_type='c', size='l', ta='0')

# period='d' > daily 
# period='w' > weekly
# period='m' > monthly

# chart_type='c' > candle
# chart_type='l' > lines

# size='m' > small
# size='l' > large

# ta='1' > display technical analysis
# ta='0' > ignore technical analysis

Environment Variables

Set DISABLE_TQDM=1 in your environment to disable the progress bar.

Documentation

You can read the rest of the documentation inside the docstrings.

Contributing

You can contribute to the project by reporting bugs, suggesting enhancements, or directly by extending and writing features (see the ongoing projects_).

.. _projects: https://github.com/mariostoev/finviz/projects/1

You can also buy me a coffee!

.. image:: https://user-images.githubusercontent.com/8982949/33011169-6da4af5e-cddd-11e7-94e5-a52d776b94ba.png :target: https://www.paypal.me/finvizapi

Disclaimer

Using the library to acquire data from FinViz is against their Terms of Service and robots.txt. Use it responsibly and at your own risk. This library is built purely for educational purposes.

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号