Skip to content

Commit f26defb

Browse files
authored
Clean up some comments and minor code improvement (#188)
1 parent 2a1c308 commit f26defb

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

pytr/portfolio.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ def __init__(self, tr):
99

1010
async def portfolio_loop(self):
1111
recv = 0
12-
# await self.tr.portfolio()
13-
# recv += 1
1412
await self.tr.compact_portfolio()
1513
recv += 1
1614
await self.tr.cash()
1715
recv += 1
18-
# await self.tr.available_cash_for_payout()
19-
# recv += 1
2016

2117
while recv > 0:
2218
subscription_id, subscription, response = await self.tr.recv()
@@ -30,9 +26,6 @@ async def portfolio_loop(self):
3026
elif subscription["type"] == "cash":
3127
recv -= 1
3228
self.cash = response
33-
# elif subscription['type'] == 'availableCashForPayout':
34-
# recv -= 1
35-
# self.payoutCash = response
3629
else:
3730
print(f"unmatched subscription of type '{subscription['type']}':\n{preview(response)}")
3831

@@ -51,8 +44,7 @@ async def portfolio_loop(self):
5144

5245
if subscription["type"] == "instrument":
5346
await self.tr.unsubscribe(subscription_id)
54-
pos = subscriptions[subscription_id]
55-
subscriptions.pop(subscription_id, None)
47+
pos = subscriptions.pop(subscription_id)
5648
pos["name"] = response["shortName"]
5749
pos["exchangeIds"] = response["exchangeIds"]
5850
else:
@@ -73,8 +65,7 @@ async def portfolio_loop(self):
7365

7466
if subscription["type"] == "ticker":
7567
await self.tr.unsubscribe(subscription_id)
76-
pos = subscriptions[subscription_id]
77-
subscriptions.pop(subscription_id, None)
68+
pos = subscriptions.pop(subscription_id)
7869
pos["netValue"] = float(response["last"]["price"]) * float(pos["netSize"])
7970
else:
8071
print(f"unmatched subscription of type '{subscription['type']}':\n{preview(response)}")
@@ -94,18 +85,13 @@ def portfolio_to_csv(self, output_path):
9485
print(f"Wrote {len(csv_lines) + 1} lines to {output_path}")
9586

9687
def overview(self):
97-
# for x in ['netValue', 'unrealisedProfit', 'unrealisedProfitPercent', 'unrealisedCost']:
98-
# print(f'{x:24}: {self.portfolio[x]:>10.2f}')
99-
# print()
100-
10188
print(
10289
"Name ISIN avgCost * quantity = buyCost -> netValue diff %-diff"
10390
)
10491
totalBuyCost = 0.0
10592
totalNetValue = 0.0
10693
positions = self.portfolio["positions"]
10794
for pos in sorted(positions, key=lambda x: x["netSize"], reverse=True):
108-
# pos['netValue'] = 0 # TODO: Update the value from each Stock request
10995
buyCost = float(pos["averageBuyIn"]) * float(pos["netSize"])
11096
diff = float(pos["netValue"]) - buyCost
11197
if buyCost == 0:

0 commit comments

Comments
 (0)