use slf4j logging in more places
This commit is contained in:
@ -17,7 +17,7 @@ import org.apache.commons.cli.HelpFormatter;
|
||||
* App is the entry point for the application.
|
||||
*/
|
||||
public class App {
|
||||
static final Logger logger = LoggerFactory.getLogger("ATS_Esper");
|
||||
static final Logger log = LoggerFactory.getLogger("ATS_Esper");
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -36,9 +36,9 @@ public class App {
|
||||
try {
|
||||
String epl = readFile(eplFile);
|
||||
processor = new EsperProcessor(epl);
|
||||
logger.info("Using EPL file {}", eplFile);
|
||||
log.info("Using EPL file {}", eplFile);
|
||||
} catch (IOException e) {
|
||||
logger.error("Error reading EPL file {}", eplFile, e);
|
||||
log.error("Error reading EPL file {}", eplFile, e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
@ -46,13 +46,13 @@ public class App {
|
||||
if (cmdline.hasOption("historical")) {
|
||||
String csv = cmdline.getOptionValue("historical");
|
||||
reader = new CSVReader(new File(csv));
|
||||
logger.info("Using CSV file {}", csv);
|
||||
log.info("Using CSV file {}", csv);
|
||||
} else {
|
||||
// TODO: separate
|
||||
AccountInfo acctInfo = new AccountInfo();
|
||||
String[] instruments = getInstruments(cmdline);
|
||||
reader = new OANDAReader(acctInfo, instruments);
|
||||
logger.info("Reading from stream.");
|
||||
log.info("Reading from stream.");
|
||||
}
|
||||
|
||||
reader.run(processor);
|
||||
@ -65,11 +65,11 @@ public class App {
|
||||
if (cmdline.hasOption("instrument")) {
|
||||
String[] instrs = cmdline.getOptionValues("instrument");
|
||||
for (String instr : instrs) {
|
||||
logger.info("using instrument: {}", instr);
|
||||
log.info("using instrument: {}", instr);
|
||||
}
|
||||
return instrs;
|
||||
} else {
|
||||
logger.debug("Using default security: EUR_USD");
|
||||
log.debug("Using default security: EUR_USD");
|
||||
return new String[] { "EUR_USD" };
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.espertech.esper.client.EPServiceProvider;
|
||||
import com.fasterxml.jackson.databind.MappingIterator;
|
||||
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
||||
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
||||
|
||||
|
||||
public class CSVReader implements TickStreamReader {
|
||||
final Logger log = LoggerFactory.getLogger(CSVReader.class);
|
||||
File file;
|
||||
|
||||
|
||||
@ -25,7 +28,7 @@ public class CSVReader implements TickStreamReader {
|
||||
processor.process(value);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("Reading CSV", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class EsperProcessor implements TickProcessor {
|
||||
final Logger logger = LoggerFactory.getLogger(EsperProcessor.class);
|
||||
EPServiceProvider engine;
|
||||
final Logger log = LoggerFactory.getLogger(EsperProcessor.class);
|
||||
EPServiceProvider engine;
|
||||
|
||||
|
||||
public EsperProcessor(String epl) {
|
||||
|
||||
@ -7,6 +7,8 @@ import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
@ -16,6 +18,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
|
||||
public class OANDAReader implements TickStreamReader {
|
||||
final Logger log = LoggerFactory.getLogger(OANDAReader.class);
|
||||
AccountInfo accountInfo;
|
||||
String[] instruments;
|
||||
|
||||
@ -36,15 +39,14 @@ public class OANDAReader implements TickStreamReader {
|
||||
try {
|
||||
query = String.format("instruments=%s", URLEncoder.encode(instrList, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
log.error("Creating stream URL", e);
|
||||
}
|
||||
|
||||
return String.format("https://stream-%s.oanda.com/v3/accounts/%s/pricing/stream?%s",
|
||||
type, accountInfo.accountID(), query);
|
||||
}
|
||||
|
||||
private static void readConnection(String urlStr, TickProcessor processor) {
|
||||
|
||||
private void readConnection(String urlStr, TickProcessor processor) {
|
||||
HttpsURLConnection httpConn = null;
|
||||
String line = null;
|
||||
try {
|
||||
@ -65,12 +67,8 @@ public class OANDAReader implements TickStreamReader {
|
||||
while ((line = is.readLine( )) != null) {
|
||||
processLine(line, processor);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch(SocketTimeoutException e){
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("Reading OANDA stream", e);
|
||||
} finally {
|
||||
httpConn.disconnect();
|
||||
}
|
||||
@ -78,21 +76,23 @@ public class OANDAReader implements TickStreamReader {
|
||||
|
||||
static ObjectMapper mapper = new ObjectMapper(); // create once, reuse
|
||||
|
||||
private static void processLine(String line, TickProcessor processor) {
|
||||
private void processLine(String line, TickProcessor processor) {
|
||||
if (line.indexOf ("PRICE") > -1) {
|
||||
OANDATick tick;
|
||||
try {
|
||||
tick = mapper.readValue(line, OANDATick.class);
|
||||
// log.info(line);
|
||||
processor.process(tick);
|
||||
} catch (JsonParseException | JsonMappingException e) {
|
||||
e.printStackTrace();
|
||||
log.error("Parsing OANDA data", e);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("Parsing OANDA data", e);
|
||||
}
|
||||
} else if (line.indexOf ("HEARTBEAT") > -1) {
|
||||
// ignore
|
||||
log.debug(line);
|
||||
} else {
|
||||
System.out.println("Unknown type: " + line);
|
||||
log.warn("Unknown type: {}", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user