用Java查询比特币实时行情 - 附免费查询接口

支持多种语言:Go, PHP, Java, Python,详细文档

Github地址:GitHub

注意:返回的数据均为实时,并非延时数据,查询方法看代码:

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

/*
 * 接口详细介绍:https://alltick.co/crypto-api
 * 备用地址:https://alltick.io
 * 免费token申请地址:https://alltick.co/register
 * 适用于量化交易的高频行情接口,实时逐笔成交数据
 * 可查询品种:A股、港股、美股、外汇、期货、加密货币
 */

public class HttpJavaExample {

    public static void main(String[] args) {

        try {

            /*
            Encode the following JSON into URL format and copy it to the query field of the HTTP request
            {"trace" : "java_http_test1","data" : {"code" : "700.HK","kline_type" : 1,"kline_timestamp_end" : 0,"query_kline_num" : 2,"adjust_type": 0}}
            Special Note:
            GitHub: https://github.com/alltick/realtime-forex-crypto-stock-tick-finance-websocket-api
            Token Application: https://alltick.co
            Replace "testtoken" in the URL below with your own token
            API addresses for forex, cryptocurrencies, and precious metals:
            https://quote.tradeswitcher.com/quote-b-api
            Stock API address:
            https://quote.tradeswitcher.com/quote-stock-b-api
            */
            String url = "http://quote.tradeswitcher.com/quote-stock-b-api/kline?token=testtoken&query=%7B%22trace%22%20%3A%20%22java_http_test1%22%2C%22data%22%20%3A%20%7B%22code%22%20%3A%20%22700.HK%22%2C%22kline_type%22%20%3A%201%2C%22kline_timestamp_end%22%20%3A%200%2C%22query_kline_num%22%20%3A%202%2C%22adjust_type%22%3A%200%7D%7D";

            URL obj = new URL(url);

            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            con.setRequestMethod("GET");

            int responseCode = con.getResponseCode();

            System.out.println("Response Code: " + responseCode);

            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

            String inputLine;

            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }

            in.close();

            System.out.println(response.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_34102871/article/details/143329029