Skip to content

Commit

Permalink
Add custom symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
VibeNL committed Oct 19, 2023
1 parent 8479039 commit fc6b7a8
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task ConvertActivitiesForAccount_TestFileSingleOrder_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("IE00B3XXRP09", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("IE00B3XXRP09", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/DeGiro/Example1/TestFileSingleOrder.csv" });
Expand Down Expand Up @@ -85,8 +85,8 @@ public async Task ConvertActivitiesForAccount_TestFileMultipleOrders_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("IE00B3XXRP09", null)).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByISIN("NL0009690239", null)).ReturnsAsync(asset2);
api.Setup(x => x.FindSymbolByIdentifier("IE00B3XXRP09", null)).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByIdentifier("NL0009690239", null)).ReturnsAsync(asset2);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/DeGiro/Example3/TestFileMultipleOrders.csv" });
Expand Down Expand Up @@ -126,7 +126,7 @@ public async Task ConvertActivitiesForAccount_TestFileDividend_WithTax_Converted
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("NL0009690239", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("NL0009690239", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/DeGiro/Example4/TestFileDividend.csv" });
Expand Down Expand Up @@ -156,7 +156,7 @@ public async Task ConvertActivitiesForAccount_TestFileDividend_NoTax_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("NL0009690239", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("NL0009690239", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/DeGiro/Example5/TestFileDividendNoTax.csv" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task ConvertActivitiesForAccount_TestFileSingleOrder_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.USD)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("US67066G1040", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("US67066G1040", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Generic/Example1/Example1.csv" });
Expand Down Expand Up @@ -70,7 +70,7 @@ public async Task ConvertActivitiesForAccount_TestFileLifecycle_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.USD)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("US67066G1040", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("US67066G1040", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Generic/Example2/Example2.csv" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public async Task ConvertActivitiesForAccount_TestFileMultipleOrders_ReferalPend
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("USDC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByISIN("BTC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset2);
api.Setup(x => x.FindSymbolByIdentifier("USDC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByIdentifier("BTC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset2);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Nexo/Example1/Example1.csv" });
Expand Down Expand Up @@ -84,8 +84,8 @@ public async Task ConvertActivitiesForAccount_TestFileMultipleOrders_ReferalAppr
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("USDC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByISIN("BTC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset2);
api.Setup(x => x.FindSymbolByIdentifier("USDC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByIdentifier("BTC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset2);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Nexo/Example2/Example2.csv" });
Expand Down Expand Up @@ -135,7 +135,7 @@ public async Task ConvertActivitiesForAccount_TestCashback_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("BTC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("BTC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Nexo/Example3/Cashback.csv" });
Expand Down Expand Up @@ -178,8 +178,8 @@ public async Task ConvertActivitiesForAccount_TestExchangeCoins_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("USDC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByISIN("BTC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset2);
api.Setup(x => x.FindSymbolByIdentifier("USDC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByIdentifier("BTC", It.IsAny<Func<IEnumerable<Asset>, Asset>>())).ReturnsAsync(asset2);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Nexo/Example4/ExchangeCoins.csv" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task ConvertActivitiesForAccount_Example1_OrderOnly()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("IE00077FRP95", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("IE00077FRP95", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/ScalableCapital/Example1/WUMExample1.csv" });
Expand Down Expand Up @@ -82,7 +82,7 @@ public async Task ConvertActivitiesForAccount_Example1_DividendOnly()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("US92343V1044", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("US92343V1044", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/ScalableCapital/Example1/RKKExample1.csv" });
Expand Down Expand Up @@ -113,8 +113,8 @@ public async Task ConvertActivitiesForAccount_Example1_Both()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("IE00077FRP95", null)).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByISIN("US92343V1044", null)).ReturnsAsync(asset2);
api.Setup(x => x.FindSymbolByIdentifier("IE00077FRP95", null)).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByIdentifier("US92343V1044", null)).ReturnsAsync(asset2);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] {
Expand Down Expand Up @@ -158,8 +158,8 @@ public async Task ConvertActivitiesForAccount_Example2_NotDuplicateFeesAndDivide
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("IE00077FRP95", null)).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByISIN("US92343V1044", null)).ReturnsAsync(asset2);
api.Setup(x => x.FindSymbolByIdentifier("IE00077FRP95", null)).ReturnsAsync(asset1);
api.Setup(x => x.FindSymbolByIdentifier("US92343V1044", null)).ReturnsAsync(asset2);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task ConvertActivitiesForAccount_TestFileSingleOrder_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("US67066G1040", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("US67066G1040", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Trading212/Example1/TestFileSingleOrder.csv" });
Expand Down Expand Up @@ -80,7 +80,7 @@ public async Task ConvertActivitiesForAccount_TestFileMultipleOrdersUS_Converted
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("US67066G1040", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("US67066G1040", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Trading212/Example2/TestFileMultipleOrdersUS.csv" });
Expand Down Expand Up @@ -121,7 +121,7 @@ public async Task ConvertActivitiesForAccount_TestFileSingleOrderUK_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("GB0007188757", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("GB0007188757", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Trading212/Example3/TestFileSingleOrderUK.csv" });
Expand Down Expand Up @@ -150,7 +150,7 @@ public async Task ConvertActivitiesForAccount_TestFileSingleDividend_Converted()
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("US0378331005", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("US0378331005", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Trading212/Example4/TestFileSingleDividend.csv" });
Expand Down Expand Up @@ -180,7 +180,7 @@ public async Task ConvertActivitiesForAccount_TestFileSingleOrderUKNativeCurrenc
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("GB0007188757", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("GB0007188757", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] { "./FileImporter/TestFiles/Trading212/Example5/TestFileSingleOrderUKNativeCurrency.csv" });
Expand Down Expand Up @@ -209,7 +209,7 @@ public async Task ConvertActivitiesForAccount_TestFileSingleOrderMultipleTimes_C
var account = fixture.Build<Account>().With(x => x.Balance, Balance.Empty(DefaultCurrency.EUR)).Create();

api.Setup(x => x.GetAccountByName(account.Name)).ReturnsAsync(account);
api.Setup(x => x.FindSymbolByISIN("US67066G1040", null)).ReturnsAsync(asset);
api.Setup(x => x.FindSymbolByIdentifier("US67066G1040", null)).ReturnsAsync(asset);

// Act
account = await parser.ConvertActivitiesForAccount(account.Name, new[] {
Expand Down
2 changes: 1 addition & 1 deletion GhostfolioSidekick/FileImporter/DeGiro/DeGiroParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public DeGiroParser(IGhostfolioAPI api) : base(api)
return Array.Empty<Model.Activity>();
}

var asset = string.IsNullOrWhiteSpace(record.ISIN) ? null : await api.FindSymbolByISIN(record.ISIN);
var asset = string.IsNullOrWhiteSpace(record.ISIN) ? null : await api.FindSymbolByIdentifier(record.ISIN);
var fee = GetFee(record, allRecords);
var taxes = GetTaxes(record, allRecords);

Expand Down
2 changes: 1 addition & 1 deletion GhostfolioSidekick/FileImporter/FileImporterTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task DoWork()

var directories = Directory.GetDirectories(fileLocation);

foreach (var directory in directories.Select(x => new DirectoryInfo(x)))
foreach (var directory in directories.Select(x => new DirectoryInfo(x)).OrderBy(x => x.Name))
{
var accountName = directory.Name;
logger.LogInformation($"AccountName: {accountName}");
Expand Down
2 changes: 1 addition & 1 deletion GhostfolioSidekick/FileImporter/Generic/GenericParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public GenericParser(IGhostfolioAPI api) : base(api)

protected override async Task<IEnumerable<Model.Activity>> ConvertOrders(GenericRecord record, Model.Account account, IEnumerable<GenericRecord> allRecords)
{
var asset = string.IsNullOrWhiteSpace(record.Symbol) ? null : await api.FindSymbolByISIN(record.Symbol);
var asset = string.IsNullOrWhiteSpace(record.Symbol) ? null : await api.FindSymbolByIdentifier(record.Symbol);

if (string.IsNullOrWhiteSpace(record.Id))
{
Expand Down
13 changes: 6 additions & 7 deletions GhostfolioSidekick/FileImporter/Nexo/NexoParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
using GhostfolioSidekick.Ghostfolio.API;
using GhostfolioSidekick.Model;
using System.Globalization;
using System.Xml.Linq;

namespace GhostfolioSidekick.FileImporter.Nexo
{
public class NexoParser : CryptoRecordBaseImporter<NexoRecord>
{
private Asset[] fiatCoin = new[] {
new Asset(new Currency("EUR"), "EURX", "EURX", null, null, null),
new Asset(new Currency("USD"), "USDX", "USDX", null, null, null),
new Asset(new Currency("EUR"), "EUR", "EUR", null, null, null),
new Asset(new Currency("USD"), "USD", "USD", null, null, null)
new Asset(new Currency("EUR"), "EURX",null, "EURX", null, null, null),
new Asset(new Currency("USD"), "USDX",null, "USDX", null, null, null),
new Asset(new Currency("EUR"), "EUR", null,"EUR", null, null, null),
new Asset(new Currency("USD"), "USD",null, "USD", null, null, null)
};

public NexoParser(IGhostfolioAPI api) : base(api)
Expand Down Expand Up @@ -66,7 +65,7 @@ protected override async Task<IEnumerable<Activity>> ConvertOrders(NexoRecord re
return null;
}

return await api.FindSymbolByISIN(assetName, x =>
return await api.FindSymbolByIdentifier(assetName, x =>
ParseFindSymbolByISINResult(assetName, assetName, x));
}
}
Expand All @@ -81,7 +80,7 @@ private IEnumerable<Activity> HandleRecord(NexoRecord record, Activity inputActi
return new[] { SetActivity(outputActivity, ActivityType.Receive) };
case "ExchangeDepositedOn":
case "Exchange":
return HandleConversion( inputActivity, outputActivity);
return HandleConversion(inputActivity, outputActivity);
case "Interest":
case "FixedTermInterest":
// return new[] { SetActivity(outputActivity, ActivityType.Interest) }; // Staking rewards are not yet supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static string DetermineKey(BaaderBankRKKRecord x)
return null;
}

var asset = await api.FindSymbolByISIN(record.Isin.Replace("ISIN ", string.Empty));
var asset = await api.FindSymbolByIdentifier(record.Isin.Replace("ISIN ", string.Empty));

var quantity = decimal.Parse(record.Quantity.Replace("STK ", string.Empty), GetCultureForParsingNumbers());
var unitPrice = record.UnitPrice.GetValueOrDefault() / quantity;
Expand All @@ -138,7 +138,7 @@ static string DetermineKey(BaaderBankRKKRecord x)

private async Task<Activity> ConvertToOrder(BaaderBankWUMRecord record, ConcurrentDictionary<string, BaaderBankRKKRecord> rkkRecords)
{
var asset = await api.FindSymbolByISIN(record.Isin);
var asset = await api.FindSymbolByIdentifier(record.Isin);

var fee = FindFeeRecord(rkkRecords, record.Reference);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected override async Task<IEnumerable<Activity>> ConvertOrders(Trading212Rec
return Array.Empty<Activity>();
}

var asset = string.IsNullOrWhiteSpace(record.ISIN) ? null : await api.FindSymbolByISIN(record.ISIN);
var asset = string.IsNullOrWhiteSpace(record.ISIN) ? null : await api.FindSymbolByIdentifier(record.ISIN);

if (string.IsNullOrWhiteSpace(record.Id))
{
Expand Down
20 changes: 11 additions & 9 deletions GhostfolioSidekick/Ghostfolio/API/Contract/Asset.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
namespace GhostfolioSidekick.Ghostfolio.API.Contract
{
public class Asset
{
public string Currency { get; set; }
public class Asset
{
public string Currency { get; set; }

public string Symbol { get; set; }
public string Symbol { get; set; }

public string Name { get; set; }
public string Name { get; set; }

public string DataSource { get; set; }
public string DataSource { get; set; }

public string AssetSubClass { get; set; }
public string AssetSubClass { get; set; }

public string AssetClass { get; set; }
}
public string AssetClass { get; set; }

public string ISIN { get; set; }
}
}
20 changes: 11 additions & 9 deletions GhostfolioSidekick/Ghostfolio/API/Contract/SymbolProfile.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
namespace GhostfolioSidekick.Ghostfolio.API.Contract
{
public class SymbolProfile
{
public string Currency { get; set; }
public class SymbolProfile
{
public string Currency { get; set; }

public string Symbol { get; set; }
public string Symbol { get; set; }

public string DataSource { get; set; }
public string DataSource { get; set; }

public string Name { get; set; }
public string Name { get; set; }

public string AssetSubClass { get; set; }
public string AssetSubClass { get; set; }

public string AssetClass { get; set; }
}
public string AssetClass { get; set; }

public string ISIN { get; set; }
}
}
Loading

0 comments on commit fc6b7a8

Please sign in to comment.