Parsing list of objects

Viewed 35

I am pulling in a list of something (I think it's objects?) and I'm trying to parse. How do I navigate the categories? For example, if I type the number of the item in this list (I've saved variable as "posi") as posi[3] I will get the fourth record as expected. However, when I try to access the various records i.e. 'cost basis' I get an error.

[Position({   'asset_class': 'us_equity',
     'asset_id': 'e044c486-f84b-45e1-a8d7-9795c7cfe85c',
     'asset_marginable': False,
     'avg_entry_price': '4.9372',
     'change_today': '0.0159090909090909',
     'cost_basis': '4.9372',
     'current_price': '4.47',
     'exchange': 'NASDAQ',
     'lastday_price': '4.4',
     'market_value': '4.47',
     'qty': '1',
     'qty_available': '1',
     'side': 'long',
     'symbol': 'TKNO',
     'unrealized_intraday_pl': '0.07',
     'unrealized_intraday_plpc': '0.0159090909090909',
     'unrealized_pl': '-0.4672',
     'unrealized_plpc': '-0.0946285343919631'}),
 Position({   'asset_class': 'us_equity',
     'asset_id': 'f0b52686-5edb-49ac-b81d-cb4668ceefcc',
     'asset_marginable': False,
     'avg_entry_price': '4.1',
     'change_today': '0.1552631578947368',
     'cost_basis': '4.1',
     'current_price': '4.39',
     'exchange': 'NASDAQ',
     'lastday_price': '3.8',
     'market_value': '4.39',
     'qty': '1',
     'qty_available': '1',
     'side': 'long',
     'symbol': 'TERN',
     'unrealized_intraday_pl': '0.59',
     'unrealized_intraday_plpc': '0.1552631578947368',
     'unrealized_pl': '0.29',
     'unrealized_plpc': '0.0707317073170732'}),

When I look at posi as a type it is a list. When I look at the record i.e. posi[3] it of type alpaca_trade_api.entity.Position

How do I access the records?

0 Answers
Related