Skip to content

Commit

Permalink
Merge pull request #43 from Sonlis/feature/match-transaction-and-fees…
Browse files Browse the repository at this point in the history
…-with-orderId

DEGIRO: Match transactions with their fees through the orderId
  • Loading branch information
dickwolff authored Apr 3, 2024
2 parents 7211fec + 83ee96e commit de44032
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
next-version: 0.7.2
next-version: 0.7.3
assembly-informational-format: "{NuGetVersion}"
mode: ContinuousDeployment
branches:
Expand Down
4 changes: 2 additions & 2 deletions src/converters/degiroConverterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GhostfolioExport } from "../models/ghostfolioExport";
describe("degiroConverterV2", () => {

beforeEach(() => {
jest.spyOn(console, "log").mockImplementation(jest.fn());
// jest.spyOn(console, "log").mockImplementation(jest.fn());
});

afterEach(() => {
Expand Down Expand Up @@ -33,7 +33,7 @@ describe("degiroConverterV2", () => {
// Assert
expect(actualExport).toBeTruthy();
expect(actualExport.activities.length).toBeGreaterThan(0);
expect(actualExport.activities.length).toBe(16);
expect(actualExport.activities.length).toBe(15);

done();
}, () => { done.fail("Should not have an error!"); });
Expand Down
31 changes: 18 additions & 13 deletions src/converters/degiroConverterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class DeGiroConverterV2 extends AbstractConverter {
continue;
}
}
else if (this.isTransactionFeeRecord(record)) {
else if (this.isTransactionFeeRecord(record, false)) {

// If it was a transaction record without any other transaction connected, skip it.
bar1.increment();
Expand Down Expand Up @@ -223,7 +223,7 @@ export class DeGiroConverterV2 extends AbstractConverter {
const nextRecord = records[currentIndex + 1];

// Return wether both records are about the same product.
return currentRecord.product === nextRecord.product;
return currentRecord.product === nextRecord.product && currentRecord.orderId === nextRecord.orderId;
}

private combineRecords(currentRecord: DeGiroRecord, nextRecord: DeGiroRecord, security: YahooFinanceRecord): [GhostfolioActivity, number] {
Expand All @@ -236,12 +236,12 @@ export class DeGiroConverterV2 extends AbstractConverter {

// Determine which of the two records is the action record (e.g. buy/sell) and which contains the transaction fees.
// Firstly, check if the current record is the TxFee record.
if (this.isTransactionFeeRecord(currentRecord)) {
if (this.isTransactionFeeRecord(currentRecord, true)) {
actionRecord = nextRecord;
txFeeRecord = currentRecord;
}
// Next, check wether the next record is NOT a TxFee record. In this case, the transaction has no fees.
else if (!this.isTransactionFeeRecord(nextRecord)) {
else if (!this.isTransactionFeeRecord(nextRecord, true)) {
txFeeRecord = null;
}

Expand Down Expand Up @@ -295,12 +295,12 @@ export class DeGiroConverterV2 extends AbstractConverter {

// Determine which of the two records is the dividend record and which contains the transaction fees.
// Firstly, check if the current record is the TxFee record.
if (this.isTransactionFeeRecord(currentRecord)) {
if (this.isTransactionFeeRecord(currentRecord, false)) {
dividendRecord = nextRecord;
txFeeRecord = currentRecord;
}
// Next, check wether the next record is NOT a TxFee record. In this case, the dividend has no fees.
else if (!this.isTransactionFeeRecord(nextRecord)) {
else if (!this.isTransactionFeeRecord(nextRecord, false)) {
txFeeRecord = null;
}

Expand Down Expand Up @@ -338,9 +338,9 @@ export class DeGiroConverterV2 extends AbstractConverter {
// - TxFee + Buy/Sell records, or
// - Buy/Sell record without TxFee.
return (
(this.isBuyOrSellRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord)) ||
(this.isTransactionFeeRecord(currentRecord) && this.isBuyOrSellRecord(nextRecord) ||
(this.isBuyOrSellRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord))));
(this.isBuyOrSellRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord, true)) ||
(this.isTransactionFeeRecord(currentRecord, true) && this.isBuyOrSellRecord(nextRecord) ||
(this.isBuyOrSellRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord, true))));
}

private isDividendRecordSet(currentRecord: DeGiroRecord, nextRecord: DeGiroRecord): boolean {
Expand All @@ -350,9 +350,9 @@ export class DeGiroConverterV2 extends AbstractConverter {
// - TxFee + Dividend record, or
// - Dividend record without TxFee.
return (
(this.isDividendRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord)) ||
(this.isTransactionFeeRecord(currentRecord) && this.isDividendRecord(nextRecord)) ||
(this.isDividendRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord)));
(this.isDividendRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord, false)) ||
(this.isTransactionFeeRecord(currentRecord, false) && this.isDividendRecord(nextRecord)) ||
(this.isDividendRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord, false)));
}

private isBuyOrSellRecord(record: DeGiroRecord): boolean {
Expand All @@ -375,12 +375,17 @@ export class DeGiroConverterV2 extends AbstractConverter {
return record.description.toLocaleLowerCase().indexOf("dividend") > -1 || record.description.toLocaleLowerCase().indexOf("capital return") > -1;
}

private isTransactionFeeRecord(record: DeGiroRecord): boolean {
private isTransactionFeeRecord(record: DeGiroRecord, isBuyOrSellTransactionFeeRecord: boolean): boolean {

if (!record) {
return false;
}

// When a dividend transaction must be found, there should not be an orderid.
if (!isBuyOrSellTransactionFeeRecord && record.orderId) {
return false;
}

const transactionFeeRecordType = ["en\/of", "and\/or", "und\/oder", "e\/o", "adr\/gdr", "ritenuta", "belasting", "daň z dividendy", "taxe sur les", "comissões de transação", "courtage et/ou"];

return transactionFeeRecordType.some((t) => record.description.toLocaleLowerCase().indexOf(t) > -1);
Expand Down
1 change: 1 addition & 0 deletions src/models/degiroRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export class DeGiroRecord {
fx: string;
currency: string;
amount: string;
orderId: string;
}

0 comments on commit de44032

Please sign in to comment.