Java Code Examples for org.apache.commons.configuration2.builder.fluent.Configurations

The following examples show how to use org.apache.commons.configuration2.builder.fluent.Configurations. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test(enabled = false)
public void testOrder() throws ConfigurationException, InterruptedException {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    Set<CreateInstruction> creates = Sets.newHashSet(
            CreateInstruction.builder().price(new BigDecimal("1000000")).size(new BigDecimal("+0.0001")).build(),
            CreateInstruction.builder().price(new BigDecimal("1500000")).size(new BigDecimal("-0.0001")).build()
    );

    Map<CreateInstruction, String> created = target.createOrders(key, creates);
    System.out.println("Created : " + created);

    TimeUnit.SECONDS.sleep(10L);

    Set<CancelInstruction> cancels = created.values().stream().filter(StringUtils::isNotEmpty)
            .map(id -> CancelInstruction.builder().id(id).build()).collect(toSet());
    Map<CancelInstruction, String> cancelled = target.cancelOrders(key, cancels);
    System.out.println("Cancelled : " + cancelled);

}
 
Example 2
Source Project: Getaviz   Source File: SettingsConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
private static void loadConfig(String path) {
	File file = new File(path);
	try {
		Configurations configs = new Configurations();
		config = configs.properties(file);
	} catch (ConfigurationException cex) {
		System.out.println(cex);
	}
}
 
Example 3
Source Project: Getaviz   Source File: SettingsConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
private static void loadConfig(String path) {
	File file = new File(path);
	try {
		Configurations configs = new Configurations();
		config = configs.properties(file);
		new File(instance.getOutputPath()).mkdirs();
	} catch (ConfigurationException cex) {
		log.error(cex);
	}
}
 
Example 4
Source Project: 2018-TowerDefence   Source File: GameConfig.java    License: MIT License 5 votes vote down vote up
public static void initConfig(String configLocation) {
    if (configuration == null) {
        Configurations configurations = new Configurations();

        try {
            configuration = configurations.properties(configLocation);

        } catch (ConfigurationException e) {
            log.error("Unable to initialise configuration, please have a look at the inner exception.", e);
            throw new RuntimeException("Unable to initialise configuration, please have a look at the inner exception.", e);
        }
    }
}
 
Example 5
Source Project: bireme   Source File: Config.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Read config file and store in {@code Config}.
 *
 * @param configFile the config file.
 * @throws ConfigurationException - if an error occurred when loading the configuration
 * @throws BiremeException - wrap and throw Exception which cannot be handled
 */
public Config(String configFile) throws ConfigurationException, BiremeException {
  Configurations configs = new Configurations();
  config = configs.properties(new File(configFile));

  basicConfig();
  connectionConfig("target");
  dataSourceConfig();

  logConfig();
}
 
Example 6
Source Project: bireme   Source File: Config.java    License: Apache License 2.0 5 votes vote down vote up
private HashMap<String, String> fetchTableMap(String dataSource)
    throws ConfigurationException, BiremeException {
  Configurations configs = new Configurations();
  Configuration tableConfig = null;

  tableConfig = configs.properties(new File(DEFAULT_TABLEMAP_DIR + dataSource + ".properties"));

  String originTable, mappedTable;
  HashMap<String, String> localTableMap = new HashMap<String, String>();
  Iterator<String> tables = tableConfig.getKeys();

  while (tables.hasNext()) {
    originTable = tables.next();
    mappedTable = tableConfig.getString(originTable);

    if (originTable.split("\\.").length != 2 || mappedTable.split("\\.").length != 2) {
      String message = "Wrong format: " + originTable + ", " + mappedTable;
      logger.fatal(message);
      throw new BiremeException(message);
    }

    localTableMap.put(dataSource + "." + originTable, mappedTable);

    if (!tableMap.values().contains(mappedTable)) {
      loadersCount++;
    }
    tableMap.put(dataSource + "." + originTable, mappedTable);
  }

  return localTableMap;
}
 
Example 7
@Test(enabled = false)
public void test() throws Exception {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Key key = Key.builder().instrument("XBT_QT").timestamp(Instant.now()).build();

    // Tick
    System.out.println("Ask : " + target.getBestAskPrice(key));
    System.out.println("Bid : " + target.getBestBidPrice(key));
    System.out.println("Mid : " + target.getMidPrice(key));
    System.out.println("Ltp : " + target.getLastPrice(key));

    // Book
    System.out.println("ASZ : " + target.getBestAskSize(key));
    System.out.println("BSZ : " + target.getBestBidSize(key));

    // Trade
    System.out.println("TRD : " + target.listTrades(key, null));

    // Account
    System.out.println("IPS : " + target.getInstrumentPosition(key));
    System.out.println("FPS : " + target.getFundingPosition(key));

    // Reference
    System.out.println("COM : " + target.getCommissionRate(key));
    System.out.println("MGN : " + target.isMarginable(key));
    System.out.println("EXP : " + target.getExpiry(key));

    // Order Query
    System.out.println("ORD : " + target.findOrders(key));
    System.out.println("EXC : " + target.listExecutions(key));

}
 
Example 8
@Test(enabled = false)
public void test_Order() throws Exception {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Key key = Key.builder().instrument("XBJ_QT").timestamp(Instant.now()).build();

    Map<CreateInstruction, String> ids = target.createOrders(
            key, Sets.newHashSet(
                    CreateInstruction.builder()
                            .price(new BigDecimal("1000000"))
                            .size(new BigDecimal("10E-1")).build(),
                    CreateInstruction.builder()
                            .price(new BigDecimal("1000000"))
                            .size(new BigDecimal("0.2E1")).build()
            ));

    System.out.println("NEW : " + ids);

    Thread.sleep(TimeUnit.SECONDS.toMillis(5));

    System.out.println("CND : " + target.cancelOrders(key, ids.values().stream()
            .map(id -> CancelInstruction.builder().id(id).build()).collect(Collectors.toSet())
    ));

}
 
Example 9
@Test(enabled = false)
public void test() throws ConfigurationException, IOException {

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    System.out.println("AP: " + target.getBestAskPrice(key));
    System.out.println("BP: " + target.getBestBidPrice(key));
    System.out.println("AS: " + target.getBestAskSize(key));
    System.out.println("BS: " + target.getBestBidSize(key));
    System.out.println("MP: " + target.getMidPrice(key));
    System.out.println("AD: " + target.getAskPrices(key));
    System.out.println("BD: " + target.getBidPrices(key));

    System.out.println("LP:" + target.getLastPrice(key));
    System.out.println("TD:" + target.listTrades(key, null));

    System.out.println("IC:" + target.getInstrumentCurrency(key));
    System.out.println("FC:" + target.getFundingCurrency(key));
    System.out.println("FP:" + target.findProduct(key, BTC, JPY));
    System.out.println("CM:" + target.getCommissionRate(key));

    System.out.println("P1:" + target.getConversionPrice(key, BTC));
    System.out.println("P2:" + target.getConversionPrice(key, JPY));

    System.out.println("IP:" + target.getInstrumentPosition(key));
    System.out.println("FP:" + target.getFundingPosition(key));
    System.out.println("AO:" + target.listActiveOrders(key));
    System.out.println("EX:" + target.listExecutions(key));

}
 
Example 10
@Test(enabled = false)
public void testOrder() throws ConfigurationException, InterruptedException, IOException {

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    Set<Instruction.CreateInstruction> creates = Sets.newHashSet(
            Instruction.CreateInstruction.builder().price(new BigDecimal("700000")).size(new BigDecimal("+0.001")).build(),
            Instruction.CreateInstruction.builder().price(new BigDecimal("800000")).size(new BigDecimal("-0.001")).build()
    );

    Map<Instruction.CreateInstruction, String> created = target.createOrders(key, creates);
    System.out.println("Created : " + created);

    TimeUnit.SECONDS.sleep(5L);
    System.out.println("Orders:" + target.listActiveOrders(key));
    TimeUnit.SECONDS.sleep(30L);

    Set<Instruction.CancelInstruction> cancels = created.values().stream().filter(StringUtils::isNotEmpty)
            .map(id -> Instruction.CancelInstruction.builder().id(id).build()).collect(toSet());
    Map<Instruction.CancelInstruction, String> cancelled = target.cancelOrders(key, cancels);
    System.out.println("Cancelled : " + cancelled);

    TimeUnit.SECONDS.sleep(5L);
    System.out.println("Orders:" + target.listActiveOrders(key));

}
 
Example 11
@Test(enabled = false)
public void test() throws ConfigurationException {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    System.out.println("AP: " + target.getBestAskPrice(key));
    System.out.println("BP: " + target.getBestBidPrice(key));
    System.out.println("AS: " + target.getBestAskSize(key));
    System.out.println("BS: " + target.getBestBidSize(key));
    System.out.println("MP: " + target.getMidPrice(key));
    System.out.println("AD: " + target.getAskPrices(key));
    System.out.println("BD: " + target.getBidPrices(key));

    System.out.println("LP:" + target.getLastPrice(key));
    System.out.println("TD:" + target.listTrades(key, null));

    System.out.println("IC:" + target.getInstrumentCurrency(key));
    System.out.println("FC:" + target.getFundingCurrency(key));
    System.out.println("FP:" + target.findProduct(key, BTC, JPY));

    System.out.println("P1:" + target.getConversionPrice(key, BTC));
    System.out.println("P2:" + target.getConversionPrice(key, JPY));

    System.out.println("IP:" + target.getInstrumentPosition(key));
    System.out.println("FP:" + target.getFundingPosition(key));

}
 
Example 12
@Test(enabled = false)
public void test() throws Exception {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));

    doCallRealMethod().when(target).request(any(), any(), any(), any());
    doCallRealMethod().when(target).scheduleSocket(any(), any());

    Key key = Key.builder().instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    System.out.println("APX : " + target.getBestAskPrice(key));
    System.out.println("ASZ : " + target.getBestAskSize(key));
    System.out.println("BPX : " + target.getBestBidPrice(key));
    System.out.println("BSZ : " + target.getBestBidSize(key));
    System.out.println("MID : " + target.getMidPrice(key));
    System.out.println("LTP : " + target.getLastPrice(key));
    System.out.println("TRD : " + target.listTrades(key, null));

    System.out.println("CYI : " + target.getInstrumentCurrency(key));
    System.out.println("CYF : " + target.getFundingCurrency(key));
    System.out.println("CVB : " + target.getConversionPrice(key, CurrencyType.BTC));
    System.out.println("CVJ : " + target.getConversionPrice(key, CurrencyType.JPY));

    System.out.println("PSI : " + target.getInstrumentPosition(key));
    System.out.println("PSF : " + target.getFundingPosition(key));

    System.out.println("RIU : " + target.roundLotSize(key, new BigDecimal("1.23456"), UP));
    System.out.println("RID : " + target.roundLotSize(key, new BigDecimal("1.23456"), DOWN));
    System.out.println("RTU : " + target.roundTickSize(key, new BigDecimal("1.23456"), UP));
    System.out.println("RTD : " + target.roundTickSize(key, new BigDecimal("1.23456"), DOWN));
    System.out.println("COM : " + target.getCommissionRate(key));

    System.out.println("FDO : " + target.findOrder(key, "some_order_id"));
    System.out.println("LAO : " + target.listActiveOrders(key));
    System.out.println("LSE : " + target.listExecutions(key));

}
 
Example 13
@Test(enabled = false)
public void test_Order() throws Exception {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Key key = Key.builder().instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    Map<CreateInstruction, String> creates = target.createOrders(key, Sets.newHashSet(
            CreateInstruction.builder()
                    .price(new BigDecimal("1000001"))
                    .size(new BigDecimal("0.005")).build(),
            CreateInstruction.builder()
                    .price(new BigDecimal("1000002"))
                    .size(new BigDecimal("0.005")).build()
    ));

    creates.forEach((instruction, id) -> System.out.println(instruction + " -> " + id));

    TimeUnit.SECONDS.sleep(10);

    Map<CancelInstruction, String> cancels = target.cancelOrders(key, creates.values().stream()
            .filter(StringUtils::isNotEmpty)
            .map(id -> CancelInstruction.builder().id(id).build())
            .collect(Collectors.toSet())
    );

    cancels.forEach((instruction, id) -> System.out.println(instruction + " -> " + id));

}
 
Example 14
@Test(enabled = false)
public void test() throws ConfigurationException, IOException {

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    System.out.println("AP: " + target.getBestAskPrice(key));
    System.out.println("BP: " + target.getBestBidPrice(key));
    System.out.println("AS: " + target.getBestAskSize(key));
    System.out.println("BS: " + target.getBestBidSize(key));
    System.out.println("MP: " + target.getMidPrice(key));
    System.out.println("AD: " + target.getAskPrices(key));
    System.out.println("BD: " + target.getBidPrices(key));

    System.out.println("LP:" + target.getLastPrice(key));
    System.out.println("TD:" + target.listTrades(key, null));

    System.out.println("IC:" + target.getInstrumentCurrency(key));
    System.out.println("FC:" + target.getFundingCurrency(key));
    System.out.println("FP:" + target.findProduct(key, BTC, JPY));
    System.out.println("CM:" + target.getCommissionRate(key));

    System.out.println("P1:" + target.getConversionPrice(key, BTC));
    System.out.println("P2:" + target.getConversionPrice(key, JPY));

    System.out.println("IP:" + target.getInstrumentPosition(key));
    System.out.println("FP:" + target.getFundingPosition(key));
    System.out.println("AO:" + target.listActiveOrders(key));
    System.out.println("EX:" + target.listExecutions(key));

}
 
Example 15
@Test(enabled = false)
public void testOrder() throws ConfigurationException, InterruptedException, IOException {

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    Set<Instruction.CreateInstruction> creates = Sets.newHashSet(
            Instruction.CreateInstruction.builder().price(new BigDecimal("400000")).size(new BigDecimal("+0.001")).build(),
            Instruction.CreateInstruction.builder().price(new BigDecimal("600000")).size(new BigDecimal("-0.001")).build()
    );

    Map<Instruction.CreateInstruction, String> created = target.createOrders(key, creates);
    System.out.println("Created : " + created);

    TimeUnit.SECONDS.sleep(5L);
    System.out.println("Orders:" + target.listActiveOrders(key));
    TimeUnit.SECONDS.sleep(30L);

    Set<Instruction.CancelInstruction> cancels = created.values().stream().filter(StringUtils::isNotEmpty)
            .map(id -> Instruction.CancelInstruction.builder().id(id).build()).collect(toSet());
    Map<Instruction.CancelInstruction, String> cancelled = target.cancelOrders(key, cancels);
    System.out.println("Cancelled : " + cancelled);

    TimeUnit.SECONDS.sleep(5L);
    System.out.println("Orders:" + target.listActiveOrders(key));

}
 
Example 16
@Test(enabled = false)
public void test() throws ConfigurationException, IOException {

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    System.out.println("AP: " + target.getBestAskPrice(key));
    System.out.println("BP: " + target.getBestBidPrice(key));
    System.out.println("AS: " + target.getBestAskSize(key));
    System.out.println("BS: " + target.getBestBidSize(key));
    System.out.println("MP: " + target.getMidPrice(key));
    System.out.println("AD: " + target.getAskPrices(key));
    System.out.println("BD: " + target.getBidPrices(key));

    System.out.println("LP:" + target.getLastPrice(key));
    System.out.println("TD:" + target.listTrades(key, null));

    System.out.println("IC:" + target.getInstrumentCurrency(key));
    System.out.println("FC:" + target.getFundingCurrency(key));
    System.out.println("FP:" + target.findProduct(key, BTC, JPY));

    System.out.println("P1:" + target.getConversionPrice(key, BTC));
    System.out.println("P2:" + target.getConversionPrice(key, JPY));

    System.out.println("IP:" + target.getInstrumentPosition(key));
    System.out.println("FP:" + target.getFundingPosition(key));
    System.out.println("AO:" + target.listActiveOrders(key));
    System.out.println("EX:" + target.listExecutions(key));

}
 
Example 17
@Test(enabled = false)
public void testOrder() throws ConfigurationException, InterruptedException, IOException {

    doCallRealMethod().when(target).request(any(), any(), any(), any());

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Key key = Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    Set<Instruction.CreateInstruction> creates = Sets.newHashSet(
            Instruction.CreateInstruction.builder().price(new BigDecimal("1000000")).size(new BigDecimal("+0.0001")).build(),
            Instruction.CreateInstruction.builder().price(new BigDecimal("1500000")).size(new BigDecimal("-0.0001")).build()
    );

    Map<Instruction.CreateInstruction, String> created = target.createOrders(key, creates);
    System.out.println("Created : " + created);

    TimeUnit.SECONDS.sleep(5L);
    System.out.println("Orders:" + target.listActiveOrders(key));
    TimeUnit.SECONDS.sleep(5L);

    Set<Instruction.CancelInstruction> cancels = created.values().stream().filter(StringUtils::isNotEmpty)
            .map(id -> Instruction.CancelInstruction.builder().id(id).build()).collect(toSet());
    Map<Instruction.CancelInstruction, String> cancelled = target.cancelOrders(key, cancels);
    System.out.println("Cancelled : " + cancelled);

    TimeUnit.SECONDS.sleep(5L);
    System.out.println("Orders:" + target.listActiveOrders(key));

}
 
Example 18
@Test(enabled = false)
public void test() throws ConfigurationException {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Context.Key key = Context.Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    System.out.println("AP: " + target.getBestAskPrice(key));
    System.out.println("BP: " + target.getBestBidPrice(key));
    System.out.println("AS: " + target.getBestAskSize(key));
    System.out.println("BS: " + target.getBestBidSize(key));
    System.out.println("MP: " + target.getMidPrice(key));
    System.out.println("AD: " + target.getAskPrices(key));
    System.out.println("BD: " + target.getBidPrices(key));

    System.out.println("LP:" + target.getLastPrice(key));
    System.out.println("TD:" + target.listTrades(key, null));

    System.out.println("IC:" + target.getInstrumentCurrency(key));
    System.out.println("FC:" + target.getFundingCurrency(key));
    System.out.println("FP:" + target.findProduct(key, BTC, JPY));

    System.out.println("P1:" + target.getConversionPrice(key, BTC));
    System.out.println("P2:" + target.getConversionPrice(key, JPY));

    System.out.println("IP:" + target.getInstrumentPosition(key));
    System.out.println("FP:" + target.getFundingPosition(key));
    System.out.println("AO:" + target.listActiveOrders(key));
    System.out.println("EX:" + target.listExecutions(key));

}
 
Example 19
@Test(enabled = false)
public void testOrder() throws ConfigurationException, InterruptedException {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Context.Key key = Context.Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    Set<Instruction.CreateInstruction> creates = Sets.newHashSet(
            Instruction.CreateInstruction.builder().price(new BigDecimal("1000000")).size(new BigDecimal("-0.001")).build(),
            Instruction.CreateInstruction.builder().price(new BigDecimal("+800000")).size(new BigDecimal("+0.001")).build()
    );

    Map<Instruction.CreateInstruction, String> created = target.createOrders(key, creates);
    System.out.println("Created : " + created);

    TimeUnit.SECONDS.sleep(5L);
    System.out.println("AO:" + target.listActiveOrders(key));

    TimeUnit.SECONDS.sleep(5L);
    created.values().stream().filter(StringUtils::isNotEmpty)
            .forEach(id -> System.out.println("FO:" + target.findOrder(key, id)));

    Set<Instruction.CancelInstruction> cancels = created.values().stream().filter(StringUtils::isNotEmpty)
            .map(id -> Instruction.CancelInstruction.builder().id(id).build()).collect(toSet());
    Map<Instruction.CancelInstruction, String> cancelled = target.cancelOrders(key, cancels);
    System.out.println("Cancelled : " + cancelled);

}
 
Example 20
@Test(enabled = false)
public void test() throws ConfigurationException {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Context.Key key = Context.Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    System.out.println("AP: " + target.getBestAskPrice(key));
    System.out.println("BP: " + target.getBestBidPrice(key));
    System.out.println("AS: " + target.getBestAskSize(key));
    System.out.println("BS: " + target.getBestBidSize(key));
    System.out.println("MP: " + target.getMidPrice(key));
    System.out.println("AD: " + target.getAskPrices(key));
    System.out.println("BD: " + target.getBidPrices(key));

    System.out.println("LP:" + target.getLastPrice(key));
    System.out.println("TD:" + target.listTrades(key, null));

    System.out.println("IC:" + target.getInstrumentCurrency(key));
    System.out.println("FC:" + target.getFundingCurrency(key));
    System.out.println("FP:" + target.findProduct(key, BTC, JPY));

    System.out.println("P1:" + target.getConversionPrice(key, BTC));
    System.out.println("P2:" + target.getConversionPrice(key, JPY));

    System.out.println("IP:" + target.getInstrumentPosition(key));
    System.out.println("FP:" + target.getFundingPosition(key));
    System.out.println("AO:" + target.listActiveOrders(key));
    System.out.println("EX:" + target.listExecutions(key));

}
 
Example 21
@Test(enabled = false)
public void testOrder() throws ConfigurationException, InterruptedException {

    Path path = Paths.get(System.getProperty("user.home"), ".cryptotrader");
    target.setConfiguration(new Configurations().properties(path.toAbsolutePath().toFile()));
    Context.Key key = Context.Key.builder().site(ID).instrument(BTC_JPY.name()).timestamp(Instant.now()).build();

    Set<Instruction.CreateInstruction> creates = Sets.newHashSet(
            Instruction.CreateInstruction.builder().price(new BigDecimal("1500000")).size(new BigDecimal("-0.001")).build(),
            Instruction.CreateInstruction.builder().price(new BigDecimal("1000000")).size(new BigDecimal("+0.001")).build()
    );

    Map<Instruction.CreateInstruction, String> created = target.createOrders(key, creates);
    System.out.println("Created : " + created);

    TimeUnit.SECONDS.sleep(5L);
    System.out.println("AO:" + target.listActiveOrders(key));

    TimeUnit.SECONDS.sleep(5L);
    created.values().stream().filter(StringUtils::isNotEmpty)
            .forEach(id -> System.out.println("FO:" + target.findOrder(key, id)));

    Set<Instruction.CancelInstruction> cancels = created.values().stream().filter(StringUtils::isNotEmpty)
            .map(id -> Instruction.CancelInstruction.builder().id(id).build()).collect(toSet());
    Map<Instruction.CancelInstruction, String> cancelled = target.cancelOrders(key, cancels);
    System.out.println("Cancelled : " + cancelled);

}
 
Example 22
Source Project: doctorkafka   Source File: DoctorKafkaConfig.java    License: Apache License 2.0 5 votes vote down vote up
public DoctorKafkaConfig(String configPath) throws Exception {
  try {
    Configurations configurations = new Configurations();
    configuration = configurations.properties(new File(configPath));
    drkafkaConfiguration = new SubsetConfiguration(configuration, DOCTORKAFKA_PREFIX);
    this.initialize();
  } catch (Exception e) {
    LOG.error("Failed to initialize configuration file {}", configPath, e);
  }
}
 
Example 23
Source Project: standalone-app   Source File: Helios.java    License: Apache License 2.0 5 votes vote down vote up
private static Configuration loadConfiguration() throws IOException, ConfigurationException {
    Configurations configurations = new Configurations();
    File file = Constants.SETTINGS_FILE_XML;
    if (!file.exists()) {
        XMLConfiguration tempConfiguration = new XMLConfiguration();
        new FileHandler(tempConfiguration).save(file);
    }
    FileBasedConfigurationBuilder<XMLConfiguration> builder = configurations.xmlBuilder(file);
    builder.setAutoSave(true);
    return builder.getConfiguration();
}
 
Example 24
Source Project: swagger2markup   Source File: DocumentationTest.java    License: Apache License 2.0 5 votes vote down vote up
public void swagger2MarkupConfigFromCommonsConfiguration() throws IOException, ConfigurationException {
    Path localSwaggerFile = Paths.get("/path/to/swagger.yaml");

    // tag::swagger2MarkupConfigFromCommonsConfiguration[]
    Configurations configs = new Configurations();
    Configuration configuration = configs.properties("config.properties"); //<1>

    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configuration) //<2>
            .build();

    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(localSwaggerFile)
            .withConfig(config)
            .build();
    // end::swagger2MarkupConfigFromCommonsConfiguration[]
}
 
Example 25
Source Project: swagger2markup   Source File: Schema2MarkupConfigBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loads the default properties from the classpath.
 *
 * @return the default properties
 */
public static Configuration getDefaultConfiguration() {
    Configurations configs = new Configurations();
    try {
        return configs.properties(PROPERTIES_DEFAULT);
    } catch (ConfigurationException e) {
        throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e);
    }
}
 
Example 26
Source Project: swagger2markup-cli   Source File: Application.java    License: Apache License 2.0 5 votes vote down vote up
public void run() {

        Swagger2MarkupConfig swagger2MarkupConfig = null;
        if(StringUtils.isNotBlank(configFile)) {
            Configurations configs = new Configurations();
            Configuration config;
            try {
                config = configs.properties(configFile);
            } catch (ConfigurationException e) {
                throw new IllegalArgumentException("Failed to read configFile", e);
            }
            swagger2MarkupConfig = new Swagger2MarkupConfigBuilder(config).build();
        }
        Swagger2MarkupConverter.Builder converterBuilder = Swagger2MarkupConverter.from(URIUtils.create(swaggerInput));
        if(swagger2MarkupConfig != null){
            converterBuilder.withConfig(swagger2MarkupConfig);
        }
        Swagger2MarkupConverter converter = converterBuilder.build();

        if(StringUtils.isNotBlank(outputFile)){
            converter.toFile(Paths.get(outputFile).toAbsolutePath());
        }else if (StringUtils.isNotBlank(outputDir)){
            converter.toFolder(Paths.get(outputDir).toAbsolutePath());
        }else {
            throw new IllegalArgumentException("Either outputFile or outputDir option must be used");
        }
    }
 
Example 27
Source Project: activemq-artemis   Source File: ArtemisTest.java    License: Apache License 2.0 5 votes vote down vote up
private void checkRole(String user, File roleFile, String... roles) throws Exception {
   Configurations configs = new Configurations();
   FileBasedConfigurationBuilder<PropertiesConfiguration> roleBuilder = configs.propertiesBuilder(roleFile);
   PropertiesConfiguration roleConfig = roleBuilder.getConfiguration();

   for (String r : roles) {
      String storedUsers = (String) roleConfig.getProperty(r);

      log.debug("users in role: " + r + " ; " + storedUsers);
      List<String> userList = StringUtil.splitStringList(storedUsers, ",");
      assertTrue(userList.contains(user));
   }
}
 
Example 28
Source Project: tinkerpop   Source File: GraphFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static org.apache.commons.configuration2.Configuration getConfiguration(final File configurationFile) {
    if (!configurationFile.isFile())
        throw new IllegalArgumentException(String.format("The location configuration must resolve to a file and [%s] does not", configurationFile));

    try {
        final String fileName = configurationFile.getName();
        final String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);

        final Configuration conf;
        final Configurations configs = new Configurations();

        switch (fileExtension) {
            case "yml":
            case "yaml":
                final Parameters params = new Parameters();
                final FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
                        new FileBasedConfigurationBuilder<FileBasedConfiguration>(YAMLConfiguration.class).
                                configure(params.fileBased().setFile(configurationFile));

                final org.apache.commons.configuration2.Configuration copy = new org.apache.commons.configuration2.BaseConfiguration();
                ConfigurationUtils.copy(builder.configure(params.fileBased().setFile(configurationFile)).getConfiguration(), copy);
                conf = copy;
                break;
            case "xml":
                conf = configs.xml(configurationFile);
                break;
            default:
                conf = configs.properties(configurationFile);
        }
        return conf;
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException(String.format("Could not load configuration at: %s", configurationFile), e);
    }
}
 
Example 29
Source Project: batfish   Source File: BaseSettings.java    License: Apache License 2.0 5 votes vote down vote up
private static Configuration loadFileConfiguration(File configFile) {
  try {
    return new Configurations().properties(configFile);
  } catch (ConfigurationException e) {
    throw new BatfishException(
        "Error loading configuration from " + configFile.getAbsolutePath(), e);
  }
}
 
Example 30
Source Project: batfish   Source File: Version.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns the version corresponding to the specified key, in the specified properties file */
public static String getPropertiesVersion(String propertiesPath, String key) {
  try {
    Configuration config = new Configurations().properties(propertiesPath);
    String version = config.getString(key);
    if (version.contains("project.version")) {
      // For whatever reason, resource filtering didn't work.
      return UNKNOWN_VERSION;
    }
    return version;
  } catch (Exception e) {
    return UNKNOWN_VERSION;
  }
}