Thanks.
If I have a 500-520 call spread and they expire when the SP is $580. Do I just get $2,000 credited to my account and pay tax on that $2000? Or am I going to have to sell my 100 shares at 520, creating a bigger taxable event, and buy 100 shares at 500? If the latter, what happens first? The sale or the purchase? If the purchase happens first and I don't have enough money to exercise, what happens then?
Assuming this was a bull spread, (you bought the 500's and sold the 520's), then extremely, extremely likely but technically not guaranteed (see below), the 520 would be assigned to you so you will sell 100 shares to whoever bought the 520 in exchange for $52,000. For tax treatment, if you didn't take any other steps your broker will usually have you set to FIFO (first-in-first-out) trading (but check your broker, it could be different) meaning your longest held shares would be the ones sold. The premium you received for selling the 520 leg would be subtracted from the cost-basis of of those shares and you will owe tax (either long-term or short depending on when they were bought) on the gain for selling them for $52,000. Then your 500's would be exercised and you will buy 100 shares for $50,000 and your cost basis for those shares will be $50,000 + whatever price you paid for the 500 leg.
Since the buying and selling happened at the same time (there is no "first", the cash from the assignment will be used to pay for the exercise), it might well look like you just got $2,000 credited to your account (unless you check your transaction history where you will see each leg sparately). But tax wise you'd have the above case unless you instructed your broker to use LIFO tax method, in which case it would be a short-term gain (same as ordinary income) on $2,000.
If by some miracle, some fool instructed their broker to not exercise the ITM option and you were the lucky person who was randomly not-assigned that non-exercise then that leg expires worthless and you don't sell any shares for $520. But you are still on the hook for buying the exercise of your $500 leg, so if you don't have $50,000 in cash+margin in your account you will get a margin call. What happens then depends on your broker and maybe what the opening price on Monday is. I may have made this sound bad, but realistically you won a $6,000 bonus unless the stock absolutely tanked Monday morning in which case you may lose big time, since you will be long 100 more (tanking) shares which you may or may not have been able to pay for.