On the other hand, with a leveraged position in the market, if the value of your portfolio falls to a certain level, you either need to post more capital or your position is liquidated. If you are capital constrained, there is literally nothing you can do in the case of a leveraged position - your broker forces you out.
Regardless, if you keep making your payments, there is no way for a bank to force you out of your mortgage or call for additional capital due to a decline in value. This is the big difference.
it's the same coin, you're just looking at it from a different angle. The timeframes are certainly different between foreclosure and margin calls, but the concept is the same - the lender sees you as more risky than they originally intended, and chooses to liquidate you. In a foreclosure, you "prevent it" by constantly paying the interest. In a margin call, you are not paying until you hit the drop in valuation, and you have to pay to top it back up.