Skip to content

Instantly share code, notes, and snippets.

@QuantumDamage
Created December 10, 2013 15:55
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 QuantumDamage/7892944 to your computer and use it in GitHub Desktop.
Save QuantumDamage/7892944 to your computer and use it in GitHub Desktop.
import urllib2
import json
import time
import pylab
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def update_line(data):
x, price = data
xdata.append(x)
ydata.append(price)
l.set_data(xdata,ydata)
print xdata, ydata
return l,
def get_data():
counter = 0
while True:
f = urllib2.urlopen('http://data.mtgox.com/api/1/BTCPLN/depth/fetch')
json_string = f.read()
parsed_json = json.loads(json_string)
print counter
counter = counter + 1
yield counter, parsed_json['return']['asks'][0]['price']
xdata, ydata = [], []
fig1 = plt.figure()
l, = plt.plot([], [])
line_ani = animation.FuncAnimation(fig1, update_line, get_data,
interval=1000, blit=True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment