Skip to content

Instantly share code, notes, and snippets.

@psidex
Created January 18, 2018 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psidex/23e7f2fac20a7bd819172ecc9bb4d2c6 to your computer and use it in GitHub Desktop.
Save psidex/23e7f2fac20a7bd819172ecc9bb4d2c6 to your computer and use it in GitHub Desktop.
import websocket
from json import loads as tojson
def on_message(ws, raw_message):
print("\nGot raw_message")
message = tojson(raw_message)
invalue = int(message["x"]["inputs"][0]["prev_out"]["value"]) / 100000000
outvalue = int(message["x"]["out"][0]["value"]) / 100000000
print("BTC in :", invalue)
print("BTC out:", outvalue) # Actual confirmed transaction
def on_error(ws, error):
print("\n\n### Error:", error)
def on_close(ws):
print("### ws closed ###")
def on_open(ws):
ws.send('{"op":"unconfirmed_sub"}')
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://ws.blockchain.info/inv",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment