Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XTB: Support interest and fractional shares #51

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ DEBUG_LOGGING = false
# Set prefered exchange if you have securities that are traded at multiple exchanges, like Vanguard FTSE All-World UCITS ETF (VWRL.AS, VWCE.DE, VRRA.L)
# Leave commented if you don't want to use this.
#DEGIRO_PREFERED_EXCHANGE_POSTFIX = ".AS"

# Default account currency that will be used when the currency is not present in the input file.
#XTB_ACCOUNT_CURRENCY = "EUR"
9 changes: 7 additions & 2 deletions sample-xtb-export.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
ID;Type;Time;Symbol;Comment;Amount
530692719;Stocks/ETF purchase;12.04.2024 13:01:45;SPYL.DE;OPEN BUY 34/42.5658 @ 11.7480;-399.43
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the unit test to reflect the new lines that should be added?

530692718;Stocks/ETF purchase;12.04.2024 13:01:45;SPYL.DE;OPEN BUY 8/42.5658 @ 11.7480;-93.98
530692712;Stocks/ETF purchase;12.04.2024 13:01:44;SPYL.DE;OPEN BUY 0.5658/42.5658 @ 11.7470;-6.65
530691593;Deposit;12.04.2024 13:00:22;;JP_MORGAN deposit, JP_MORGAN provider transaction id=TXN-C-4259483-259486, JP_MORGAN merchant reference id=TXN-C-4259483-259486, id=11083197;500
527253683;Free funds interests;05.04.2024 13:42:58;;Free-funds Interest 2024-03;0.1
525965629;Deposit;04.04.2024 09:30:02;;JP_MORGAN deposit, JP_MORGAN provider transaction id=TXN-C-4252349-60532, JP_MORGAN merchant reference id=TXN-C-4252349-60532, id=10944791;1000
524538242;Stocks/ETF purchase;02.04.2024 14:48:16;SPYL.DE;OPEN BUY 85 @ 11.7305;-997.09
524522819;Stocks/ETF purchase;02.04.2024 14:21:03;SPYL.DE;OPEN BUY 35 @ 11.7405;-410.92
524303821;Stocks/ETF sale;02.04.2024 11:42:37;ZAL.DE;CLOSE BUY 1 @ 26.280;26.28
Expand All @@ -8,5 +14,4 @@ ID;Type;Time;Symbol;Comment;Amount
516573845;Stocks/ETF purchase;15.03.2024 15:37:59;SPYL.DE;OPEN BUY 26 @ 11.3500;-295.1
515435183;Deposit;14.03.2024 10:30:23;;JP_MORGAN deposit, JP_MORGAN provider transaction id=TXN-C-4233659-166217, JP_MORGAN merchant reference id=TXN-C-4233659-166217, id=10635042;300
514947144;Deposit;13.03.2024 13:00:20;;JP_MORGAN deposit, JP_MORGAN provider transaction id=TXN-C-4232520-290438, JP_MORGAN merchant reference id=TXN-C-4232520-290438, id=10619119;300
513492358;Stocks/ETF purchase;11.03.2024 10:05:05;SPYL.DE;OPEN BUY 8 @ 11.2835;-90.27
511590287;Deposit;06.03.2024 16:00:05;;JP_MORGAN deposit, JP_MORGAN provider transaction id=TXN-C-4226067-324222, JP_MORGAN merchant reference id=TXN-C-4226067-324222, id=10499656;100

31 changes: 28 additions & 3 deletions src/converters/xtbConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ export class XtbConverter extends AbstractConverter {
if (type.indexOf("stocks/etf purchase") > -1) {
return "buy";
}
if (type.indexOf("stocks/etf sale") > -1) {
else if (type.indexOf("stocks/etf sale") > -1) {
return "sell";
}
else if (type.indexOf("free funds interests") > -1) {
return "interest";
}
}

// Parse numbers to floats (from string).
Expand Down Expand Up @@ -83,8 +86,30 @@ export class XtbConverter extends AbstractConverter {
}

const date = dayjs(`${record.time}`, "DD.MM.YYYY HH:mm:ss");
const match = record.comment.match(/(?:OPEN|CLOSE) BUY (\d+) @ ((?:[0-9]*[.])?[0-9]+)/)
const quantity = parseInt(match[1]);

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

// Add interest record to export.
result.activities.push({
accountId: process.env.GHOSTFOLIO_ACCOUNT_ID,
comment: record.comment,
fee: 0,
quantity: 1,
type: GhostfolioOrderType[record.type],
unitPrice: record.amount,
currency: process.env.XTB_ACCOUNT_CURRENCY,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a fallback to this? Like process.env.XTB_ACCOUNT_CURRENCY || “EUR”. I think currently Ghostfolio will not accept the export if you don’t provide a currency.

dataSource: "MANUAL",
date: date.format("YYYY-MM-DDTHH:mm:ssZ"),
symbol: record.comment,
});

bar1.increment();
continue;
}

const match = record.comment.match(/(?:OPEN|CLOSE) BUY (\d+|(?:[0-9]*[.])?[0-9]+)(?:\/(?:[0-9]*[.])?[0-9]+)? @ ((?:[0-9]*[.])?[0-9]+)/)
const quantity = parseFloat(match[1]);
const unitPrice = parseFloat(match[2]);

let security: YahooFinanceRecord;
Expand Down