Python extract information from list of objects

Viewed 39

The following is a list of 'Position' objects.

[Position(account='U3953931', contract=Forex('AUDUSD', conId=14433401, localSymbol='AUD.USD', tradingClass='AUD.USD'), position=100.0, avgCost=0.70995),
 Position(account='U3953931', contract=Stock(conId=211651685, symbol='URA', exchange='ARCA', currency='USD', localSymbol='URA', tradingClass='URA'), position=-20.0, avgCost=23.06155705)]

How can I extract the -20.0 value given that I'm looking for the position within the URA symbol?

I managed to make this:

positions[1][2]   

That returns the -20.0

1 Answers

probably not very elegant but this works:

for i in range(0, len(positions)):
    if positions[i].contract.symbol == Stock_Symbol:
        print(positions[i].position)  
Related