I think the way it works in the real life stock market is that your broker gets a commission for doing her job which is to handle the matching. So if I want to sell 8763 shares of IBM, it's pretty unlikely that there will be someone wanting to buy 8763 shares so she sells 4000 to one person, 3000 to another person, and 1763 to a third person. (The third person really wanted to buy 2000 but they take what they can get).
Actually, I think there is another factor which is that the broker has a pool of stocks. When I want to sell 8763 shares of IBM and they have a buyer for 8000 shares, they buy the whole amount from me and keep 763 for themselves which they keep around for a week or two until they find a buyer. Running this pool (or buffer) is a little risky for the broker but (a) they might make a few bucks on the stocks in the pool, (b) they might make more $$ off my commission than the amount they risk losing by sitting on 763 shares of IBM for a few weeks.
But back to your question: If I want to sell 8763 shares of www.yahoo.com, I don't care if you sell that to one person, three people, or 8763 people who all wanted one share each. I'm not paying you my $1.00 selling commission based on the number of people you deliver the shares to. (I'm certainly not paying you $8763 in commissions if you deliver my shares to 8763 people!) The buyer is paying their dollar to get X number of shares - they don't care if it comes from one person or six. They just want to pay their dollar and get their shares.
So my suggestion is that you find a way programatically to do your best to enable as many trades as possible to happen as often as possible so that you can pick up a dollar from each seller and a dollar from each buyer as often as possible. More trades is more money for you!
Sometimes you will have one seller and multiple buyers - sometimes you will have multiple sellers dumping shares that all go to one buyer. You might be able to accomplish this by "pooling" shares so that buyers and sellers find it fairly easy to make their transaction happen.
Of course, let's say that www.yahoo.com is selling for $9 and a seller comes along and asks $80 per share for his 1000 shares. You aren't obligated to buy his shares for that price. You'll need some sort of computer logic that says, "his asking price is close enough to the going rate that I'm willing to buy them at that rate and keep some in the pool for awhile because if I can't sell them today, I'll be able to sell them out of the pool tomorrow." Likewise, if someone wants to buy shares for $2 and you have a bunch in the pool, you aren't obligated to sell them if the going rate is $9.