@bowguo You may think about the orders as instructions to change the current position. The order doesn't constitute the position itself.
The position is maintained by the broker per data ( not per order ). So if you buy order has completed - your position for particular data has increased and vice versa for sell order.
Regarding the multiple orders with different prices - once again the position is not maintained per order - so if you sell part of your position - the position will just decrease by the size of the sell order - regardless of any previous order history that brought your position to the current state.
Diving a little bit deeper however, the real broker maintains the base price for every single share/unit of the entity you are holding in your position - for various purposes ( tax calculation, average price calculation, margin requirements and so on ). Some brokers even allow you to select the tax calculation policy if multiple lots of the same entity with different prices are part of your position.