Just made something with help of the API documentation. Make sure to create Advanced API Key at
https://mtgox.com/security (only need Get info rights) and add it in the script (line 6/7.)
<?php
$currency = 'EUR';
function mtgox_query($path, array $req = array()) {
// API settings
$key = '';
$secret = '';
// generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1].substr($mt[0], 2, 6);
// generate the POST data string
$post_data = http_build_query($req, '', '&');
$prefix = '';
if (substr($path, 0, 2) == '2/') {
$prefix = substr($path, 2)."\0";
}
// generate the extra headers
$headers = array(
'Rest-Key: '.$key,
'Rest-Sign: '.base64_encode(hash_hmac('sha512', $prefix.$post_data, base64_decode($secret), true)),
);
// our curl handle (initialize if required)
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
}
curl_setopt($ch, CURLOPT_URL, 'https://data.mtgox.com/api/'.$path);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// run the query
$res = curl_exec($ch);
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
$dec = json_decode($res, true);
if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
return $dec;
}
// Get order history
$cur_trades = mtgox_query('2/money/wallet/history',array('currency'=>$currency));
// Check if not empty
if ($cur_trades['result'] == 'success') {
if (!empty($cur_trades['data']['records']) && $cur_trades['data']['records'] > 0) {
// Start table and loop
echo '<table><tr><th>Date</th><th>Type</th><th>BTC</th><th>'. $currency .'</th><th>Price</th></tr>';
foreach($cur_trades['data']['result'] as $cur_trade) {
if (in_array($cur_trade['Type'],array('earned','spent'))) {
// Calculate price
$price = $cur_trade['Value']['value_int']/$cur_trade['Trade']['Amount']['value_int']*1000;
// Show trade
echo '<tr><td>'. date('d-m-y H:i',$cur_trade['Date']) .'</td><td>'. ($cur_trade['Type']=='earned'?'sell':'buy') .'</td><td>'. $cur_trade['Trade']['Amount']['value'] .' BTC</td><td>'. $cur_trade['Value']['display'] .'</td><td>'. $price .'</td></tr>';
}
}
echo '</table>';
}
}
?>
Just thought I will put it in public so everyone can use it. It uses API V2 so it will last for long. Donation on the address of my signature is very welcome though
Obviously it doesn't have CSS and it looks pretty bad. But I assume you can change that. If something is not working correctly, or you want some extra info from the trades, please tell me