Move OANDA account info into separate file
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@
|
|||||||
/.emacs.desktop.lock
|
/.emacs.desktop.lock
|
||||||
/.meghanada/
|
/.meghanada/
|
||||||
*.csv
|
*.csv
|
||||||
|
/config/config.properties
|
||||||
|
|||||||
@ -59,7 +59,11 @@ distributions {
|
|||||||
include '*.epl'
|
include '*.epl'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
into('config') {
|
||||||
|
from('config') {
|
||||||
|
include '*.properties'
|
||||||
|
}
|
||||||
|
}
|
||||||
// exclude('**/.data/**')
|
// exclude('**/.data/**')
|
||||||
// from('src/main/webapp') {
|
// from('src/main/webapp') {
|
||||||
// include '**/*.jsp'
|
// include '**/*.jsp'
|
||||||
|
|||||||
11
config/config.properties.sample
Normal file
11
config/config.properties.sample
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Configuration properties
|
||||||
|
|
||||||
|
# An OANDA numeric account id
|
||||||
|
OANDA.accountID=000-000-0000000-000
|
||||||
|
|
||||||
|
# The personal API access token for the account ID above
|
||||||
|
OANDA.accessToken=00000000000000000000000000000000-00000000000000000000000000000000
|
||||||
|
|
||||||
|
# Set to 'true' if the account is on the 'fxlive' service.
|
||||||
|
# Set to 'false' if the account is on the 'fxpractice' service.
|
||||||
|
OANDA.isLiveAccount=false
|
||||||
@ -1,16 +0,0 @@
|
|||||||
public class AccountInfo {
|
|
||||||
|
|
||||||
// TODO use properties file
|
|
||||||
|
|
||||||
public String accountID() {
|
|
||||||
return "101-001-7935538-001";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLiveAccount() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String accessToken() {
|
|
||||||
return "9a480f0b83e987f4015cf0846790c7d9-695ced635526744abd61bdf0e2ae8b71";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -48,11 +48,7 @@ public class App {
|
|||||||
String csv = cmdline.getOptionValue("historical");
|
String csv = cmdline.getOptionValue("historical");
|
||||||
reader = new CSVReader(new File(csv));
|
reader = new CSVReader(new File(csv));
|
||||||
log.info("Using CSV file {}", csv);
|
log.info("Using CSV file {}", csv);
|
||||||
} else {
|
|
||||||
// TODO: separate
|
|
||||||
AccountInfo acctInfo = new AccountInfo();
|
|
||||||
String[] instruments = getInstruments(cmdline);
|
String[] instruments = getInstruments(cmdline);
|
||||||
reader = new OANDAReader(acctInfo, instruments);
|
|
||||||
log.info("Reading from stream.");
|
log.info("Reading from stream.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,4 +118,6 @@ public class App {
|
|||||||
formatter.printHelp("java -jar ATS_Esper-all.jar [args] rules.epl", options);
|
formatter.printHelp("java -jar ATS_Esper-all.jar [args] rules.epl", options);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
Config config = new Config();
|
||||||
|
reader = new OANDAReader(config, instruments);
|
||||||
}
|
}
|
||||||
|
|||||||
57
src/main/java/Config.java
Normal file
57
src/main/java/Config.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config provides access to runtime configuration properties defined
|
||||||
|
* in a Java properties file. The file is located in
|
||||||
|
* "config/config.properties" relative to the installation root.
|
||||||
|
*/
|
||||||
|
public class Config {
|
||||||
|
static final Logger log = LoggerFactory.getLogger("Config");
|
||||||
|
private Properties properties = new Properties();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the configuration properties file.
|
||||||
|
*/
|
||||||
|
public Config() {
|
||||||
|
try {
|
||||||
|
String cwd = System.getProperty("user.dir");
|
||||||
|
String configFile = cwd + File.separator + "config" +
|
||||||
|
File.separator + "config.properties";
|
||||||
|
log.info("Loading config file " + configFile);
|
||||||
|
properties.load(new FileInputStream(configFile));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error loading config.properties", e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the OANDA account id.
|
||||||
|
*/
|
||||||
|
public String accountID() {
|
||||||
|
return properties.getProperty("OANDA.accountID");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the OANDA account is on the live ('fxlive') site.
|
||||||
|
* Return false if it is on the practice ('fxpractice') site.
|
||||||
|
*/
|
||||||
|
public boolean isLiveAccount() {
|
||||||
|
return Boolean.parseBoolean(properties.getProperty("OANDA.isLiveAccount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public String accessToken() {
|
||||||
|
return properties.getProperty("OANDA.accessToken");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,12 +21,12 @@ import org.slf4j.LoggerFactory;
|
|||||||
public class OANDAReader implements TickStreamReader {
|
public class OANDAReader implements TickStreamReader {
|
||||||
final Logger log = LoggerFactory.getLogger(OANDAReader.class);
|
final Logger log = LoggerFactory.getLogger(OANDAReader.class);
|
||||||
ObjectMapper mapper;
|
ObjectMapper mapper;
|
||||||
AccountInfo accountInfo;
|
|
||||||
String[] instruments;
|
String[] instruments;
|
||||||
|
Config config;
|
||||||
|
|
||||||
|
|
||||||
public OANDAReader(AccountInfo accountInfo, String[] instruments) {
|
public OANDAReader(Config config, String[] instruments) {
|
||||||
this.accountInfo = accountInfo;
|
this.config = config;
|
||||||
this.instruments = instruments;
|
this.instruments = instruments;
|
||||||
|
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
@ -38,7 +38,6 @@ public class OANDAReader implements TickStreamReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String streamURL() {
|
private String streamURL() {
|
||||||
String type = accountInfo.isLiveAccount() ? "fxlive" : "fxpractice";
|
|
||||||
String instrList = String.join(",", instruments);
|
String instrList = String.join(",", instruments);
|
||||||
String query = "";
|
String query = "";
|
||||||
try {
|
try {
|
||||||
@ -46,9 +45,10 @@ public class OANDAReader implements TickStreamReader {
|
|||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
log.error("Creating stream URL", e);
|
log.error("Creating stream URL", e);
|
||||||
}
|
}
|
||||||
|
String type = config.isLiveAccount() ? "fxlive" : "fxpractice";
|
||||||
|
|
||||||
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, config.accountID(), query);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readConnection(String urlStr, TickProcessor processor) {
|
private void readConnection(String urlStr, TickProcessor processor) {
|
||||||
@ -65,8 +65,8 @@ public class OANDAReader implements TickStreamReader {
|
|||||||
//httpConn.setInstanceFollowRedirects(true);
|
//httpConn.setInstanceFollowRedirects(true);
|
||||||
httpConn.setRequestMethod("GET");
|
httpConn.setRequestMethod("GET");
|
||||||
//httpConn.setReadTimeout(50 * 1000);
|
//httpConn.setReadTimeout(50 * 1000);
|
||||||
httpConn.setRequestProperty("Authorization", "Bearer 9a480f0b83e987f4015cf0846790c7d9-695ced635526744abd61bdf0e2ae8b71");
|
|
||||||
BufferedReader is =
|
BufferedReader is =
|
||||||
|
httpConn.setRequestProperty("Authorization", "Bearer " + config.accessToken());
|
||||||
new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
|
new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
|
||||||
|
|
||||||
while ((line = is.readLine( )) != null) {
|
while ((line = is.readLine( )) != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user