finviz

finviz

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

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

FinvizPython API股票筛选金融数据市场分析Github开源项目

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.

编辑推荐精选

问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

下拉加载更多