import asyncio
import os
from polynode import AsyncPolyNode, perps_channels
async def main() -> None:
async with AsyncPolyNode(api_key=os.environ["POLYNODE_API_KEY"]) as pn:
perps = pn.perps
perps.on_reconnect(lambda notice: print("gap possible", notice))
perps.on_overflow(lambda notice: print("local overflow", notice))
ack = await perps.subscribe([
perps_channels.tickers,
perps_channels.bbo("BTC-USD"),
perps_channels.book("BTC-USD"),
perps_channels.trades("BTC-USD"),
perps_channels.klines("BTC-USD", "1m"),
])
if ack.rejected:
print("rejected channels", ack.rejected)
try:
async for message in perps:
if message.type == "event":
print(message.channel, message.data)
finally:
await perps.disconnect()
asyncio.run(main())