Add first draft of websocket listener
This commit is contained in:
parent
4384583988
commit
2949a18ee7
33
main.py
Normal file
33
main.py
Normal file
@ -0,0 +1,33 @@
|
||||
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())
|
Loading…
Reference in New Issue
Block a user