<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=MtGox%2FAPI%2FHTTP</id>
	<title>MtGox/API/HTTP - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=MtGox%2FAPI%2FHTTP"/>
	<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=MtGox/API/HTTP&amp;action=history"/>
	<updated>2026-05-15T07:44:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>http://en.zaoniao.it/index.php?title=MtGox/API/HTTP&amp;diff=5977&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;Two versions of the HTTP API are currently available, see the following pages for details on the methods available for each:  * Version 0 * MtGox/API/H...&quot;</title>
		<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=MtGox/API/HTTP&amp;diff=5977&amp;oldid=prev"/>
		<updated>2019-06-17T05:21:19Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Two versions of the HTTP API are currently available, see the following pages for details on the methods available for each:  * &lt;a href=&quot;/MtGox/API/HTTP/v0&quot; title=&quot;MtGox/API/HTTP/v0&quot;&gt;Version 0&lt;/a&gt; * MtGox/API/H...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&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;
'''The URL mtgox.com was changed to data.mtgox.com on March 19th 2013. https://bitcointalk.org/index.php?topic=150786.0'''&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;
== tonce and nonce ==&lt;br /&gt;
&lt;br /&gt;
Each request to the private http API ( v0, v1 , or v2 ) needs to have a nonce or a tonce&lt;br /&gt;
&lt;br /&gt;
Please have a look at http://en.wikipedia.org/wiki/Cryptographic_nonce for explanations of what is a nonce .&lt;br /&gt;
&lt;br /&gt;
See also http://en.wikipedia.org/wiki/System_time and http://en.wikipedia.org/wiki/Unix_time&lt;br /&gt;
&lt;br /&gt;
The tonce is a variant of the nonce.&lt;br /&gt;
&lt;br /&gt;
A few facts about nonce and tonce :&lt;br /&gt;
&lt;br /&gt;
* The value of the nonce must always increase, if you use a very high value during your tests, you could have to generate new api keys to be allowed to get back to lower values&lt;br /&gt;
&lt;br /&gt;
* The value of the tonce is based on the current timestamp in microseconds ( example : 1368892862123456 ) . It needs to be current microtime with +/- 10secs, and needs to be unique&lt;br /&gt;
&lt;br /&gt;
* Your computer's time needs to be exact if you want to use the tonce parameter&lt;br /&gt;
&lt;br /&gt;
* For the tonce you will use the time in microseconds , besed on http://en.wikipedia.org/wiki/Unix_time&lt;br /&gt;
&lt;br /&gt;
* As long as your tonce value is unique and is within +/-10secs of now, it doesn't need to be incremental&lt;br /&gt;
&lt;br /&gt;
* depending of which you want to use, you will add the &amp;quot;tonce=&amp;quot; or &amp;quot;nonce=&amp;quot; parameter to your api request&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;
 '''basically the base64 string should contain:'''&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'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;
'''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;
=== perl ===&lt;br /&gt;
&lt;br /&gt;
'''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'''&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT! This requires you compiled perl libwww with https support'''&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 = '_MTGOX API SECRET GET YOURS AT https://classic.mtgox.com/support/tradeAPI';&lt;br /&gt;
my $key = '_MTGOX API KEY GET YOURS AT https://classic.mtgox.com/support/tradeAPI';&lt;br /&gt;
&lt;br /&gt;
## user code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
my $request = genReq('/1/generic/private/info');&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; 'https://mtgox.com/api/'.$uri);&lt;br /&gt;
        $req-&amp;gt;content_type('application/x-www-form-urlencoded');&lt;br /&gt;
        $req-&amp;gt;content(&amp;quot;nonce=&amp;quot;.microtime());&lt;br /&gt;
        $req-&amp;gt;header('Rest-Key' =&amp;gt; $key);&lt;br /&gt;
        $req-&amp;gt;header('Rest-Sign' =&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 = '';&lt;br /&gt;
	$secret = '';&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(' ', microtime());&lt;br /&gt;
	$req['nonce'] = $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, '', '&amp;amp;');&lt;br /&gt;
&lt;br /&gt;
	$prefix = '';&lt;br /&gt;
	if (substr($path, 0, 2) == '2/') {&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;
		'Rest-Key: '.$key,&lt;br /&gt;
		'Rest-Sign: '.base64_encode(hash_hmac('sha512', $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, 'Mozilla/4.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');&lt;br /&gt;
	}&lt;br /&gt;
	curl_setopt($ch, CURLOPT_URL, 'https://mtgox.com/api/'.$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('Could not get reply: '.curl_error($ch));&lt;br /&gt;
	$dec = json_decode($res, true);&lt;br /&gt;
	if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');&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('0/info.php'));&lt;br /&gt;
&lt;br /&gt;
// old api (get funds)&lt;br /&gt;
var_dump(mtgox_query('0/getFunds.php'));&lt;br /&gt;
&lt;br /&gt;
// trade example&lt;br /&gt;
// var_dump(mtgox_query('0/buyBTC.php', array('amount' =&amp;gt; 1, 'price' =&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;
* [[Mt. Gox]]&lt;br /&gt;
* [http://bitcointalk.org/index.php?topic=164404.0 MtGox API version 2: Unofficial Documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technology]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
		
	</entry>
</feed>