Pretty basic question. Note, I’m working in Python (still learning!).
I’m trying to create a list with all the symbols I currently have positions on so I can check against it before putting in new positions.
For whatever reason, Alpaca methods get_position() or list_positions() return a strange object simply called “Position” that looks like a dictionary.
Here is the position return for my 32 AAPL stocks:
Position({ 'asset_class': 'us_equity',
'asset_id': 'b0b6dd9d-8b9b-48a9-ba46-b9d54906e415',
'avg_entry_price': '118.03625',
'change_today': '-0.0001694484453105',
'cost_basis': '3777.16',
'current_price': '118.01',
'exchange': 'NASDAQ',
'lastday_price': '118.03',
'market_value': '3776.32',
'qty': '32',
'side': 'long',
'symbol': 'AAPL',
'unrealized_intraday_pl': '-0.84',
'unrealized_intraday_plpc': '-0.0002223893083693',
'unrealized_pl': '-0.84',
'unrealized_plpc': '-0.0002223893083693'})
However, you can’t get items from it very easily (ideally I would just use list_positions(stock)[‘symbol’]). How can I cleanly pull information out of this object?
Edit: I managed to do it when I realized get_position() on a stock you don’t have returns an error, so I just used a try: statement to determine whether or not I already had a position on that stock. I’d still like to know the answer if possible, though.