Run the code below:
print(api.list_positions())
How can we format it into a table format? Thanks a lot!
return the following:
[Position({ ‘asset_class’: ‘us_equity’,
‘asset_id’: ‘fc8d427a-13df-4c7b-a26d-480079fc5ae8’,
‘avg_entry_price’: ‘13.68’,
‘change_today’: ‘0.3344370860927152’,
‘cost_basis’: ‘2995.92’,
‘current_price’: ‘12.09’,
‘exchange’: ‘NASDAQ’,
‘lastday_price’: ‘9.06’,
‘market_value’: ‘2647.71’,
‘qty’: ‘219’,
‘side’: ‘long’,
‘symbol’: ‘VVPR’,
Shlomik
September 7, 2020, 10:14am
2
Hi, what do you mean table? you have a list of positions. how would you like it to be?
Hi Shlomik
It is like excel which is more easy to read.
Is it a code to do it easily .
Thanks
Shlomik
September 7, 2020, 8:56pm
4
just search in google “python print list as table” and you will get many results. here’s one: https://stackoverflow.com/questions/9535954/printing-lists-as-tabular-data
Thanks and found it
positions = api.list_positions()
positions = pd.DataFrame({
'ticker': [x.symbol for x in positions],
'qty': [x.qty for x in positions],
'Profit' : [x.unrealized_intraday_pl for x in positions]
})
print(positions)
1 Like