In [1]:
from IPython.display import HTML
In [3]:
!curl -o mtgoxUSD.csv http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD
In [4]:
!head mtgoxUSD.csv
In [5]:
import pandas as pd
In [6]:
df=pd.read_csv("mtgoxUSD.csv",
names=["unixtime", "price", "amount"],
header=None)
In [7]:
# Live-Abfrage
#df=pd.read_csv("http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD",
# names=["unixtime", "price", "amount"],
# header=None)
In [8]:
df
Out[8]:
In [9]:
df.head()
Out[9]:
In [10]:
import datetime
In [11]:
df["datetime"]=df["unixtime"].map(datetime.datetime.fromtimestamp)
In [12]:
df.head()
Out[12]:
In [13]:
df.index
Out[13]:
In [14]:
df["price"]
Out[14]:
In [15]:
ts=df.set_index("datetime")
In [16]:
ts.head()
Out[16]:
In [17]:
del ts["unixtime"]
In [18]:
ts.head()
Out[18]:
In [19]:
ts.price
Out[19]:
In [20]:
ts.price.describe()
Out[20]:
In [21]:
%pylab inline
In [22]:
figsize(15,9)
In [23]:
ts.price.plot()
Out[23]:
In [24]:
ts.price.plot()
pd.rolling_mean(ts.price, 1000).plot(style="r-")
Out[24]:
In [25]:
ts.amount.plot()
Out[25]:
In [26]:
ts.amount.describe()
Out[26]:
In [27]:
ts["volume"]=ts["price"]*ts["amount"]
In [28]:
ts.volume.plot()
Out[28]:
In [29]:
ts.volume.sum()
Out[29]:
In [30]:
ts.volume.max()
Out[30]:
In [31]:
ts.volume.idxmax()
Out[31]:
In [32]:
per_hour = ts.resample("H", how="sum")
per_hour
Out[32]:
In [33]:
per_hour.volume.plot(kind="bar")
Out[33]:
In [34]:
!curl -o bitcoin_weighted_prices.json http://api.bitcoincharts.com/v1/weighted_prices.json
In [35]:
import json
In [36]:
!head bitcoin_weighted_prices.json
In [37]:
data=[json.loads(line) for line in open("bitcoin_weighted_prices.json")]
In [38]:
data
Out[38]:
In [39]:
data[0]
Out[39]:
In [40]:
wp=pd.DataFrame(data[0])
wp
Out[40]:
In [41]:
wp[["CAD", "EUR"]].T
Out[41]:
In [42]:
wp["datetime"]=wp.timestamp.apply(datetime.datetime.fromtimestamp)
del wp["timestamp"]
In [43]:
wp
Out[43]:
In [44]:
wp.T
Out[44]:
In [45]:
pd.DataFrame(wp.ix["24h", ["AUD", "EUR", "ILS"]]).T
Out[45]: