<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Advanced</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Advanced"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/Advanced"/>
	<updated>2026-04-09T18:29:48Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=MtGox/API/HTTP&amp;diff=37369</id>
		<title>MtGox/API/HTTP</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=MtGox/API/HTTP&amp;diff=37369"/>
		<updated>2013-04-27T10:53:36Z</updated>

		<summary type="html">&lt;p&gt;Advanced: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Two versions of the HTTP API are currently available, see the following pages for details on the methods available for each:&lt;br /&gt;
&lt;br /&gt;
* [[MtGox/API/HTTP/v0|Version 0]]&lt;br /&gt;
* [[MtGox/API/HTTP/v1|Version 1]]&lt;br /&gt;
* [[MtGox/API/HTTP/v2|Version 2]]&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The URL mtgox.com was changed to data.mtgox.com on March 19th 2013. https://bitcointalk.org/index.php?topic=150786.0&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All HTTP API requests are sent to URLs beginning with &amp;lt;nowiki&amp;gt;https://data.mtgox.com/api/*&amp;lt;/nowiki&amp;gt;. It allows placing orders, performing withdrawls, deposits, and other things. All responses are in [http://json.org/ JSON] format.&lt;br /&gt;
&lt;br /&gt;
There is a [https://rubygems.org/gems/mtgox Ruby gem], [https://rubygems.org/gems/guten-mtgox guten-mtgox] and a [[Finance::MtGox|Perl module]] available for interacting with the HTTP API.&lt;br /&gt;
&lt;br /&gt;
== Cache ==&lt;br /&gt;
&lt;br /&gt;
All API methods are cached for 10 seconds. Do not request results more often than that, you might be blocked by the anti-DDoS filters.&lt;br /&gt;
&lt;br /&gt;
== Currency Symbols ==&lt;br /&gt;
List of the currency symbols available with the API:&lt;br /&gt;
&lt;br /&gt;
USD, AUD, CAD, CHF, CNY, DKK, EUR, GBP, HKD, JPY, NZD, PLN, RUB, SEK, SGD, THB&lt;br /&gt;
&lt;br /&gt;
== Authentication ==&lt;br /&gt;
&lt;br /&gt;
Authentication is performed by signing each request using HMAC-SHA512. The request must contain an extra value &amp;quot;nonce&amp;quot; which must be an always incrementing numeric value.  A reference implementation is provided here:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;basically the base64 string should contain:&#039;&#039;&#039;&lt;br /&gt;
* the binary representation of the api key id&lt;br /&gt;
* binary hmac-sha512 signature&lt;br /&gt;
* json data&lt;br /&gt;
&lt;br /&gt;
api key looks like that: 12345678-abcd-1234-abcd-50286e649d5c&lt;br /&gt;
&lt;br /&gt;
it&#039;s actually hexadecimal, it should be converted to binary&lt;br /&gt;
&lt;br /&gt;
hash should then be appended (binary too) and then encode everything in base64&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning : the API is no more accepting authentication by login/pass ( since 2012 march 1 ) , you _need_ to use an API key.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== perl ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT! This is a simplified perl module simply returning user info not a full API, it is shown simply for illustrative purposes for those wishing to developing there own modules from scratch.. or bots.. or other&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT! This requires you compiled perl libwww with https support&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/perl&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use Time::HiRes qw(gettimeofday);&lt;br /&gt;
use MIME::Base64;&lt;br /&gt;
use Digest::SHA qw(hmac_sha512);&lt;br /&gt;
&lt;br /&gt;
use JSON;&lt;br /&gt;
use LWP::UserAgent;&lt;br /&gt;
&lt;br /&gt;
use Data::Dumper;&lt;br /&gt;
&lt;br /&gt;
my $lwp = LWP::UserAgent-&amp;gt;new;&lt;br /&gt;
$lwp-&amp;gt;agent(&amp;quot;perl $]&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
my $json = JSON-&amp;gt;new-&amp;gt;allow_nonref;&lt;br /&gt;
&lt;br /&gt;
my $secret = &#039;_MTGOX API SECRET GET YOURS AT https://classic.mtgox.com/support/tradeAPI&#039;;&lt;br /&gt;
my $key = &#039;_MTGOX API KEY GET YOURS AT https://classic.mtgox.com/support/tradeAPI&#039;;&lt;br /&gt;
&lt;br /&gt;
## user code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
my $request = genReq(&#039;/1/generic/private/info&#039;);&lt;br /&gt;
my $res = $lwp-&amp;gt;request($request);&lt;br /&gt;
&lt;br /&gt;
# Check the outcome of the response&lt;br /&gt;
if ($res-&amp;gt;is_success) {&lt;br /&gt;
        print Dumper($json-&amp;gt;decode( $res-&amp;gt;content )).&amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
else { print $res-&amp;gt;status_line, &amp;quot;\n&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
exit 0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## sub routines and helpers&lt;br /&gt;
&lt;br /&gt;
sub genReq {&lt;br /&gt;
        my ($uri) = shift;&lt;br /&gt;
&lt;br /&gt;
        my $req = HTTP::Request-&amp;gt;new(POST =&amp;gt; &#039;https://mtgox.com/api/&#039;.$uri);&lt;br /&gt;
        $req-&amp;gt;content_type(&#039;application/x-www-form-urlencoded&#039;);&lt;br /&gt;
        $req-&amp;gt;content(&amp;quot;nonce=&amp;quot;.microtime());&lt;br /&gt;
        $req-&amp;gt;header(&#039;Rest-Key&#039; =&amp;gt; $key);&lt;br /&gt;
        $req-&amp;gt;header(&#039;Rest-Sign&#039; =&amp;gt; signReq($req-&amp;gt;content(),$secret));&lt;br /&gt;
&lt;br /&gt;
        return $req;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
sub signReq {&lt;br /&gt;
        my ($content,$secret) = @_;&lt;br /&gt;
        return encode_base64(hmac_sha512($content,decode_base64($secret)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub microtime { return sprintf &amp;quot;%d%06d&amp;quot;, gettimeofday; }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
function mtgox_query($path, array $req = array()) {&lt;br /&gt;
	// API settings&lt;br /&gt;
	$key = &#039;&#039;;&lt;br /&gt;
	$secret = &#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
	// generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems&lt;br /&gt;
	$mt = explode(&#039; &#039;, microtime());&lt;br /&gt;
	$req[&#039;nonce&#039;] = $mt[1].substr($mt[0], 2, 6);&lt;br /&gt;
&lt;br /&gt;
	// generate the POST data string&lt;br /&gt;
	$post_data = http_build_query($req, &#039;&#039;, &#039;&amp;amp;&#039;);&lt;br /&gt;
&lt;br /&gt;
	$prefix = &#039;&#039;;&lt;br /&gt;
	if (substr($path, 0, 2) == &#039;2/&#039;) {&lt;br /&gt;
		$prefix = substr($path, 2).&amp;quot;\0&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// generate the extra headers&lt;br /&gt;
	$headers = array(&lt;br /&gt;
		&#039;Rest-Key: &#039;.$key,&lt;br /&gt;
		&#039;Rest-Sign: &#039;.base64_encode(hash_hmac(&#039;sha512&#039;, $prefix.$post_data, base64_decode($secret), true)),&lt;br /&gt;
	);&lt;br /&gt;
&lt;br /&gt;
	// our curl handle (initialize if required)&lt;br /&gt;
	static $ch = null;&lt;br /&gt;
	if (is_null($ch)) {&lt;br /&gt;
		$ch = curl_init();&lt;br /&gt;
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);&lt;br /&gt;
		curl_setopt($ch, CURLOPT_USERAGENT, &#039;Mozilla/4.0 (compatible; MtGox PHP client; &#039;.php_uname(&#039;s&#039;).&#039;; PHP/&#039;.phpversion().&#039;)&#039;);&lt;br /&gt;
	}&lt;br /&gt;
	curl_setopt($ch, CURLOPT_URL, &#039;https://mtgox.com/api/&#039;.$path);&lt;br /&gt;
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);&lt;br /&gt;
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);&lt;br /&gt;
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);&lt;br /&gt;
&lt;br /&gt;
	// run the query&lt;br /&gt;
	$res = curl_exec($ch);&lt;br /&gt;
	if ($res === false) throw new Exception(&#039;Could not get reply: &#039;.curl_error($ch));&lt;br /&gt;
	$dec = json_decode($res, true);&lt;br /&gt;
	if (!$dec) throw new Exception(&#039;Invalid data received, please make sure connection is working and requested API exists&#039;);&lt;br /&gt;
	return $dec;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// example 1: get infos about the account, plus the list of rights we have access to&lt;br /&gt;
var_dump(mtgox_query(&#039;0/info.php&#039;));&lt;br /&gt;
&lt;br /&gt;
// old api (get funds)&lt;br /&gt;
var_dump(mtgox_query(&#039;0/getFunds.php&#039;));&lt;br /&gt;
&lt;br /&gt;
// trade example&lt;br /&gt;
// var_dump(mtgox_query(&#039;0/buyBTC.php&#039;, array(&#039;amount&#039; =&amp;gt; 1, &#039;price&#039; =&amp;gt; 15)));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from urllib import urlencode&lt;br /&gt;
import urllib2&lt;br /&gt;
import time&lt;br /&gt;
from hashlib import sha512&lt;br /&gt;
from hmac import HMAC&lt;br /&gt;
import base64&lt;br /&gt;
import json&lt;br /&gt;
def get_nonce():&lt;br /&gt;
    return int(time.time()*100000)&lt;br /&gt;
&lt;br /&gt;
def sign_data(secret, data):&lt;br /&gt;
    return base64.b64encode(str(HMAC(secret, data, sha512).digest()))&lt;br /&gt;
      &lt;br /&gt;
class requester:&lt;br /&gt;
    def __init__(self, auth_key, auth_secret):&lt;br /&gt;
        self.auth_key = auth_key&lt;br /&gt;
        self.auth_secret = base64.b64decode(auth_secret)&lt;br /&gt;
        &lt;br /&gt;
    def build_query(self, req={}):&lt;br /&gt;
        req[&amp;quot;nonce&amp;quot;] = get_nonce()&lt;br /&gt;
        post_data = urlencode(req)&lt;br /&gt;
        headers = {}&lt;br /&gt;
        headers[&amp;quot;User-Agent&amp;quot;] = &amp;quot;GoxApi&amp;quot;&lt;br /&gt;
        headers[&amp;quot;Rest-Key&amp;quot;] = self.auth_key&lt;br /&gt;
        headers[&amp;quot;Rest-Sign&amp;quot;] = sign_data(self.auth_secret, post_data)&lt;br /&gt;
        return (post_data, headers)&lt;br /&gt;
        &lt;br /&gt;
    def perform(self, path, args):&lt;br /&gt;
        data, headers = self.build_query(args)&lt;br /&gt;
        req = urllib2.Request(&amp;quot;https://mtgox.com/api/0/&amp;quot;+path, data, headers)&lt;br /&gt;
        res = urllib2.urlopen(req, data)&lt;br /&gt;
        return json.load(res)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Node.js ===&lt;br /&gt;
Generic [[Node.js Example]] trading library (supports MtGox and Bitfloor): https://github.com/bitfloor/trader.nodejs&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
basic [[Java Example]] on https://gist.github.com/2396722 hoping for many java forks and pull requests on github&lt;br /&gt;
&lt;br /&gt;
XChange API : https://github.com/timmolter/XChange&lt;br /&gt;
&lt;br /&gt;
mtgox-java: A Java API (based on Spring &amp;amp; Maven) for the MtGox bitcoin exchange WebSocket &amp;amp; HTTP services.&lt;br /&gt;
http://grantsparks.github.com/mtgox-java/&lt;br /&gt;
&lt;br /&gt;
mtgox-api-v2-java:  A Java lib for the v2 of the API https://github.com/adv0r/mtgox-api-v2-java&lt;br /&gt;
====Java:====&lt;br /&gt;
&lt;br /&gt;
=== Javascript Firefox addon ===&lt;br /&gt;
* [https://github.com/joric/mtgox-ticker] firefox ticker addon&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[MtGox|Mt. Gox]]&lt;br /&gt;
* [http://bitcointalk.org/index.php?topic=164404.0 MtGox API version 2: Unofficial Documentation]&lt;/div&gt;</summary>
		<author><name>Advanced</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=MtGox/API/HTTP&amp;diff=37357</id>
		<title>MtGox/API/HTTP</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=MtGox/API/HTTP&amp;diff=37357"/>
		<updated>2013-04-26T14:09:08Z</updated>

		<summary type="html">&lt;p&gt;Advanced: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Two versions of the HTTP API are currently available, see the following pages for details on the methods available for each:&lt;br /&gt;
&lt;br /&gt;
* [[MtGox/API/HTTP/v0|Version 0]]&lt;br /&gt;
* [[MtGox/API/HTTP/v1|Version 1]]&lt;br /&gt;
* [[MtGox/API/HTTP/v2|Version 2]]&lt;br /&gt;
Version 2 Exists. Its very similar to API 1 although the method of which you hash your signature now includes the URL for better security. The PDF file is here: https://github.com/MtGox/mtgox-doc/blob/master/api/money.pdf?raw=true&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The URL mtgox.com was changed to data.mtgox.com on March 19th 2013. https://bitcointalk.org/index.php?topic=150786.0&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
All HTTP API requests are sent to URLs beginning with &amp;lt;nowiki&amp;gt;https://data.mtgox.com/api/*&amp;lt;/nowiki&amp;gt;. It allows placing orders, performing withdrawls, deposits, and other things. All responses are in [http://json.org/ JSON] format.&lt;br /&gt;
&lt;br /&gt;
There is a [https://rubygems.org/gems/mtgox Ruby gem], [https://rubygems.org/gems/guten-mtgox guten-mtgox] and a [[Finance::MtGox|Perl module]] available for interacting with the HTTP API.&lt;br /&gt;
&lt;br /&gt;
== Cache ==&lt;br /&gt;
&lt;br /&gt;
All API methods are cached for 10 seconds. Do not request results more often than that, you might be blocked by the anti-DDoS filters.&lt;br /&gt;
&lt;br /&gt;
== Currency Symbols ==&lt;br /&gt;
List of the currency symbols available with the API:&lt;br /&gt;
&lt;br /&gt;
USD, AUD, CAD, CHF, CNY, DKK, EUR, GBP, HKD, JPY, NZD, PLN, RUB, SEK, SGD, THB&lt;br /&gt;
&lt;br /&gt;
== Authentication ==&lt;br /&gt;
&lt;br /&gt;
Authentication is performed by signing each request using HMAC-SHA512. The request must contain an extra value &amp;quot;nonce&amp;quot; which must be an always incrementing numeric value.  A reference implementation is provided here:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;basically the base64 string should contain:&#039;&#039;&#039;&lt;br /&gt;
* the binary representation of the api key id&lt;br /&gt;
* binary hmac-sha512 signature&lt;br /&gt;
* json data&lt;br /&gt;
&lt;br /&gt;
api key looks like that: 12345678-abcd-1234-abcd-50286e649d5c&lt;br /&gt;
&lt;br /&gt;
it&#039;s actually hexadecimal, it should be converted to binary&lt;br /&gt;
&lt;br /&gt;
hash should then be appended (binary too) and then encode everything in base64&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning : the API is no more accepting authentication by login/pass ( since 2012 march 1 ) , you _need_ to use an API key.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== perl ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT! This is a simplified perl module simply returning user info not a full API, it is shown simply for illustrative purposes for those wishing to developing there own modules from scratch.. or bots.. or other&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT! This requires you compiled perl libwww with https support&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/perl&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use Time::HiRes qw(gettimeofday);&lt;br /&gt;
use MIME::Base64;&lt;br /&gt;
use Digest::SHA qw(hmac_sha512);&lt;br /&gt;
&lt;br /&gt;
use JSON;&lt;br /&gt;
use LWP::UserAgent;&lt;br /&gt;
&lt;br /&gt;
use Data::Dumper;&lt;br /&gt;
&lt;br /&gt;
my $lwp = LWP::UserAgent-&amp;gt;new;&lt;br /&gt;
$lwp-&amp;gt;agent(&amp;quot;perl $]&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
my $json = JSON-&amp;gt;new-&amp;gt;allow_nonref;&lt;br /&gt;
&lt;br /&gt;
my $secret = &#039;_MTGOX API SECRET GET YOURS AT https://classic.mtgox.com/support/tradeAPI&#039;;&lt;br /&gt;
my $key = &#039;_MTGOX API KEY GET YOURS AT https://classic.mtgox.com/support/tradeAPI&#039;;&lt;br /&gt;
&lt;br /&gt;
## user code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
my $request = genReq(&#039;/1/generic/private/info&#039;);&lt;br /&gt;
my $res = $lwp-&amp;gt;request($request);&lt;br /&gt;
&lt;br /&gt;
# Check the outcome of the response&lt;br /&gt;
if ($res-&amp;gt;is_success) {&lt;br /&gt;
        print Dumper($json-&amp;gt;decode( $res-&amp;gt;content )).&amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
else { print $res-&amp;gt;status_line, &amp;quot;\n&amp;quot;; }&lt;br /&gt;
&lt;br /&gt;
exit 0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## sub routines and helpers&lt;br /&gt;
&lt;br /&gt;
sub genReq {&lt;br /&gt;
        my ($uri) = shift;&lt;br /&gt;
&lt;br /&gt;
        my $req = HTTP::Request-&amp;gt;new(POST =&amp;gt; &#039;https://mtgox.com/api/&#039;.$uri);&lt;br /&gt;
        $req-&amp;gt;content_type(&#039;application/x-www-form-urlencoded&#039;);&lt;br /&gt;
        $req-&amp;gt;content(&amp;quot;nonce=&amp;quot;.microtime());&lt;br /&gt;
        $req-&amp;gt;header(&#039;Rest-Key&#039; =&amp;gt; $key);&lt;br /&gt;
        $req-&amp;gt;header(&#039;Rest-Sign&#039; =&amp;gt; signReq($req-&amp;gt;content(),$secret));&lt;br /&gt;
&lt;br /&gt;
        return $req;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
sub signReq {&lt;br /&gt;
        my ($content,$secret) = @_;&lt;br /&gt;
        return encode_base64(hmac_sha512($content,decode_base64($secret)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub microtime { return sprintf &amp;quot;%d%06d&amp;quot;, gettimeofday; }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
function mtgox_query($path, array $req = array()) {&lt;br /&gt;
	// API settings&lt;br /&gt;
	$key = &#039;&#039;;&lt;br /&gt;
	$secret = &#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
	// generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems&lt;br /&gt;
	$mt = explode(&#039; &#039;, microtime());&lt;br /&gt;
	$req[&#039;nonce&#039;] = $mt[1].substr($mt[0], 2, 6);&lt;br /&gt;
&lt;br /&gt;
	// generate the POST data string&lt;br /&gt;
	$post_data = http_build_query($req, &#039;&#039;, &#039;&amp;amp;&#039;);&lt;br /&gt;
&lt;br /&gt;
	$prefix = &#039;&#039;;&lt;br /&gt;
	if (substr($path, 0, 2) == &#039;2/&#039;) {&lt;br /&gt;
		$prefix = substr($path, 2).&amp;quot;\0&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// generate the extra headers&lt;br /&gt;
	$headers = array(&lt;br /&gt;
		&#039;Rest-Key: &#039;.$key,&lt;br /&gt;
		&#039;Rest-Sign: &#039;.base64_encode(hash_hmac(&#039;sha512&#039;, $prefix.$post_data, base64_decode($secret), true)),&lt;br /&gt;
	);&lt;br /&gt;
&lt;br /&gt;
	// our curl handle (initialize if required)&lt;br /&gt;
	static $ch = null;&lt;br /&gt;
	if (is_null($ch)) {&lt;br /&gt;
		$ch = curl_init();&lt;br /&gt;
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);&lt;br /&gt;
		curl_setopt($ch, CURLOPT_USERAGENT, &#039;Mozilla/4.0 (compatible; MtGox PHP client; &#039;.php_uname(&#039;s&#039;).&#039;; PHP/&#039;.phpversion().&#039;)&#039;);&lt;br /&gt;
	}&lt;br /&gt;
	curl_setopt($ch, CURLOPT_URL, &#039;https://mtgox.com/api/&#039;.$path);&lt;br /&gt;
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);&lt;br /&gt;
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);&lt;br /&gt;
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);&lt;br /&gt;
&lt;br /&gt;
	// run the query&lt;br /&gt;
	$res = curl_exec($ch);&lt;br /&gt;
	if ($res === false) throw new Exception(&#039;Could not get reply: &#039;.curl_error($ch));&lt;br /&gt;
	$dec = json_decode($res, true);&lt;br /&gt;
	if (!$dec) throw new Exception(&#039;Invalid data received, please make sure connection is working and requested API exists&#039;);&lt;br /&gt;
	return $dec;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// example 1: get infos about the account, plus the list of rights we have access to&lt;br /&gt;
var_dump(mtgox_query(&#039;0/info.php&#039;));&lt;br /&gt;
&lt;br /&gt;
// old api (get funds)&lt;br /&gt;
var_dump(mtgox_query(&#039;0/getFunds.php&#039;));&lt;br /&gt;
&lt;br /&gt;
// trade example&lt;br /&gt;
// var_dump(mtgox_query(&#039;0/buyBTC.php&#039;, array(&#039;amount&#039; =&amp;gt; 1, &#039;price&#039; =&amp;gt; 15)));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from urllib import urlencode&lt;br /&gt;
import urllib2&lt;br /&gt;
import time&lt;br /&gt;
from hashlib import sha512&lt;br /&gt;
from hmac import HMAC&lt;br /&gt;
import base64&lt;br /&gt;
import json&lt;br /&gt;
def get_nonce():&lt;br /&gt;
    return int(time.time()*100000)&lt;br /&gt;
&lt;br /&gt;
def sign_data(secret, data):&lt;br /&gt;
    return base64.b64encode(str(HMAC(secret, data, sha512).digest()))&lt;br /&gt;
      &lt;br /&gt;
class requester:&lt;br /&gt;
    def __init__(self, auth_key, auth_secret):&lt;br /&gt;
        self.auth_key = auth_key&lt;br /&gt;
        self.auth_secret = base64.b64decode(auth_secret)&lt;br /&gt;
        &lt;br /&gt;
    def build_query(self, req={}):&lt;br /&gt;
        req[&amp;quot;nonce&amp;quot;] = get_nonce()&lt;br /&gt;
        post_data = urlencode(req)&lt;br /&gt;
        headers = {}&lt;br /&gt;
        headers[&amp;quot;User-Agent&amp;quot;] = &amp;quot;GoxApi&amp;quot;&lt;br /&gt;
        headers[&amp;quot;Rest-Key&amp;quot;] = self.auth_key&lt;br /&gt;
        headers[&amp;quot;Rest-Sign&amp;quot;] = sign_data(self.auth_secret, post_data)&lt;br /&gt;
        return (post_data, headers)&lt;br /&gt;
        &lt;br /&gt;
    def perform(self, path, args):&lt;br /&gt;
        data, headers = self.build_query(args)&lt;br /&gt;
        req = urllib2.Request(&amp;quot;https://mtgox.com/api/0/&amp;quot;+path, data, headers)&lt;br /&gt;
        res = urllib2.urlopen(req, data)&lt;br /&gt;
        return json.load(res)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Node.js ===&lt;br /&gt;
Generic [[Node.js Example]] trading library (supports MtGox and Bitfloor): https://github.com/bitfloor/trader.nodejs&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
basic [[Java Example]] on https://gist.github.com/2396722 hoping for many java forks and pull requests on github&lt;br /&gt;
&lt;br /&gt;
XChange API : https://github.com/timmolter/XChange&lt;br /&gt;
&lt;br /&gt;
mtgox-java: A Java API (based on Spring &amp;amp; Maven) for the MtGox bitcoin exchange WebSocket &amp;amp; HTTP services.&lt;br /&gt;
http://grantsparks.github.com/mtgox-java/&lt;br /&gt;
&lt;br /&gt;
mtgox-api-v2-java:  A Java lib for the v2 of the API https://github.com/adv0r/mtgox-api-v2-java&lt;br /&gt;
====Java:====&lt;br /&gt;
&lt;br /&gt;
=== Javascript Firefox addon ===&lt;br /&gt;
* [https://github.com/joric/mtgox-ticker] firefox ticker addon&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[MtGox|Mt. Gox]]&lt;br /&gt;
* [http://bitcointalk.org/index.php?topic=164404.0 MtGox API version 2: Unofficial Documentation]&lt;/div&gt;</summary>
		<author><name>Advanced</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=MtGox/API/HTTP/v2&amp;diff=37356</id>
		<title>MtGox/API/HTTP/v2</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=MtGox/API/HTTP/v2&amp;diff=37356"/>
		<updated>2013-04-26T14:07:22Z</updated>

		<summary type="html">&lt;p&gt;Advanced: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== API Version 2: == &lt;br /&gt;
The V2 API URL is:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;https://data.mtgox.com/api/2/&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Documentation ===&lt;br /&gt;
&#039;&#039;&#039;unofficial&#039;&#039;&#039; documentation (So far the best we have) is provided at :&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;https://bitbucket.org/nitrous/mtgox-api/overview&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
(The bitcointalk forum link is: &#039;&#039;&#039;https://bitcointalk.org/index.php?topic=164404.0&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;official&#039;&#039;&#039; docs are on  :&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;https://github.com/MtGox/mtgox-doc&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Technical Use Explanation: ===== &lt;br /&gt;
&lt;br /&gt;
The requested path (anything after the /2/) must now be included when you compute your hashed signature (Rest-Sign) for added security.&lt;br /&gt;
&lt;br /&gt;
This is how it was done for version 1:&lt;br /&gt;
&lt;br /&gt;
You have your params(post_data) = the word nonce, followed by the actual &#039;&#039;nonce&#039;&#039; integer (params = [(u&#039;nonce&#039;,nonce)])&lt;br /&gt;
&lt;br /&gt;
You have your header made up of &#039;&#039;Rest-Key&#039;&#039; (your API-KEY) and &#039;&#039;Rest-Sign&#039;&#039; (a hashed signature)&lt;br /&gt;
&lt;br /&gt;
Rest-Sign is created by doing : base64encode( HMAC hash( base64decoded(API-secret), the nonce, with SHA512 digest))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What differs in version 2 is now&#039;&#039;&#039; : BEFORE the nonce, you are adding the &#039;&#039;&#039;relative path you are requesting&#039;&#039;&#039;(ie: BTCUSD/money/ticker) &#039;&#039;&#039;+ a NUL char (ascii code 0)&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The URL is now &#039;&#039;&#039; something along the lines of BTCUSD/money/order/add instead of BTCUSD/private/order/add in api1. &amp;lt;br&amp;gt;&lt;br /&gt;
So in my python code below which is very readable you can see everything remains the same as API v1 except now we are using api2postdatatohash = path + chr(0) + post_data          #new way to hash for API 2, includes path + NUL.&lt;br /&gt;
&lt;br /&gt;
=== Explanation of Methods ===&lt;br /&gt;
&#039;&#039;&#039;BTCUSD/money/order/quote&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;@MagicalTux&amp;gt; it estimate the result of running an order at a given price based on market depth&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;BTCUSD/money/ticker_fast&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Solves the problem of ticker lag. (supposedly)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Code Examples: ===&lt;br /&gt;
&lt;br /&gt;
====Java:====&lt;br /&gt;
&lt;br /&gt;
https://github.com/adv0r/mtgox-api-v2-java Java lib for API V2, under development&lt;br /&gt;
&lt;br /&gt;
====C# :====&lt;br /&gt;
&lt;br /&gt;
https://bitbucket.org/pipe2grep/cryptocoinxchange C# lib for V2 API and socketIO&lt;br /&gt;
&lt;br /&gt;
====Python v 2.7.3====&lt;br /&gt;
&lt;br /&gt;
http://pastebin.com/aXQfULyq - Remove any proprietary unlock_api_key stuff. You&#039;ll need [https://github.com/genbtc/trader.python/blob/master/lib/json_ascii.py json_ascii] also. Works on API 0/1/2. Link to git-repo: [https://github.com/genbtc/trader.python/ genbtc&#039;s trader.python] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Perl====&lt;br /&gt;
https://en.bitcoin.it/wiki/MtGox/API/HTTP#PHP    The Perl example on the main page is compatible with v2&lt;/div&gt;</summary>
		<author><name>Advanced</name></author>
	</entry>
</feed>