I am not an economist, so my question could be stupid for you. However, I need to understand how market order works and which variables plays in a trade. For example: let us suppose I am a trader and I have at the time t=0 a sum of cash and stocks. How do they change? Do I need consider intraday and daily trades? And what about the spread between bids and asks?
I am a financial economist, so I will attempt to answer what I think you are asking. A market order isn't one concept, it's many. Each place that accepts trades operationalizes it differently. It also depends upon whether it is a small order or a large order.
For a small order, the order result will clear at the bid if it is a sell order at the bid and at the ask if it is a buy order. Only in that case will the outcome be the same everywhere.
For a large order, it depends upon where the security trades at and it can depend upon the internal policies of which broker-dealer you use. For example, if you place a large market order on a stock that trades on the NYSE then what you are actually doing is instructing your broker to go to the floor of the exchange, to a place called the "post," and continue to bid until you are the high bidder, if buying or the low bidder if selling, until your order is filled.
On the other hand, a large market order on the NASDAQ will be filled up to the stated size limit. After that, it depends upon a number of things. For example, if there are multiple market makers then decisions to fill or not fill is made by each maker depending on orders they have, their inventory needs and what risks they will take and for what fee structure. Because a market order essentially says "I will pay any price," the makers have liberal pricing powers on large market orders. Also, the processing broker can sometimes cross the order with other orders they have pending from their own customers and so it never really makes it to the market itself, other than for record keeping purposes.
Outside of this, there are order crossing services in what have been nicknamed "dark pools," which are available to the largest financial institutions but not to ordinary traders. Different rules are in use for things other than stocks and for stocks traded in non-US exchanges.
To provide an example, imagine you own $\$1,000$ and also own 100 shares of ABC which is currently trading at 9.90 bid and 10.10 ask. It trades on the NYSE. A decision to sell 100 shares at market would increase cash to $\$1,990$ and reduce shares to zero. Since you may or may not be permitted to short sell the stock depending on your contract with your broker and the availability of shares to borrow, a decision to short sell 100 more shares of ABC would increase cash by the new bid, which for our purposes will be 9.85 per share, for $985 and add one hundred shares on the short side in the margin account. The cash will also be segregated and held as collateral on the long side of the margin account.
A large market order for a thinly traded stock could take a month or more to fill. For a "pink sheets" stock it could take years. For a heavily traded stock, it could take less than a second.
It is important to note that the recording of a trade for customer accounting purposes may not match market records. Consider a person who sold 100 shares of ABC for 9.65 per share. They record an increase in cash of $965 and a decrease in shares by one hundred shares. The "tape" may not record it this way if it is part of a large buy order. In that case, if the weighted average price was 10.10 then the market would see one large order for 10.10 per share, though it may also be the case that nobody actually received that amount of money. It is also the case that the time of order completion will not match.
I see two general questions here:
How does a market order work?
When you submit a market order, you ask your broker to buy or sell a security right now, at the best available price. You control the timing but not the execution price. This is as opposed to a limit order, in which you ask the broker to put out a for-sale (or want-to-buy) notice at a given price. Your trade will not execute unless someone else agrees to that price. You control the price with a limit order, but not the timing. If you demand too good a price, it may not execute at all.
Do I need to control intraday and daily trades? How about the spread?
If you submit a market order, it will execute right away. It will not stay open overnight or anything. What you do need to look at is how liquid the stock is. In other words, how much space is there between the bid (highest price people will buy it for) and ask (lowest price people are selling it for) and how many open (limit) orders there are in each. A more liquid stock (smaller bid-ask spread and higher volume) means you have to worry less about poor execution when submitting a limit order. If it is a big stock with lots of trades and sellers/buyers, then a market order is pretty safe. Otherwise you may want to submit a limit order and wait for the other side of the transaction to come to you.
Worst case scenario is that you submit a market order to buy and no one is selling so you pay a ton (or you submit an order sell and no one is there to buy, so it goes for super cheap).