Post
Topic
Board Marketplace
[BETA] MTGox websocket API, testers wanted
by
MagicalTux
on 15/04/2011, 02:48:21 UTC
Hi,

There's a new MTGox websocket API. This API works by subscription to channels, and each channel is represented by an UUID.

You can connect via: ws://websocket.mtgox.com/mtgox

The websocket will subscribe you to some channels automatically:
  • dbf1dee9-4f2e-4a08-8cb7-748919a71b21: trades (each time a trade happens, you get something here)
  • d5f06780-30a8-4a48-a2f8-7ed181b4a13f: the mtgox ticker (lots of updates, with often the same data)
  • 24e67e0d-1cad-4cc0-9e7a-f8523ef460fe: depth information in realtime (price + amount + type... type=1=Ask, type=2=Bid)

Additionally each user has a "own" channel which streams informations about orders (new order, deleted order, etc) and trades only the user's trades).

Each message is a JSON-encoded object, with at least "op" element. The "op" element contains the operation to be done (for outgoing messages), or the type of message (for incoming messages).

Possible outgoing commands:

  • unsubscribe Stop receiving messages from a channel (parameter "channel")

Example incoming data:

Ticker
Code:
{"channel":"d5f06780-30a8-4a48-a2f8-7ed181b4a13f","op":"private","origin":"broadcast","private":"ticker","ticker":{"buy":0.9515,"high":1,"low":0.91,"sell":0.9697,"vol":34349}}
Trade
Code:
{"channel":"dbf1dee9-4f2e-4a08-8cb7-748919a71b21","op":"private","origin":"broadcast","private":"trade","trade":{"amount":2.71,"amount_int":"271000000","date":1310279340,"item":"BTC","price":14.43,"price_currency":"USD","price_int":"1443000","tid":"1310279340877902","trade_type":"bid","type":"trade"}}

Contains:
  • amount: the traded amount in item (BTC), float, deprecated
  • amount_int: same as amount, but in smallest unit
  • date: unix timestamp of trade
  • item: What was this trade about
  • price: price per unit, float, deprecated
  • price_int: price in smallest unit as integer (5 decimals of USD, 3 in case of JPY)
  • price_currency: currency in which trade was completed
  • tid: Trade id (big integer, which is in fact trade timestamp in microseconds)
  • trade_type: Did this trade result from the execution of a bid or a ask?

Depth update
Code:
{"channel":"24e67e0d-1cad-4cc0-9e7a-f8523ef460fe","depth":{"currency":"USD","item":"BTC","price":"14.43","price_int":"1443000","type":1,"type_str":"ask","volume":"-2.71","volume_int":"-271000000"},"op":"private","origin":"broadcast","private":"depth"}

Contains:
  • currency: the currency affected
  • item: the item (BTC)
  • price: price as a float, deprecated
  • price_int: the price at which volume change happened
  • type: 1=ask 2=bid. Deprecated, see type_str
  • type_str: type of order at this depth, either "ask" or "bid"
  • volume: the volume change as float, deprecated
  • volume_int: volume change in smallest unit

(priv) Order update
Code:
{"channel":"(partial key)","op":"private","order_upd":{"amount":1000,"darkStatus":0,"date":1302836027,"oid":"(oid)","price":0.9899,"status":1},"origin":"broadcast","private":"order_upd"}


This is still under tests, and any element of this websocket API may change anytime.
Ideas/comments are welcome Smiley