dickwolff/Export-To-Ghostfolio

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

Closed this issue · 11 comments

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

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!

Hey. Thank you for the really fast response!

These are connected to CFDs orders.

  • SWAP: Is the price you have to pay for opening the CFD (so, is, in my outsider view of the issue, a fee you pay for holding the CFD and it's paid at the moment you take profit (or loss) from it).
  • Profit/Loss: Is calculated at the time you close the CFD and it can be negative or positive (so, basically the same as the outcome of a normal trade).

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?

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.

  • Open CFD
  • Take Profit/Loss on that CFD upon close
  • Take the fee (SWAP) out of that Profit/Loss

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!

Thanks, that would be stellar!

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!

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

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.

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

Closing due to inactivity.