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

timelineCsvConverter.py index out of range for selling a fractional share (gift) by market order #19

Open
bufemc opened this issue Dec 12, 2021 · 0 comments

Comments

@bufemc
Copy link

bufemc commented Dec 12, 2021

timelineCsvConverter.py index out of range for selling a fractional share (giftby Stellantis) by market order, and selling I guess "Bezugsrechte" by Kion (this might be 2 bugs in 1 report):

This:

            profit = abs(float(re.findall("[-+]?\d.*\.\d+|\d+", body)[1].replace(",", "")) / 100) #as decimal (percentage)

works fine for e.g.

'Limit Sell order executed at 132.22 €\nProfit:  -1.18 %'

But breaks on:

'Sell order executed at 46.58 €'
'Sell order executed at 0.3727 €'

with (for both):

Traceback (most recent call last):
  File "C:\workspace\python\TradeRepublicApi\examples\timelineCsvConverter.py", line 180, in <module>
    profit = abs(float(re.findall("[-+]?\d.*\.\d+|\d+", body)[1].replace(",", "")) / 100) #as decimal (percentage)
IndexError: list index out of range

and (only for the second):

Traceback (most recent call last):
  File "C:\workspace\python\TradeRepublicApi\examples\timelineCsvConverter.py", line 187, in <module>
    shares = "{0:.4f}".format(cashChangeAmount / amountPerShare)
ZeroDivisionError: float division by zero

There is a clue: this was a and my only (maybe) fractional share I got from Stellantis as a "gift" once:

	{
		"type": "timelineEvent",
		"data": {
			"id": "***",
			"timestamp": 1618213392603,
			"icon": "https://assets.traderepublic.com/img/icon/timeline/Arrow-Left.png",
			"title": "Faurecia",
			"body": "Sell order executed at 46.58 \u20ac",
			"cashChangeAmount": 16.73,
			"action": {
				"type": "timelineDetail",
				"payload": "***"
			},
			"attributes": [],
			"month": "2021-04"
		}
	},

and I guess Bezugsrechte Kion:

	{
		"type": "timelineEvent",
		"data": {
			"id": "***",
			"timestamp": 1606928074040,
			"icon": "https://assets.traderepublic.com/img/icon/timeline/Arrow-Left.png",
			"title": "KION GROUP AG",
			"body": "Sell order executed at 0.3727 \u20ac",
			"cashChangeAmount": 4.74,
			"action": {
				"type": "timelineDetail",
				"payload": "***"
			},
			"attributes": [],
			"month": "2020-12"
		}
	},

Which could be sold only by market order and might even have no buy in.
It's no big bug, as the occurence might be quite rare. But just wanted it to be noted.

First one is a "gift" by Stellantis and second one might be "Bezugsrechte" by Kion.

Workaround: edit myTimeline.json and change it e.g. to:

"Sell order executed at 46.58 €\nProfit:  0.00 %",

The latter one (Bezugsrechte) I added some print statements and it turned out that:
cashChangeAmount = 4.74
amountPerShare = 0.0
So that's why division by zero error.

A really dirty quick workaround could be here:

            if amountPerShare == 0:
                amountPerShare = cashChangeAmount

If this issue should be too confusing I could create 2 issues instead, now it's mixed up a little ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant