This function is developed over AliceBlue Official Python library.
def get_mtm(portfolio): mtm = 0 for j in range(len(portfolio)): mtm = mtm + float(portfolio[j]['MtoM']) return mtm mtm = get_mtm(alice.get_netwise_positions())
Note that, this sums the net mtm from netwise positions. This function is and will be highly used for intraday traders for their risk management.
Also note, there can be an error if it is scanned over accounts with no positions. I did not manage to test that condition because all accounts of mine have positions.
except and solve it in that case. If you do, share updated code.