def stock_sort_key(item, max_amount):
    """Sort by increasing amount but ensure that negative amounts are
    sorted first.  max_amount is the maximum amount found in the stock.

    """
    amount = item['amount']
    if amount < 0:
        amount = max_amount - amount
    return -amount
