3 ms·
You can definitely get away with traversals - and they are often required. The simplest method would be to use a sorted list. The head of the list is always the
by RyanZAG 13y ago
You can definitely get away with traversals - and they are often required. The simplest method would be to use a sorted list. The head of the list is always the best price, so comparing the best bid against the best offer is linear and can be performed every time the orders are modified. Order insertion is naively O(log n) as the list is sorted, but this can be optimized by keeping a journal of orders and only immediately inserting orders close to the best price. You can then insert from the journal into the order book as time allows or if the best price moves a large enough amount.
There are a lot of other techniques too, but you definitely can't just let people buy or sell a different quantity. At least on any formal market I know of?
- dclusin 13y agoI'm thinking about FX where I work. If the price you get executed at is better than what you wanted your term currency amount changes. Often times what ends up happening is that some someone upstream (e.g. broker) ends up keeping the improvement.