Search in sources :

Example 36 with SecurityNode

use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.

the class AccountPropertiesController method updateCommodityText.

private void updateCommodityText() {
    if (!securityNodeSet.isEmpty()) {
        StringBuilder buf = new StringBuilder();
        Iterator<SecurityNode> it = securityNodeSet.iterator();
        SecurityNode node = it.next();
        buf.append(node.getSymbol());
        while (it.hasNext()) {
            buf.append(", ");
            node = it.next();
            buf.append(node.getSymbol());
        }
        JavaFXUtils.runLater(() -> {
            securitiesButton.setText(buf.toString());
            securitiesButton.setTooltip(new Tooltip(buf.toString()));
        });
    } else {
        JavaFXUtils.runLater(() -> securitiesButton.setText(resources.getString("Word.None")));
    }
}
Also used : SecurityNode(jgnash.engine.SecurityNode) Tooltip(javafx.scene.control.Tooltip)

Example 37 with SecurityNode

use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.

the class SecurityComboBox method messagePosted.

@Override
public void messagePosted(final Message event) {
    if (event.getObject(MessageProperty.COMMODITY) instanceof SecurityNode) {
        final SecurityNode node = event.getObject(MessageProperty.COMMODITY);
        final Account account = event.getObject(MessageProperty.ACCOUNT);
        JavaFXUtils.runLater(() -> {
            switch(event.getEvent()) {
                case ACCOUNT_SECURITY_ADD:
                    if (account != null && account.equals(this.account.get())) {
                        final int index = Collections.binarySearch(items, node);
                        if (index < 0) {
                            items.add(-index - 1, node);
                        }
                    }
                    break;
                case ACCOUNT_SECURITY_REMOVE:
                    if (account != null && account.equals(this.account.get())) {
                        items.removeAll(node);
                    }
                    break;
                case SECURITY_REMOVE:
                    items.removeAll(node);
                    break;
                case SECURITY_ADD:
                    final int index = Collections.binarySearch(items, node);
                    if (index < 0) {
                        items.add(-index - 1, node);
                    }
                    break;
                case SECURITY_MODIFY:
                    items.removeAll(node);
                    final int i = Collections.binarySearch(items, node);
                    if (i < 0) {
                        items.add(-i - 1, node);
                    }
                    break;
                case FILE_CLOSING:
                    items.clear();
                default:
                    break;
            }
        });
    }
}
Also used : Account(jgnash.engine.Account) SecurityNode(jgnash.engine.SecurityNode)

Example 38 with SecurityNode

use of jgnash.engine.SecurityNode 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());
}
Also used : IEXParser(jgnash.net.security.iex.IEXParser) SecurityNode(jgnash.engine.SecurityNode) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) QuoteSource(jgnash.engine.QuoteSource) SecurityParser(jgnash.net.security.SecurityParser) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.jupiter.api.Test) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

Example 39 with SecurityNode

use of jgnash.engine.SecurityNode 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());
}
Also used : IEXParser(jgnash.net.security.iex.IEXParser) SecurityNode(jgnash.engine.SecurityNode) QuoteSource(jgnash.engine.QuoteSource) SecurityParser(jgnash.net.security.SecurityParser) SecurityHistoryEvent(jgnash.engine.SecurityHistoryEvent) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.jupiter.api.Test) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

Aggregations

SecurityNode (jgnash.engine.SecurityNode)39 Engine (jgnash.engine.Engine)12 Account (jgnash.engine.Account)10 SecurityHistoryNode (jgnash.engine.SecurityHistoryNode)8 LocalDate (java.time.LocalDate)7 ArrayList (java.util.ArrayList)6 AbstractEngineTest (jgnash.engine.AbstractEngineTest)6 Test (org.junit.jupiter.api.Test)6 CurrencyNode (jgnash.engine.CurrencyNode)5 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)5 List (java.util.List)4 QuoteSource (jgnash.engine.QuoteSource)4 SecurityParser (jgnash.net.security.SecurityParser)4 FXML (javafx.fxml.FXML)3 InvestmentTransaction (jgnash.engine.InvestmentTransaction)3 SecurityHistoryEvent (jgnash.engine.SecurityHistoryEvent)3 Transaction (jgnash.engine.Transaction)3 IEXParser (jgnash.net.security.iex.IEXParser)3 InjectFXML (jgnash.uifx.util.InjectFXML)3 NotNull (jgnash.util.NotNull)3