MtGox/API/HTTP/v0

From Bitcoin Wiki
Revision as of 00:40, 10 March 2013 by Neofutur (talk | contribs)
Jump to navigation Jump to search

Version 0 of the HTTP API is available at https://mtgox.com/api/0.

HTTP API version 0 methods

0/data/getTrades.php

This allows retrieving all trades which happened in the last 24 hours. The returned data is cached and may not reflect latest activity.

http://data.mtgox.com/api/0/data/getTrades.php?Currency=USD
http://data.mtgox.com/api/0/data/getTrades.php?Currency=USD&since=1

Parameters:

  • since: Passing a tid in "since" allows retrieving all trades since that trade. The passed id is may not exist. Ie. to get all trades from the very beginning one would just call https://mtgox.com/code/data/getTrades.php?since=0 . since returns only 100 trades, and you can call the method again by passing the latest trade you have imported in since.
  • data is returned in standard json format like :
[
{"date":1279408157,
"price":"0.04951",
"amount":"20",
"price_int":"4951",
"amount_int":"2000000000",
"tid":"1",
"price_currency":"USD",
"item":"BTC",
"trade_type":""
"primary":"Y"
},
{"date":1279424586,"price":"0.05941","amount":"50.01","price_int":"5941","amount_int":"5001000000","tid":"2","price_currency":"USD","item":"BTC","trade_type":""}]

0/getDepth.php

Get the current Market depth

https://data.mtgox.com/api/0/data/getDepth.php?Currency=PLN
https://data.mtgox.com/api/0/data/getDepth.php?Currency=AUD
https://data.mtgox.com/api/0/data/getDepth.php?Currency=USD
{"asks":[[11.37998,22.89],[11.38,42.44592124],[11.3844,165],[11.599,1000]],"bids":[[10.7078,0.3],[10.70964,0.02024837],[10.70978,0.55822],[11.2903,2.8]]}

0/getFunds.php

Get your current balance

https://mtgox.com/api/0/getFunds.php

getfunds is now deprecated since multi currency, please use info.php

{
  ["usds"]=> "18.74737"
  ["btcs"]=> "0.01733"
}

0/buyBTC.php

Place an order to Buy BTC

https://mtgox.com/api/0/buyBTC.php

POST data: amount=#&price=#&Currency=PLN

returns a list of your open orders

you can omit the price to do a market order

0/sellBTC.php

Place an order to Sell BTC

https://mtgox.com/api/0/sellBTC.php

POST data: &amount=#&price=#&Currency=PLN

returns a list of your open orders

you can omit the price to do a market order

0/getOrders.php

Fetch a list of your open Orders

https://mtgox.com/api/0/getOrders.php

oid: Order ID

type: 1 for sell order or 2 for buy order

status: 1 for active, 2 for not enough funds

0/cancelOrder.php

Cancel an order

https://mtgox.com/api/0/cancelOrder.php

POST data: oid=#&type=#

oid: Order ID

type: 1 for sell order or 2 for buy order

0/redeemCode.php

Used to redeem a mtgox coupon code

https://mtgox.com/api/0/redeemCode.php

  • call with a post parameter "code" containing the code to redeem
  • it will return an array with amount (float amount value of code), currency (3 letters, BTC or USD), reference (the transaction id), and status

0/redeemBtcPrivkey.php

used to redeem a private key via the API

https://mtgox.com/api/0/redeemBtcPrivkey.php

  • parameters :

"key":code "keytype":"auto" "description":description

  • returns the btc adress and the total number of btcs in this private key

0/withdraw.php

withdraw / Send BTC

https://mtgox.com/api/0/withdraw.php

POST data: group1=BTC&btca=bitcoin_address_to_send_to&amount=#

  • pass btca parameter to withdraw to a btc adress
  • pass group1 for a coupon : BTC2CODE or USD2CODE
  • pass group1=DWUSD&dwaccount=XXX-XXX-XXXX (no btca=xxxxxxx) for a dwolla withdraw
  • pass green=1 to use the new greenaddress feature ( see GreenAddress )
  • pass no_instant=1 to use the bitcoin blockchain, even if the receiving address (btca) is on MtGox
  • return code and status if successful
Example response

{u'status': u'Funds are on their way (bitcoin transaction: 2426f19cda3332b25d02daf2479bc558b243a0631584d75dd2bb8ee45f50a118)',
u'reference': u'58a9e537-e64a-4e66-bc45-31c1bdc3a91b'}

To make a withdraw in another Currency , use group1=USD2CODE and add a Currency parameter ( example Currency=EUR to get a mtgox EUR coupon )

0/btcAddress.php

get a bitcoin deposit adress for your account

https://mtgox.com/api/0/btcAddress.php

  • pass POST data "description" to add a description that will appear in your history when this BTC address receive a deposit
  • pass POST data "ipn" to add an url that mtgox will ping whenever this new address receive funds

description ( see above ) is also required for ipn to work

  • returns a bitcoin deposit address

0/history_[CUR].csv

Allows downloading your activity history for a given currency (BTC or USD for now).

https://mtgox.com/api/0/history_BTC.csv

https://mtgox.com/api/0/history_USD.csv

encoding is utf-8

0/info.php

https://mtgox.com/api/0/info.php

returns info about your account, funds, fees, API privileges, withdraw limits . . .

 {
  ["Login"]=> "some_user"
  ["Index"]=> "111111"
  ["Rights"]=> {
    [0]=> "get_info"
    [1]=> "trade"
  }
  ["Language"]=> "en_US"
  ["Created"]=> "2012-03-12 17:58:53"
  ["Last_Login"]=> "2012-07-10 09:19:56"
  ["Wallets"]=>
   {
    ["BTC"]=>
     {
      ["Balance"]=>
       {
        ["value"]=> "0.01733000"
        ["value_int"]=> "1733000"
        ["display"]=> "0.01733000| BTC"
        ["display_short"]=> "0.02| BTC"
        ["currency"]=> "BTC"
      }
      ["Operations"]=> ''
      ["Daily_Withdraw_Limit"]=>
       {
        ["value"]=> "200.00000000"
        ["value_int"]=> "20000000000"
        ["display"]=> "200.00000000| BTC"
        ["display_short"]=> "200.00| BTC"
        ["currency"]=> "BTC"
      }
      ["Monthly_Withdraw_Limit"]=> ''
      ["Max_Withdraw"]=>
       {
        ["value"]=> "200.00000000"
        ["value_int"]=> "20000000000"
        ["display"]=> "200.00000000| BTC"
        ["display_short"]=> "200.00| BTC"
        ["currency"]=> "BTC"
      }
    }
    ["EUR"]=>
    {
...
    }
  }
  ["Trade_Fee"]=> float(0.6)
}

0/ticker

http://mtgox.com/api/0/data/ticker.php

returns the current ticker :

{"ticker":
 {
 "high":5.70653,
 "low":5.4145,
 "avg":5.561388723,
 "vwap":5.610932845,
 "vol":55698,
 "last":5.56915,
 "buy":5.51326,
 "sell":5.5672
 }
}
the time frame for high, low, vol, avg, vwap . . . is sliding 24 hours

what is vwap ?

please see http://en.wikipedia.org/wiki/VWAP

0/bitcoin_tx

https://mtgox.com/api/0/bitcoin_tx.php

will show the list of all unconfirmed pending txs tracked by mtgox

pending transactions

https://mtgox.com/api/0/bitcoin_tx.php

gives a list of the transaction numbers for transactions broadcasted by mtgox to the bitcoin network, but not yet included in a block

Examples & Tools

Shell-type CLI

python : http://www.goxsh.info/

Perl module

http://pastebin.com/vEpgw5nW

Other

https : http://stackoverflow.com/questions/7046370/https-request-with-boost-asio-and-openssl

https://github.com/sje397/mtgox-plasmoid

module perl : http://search.cpan.org/~mndrix/Finance-MtGox-0.02/

PHP Dashboard

https://github.com/Lexiks/MyBitBoard

PHP ticker and pricing tools

https://github.com/neofutur/bitcoin_simple_php_tools

Bash trade history

bash : https://bitcointalk.org/index.php?topic=39402.0

PHP Ticker & BTCGuild mining estimator

http://pastebin.com/pd0ZR4WY