use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class ImportUtils method createSecurityNode.
static SecurityNode createSecurityNode(final ImportSecurity security, final CurrencyNode currencyNode) {
final SecurityNode securityNode = new SecurityNode(currencyNode);
securityNode.setSymbol(security.getTicker());
securityNode.setScale(currencyNode.getScale());
security.getSecurityName().ifPresent(securityNode::setDescription);
security.getId().ifPresent(securityNode::setISIN);
return securityNode;
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class JpaCommodityDAO method getActiveCurrencies.
/*
* @see jgnash.engine.CommodityDAOInterface#getActiveAccountCommodities()
*/
@Override
public Set<CurrencyNode> getActiveCurrencies() {
Set<CurrencyNode> currencyNodeSet = Collections.emptySet();
try {
Future<Set<CurrencyNode>> future = executorService.submit(() -> {
emLock.lock();
try {
final TypedQuery<Account> q = em.createQuery("SELECT a FROM Account a WHERE a.markedForRemoval = false", Account.class);
final List<Account> accountList = q.getResultList();
final Set<CurrencyNode> currencies = new HashSet<>();
for (final Account account : accountList) {
currencies.add(account.getCurrencyNode());
currencies.addAll(account.getSecurities().parallelStream().map(SecurityNode::getReportedCurrencyNode).collect(Collectors.toList()));
}
return currencies;
} finally {
emLock.unlock();
}
});
currencyNodeSet = future.get();
} catch (final InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
return currencyNodeSet;
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class YahooEventParserTest method testParser.
@SuppressWarnings("ConstantConditions")
@Test
// disable on Travis-CI
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
@Disabled
void testParser() throws IOException {
if (System.getenv(GITHUB_ACTION) != null) {
// don't test with Github actions
return;
}
for (int i = 0; i < ATTEMPTS; i++) {
// try multiple times to pass
final SecurityNode ibm = new SecurityNode(e.getDefaultCurrency());
ibm.setSymbol("IBM");
ibm.setScale((byte) 2);
ibm.setQuoteSource(QuoteSource.YAHOO);
final SecurityHistoryNode historyNode = new SecurityHistoryNode(LocalDate.of(1962, Month.JANUARY, 1), BigDecimal.TEN, 1000, BigDecimal.TEN, BigDecimal.TEN);
e.addSecurity(ibm);
e.addSecurityHistory(ibm, historyNode);
QuoteSource quoteSource = ibm.getQuoteSource();
Objects.requireNonNull(quoteSource);
SecurityParser securityParser = quoteSource.getParser();
Objects.requireNonNull(securityParser);
final Set<SecurityHistoryEvent> events = securityParser.retrieveHistoricalEvents(ibm, LocalDate.of(2015, Month.AUGUST, 22));
assertNotNull(events);
// size fluctuates
if (events.size() <= 221 && events.size() >= 220) {
assertTrue(events.size() <= 221 && events.size() >= 220);
return;
}
}
fail("Failed to pass test");
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class YahooEventParserTest method testHistoricalDownload.
@Test
// disable on Travis-CI
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
@Disabled
void testHistoricalDownload() throws IOException {
if (System.getenv(GITHUB_ACTION) != null) {
// don't test with Github actions
return;
}
for (int i = 0; i < ATTEMPTS; i++) {
// try multiple times to pass
final SecurityNode ibm = new SecurityNode(e.getDefaultCurrency());
ibm.setSymbol("IBM");
ibm.setScale((byte) 2);
e.addSecurity(ibm);
// force re-authorization to prevent failed unit test
YahooCrumbManager.clearAuthorization();
final List<SecurityHistoryNode> events = Objects.requireNonNull(QuoteSource.YAHOO.getParser()).retrieveHistoricalPrice(ibm, LocalDate.of(2016, Month.JANUARY, 1), LocalDate.of(2016, Month.DECEMBER, 30));
if (events.size() == 252) {
assertEquals(252, events.size());
return;
}
}
fail("Failed to pass test");
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class HistoricalImportController method initialize.
@FXML
void initialize() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final List<SecurityNode> securityNodes = engine.getSecurities().stream().filter(securityNode -> securityNode.getQuoteSource() != QuoteSource.NONE).sorted().collect(Collectors.toList());
checkListView.getItems().addAll(securityNodes);
startDatePicker.setValue(LocalDate.now().minusMonths(1));
checkListView.disableProperty().bind(disableUI);
endDatePicker.disableProperty().bind(disableUI);
startDatePicker.disableProperty().bind(disableUI);
startButton.disableProperty().bind(disableUI);
selectAllButton.disableProperty().bind(disableUI);
clearAllButton.disableProperty().bind(disableUI);
invertAllButton.disableProperty().bind(disableUI);
stopButton.disableProperty().bind(disableUI.not());
}
Aggregations