Skip to content

Commit

Permalink
Etoro add fee and refund (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbcelly authored Jan 9, 2025
1 parent df14603 commit f068d1b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 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.22.1
next-version: 0.22.2
assembly-informational-format: "{NuGetVersion}"
mode: ContinuousDeployment
branches:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "export-to-ghostfolio",
"version": "0.22.1",
"version": "0.22.2",
"type": "module",
"description": "Convert multiple broker exports to Ghostfolio import",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion samples/etoro-export.csv
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ Date,Type,Details,Amount,Units,Realized Equity Change,Realized Equity,Balance,Po
17/01/2024 00:04:28,Dividend,KER/EUR,0.01,-,0.01,"4,581.91",0.80,831716072,Stocks,0.00
17/01/2024 00:04:28,Dividend,KER/EUR,0.01,-,0.01,"4,581.91",0.80,1074146904,Stocks,0.00
14/04/2020 14:00:25,Open Position,NKE/USD," 100,00 ",0.398451," 0,00 "," 212,87 "," 12,87 ",1074146905,CFD," 0,00 "
15/04/2020 00:46:41,Overnight fee,Daily,"(0,10)",-,"(0,10)"," 212,77 "," 12,77 ",1074146905,CFD," 0,00 "
15/04/2020 00:46:41,Overnight fee,Daily,"(0,10)",-,"(0,10)"," 212,77 "," 12,77 ",1074146905,CFD," 0,00 "
18/05/2020 04:09:41,Open Position,NKE/USD," 200,00 ",65.359477," 0,00 "," 1 757,95 "," 1 157,95 ",624957573,CFD," 0,00 "
19/05/2020 00:51:22,Overnight fee,Daily,"(0,31)",-,"(0,31)"," 1 791,84 "," 1 091,84 ",624957573,CFD," 0,00 "
20/05/2020 01:31:04,Overnight refund,Daily," 0,21 ",-," 0,21 "," 1 903,87 "," 1 303,87 ",624957573,CFD," 0,00 "
20/05/2020 20:59:02,Position closed,NKE/USD," 392,16 ",65.359477," 192,16 "," 2 229,31 "," 1 829,31 ",624957573,CFD," 0,00 "
27 changes: 26 additions & 1 deletion src/converters/etoroConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,32 @@ describe("etoroConverter", () => {
// Assert
expect(actualExport).toBeTruthy();
expect(actualExport.activities.length).toBeGreaterThan(0);
expect(actualExport.activities.length).toBe(19);
expect(actualExport.activities.length).toBe(26);

done();
}, () => { done.fail("Should not have an error!"); });
});

it("should process fee and interest records with comments", (done) => {

// Arange
const sut = new EtoroConverter(new SecurityService(new YahooFinanceServiceMock()));
const inputFile = "samples/etoro-export.csv";

// Act
sut.readAndProcessFile(inputFile, (actualExport: GhostfolioExport) => {

// Assert
expect(actualExport).toBeTruthy();
const fee = actualExport.activities[23];
expect(fee.comment).toBe("FEE CFD Daily");
expect(fee.type).toBe("FEE");
expect(fee.fee).toBe(0.31);

const refund = actualExport.activities[24];
expect(refund.comment).toBe("REFUND CFD Daily");
expect(refund.type).toBe("INTEREST");
expect(refund.fee).toBe(0.21);

done();
}, () => { done.fail("Should not have an error!"); });
Expand Down
24 changes: 20 additions & 4 deletions src/converters/etoroConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export class EtoroConverter extends AbstractConverter {
else if (action.indexOf("interest") > -1) {
return "interest";
}
else if (action.indexOf("fee") > -1) {
return "fee";
}
else if (action.indexOf("refund") > -1) {
return "refund";
}
}

// Parse numbers to floats (from string).
Expand Down Expand Up @@ -97,18 +103,28 @@ export class EtoroConverter extends AbstractConverter {

const date = dayjs(`${record.date}`, "DD/MM/YYYY HH:mm:ss");

// Interest does not have a security, so add those immediately.
if (record.type.toLocaleLowerCase() === "interest") {
// Interest, fee and refund does not have a security, so add those immediately.
if (record.type.toLocaleLowerCase() === "interest" || record.type.toLocaleLowerCase() === "fee" || record.type.toLocaleLowerCase() === "refund") {

const feeAmount = Math.abs(record.amount);
let recordType = record.type
let comment = '';

if (record.type.toLocaleLowerCase() === "fee" || record.type.toLocaleLowerCase() === "refund") {
comment += `${recordType.toLocaleUpperCase()} ${record.assetType} ${record.details}`;
}

if (recordType.toLocaleLowerCase() === "refund") {
recordType = "interest";
}

// Add fees record to export.
result.activities.push({
accountId: process.env.GHOSTFOLIO_ACCOUNT_ID,
comment: "",
comment: comment,
fee: feeAmount,
quantity: 1,
type: GhostfolioOrderType[record.type],
type: GhostfolioOrderType[recordType],
unitPrice: feeAmount,
currency: "USD",
dataSource: "MANUAL",
Expand Down

0 comments on commit f068d1b

Please sign in to comment.