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