Hi! I wanted to get MtGox trading history for backtesting of few simple trading strategies, but found that there is no easy way to do it - just some very old methods that don't work with the current API, a crazy way using Google's BigQuery and storing the data to SQLite, etc. There is a BitcoinCharts export, but it does not include information on whether the trade was bid/ask, making the data useless for backtesting especially in periods of big ask/bid spreads.
It turns out that if I just wrote a script right away instead of looking for an existing solution, my life would be easier. :-)
#!/usr/bin/perl
use warnings;
use strict;
use JSON;
my $since = 1354767190000000; # XXX: Fill your own; use e.g. `date -d '2013-01-01' +%s`
while (1) {
my $json = decode_json `curl http://data.mtgox.com/api/2/BTCUSD/money/trades/fetch?since=$since`;
for my $i (@{$json->{data}}) {
print join(',', $i->{date}, $i->{price}, $i->{amount}, $i->{trade_type})."\n";
$since = $i->{tid} + 1;
print STDERR "$since\n";
}
}
This Perl script produces a simple CSV file with timestamp, price, amount and type of trade. Downloading a year's worth of data takes a few hours. As it is downloading the data, it will print an updated "since" timestamp value for resuming the download later.
Hope that's useful for someone.