This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Order { | |
val broker: String | |
val qty: Double | |
val side: Side | |
} | |
case class LimitOrder(broker: String, side: Side, qty: Double, limit: Double) extends Order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderBook(val side: Side, orderTypes: (Order => OrderType)) { | |
def add(order: Order) = throw new NotImplementedError() | |
def orders(): List[Order] = throw new NotImplementedError() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Core Functionality for Order Book | |
Scenario: Add a single limit order to the SELL order book | |
When the following orders are added to the "Sell" book: | |
| Broker | Qty | Price | | |
| A | 100 | 10.6 | | |
Then the "Sell" order book looks like: | |
| Broker | Qty | Price | | |
| A | 100 | 10.6 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(classOf[Cucumber]) | |
class AllMatchingFeaturesTest { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test '.Scenario: Add a single limit order to the BUY order book .When the following orders are added to the "Buy" book: ' ignored | |
Test '.Scenario: Add a single limit order to the BUY order book .Then the "Buy" order book looks like: ' ignored | |
Test '.Feature: Core Functionality for Order Book .Scenario: Add a single limit order to the BUY order book ' ignored | |
Wrong test finished. Last started: [] stopped: Scenario: Add a single limit order to the BUY order book ; class org.junit.runner.Description | |
You can implement missing steps with the snippets below: | |
@When("^the following orders are added to the \"([^\"]*)\" book:$") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderBookSteps extends ShouldMatchers { | |
val orderTypes = OrderType.all() | |
val buyBook: OrderBook = new OrderBook(Buy, orderTypes) | |
val sellBook: OrderBook = new OrderBook(Sell, orderTypes) | |
@Given("^the following orders are added to the \"([^\"]*)\" book:$") | |
def the_following_orders_are_added_to_the_book(sideString: String, orderTable: DataTable) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala.NotImplementedError: an implementation is missing | |
at com.prystupa.matching.OrderBook.orders(OrderBook.scala:15) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderBook(val side: Side, orderTypes: (Order => OrderType)) { | |
private var limitBook: List[Order] = Nil | |
def add(order: Order) { | |
book = order :: limitBook; | |
} | |
def orders(): List[Order] = limitBook | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scenario: Add two limit orders to the BUY order book, with more aggressive order first | |
When the following orders are added to the "Buy" book: | |
| Broker | Qty | Price | | |
| A | 100 | 10.5 | | |
| B | 100 | 10.4 | | |
Then the "Buy" order book looks like: | |
| Broker | Qty | Price | | |
| A | 100 | 10.5 | | |
| B | 100 | 10.4 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderBook(side: Side, orderTypes: (Order => OrderType)) { | |
private var limitBook: List[(Double, List[Order])] = Nil | |
def add(order: Order) { | |
orderTypes(order).price match { | |
case LimitPrice(level) => addLimit(level, order) | |
} |
OlderNewer