How to efficiently query realtime stock price data

Overview

In this how to guide, we will show you how simple it is to use Intrinio to efficiently query realtime stock price data. In this example we will be using Python however, you can use any one of our client SDKs or query our REST API directly using your programming language of choice.


Prerequisites

  1. Create an account to get an API key
  2. Sign up for a free trial (of IEX)
  3. Contact sales if you wish to trial Nasdaq Basic or Delayed SIP
  4. Choose which SDK you wish to use Python, Javascript/Node, C#, Java, Ruby, or R.
  5. Use pip to install the intrinio sdk. (This how to assumes you already have python installed)

Procedure

Using the Realtime Stock Price for Security API  we can get a stock price for any active security. Create new file named example.py and add the following code updating your api key.

import intrinio_sdk as intrinio

intrinio.ApiClient().set_api_key('YOUR_API_KEY_HERE')

identifier = 'AAPL'
source = 'iex' # Use nasdaq_basic or delayed_sip if applicable

response = intrinio.SecurityApi().get_security_realtime_price(identifier, source=source)
print(response)


You'll receive the latest stock price ask and bid for a single stock. This is perfect if you only need to track a small handful of stocks. What if you need more? Or all of them? (Let's be real, you probably need all of them). The best thing to do use our Realtime Stock Price for Exchange API

import intrinio_sdk as intrinio

intrinio.ApiClient().set_api_key('YOUR_API_KEY_HERE')

identifier = 'USCOMP'
source = 'iex' # Use nasdaq_basic or delayed_sip if applicable
active_only = 'true'
page_size = 1000 # Max 10,0000
page = 1
next_page = None

while page == 1 or next_page != None:
    response = intrinio.StockExchangeApi().get_stock_exchange_realtime_prices(identifier, source=source, active_only=active_only, page_size=page_size, next_page=next_page)
    print(f'Page processed {page}')
    print(response.stock_prices[0]) # Fist stock price on this page
    page += 1
    next_page = response.next_page

"What's USCOMP you ask?" USCOMP is just a composite of all of the US Stock Exchanges (including NYSE, Nasdaq, etc) and is the typically way to query for US stock prices on our API's.

Now, if you are still reading this and not integrating the above API's into your app right now that your use case is probably different. You might be thinking "that is great and all but I need the data faster than I could poll from a REST api. Many stocks trade multiple times a second!" For this scenario, take a look at our guide for streaming stock price data.

Alternatively, you might be thinking, "well yeah, I will need realtime data eventually, but for now I just need to prove my brilliant idea using EOD stock price data." For this historical end of data stock price scenario, check out our Stock Prices by Security and Stock Prices by Exchange APIs.

Conclusion

Hopefully this helped. Seriously, our love language is acts of service.

Questions? Comments? Ready to buy? Contact sales@intrinio.com.