<p>I have rolled my own mtgox api implementation in java. it is based on <a href="http://code.google.com/p/google-gson/" rel="nofollow">google-Gson</a> and raw URL requests. i plan on releasing it eventually but the code is not yet on release quality level. if you have any specific questions, just ask in comments</p>

CC BY-SA 3.0
2011-09-09T21:30:30.073Z
2011-09-09T21:30:30.073Z
Andreas Petersson
<p>I don't know of a currently existing Java API for Mt Gox - most folks will probably roll their own until Mt Gox issues their own demonstration client in Java. </p>

<p>However, in the interests of helping you make some progress in this area here is a short tutorial that may be of some use.</p>

<p><strong>How to build a Java API for Mt Gox</strong></p>

<p>You could just throw one together using the <a href="https://en.bitcoin.it/wiki/MtGox/API" rel="nofollow">web API specification provided by Mt Gox</a>.</p>

<p>Although the examples are written in PHP, the nature of the API is a bunch of simple HTTP requests which typically use JSON to transfer the payload.</p>

<p>For example the getDepth request</p>

<pre><code>https://mtgox.com/api/0/data/getDepth.php?Currency=PLN
</code></pre>

<p>will return a block of JSON that looks something like this:</p>

<blockquote>
  <p>{"asks":[[13.32937,46.25473014],</p>
  
  <p>....</p>
  
  <p>"bids": [[11.09752,1],[11.18583,259.5],</p>
  
  <p>[12.64579,3]]}</p>
</blockquote>

<p>which can be mapped to a Java object as follows</p>

<pre><code>package org.example.mtgox;

import java.util.List;

public class Depth {
    private List&lt;Asks&gt; asks;
    private List&lt;Bids&gt; bids;

    public List&lt;Asks&gt; getAsks(){
        return this.asks;
    }
    public void setAsks(List&lt;Asks&gt; asks){
        this.asks = asks;
    }
    public List&lt;Bids&gt; getBids(){
        return this.bids;
    }
    public void setBids(List&lt;Bids&gt; bids){
        this.bids = bids;
    }
}
</code></pre>

<p>Add a sprinkle of JAXB annotations (@XmlRootElement and so on), plug it into the RESTEasy framework and it'll handle all the translation for you. Note that JAXB annotations allow rendering to XML, JSON and YAML - they're just markers. Barely a line of code to be written. </p>

<p>Incidentally, if you have a JSON input and you want a bare Java POJO generated from it, you can use the <a href="http://jsongen.byingtondesign.com/" rel="nofollow">very handy JSONGen web service</a>. </p>

<p><strong>Shameless plug</strong></p>

<p>If you want this developed more, then let me know and I'll see what I can do to help.</p>

CC BY-SA 3.0
2011-09-10T23:56:38.197Z
Thank you for your very informative post but actually I use groovy which has very convenient json facilities: 'getMtGoxSslClient().get(path: "api/0/data/ticker.php") { resp, json ->
            println "BUY: " + json.ticker.buy
            println "SELL: " + json.ticker.sell
        }'
barrymac
CC BY-SA 3.0
2011-09-11T07:55:19.823Z
@barrymac Groovy is ideal for this kind of work. I only offered JAXB since you mentioned Java. Good luck with your project.
Gary
CC BY-SA 3.0
2011-09-09T20:58:38.380Z
2011-09-09T20:58:38.380Z
Gary
<p><strong>There is now the <a href="https://github.com/timmolter/XChange">XChange</a> library</strong></p>

<p>This is a pure Java library that has been released under the MIT license. It currently supports Mt Gox, but there are simple hooks to allow other exchanges such as <a href="http://intersango.com">Intersango</a> and <a href="http://cryptoxchange.com/">CryptoXChange</a> to be supported.</p>

<p>It is currently used by the <a href="http://multibit.org">MultiBit</a> client.</p>

CC BY-SA 3.0
2012-07-02T22:04:33.493Z
2012-07-02T22:04:33.493Z
Gary
<p>So far I have seen some Perl modules; <a href="http://search.cpan.org/~mndrix/Finance-MtGox-0.01/lib/Finance/MtGox.pm">Finance:MtGox</a> and <a href="http://search.cpan.org/~beppu/WebService-MtGox-0.05/lib/WebService/MtGox.pm">Webservice:MtGox</a> for interacting with Mt.Gox, a <a href="http://rubygems.org/gems/mtgox">Ruby gem for Mt.Gox</a> and a <a href="http://www.goxsh.info/">Python based command line client</a> for again, Mt.Gox.</p>

<p>I'm wondering if there are any other language APIs for other exchanges? </p>

<p>I'd especially like to find a Java API for more than one exchange.</p>

CC BY-SA 3.0
2013-04-19T07:17:36.357Z
@Harpyon, page not found... 404
Pacerier
CC BY-SA 3.0
2011-09-09T18:08:47.460Z
@barrymac, why don't you make an answer to this question listing the ones you already know with a short description of each. People might add to you answer and we'll soon get a great list without relying on a link to somewhere else.
D.H.
CC BY-SA 3.0
2011-09-09T19:30:00.020Z
@Harpyon Well I might end up doing that, not sure the quality will be amazing though. The authentication mechanism is complicated and confuses me a bit. Also there's an issue with the SSL certificate that makes things annoying as well, you have to add an exclusion to a local trust store and add this to the JDK.
barrymac
CC BY-SA 3.0
2011-09-09T19:31:54.327Z
@D.H. I'll add what I know to the question with some links
barrymac
<development><exchanges>
Is there a list of available APIs for Bitcoin exchanges?
barrymac
# Is there a list of available APIs for Bitcoin exchanges?

(Asked by: username_0 on 2011-09-09)

So far I have seen some Perl modules; [Finance:MtGox](http://search.cpan.org/~mndrix/Finance-MtGox-0.01/lib/Finance/MtGox.pm) and [Webservice:MtGox](http://search.cpan.org/~beppu/WebService-MtGox-0.05/lib/WebService/MtGox.pm) for interacting with Mt.Gox, a [Ruby gem for Mt.Gox](http://rubygems.org/gems/mtgox) and a [Python based command line client](http://www.goxsh.info/) for again, Mt.Gox.

I'm wondering if there are any other language APIs for other exchanges?

I'd especially like to find a Java API for more than one exchange.

**Tags:** development, exchanges

> **Comments:**
> **username_2**: @username_0, why don't you make an answer to this question listing the ones you already know with a short description of each. People might add to you answer and we'll soon get a great list without relying on a link to somewhere else.  
> **username_0**: @Harpyon Well I might end up doing that, not sure the quality will be amazing though. The authentication mechanism is complicated and confuses me a bit. Also there's an issue with the SSL certificate that makes things annoying as well, you have to add an exclusion to a local trust store and add this to the JDK.  
> **username_0**: @D.H. I'll add what I know to the question with some links  
> **username_1**: @Harpyon, page not found... 404  

---

## 3 answers

### Answer by username_4 on 2012-07-02. Score: 7 | Accepted answer

**There is now the [XChange](https://github.com/timmolter/XChange) library**

This is a pure Java library that has been released under the MIT license. It currently supports Mt Gox, but there are simple hooks to allow other exchanges such as [Intersango](http://intersango.com) and [CryptoXChange](http://cryptoxchange.com/) to be supported.

It is currently used by the [MultiBit](http://multibit.org) client.


---

### Answer by username_3 on 2011-09-09. Score: 3

I have rolled my own mtgox api implementation in java. it is based on [google-Gson](http://code.google.com/p/google-gson/) and raw URL requests. i plan on releasing it eventually but the code is not yet on release quality level. if you have any specific questions, just ask in comments


---

### Answer by username_4 on 2011-09-09. Score: 2

I don't know of a currently existing Java API for Mt Gox - most folks will probably roll their own until Mt Gox issues their own demonstration client in Java.

However, in the interests of helping you make some progress in this area here is a short tutorial that may be of some use.

**How to build a Java API for Mt Gox**

You could just throw one together using the [web API specification provided by Mt Gox](https://en.bitcoin.it/wiki/MtGox/API).

Although the examples are written in PHP, the nature of the API is a bunch of simple HTTP requests which typically use JSON to transfer the payload.

For example the getDepth request

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

```

will return a block of JSON that looks something like this:

> {"asks":[[13.32937,46.25473014],
>
> ....
>
> "bids": [[11.09752,1],[11.18583,259.5],
>
> [12.64579,3]]}

which can be mapped to a Java object as follows

```
package org.example.mtgox;

import java.util.List;

public class Depth {
    private List<Asks> asks;
    private List<Bids> bids;

    public List<Asks> getAsks(){
        return this.asks;
    }
    public void setAsks(List<Asks> asks){
        this.asks = asks;
    }
    public List<Bids> getBids(){
        return this.bids;
    }
    public void setBids(List<Bids> bids){
        this.bids = bids;
    }
}

```

Add a sprinkle of JAXB annotations (@XmlRootElement and so on), plug it into the RESTEasy framework and it'll handle all the translation for you. Note that JAXB annotations allow rendering to XML, JSON and YAML - they're just markers. Barely a line of code to be written.

Incidentally, if you have a JSON input and you want a bare Java POJO generated from it, you can use the [very handy JSONGen web service](http://jsongen.byingtondesign.com/).

**Shameless plug**

If you want this developed more, then let me know and I'll see what I can do to help.

> **Comments:**
> **username_0**: Thank you for your very informative post but actually I use groovy which has very convenient json facilities: 'getMtGoxSslClient().get(path: "api/0/data/ticker.php") { resp, json ->             println "BUY: " + json.ticker.buy             println "SELL: " + json.ticker.sell         }'  
> **username_4**: @username_0 Groovy is ideal for this kind of work. I only offered JAXB since you mentioned Java. Good luck with your project.  

---

