forked from portfolio-performance/portfolio
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable online sync of existing securities with etf-data.com
Co-authored-by: Marvin Frick <marvin.frick@shopify.com> Co-authored-by: Andreas Buchen <andreas.buchen@gmail.com> Issue: portfolio-performance#1908
- Loading branch information
Showing
12 changed files
with
138 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions
28
name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/handlers/DownloadETFDataHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package name.abuchen.portfolio.ui.handlers; | ||
|
||
import javax.inject.Named; | ||
|
||
import org.eclipse.e4.core.di.annotations.CanExecute; | ||
import org.eclipse.e4.core.di.annotations.Execute; | ||
import org.eclipse.e4.ui.model.application.ui.basic.MPart; | ||
import org.eclipse.e4.ui.services.IServiceConstants; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
import name.abuchen.portfolio.ui.jobs.SyncETFDataJob; | ||
|
||
public class DownloadETFDataHandler | ||
{ | ||
@CanExecute | ||
boolean isVisible(@Named(IServiceConstants.ACTIVE_PART) MPart part) | ||
{ | ||
return MenuHelper.isClientPartActive(part); | ||
} | ||
|
||
@Execute | ||
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, | ||
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) | ||
{ | ||
MenuHelper.getActiveClientInput(part) | ||
.ifPresent(clientInput -> new SyncETFDataJob(clientInput.getClient()).schedule()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/jobs/SyncETFDataJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package name.abuchen.portfolio.ui.jobs; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
|
||
import com.google.common.base.Strings; | ||
import com.ibm.icu.text.MessageFormat; | ||
|
||
import name.abuchen.portfolio.model.Client; | ||
import name.abuchen.portfolio.model.Security; | ||
import name.abuchen.portfolio.online.SecuritySearchProvider.ResultItem; | ||
import name.abuchen.portfolio.online.impl.ETFDataCom; | ||
import name.abuchen.portfolio.ui.Messages; | ||
import name.abuchen.portfolio.ui.PortfolioPlugin; | ||
|
||
public final class SyncETFDataJob extends AbstractClientJob | ||
{ | ||
public SyncETFDataJob(Client client) | ||
{ | ||
super(client, Messages.JobLabelSyncSecuritiesOnline); | ||
} | ||
|
||
@Override | ||
protected IStatus run(IProgressMonitor monitor) | ||
{ | ||
List<Security> toBeSynced = getClient().getSecurities().stream() | ||
.filter(s -> !Strings.isNullOrEmpty(s.getIsin())).collect(Collectors.toList()); | ||
|
||
if (toBeSynced.isEmpty()) | ||
return Status.OK_STATUS; | ||
|
||
monitor.beginTask(MessageFormat.format(Messages.JobLabelSyncSecuritiesOnline, "https://etf-data.com"), //$NON-NLS-1$ | ||
toBeSynced.size()); | ||
|
||
boolean isDirty = false; | ||
|
||
ETFDataCom etfdata = new ETFDataCom(); | ||
|
||
for (Security security : toBeSynced) | ||
{ | ||
monitor.worked(1); | ||
|
||
try | ||
{ | ||
List<ResultItem> items = etfdata.search(security.getIsin()); | ||
|
||
if (!items.isEmpty()) | ||
{ | ||
boolean hasUpdate = ETFDataCom.updateWith(security, getClient().getSettings(), items.get(0)); | ||
isDirty = isDirty || hasUpdate; | ||
} | ||
else | ||
{ | ||
PortfolioPlugin.info( | ||
MessageFormat.format("No etf-data.com information found for ''{0}'' with ISIN {1}", //$NON-NLS-1$ | ||
security.getName(), security.getIsin())); | ||
} | ||
} | ||
catch (IOException e) | ||
{ | ||
PortfolioPlugin.log(e); | ||
} | ||
} | ||
|
||
if (isDirty) | ||
getClient().markDirty(); | ||
|
||
return Status.OK_STATUS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters