Package com.appspot.btcticker

Source Code of com.appspot.btcticker.MtGoxServlet

package com.appspot.btcticker;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

import com.appspot.btcticker.enums.Currency;
import com.appspot.btcticker.fsm.MtgoxTickerV2;
import com.appspot.btcticker.model.Valuation;

@SuppressWarnings("serial")
public class MtGoxServlet extends TickerServlet {

    protected void updateBitcoinValue() throws IOException {
        if (upToDate(Currency.BITCOIN)) {
            return;
        }
        // Reset imageCache
        imageCache.clearAll();

        URL url = new URL(MtgoxTickerV2.URL_V2);

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                url.openStream()));
        String response = reader.readLine();

        reader.close();

        // update timestamp
        btcTimestamp = System.currentTimeMillis();
        Valuation valuation = MtgoxTickerV2.parse(response);
        if (valuation == null) {
            throw new RuntimeException("failed to parse: " + response);
        }
        btcRate = valuation.weightedValue();
        buyRate = valuation.buy;
        sellRate = valuation.sell;
    }

}
TOP

Related Classes of com.appspot.btcticker.MtGoxServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.