MtGox/API/HTTP/v2

From Bitcoin Wiki
Revision as of 08:11, 8 April 2013 by Dxbydt (talk | contribs)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

API Version 2:

The V2 API URL is:

https://data.mtgox.com/api/2/

Documentation

unofficial documentation (So far the best we have) is provided at :

https://bitbucket.org/nitrous/mtgox-api/overview
(The bitcointalk forum link is: https://bitcointalk.org/index.php?topic=164404.0

official docs are on  :

https://github.com/MtGox/mtgox-doc

Technical Use Explanation:

The requested path (anything after the /2/) must now be included when you compute your hashed signature (Rest-Sign) for added security.

This is how it was done for version 1:

You have your params(post_data) = the word nonce, followed by the actual nonce integer (params = [(u'nonce',nonce)])

You have your header made up of Rest-Key (your API-KEY) and Rest-Sign (a hashed signature)

Rest-Sign is created by doing : base64encode( HMAC hash( base64decoded(API-secret), the nonce, with SHA512 digest))

What differs in version 2 is now : BEFORE the nonce, you are adding the relative path you are requesting(ie: BTCUSD/money/ticker) + a NUL char (ascii code 0).

The URL is now something along the lines of BTCUSD/money/order/add instead of BTCUSD/private/order/add in api1.
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.


BTCUSD/money/order/quote <@MagicalTux> it estimate the result of running an order at a given price based on market depth


Code Examples:

C# :

https://bitbucket.org/pipe2grep/cryptocoinxchange C# lib for V2 API and socketIO

Python v 2.7.3

http://pastebin.com/aXQfULyq - Remove any proprietary unlock_api_key stuff. You'll need json_ascii also. Works on API 0/1/2. Link to git-repo: genbtc's trader.python

Perl

https://en.bitcoin.it/wiki/MtGox/API/HTTP#PHP The Perl example on the main page is compatible with v2