Search in sources :

Example 31 with SecurityNode

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;
}
Also used : SecurityNode(jgnash.engine.SecurityNode)

Example 32 with SecurityNode

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

the class SecuritiesHistoryDialog method changeNode.

private void changeNode() {
    SecurityNode node = securityCombo.getSelectedSecurityNode();
    if (node != null) {
        updateChart();
        model.setSecurity(node);
        closeField.setScale(node.getScale());
        lowField.setScale(node.getScale());
        highField.setScale(node.getScale());
        updateButton.setEnabled(node.getQuoteSource() != QuoteSource.NONE);
    }
}
Also used : SecurityNode(jgnash.engine.SecurityNode)

Example 33 with SecurityNode

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

the class SecurityModifyPanel method messagePosted.

@Override
public void messagePosted(final Message event) {
    if (event.getObject(MessageProperty.COMMODITY) instanceof SecurityNode) {
        final SecurityNode node = event.getObject(MessageProperty.COMMODITY);
        EventQueue.invokeLater(() -> {
            switch(event.getEvent()) {
                case SECURITY_REMOVE:
                    model.removeElement(node);
                    clearForm();
                    break;
                case SECURITY_REMOVE_FAILED:
                    String message = "Commodity " + node + " cannot be removed";
                    JOptionPane.showMessageDialog(SecurityModifyPanel.this, message, rb.getString("Message.Warn.CommodityInUse"), JOptionPane.WARNING_MESSAGE);
                    break;
                case SECURITY_ADD:
                    clearForm();
                    model.addElement(node);
                    break;
                case SECURITY_ADD_FAILED:
                    JOptionPane.showMessageDialog(SecurityModifyPanel.this, rb.getString("Message.Error.AddCommodity"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
                    break;
                case SECURITY_MODIFY:
                    clearForm();
                    // force load of new instance
                    model.removeElement(node);
                    model.addElement(node);
                    model.fireContentsChanged();
                    break;
                case SECURITY_MODIFY_FAILED:
                    JOptionPane.showMessageDialog(SecurityModifyPanel.this, rb.getString("Message.Error.ModifyCommodity"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
                    break;
                default:
            }
        });
    }
}
Also used : SecurityNode(jgnash.engine.SecurityNode)

Example 34 with SecurityNode

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

the class OfxImport method importInvestmentTransaction.

private static InvestmentTransaction importInvestmentTransaction(final OfxBank ofxBank, final ImportTransaction ofxTransaction, final Account investmentAccount) {
    final SecurityNode securityNode = matchSecurity(ofxBank, ofxTransaction.getSecurityId());
    final String memo = ofxTransaction.getMemo();
    final LocalDate datePosted = ofxTransaction.getDatePosted();
    final BigDecimal units = ofxTransaction.getUnits();
    final BigDecimal unitPrice = ofxTransaction.getUnitPrice();
    final Account incomeAccount = ofxTransaction.getGainsAccount();
    final Account fessAccount = ofxTransaction.getFeesAccount();
    Account cashAccount = ofxTransaction.getAccount();
    // force use of cash balance
    if (OfxTags.CASH.equals(ofxTransaction.getSubAccount())) {
        cashAccount = investmentAccount;
    }
    final List<TransactionEntry> fees = new ArrayList<>();
    final List<TransactionEntry> gains = new ArrayList<>();
    if (ofxTransaction.getCommission().compareTo(BigDecimal.ZERO) != 0) {
        final TransactionEntry transactionEntry = new TransactionEntry(fessAccount, ofxTransaction.getCommission().negate());
        transactionEntry.setTransactionTag(TransactionTag.INVESTMENT_FEE);
        fees.add(transactionEntry);
    }
    if (ofxTransaction.getFees().compareTo(BigDecimal.ZERO) != 0) {
        final TransactionEntry transactionEntry = new TransactionEntry(fessAccount, ofxTransaction.getFees().negate());
        transactionEntry.setTransactionTag(TransactionTag.INVESTMENT_FEE);
        fees.add(transactionEntry);
    }
    InvestmentTransaction transaction = null;
    if (securityNode != null) {
        switch(ofxTransaction.getTransactionType()) {
            case DIVIDEND:
                final BigDecimal dividend = ofxTransaction.getAmount();
                transaction = TransactionFactory.generateDividendXTransaction(incomeAccount, investmentAccount, cashAccount, securityNode, dividend, dividend, dividend, datePosted, memo);
                break;
            case REINVESTDIV:
                // Create a gains entry of an account other than the investment account has been selected
                if (incomeAccount != investmentAccount) {
                    final TransactionEntry gainsEntry = TransactionFactory.createTransactionEntry(incomeAccount, investmentAccount, ofxTransaction.getAmount().negate(), memo, TransactionTag.GAIN_LOSS);
                    gains.add(gainsEntry);
                }
                transaction = TransactionFactory.generateReinvestDividendXTransaction(investmentAccount, securityNode, unitPrice, units, datePosted, memo, fees, gains);
                break;
            case BUYSHARE:
                transaction = TransactionFactory.generateBuyXTransaction(cashAccount, investmentAccount, securityNode, unitPrice, units, BigDecimal.ONE, datePosted, memo, fees);
                break;
            case SELLSHARE:
                transaction = TransactionFactory.generateSellXTransaction(cashAccount, investmentAccount, securityNode, unitPrice, units, BigDecimal.ONE, datePosted, memo, fees, gains);
                break;
            default:
        }
    }
    return transaction;
}
Also used : Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) SecurityNode(jgnash.engine.SecurityNode) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) TransactionEntry(jgnash.engine.TransactionEntry)

Example 35 with SecurityNode

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

the class HistoricalImportController method handleStartAction.

@FXML
private void handleStartAction() {
    disableUI.set(true);
    final DateTimeFormatter dateTimeFormatter = DateUtils.getShortDateFormatter();
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    updateTask = new Task<>() {

        @Override
        protected Void call() {
            final LocalDate startDate = startDatePicker.getValue();
            final LocalDate endDate = endDatePicker.getValue();
            final Map<SecurityNode, List<SecurityHistoryNode>> historyMap = new HashMap<>();
            // create a defensive copy
            final List<SecurityNode> securityNodes = new ArrayList<>(checkListView.getCheckedItems());
            // need to determine the total count
            long historyCount = 0;
            // Collect and count the number of nodes
            for (final SecurityNode securityNode : securityNodes) {
                updateMessage(ResourceUtils.getString("Message.DownloadingX", securityNode.getSymbol()));
                try {
                    final List<SecurityHistoryNode> historyNodes = UpdateFactory.downloadHistory(securityNode, startDate, endDate);
                    // reverse the sort order
                    Collections.reverse(historyNodes);
                    historyCount += historyNodes.size();
                    historyMap.put(securityNode, historyNodes);
                } catch (final IllegalArgumentException iae) {
                    updateMessage(ResourceUtils.getString("Message.Error.DataSupplierToken", securityNode.getSymbol()));
                    this.cancel();
                }
            }
            // need to track the total processed count
            long processedHistory = 0;
            for (final Map.Entry<SecurityNode, List<SecurityHistoryNode>> entry : historyMap.entrySet()) {
                if (!requestCancel) {
                    for (final SecurityHistoryNode historyNode : entry.getValue()) {
                        if (!requestCancel) {
                            engine.addSecurityHistory(entry.getKey(), historyNode);
                            updateProgress(++processedHistory, historyCount);
                            updateMessage(ResourceUtils.getString("Message.UpdatedPriceDate", entry.getKey().getSymbol(), dateTimeFormatter.format(historyNode.getLocalDate())));
                        }
                    }
                }
            }
            updateMessage("");
            return null;
        }
    };
    updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_SUCCEEDED, event -> taskComplete());
    updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_CANCELLED, event -> taskComplete());
    updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_FAILED, event -> taskComplete());
    progressBar.progressProperty().bind(updateTask.progressProperty());
    messageLabel.textProperty().bind(updateTask.messageProperty());
    final Thread thread = new Thread(updateTask);
    thread.setDaemon(true);
    thread.start();
}
Also used : LocalDate(java.time.LocalDate) SecurityNode(jgnash.engine.SecurityNode) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) ArrayList(java.util.ArrayList) List(java.util.List) DateTimeFormatter(java.time.format.DateTimeFormatter) HashMap(java.util.HashMap) Map(java.util.Map) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

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