New to trading. I came across the concept of an "Order Book". 

<h2> MY UNDERSTANDING </h2>

My understanding (when going **LONG**) is that a trade ONLY takes place if the **BID Amount >= the ASK Amount - ONLY**. 

In the other words, if the **ASK** Amount is $400 and the **BID** Amount is $399.99, the order will not go through.

If the **ASK** Amount is $400 and the **BID** Amount is $400.01, then the order will go through  

<h2> SITUATION (YESTERDAY) </h2>

This took place **YESTERDAY**

Suppose there is a person selling 4000 coins for an **ASKING** price of $4000 ( $1.00 per coin ). His order is **far from the Market Value Line** (not close to it at all)

I would only want 300 of those coins (not all 4000).

I see his order in the book.

I put in my **BUY** order of 300 coins for $1.01 per coin. 

<h2> SITUATION (TODAY) </h2>

There are a lot of BUY orders.  The 4000 Coin Order is **getting close the** **Market Value Line**. 

**So the question is:** When the 4000 coins are being sold, which buyers will go first? What algorithm is used to determine who gets to buy first, who gets to buy second, etc?
 
 My hope is that with my order being $1.01 per coin, I would be "somewhere in line" - but - it would be good to know. How exactly is the line formed? Which BUYER would have their order honored/filled first?
 

 - Is it by time (the earliest BUY order created)? 
 - Is it by some factor that the Exchange uses (i.e. the person with the
   biggest Account, the person who executes the most orders on the
   Exchange, Youtube Influencers, etc.)
 - Is it by the Order that offers the Amount closest to the what the ASKING person
   wanted? (ex: I may offer $1.01 per coin when I first saw that the coins were being sold - which could have been yesterday - but - would my offer be rejected NOW(i.e. today) by someone who offered $5.00 per coin NOW (i.e. today) )?

Any answers, clues, hints or suggestions would be greatly appreciated.

TIA