Polygon bar streaming

I am trying to use streamconn to get the minute bar for a list of tickers and have tried using the subscribe method. However there is not much on how to do this and I am having trouble getting what is below to work. Yet I also get ‘StreamConn.subscribe’ was never awaited. What I am I doing wrong and how do I get it to print the minute bar for each of tickers in my ticker list?

conn = StreamConn(base_url=base_url,key_id=api_key_id,secret_key=api_secret,)

async def on_account_updates(conn, channel, account):
print(‘account’, account)

async def on_status(conn, channel, data):
print(‘polygon status update’, data)

async def on_minute_bars(conn, channel, bar):
print(‘bars’, bar)

async def on_second_bars(conn, channel, bar):
print(‘bars’, bar)


conn.run([‘account_updates’, 'AM.'l])

1 Like

Hey. I am also struggling with this. For what it’s worth, I don’t think you need to call conn.subscribe, if you are calling conn.run() (as the .run method has the subscribe call inside of it). Try removing one of these calls (either subscribe, or run) and see what you get.

In contradiction to what I wrote above, I got it to work on my machine like so:

import nest_asyncio

conn = StreamConn()

async def on_minute_bars(conn, channel, bar):
    print('bars', bar)


It still gives me a “Runtime error: cannot close the loop” on the first try but then if I comment out the conn.run() line and run it again with subscribe() only, it starts printing out bars