Commit 5cbca951 by Amelin Konstantin

Move general part from RepoTemplate to TradeTemlate. Complete RepoTemplate

parent 5a949c6c
......@@ -17,12 +17,12 @@ object Main extends App {
}
val p = new PrettyPrinter(140, 2)
val sourceXml = XML.loadFile("src/main/resources/nsd/Repo NSD equity.xml")
val sourceXml = XML.loadFile("src/main/resources/nsd/Repo NSD bond.xml")
val template = Template(sourceXml)
val outputXml = XML.loadString(p.format(template.render))
//val outputXml = template.template
template.log()
//template.log()
Try {
XMLValid("src/main/resources/nsd/nsd-ext-merged-schema.xsd").loadString(sourceXml.mkString)
......
package templates
import scala.util.Try
import scala.xml.Node
class RepoTemplate(source: Node) extends TradeTemplate(source) {
protected[this] def templateTrade: Node = {
<fpml:trade>
<fpml:tradeHeader>
{ for (s <- source \ "trade" \ "tradeHeader" \ "partyTradeIdentifier") yield {
<fpml:partyTradeIdentifier>
<fpml:partyReference href={ get(s \ "partyReference", "href") }/>
<fpml:tradeId tradeIdScheme={ get(s \ "tradeId", "tradeIdScheme") }>{ get(s \ "tradeId") }</fpml:tradeId>
</fpml:partyTradeIdentifier>
}
}
{/* for (s <- source \ "trade" \ "tradeHeader" \ "partyTradeInformation") yield {
<fpml:partyTradeInformation>
<fpml:partyReference href="SPB01" />
<fpml:relatedParty>
<fpml:partyReference href="LEI_vvv" />
<fpml:role>ClearingOrganization</fpml:role>
</fpml:relatedParty>
<fpml:category categoryScheme="http://www.fpml.ru/repository/trade-settlement-type">ОТС</fpml:category>
<fpml:category categoryScheme="http://www.fpml.ru/repository/trade-settlement-method">C</fpml:category>
<fpml:executionDateTime>2018-10-05T00:00:00</fpml:executionDateTime>
<fpml:reportingRegime>
<fpml:name>RussianFederation</fpml:name>
<fpml:mandatorilyClearable>true</fpml:mandatorilyClearable>
</fpml:reportingRegime>
</fpml:partyTradeInformation>
}
*/}
{/*
<fpml:partyTradeInformation>
<fpml:partyReference href="SPB01" />
<fpml:relatedParty>
<fpml:partyReference href="LEI_vvv" />
<fpml:role>ClearingOrganization</fpml:role>
</fpml:relatedParty>
<fpml:category categoryScheme="http://www.fpml.ru/repository/trade-settlement-type">ОТС</fpml:category>
<fpml:category categoryScheme="http://www.fpml.ru/repository/trade-settlement-method">C</fpml:category>
<fpml:executionDateTime>2018-10-05T00:00:00</fpml:executionDateTime>
<fpml:reportingRegime>
<fpml:name>RussianFederation</fpml:name>
<fpml:mandatorilyClearable>true</fpml:mandatorilyClearable>
</fpml:reportingRegime>
</fpml:partyTradeInformation>
<fpml:partyTradeInformation>
<fpml:partyReference href="LEI_253400S2HGY7JG1JWC41" />
<fpml:relatedParty>
<fpml:partyReference href="LEI_12548741" />
<fpml:role>Client</fpml:role>
<fpml:type>L</fpml:type>
</fpml:relatedParty>
<fpml:relatedParty>
<fpml:partyReference href="LEI_43382" />
<fpml:role>ClearingOrganization</fpml:role>
</fpml:relatedParty>
<fpml:relatedParty>
<fpml:partyReference href="TEST" />
<fpml:role>Party</fpml:role>
</fpml:relatedParty>
<fpml:timestamps>
<fpml:timestamp>
<fpml:type>InClearingPool</fpml:type>
<fpml:value>2018-10-09T09:00:00</fpml:value>
</fpml:timestamp>
<fpml:timestamp>
<fpml:type>InPortfolio</fpml:type>
<fpml:value>2018-10-09T09:00:00</fpml:value>
</fpml:timestamp>
<fpml:timestamp>
<fpml:type>OutPortfolio</fpml:type>
<fpml:value>2018-10-09T09:00:00</fpml:value>
</fpml:timestamp>
</fpml:timestamps>
<fpml:collateralizationType>Uncollateralized</fpml:collateralizationType>
<fpml:collateralPortfolio>Fully</fpml:collateralPortfolio>
</fpml:partyTradeInformation>
<fpml:partyTradeInformation>
<fpml:partyReference href="TEST" />
<fpml:relatedParty>
<fpml:partyReference href="PASS_9999445555" />
<fpml:role>Client</fpml:role>
<fpml:type>TR</fpml:type>
</fpml:relatedParty>
<fpml:relatedParty>
<fpml:partyReference href="LEI_NNN" />
<fpml:role>ClearingOrganization</fpml:role>
</fpml:relatedParty>
<fpml:relatedParty>
<fpml:partyReference href="LEI_253400S2HGY7JG1JWC41" />
<fpml:role>Party</fpml:role>
</fpml:relatedParty>
<timestamps>
<timestamp>
<type>InClearingPool</type>
<value>2018-10-09T09:00:00</value>
</timestamp>
<timestamp>
<type>InPortfolio</type>
<value>2018-10-09T09:00:00</value>
</timestamp>
<timestamp>
<type>OutPortfolio</type>
<value>2018-10-10T10:00:00</value>
</timestamp>
</timestamps>
<fpml:collateralizationType>Uncollateralized</fpml:collateralizationType>
<fpml:collateralPortfolio>Fully</fpml:collateralPortfolio>
</fpml:partyTradeInformation>
*/}
</fpml:tradeHeader>
protected[this] def templateTradeBody: Node = {
<fpmlext:repo xsi:type="rtsrep:Repo">
<fpml:productId>{ get(source \ "trade" \ "repo" \ "productType") }</fpml:productId>
<fpml:productId productIdScheme={ get(source \ "trade" \ "repo" \ "productId", "productIdScheme") }>{ get(source \ "trade" \ "repo" \ "productId") }</fpml:productId>
<fpmlext:fixedRateSchedule>
<fpml:initialValue>{ get(source \ "trade" \ "repo" \ "fixedRateSchedule" \ "initialValue") }</fpml:initialValue>
<step>
<stepDate>{ get(source \ "trade" \ "repo" \ "fixedRateSchedule" \\ "stepDate") }</stepDate>
<stepValue>{ get(source \ "trade" \ "repo" \ "fixedRateSchedule" \\ "stepValue") }</stepValue>
</step>
<fpml:step>
<fpml:stepDate>{ get(source \ "trade" \ "repo" \ "fixedRateSchedule" \\ "stepDate") }</fpml:stepDate>
<fpml:stepValue>{ get(source \ "trade" \ "repo" \ "fixedRateSchedule" \\ "stepValue") }</fpml:stepValue>
</fpml:step>
</fpmlext:fixedRateSchedule>
<fpmlext:floatingRateCalculation>
<fpml:floatingRateIndex>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \ "floatingRateIndex") }</fpml:floatingRateIndex>
<indexTenor>
<periodMultiplier>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \\ "periodMultiplier") }</periodMultiplier>
<period>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \\ "period") }</period>
</indexTenor>
<spreadSchedule>
<initialValue>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \\ "initialValue") }</initialValue>
</spreadSchedule>
<initialRate>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \\ "initialRate") }</initialRate>
<fpml:indexTenor>
<fpml:periodMultiplier>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \\ "periodMultiplier") }</fpml:periodMultiplier>
<fpml:period>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \\ "period") }</fpml:period>
</fpml:indexTenor>
<fpml:spreadSchedule>
<fpml:initialValue>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \\ "initialValue") }</fpml:initialValue>
</fpml:spreadSchedule>
<fpml:initialRate>{ get(source \ "trade" \ "repo" \ "floatingRateCalculation" \\ "initialRate") }</fpml:initialRate>
</fpmlext:floatingRateCalculation>
<fpmlext:dayCountFraction>{ get(source \ "trade" \ "repo" \ "dayCountFraction") }</fpmlext:dayCountFraction>
<fpmlext:spotLeg xsi:type="rtsrep:RepoTransactionLeg">
......@@ -146,19 +38,24 @@ class RepoTemplate(source: Node) extends TradeTemplate(source) {
<fpml:currency>{ get(source \ "trade" \ "repo" \ "spotLeg" \\ "currency") }</fpml:currency>
<fpml:amount>{ get(source \ "trade" \ "repo" \ "spotLeg" \\ "amount") }</fpml:amount>
</fpml:settlementAmount>
{/*
<fpmlext:collateral xsi:type="rtsrep:CollateralValuation">
<fpmlext:numberOfUnits>100</fpmlext:numberOfUnits>
<fpmlext:assetReference href="RU0009109391" />
{ /* <fpmlext:collateral xsi:type="rtsrep:CollateralValuation"> */ }
<fpmlext:collateral>
<fpmlext:numberOfUnits>{ get(source \ "trade" \ "repo" \ "spotLeg" \ "collateral" \ "numberOfUnits") }</fpmlext:numberOfUnits>
<fpmlext:unitPrice>
<fpml:currency>{ get(source \ "trade" \ "repo" \ "spotLeg" \ "collateral" \ "unitPrice" \ "currency") }</fpml:currency>
<fpml:amount>{ get(source \ "trade" \ "repo" \ "spotLeg" \ "collateral" \ "unitPrice" \ "ammount") }</fpml:amount>
</fpmlext:unitPrice>
<fpmlext:nominalAmount>
<fpml:currency>{ get(source \ "trade" \ "repo" \ "spotLeg" \ "collateral" \ "nominalAmount" \ "currency") }</fpml:currency>
<fpml:amount>{ get(source \ "trade" \ "repo" \ "spotLeg" \ "collateral" \ "nominalAmount" \ "ammount") }</fpml:amount>
</fpmlext:nominalAmount>
<fpmlext:assetReference href={ get(source \ "trade" \ "repo" \ "spotLeg" \ "collateral" \ "assetReference", "href") }/>
</fpmlext:collateral>
*/}
{/*
<rtsrep:deliveryDate>
<fpml:adjustableDate>
<fpml:unadjustedDate>{ get(Try { (source \ "trade" \ "repo" \ "spotLeg" \ "deliveryDate" \\ "unadjustedDate").head }) }</fpml:unadjustedDate>
<fpml:unadjustedDate>{ get(source \ "trade" \ "repo" \ "spotLeg" \ "deliveryDate" \\ "unadjustedDate") }</fpml:unadjustedDate>
</fpml:adjustableDate>
</rtsrep:deliveryDate>
*/}
</fpmlext:spotLeg>
<fpmlext:forwardLeg xsi:type="rtsrep:ForwardRepoTransactionLeg">
<fpml:buyerPartyReference href={ get(source \ "trade" \ "repo" \ "forwardLeg" \ "buyerPartyReference", "href") } />
......@@ -172,13 +69,11 @@ class RepoTemplate(source: Node) extends TradeTemplate(source) {
<fpml:currency>{ get(source \ "trade" \ "repo" \ "forwardLeg" \\ "currency") }</fpml:currency>
<fpml:amount>{ get(source \ "trade" \ "repo" \ "forwardLeg" \\ "amount") }</fpml:amount>
</fpml:settlementAmount>
{/*
<rtsrep:deliveryDate>
<fpml:adjustableDate>
<fpml:unadjustedDate>{ get(Try { (source \ "trade" \ "repo" \ "forwardLeg" \ "deliveryDate" \\ "unadjustedDate").head }) }</fpml:unadjustedDate>
<fpml:unadjustedDate>{ get(source \ "trade" \ "repo" \ "forwardLeg" \ "deliveryDate" \\ "unadjustedDate") }</fpml:unadjustedDate>
</fpml:adjustableDate>
</rtsrep:deliveryDate>
*/}
</fpmlext:forwardLeg>
<fpml:equity id={ get(source \ "trade" \ "repo" \ "equity", "id") }>
<fpml:instrumentId instrumentIdScheme={ get(source \ "trade" \ "repo" \ "equity" \ "instrumentId", "instrumentIdScheme") }>{ get(source \ "trade" \ "repo" \ "equity" \ "instrumentId") }</fpml:instrumentId>
......@@ -187,11 +82,5 @@ class RepoTemplate(source: Node) extends TradeTemplate(source) {
<fpml:instrumentId instrumentIdScheme={ get(source \ "trade" \ "repo" \ "bond" \ "instrumentId", "instrumentIdScheme") }>{ get(source \ "trade" \ "repo" \ "bond" \ "instrumentId") }</fpml:instrumentId>
</fpml:bond>
</fpmlext:repo>
<fpml:documentation>
<fpml:masterAgreement>
<fpml:masterAgreementId>{ get(source \ "trade" \ "tradeHeader" \ "partyTradeIdentifier" \ "linkId") }</fpml:masterAgreementId>
</fpml:masterAgreement>
</fpml:documentation>
</fpml:trade>
}
}
\ No newline at end of file
package templates
import scala.util.Try
import scala.xml.Node
abstract class TradeTemplate(source: Node) extends Template(source) {
protected[this] def templateTrade: Node
protected[this] def templateTradeBody: Node
def template: Node = {
<signedDocument xmlns="http://www.fpml.ru/repository">
......@@ -23,7 +22,72 @@ abstract class TradeTemplate(source: Node) extends Template(source) {
</fpml:header>
<fpml:isCorrection>{ get(source \ "isCorrection") }</fpml:isCorrection>
<fpml:correlationId correlationIdScheme="">{ get(source \ "correlationId") }</fpml:correlationId>
{ templateTrade }
<fpml:trade>
<fpml:tradeHeader>
{ for (s <- source \ "trade" \ "tradeHeader" \ "partyTradeIdentifier") yield {
<fpml:partyTradeIdentifier>
<fpml:partyReference href={ get(s \ "partyReference", "href") }/>
<fpml:tradeId tradeIdScheme={ get(s \ "tradeId", "tradeIdScheme") }>{ get(s \ "tradeId") }</fpml:tradeId>
</fpml:partyTradeIdentifier>
}
}
<fpml:partyTradeInformation>
<fpml:partyReference href={ get(source \ "trade" \ "tradeHeader" \ "partyTradeInformation" \ "partyReference", "href") }/>
<fpml:relatedParty>
<fpml:partyReference href={ get(source \ "trade" \ "tradeHeader" \ "partyTradeInformation" \ "partyReference", "href") } />
<fpml:role>ClearingOrganization</fpml:role>
</fpml:relatedParty>
<fpml:category categoryScheme="http://www.fpml.ru/repository/trade-settlement-type">{ get(source \ "trade" \ "nsdSpecificTradeFields" \ "clearSettlementType") }</fpml:category>
<fpml:category categoryScheme="http://www.fpml.ru/repository/trade-settlement-method">{ get(source \ "trade" \ "nsdSpecificTradeFields" \ "clearSettlementMethod") }</fpml:category>
<fpml:executionDateTime>{ get(source \ "trade" \ "tradeHeader" \ "tradeDate") + "T00:00:00" }</fpml:executionDateTime>
<fpml:reportingRegime>
<fpml:name>{ get(source \ "trade" \ "tradeHeader" \ "partyTradeInformation" \ "reportingRegime" \ "name") }</fpml:name>
<fpml:mandatorilyClearable>{ if (get(source \ "trade" \ "nsdSpecificTradeFields" \ "cleared").mkString.contains("Y")) "true" else "" }</fpml:mandatorilyClearable>
</fpml:reportingRegime>
</fpml:partyTradeInformation>
{ for (s <- source \ "trade" \ "nsdSpecificTradeFields" \ "clientDetails") yield {
<fpml:partyTradeInformation>
<fpml:partyReference href={ get(s \ "servicingParty", "href") } />
{ /*<fpml:relatedParty>
<fpml:partyReference href={ get(s \ "id") } />
<fpml:role>{ if (get(s \ "id").mkString != msgNotFound) "Client" else ""}</fpml:role>
<fpml:type>{ get(s \ "type") }</fpml:type>
</fpml:relatedParty> */}
<fpml:timestamps>
<fpml:timestamp>
<fpml:type>{ if (get(source \ "trade" \ "nsdSpecificTradeFields" \ "clearedDate").mkString != msgNotFound) "InClearingPool" else ""}</fpml:type>
<fpml:value>{ get(source \ "trade" \ "nsdSpecificTradeFields" \ "clearedDate") + "T00:00:00" }</fpml:value>
</fpml:timestamp>
<fpml:timestamp>
<fpml:type>{ if (get(source \ "trade" \ "nsdSpecificTradeFields" \ "startAgreementDate").mkString != msgNotFound) "InPortfolio" else ""}</fpml:type>
<fpml:value>{ get(source \ "trade" \ "nsdSpecificTradeFields" \ "startAgreementDate") + "T00:00:00" }</fpml:value>
</fpml:timestamp>
<fpml:timestamp>
<fpml:type>{ if (get(source \ "trade" \ "nsdSpecificTradeFields" \ "endAgreementDate").mkString != msgNotFound) "OutPortfolio" else ""}</fpml:type>
<fpml:value>{ get(source \ "trade" \ "nsdSpecificTradeFields" \ "endAgreementDate") + "T00:00:00" }</fpml:value>
</fpml:timestamp>
</fpml:timestamps>
<fpml:collateralizationType>{
get(source \ "trade" \ "collateral" \ "marginType").mkString match {
case v if v == "FC" => "Fully"
case v if v == "PC" => "Partially"
case v if v == "OC" => "OneWay"
case v if v == "U" => "Uncollateralized"
case _ => ""
}
}</fpml:collateralizationType>
<fpml:collateralPortfolio>{ get(source \ "trade" \ "collateral" \ "collateralForm") }</fpml:collateralPortfolio>
</fpml:partyTradeInformation>
}
}
</fpml:tradeHeader>
{ templateTradeBody }
<fpml:documentation>
<fpml:masterAgreement>
<fpml:masterAgreementId>{ get(source \ "trade" \ "tradeHeader" \ "partyTradeIdentifier" \ "linkId") }</fpml:masterAgreementId>
</fpml:masterAgreement>
</fpml:documentation>
</fpml:trade>
{ for (s <- source \ "party") yield {
<fpml:party id={ get(s, "id") }>
<fpml:partyId partyIdScheme={ get(s \ "partyId", "partyIdScheme") }>{ get(s \ "partyId") }</fpml:partyId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment