Search in sources :

Example 1 with QuoteFeed

use of name.abuchen.portfolio.online.QuoteFeed in project portfolio by buchen.

the class UpdateQuotesJob method addLatestQuotesJobs.

private void addLatestQuotesJobs(Dirtyable dirtyable, List<Job> jobs) {
    for (Security s : securities) {
        // if configured, use feed for latest quotes
        // otherwise use the default feed used by historical quotes as well
        String feedId = s.getLatestFeed();
        if (feedId == null)
            feedId = s.getFeed();
        QuoteFeed feed = Factory.getQuoteFeedProvider(feedId);
        if (feed == null)
            continue;
        Job job = createLatestQuoteJob(dirtyable, feed, s);
        jobs.add(job);
        // one request is made per host at a given time)
        if (HTMLTableQuoteFeed.ID.equals(feedId)) {
            job.setRule(HostSchedulingRule.createFor(s.getLatestFeedURL() == null ? s.getFeedURL() : s.getLatestFeedURL()));
        } else if (// $NON-NLS-1$
        feedId.startsWith("YAHOO")) {
            // $NON-NLS-1$
            job.setRule(new HostSchedulingRule("finance.yahoo.com"));
        }
    }
}
Also used : Security(name.abuchen.portfolio.model.Security) Job(org.eclipse.core.runtime.jobs.Job) HTMLTableQuoteFeed(name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed)

Example 2 with QuoteFeed

use of name.abuchen.portfolio.online.QuoteFeed in project portfolio by buchen.

the class SecuritiesTable method addQuoteFeedColumns.

private void addQuoteFeedColumns() {
    Function<Object, String> quoteFeed = e -> {
        String feedId = ((Security) e).getFeed();
        if (feedId == null || feedId.isEmpty())
            return null;
        QuoteFeed feed = Factory.getQuoteFeedProvider(feedId);
        return feed != null ? feed.getName() : null;
    };
    // $NON-NLS-1$
    Column column = new Column("qf-historic", Messages.ColumnQuoteFeedHistoric, SWT.LEFT, 200);
    column.setGroupLabel(Messages.GroupLabelQuoteFeed);
    column.setVisible(false);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return quoteFeed.apply(e);
        }
    });
    column.setSorter(ColumnViewerSorter.create(quoteFeed::apply));
    support.addColumn(column);
    Function<Object, String> latestQuoteFeed = e -> {
        Security security = (Security) e;
        String feedId = security.getLatestFeed();
        if (feedId == null || feedId.isEmpty())
            return security.getFeed() != null ? Messages.EditWizardOptionSameAsHistoricalQuoteFeed : null;
        QuoteFeed feed = Factory.getQuoteFeedProvider(feedId);
        return feed != null ? feed.getName() : null;
    };
    // $NON-NLS-1$
    column = new Column("qf-latest", Messages.ColumnQuoteFeedLatest, SWT.LEFT, 200);
    column.setGroupLabel(Messages.GroupLabelQuoteFeed);
    column.setVisible(false);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return latestQuoteFeed.apply(e);
        }
    });
    column.setSorter(ColumnViewerSorter.create(latestQuoteFeed::apply));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("url-history", Messages.ColumnFeedURLHistoric, SWT.LEFT, 200);
    column.setGroupLabel(Messages.GroupLabelQuoteFeed);
    column.setVisible(false);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Security security = (Security) e;
            return security.getFeedURL();
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Security.class, "feedURL"));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("url-latest", Messages.ColumnFeedURLLatest, SWT.LEFT, 200);
    column.setGroupLabel(Messages.GroupLabelQuoteFeed);
    column.setVisible(false);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Security security = (Security) e;
            return security.getLatestFeedURL();
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Security.class, "latestFeedURL"));
    support.addColumn(column);
}
Also used : ReportingPeriodColumnOptions(name.abuchen.portfolio.ui.util.viewers.ReportingPeriodColumnOptions) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) BiFunction(java.util.function.BiFunction) DND(org.eclipse.swt.dnd.DND) SecurityDragListener(name.abuchen.portfolio.ui.dnd.SecurityDragListener) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) SecurityTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransactionDialog) StockSplitWizard(name.abuchen.portfolio.ui.wizards.splits.StockSplitWizard) Composite(org.eclipse.swt.widgets.Composite) AbstractFinanceView(name.abuchen.portfolio.ui.AbstractFinanceView) KeyEvent(org.eclipse.swt.events.KeyEvent) Factory(name.abuchen.portfolio.online.Factory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Separator(org.eclipse.jface.action.Separator) SecurityTransferDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransferDialog) MenuManager(org.eclipse.jface.action.MenuManager) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) Transfer(org.eclipse.swt.dnd.Transfer) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) OptionLabelProvider(name.abuchen.portfolio.ui.util.viewers.OptionLabelProvider) List(java.util.List) UpdateQuotesJob(name.abuchen.portfolio.ui.UpdateQuotesJob) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) Colors(name.abuchen.portfolio.ui.util.Colors) EditSecurityDialog(name.abuchen.portfolio.ui.wizards.security.EditSecurityDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) Watchlist(name.abuchen.portfolio.model.Watchlist) AccountTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.AccountTransactionDialog) SecurityTransfer(name.abuchen.portfolio.ui.dnd.SecurityTransfer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed) BooleanEditingSupport(name.abuchen.portfolio.ui.util.viewers.BooleanEditingSupport) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) Function(java.util.function.Function) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Messages(name.abuchen.portfolio.ui.Messages) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Taxonomy(name.abuchen.portfolio.model.Taxonomy) NumberColorLabelProvider(name.abuchen.portfolio.ui.util.viewers.NumberColorLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Shell(org.eclipse.swt.widgets.Shell) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) Dialog(org.eclipse.jface.dialogs.Dialog) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Menu(org.eclipse.swt.widgets.Menu) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) Security(name.abuchen.portfolio.model.Security) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed)

Example 3 with QuoteFeed

use of name.abuchen.portfolio.online.QuoteFeed in project portfolio by buchen.

the class ReviewImportedQuotesPage method beforePage.

@Override
public void beforePage() {
    String source = page.getSourceText();
    // $NON-NLS-1$
    QuoteFeed feed = Factory.getQuoteFeedProvider("GENERIC_HTML_TABLE");
    List<Exception> errors = new ArrayList<Exception>();
    quotes = feed.getHistoricalQuotes(source, errors);
    PortfolioPlugin.log(errors);
    setErrorMessage(null);
    setPageComplete(!quotes.isEmpty());
    tableSampleData.setInput(quotes);
    tableSampleData.refresh(true);
    // scroll up to top
    if (!quotes.isEmpty())
        tableSampleData.getTable().showItem(tableSampleData.getTable().getItem(0));
}
Also used : ArrayList(java.util.ArrayList) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed)

Example 4 with QuoteFeed

use of name.abuchen.portfolio.online.QuoteFeed in project portfolio by buchen.

the class AbstractQuoteProviderPage method onExchangeChanged.

private void onExchangeChanged(SelectionChangedEvent event) {
    Exchange exchange = (Exchange) ((IStructuredSelection) event.getSelection()).getFirstElement();
    setStatus(null);
    if (exchange == null) {
        clearSampleQuotes();
    } else {
        QuoteFeed feed = (QuoteFeed) ((IStructuredSelection) comboProvider.getSelection()).getFirstElement();
        showSampleQuotes(feed, exchange);
    }
}
Also used : Exchange(name.abuchen.portfolio.model.Exchange) AlphavantageQuoteFeed(name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed) HTMLTableQuoteFeed(name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed)

Example 5 with QuoteFeed

use of name.abuchen.portfolio.online.QuoteFeed in project portfolio by buchen.

the class UpdateQuotesJob method addHistoricalQuotesJobs.

private void addHistoricalQuotesJobs(Dirtyable dirtyable, List<Job> jobs) {
    // randomize list in case LRU cache size of HTMLTableQuote feed is too
    // small; otherwise entries would be evicted in order
    Collections.shuffle(securities);
    for (Security security : securities) {
        Job job = new Job(security.getName()) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    QuoteFeed feed = Factory.getQuoteFeedProvider(security.getFeed());
                    if (feed == null)
                        return Status.OK_STATUS;
                    ArrayList<Exception> exceptions = new ArrayList<>();
                    if (feed.updateHistoricalQuotes(security, exceptions))
                        dirtyable.markDirty();
                    if (!exceptions.isEmpty())
                        PortfolioPlugin.log(createErrorStatus(security.getName(), exceptions));
                    return Status.OK_STATUS;
                } catch (RateLimitExceededException e) {
                    schedule(2000);
                    return Status.OK_STATUS;
                }
            }
        };
        if (HTMLTableQuoteFeed.ID.equals(security.getFeed()))
            job.setRule(HostSchedulingRule.createFor(security.getFeedURL()));
        jobs.add(job);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) RateLimitExceededException(name.abuchen.portfolio.util.RateLimitExceededException) Security(name.abuchen.portfolio.model.Security) Job(org.eclipse.core.runtime.jobs.Job) HTMLTableQuoteFeed(name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed) URISyntaxException(java.net.URISyntaxException) RateLimitExceededException(name.abuchen.portfolio.util.RateLimitExceededException)

Aggregations

QuoteFeed (name.abuchen.portfolio.online.QuoteFeed)13 HTMLTableQuoteFeed (name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed)10 AlphavantageQuoteFeed (name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed)8 ArrayList (java.util.ArrayList)6 Exchange (name.abuchen.portfolio.model.Exchange)5 Security (name.abuchen.portfolio.model.Security)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 MessageFormat (java.text.MessageFormat)2 List (java.util.List)2 Messages (name.abuchen.portfolio.ui.Messages)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 PropertyChangeListener (java.beans.PropertyChangeListener)1 URISyntaxException (java.net.URISyntaxException)1 LocalDate (java.time.LocalDate)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 BiFunction (java.util.function.BiFunction)1