Binance-Nano-Listener/main.py

34 lines
1.0 KiB
Python
Raw Normal View History

2021-07-07 15:58:29 +00:00
import asyncio
import websockets
import json
from datetime import datetime
def present_transaction(trans):
"""
Print the time, recipient and amount of the transaction
"""
date = datetime.fromtimestamp(int(trans["time"][:-3]))
amount = float(trans["message"]["amount"]) / (10**30)
print(str(date) + " " + trans["message"]["account"] + " " + str(amount))
async def listen():
uri = "wss://ws.mynano.ninja"
async with websockets.connect(uri) as websocket:
# Listen to confirmed transactions from Binance's hot wallet
await websocket.send(json.dumps({
"action":"subscribe",
"topic":"confirmation",
"ack":"false",
"accounts": [
"nano_3jwrszth46rk1mu7rmb4rhm54us8yg1gw3ipodftqtikf5yqdyr7471nsg1k"
]
}))
while True:
msg = await websocket.recv()
present_transaction(json.loads(msg))
asyncio.get_event_loop().run_until_complete(listen())