Here is an example where we are assuming the legs,
for leg in position.legs:
# Extract order parameters
symbol = leg.symbol
orderSide = leg.orderSide
# orderQuantity = leg.orderQuantity
# TODO: I'm not sure about this order side check here
if orderSide != 0:
targets.append(PortfolioTarget(symbol, orderSide))
Same thing is in positionPnl calculation in the position class, which we use extensively in monitor.