I’ve used to timeframe for getting historical data by x minutes as in alpaca-trade-api-python/rest.py at master · alpacahq/alpaca-trade-api-python · GitHub.
Now, I’d like to know how I can configure real-time streaming to get bars for a custom x minutes interval e.g 5mins instead of the default minute bars. If this functionality is not available yet, I can try and collect minute bars for the desired minuted interval and perform a datapoint aggregation for each symbol. If this is the preferred approach, please share how to aggregate ‘volume’, ‘vwap’ and ‘trade_count’
Streaming supports only minute and day bars. You are right - you have to re-sample bars on your side or just request 5-minute bars every… 5 minutes using a multi-bar historical request. If you prefer resampling for some reason: the volume
and trade_count
values of the 5-minute bar are just a sum of the related fields in the source 1-minute bars.
The vwap
is a more hard case. You are unable to get the correct VWAP value from the already sampled data - you need raw trades with volumes to calculate it 100% correctly. But a weighted average of underlying vwap
values should provide you with a good approximation. Of course, you should use the volume
as your weight factor in this case.