Created
January 18, 2018 22:31
-
-
Save psidex/23e7f2fac20a7bd819172ecc9bb4d2c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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