Are you looking to gain deeper insights into the stock market using the FinViz Unofficial Python API? Look no further! This guide will lead you through the installation process, how to utilize the screener and portfolio features, and offer troubleshooting options along the way. Let’s dive in!
What is FinViz?
FinViz aims to make market information accessible, providing a wealth of data in visual snapshots. The platform allows traders and investors to quickly identify stocks, futures, or forex pairs they are interested in. It offers advanced screeners, market maps, analysis tools, and charts. You can discover more at FinViz.
Installation
To get started with the API, you’ll first need to install it. Open your terminal and run:
$ pip install -U git+https://github.com/mariostoev/finviz
Using the Screener
The Screener class allows you to filter stocks based on your specific settings. Before using this class, you’ll need to set your desired parameters on the FinViz screener on their website. The URL will alter to reflect your chosen configurations. Think of it as preparing a recipe; you gather the ingredients (filters) to whip up a detailed stock list.
The URL might end up looking something like this: https://finviz.com/screener.ashx?v=111&f=cap_largeover,exch_nasd,fa_fpe_o10&t=ZM where:
- f=cap_largeover: A filter for stocks with a large market cap.
- o=-ticker: Indicates the order in which the stocks should be listed.
- t=ZM: Represents tickers of interest.
Here’s a sample code to utilize the Screener:
from finviz.screener import Screener
filters = [exch_nasd, idx_sp500] # Shows companies in NASDAQ which are in the SP500
stock_list = Screener(filters=filters, table=Performance, order=price) # Get performance table sorted by price
stock_list.to_csv(stock.csv) # Export results to .csv
stock_list.to_sqlite(stock.sqlite3) # Create a SQLite database
for stock in stock_list[9:19]: # Print symbol and price for stocks 10-20
print(stock[Ticker], stock[Price])
stock_list.add(filters=[fa_div_high]) # Show stocks with high dividend yield
print(stock_list) # Print the table to the console
Using the Portfolio Feature
The Portfolio class lets you manage your investment holdings. Here’s how to use it:
from finviz.portfolio import Portfolio
portfolio = Portfolio(your-email-address, your-password, portfolio-name) # Print portfolio into the console
print(portfolio)
You can also create a portfolio from a .csv file formatted like this:
**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 blank, the API will automatically populate them with today’s data.
Getting Individual Stock Information
The API allows you to retrieve various information regarding individual stocks:
import finviz
finviz.get_stock(AAPL) # Get stock info
finviz.get_insider(AAPL) # Get insider trading info
finviz.get_news(AAPL) # Get recent news
finviz.get_analyst_price_targets(AAPL) # Get analyst price targets
Downloading Charts
To visualize your stock data through charts, use the following code:
stock_list.get_charts(period=m, chart_type=c, size=l, ta=0) # Download charts
Here, you can specify the period (daily, weekly, monthly), the type of chart (candles or lines), size, and whether to include technical analysis.
Environment Variables
If you’d like to disable progress bar notifications, set the environment variable DISABLE_TQDM=1.
Troubleshooting
Getting stuck? Here are some common issues and solutions:
- Installation Issues: Ensure that your Python version is compatible. You can check for the latest update at Python 3.9.
- Data Retrieval: Remember that quotes data is delayed (15 minutes for NASDAQ, 20 minutes for NYSE and AMEX) and should not be used for live trading.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Final Thoughts
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

