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
package com.prystupa | |
import org.scalatest.matchers.ShouldMatchers | |
import org.junit.runner.RunWith | |
import org.scalatest.junit.JUnitRunner | |
/** | |
* Created with IntelliJ IDEA. | |
* User: eprystupa | |
* Date: 8/24/13 |
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
package com.prystupa | |
import org.scalatest.{Tag, FunSpec} | |
import scala.collection.mutable | |
trait JasmineSpec extends FunSpec { | |
private val itWord = new ItWord | |
private val setup: mutable.Stack[List[() => Unit]] = mutable.Stack() | |
private val tearDown: mutable.Stack[List[() => Unit]] = mutable.Stack() |
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
package com.euronextclone; | |
import com.euronextclone.ordertypes.Limit; | |
import com.google.common.base.Function; | |
import com.google.common.base.Optional; | |
import com.google.common.base.Predicate; | |
import com.google.common.collect.FluentIterable; | |
import com.google.common.collect.Lists; | |
import hu.akarnokd.reactive4java.reactive.DefaultObservable; | |
import hu.akarnokd.reactive4java.reactive.Observable; |
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)) | |
extends mutable.Publisher[OrderBookEvent] { | |
private case class OrdersAtLimit(limit: Double, orders: FastList[Order]) | |
private case class OrderLocation(list: FastList.Entry[OrdersAtLimit], entry: FastList.Entry[Order]) | |
private val marketBook: FastList[Order] = FastList() | |
private val limitBook = FastList[OrdersAtLimit]() | |
private val priceOrdering = if (side == Sell) Ordering[Double] else Ordering[Double].reverse |
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 Outline: Price and time priority of pegged orders over market and limit orders | |
When the following orders are added to the "<Side>" book: | |
| Broker | Qty | Price | | |
| A | 100 | <Top Limit> | | |
| B | 100 | <Non-top Limit> | | |
Then the "<Side>" order book looks like: | |
| Broker | Qty | Price | | |
| A | 100 | <Top Limit> | | |
| B | 100 | <Non-top Limit> | | |
When the following orders are added to the "<Side>" 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
sealed trait PriceLevel | |
case object MarketPrice extends PriceLevel | |
case class LimitPrice(limit: Double) extends PriceLevel | |
case object PegPrice extends PriceLevel |
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
sealed trait OrderBookEvent | |
case class Trade(buyingBroker: String, sellingBroker: String, | |
price: Double, qty: Double) extends OrderBookEvent | |
case class RejectedOrder(order: Order) extends OrderBookEvent | |
case class CancelledOrder(order: Order) extends OrderBookEvent |
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)) | |
extends mutable.Publisher[OrderBookEvent] { | |
private case class OrdersAtLimit(limit: Double, orders: FastList[Order]) | |
private case class OrderLocation(list: FastList.Entry[OrdersAtLimit], entry: FastList.Entry[Order]) | |
private val marketBook: FastList[Order] = FastList() | |
private val limitBook = FastList[OrdersAtLimit]() | |
private val priceOrdering = if (side == Sell) Ordering[Double] else Ordering[Double].reverse |
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(buyBook, sellBook) | |
val buyBook: OrderBook = new OrderBook(Buy, orderTypes) | |
val sellBook: OrderBook = new OrderBook(Sell, orderTypes) | |
var actualRejected = Vector.empty[Order] | |
events { | |
case RejectedOrder(order) => actualRejected = actualRejected :+ 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
Feature: Core Pegged Order Functionality | |
Scenario Outline: Adding pegged order to a book with no best limit to peg | |
If a book is empty than no best limit is available to peg, so we expect the order to be rejected | |
If a book only has market orders then best limit is also undefined, so we also expect the order to be rejected | |
Given the "<Side>" order book looks like: | |
| Broker | Qty | Price | | |
When the following orders are added to the "<Side>" book: | |
| Broker | Qty | Price | |
NewerOlder