Skip to content

Commit

Permalink
fix how stock lookup was integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Jun 20, 2023
1 parent 38bea50 commit 3c38ec0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 45 deletions.
9 changes: 4 additions & 5 deletions Pages/Portfolio-Review.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@inject IJSRuntime JS
@inject NavigationManager Navigation
@inject IList<Fund> Funds
@inject IList<Fund> Stocks
@using System.Text.Json.Serialization

<PageTitle>
Expand Down Expand Up @@ -1146,7 +1145,7 @@ Portfolio Review@(stepPath==null?"":": "+stepPath.Replace('-',' ')) - bogle.tool
private async Task OnDataFilesImport(InputFileChangeEventArgs e)
{
var files = e.GetMultipleFiles();
ImportResult = await Importer.ImportDataFiles(files, Funds, Stocks, familyData.Accounts);
ImportResult = await Importer.ImportDataFiles(files, Funds, familyData.Accounts);
foreach (var account in ImportResult.ImportedAccounts)
{
account.Import = true;
Expand Down Expand Up @@ -1189,7 +1188,7 @@ Portfolio Review@(stepPath==null?"":": "+stepPath.Replace('-',' ')) - bogle.tool

private void addInvestment(MouseEventArgs e, int accountIndex)
{
var newInvestment = new Investment() { funds = Funds, stocks = Stocks };
var newInvestment = new Investment() { funds = Funds };
familyData.Accounts[accountIndex].Investments.Add(newInvestment);
focusTicker = true;
}
Expand All @@ -1202,7 +1201,7 @@ Portfolio Review@(stepPath==null?"":": "+stepPath.Replace('-',' ')) - bogle.tool
}
void addAvailableFund(MouseEventArgs e, Account account)
{
var newFund = new Investment() { funds = Funds, stocks = Stocks };
var newFund = new Investment() { funds = Funds };
account.AvailableFunds.Add(newFund);
focusTicker = true;
}
Expand All @@ -1213,7 +1212,7 @@ Portfolio Review@(stepPath==null?"":": "+stepPath.Replace('-',' ')) - bogle.tool
void addAccount()
{
var newAccount = new Account();
var newInvestment = new Investment() { funds = Funds, stocks = Stocks };
var newInvestment = new Investment() { funds = Funds };
newAccount.Investments.Add(newInvestment);
familyData?.Accounts.Add(newAccount);
focusAccount = true;
Expand Down
9 changes: 4 additions & 5 deletions Pages/Portfolio.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@inject IJSRuntime JS
@inject NavigationManager Navigation
@inject IList<Fund> Funds
@inject IList<Fund> Stocks
@using System.Text.Json.Serialization

<PageTitle>
Expand Down Expand Up @@ -1024,7 +1023,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
private async Task OnDataFilesImport(InputFileChangeEventArgs e)
{
var files = e.GetMultipleFiles();
ImportResult = await Importer.ImportDataFiles(files, Funds, Stocks, familyData.Accounts);
ImportResult = await Importer.ImportDataFiles(files, Funds, familyData.Accounts);
foreach (var account in ImportResult.ImportedAccounts)
{
account.Import = true;
Expand Down Expand Up @@ -1067,7 +1066,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too

private void addInvestment(MouseEventArgs e, int accountIndex)
{
var newInvestment = new Investment() { funds = Funds, stocks = Stocks };
var newInvestment = new Investment() { funds = Funds };
familyData.Accounts[accountIndex].Investments.Add(newInvestment);
focusTicker = true;
}
Expand All @@ -1080,7 +1079,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
}
void addAvailableFund(MouseEventArgs e, Account account)
{
var newFund = new Investment() { funds = Funds, stocks = Stocks };
var newFund = new Investment() { funds = Funds };
account.AvailableFunds.Add(newFund);
focusTicker = true;
}
Expand All @@ -1091,7 +1090,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
void addAccount()
{
var newAccount = new Account();
var newInvestment = new Investment() { funds = Funds, stocks = Stocks };
var newInvestment = new Investment() { funds = Funds };
newAccount.Investments.Add(newInvestment);
familyData?.Accounts.Add(newAccount);
focusAccount = true;
Expand Down
3 changes: 1 addition & 2 deletions Pages/Retirement.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@inject IJSRuntime JS
@inject NavigationManager Navigation
@inject IList<Fund> Funds
@inject IList<Fund> Stocks
@using System.Text.Json.Serialization

<PageTitle>
Expand Down Expand Up @@ -603,7 +602,7 @@ Retirement - bogle.tools
private async Task OnDataFilesImport(InputFileChangeEventArgs e)
{
var files = e.GetMultipleFiles();
ImportResult = await Importer.ImportDataFiles(files, Funds, Stocks, familyData.Accounts);
ImportResult = await Importer.ImportDataFiles(files, Funds, familyData.Accounts);
foreach (var account in ImportResult.ImportedAccounts)
{
account.Import = true;
Expand Down
8 changes: 2 additions & 6 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@
};

var Funds = await JsonSerializer.DeserializeAsync<List<Fund>>(fundsJson.Content.ReadAsStream(), options);
if (Funds != null) {
builder.Services.AddSingleton<IList<Fund>>(Funds);
}
var Stocks = await JsonSerializer.DeserializeAsync<List<Fund>>(stocksJson.Content.ReadAsStream(), options);
if (Stocks != null) {
builder.Services.AddSingleton<IList<Fund>>(Stocks);
}
Funds.AddRange(Stocks);
builder.Services.AddSingleton<IList<Fund>>(Funds);

builder.Services.AddScoped<LocalStorageAccessor>();

Expand Down
30 changes: 15 additions & 15 deletions Shared/Models/FamilyData/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ImportError
}

public class Importer {
public static async Task<ImportResult> ImportDataFiles(IReadOnlyList<IBrowserFile> files, IList<Fund> funds, IList<Fund> stocks, List<Account> existingAccounts)
public static async Task<ImportResult> ImportDataFiles(IReadOnlyList<IBrowserFile> files, IList<Fund> funds, List<Account> existingAccounts)
{
ImportResult result = new();

Expand All @@ -62,7 +62,7 @@ public static async Task<ImportResult> ImportDataFiles(IReadOnlyList<IBrowserFil
}

var lines = System.Text.RegularExpressions.Regex.Split(content, "\r\n|\r|\n");
var importedAccountsCSV = await Importer.ImportCSV(lines, funds, stocks);
var importedAccountsCSV = await Importer.ImportCSV(lines, funds);
result.ImportedAccounts.AddRange(importedAccountsCSV);
result.DataFilesImported++;
} catch (Exception e) {
Expand All @@ -73,7 +73,7 @@ public static async Task<ImportResult> ImportDataFiles(IReadOnlyList<IBrowserFil
using (var stream = file.OpenReadStream())
{
try {
var importedAccountsXLSX = await Importer.ImportXLSX(stream, funds, stocks);
var importedAccountsXLSX = await Importer.ImportXLSX(stream, funds);
result.ImportedAccounts.AddRange(importedAccountsXLSX);
result.DataFilesImported++;
} catch (Exception e) {
Expand Down Expand Up @@ -109,7 +109,7 @@ public static async Task<ImportResult> ImportDataFiles(IReadOnlyList<IBrowserFil
return result;
}

public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> funds, IList<Fund> stocks)
public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> funds)
{
try {
List<Account> importedAccounts = new();
Expand Down Expand Up @@ -149,7 +149,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
accountLookup.Add(accountNum, newAccount);
}

Investment newInvestment = new () { funds = funds, stocks = stocks, Ticker = symbol, Name = (investmentName != null ? investmentName : null), Value = value, Shares = shares, CostBasis = costBasis };
Investment newInvestment = new () { funds = funds, Ticker = symbol, Name = (investmentName != null ? investmentName : null), Value = value, Shares = shares, CostBasis = costBasis };
newAccount?.Investments.Add(newInvestment);
}

Expand Down Expand Up @@ -212,7 +212,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
lastAccountNumber = accountNumber;
}

Investment newInvestment = new () { funds = funds, stocks = stocks, Ticker = symbol, Name = investmentName, Price = price, Value = value, Shares = shares, CostBasis = costBasis };
Investment newInvestment = new () { funds = funds, Ticker = symbol, Name = investmentName, Price = price, Value = value, Shares = shares, CostBasis = costBasis };
newAccount?.Investments.Add(newInvestment);
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
importedAccounts.Add(newAccount);
}

Investment newInvestment = new () { funds = funds, stocks = stocks, Ticker = symbol, Name = investmentName, Price = price, Value = value, Shares = shares };
Investment newInvestment = new () { funds = funds, Ticker = symbol, Name = investmentName, Price = price, Value = value, Shares = shares };
newAccount?.Investments.Add(newInvestment);
}

Expand Down Expand Up @@ -314,7 +314,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
accountLookup.Add(accountNum, newAccount);
}

Investment newInvestment = new () { funds = funds, stocks = stocks, Ticker = symbol, Name = (investmentName != null ? investmentName : null) , Value = value, Shares = shares };
Investment newInvestment = new () { funds = funds, Ticker = symbol, Name = (investmentName != null ? investmentName : null) , Value = value, Shares = shares };
newAccount?.Investments.Add(newInvestment);
}
}
Expand Down Expand Up @@ -363,7 +363,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
}

if (value < 0.0 || value > 1.0) {
Investment newInvestment = new () { funds = funds, stocks = stocks, Ticker = symbol, Name = (investmentName != null ? investmentName : null), Value = value, Shares = shares, CostBasis = costBasis };
Investment newInvestment = new () { funds = funds, Ticker = symbol, Name = (investmentName != null ? investmentName : null), Value = value, Shares = shares, CostBasis = costBasis };
newAccount?.Investments.Add(newInvestment);
}

Expand Down Expand Up @@ -415,7 +415,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
}

if (value < 0.0 || value > 1.0) {
Investment newInvestment = new () { funds = funds, stocks = stocks, Ticker = symbol, Name = (investmentName != null ? investmentName : null), Value = value, Shares = shares, CostBasis = costBasis };
Investment newInvestment = new () { funds = funds, Ticker = symbol, Name = (investmentName != null ? investmentName : null), Value = value, Shares = shares, CostBasis = costBasis };
newAccount?.Investments.Add(newInvestment);
}

Expand Down Expand Up @@ -509,7 +509,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
var quantity = ParseDoubleOrNull(GetValue(chunks, quantityCol));
var value = ParseDoubleOrNull(GetValue(chunks, valueCol), allowCurrency:true);

var newAccount = StoreInvestment(accountLookup, importedAccounts, funds, stocks, "Ameriprise", value, accountDescription!.Substring(accountDescription.Length-4), symbol, investmentName, quantity, costBasis:null);
var newAccount = StoreInvestment(accountLookup, importedAccounts, funds, "Ameriprise", value, accountDescription!.Substring(accountDescription.Length-4), symbol, investmentName, quantity, costBasis:null);
}
}
}
Expand All @@ -532,7 +532,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
}


private static Account? StoreInvestment(Dictionary<string,Account> accountLookup, List<Account> importedAccounts, IList<Fund> funds, IList<Fund> stocks, string custodian, double? value, string account, string? symbol, string? investmentName, double? shares, double? costBasis)
private static Account? StoreInvestment(Dictionary<string,Account> accountLookup, List<Account> importedAccounts, IList<Fund> funds, string custodian, double? value, string account, string? symbol, string? investmentName, double? shares, double? costBasis)
{
Account? newAccount = null;

Expand All @@ -549,7 +549,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
accountLookup.Add(account, newAccount);
}

Investment newInvestment = new () { funds = funds, stocks = stocks, Ticker = symbol, Name = investmentName, Value = value, Shares = shares, CostBasis = costBasis };
Investment newInvestment = new () { funds = funds, Ticker = symbol, Name = investmentName, Value = value, Shares = shares, CostBasis = costBasis };
newAccount?.Investments.Add(newInvestment);
}

Expand All @@ -561,7 +561,7 @@ public static async Task<List<Account>> ImportCSV(string[] lines, IList<Fund> fu
return (columnIndex.HasValue ? TrimQuotes(chunks[columnIndex.Value]) : null);
}

public static async Task<List<Account>> ImportXLSX(Stream stream, IList<Fund> funds, IList<Fund> stocks) {
public static async Task<List<Account>> ImportXLSX(Stream stream, IList<Fund> funds) {
List<Account> importedAccounts = new();

MemoryStream ms = new MemoryStream();
Expand Down Expand Up @@ -617,7 +617,7 @@ public static async Task<List<Account>> ImportXLSX(Stream stream, IList<Fund> fu
importedAccounts.Add(newAccount);
}

Investment newInvestment = new () { funds = funds, stocks = stocks, Ticker = symbol, Name = investmentName, Value = value, Shares = shares, CostBasis = costBasis };
Investment newInvestment = new () { funds = funds, Ticker = symbol, Name = investmentName, Value = value, Shares = shares, CostBasis = costBasis };
newAccount?.Investments.Add(newInvestment);
}
row++;
Expand Down
17 changes: 5 additions & 12 deletions Shared/Models/FamilyData/Investment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ public class Investment
{
[JsonIgnore]
public IList<Fund>? funds { get; set; }
[JsonIgnore]
public IList<Fund>? stocks { get; set; }

private string? _Name;
public string? Name {
Expand All @@ -32,21 +30,16 @@ public string? Ticker {
{
if (_Ticker == fund.Ticker)
{
if (fund.AssetType == null)
{
fund.AssetType = global::AssetType.Stock;
}

AutoComplete(fund);
found = true;
return;
}
}
foreach (var stock in stocks)
{
if (_Ticker == stock.Ticker)
{
stock.AssetType = global::AssetType.Stock;
AutoComplete(stock);
found = true;
return;
}
}
if (!found) {
if (AutoCompleted) {
AutoComplete(null);
Expand Down

0 comments on commit 3c38ec0

Please sign in to comment.