Select Page

A few months ago I challenged myself to develop a simple Pre-market scanner without spending any money on subscriptions or APIs. I was able to do this using the web scraping technique. I blogged about this on How to Code your own Pre-market Stocks Scanner Web application (Using Python). Aside from Benzinga, I found another website that displays a list of highest pre-market gainers, TheStockCatalyst.com. It displays the recent headlines to hopefully give the viewers “an indication why the stock is moving“.

However, sometimes there is no Recent Headlines from TheStockCatalyst.com causing the scanner results to display no news. I had to manually search the web to find out the reason of price increase.

In order to fix this, I did my research on where to get real-time stock market news for stock tickers programmatically. There are free REST API endpoints and there are also paid API subscriptions that offers core services such as Market Data, Historical Data, etc. and they include News API endpoint(s).

Free Resources

ResourceSample LinkNotes
Google Newshttps://news.google.com/rss/search?q=AAPLWrite a program that will consume RSS feed, sort and filter the results.
Yahoo Financehttps://query2.finance.yahoo.com/v1/finance/search?q=AAPLExtract the news element in the JSON result.
Other Yahoo Finance endpoints can be found by looking at the source codes of popular Python library YFinance.
Bing News SearchDocumentation is in https://docs.microsoft.com/en-us/azure/cognitive-services/bing-news-search/search-the-web
Twitterhttps://twitter.com/search?q=%24AAPLMost tweets may not be relevant. Parsing the results may be difficult. Twitter API may be worth looking at.

Stock Market API Paid Subscriptions

Subscription
(alpabetical order)
PricingSubscription feeThreshold calls for real-time dataAPI Developer Documentation
Alpacahttps://app.alpaca.markets/brokerage/new-account/data-subscription$99/month1000 API calls / minutehttps://alpaca.markets/docs/api-references/market-data-api/news-data/realtime/
Alpha Vantagehttps://www.alphavantage.co/premium/$49.99/month75 API requests per minute
https://www.alphavantage.co/documentation/#fundamentals
EOD Historical Datahttps://eodhistoricaldata.com/pricing$79.99/month1000 API calls per minutehttps://eodhistoricaldata.com/financial-apis/stock-market-financial-news-api/
https://eodhistoricaldata.com/financial-apis/stock-market-financial-news-api
Financial Modeling Prephttps://site.financialmodelingprep.com/developer/docs/pricing/$10.50/month300 API requests per minutehttps://site.financialmodelingprep.com/developer/docs/#Stock-News
Finnhubhttps://finnhub.io/pricing-fundamental-data$50/month/market300 API calls/minutehttps://finnhub.io/docs/api/company-news
FMPCloudhttps://fmpcloud.io/plans$14/month300 API calls / minutehttps://fmpcloud.io/documentation/#stockNews
IEX Cloudhttps://www.iexcloud.io/pricing/$49/month5k records per secondhttps://www.iexcloud.io/docs/iex-exchange
Intriniohttps://intrinio.com/pricing$100/monthhttps://docs.intrinio.com/documentation/api_v2/getting_started
MarketStackhttps://marketstack.com/product$49.99/month100,000 requests / monthhttps://marketstack.com/documentation
Polygonhttps://polygon.io/pricing
$29/monthUnlimited API callshttps://polygon.io/docs/stocks/get_v2_reference_news
Tiingohttps://api.tiingo.com/about/pricing$10/month5000 requests per dayhttps://api.tiingo.com/documentation/news
Twelve Datahttps://twelvedata.com/pricing$79/monthNo daily API limitshttps://twelvedata.com/docs

If you want to avail of paid subscription(s), the subscription fee should not be the top criteria. It is also important that the news that the API shows should be relevant and current.

Code for Getting News List for a Ticker (Using Alpaca REST API):

Since I already subscribed to Alpaca, I use their endpoint to retrieve the latest news of a certain tickers.

import alpaca_trade_api as tradeapi
import os


API_KEY = os.environ.get('APCA_API_KEY_ID')
API_SECRET_KEY = os.environ.get('APCA_API_SECRET_KEY')
ticker = 'AAPL'
api = tradeapi.REST(API_KEY, API_SECRET_KEY, NEWS_URL, api_version='v2')
news_list = api.get_news(ticker
news_link = ''

for news_ctr in range(len(news_list)):
    news_obj = news_list[news_ctr]
    news_link += f"<a href=\'{news_obj.url}\' target='_blank'>{news_obj.headline} [{news_obj.updated_at}]</a><br/><br/>"

Here is the JSON result when I retrieve the news about AAPL

[NewsV2({   'author': 'Maureen Meehan',
    'content': '',
    'created_at': '2022-09-01T18:30:21Z',
    'headline': 'EXCLUSIVE: Outstanding Cannabis Podcasts, Meet The Producers '
                '& Guests At Benzinga Cannabis Capital Conference',
    'id': 28723850,
    'images': [   {   'size': 'large',
                      'url': 'https://cdn.benzinga.com/files/imagecache/2048x1536xUP/images/story/2022/09/01/cannabis_podcast_irina_popova_st_by_shutterstock.jpg'},
                  {   'size': 'small',
                      'url': 'https://cdn.benzinga.com/files/imagecache/1024x768xUP/images/story/2022/09/01/cannabis_podcast_irina_popova_st_by_shutterstock.jpg'},
                  {   'size': 'thumb',
                      'url': 'https://cdn.benzinga.com/files/imagecache/250x187xUP/images/story/2022/09/01/cannabis_podcast_irina_popova_st_by_shutterstock.jpg'}],
    'source': 'benzinga',
    'summary': 'A stroll through Spotify\xa0(NYSE: SPOT) and Apple (NASDAQ: '
               'AAPL) iTunes\xa0reveals that there are over 2000 '
               'cannabis-related podcasts.\xa0',
    'symbols': ['AAPL', 'CURLF', 'GHBWF', 'GRAMF', 'SPOT', 'TCNNF'],
    'updated_at': '2022-09-01T20:45:46Z',
    'url': 'https://www.benzinga.com/markets/cannabis/22/09/28723850/outstanding-cannabis-podcasts-meet-the-producers-guests-at-benzinga-cannabis-capital-conference'}), 

NewsV2({   'author': 'Michael Horton',
    'content': '',
    'created_at': '2022-09-01T18:03:17Z',
    'headline': 'Top 15 Trending Stocks On WallStreetBets As Of Thursday, '
                'September 1, 2022 (Via Swaggy Stocks)',
    'id': 28723480,
    'images': [],
    'source': 'benzinga',
    'summary': '',
    'symbols': [   'AAPL',
                   'AI',
                   'AMD',
                   'AMZN',
                   'BBBY',
                   'GME',
                   'INTC',
                   'LULU',
                   'META',
                   'NVDA',
                   'OKTA',
                   'SNAP',
                   'SQQQ',
                   'TQQQ',
                   'TSLA'],
    'updated_at': '2022-09-01T18:03:18Z',
    'url': 'https://www.benzinga.com/trading-ideas/22/09/28723480/top-15-trending-stocks-on-wallstreetbets-as-of-thursday-september-1-2022-via-swaggy-stocks'})
]

Here is the actual HTML output of the above Python code:

EXCLUSIVE: Outstanding Cannabis Podcasts, Meet The Producers & Guests At Benzinga Cannabis Capital Conference [2022-09-01 20:45:46+00:00]

Top 15 Trending Stocks On WallStreetBets As Of Thursday, September 1, 2022 (Via Swaggy Stocks) [2022-09-01 18:03:18+00:00]

Finally, after implementing the Pyton code on Pre-market scanner here is a screenshot of the fixed results page. The missing entries in News column were populated from the Alpaca News API.

Based on my observation, Alpaca’s news are all sourced from Benzinga. I then checked out the pricing and threshold calls of Benzinga’s APIs if I want to call their endpoints directly rather than going through Alpaca. But I only found this:

To get started with Benzinga’s APIs please email us directly at licensing@benzinga.com or give us a call: 877-440-9464. We will respond within a business day.

For now, I will stick to using Alpaca API news endpoint as it solves my problem. If there’s a need for better source of news, I will revisit this research again.

References