Loop through position list (Python)

I wish to loop through my position list, to get the symbols in it. How do I do that?

for exampl:

api.list_positions()[0]

would return:

Position({ ‘asset_class’: ‘us_equity’,
‘asset_id’: ‘f30d734c-2806-4d0d-b145-f9fade61432b’,
‘asset_marginable’: True,
‘avg_entry_price’: ‘2615.88’,
‘change_today’: ‘0.0017749437658003’,
‘cost_basis’: ‘18311.16’,
‘current_price’: ‘3019.53’,
‘exchange’: ‘NASDAQ’,
‘lastday_price’: ‘3014.18’,
‘market_value’: ‘21136.71’,
‘qty’: ‘7’,
‘side’: ‘long’,
‘symbol’: ‘GOOG’,
‘unrealized_intraday_pl’: ‘37.45’,
‘unrealized_intraday_plpc’: ‘0.0017749437658003’,
‘unrealized_pl’: ‘2825.55’,
‘unrealized_plpc’: ‘0.1543075370429836’})


now I would like to return only:
‘symbol’: ‘GOOG’

how do I go about it?

use for loop and return symbol
my_positions = api.list_positions()
for position in my_positions:
print(position.symbol,position.qty, position.market_value)

2 Likes