Skip to content

Instantly share code, notes, and snippets.

trait Order {
val broker: String
val qty: Double
val side: Side
}
case class LimitOrder(broker: String, side: Side, qty: Double, limit: Double) extends Order
class OrderBook(val side: Side, orderTypes: (Order => OrderType)) {
def add(order: Order) = throw new NotImplementedError()
def orders(): List[Order] = throw new NotImplementedError()
}
@RunWith(classOf[Cucumber])
class AllMatchingFeaturesTest {
}
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:$")
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 |
scala.NotImplementedError: an implementation is missing
at com.prystupa.matching.OrderBook.orders(OrderBook.scala:15)
...
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) {
@prystupa
prystupa / OrderBook.scala
Last active December 10, 2015 01:48
Implementation of OrderBook to pass "adding a simple order to the book"
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
}
@prystupa
prystupa / OrderBook.Limit.feature
Last active December 10, 2015 01:58
Additional two tests for buy orders, to test price priority rule
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 |
@prystupa
prystupa / OrderBook.scala
Last active December 10, 2015 01:58
Implementation of OrderBook that supports price priority for both Buy and Sell orders
class OrderBook(side: Side, orderTypes: (Order => OrderType)) {
private var limitBook: List[(Double, List[Order])] = Nil
private val priceOrdering = if (side == Sell) Ordering[Double] else Ordering[Double].reverse
def add(order: Order) {
orderTypes(order).price match {
case LimitPrice(limit) => addLimit(limit, order)