Skip to content

Commit

Permalink
Improved parsing for IB/Lynx. Added support for parsing also of Activ…
Browse files Browse the repository at this point in the history
…ity Summary (extra to Activity statement).
  • Loading branch information
vladimir-aubrecht committed Mar 28, 2022
1 parent ddda760 commit c659d82
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private IList<StatementRowModel> LoadStatementModel(string statementFilePath)
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine($"{nameof(DegiroParser)} failed to parse statement.");
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ namespace StatementParser.Parsers.Brokers.Lynx.CsvModels
{
internal class DividendsRowModel
{
[Index(0)]
[Name("Dividends")]
public string Section { get; set; }

[Index(2)]
[Name("Currency")]
public string Currency { get; set; }

[Index(3)]
[Name("Date")]
public DateTime? Date { get; set; }

[Index(4)]
[Name("Description")]
public string Description { get; set; }

[Index(5)]
[Name("Amount")]
public decimal Amount { get; set; }

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ namespace StatementParser.Parsers.Brokers.Lynx.CsvModels
{
internal class WithholdingTaxRowModel
{
[Index(0)]
[Name("Withholding Tax")]
public string Section { get; set; }

[Index(2)]
[Name("Currency")]
public string Currency { get; set; }

[Index(3)]
[Name("Date")]
public DateTime Date { get; set; }

[Index(4)]
[Name("Description")]
public string Description { get; set; }

[Index(5)]
[Name("Amount")]
public decimal Amount { get; set; }

[Index(6)]
[Name("Code")]
public string Code { get; set; }

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public static T ReadObject<T>(this CsvReader csvReader, int headerFieldIndex, Fu

dataSets[key].PropertyType.GetMethod("Add").Invoke(value, new[] { record });
}
catch (Exception ex) when (ex.InnerException is FormatException)
catch (Exception ex) when (csvReader.HeaderRecord[csvReader.CurrentIndex] == "Date" && String.IsNullOrEmpty(csvReader.GetField(csvReader.CurrentIndex)))
{
//skip it, it's not interesting record (typically row with totals).
//skip it, it's not interesting record as it doesn't have date (typically row with totals).
}
}
return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ public IList<Transaction> Parse(string statementFilePath)

var statement = LoadStatementModel(statementFilePath);

if (statement == null || statement.Statement[0].FieldValue != "Activity Statement")
if (statement == null)
{
return null;
}

var titleField = statement.Statement.Where(i => i.FieldName == "Title");
if (titleField.First()?.FieldValue.StartsWith("Activity") != true)
{
Console.WriteLine("Statement was parsed, but it's not recognized as Activity Statement neither Activity Summary, so throwing the result away.");
return null;
}

var output = new List<Transaction>();
foreach (var dividend in statement.Dividends)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"StatementParserCLI": {
"commandName": "Project",
"commandLineArgs": "\"C:\\Users\\vladi\\Downloads\\ProfitAndLostStatement.pdf\""
"commandLineArgs": "C:\\Users\\vladi\\Downloads\\IB"
}
}
}

0 comments on commit c659d82

Please sign in to comment.