Created
July 20, 2011 17:16
-
-
Save sc68cal/1095392 to your computer and use it in GitHub Desktop.
Python Async
This file contains hidden or 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 | |
import sys | |
import select | |
import json | |
""" | |
Pulls trading data from MtGox bitcoin exchange, | |
prints the trading price. | |
Written to brush up on async programming | |
Depends on https://github.com/liris/websocket-client | |
""" | |
if __name__ == "__main__": | |
ws = websocket.create_connection(sys.argv[1]) | |
ws.sock.setblocking(0) | |
while True: | |
for socket in select.select([ws.sock],[],[])[0]: | |
data = json.loads(ws.recv()) | |
if data.has_key("depth"): | |
print data["depth"]["price"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment