I would like to know how many shares I have of a specific position using ib_insync. Using solely the ib.positions() function gives me a [...] with much more information that just the number of shares.
I found some code on the internet:
from random import choice
pos = ib.positions()
p = choice(pos)
return p.position`
this code works for me, but I presume this is only because I have just one stock in my portfolio. Thank you for sharing what code I can use to get the number of shares in my portfolio.
ib.positions() will give you a list so you can use
for
to show every position of yours.