the code I pasted was working - I was just showing others who were having problems :] thanks though.
It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
if (connection.getResponseCode() != 200) {
System.err.println("Failed : HTTP error code : "
+ connection.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
String output;
System.out.println("HTTP response \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
answer+=output;
}
connection.disconnect();
Failed : HTTP error code : 403
Apr 15, 2013 4:09:58 PM io.botcoin.api.MtGox query
java.io.IOException: Server returned HTTP response code: 403 for URL: https://data.mtgox.com/api/2/BTCUSD/money/info
post_data_mac : BTCUSD/money/infononce=1366035867142
signature: ZprNub9nISb5NdCig1LMXI9VYCdlbV/3/klZ78EJXHsTASg12xvWEZyrUTaVw5MUcJQtDMf1LrbguKka6BDlMA==
$ticker_ref = __request('BTCUSD/money/ticker');
sub __request {
my ($method, $args) = @_;
$args = "" unless defined $args;
my $nonce = 'nonce=' . sprintf "%d", gettimeofday * 1e6;
my $hash_data = $method . chr(0) . $nonce . $args;
my $req = HTTP::Request->new(POST => 'https://data.mtgox.com/api/2/' . $method );
$req->content_type('application/x-www-form-urlencoded');
$req->content($nonce . $args);
$req->header('Rest-Key' => $key);
$req->header('Rest-Sign' => encode_base64( hmac_sha512( $hash_data, decode_base64($secret) ) ));
my $result = $lwp->request($req);
unless ( $result->is_success ) {
__msg "failed $method";
exit 1;
};
return $json->decode( $result->content );
};
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
my $post_data = $nonce . ($args == '' ? '' : '&' . $args);
my $hash_data = $method . chr(0) . $post_data;
use Time::HiRes qw(gettimeofday);
use Digest::SHA qw( hmac_sha512 );
use HTTP::Request::Common qw(POST GET);
use MIME::Base64;
use LWP::UserAgent;
post_data_mac : BTCUSD/money/infononce=1366035867142
signature: ZprNub9nISb5NdCig1LMXI9VYCdlbV/3/klZ78EJXHsTASg12xvWEZyrUTaVw5MUcJQtDMf1LrbguKka6BDlMA==
if (connection.getResponseCode() != 200) {
System.err.println("Failed : HTTP error code : "
+ connection.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
String output;
System.out.println("HTTP response \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
answer+=output;
}
connection.disconnect();
Failed : HTTP error code : 403
Apr 15, 2013 4:09:58 PM io.botcoin.api.MtGox query
java.io.IOException: Server returned HTTP response code: 403 for URL: https://data.mtgox.com/api/2/BTCUSD/money/info
{"result":"success","data":
// write post
connection.getOutputStream().write(post_data.getBytes());
// read info
byte buffer[] = new byte[16384];
int len = connection.getInputStream().read(buffer, 0, 16384);
System.out.print(new String(buffer, 0, len, "UTF-8"));
byte current;
byte buffer[] = new byte[16384];
int len = 0;
InputStream s = connection.getInputStream();
while (true) {
current = s.read();
if (current == -1) break;
buffer[len] = current;
len++;
}
System.out.print(new String(buffer, 0, len, "UTF-8"));
https://data.mtgox.com/api/2/
BTCUSD/money/ticker
$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)),
);
$prefix = $path;
if (substr($path, 0, 2) == '2/') {
$prefix = substr($path, 2);
}
// generate the extra headers
$headers = array(
'Rest-Key: '.$key,
'Rest-Sign: '.base64_encode(hash_hmac('sha512', $prefix."\0".$post_data, base64_decode($secret), true)),
);
{"result":"success","data":
// write post
connection.getOutputStream().write(post_data.getBytes());
// read info
byte buffer[] = new byte[16384];
int len = connection.getInputStream().read(buffer, 0, 16384);
System.out.print(new String(buffer, 0, len, "UTF-8"));
https://data.mtgox.com/api/2/
BTCUSD/money/ticker
function mtgox_query($path, array $req = array()) {
// API settings
$key = 'my valid key';
$secret = 'my secret code';
// 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/2/'.$path); //Base URL
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;
}
// example 1: get infos about the account, plus the list of rights we have access to
var_dump(mtgox_query('BTCUSD/money/ticker'));// PATH
// old api (get funds)
//var_dump(mtgox_query('0/getFunds.php'));
// trade example
// var_dump(mtgox_query('0/buyBTC.php', array('amount' => 1, 'price' => 15)));
keytool -import -alias mtgox-data -file data.mtgox.com.cer -keystore mtgox.jks
keytool -import -alias mtgox-com -file mtgox.com.cer -keystore mtgox.jks
System.setProperty("javax.net.ssl.trustStore",settings.KEYSTORE_PATH);
System.setProperty("javax.net.ssl.trustStorePassword",settings.KEYSTORE_PWD);
java.io.IOException: Server returned HTTP response code: 403 for URL: https://data.mtgox.com/api/2/BTCUSD/money/info
keytool -import -alias mtgox-data -file data.mtgox.com.cer -keystore mtgox.jks
keytool -import -alias mtgox-com -file mtgox.com.cer -keystore mtgox.jks
System.setProperty("javax.net.ssl.trustStore",settings.KEYSTORE_PATH);
System.setProperty("javax.net.ssl.trustStorePassword",settings.KEYSTORE_PWD);
java.io.IOException: Server returned HTTP response code: 403 for URL: https://data.mtgox.com/api/2/BTCUSD/money/info
keytool -import -alias mtgox-data -file data.mtgox.com.cer -keystore mtgox.jks
keytool -import -alias mtgox-com -file mtgox.com.cer -keystore mtgox.jks
System.setProperty("javax.net.ssl.trustStore",settings.KEYSTORE_PATH);
System.setProperty("javax.net.ssl.trustStorePassword",settings.KEYSTORE_PWD);
java.io.IOException: Server returned HTTP response code: 403 for URL: https://data.mtgox.com/api/2/BTCUSD/money/info