Skip to content

Commit

Permalink
Merge pull request #65 from Katzmann1983/fixing_issue_64
Browse files Browse the repository at this point in the history
Fixing issue 64
  • Loading branch information
Katzmann1983 authored Jun 25, 2024
2 parents 7b96f8b + f67f7c7 commit 52f00d5
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pytr/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,44 @@ async def portfolio_loop(self):

await self.tr.unsubscribe(subscription_id)

# Populate netValue for each ISIN
positions = self.portfolio['positions']
# Populate name for each ISIN
subscriptions = {}
positions = self.portfolio['positions']
for pos in sorted(positions, key=lambda x: x['netSize'], reverse=True):
isin = pos['instrumentId']
# subscription_id = await self.tr.instrument_details(pos['instrumentId'])
subscription_id = await self.tr.ticker(isin, exchange='LSX')
subscription_id = await self.tr.instrument_details(pos['instrumentId'])
subscriptions[subscription_id] = pos

while len(subscriptions) > 0:
subscription_id, subscription, response = await self.tr.recv()

if subscription['type'] == 'ticker':
if subscription['type'] == 'instrument':
await self.tr.unsubscribe(subscription_id)
pos = subscriptions[subscription_id]
subscriptions.pop(subscription_id, None)
pos['netValue'] = float(response['last']['price']) * float(pos['netSize'])
pos['name'] = response['shortName']
pos['exchangeIds'] = response['exchangeIds']
else:
print(f"unmatched subscription of type '{subscription['type']}':\n{preview(response)}")

# Populate name for each ISIN
# Populate netValue for each ISIN
subscriptions = {}
for pos in sorted(positions, key=lambda x: x['netSize'], reverse=True):
isin = pos['instrumentId']
subscription_id = await self.tr.instrument_details(pos['instrumentId'])
subscriptions[subscription_id] = pos
if len(pos['exchangeIds']) > 0:
subscription_id = await self.tr.ticker(isin, exchange=pos['exchangeIds'][0])
subscriptions[subscription_id] = pos
else:
pos['netValue'] = float(pos['averageBuyIn'] )* float(pos['netSize'])

while len(subscriptions) > 0:
subscription_id, subscription, response = await self.tr.recv()

if subscription['type'] == 'instrument':
if subscription['type'] == 'ticker':
await self.tr.unsubscribe(subscription_id)
pos = subscriptions[subscription_id]
subscriptions.pop(subscription_id, None)
pos['name'] = response['shortName']
pos['netValue'] = float(response['last']['price']) * float(pos['netSize'])
else:
print(f"unmatched subscription of type '{subscription['type']}':\n{preview(response)}")

Expand Down

0 comments on commit 52f00d5

Please sign in to comment.