If you are subscribed to the market stream you are receiving price_change events like these:
{| import asyncio | |
| import orjson | |
| import websockets | |
| async def send_ping(websocket: websockets.WebSocketClientProtocol, interval=5): | |
| """Send ping to keep the WebSocket connection alive.""" | |
| try: | |
| while True: | |
| await asyncio.sleep(interval) # Wait for the specified interval |
| import asyncio | |
| import orjson | |
| import websockets | |
| async def send_ping(websocket: websockets.WebSocketClientProtocol, interval=5): | |
| """Send ping to keep the WebSocket connection alive.""" | |
| try: | |
| while True: | |
| await asyncio.sleep(interval) # Wait for the specified interval |
| from web3 import Web3 | |
| from web3.constants import MAX_INT | |
| from web3.middleware import geth_poa_middleware | |
| rpc_url = "" # Polygon rpc url | |
| priv_key = "" # Polygon account private key (needs some MATIC) | |
| pub_key = "" # Polygon account public key corresponding to private key | |
| chain_id = 137 |