Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SPB_Exchange_Repo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Amelin Konstantin
SPB_Exchange_Repo
Commits
82523709
Commit
82523709
authored
Oct 18, 2018
by
Amelin Konstantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add automatic template choice
parent
11e60d11
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
18 deletions
+54
-18
src/main/resources/nsd/Repo NSD equity.xml
+0
-0
src/main/resources/rts/Repo RTS equity 1.xml
+0
-0
src/main/resources/rts/Repo RTS equity 2.xml
+0
-0
src/main/scala/Main.scala
+5
-5
src/main/scala/templates/RepoTemplate.scala
+30
-12
src/main/scala/templates/Template.scala
+19
-1
No files found.
src/main/resources/nsd/Repo NSD e
nt
ity.xml
→
src/main/resources/nsd/Repo NSD e
qu
ity.xml
View file @
82523709
File moved
src/main/resources/rts/Repo RTS e
nt
ity 1.xml
→
src/main/resources/rts/Repo RTS e
qu
ity 1.xml
View file @
82523709
File moved
src/main/resources/rts/Repo RTS e
nt
ity 2.xml
→
src/main/resources/rts/Repo RTS e
qu
ity 2.xml
View file @
82523709
File moved
src/main/scala/Main.scala
View file @
82523709
...
...
@@ -5,11 +5,11 @@ import templates._
object
Main
extends
App
{
//val p = new PrettyPrinter(12
0, 2)
val
sourceXml
=
XML
.
loadFile
(
"src/main/resources/nsd/Repo NSD
entity
.xml"
)
val
template
=
new
Repo
Template
(
sourceXml
)
//val outputXml = XML.loadString(p.format(template.render
))
val
outputXml
=
template
.
template
val
p
=
new
PrettyPrinter
(
14
0
,
2
)
val
sourceXml
=
XML
.
loadFile
(
"src/main/resources/nsd/Repo NSD
bond
.xml"
)
val
template
=
Template
(
sourceXml
)
val
outputXml
=
XML
.
loadString
(
p
.
format
(
template
.
template
))
//
val outputXml = template.template
template
.
log
()
...
...
src/main/scala/templates/RepoTemplate.scala
View file @
82523709
...
...
@@ -2,11 +2,16 @@ package templates
import
scala.util.Try
import
scala.xml.Node
import
templates.Template._
final
class
RepoTemplate
(
source
:
Node
)
extends
TradeTemplate
(
source
)
{
override
protected
[
this
]
val
msgNotFound
=
"No elem found"
protected
[
this
]
def
templateTrade
:
Node
=
{
val
productType
=
(
source
\
"trade"
\
"repo"
\
"productType"
).
head
.
text
.
mkString
match
{
case
"Equity:Repo:EquityRepo"
=>
Equity
case
"InterestRate:Repo:BondRepo"
=>
Bond
}
<
fpml
:
trade>
<fpml:tradeHeader>
{
for
(
s
<-
source
\
"
trade
"
\
"
tradeHeader
"
\
"
partyTradeIdentifier
"
)
yield
{
...
...
@@ -117,18 +122,26 @@ final class RepoTemplate(source: Node) extends TradeTemplate(source) {
<fpmlext:repo
xsi:
type
=
"rtsrep:Repo"
>
<
fpml
:
productId>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
productType
"
)
.head
})
}
</fpml:productId>
<fpml:productId
productIdScheme
={
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"productId"
).
head
},
"productIdScheme"
)
}>{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"productId"
).
head
})
}</
fpml
:
productId>
{
val
iv
=
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
fixedRateSchedule
"
\
"
initialValue
"
)
.head
})
if
(
iv.mkString
!=
msgNotFound
)
{
if
(
productType
==
Equity
)
<
fpmlext
:
fixedRateSchedule>
<fpml:initialValue>
{
iv
}
</fpml:initialValue>
<fpml:initialValue>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
fixedRateSchedule
"
\
"
initialValue
"
)
.head
})
}
</fpml:initialValue>
<step>
<stepDate>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
fixedRateSchedule
"
\\
"
stepDate
"
)
.head
})
}
</stepDate>
<stepValue>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
fixedRateSchedule
"
\\
"
stepValue
"
)
.head
})
}
</stepValue>
</step>
</fpmlext:fixedRateSchedule>
else
/* Add different type to template */
else
if
(
productType
==
Bond
)
<
fpmlext
:
floatingRateCalculation>
<fpml:floatingRateIndex>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
floatingRateCalculation
"
\
"
floatingRateIndex
"
)
.head
})
}
</fpml:floatingRateIndex>
<indexTenor>
<periodMultiplier>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
floatingRateCalculation
"
\\
"
periodMultiplier
"
)
.head
})
}
</periodMultiplier>
<period>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
floatingRateCalculation
"
\\
"
period
"
)
.head
})
}
</period>
</indexTenor>
<spreadSchedule>
<initialValue>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
floatingRateCalculation
"
\\
"
initialValue
"
)
.head
})
}
</initialValue>
</spreadSchedule>
<initialRate>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
floatingRateCalculation
"
\\
"
initialRate
"
)
.head
})
}
</initialRate>
</fpmlext:floatingRateCalculation>
/*---------------------------------*/
}
<
fpmlext
:
dayCountFraction>
{
get
(
Try
{
(
source
\
"
trade
"
\
"
repo
"
\
"
dayCountFraction
"
)
.head
})
}
</fpmlext:dayCountFraction>
<fpmlext:spotLeg
xsi:
type
=
"rtsrep:RepoTransactionLeg"
>
...
...
@@ -173,10 +186,15 @@ final class RepoTemplate(source: Node) extends TradeTemplate(source) {
</fpml:adjustableDate>
</rtsrep:deliveryDate>
</fpmlext:forwardLeg>
{
/*Its
necessary
to
add
instrument
choice
*/
}
<fpml:equity
id
={
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"equity"
).
head
},
"id"
)
}>
<
fpml
:
instrumentId
instrumentIdScheme
=
""
>{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"equity"
\
"instrumentId"
).
head
})
}</
fpml
:
instrumentId>
</fpml:equity>
{
if
(
productType
==
Equity
)
<
fpml
:
equity
id
={
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"equity"
).
head
},
"id"
)
}>
<
fpml
:
instrumentId
instrumentIdScheme
=
""
>{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"equity"
\
"instrumentId"
).
head
})
}</
fpml
:
instrumentId>
</fpml:equity>
else
if
(
productType
==
Bond
)
<
fpml
:
bond
id
={
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"bond"
).
head
},
"id"
)
}>
<
fpml
:
instrumentId
instrumentIdScheme
=
""
>{
get
(
Try
{
(
source
\
"trade"
\
"repo"
\
"bond"
\
"instrumentId"
).
head
})
}</
fpml
:
instrumentId>
</fpml:bond>
}
</
fpmlext
:
repo>
<fpml:documentation>
<fpml:masterAgreement>
...
...
src/main/scala/templates/Template.scala
View file @
82523709
...
...
@@ -3,7 +3,7 @@ package templates
import
scala.collection.mutable
import
scala.util.
{
Success
,
Try
}
import
scala.xml.transform.
{
RewriteRule
,
RuleTransformer
}
import
scala.xml.
{
Node
,
NodeSeq
,
Text
}
import
scala.xml.
_
abstract
class
Template
(
protected
[
this
]
val
source
:
Node
)
{
protected
[
this
]
val
msgNotFound
=
"Not found"
...
...
@@ -79,3 +79,21 @@ abstract class Template(protected[this] val source: Node) {
def
log
()
:
Unit
=
data
.
foreach
(
e
=>
println
(
e
.
_2
))
}
object
Template
{
sealed
trait
ProductType
case
object
Equity
extends
ProductType
case
object
Bond
extends
ProductType
def
apply
(
source
:
Node
)
:
Template
=
(
source
\
"trade"
).
head
.
child
.
filter
{
case
v
:
Elem
=>
true
case
_
=>
false
}(
1
).
label
match
{
case
"repo"
=>
new
RepoTemplate
(
source
)
case
v
=>
throw
new
Exception
(
"Undefined trade type"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment