Trading extended hours w/ Alpaca?

Per my understanding of the documentation, it appears that the trading calendar for Alpaca doesn't include extended hours. Any chance we can get this added for US equities?

Basically, when trading small cap stocks, many large gap mean reversion opportunities offer the best entry prices during pre-market trading. Or when trading earnings plays, the best price action is often after hours, during post-market trading. Any chance we can start live trading starting at 4am EST, through to 8pm EST, when using Alpaca/Polygon?

If I misunderstood the documentation, or if there's a workaround to accomplish trading extended hours, please let me know. Thanks!

Hi Charles, I ran into this as well. Alpaca itself only supports these hours, so QR can't pull outside of this and/or execute or you'll get a rejection notice by Alpaca via the flight log. Typically I'll use an IBKR database to pull all extended hours, and set my crontab to send to Alpaca during the hours it allows.

I'll actually be entering my trades during the day, but I just need the extended hours data. My hunch was that IB could be a workaround, but I'll need to sign up for an account. @Brian would love your feedback on this topic.

In short, I'm struggling to figure out the best to simply get extended hours minute data for trading and historical backtesting. Ideally, I could just use the Polygon API for both live trading and Zipline backtesting as that would solve my needs. Being able to create a Zipline bundle from Polygon data would be ideal.

Is there some sort of limitation in Zipline that prevents extended hours backtesting? Possible to create a custom NYSE trading calendar that would included extended hours in Zipline?

Loving everything else about QuantRocket; this is the only thing holding me up.

The title and content of this thread don’t seem to match, but I think you’re asking how to use Zipline with extended hours data. You can use Interactive Brokers for the extended hours data. But Zipline doesn’t have an extended hours calendar, so by default the data will truncated to regular hours during ingestion. To actually use the extended hours data in Zipline, your choices would be:

  • use get_prices to query the IBKR history database directly from your Zipline strategy, instead of getting the (truncated) data from the bundle
  • Use the 24/5 Zipline calendar so that the data isn't truncated during ingestion (it will have NaNs for non-trading hours)

In the future we might try to add an extended hours US calendar to the trading_calendars package for those who are using Zipline with IBKR extended hours data. In the meantime feel free to fork trading_calendars, create an extended hours calendar, and pip install the fork on the zipline container. If you go that route and submit a PR, we’ll get it in a subsequent release.

@Brian thanks for the additional details, this def helps clarify things for me. At this point, I think my best bet is to use Moonshot instead as it's a little more flexible, and then create a custom Polygon downloader to create the minute extended hours intraday history database. Off top, my plan is to reverse engineer the minute intraday history database created by the IBKR downloader, and have the Polygon downloader mimic that structure. That said, it would definitely be helpful if you could provide any sort of direction/examples on building the downloader so that I could then submit a PR and contribute it back to the community. Let me know; thanks mate!

I would think it might be easier to open a token IBKR account than create a Polygon historical data downloader. That said, hopefully we can get some documentation and better support for loading custom data in the near future, since this is frequently requested.

@Brian I certainly considered just using IBKR, but given the throttling, it would take forever to get the data I want (5-10 years of minute level data for ~8k tradeable us equities). I'll take a first pass at a Polygon downloader, and run it by you when done. At a minimum, I plan to set it up as a satellite service, but would be awesome to have a general method for loading custom price, fundamental, and alternative data into QuantRocket.