Skip to content

Commit

Permalink
Filter out activities for accounts not being managed
Browse files Browse the repository at this point in the history
  • Loading branch information
VibeNL committed Dec 3, 2024
1 parent 2e04bdd commit 5589c9d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions GhostfolioAPI/API/ApiWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Linq;

namespace GhostfolioSidekick.GhostfolioAPI.API
{
Expand Down Expand Up @@ -113,19 +114,22 @@ public async Task CreatePlatform(Model.Accounts.Platform platform)
public async Task SyncAllActivities(List<Model.Activities.Activity> allActivities)
{
var content = await restCall.DoRestGet($"api/v1/order");
var existingActivities = JsonConvert.DeserializeObject<ActivityList>(content!)!.Activities;
var existingActivities = JsonConvert.DeserializeObject<ActivityList>(content!)!.Activities.ToList();

// fixup
foreach (var existingActivity in existingActivities)
{
existingActivity.FeeCurrency = existingActivity.FeeCurrency ?? existingActivity.SymbolProfile.Currency;
}

// TODO, only handle activities of the managed accounts, not all

var symbols = await GetAllSymbolProfiles();
var accounts = await GetAllAccounts();

// Filter out existing activities that are not in the new list
var accountFromActivities = allActivities.Select(x => x.Account.Name).Distinct().ToList();
var accountIds = accountFromActivities.Select(x => accounts.SingleOrDefault(y => y.Name == x)?.Id).Where(x => x != null).Select(x => x!).ToList();
existingActivities = existingActivities.Where(x => accountIds.Contains(x.AccountId!)).ToList();

// Get new activities
var newActivities = allActivities.Select(async activity =>
{
Expand Down

0 comments on commit 5589c9d

Please sign in to comment.