MtGox/API/HTTP/v0: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Nederhoed (talk | contribs)
Neofutur (talk | contribs)
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Version 0 of the HTTP API is available at https://mtgox.com/api/0.
Version 0 of the HTTP API is available at https://data.mtgox.com/api/0/.<br />
This API is becoming deprecated. You will see warning messages in the responses when you use this API.<br />
The URLs used as titles below already include the 0 as part of the url shown above. There is no need to repeat this.


== HTTP API version 0 methods ==
== HTTP API version 0 methods ==
Line 5: Line 7:
=== 0/data/getTrades.php ===
=== 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.
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:
Parameters:
Line 29: Line 34:
Get the current Market depth
Get the current Market depth


https://mtgox.com/api/0/data/getDepth.php?Currency=PLN
https://data.mtgox.com/api/0/data/getDepth.php?Currency=PLN
 
https://data.mtgox.com/api/0/data/getDepth.php?Currency=AUD
https://mtgox.com/api/0/data/getDepth.php?Currency=AUD
https://data.mtgox.com/api/0/data/getDepth.php?Currency=USD
 
https://mtgox.com/api/0/data/getDepth.php?Currency=USD


<source lang="php">
<source lang="php">
Line 42: Line 45:
Get your current balance
Get your current balance


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


getfunds is now deprecated since multi currency, please use info.php
getfunds is now deprecated since multi currency, please use info.php
Line 56: Line 59:
Place an order to Buy BTC
Place an order to Buy BTC


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


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


returns a list of your open orders
returns a list of your open orders


you can omit the price to do a market order
you can omit the price to do a market order
This will return THE ENTIRE list of all open orders (after the cancel). <br>
Consider switching to V1/V2 if you do not need the complete list returned after every call to buyBTC.php <br>


=== 0/sellBTC.php ===
=== 0/sellBTC.php ===
Place an order to Sell BTC
Place an order to Sell BTC


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


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


returns a list of your open orders
returns a list of your open orders


you can omit the price to do a market order
you can omit the price to do a market order
This will return THE ENTIRE list of all open orders (after the cancel). <br>
Consider switching to V1/V2 if you do not need the complete list returned after every call to sellBTC.php <br>


=== 0/getOrders.php ===
=== 0/getOrders.php ===
Fetch a list of your open Orders
Fetch a list of your open Orders


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


oid: Order ID
oid: Order ID
Line 85: Line 94:


status: 1 for active, 2 for not enough funds
status: 1 for active, 2 for not enough funds
This will return THE ENTIRE list of all open orders (after the cancel). <br>
Consider switching to V1/V2 if you do not need the complete list returned after every call to getOrders.php <br>
This will break apart "Not enough funds" Orders into two parts, the first part will be the order ID with the amount of the valid portion. The second part will have an "X" in front of the Order_ID (so it will be 1 char longer) with the amount of the INVALID portion. (that you can't afford)


=== 0/cancelOrder.php ===
=== 0/cancelOrder.php ===
Cancel an order
Cancel an order


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


POST data: oid=#&type=#
POST data: oid=#&type=#
Line 96: Line 109:


type: 1 for sell order or 2 for buy order
type: 1 for sell order or 2 for buy order
This will return THE ENTIRE list of all open orders (after the cancel).<br>
Consider switching to V1/V2 if you do not need the complete list returned after every call to cancelOrder.php


=== 0/redeemCode.php ===
=== 0/redeemCode.php ===
Used to redeem a mtgox coupon code
Used to redeem a mtgox coupon code


https://mtgox.com/api/0/redeemCode.php
Most likely requires deposit privileges on the API Key.
 
https://data.mtgox.com/api/0/redeemCode.php


* call with a post parameter "code" containing the code to redeem
* call with a post parameter "code" containing the code to redeem
Line 107: Line 125:


=== 0/redeemBtcPrivkey.php ===
=== 0/redeemBtcPrivkey.php ===
used to redeem a private key via the API


used to redeem a private key via the API
Most likely requires deposit privileges on the API Key.


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


* parameters :  
* parameters :  
Line 121: Line 140:
=== 0/withdraw.php ===
=== 0/withdraw.php ===
withdraw / Send BTC
withdraw / Send BTC
You NEED Withdraw privileges set up to enabled on the API key.


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


POST data: group1=BTC&btca=bitcoin_address_to_send_to&amount=#
POST data: group1=BTC&btca=bitcoin_address_to_send_to&amount=#
Line 136: Line 156:
{u'status': u'Funds are on their way (bitcoin transaction: 2426f19cda3332b25d02daf2479bc558b243a0631584d75dd2bb8ee45f50a118)',
{u'status': u'Funds are on their way (bitcoin transaction: 2426f19cda3332b25d02daf2479bc558b243a0631584d75dd2bb8ee45f50a118)',
<br/> u'reference': u'58a9e537-e64a-4e66-bc45-31c1bdc3a91b'}
<br/> u'reference': u'58a9e537-e64a-4e66-bc45-31c1bdc3a91b'}
;Example error:
{u'error': u'Please enter a valid amount'}


  To make a withdraw in another Currency , use group1=USD2CODE and add a Currency parameter ( example Currency=EUR to get a mtgox EUR coupon )
  To make a withdraw in another Currency , use group1=USD2CODE and add a Currency parameter ( example Currency=EUR to get a mtgox EUR coupon )
Line 142: Line 164:
get a bitcoin deposit adress for your account  
get a bitcoin deposit adress for your account  


https://mtgox.com/api/0/btcAddress.php
You NEED Deposit privileges set up to enabled on the API key.
 
https://data.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 "description" to add a description that will appear in your history when this BTC address receive a deposit
Line 150: Line 174:


* returns a bitcoin deposit address
* returns a bitcoin deposit address
;Example response:
{u'return': {u'addr': u'17A1vbzQ39o8cGNnpqx8UvXNrhqwAEP8wY'}, u'result': u'success'}


=== 0/history_[CUR].csv ===
=== 0/history_[CUR].csv ===
Line 155: Line 182:
Allows downloading your activity history for a given currency (BTC or USD for now).
Allows downloading your activity history for a given currency (BTC or USD for now).


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


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


encoding is utf-8
encoding is utf-8
Line 163: Line 190:
=== 0/info.php ===
=== 0/info.php ===


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


returns info about your account, funds, fees, API privileges, withdraw limits . . .  
returns info about your account, funds, fees, API privileges, withdraw limits . . .  
Line 220: Line 247:
=== 0/ticker ===
=== 0/ticker ===


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


returns the current ticker :
returns the current ticker :
Line 247: Line 274:
=== 0/bitcoin_tx ===
=== 0/bitcoin_tx ===


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


will show the list of all unconfirmed pending txs tracked by mtgox
will show the list of all unconfirmed pending txs tracked by mtgox
when you place a tx on mtgox, we try to broadcast it, but if after 2 hours it hasn't appeared in the blockchain, it'll appear in this API
containing the raw signed tx number in base64


=== pending transactions ===
=== pending transactions ===


https://mtgox.com/api/0/bitcoin_tx.php
https://data.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
gives a list of the transaction numbers for transactions broadcasted by mtgox to the bitcoin network, but not yet included in a block

Latest revision as of 11:34, 12 April 2013

Version 0 of the HTTP API is available at https://data.mtgox.com/api/0/.
This API is becoming deprecated. You will see warning messages in the responses when you use this API.
The URLs used as titles below already include the 0 as part of the url shown above. There is no need to repeat this.

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://data.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://data.mtgox.com/api/0/buyBTC.php

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

returns a list of your open orders

you can omit the price to do a market order

This will return THE ENTIRE list of all open orders (after the cancel).
Consider switching to V1/V2 if you do not need the complete list returned after every call to buyBTC.php

0/sellBTC.php

Place an order to Sell BTC

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

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

returns a list of your open orders

you can omit the price to do a market order

This will return THE ENTIRE list of all open orders (after the cancel).
Consider switching to V1/V2 if you do not need the complete list returned after every call to sellBTC.php

0/getOrders.php

Fetch a list of your open Orders

https://data.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

This will return THE ENTIRE list of all open orders (after the cancel).
Consider switching to V1/V2 if you do not need the complete list returned after every call to getOrders.php
This will break apart "Not enough funds" Orders into two parts, the first part will be the order ID with the amount of the valid portion. The second part will have an "X" in front of the Order_ID (so it will be 1 char longer) with the amount of the INVALID portion. (that you can't afford)

0/cancelOrder.php

Cancel an order

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

POST data: oid=#&type=#

oid: Order ID

type: 1 for sell order or 2 for buy order

This will return THE ENTIRE list of all open orders (after the cancel).
Consider switching to V1/V2 if you do not need the complete list returned after every call to cancelOrder.php

0/redeemCode.php

Used to redeem a mtgox coupon code

Most likely requires deposit privileges on the API Key.

https://data.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

Most likely requires deposit privileges on the API Key.

https://data.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 You NEED Withdraw privileges set up to enabled on the API key.

https://data.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'}

Example error

{u'error': u'Please enter a valid amount'}

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

You NEED Deposit privileges set up to enabled on the API key.

https://data.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
Example response

{u'return': {u'addr': u'17A1vbzQ39o8cGNnpqx8UvXNrhqwAEP8wY'}, u'result': u'success'}

0/history_[CUR].csv

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

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

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

encoding is utf-8

0/info.php

https://data.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://data.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://data.mtgox.com/api/0/bitcoin_tx.php

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

when you place a tx on mtgox, we try to broadcast it, but if after 2 hours it hasn't appeared in the blockchain, it'll appear in this API

containing the raw signed tx number in base64

pending transactions

https://data.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