Created
October 16, 2019 01:29
-
-
Save boshng95/d41c46660aae8ad84b2e6e3af526b609 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void getStockPricesOnline(final String companyCode){ | |
Thread thread = new Thread(new Runnable() { | |
@Override | |
public void run() { | |
String inputLine; | |
String result; | |
boolean successful = false; | |
while(!successful){ | |
try{ | |
String url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" | |
+companyCode+ | |
"&apikey=demo&outputsize=compact"; | |
System.out.println(url); | |
URL api = new URL(url); | |
HttpURLConnection connection =(HttpURLConnection) api.openConnection(); | |
connection.connect(); | |
InputStreamReader streamReader = new InputStreamReader(connection.getInputStream()); | |
BufferedReader reader = new BufferedReader(streamReader); | |
StringBuilder stringBuilder = new StringBuilder(); | |
while((inputLine = reader.readLine()) != null){ | |
stringBuilder.append(inputLine); | |
} | |
reader.close(); | |
streamReader.close(); | |
result = stringBuilder.toString(); | |
JSONObject jsonObject = new JSONObject(result); | |
} catch (Exception ex){ | |
ex.printStackTrace(); | |
} | |
} | |
} | |
}); | |
thread.start(); | |
try{ | |
thread.join(); | |
}catch (Exception ex){ | |
ex.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment