From Haggling to Algorithms
A market is simply a place where people exchange things. Goods for money, promises for future goods, risks for security. But behind this simple act lies a sprawling architecture - an emergent machine of rules, signals, incentives, and delays. Why do prices fluctuate? How are trades matched? Who ensures that agreements are kept? These are not philosophical questions. They are mechanical ones. And like any complex mechanism, the financial market has evolved piece by piece, each part introduced to solve a problem, reduce friction, or create new possibility. What follows is a journey from barter to matching engines, from shouting traders to silent algorithms - an attempt to understand how markets for securities actually work. Not in metaphor, but in machinery.
Imagine a bustling village square. Farmers and artisans bring their produce and crafts. Buyers wander around, looking for what they need. Transactions are direct, face-to-face. Buyers haggle with sellers over the price and quantity of the goods, e.g. saying "I'll buy 5 units at 3\$ each", or "I'll sell you 4 units at 5\$ each". In effect these are primitive bid and ask signals. For each good there are multiple sellers scattered throughout the market, and each may ask a different price. Whenever a buyer's bid price is higher than the seller's ask price, a transaction happens. Other buyers and sellers do not immediately get notified about the transaction. It takes effort for a consumer to go through all sellers, and to find the lowest asking price. Similarly, it takes effort by a seller to find out how other sellers are pricing the good. Such market frictions, like search costs, or some consumers not searching enough, introduce price dispersion and general heterogeneity in the market matching process.
A simple idea to reduce search costs is to get all sellers of a particular good in a single small area. In that way neither sellers, nor buyers, have to wander too much to gauge the supply/demand. This is the basic idea of an exchange – a central meeting place. However, with everyone in the same place it gets crowded. Sellers shout out their asks, and buyers their bids. It's hard to hear the best prices. To address this, a clever person, a market registrar, decides to hold up a big white board, which everyone could see, and to write on it the sorted asking and bidding prices at any given time. Specifically, the highest bidding price is put next to the lowest asking price. Sellers communicate their asking prices to the market registrar and buyers their bid prices. Everyone can see the current lowest price by any of the sellers. This is the beginning of price discovery based on collective supply and demand. The registrar's board contains a written visible account of how many total units would be bought/sold at any given price, e.g. 1 unit would be sold at a price of 5\$, 2 units at 6\$, 10 units at 8\$ (across say 4 sellers), and so on. This becomes a primitive order book. When a deal happens, the registrar strikes through the line in the order book corresponding to the price of the transaction.
The order book model of the market is one way in which transactions happen. Another viable approach is through auctions. In any case, when a bid and an ask match, the registrar reveals to the buyer the particular seller that will sell the goods. It is up to them to meet and finish the transaction. In some cases though, one of the parties may try to swindle the other one, for example by not paying, or by selling lower quality goods. To avoid this, another innovation is needed. Another person, called a market custodian, trusted by everyone, is designated to complete the deal. When a deal is struck, the seller gives their goods to the custodian, and the buyer gives their payment. Once both are confirmed, the Custodian releases the goods to the buyer and the money to the seller, perhaps at the end of the market day. This introduces the concept of clearing (confirming the trade and obligations) and settlement (actual exchange of goods and money). This drastically reduces counterparty risk – the risk that the other side won't fulfill their part of the bargain. It is the precursor to a clearing house or Central Counterparty (CCP).
Not too bad. However, consider that if there are no buyers or no sellers, there would be no trades. In these cases the entire market could freeze to a halt, or prices can jump up and down tremendously. It is profitable for some people to simply always be ready to buy or sell goods, so that trades can still happen and prices remain within a constant range, ceteris paribus. These participants become market makers. They place both buy and sell orders, quote both a bid and an ask, and are looking to make a profit off of the spread. By standing ready to always buy or sell, they provide precious liquidity in the market. The existence of such market makers is beneficial to everybody. Since the people running the market provide a service to everybody else, they take small fees from every transaction. Market makers could be rewarded by having lower fees in exchange of the liquidity they add.
Good, at this stage the market has a centralized location, a useful price discovery mechanism, clearing and settlement facilities, and high liquidity. It grows large, attracting people. Let's think of company stocks as exemplary goods, in which case the market becomes an exchange, where traders meet to buy and sell firm stocks. Naturally, to scale better with the growing interest, the services of the registrar are digitalized and are substituted by electronic systems that keep track of the best bids and asks. Traders start submitting their desired stock prices and quantities (volumes) electronically. The exchange starts broadcasting the prices to nearby towns, which increases its visibility. The market makers are also substituted by algorithms ready to buy and sell.
Electronic algorithms require specifying clear rules to execute. Electronic order execution follows very clearly defined steps. For example, according to price time priority logic, whenever a buy order at the market rate (whichever price it is) comes in, the sell order with the lowest ask price is selected. If there are multiple orders at that price, the earliest one is selected. If the sell order fulfills the entire volume of the buy order, it is deleted from the order book, otherwise, however many units are desired to be bought, that many are sold, and the rest are modified into a new sell order at the same price. If liquidity is thin, the buy order could eat through multiple price levels, which is called slippage. Electronic matching engines allow for the accurate execution of sophisticated new types of orders, beyond market, which executes immediately at the best available price, and limit ones, which execute whenever a price is reached. These include Fill-Or-Kill, Immediate-Or-Cancel, stop orders which activate depending on a condition, trailing limits which follow the price within a range, etc. Multiple kinds really.
Note that market orders, to be executed immediately, most often hit the market maker rates. Whenever a market order is executed, or a limit order for buying above the minimum ask is fulfilled, the price in the last transaction changes. This is taken to be the current price of the asset. The price fluctuates simply because different trades happen at different prices. Big sell-offs tank the price because they overwhelm the bid side of the order book - starting from the best bid, it takes multiple bid orders to satisfy the volume of the large sell, and the price naturally drops.
As we said, the price is actually the last transacted price. So if, say, the best ask is for 1 unit @10\$, and the second best is for 1 unit @50\$, a market buy order for 2 units will hit both of these and will push the price up to 50\$. The average buying price will be 30\$, but the new price will be 50\$. So huge price changes are possible if the bid/ask structures are sparse. Apart from the last transacted price in any given time the market can be characterized by the order book. It shows the cumulative supply and demand at different price levels. A buy wall (very sharply increasing bid volume at lower prices) represents "support". Likewise, a sell wall (sharply increasing ask volume at higher prices) indicates "resistance". These support and resistance walls could easily change by the whims of the traders. Fake walls could form as traders place spoof orders only to cancel them later. Alternatively, once breached, support can turn into resistance and vice versa (classic flip).
The order book, along with the liquidity depth at every price, is a treasure trove of information for interpreting the sentiment of the market participants. Exchanges own this data, and they sell it. They do not give it away for free. Even the last traded price is considered proprietary market data. Unless you, as an exchange participant, or your broker pay for it, exchanges legally must delay it, usually by 15 minutes. Luckily, one can typically see real-time order books in cryptoexchanges such as Bitstamp, where it's shown for free. And by the heavens, it's beautiful. You can see how the supply and demand curves shift, how market orders are executed, how profit is made in front of your very own eyes. You can feel the animal spirits that drive the market. It's wild.
Now that most of the exchange services are handled by computer programs, exchanges work more accurately and scale to more participants. Their information is easily disseminated to other parts of the world. This creates possibilities for arbitrage. If the best ask in one exchange is strictly lower than the best bid in another exchange, one can buy from the first one and immediately sell on the second one, making a guaranteed profit. If many people do this, they will bid the price up in the first exchange and push it down in the second one, roughly until the profit opportunity disappears. The efficient market hypothesis says that you can't consistently beat the market, because all available information is already reflected in asset prices. Yet, the market is efficient not by design, but rather by battle. Pockets of arbitrage opportunities do exist, and it is competition that closes them. Arbitrage disappears only after someone harvests its profit. The profit isn’t hypothetical - it’s the fuel that removes the mispricing. Likewise, someone's profit is another person's loss, at least in the short run game of trading (not investing). Thus, even the dynamics of returning to equilibrium can create winners and losers.
Another important service that has developed is that of brokers, which mediate the relations between retail traders and the exchanges. Exchanges are highly regulated and it is easier for the regulatory bodies to enforce stringent rules on the brokers instead of directly on the individual traders. This includes for example Know Your Customer checks. Another reason for the existence of brokers is that they are more operationally efficient because they can batch the orders from multiple traders and route them together to the exchange. Or they can even aggregate the order books from different exchanges and provide it to its clients (though this costs a lot). Naturally, brokers facilitate trading and earn commission in doing so. It is common for stock exchanges to only allow institutional traders and brokers to be members. Crypto exchanges though typically allow individual traders. There you create an account directly with the exchange and any fees you pay go directly towards the exchange, not the middleman.
Another crucial service enabled by brokers is margin trading. The individual trader takes a loan from the broker and uses the money to buy more securities than he can afford without the loan. Naturally, this allows him to have bigger profits, but also bigger losses. A 50:1 leverage implies that one can realize 50 times bigger profit but only a 2% drop in the price is enough to wipe out the borrower's initial funds. The loan is not free - it is required to pay interest on it. Also, the securities purchased in the account, along with any cash, serve as collateral for the loan. If the current value of the assets drops below some pre-agreed level, such that the broker may not recover the initial value of the loan, they would issue a margin call, prompting the trader to immediately deposit more cash. If this is not enough, the broker could immediately liquidate the trader's assets, selling them off, in which case the trader loses everything and may still even end up having to pay any remaining differences and interest. Margin trading is powerful but dangerous.
As exchanges become more sophisticated, the possibility for trading complicated securities emerges. Instead of trading stocks and commodities, one can trade contracts based on them - these are called derivatives. Suppose we have the price of some bushels of corn. Naturally, this is a random variable and it is uncertain what value it will take in the future. Yet, people can enter contracts based on it - e.g. "I commit to buy 100 bushels of corn 4 months from today, at a price of 4.5\$ each". This is a simple contract whose value (the consumer surplus) is also a random variable, because of the randomness of the underlying asset. If corn costs at that day more than 4.5\$, then the contract is profitable, otherwise it's not. So how should this contract itself be priced in the market? How much are you willing to pay to have this contract? Futures like this are easy to price, while options not so much. In any case, derivative exchanges are all about pricing different kinds of functions of the underlying assets.
Finally, to scale up and squeeze out any profit opportunities, almost all operational trading aspects become electronic. Exchanges can offer APIs for programmatic management of traders' accounts. With the ability to submit buy or sell orders, algorithms can substitute pretty much the entire human's decision making process, giving rise to algorithmic trading. For lowest latency, algorithmic traders often use co-location (placing their servers in the same data center as the exchange's matching engine) and Direct Market Access (DMA) provided by brokers. The algorithms responsible for deciding when to buy and sell could be rule-based (e.g. based on moving averages) or learning-based (based on machine learning). Finally, exciting new tools are agentic systems, LLMs to interpret news and world events, or deep reinforcement learning for adapting to the changing stochasticity in the market. Whether all of these work reliably is an altogether different question.
This completes our brief, simplified overview of how markets for securities work. As we saw, the development has been one of overwhelming digitalization and automation. Approximately 60% to 75% of all trades on U.S. equity markets, including the NASDAQ, are executed by algorithmic trading systems rather than humans. Naturally, the human hand was never built for this tempo. Algorithms do not sweat or doubt. Out there, in the humming data centers, they trade in their dreams and the tremors of digital intention slice through time. Signals and decisions. Unhuman.