For performance, change the body of this for loop to:

    if pos.amount != 0:
        positions.append(pos.to_dict())