Alpaca Market Data Update: Bars
We are moving the updated bars to a separate subscription. Open-high-low-close (OHLC) updates that were sent at the half minute mark on the “bars” subscription will now be sent under “updatedBars”.
A few things to note about streamed aggregate minute bars as of today.
First, bars are only generated when there are ‘valid’ trades during the bar. Alpaca follows the Systematic Investment Plan (SIP) recommendations for valid trades to include and exclude when calculating aggregate data.
Second, bars are always labeled by the beginning time. A bar between 9:31-9:32 will be labeled 9:31. It’s not a minute late but rather simply labeled by the start of the bar. The bar is technically closed left and open right meaning ‘Tstart <= T < Tend’ . Bars are generated immediately after the end time so will typically be received 20-100ms after the end of the bar.
However there can sometimes be late reported trades. Participant exchanges on the market have 10 seconds to report a trade. So, a trade that occurred at 9:31:55 (5 seconds before the end of the 9:31 bar) could be reported at 9:32:04 (4 seconds after the close of the bar). In these cases, the bar is recalculated and a new updated bar is streamed 30 seconds later or, in this example, 9:32:30. It will have the same timestamp as the original bar but just updated data.
As another example, if you query the historical crypto trades in the following period you can see this:
api.get_crypto_trades(symbol="BTCUSD", start="2021-11-12T22:45:59Z", end="2021-11-12T22:46:00Z").df
timestamp exchange price size takerside
2021-11-12 22:45:59.124309+00:00 CBSE 64050.06 0.003059 S
2021-11-12 22:45:59.796527+00:00 CBSE 64052.14 0.001846 B
2021-11-12 22:45:59.800310+00:00 CBSE 64052.14 0.161904 B
2021-11-12 22:45:59.800310+00:00 CBSE 64048.18 0.030787 B
2021-11-12 22:45:59.800310+00:00 CBSE 64048.17 0.127397 B
2021-11-12 22:45:59.800310+00:00 CBSE 64048.04 0.033912 B
2021-11-12 22:45:59.811752+00:00 CBSE 64046.86 0.023531 B
The original bar that was sent out on the stream had a closing price of 64050.06, you can see that that trade happened at 22:45:59.124309. The next 6 trades (starting at 59.796527) were reported after the bar was already sent out, so we sent an updated bar at 22:46:30 with the same timestamp.
Updated bars as a separate subscription
The data we provide does not change with this update, but the updated bars will be sent out on their dedicated channel, in order to avoid confusion. The new channel is called “updatedBars” for which the message type should be U. In order to receive updates you need to explicitly subscribe to updated bars.
Please note that this article is for general informational purposes only. All images and examples are for illustrative purposes only. Alpaca does not recommend any specific securities, cryptocurrencies or investment strategies.
Securities brokerage services are provided by Alpaca Securities LLC (“Alpaca Securities”), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.
Cryptocurrency services are made available by Alpaca Crypto LLC (“Alpaca Crypto”), a FinCEN registered money services business (NMLS # 2160858), and a wholly-owned subsidiary of AlpacaDB, Inc. Alpaca Crypto is not a member of SIPC or FINRA. Cryptocurrencies are not stocks and your cryptocurrency investments are not protected by either FDIC or SIPC. Depending on your location, cryptocurrency services may be provided by West Realm Shires Services, Inc., d/b/a FTX US (NMLS #1957771).
This is not an offer, solicitation of an offer, or advice to buy or sell securities or cryptocurrencies, or open a brokerage account or cryptocurrency account in any jurisdiction where Alpaca Securities, Alpaca Crypto, or FTX US respectively, are not registered or licensed, as applicable.
Cryptocurrency is highly speculative in nature, involves a high degree of risks, such as volatile market price swings, market manipulation, flash crashes, and cybersecurity risks. Cryptocurrency is not regulated or is lightly regulated in most countries. Cryptocurrency trading can lead to large, immediate and permanent loss of financial value. You should have appropriate knowledge and experience before engaging in cryptocurrency trading.