Skip to content

Commit

Permalink
#980 adding description to the new constituent on basket trading
Browse files Browse the repository at this point in the history
  • Loading branch information
naleeha committed Dec 6, 2023
1 parent c57daf3 commit f6de416
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import org.finos.toolbox.time.Clock
import org.finos.vuu.api.JoinTableDef
import org.finos.vuu.core.module.basket.BasketConstants.Side
import org.finos.vuu.core.module.basket.BasketModule
import org.finos.vuu.core.module.basket.BasketModule.{BasketTradingColumnNames => BTColumnName, BasketTradingConstituentColumnNames => ColumnName}
import org.finos.vuu.core.module.basket.BasketModule.{BasketConstituentColumnNames => BCColumnName, BasketTradingColumnNames => BTColumnName, BasketTradingConstituentColumnNames => ColumnName}
import org.finos.vuu.core.module.basket.result.ErrorReason
import org.finos.vuu.core.table.{DataTable, JoinTable, RowWithData, TableContainer}
import org.finos.vuu.core.table.{DataTable, JoinTable, RowData, RowWithData, TableContainer}
import org.finos.vuu.net.rpc.{EditRpcHandler, RpcHandler}
import org.finos.vuu.net.{ClientSessionId, RequestContext}
import org.finos.vuu.viewport._
Expand Down Expand Up @@ -64,11 +64,18 @@ class BasketTradingConstituentJoinService(val table: DataTable, val tableContain
val basketId = tradeRow.get(BTColumnName.BasketId).asInstanceOf[String]
val tradeUnit = tradeRow.get(BTColumnName.Units).asInstanceOf[Int]

val basketConstituentRows = getConstituentsWith(ric) //todo what to do when multiple result?
val description =
if(basketConstituentRows.nonEmpty)
basketConstituentRows.head.get(BCColumnName.Description).asInstanceOf[String]
else ""

val newRow = mkTradingConstituentRow(
basketTradeInstanceId = tradeId,
sourceBasketId = basketId,
tradeUnit = tradeUnit,
ric = ric)
ric = ric,
description = description)

//todo should we guard against adding row for ric that already exist?
updateJoinTable(Array(newRow)) match {
Expand All @@ -79,6 +86,12 @@ class BasketTradingConstituentJoinService(val table: DataTable, val tableContain
}
}

private def getConstituentsWith(ric: String): List[RowData] = {
val table = tableContainer.getTable(BasketModule.BasketConstituentTable)
val keys = table.primaryKeys.toList
keys.map(key => table.pullRow(key)).filter(_.get(BCColumnName.Ric).toString == ric)
}

private def onEditCell(key: String, columnName: String, data: Any, vp: ViewPort, session: ClientSessionId): ViewPortEditAction = {
try {
getBaseTable() match {
Expand Down Expand Up @@ -180,7 +193,7 @@ class BasketTradingConstituentJoinService(val table: DataTable, val tableContain
}
}

private def mkTradingConstituentRow(basketTradeInstanceId: String, sourceBasketId: String, tradeUnit: Int, ric: String): RowWithData = {
private def mkTradingConstituentRow(basketTradeInstanceId: String, sourceBasketId: String, tradeUnit: Int, ric: String, description: String): RowWithData = {
val constituentKey = s"$basketTradeInstanceId.$ric"
val weighting: Double = 0.1
RowWithData(
Expand All @@ -191,7 +204,7 @@ class BasketTradingConstituentJoinService(val table: DataTable, val tableContain
ColumnName.InstanceId -> basketTradeInstanceId,
ColumnName.InstanceIdRic -> constituentKey,
ColumnName.Quantity -> (weighting * 100).asInstanceOf[Long],
ColumnName.Description -> "", //todo look up description from instrument table
ColumnName.Description -> description,
ColumnName.Side -> Side.Buy,
ColumnName.Weighting -> weighting,
ColumnName.PriceStrategyId -> 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class BasketMutateOffMarketTest extends VuuServerTestCase {
}
}

//TODO oin table cannot be tested currently as it doesnt get updated when underlying table gets updated
//TODO join table cannot be tested currently as it doesnt get updated when underlying table gets updated
// Scenario("Adding new constituents by ric should add it to basket trading") {
// import BasketModule._
// implicit val clock: Clock = new TestFriendlyClock(10001L)
Expand Down Expand Up @@ -217,11 +217,9 @@ class BasketMutateOffMarketTest extends VuuServerTestCase {
// Then("get all the updates that have occurred for all view ports from the outbound queue")
// val updates = combineQs(vpBasketTradingConsJoin)
//
// //todo should basketid be where the stock was sourced from? in this case .HSI?
//
// //todo map description
// //todo should basketid be where the stock was sourced from? in this case .HSI?
//
// And("assert the basket trading constituent table has not changed sides")
// And("assert the basket trading constituent table has added row")
// assertVpEq(filterByVp(vpBasketTradingCons, updates)) {
// Table(
// ("quantity", "side", "instanceId", "instanceIdRic", "basketId", "ric", "description", "notionalUsd", "notionalLocal", "venue", "algo", "algoParams", "pctFilled", "weighting", "priceSpread", "limitPrice", "priceStrategyId", "filledQty", "orderStatus"),
Expand Down

0 comments on commit f6de416

Please sign in to comment.