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 (https://iexcloud.io/financial-data/)?

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 (https://pypi.org/project/finviz/). 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.

Polygon:

1 Like

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?