Created
December 10, 2013 15:55
-
-
Save QuantumDamage/7892944 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 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