dickwolff / Export-To-Ghostfolio

Convert transaction history export from your favorite broker to a format that can be imported in Ghostfolio.
https://hub.docker.com/r/dickwolff/export-to-ghostfolio
Apache License 2.0
63 stars 10 forks source link

XTB import fails with `TypeError: Cannot read properties of null (reading '1')` #90

Closed jbmorgado closed 3 months ago

jbmorgado commented 4 months ago

Hello.

I'm using the latest 0.16.0 version and when I try to import the XTB transactions, I get the following error: TypeError: Cannot read properties of null (reading '1')

This is the last block of the import plus the error:

{
  iD: '519422100',
  type: 'Swap',
  time: '21.03.2024 13:30:19',
  symbol: 'DIS.US',
  comment: 'Swap of position #994025001',
  amount: -142.12
}
/app/src/converters/xtbConverter.ts:114
                const quantity = parseFloat(match[1]);
                                            ^

TypeError: Cannot read properties of null (reading '1')
    at <anonymous> (/app/src/converters/xtbConverter.ts:114:45)

Node.js v20.15.1

And on the csv, the corresponding line of the message and the next one (not sure if the error is about the block already presented or when picking the next one) is:

519422100;Swap;21.03.2024 13:30:19;DIS.US;Swap of position #994025001;-142.12 
519422099;Profit/Loss (FX/CFD);21.03.2024 13:30:19;DIS.US;Profit of position #994025001;500.79
dickwolff commented 4 months ago

Hi! I've checked the converter and the Swap and Profit/loss records are not recognized correctly in the XTB converter.

Could you tell me what these records are, and what they are supposed to do? Like, is Profit/loss some kind of dividend? When I know how to handle these records, I can add them to the converter for future processing. The alternative is adding them to the ignore list.

Thanks for your help!

jbmorgado commented 4 months ago

Hey. Thank you for the really fast response!

These are connected to CFDs orders.

dickwolff commented 4 months ago

Thanks for the explanation. So am I correct to summarize that a swap could be seen as a separate Fee record inside Ghostfolio, or as a fee attached to the Profit/Loss record, which in turn can be seen as a Buy/Sell record inside Ghostfolio?

jbmorgado commented 4 months ago

Yes, I would say that the best way is if it could be attached to the same trade that has the Profit/Loss record.

So, it would be mostly like a normal trade.

dickwolff commented 4 months ago

I've done something similar with DEGIRO so should not be a problem. Will try and work something out this week and get back to you!

jbmorgado commented 4 months ago

Thanks, that would be stellar!

dickwolff commented 4 months ago

Sorry for the late response. I've just added support for this. Could you try and test it with the beta image?

Some notes: I've tagged the CFD as a sell order in Ghostfolio. The fee record will be attached to it. I don't think it's possible to know/determine how it would be registered as a CFD with a loss/profit. So I decided it would probably be a sell order. Please let me know if this is how you would like it registered, or if there needs to change anything. Thanks!

jbmorgado commented 4 months ago

Hi there, sorry, I was busy yesterday.

So, the exporter finishes successfully, but then, ghostfolio complains the file to import is wrongly formatted (see attachment).

I don't mind sending you the output JSON file through PM if you think it helps.

Screenshot 2024-07-25 171227

dickwolff commented 4 months ago

So now the unit price mapping does not work at all, that's not helpful :-)

Could you maybe send me the input CSV you used for this? So then I can check it locally and try and make it work again. This would also help for the instances without the BUY/DIVIDEND/FEE/... errors.

dickwolff commented 3 months ago

Hi @jbmorgado, any change you can get back to me and provide me the input you used? Thanks!

dickwolff commented 3 months ago

Closing due to inactivity.