In a
stock exchange, each trade takes place between two counterparties: the
buyer and the
seller. Under
open outcry, the counterparties are represented by individual
traders in the
dealing pit wearing coloured jackets to indicate whom they represent.
Each trader completes one half of a trading slip, and the slips are matched up, under a process of trade registration. Under electronic trading, the same process happens, but it is invisible; the traders do not know, and do not need to know who the other counterparty is.
Once the trades are registered, the clearing house becomes involved, and becomes counterparty to each of the traders. It is the clearing house's job to handle the cash side of the transaction, i.e. settlement, reimbursement and margin payments.
The same term, counterparty, is used in a bank, in the same way, when referring to OTC trades.