Skip to content

Commit

Permalink
Allow priority setting of DataSource (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
VibeNL authored Jan 11, 2024
1 parent 22d5f29 commit 0c75379
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
11 changes: 10 additions & 1 deletion GhostfolioSidekick/Configuration/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
using System.Text.Json.Serialization;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

namespace GhostfolioSidekick.Configuration
{
public class Settings
{
[SetsRequiredMembers]
public Settings()
{
}

[JsonPropertyName("dataprovider.preference.order")]
public required string DataProviderPreference { get; set; } = "YAHOO;COINGECKO";

[JsonPropertyName("use.crypto.workaround.stakereward.as.dividends")]
public bool CryptoWorkaroundStakeReward { get; set; }

Expand Down
1 change: 1 addition & 0 deletions GhostfolioSidekick/DisplayInformationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private void PrintUsedSettings()
sb.AppendLine($"GhostfolioUrl : {applicationSettings.GhostfolioUrl}");
sb.AppendLine($"FileImporterPath : {applicationSettings.FileImporterPath}");

sb.AppendLine($"DataProviderPreference : {applicationSettings.ConfigurationInstance.Settings.DataProviderPreference}");
sb.AppendLine($"CryptoWorkaroundStakeReward : {applicationSettings.ConfigurationInstance.Settings.CryptoWorkaroundStakeReward}");
sb.AppendLine($"CryptoWorkaroundDust : {applicationSettings.ConfigurationInstance.Settings.CryptoWorkaroundDust}");
sb.AppendLine($"CryptoWorkaroundDustThreshold : {applicationSettings.ConfigurationInstance.Settings.CryptoWorkaroundDustThreshold.ToString(CultureInfo.InvariantCulture)}");
Expand Down
15 changes: 14 additions & 1 deletion GhostfolioSidekick/Ghostfolio/API/GhostfolioAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public partial class GhostfolioAPI : IGhostfolioAPI
private readonly SymbolMapper mapper;
private RestCall restCall;

private List<string> SortorderDataSources { get; set; }

public bool AllowAdminCalls { get; private set; } = true;

public GhostfolioAPI(
Expand All @@ -36,6 +38,8 @@ public GhostfolioAPI(
restCall = new RestCall(memoryCache, logger, settings.GhostfolioUrl, settings.GhostfolioAccessToken);
modelToContractMapper = new ModelToContractMapper(new CurrentPriceCalculator(this));
mapper = new SymbolMapper(settings.ConfigurationInstance.Mappings ?? []);

SortorderDataSources = [.. settings.ConfigurationInstance.Settings.DataProviderPreference.Split(',') ?? []];
}

public async Task<Model.Account?> GetAccountByName(string name)
Expand Down Expand Up @@ -288,7 +292,16 @@ static void AddToCache(CacheKey key, Model.SymbolProfile? asset, IMemoryCache ca
.ThenByDescending(x => FussyMatch(identifiers, x))
.ThenBy(x => string.Equals(x.Currency.Symbol, expectedCurrency?.Symbol, StringComparison.InvariantCultureIgnoreCase) ? 0 : 1)
.ThenBy(x => new[] { CurrencyHelper.EUR.Symbol, CurrencyHelper.USD.Symbol, CurrencyHelper.GBP.Symbol }.Contains(x.Currency.Symbol) ? 0 : 1) // prefer well known currencies
.ThenByDescending(x => x.DataSource) // prefer Yahoo above Coingecko due to performance
.ThenBy(x =>
{
var index = SortorderDataSources.IndexOf(x.DataSource);
if (index < 0)
{
index = int.MaxValue;
}

return index;
}) // prefer Yahoo above Coingecko due to performance
.ThenBy(x => x.Name?.Length ?? int.MaxValue)
.FirstOrDefault();
return filteredAsset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private async Task SetKnownPrices(SymbolConfiguration symbolConfiguration, List<
.GroupBy(x => x.Date)
.Select(x => x
.OrderBy(x => x.ReferenceCode)
.ThenByDescending(x => x.UnitPrice)
.ThenByDescending(x => x.UnitPrice.Amount)
.ThenByDescending(x => x.Quantity)
.ThenByDescending(x => x.ActivityType).First())
.OrderBy(x => x.Date)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Also allows the following sybol settings
```
{
"settings" : {
"dataprovider.preference.order": "COINGECKO,YAHOO", // default "YAHOO,COINGECKO"
"use.crypto.workaround.stakereward.as.dividends" : true, // default is false
"use.crypto.workaround.dust" : true // default is false,
"use.crypto.workaround.dust.threshold": 0.01 // default is 0
Expand Down

0 comments on commit 0c75379

Please sign in to comment.