import asyncio
import os
from polynode import AsyncPolyNode
async def main() -> None:
async with AsyncPolyNode(api_key=os.environ["POLYNODE_API_KEY"]) as pn:
sub = await (
pn.ws.subscribe("settlements")
.status("all")
.min_size(100)
.send()
)
print({"subscription_id": sub.id, "warnings": sub.warnings})
sub.on("settlement", lambda event: print(
"pending", event.tx_hash, event.taker_size
))
sub.on("status_update", lambda event: print(
"confirmed", event.tx_hash, event.block_number
))
sub.on_overflow(lambda notice: print("consumer fell behind", notice))
pn.ws.on_replay(lambda notice: print("reconnect replay", notice))
try:
async for event in sub:
if event.event_type == "unknown":
print("new event type", event.wire_event_type, event.raw)
finally:
sub.unsubscribe()
pn.ws.disconnect()
asyncio.run(main())