use of jgnash.engine.QuoteSource in project jgnash by ccavanaugh.
the class UpdateFactory method downloadHistory.
public static List<SecurityHistoryNode> downloadHistory(final SecurityNode securityNode, final LocalDate startDate, final LocalDate endDate) throws IllegalArgumentException {
List<SecurityHistoryNode> newSecurityNodes = Collections.emptyList();
QuoteSource quoteSource = securityNode.getQuoteSource();
Objects.requireNonNull(quoteSource);
SecurityParser securityParser = quoteSource.getParser();
Objects.requireNonNull(securityParser);
securityParser.setTokenSupplier(getTokenSupplier(securityParser));
try {
newSecurityNodes = securityParser.retrieveHistoricalPrice(securityNode, startDate, endDate);
if (!newSecurityNodes.isEmpty()) {
logger.info(ResourceUtils.getString("Message.UpdatedPrice", securityNode.getSymbol()));
}
} catch (final IOException ex) {
LogUtil.logSevere(UpdateFactory.class, ex);
} catch (final IllegalArgumentException iae) {
LogUtil.logSevere(UpdateFactory.class, iae);
throw new IllegalArgumentException(iae);
}
return newSecurityNodes;
}
use of jgnash.engine.QuoteSource 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.QuoteSource in project jgnash by ccavanaugh.
the class IEXParserTest method testHistoricalDividendsDownload.
@Test
// disable on Travis-CI
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void testHistoricalDividendsDownload() throws IOException {
if (System.getenv(GITHUB_ACTION) != null) {
// don't test with Github actions
return;
}
// test env must be configured with a valid token
if (System.getenv(TEST_TOKEN) == null) {
// don't test with Github actions
return;
}
final SecurityNode spy = new SecurityNode(e.getDefaultCurrency());
spy.setSymbol("SPY");
spy.setScale((byte) 2);
spy.setQuoteSource(QuoteSource.IEX_CLOUD);
e.addSecurity(spy);
final QuoteSource quoteSource = spy.getQuoteSource();
assertNotNull(quoteSource);
final SecurityParser securityParser = quoteSource.getParser();
assertNotNull(securityParser);
assertThat(securityParser, instanceOf(IEXParser.class));
((IEXParser) securityParser).setUseSandbox();
securityParser.setTokenSupplier(() -> System.getenv(TEST_TOKEN));
final Set<SecurityHistoryEvent> historicalEvents = securityParser.retrieveHistoricalEvents(spy, LocalDate.of(2015, Month.JANUARY, 1));
assertNotNull(historicalEvents);
assertEquals(1, historicalEvents.size());
}
use of jgnash.engine.QuoteSource in project jgnash by ccavanaugh.
the class IEXParserTest method testHistoricalDownload.
@Test
// disable on Travis-CI
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void testHistoricalDownload() throws IOException {
if (System.getenv(GITHUB_ACTION) != null) {
// don't test with Github actions
return;
}
// test env must be configured with a valid token
if (System.getenv(TEST_TOKEN) == null) {
// don't test with Github actions
return;
}
final SecurityNode ibm = new SecurityNode(e.getDefaultCurrency());
ibm.setSymbol("IBM");
ibm.setScale((byte) 2);
ibm.setQuoteSource(QuoteSource.IEX_CLOUD);
e.addSecurity(ibm);
final QuoteSource quoteSource = ibm.getQuoteSource();
assertNotNull(quoteSource);
final SecurityParser securityParser = quoteSource.getParser();
assertNotNull(securityParser);
assertThat(securityParser, instanceOf(IEXParser.class));
((IEXParser) securityParser).setUseSandbox();
securityParser.setTokenSupplier(() -> System.getenv(TEST_TOKEN));
final List<SecurityHistoryNode> events = securityParser.retrieveHistoricalPrice(ibm, LocalDate.of(2019, Month.JANUARY, 2), LocalDate.of(2019, Month.MARCH, 1));
assertNotNull(events);
assertEquals(41, events.size());
}
use of jgnash.engine.QuoteSource in project jgnash by ccavanaugh.
the class IEXParserTest method testHistoricalSplitsDownload.
@Test
// disable on Travis-CI
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void testHistoricalSplitsDownload() throws IOException {
if (System.getenv(GITHUB_ACTION) != null) {
// don't test with Github actions
return;
}
// test env must be configured with a valid token
if (System.getenv(TEST_TOKEN) == null) {
// don't test with Github actions
return;
}
final SecurityNode pstv = new SecurityNode(e.getDefaultCurrency());
pstv.setSymbol("PSTV");
pstv.setScale((byte) 2);
pstv.setQuoteSource(QuoteSource.IEX_CLOUD);
e.addSecurity(pstv);
final QuoteSource quoteSource = pstv.getQuoteSource();
assertNotNull(quoteSource);
final SecurityParser securityParser = quoteSource.getParser();
assertNotNull(securityParser);
assertThat(securityParser, instanceOf(IEXParser.class));
((IEXParser) securityParser).setUseSandbox();
securityParser.setTokenSupplier(() -> System.getenv(TEST_TOKEN));
final Set<SecurityHistoryEvent> historicalEvents = securityParser.retrieveHistoricalEvents(pstv, LocalDate.of(2015, Month.JANUARY, 1));
assertNotNull(historicalEvents);
assertEquals(1, historicalEvents.size());
}
Aggregations