Skip to content

Commit

Permalink
#1107 handling create basket for constituent with missing last price
Browse files Browse the repository at this point in the history
  • Loading branch information
naleeha authored and chrisjstevo committed Jan 9, 2024
1 parent 4fbbf35 commit eb6c493
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import java.util.concurrent.atomic.AtomicInteger
object BasketTradeId {

private val counter: AtomicInteger = new AtomicInteger(0)
def oneNew(user:String): String = {

def oneNew(user: String): String = {
val counterValue = counter.incrementAndGet()
user + "-" + "".padTo(5 - counterValue.toString.length, "0").mkString + counterValue
}
}

trait BasketServiceIF{
trait BasketServiceIF {
def createBasket(basketId: String, name: String)(ctx: RequestContext): ViewPortAction
}

Expand All @@ -34,7 +35,7 @@ class BasketService(val table: DataTable, val tableContainer: TableContainer, va
private def getConstituentsForSourceBasket(basketId: String): List[RowData] = {
val table = tableContainer.getTable(BasketConstituentTable)
val keys = table.primaryKeys.toList
keys.map( key => table.pullRow(key) ).filter(_.get(BC.BasketId).toString == basketId)
keys.map(key => table.pullRow(key)).filter(_.get(BC.BasketId).toString == basketId)
}

private def mkTradingConstituentRow(side: String, sourceBasketId: String, basketTradeInstanceId: String, constituentKey: String,
Expand All @@ -51,7 +52,7 @@ class BasketService(val table: DataTable, val tableContainer: TableContainer, va
BTC.Side -> side,
BTC.Weighting -> weighting,
BTC.PriceStrategyId -> 2,
BTC.LimitPrice -> limitPrice.getOrElse(null),
BTC.LimitPrice -> limitPrice.orNull,
BTC.Algo -> -1,
BTC.OrderStatus -> OrderStates.PENDING,
BTC.FilledQty -> 0
Expand All @@ -76,7 +77,7 @@ class BasketService(val table: DataTable, val tableContainer: TableContainer, va
val priceTable = tableContainer.getTable(PriceModule.PriceTable)
tableContainer.getTable(BasketModule.BasketTradingConstituentTable) match {
case table: DataTable =>
constituents.foreach( rowData => {
constituents.foreach(rowData => {
val ric = rowData.get(BTC.Ric).toString
val constituentKey = s"$basketTradeId.$ric"
val weighting = rowData.get(BTC.Weighting).asInstanceOf[Double]
Expand All @@ -94,7 +95,11 @@ class BasketService(val table: DataTable, val tableContainer: TableContainer, va

private def getLastPrice(priceTable: DataTable, ric: String): Option[Double] = {
priceTable.pullRow(ric) match {
case row: RowWithData => Some(row.get("last").asInstanceOf[Double])
case row: RowWithData =>
row.get("last") match {
case null => None
case price: Double => Some(price)
}
case EmptyRowData => None
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ class BasketCreateTest extends VuuServerTestCase {
constituentProvider.tick(s"BT.L.$basketId", Map(BC.RicBasketId -> s"BT.L.$basketId", BC.Ric -> "BT.L", BC.BasketId -> basketId, BC.Weighting -> 0.1, BC.Side -> "SELL", BC.Description -> "British Telecom"))

//given constituent with price but missing last price
// constituentProvider.tick(s"BP.L.$basketId", Map(BC.RicBasketId -> s"BP.L.$basketId", BC.Ric -> "BP.L", BC.BasketId -> basketId, BC.Weighting -> 0.1, BC.Side -> "BUY", BC.Description -> "Beyond Petroleum"))
// pricesProvider.tick("BP.L", Map("ric" -> "BP.L", "bid" -> 5.3, "phase" -> "C"))
constituentProvider.tick(s"BP.L.$basketId", Map(BC.RicBasketId -> s"BP.L.$basketId", BC.Ric -> "BP.L", BC.BasketId -> basketId, BC.Weighting -> 0.1, BC.Side -> "BUY", BC.Description -> "Beyond Petroleum"))
pricesProvider.tick("BP.L", Map("ric" -> "BP.L", "bid" -> 5.3, "phase" -> "C"))

val viewportPrices = vuuServer.createViewPort(PriceModule.NAME, "prices")

vuuServer.runOnce()

//todo last price is null, no ric in the prices table
assertVpEq(combineQsForVp(viewportPrices)) {
Table(
("ric", "bid", "ask", "bidSize", "askSize", "last", "open", "close", "phase", "scenario"),
// ("BP.L", 5.3, null, null, null, null, null, null, "C", null),
("BP.L", 5.3, null, null, null, null, null, null, "C", null),
("VOD.L", 1.3, 1.6, null, null, 1.5, null, null, "C", null),
)
}
Expand Down Expand Up @@ -98,7 +97,7 @@ class BasketCreateTest extends VuuServerTestCase {
assertVpEq(filterByVp(viewportBasketTradingCons, updates)) {
Table(
("quantity", "side", "instanceId", "instanceIdRic", "basketId", "ric", "description", "notionalUsd", "notionalLocal", "venue", "algo", "algoParams", "pctFilled", "weighting", "priceSpread", "limitPrice", "priceStrategyId", "filledQty", "orderStatus"),
// (10L, "BUY", basketTradeInstanceId, s"$basketTradeInstanceId.BP.L", ".FTSE", "BP.L", "Beyond Petroleum", null, null, null, -1, null, null, 0.1, null, null, 2, 0, "PENDING"),
(10L, "BUY", basketTradeInstanceId, s"$basketTradeInstanceId.BP.L", ".FTSE", "BP.L", "Beyond Petroleum", null, null, null, -1, null, null, 0.1, null, null, 2, 0, "PENDING"),
(10L, "SELL", basketTradeInstanceId, s"$basketTradeInstanceId.BT.L", ".FTSE", "BT.L", "British Telecom", null, null, null, -1, null, null, 0.1, null, null, 2, 0, "PENDING"),
(10L, "BUY", basketTradeInstanceId, s"$basketTradeInstanceId.VOD.L", ".FTSE", "VOD.L", "Vodafone", null, null, null, -1, null, null, 0.1, null, 1.5, 2, 0, "PENDING"),
)
Expand Down

0 comments on commit eb6c493

Please sign in to comment.