<?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=GutenYe</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=GutenYe"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/GutenYe"/>
	<updated>2026-05-12T10:26:10Z</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=24963</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=24963"/>
		<updated>2012-03-29T06:02:46Z</updated>

		<summary type="html">&lt;p&gt;GutenYe: add another ruby gem.&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;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
All HTTP API requests are sent to URLs beginning with &amp;lt;nowiki&amp;gt;https://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;
== 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;
Warning : the API is no more accepting authentication by login/pass ( since 2012 march 1 ) , you _need_ to use an API key.&lt;br /&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;
	// 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;, $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;
Python version here: https://bitcointalk.org/index.php?topic=49789.msg592388#msg592388&lt;br /&gt;
&lt;br /&gt;
=== Node.js ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var querystring = require(&#039;querystring&#039;),&lt;br /&gt;
        https = require(&#039;https&#039;),&lt;br /&gt;
        crypto = require(&#039;crypto&#039;);&lt;br /&gt;
&lt;br /&gt;
function MtGoxClient(key, secret) {&lt;br /&gt;
        this.key = key;&lt;br /&gt;
        this.secret = secret;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
MtGoxClient.prototype.query = function(path, args, callback) {&lt;br /&gt;
        var client = this;&lt;br /&gt;
&lt;br /&gt;
        // if no args or invalid args provided, just reset the arg object&lt;br /&gt;
        if (typeof args != &amp;quot;object&amp;quot;) args = {};&lt;br /&gt;
&lt;br /&gt;
        // generate a nonce&lt;br /&gt;
        args[&#039;nonce&#039;] = (new Date()).getTime() * 1000;&lt;br /&gt;
        // compute the post data&lt;br /&gt;
        var post = querystring.stringify(args);&lt;br /&gt;
        // compute the sha512 signature of the post data&lt;br /&gt;
        var hmac = crypto.createHmac(&#039;sha512&#039;, new Buffer(client.secret, &#039;base64&#039;));&lt;br /&gt;
        hmac.update(post);&lt;br /&gt;
&lt;br /&gt;
        // this is our query&lt;br /&gt;
        var options = {&lt;br /&gt;
                host: &#039;mtgox.com&#039;,&lt;br /&gt;
                port: 443,&lt;br /&gt;
                path: &#039;/api/&#039; + path,&lt;br /&gt;
                method: &#039;POST&#039;,&lt;br /&gt;
                agent: false,&lt;br /&gt;
                headers: {&lt;br /&gt;
                        &#039;Rest-Key&#039;: client.key,&lt;br /&gt;
                        &#039;Rest-Sign&#039;: hmac.digest(&#039;base64&#039;),&lt;br /&gt;
                        &#039;User-Agent&#039;: &#039;Mozilla/4.0 (compatible; MtGox node.js client)&#039;,&lt;br /&gt;
                        &#039;Content-type&#039;: &#039;application/x-www-form-urlencoded&#039;&lt;br /&gt;
                }&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        // run the query, buffer the data and call the callback&lt;br /&gt;
        var req = https.request(options, function(res) {&lt;br /&gt;
                res.setEncoding(&#039;utf8&#039;);&lt;br /&gt;
                var buffer = &#039;&#039;;&lt;br /&gt;
                res.on(&#039;data&#039;, function(data) { buffer += data; });&lt;br /&gt;
                res.on(&#039;end&#039;, function() { if (typeof callback == &amp;quot;function&amp;quot;) { callback(JSON.parse(buffer)); } });&lt;br /&gt;
        });&lt;br /&gt;
&lt;br /&gt;
        // basic error management&lt;br /&gt;
        req.on(&#039;error&#039;, function(e) {&lt;br /&gt;
                console.log(&#039;warning: problem with request: &#039; + e.message);&lt;br /&gt;
        });&lt;br /&gt;
&lt;br /&gt;
        // post the data&lt;br /&gt;
        req.write(post);&lt;br /&gt;
        req.end();&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
var client = new MtGoxClient(&#039;mykey&#039;, &#039;mysecret&#039;);&lt;br /&gt;
client.query(&#039;1/BTCUSD/public/ticker&#039;, {}, function(json) {&lt;br /&gt;
        // do something&lt;br /&gt;
        console.log(json);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>GutenYe</name></author>
	</entry>
</feed>