Bitcoin Forum
April 19, 2024, 11:13:00 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: JAVA implementation for Mt. Gox API needed  (Read 814 times)
CharlyBln (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
June 28, 2011, 09:00:14 PM
 #1

Hey Guys,

aside from the fact, that the Mt.Gox API seems to be not available for the moment i need your help.
Does anybody know an existing JAVA implementation for POST an https request on Mt.Gox?
I have experiences in programming with JAVA and i want to implement a simple "ticker" program, that only displays me current rates.
This whole displaying stuff and further functions will not be the problem, but my actual problem is getting the raw-data from Mt.Gox.
I would be so thankful if anybody has a short JAVA-example for me, which gives me some hints for solving this problem.
1713525180
Hero Member
*
Offline Offline

Posts: 1713525180

View Profile Personal Message (Offline)

Ignore
1713525180
Reply with quote  #2

1713525180
Report to moderator
1713525180
Hero Member
*
Offline Offline

Posts: 1713525180

View Profile Personal Message (Offline)

Ignore
1713525180
Reply with quote  #2

1713525180
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713525180
Hero Member
*
Offline Offline

Posts: 1713525180

View Profile Personal Message (Offline)

Ignore
1713525180
Reply with quote  #2

1713525180
Report to moderator
1713525180
Hero Member
*
Offline Offline

Posts: 1713525180

View Profile Personal Message (Offline)

Ignore
1713525180
Reply with quote  #2

1713525180
Report to moderator
CharlyBln (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
June 29, 2011, 08:10:17 AM
 #2

Is there nobody out there, who has something like this implemented? I need really only a code-fragment which grabs the ticker-data from Mt. Gox...
SlipperySlope
Hero Member
*****
Offline Offline

Activity: 686
Merit: 501

Stephen Reed


View Profile
June 29, 2011, 02:05:14 PM
 #3

Is there nobody out there, who has something like this implemented? I need really only a code-fragment which grabs the ticker-data from Mt. Gox...

I have not yet tried POST on Mt Gox.  Because their websocket API is non-responsive, I have been polling their published ticker API ...


Code:
    final String httpsURLString = "https://mtgox.com/code/data/ticker.php";
    final StringBuilder stringBuilder = new StringBuilder();
    try {
      final URL url = new URL(httpsURLString);
      final HttpsURLConnection httpURLConnection = (HttpsURLConnection) url.openConnection();
      final InputStream inputStream = httpURLConnection.getInputStream();
      final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

      String inputLine;

      while ((inputLine = bufferedReader.readLine()) != null) {
        stringBuilder.append(inputLine);
        stringBuilder.append(' ');
      }

      bufferedReader.close();
    } catch (IOException ex) {
      // report exception
    }

    final JSONObject jsonObject1 = (JSONObject) JSONValue.parse(stringBuilder.toString());
    final JSONObject jsonObject2 = (JSONObject) jsonObject1.get("ticker");
    final BigDecimal bidPrice = new BigDecimal(jsonObject2.get("buy").toString());
    final BigDecimal askPrice = new BigDecimal(jsonObject2.get("sell").toString());
    final BigDecimal lastPrice = new BigDecimal(jsonObject2.get("last").toString());
    final BigDecimal highPrice = new BigDecimal(jsonObject2.get("high").toString());
    final BigDecimal lowPrice = new BigDecimal(jsonObject2.get("low").toString());
    final BigDecimal volume = new BigDecimal(jsonObject2.get("vol").toString());


The json-simple1.1.jar is a dependency.  I used keytool to import the Mt Gox SSL certificates from my web browser into cacerts, as I previously deleted all X509 certificates from that keystore as a security precaution.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!