Best way to scan for stocks

It seems easy to fetch data for a particular stock with the API. In python: df = api.get_barset('AAPL', 'day', limit=500).df['AAPL']. However, how can I scan for stocks that I want to trade? Simple example: I’d like to get all stocks that gapped up premarket by > 20%.

It seems like for this, Alpaca does not really have a good support yet. Hence, my question:
Is the best way to scan for stocks to directly query the IEX API to find the tickers I want to trade (

Alpaca’s purpose is to facilitate the trade, it’s our job as the programmer to come up with the logic to make a good trade. You’re going to need to define your own filters/scanners. As for Pandas DataFrames you can use Lambda functions.

1 Like

@joshcogburn, thanks a lot for your answer. I’m already downloading all IEX intra-day data. The problem is: It’s a lot of tickers (several thousand). Even with asynchronous requests, it takes a while to get the tickers. So building a real time scanner would be tricky.

Hence, I am wondering: What’s the best practice for this? Do you use something like the inofficial finviz api ( Or do you have your own data pipeline that fetches all, say IEX, tickers every hour or so to scan for new opportunities?

@grandpawithgreyhair No problem, Take a look at the Web Socket API. Web Sockets use a protocol different from http, they will allow you to stream data.



You can also use python filters to define a function that will return results that only match your filters.

Okay, but if I’m not mistaken the Alpaca stream endpoint is only for account and order updates. So you can’t listen to say all stocks on the market every minute. Instead, you can only stream/listen to your current trades, right?

Maybe you have an example of how you use python filters to keep scanning real time market data for several thousand tickers you’re currently not trading yet (without polygon if possible)? That would be really helpful!

@grandpawithgreyhair Can you post your code for fetching the data from IEX. I’m guessing there may be room for improvement there. I have some code that pulled 1000 tickers from IEX and it only took ~1 minute. Two tricks you can use to reduce the amount of data coming back are:

  1. send multiple requests at once, you can request 100 tickers at a time
  2. just get the quote, don’t ask IEX to send you everything they know about the ticker. That’s just too much data.

With those improvements you should be able to scan several thousand in a few minutes.

1 Like

Good point! Using just the quotes will definitely speed things up.

I am fetching all IEX tickers just to get training data. It takes me ca. 7 minutes for 8.8K tickers (all data in 1-min resolution for each ticker for 1 day). I am using asyncio in Python for asynchronous requests (with 4 workers).

Your definitely heading in the right direction with asynchronous requests. Could you post the problematic code?

the following new information that i found from polygon websites seems to require a fee of $199/m to access real data. pls help me to resolve the discrepancy:
from alpaca: “”"" [Documentation | Alpaca

Alpaca API lets you build and trade with real-time market data for free."""
from polygon:
“”" Stocks
Great for Historical Data
• Unlimited API Calls
• 15-minute Delayed Data

Great for Real Time Data
• Unlimited API Calls
• Real-time Data

If you do not have access to real-time data, you will need to connect to wss:// to receive messages.

Stocks Cluster
real-time: wss://
delayed: wss://
Available Channels:
T.* Trades
Q.* Quotes
A.* Aggregate ( per second )"""

Hey @Joe_Ching

Perhaps this previous thread will help here

TLDR: If an Alpaca User has a funded live trading account they have access to Polygon Data

Hope this helps,
Jason from Alpaca

If you have an Alpaca brokerage account, you get access to the Polygon API for free. Your live Alpaca API key will allow you to access the Polygon API.

thanks. that’s great news.

thanks for the reconfirmation. but the final verdict is live trading, which will start next week. and i ll let u know then.