MtGox/API/HTTP/v2: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
GenBTC (talk | contribs)
Karlb (talk | contribs)
No edit summary
 
(4 intermediate revisions by 4 users not shown)
Line 5: Line 5:


=== Documentation ===
=== Documentation ===
'''unofficial''' documentation (So far the best we have) is provided at :
'''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 )


'''https://bitbucket.org/nitrous/mtgox-api/overview''' <br>
'''Official''' docs are on: https://github.com/MtGox/mtgox-doc
(The bitcointalk forum link is: '''https://bitcointalk.org/index.php?topic=164404.0'''
<br>


'''official''' docs are on  :
===== Differences between v1 and v2: =====


'''https://github.com/MtGox/mtgox-doc'''
* The '''URL''' is now something along the lines of BTCUSD/money/order/add instead of BTCUSD/private/order/add in api1. All current known methods are found in the money category.
* The ''requested path''  must now be included when you compute your '''hashed signature (Rest-Sign)''' for added security.<br><br> In version 1, Rest-Sign is created through base64-encoding the 256-digest HMAC hashing of your post data (which of course must include your nonce) with your API secret, previously base64 decoded. Now in version 2,  you must simply add ''before'' your post data the relative path you are requesting (anything after the /api/2/ base, ie: BTCUSD/money/ticker), concatenated with a NUL character (ASCII code 0). So the signature is now made starting from your relative path + NUL character + post data (which must include your nonce!).


===== Technical Use Explanation: =====
* fast ticker
http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast


The requested path (anything after the /2/) must now be included when you compute your hashed signature (Rest-Sign) for added security.
and
 
This is how it was done for version 1:
http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast?pretty
 
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. <br>
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.


=== Explanation of Methods ===
=== Explanation of Methods ===
Line 40: Line 29:


=== Code Examples: ===
=== Code Examples: ===
====Java:====
https://github.com/adv0r/mtgox-api-v2-java Java lib for API V2, under development


====C# :====
====C# :====
Line 47: Line 40:
====Python v 2.7.3====
====Python v 2.7.3====


https://bitbucket.org/karlb/gox2 -  A minimalistic API wrapper <br>
http://pastebin.com/aXQfULyq - Remove any proprietary unlock_api_key stuff. You'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's trader.python] <br>
http://pastebin.com/aXQfULyq - Remove any proprietary unlock_api_key stuff. You'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's trader.python] <br>


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

Latest revision as of 08:33, 1 November 2013

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

Differences between v1 and v2:
  • The URL is now something along the lines of BTCUSD/money/order/add instead of BTCUSD/private/order/add in api1. All current known methods are found in the money category.
  • The requested path must now be included when you compute your hashed signature (Rest-Sign) for added security.

    In version 1, Rest-Sign is created through base64-encoding the 256-digest HMAC hashing of your post data (which of course must include your nonce) with your API secret, previously base64 decoded. Now in version 2, you must simply add before your post data the relative path you are requesting (anything after the /api/2/ base, ie: BTCUSD/money/ticker), concatenated with a NUL character (ASCII code 0). So the signature is now made starting from your relative path + NUL character + post data (which must include your nonce!).
  • fast ticker
http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast

and

http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast?pretty

Explanation of Methods

BTCUSD/money/order/quote
<@MagicalTux> it estimate the result of running an order at a given price based on market depth
BTCUSD/money/ticker_fast
Solves the problem of ticker lag. (supposedly)


Code Examples:

Java:

https://github.com/adv0r/mtgox-api-v2-java Java lib for API V2, under development

C# :

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

Python v 2.7.3

https://bitbucket.org/karlb/gox2 - A minimalistic API wrapper
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

PHP

https://github.com/pathaksa/MtGox-PHP-API-V2