The only thing you need to make a realistic market is to have stockpiles on the resources that the market can hold.
I would like to see a stockpile too; in fact, I suggest the very thing in a different thread. But this what I consider yet another game mechanic that makes the market
act like a real market but isn't a complete simulation. For example, who exactly is "the Market"? Who runs it, who collects that 30% market fee and where does it go? Which isn't to say I would be dissatisfied with this solution, but I would be dissatisfied with this as a simulation. See below.
A big problem though is the fact that resources can be bought and sold in bulk and this isn't taken into account when determining prices. There has to be an algorithm that can predict how purchases in the market will affect the amount that's in storage and adjust the prices accordingly.
I agree. This can and should be done.
The civilians in Stellaris only really deals with consumer goods and food so I see no reason why they should partake in the market, unless you're meaning to add actual corporations which produce resources for profit.
In case you aren't familiar with PDX's Victoria series, I'll summarize it. If you are, I'll leave a reminder.
Money never disappears; it always circulates and new money only enters through gold/silver mines. All resources traded always go to a recipient, until they are consumed. Raw resources are produced in farms and mines, then sold on the market. The money earned goes to the aristocrats who own the farms/mines and the laborers employed. The raw resources are either bought by artisans or factories and converted to refined goods (also sold on the market), or are bought by pops for consumption. Any amount not bought is destroyed (and the pop loses revenue). Each pop has essential needs, day-to-day needs, and luxury needs, and the amount they can (afford to) obtain determines their happiness. The government taxes each pop's wages or profits. Middle-class pops might invest their savings in the national bank. When governments (the player) take loans, they come from the national banks. When governments default on loans, the national bank loses money and thus the pops who invested lose money, making them poorer.
TLDR every resource is produced somewhere and goes somewhere for consumption; all money goes to someone and comes from someone. So I ask again, when I sell minerals to the market, who takes the minerals besides "the Market"?
Unless you want the only participants of the market to be the galactic governments, with supply and demand determined only by the players' and AI's supply and demand. In that case, when I sell minerals, they will sit in the stockpile until a player / AI empire buys it. But can you foresee how flat that system might become? What happens when there are only two empires left in the game? The market would just be a 30% more expensive replacement for the diplomacy screen. What happens if all empires tend to sell only certain types of goods (for example, worker-produced resources) and buys only another type (say, specialist-produced goods)? The price of some goods will plummet and others will skyrocket and if the pattern persists the market will be useless as each empire turns to self-reliance, producing what they need to fill the deficit (as we did pre-2.2).