Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SecurityListView: Properly show short holdings for "Shares held != 0" filter #4500

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ else if (watchlist != null)
*/
private long getSharesHeld(Client client, Security security)
{
// collect all shares and return a value greater 0
return Math.max(security.getTransactions(client).stream()
// TODO: This calculation is simplistic and may be incorrect.
// e.g., if one account has 1 (long) share and another - -1 (short) share,
// this calculation returns 0. But it's clear that it's not the case that
// we have 0 (i.e. none) shares.
return security.getTransactions(client).stream()
.filter(t -> t.getTransaction() instanceof PortfolioTransaction) //
.map(t -> (PortfolioTransaction) t.getTransaction()) //
.mapToLong(t -> {
Expand All @@ -261,7 +264,7 @@ private long getSharesHeld(Client client, Security security)
default:
return 0L;
}
}).sum(), 0);
}).sum();
}

private boolean isLimitPriceExceeded(Security security)
Expand Down