factor App.java into domain classes

This commit is contained in:
2018-04-06 18:24:19 -07:00
parent 64a13a3727
commit aff8fb8404
11 changed files with 382 additions and 61 deletions

View File

@ -1,75 +1,30 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import javax.net.ssl.HttpsURLConnection;
//import com.espertech.esper.client.*;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
public class App {
public static void main(String[] args) {
//EPServiceProvider esper = EPServiceProviderManager.getDefaultProvider();
//EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider();
File f = new File("/home/alx/Nextcloud/projects/ATS_Esper/EURUSD-2017-01-small.csv");
// new CSVReader(f).run(new DebugProcessor());
try {
String[] instruments = new String[] {"USD_CAD", "EUR_USD", "USD_JPY"};
String query = String.format("instruments=%s",
URLEncoder.encode(String.join(",", instruments), "UTF-8"));
openConnection("https://stream-fxpractice.oanda.com/v3/accounts/101-001-7935538-001/pricing/stream?" + query);
} catch (IOException e) {
e.printStackTrace();
}
}
private static void openConnection(String urlStr)
throws IOException
{
HttpsURLConnection httpConn = null;
String line = null;
try {
URL url = new URL(urlStr);
URLConnection urlConn = url.openConnection();
if (!(urlConn instanceof HttpsURLConnection)) {
throw new IOException ("URL is not an Https URL");
}
httpConn = (HttpsURLConnection)urlConn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.setReadTimeout(50 * 1000);
httpConn.setRequestProperty("Authorization", "Bearer 9a480f0b83e987f4015cf0846790c7d9-695ced635526744abd61bdf0e2ae8b71");
BufferedReader is =
new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
while ((line = is.readLine( )) != null) {
System.out.println(line);
// Message msg = Message.obtain();
// msg.what=1;
// msg.obj=line;
// mhandler.sendMessage(msg);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch(SocketTimeoutException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
//Message msg = Message.obtain();
//msg.what=2;
//BufferedInputStream in = new BufferedInputStream(httpConn.getErrorStream());
//line = new String(readStream(in));
//msg.obj = line;
//mhandler.sendMessage(msg);
} finally {
httpConn.disconnect();
}
AccountInfo acctInfo = new AccountInfo();
String[] instruments = new String[] { "USD_CAD", "EUR_USD", "USD_JPY" };
new OANDAReader(acctInfo, instruments).run(new DebugProcessor());
}
}