@@ -9,14 +9,10 @@ def __init__(self, tr):
9
9
10
10
async def portfolio_loop (self ):
11
11
recv = 0
12
- # await self.tr.portfolio()
13
- # recv += 1
14
12
await self .tr .compact_portfolio ()
15
13
recv += 1
16
14
await self .tr .cash ()
17
15
recv += 1
18
- # await self.tr.available_cash_for_payout()
19
- # recv += 1
20
16
21
17
while recv > 0 :
22
18
subscription_id , subscription , response = await self .tr .recv ()
@@ -30,9 +26,6 @@ async def portfolio_loop(self):
30
26
elif subscription ["type" ] == "cash" :
31
27
recv -= 1
32
28
self .cash = response
33
- # elif subscription['type'] == 'availableCashForPayout':
34
- # recv -= 1
35
- # self.payoutCash = response
36
29
else :
37
30
print (f"unmatched subscription of type '{ subscription ['type' ]} ':\n { preview (response )} " )
38
31
@@ -51,8 +44,7 @@ async def portfolio_loop(self):
51
44
52
45
if subscription ["type" ] == "instrument" :
53
46
await self .tr .unsubscribe (subscription_id )
54
- pos = subscriptions [subscription_id ]
55
- subscriptions .pop (subscription_id , None )
47
+ pos = subscriptions .pop (subscription_id )
56
48
pos ["name" ] = response ["shortName" ]
57
49
pos ["exchangeIds" ] = response ["exchangeIds" ]
58
50
else :
@@ -73,8 +65,7 @@ async def portfolio_loop(self):
73
65
74
66
if subscription ["type" ] == "ticker" :
75
67
await self .tr .unsubscribe (subscription_id )
76
- pos = subscriptions [subscription_id ]
77
- subscriptions .pop (subscription_id , None )
68
+ pos = subscriptions .pop (subscription_id )
78
69
pos ["netValue" ] = float (response ["last" ]["price" ]) * float (pos ["netSize" ])
79
70
else :
80
71
print (f"unmatched subscription of type '{ subscription ['type' ]} ':\n { preview (response )} " )
@@ -94,18 +85,13 @@ def portfolio_to_csv(self, output_path):
94
85
print (f"Wrote { len (csv_lines ) + 1 } lines to { output_path } " )
95
86
96
87
def overview (self ):
97
- # for x in ['netValue', 'unrealisedProfit', 'unrealisedProfitPercent', 'unrealisedCost']:
98
- # print(f'{x:24}: {self.portfolio[x]:>10.2f}')
99
- # print()
100
-
101
88
print (
102
89
"Name ISIN avgCost * quantity = buyCost -> netValue diff %-diff"
103
90
)
104
91
totalBuyCost = 0.0
105
92
totalNetValue = 0.0
106
93
positions = self .portfolio ["positions" ]
107
94
for pos in sorted (positions , key = lambda x : x ["netSize" ], reverse = True ):
108
- # pos['netValue'] = 0 # TODO: Update the value from each Stock request
109
95
buyCost = float (pos ["averageBuyIn" ]) * float (pos ["netSize" ])
110
96
diff = float (pos ["netValue" ]) - buyCost
111
97
if buyCost == 0 :
0 commit comments