Check out https://www.npmjs.com/package/metaapi.cloud-sdk as well. This is an SDK for the MetaApi service https://metaapi.cloud. It essentially acts as a bridge for communicating with MetaTrader brokers.
I’m by no means an “expert”, though I’ve spent a fair amount of time studying this and writing quant software.
There are three important starting places to study this question, in this order:
1 dark pools ( see https://squeezemetrics.com/monitor/dix )
40% to 60% of large trades are now done in dark pools.
2 the “closing auction” at 4pm
3 the “on balance ...
Let me try to answer. I have worked at an Algo-trading firm that trades equities and have seen how trades are executed at the order book level. Let's say the price of the stock is 100 (last traded price). Let's say the order book is as follows:
Bids: Bid1 = 99 (size = 10,000), Bid2 = 98 (size = 20,000), Bid3 = 97 (size = 25,000), Bid4 = 96 (size = 30,000), ...