Skip to content

Instantly share code, notes, and snippets.

@sc68cal
Created July 20, 2011 17:16
Show Gist options
  • Save sc68cal/1095392 to your computer and use it in GitHub Desktop.
Save sc68cal/1095392 to your computer and use it in GitHub Desktop.
Python Async
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