Skip to content

Instantly share code, notes, and snippets.

@prystupa
Last active November 26, 2017 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prystupa/4415780 to your computer and use it in GitHub Desktop.
Save prystupa/4415780 to your computer and use it in GitHub Desktop.
Market orders matching with other market orders when "best limit" is defined
Scenario: Matching incoming Buy market order against Sell market order when another - limit - Sell order present
Given the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| A | Sell | 100 | MO |
| B | Sell | 100 | 10.5 |
Then market order book looks like:
| Broker | Qty | Price | Price | Qty | Broker |
| | | | MO | 100 | A |
| | | | 10.5 | 100 | B |
When the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| C | Buy | 100 | MO |
Then the following trades are generated:
| Buying broker | Selling broker | Qty | Price |
| C | A | 100 | 10.5 |
And market order book looks like:
| Broker | Qty | Price | Price | Qty | Broker |
| | | | 10.5 | 100 | B |
Scenario: Matching incoming Sell market order against Buy market order when another - limit - Buy order present
Given the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| A | Buy | 100 | MO |
| B | Buy | 100 | 10.5 |
Then market order book looks like:
| Broker | Qty | Price | Price | Qty | Broker |
| A | 100 | MO | | | |
| B | 100 | 10.5 | | | |
When the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| C | Sell | 100 | MO |
Then the following trades are generated:
| Buying broker | Selling broker | Qty | Price |
| A | C | 100 | 10.5 |
And market order book looks like:
| Broker | Qty | Price | Price | Qty | Broker |
| B | 100 | 10.5 | | | |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment