Skip to content

Instantly share code, notes, and snippets.

@prystupa
Created December 27, 2012 20:10
Show Gist options
  • Save prystupa/4391542 to your computer and use it in GitHub Desktop.
Save prystupa/4391542 to your computer and use it in GitHub Desktop.
Matching incoming limit orders against outstanding market orders
Scenario: Matching incoming Buy limit order against a single outstanding Sell market order
When the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| A | Sell | 100 | MO |
| B | Buy | 120 | 10.5 |
Then the following trades are generated:
| Buying broker | Selling broker | Qty | Price |
| B | A | 100 | 10.5 |
And market order book looks like:
| Broker | Qty | Price | Price | Qty | Broker |
| B | 20 | 10.5 | | | |
Scenario: Matching incoming Sell limit order against a single outstanding Buy market order
When the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| A | Buy | 100 | MO |
| B | Sell | 120 | 10.5 |
Then the following trades are generated:
| Buying broker | Selling broker | Qty | Price |
| A | B | 100 | 10.5 |
And market order book looks like:
| Broker | Qty | Price | Price | Qty | Broker |
| | | | 10.5 | 20 | B |
Scenario: Matching incoming Buy limit order against Sell market order while another NON-CROSSING Sell limit order is outstanding
When the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| A | Sell | 100 | MO |
| B | Sell | 100 | 10.6 |
| C | Buy | 120 | 10.5 |
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 |
| C | 20 | 10.5 | 10.6 | 100 | B |
Scenario: Matching incoming Sell limit order against Buy market order while another NON-CROSSING Buy limit order is outstanding
When the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| A | Buy | 100 | MO |
| B | Buy | 100 | 10.4 |
| C | Sell | 120 | 10.5 |
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.4 | 10.5 | 20 | C |
Scenario: Matching incoming Buy limit order against Sell market order while another CROSSING Sell limit order is outstanding
When the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| A | Sell | 100 | MO |
| B | Sell | 100 | 10.4 |
| C | Buy | 120 | 10.5 |
Then the following trades are generated:
| Buying broker | Selling broker | Qty | Price |
| C | A | 100 | 10.4 |
| C | B | 20 | 10.4 |
And market order book looks like:
| Broker | Qty | Price | Price | Qty | Broker |
| | | | 10.4 | 80 | B |
Scenario: Matching incoming Sell limit order against Buy market order while another CROSSING Buy limit order is outstanding
When the following orders are submitted in this order:
| Broker | Side | Qty | Price |
| A | Buy | 100 | MO |
| B | Buy | 100 | 10.6 |
| C | Sell | 120 | 10.5 |
Then the following trades are generated:
| Buying broker | Selling broker | Qty | Price |
| A | C | 100 | 10.6 |
| B | C | 20 | 10.6 |
And market order book looks like:
| Broker | Qty | Price | Price | Qty | Broker |
| B | 80 | 10.6 | | | |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment