AlexTCX
/
aStock-realtime-market-data-tick-chinaStock-cnStock-aShare-cnShare-chinaShare-api-websocket
Public
forked from alltick/alltick-realtime-forex-crypto-stock-tick-finance-websocket-api
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHttpJavaExample.java
More file actions
54 lines (38 loc) · 2.01 KB
/
HttpJavaExample.java
File metadata and controls
54 lines (38 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
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();
}
}
}