# Intra day 5 min bar

**URL:** https://forum.alpaca.markets/t/intra-day-5-min-bar/15620
**Category:** Alpaca Market Data
**Created:** [December 17, 2024, 10:23pm UTC](https://forum.alpaca.markets/t/intra-day-5-min-bar/15620 "2024-12-17T22:23:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ven7782](https://avatars.discourse-cdn.com/v4/letter/v/90ced4/32.png) [@ven7782](https://forum.alpaca.markets/u/ven7782)
#### Post date: [December 17, 2024, 10:23pm UTC](https://forum.alpaca.markets/t/intra-day-5-min-bar/15620/1 "2024-12-17T22:23:42Z")

</div>

I am testing a strategy on alpaca paper account which requires making buy/sell decisions on 5 min bar data. I am currently on free tier with plans to upgrade later. I need real time 5 min bar data as soon as they are formed. For E.G. at 9:35 AM EST the first 5 min bar for the day will be available for a symbol. I am using a websocket and subscribing to the symbol using IEX  
DATA\_URL = “wss://stream.data.alpaca.markets/v2/iex”

1.) I am getting one min bar data but its delayed by a minute. Is that normal?  
2.) I am aggregating the 1 min bar data and resampling it to generate 5 min bar data. Is there an option to directly get the 5 min bar data rather than me doing the aggregation and resampling?  
3.) If I subscribe to Algo trader plus I can query sip feed rather than iex. Will I get real time 5 min bar at the precise intervals of 9:35, 9:40 and so on without me doing resampling?

Sample code below

```auto
async def stream_data():
    """Stream live bar data for all symbols."""
    import websocket

    def on_open(ws):
        # Authenticate
        ws.send(json.dumps({"action": "auth", "key": API_KEY, "secret": API_SECRET}))
        # Subscribe to bar updates
        ws.send(json.dumps({"action": "subscribe", "bars": SYMBOLS}))

    def on_message(ws, message):
        logging.info(f"Received message: {message}")

    def on_close(ws, close_status_code, close_msg):
        logging.info(f"WebSocket closed: {close_status_code} - {close_msg}")
        # Trigger an explicit exit
        ws.keep_running = False # Exit `run_forever()`

    def on_error(ws, error):
        logging.error(f"WebSocket error: {error}")

    ws = websocket.WebSocketApp(DATA_URL, on_open=on_open, on_message=on_message, on_close=on_close, on_error=on_error)

    while True: # Auto-reconnect logic
        ws.run_forever()
        logging.info("WebSocket disconnected. Retrying in 10 seconds...")
        await asyncio.sleep(10) # Wait before reconnecting

```

Thanks.

---

<div class="post-metadata">

### Author: ![ven7782](https://avatars.discourse-cdn.com/v4/letter/v/90ced4/32.png) [@ven7782](https://forum.alpaca.markets/u/ven7782)
#### Post date: [December 17, 2024, 11:19pm UTC](https://forum.alpaca.markets/t/intra-day-5-min-bar/15620/2 "2024-12-17T23:19:18Z")

</div>

Update: The data may not be delayed after all. I am getting the below one min bar data at exactly 2024-12-17T15:20:00Z. The timestamp in the bar indicates data from **15:19:00 to 15:19:59** (inclusive) so it is current

[{‘T’: ‘b’, ‘S’: ‘ABC’, ‘o’: 20.64, ‘h’: 20.65, ‘l’: 20.64, ‘c’: 20.65, ‘v’: 1570, ‘t’: ‘2024-12-17T15:19:00Z’, ‘n’: 2, ‘vw’: 20.643631}]

---

<div class="post-metadata">

### Author: ![Gergely\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/gergely_alpaca/32/3210_2.png) [@Gergely\_Alpaca](https://forum.alpaca.markets/u/Gergely_Alpaca)
#### Post date: [December 18, 2024, 9:48am UTC](https://forum.alpaca.markets/t/intra-day-5-min-bar/15620/3 "2024-12-18T09:48:47Z")

</div>

Hi! 👋

> 1.) I am getting one min bar data but its delayed by a minute. Is that normal?

As you realised in your update, the data is not delayed. The bar’s timestamp simply indicates the start of the bar.

> 2.) I am aggregating the 1 min bar data and resampling it to generate 5 min bar data. Is there an option to directly get the 5 min bar data rather than me doing the aggregation and resampling?

No, there is no such option on the stream.

> 3.) If I subscribe to Algo trader plus I can query sip feed rather than iex. Will I get real time 5 min bar at the precise intervals of 9:35, 9:40 and so on without me doing resampling?

No, there is no such option on the SIP stream either. The main benefit you get from using SIP instead of IEX is that the quality of the minute bars will [drastically improve](https://docs.alpaca.markets/docs/market-data-faq#whats-the-difference-between-iex-and-sip-data), because they will contain all the trades from all US Exchanges (instead of IEX only).

---

<div class="post-metadata">

### Author: ![ven7782](https://avatars.discourse-cdn.com/v4/letter/v/90ced4/32.png) [@ven7782](https://forum.alpaca.markets/u/ven7782)
#### Post date: [December 18, 2024, 5:48pm UTC](https://forum.alpaca.markets/t/intra-day-5-min-bar/15620/4 "2024-12-18T17:48:20Z")

</div>

Thanks for the response. For IEX, there are lots of missing one min bars which messes up my 5 min bar aggregation. I believe that won’t happen with SIP right?

---

<div class="post-metadata">

### Author: ![Gergely\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/gergely_alpaca/32/3210_2.png) [@Gergely\_Alpaca](https://forum.alpaca.markets/u/Gergely_Alpaca)
#### Post date: [December 18, 2024, 8:33pm UTC](https://forum.alpaca.markets/t/intra-day-5-min-bar/15620/5 "2024-12-18T20:33:09Z")

</div>

There will be less missing on minute bars with SIP. But there still can be some for less frequently traded stocks. It shouldn’t mess up your 5-min bar aggregation though.
