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,)

@conn.on(r’^account_updates$’)
async def on_account_updates(conn, channel, account):
print(‘account’, account)

@conn.on(r’^status$’)
async def on_status(conn, channel, data):
print(‘polygon status update’, data)

@conn.on(r’^AM$’)
async def on_minute_bars(conn, channel, bar):
print(‘bars’, bar)

@conn.on(r’^A$’)
async def on_second_bars(conn, channel, bar):
print(‘bars’, bar)

conn.subscribe(ticker_list)

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
nest_asyncio.apply()

conn = StreamConn()

@conn.on(r'^AM$')
async def on_minute_bars(conn, channel, bar):
    print('bars', bar)

conn.subscribe(['AM.SPY'])
conn.run(['AM.SPY'])

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