Bitcoin Forum
December 13, 2017, 03:39:43 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: JAVA implementation for Mt. Gox API needed  (Read 718 times)
CharlyBln
Newbie
*
Offline Offline

Activity: 4


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.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1513136383
Hero Member
*
Offline Offline

Posts: 1513136383

View Profile Personal Message (Offline)

Ignore
1513136383
Reply with quote  #2

1513136383
Report to moderator
CharlyBln
Newbie
*
Offline Offline

Activity: 4


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

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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!