Move OANDA account info into separate file
This commit is contained in:
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user