Rate Card

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

Ext.define('fmconnect.fxcash.component.

RateCard', {
extend:'Ext.panel.Panel',
alias: 'widget.rateCard',
width:350,
height:110,
layout : 'hbox',
defaults:{
margin:1
},
getRateParts:function(rate,pointsDigit){
var rateObj = new Object();
var rateStr = padWithZeros(rate, 10);
var decLoc = decimalLocation(rate);
var beforeDecimal=rateStr.substring(0,decLoc+1);
rateObj.rate = beforeDecimal + rateStr.substr(decLoc+1,pointsDig
it-2);
//rateObj.rate = rateStr.substring(0,3); //decimal point include
d
var bigfigureloc= decLoc+1+pointsDigit-2;
rateObj.bigfigure = rateStr.substr(bigfigureloc,2);
rateObj.smallfigure = rateStr.substr(bigfigureloc+2,1);
//rateObj.smallfigure = 0;
return rateObj;
},
clearDisplay : function(){
this.getBidCard().setText(null);
this.getAskCard().setText(null);
this.getBidCard().setIcon(null);
this.getAskCard().setIcon(null);
},
setTickDirection:function(card, direction){
switch(direction){
case 0 :
card.setIcon (null); break;
case 1 :
card.setIcon('images/arrow_green.png');
break;
case -1 :

card.setIcon('images/arrow_red.png'); br

default :

card.setIcon (null); break;

eak;
}
},
setRfqText : function(card){
card.setText('<font style="font-color:white;font-size:50px;fontweight:bold;vertical-align:middle">RFQ</font>');
},
round: function(rate, pointsDigit){
var tens = Math.pow(10,pointsDigit+1);
return Math.round(rate*tens)/tens;
},
updateForwardRate : function(fxRateFeedAppObj){
this.fxRateFeedAppObj = fxRateFeedAppObj;

//var htmlStringFwd = '<span><table align="center"><tr><td align


="center"> <font style="font-size:15px;font-weight:normal;vertical-align:top">SE
LL USD</font> </td></tr></table><table align="center"><tr><td align="center" ><f
ont style="font-size:12px;color:yellow;font-weight:normal;">SP: {SPOT_REF}</td><
td align="center"><font style="font-size:12px;color:#33FF66;font-weight:normal;"
> SW: {SWAP_POINTS}</font></td></tr></table><table align="center" style="margintop:-10px"><tr><td align="center"><font style="font-size:20px;font-weight:normal
;vertical-align:bottom">{RATE} </font><font style="font-size:50px;font-weight:bo
ld;vertical-align:top">{BIGFIGURE}&nbsp;</font><font style="font-size:20px;fontweight:normal;vertical-align:bottom">{SMALLFIGURE}</font></td></tr></span>';
var htmlStringFwd = '<span><table align="center"><tr><td align="
center"> <font style="font-size:15px;font-weight:normal;vertical-align:top">{DIR
ECTION} {CCY1}</font> </td></tr><tr></tr><tr><td align="center"><font style="fon
t-size:20px;font-weight:normal;vertical-align:bottom">{RATE} </font><font style=
"font-size:50px;font-weight:bold;vertical-align:top">{BIGFIGURE}&nbsp;</font><fo
nt style="font-size:20px;font-weight:normal;vertical-align:bottom">{SMALLFIGURE}
</font></td></tr></span>';
htmlStringFwd = htmlStringFwd.replace("{CCY1}",this.fxRateFeedAp
pObj.ccy1);
var titleccy=fxRateFeedAppObj.ccyPair;
var titlebidRate=fxRateFeedAppObj.bidRate+"/";
var titleaskRate=fxRateFeedAppObj.askRate;
if(fxRateFeedAppObj.bidTradingMode=="RFQ"){
this.setRfqText(this.getBidCard());
titlebidRate="";
}else {
var bidRateParts = this.getRateParts(fxRateFeedAppObj.bi
dRate,fxRateFeedAppObj.pointsDigit);
var bidHtml = htmlStringFwd.
replace("{DIRECTION}", "
SELL").
replace("{RATE}", bidRat
eParts.rate).
replace("{BIGFIGURE}", b
idRateParts.bigfigure).
replace("{SMALLFIGURE}",
bidRateParts.smallfigure).
replace("{SPOT_REF}", th
is.round(fxRateFeedAppObj.bidSpotRef,fxRateFeedAppObj.pointsDigit)).
replace("{SWAP_POINTS}",
this.round(fxRateFeedAppObj.bidPoints, fxRateFeedAppObj.pointsDigit));
this.setTickDirection(this.getBidCard(), fxRateFeedAppOb
j.bidTickDirection);
this.getBidCard().setText(bidHtml);
};
if(fxRateFeedAppObj.askTradingMode=="RFQ"){
this.setRfqText(this.getAskCard());
titleaskRate="";
}else{
var askRateParts = this.getRateParts(fxRateFeedAppObj.as
kRate,fxRateFeedAppObj.pointsDigit);
var askHtml = htmlStringFwd.
replace("{DIRECTION}", "
BUY").
replace("{RATE}", askRat
eParts.rate).
replace("{BIGFIGURE}", a
skRateParts.bigfigure).
replace("{SMALLFIGURE}",

askRateParts.smallfigure).
replace("{SPOT_REF}", th
is.round(fxRateFeedAppObj.askSpotRef,fxRateFeedAppObj.pointsDigit)).
replace("{SWAP_POINTS}",
this.round(fxRateFeedAppObj.askPoints,fxRateFeedAppObj.pointsDigit));
this.setTickDirection(this.getAskCard(), fxRateFeedAppOb
j.askTickDirection);
this.getAskCard().setText(askHtml);
if(this.up('streamingCard').collapsed){
var title=titleccy+" "+titlebidRate+titleaskRate
;
this.up('streamingCard').setTitle(title);
}
};
},
updateSpotRate : function (fxRateFeedAppObj){
this.fxRateFeedAppObj = fxRateFeedAppObj;
var htmlStringSpot = '<span><table align="center"><tr><td align=
"center"> <font style="font-size:15px;font-weight:normal;vertical-align:top">{DI
RECTION} {CCY1}</font> </td></tr><tr></tr><tr><td align="center"><font style="fo
nt-size:20px;font-weight:normal;vertical-align:bottom">{RATE} </font><font style
="font-size:50px;font-weight:bold;vertical-align:top">{BIGFIGURE}&nbsp;</font><f
ont style="font-size:20px;font-weight:normal;vertical-align:bottom">{SMALLFIGURE
}</font></td></tr></span>';
var titleccy=fxRateFeedAppObj.ccyPair;
var titlebidRate=fxRateFeedAppObj.bidRate+"/";
var titleaskRate=fxRateFeedAppObj.askRate;
htmlStringSpot = htmlStringSpot.replace("{CCY1}",this.fxRateFeed
AppObj.ccy1);
if(fxRateFeedAppObj.bidTradingMode=="RFQ"){
this.setRfqText(this.getBidCard());
titlebidRate="";
}else{
var bidRateParts = this.getRateParts(fxRateFeedAppObj.bi
dRate,fxRateFeedAppObj.pointsDigit);
var bidHtml = htmlStringSpot.replace("{DIRECTION}", "SEL
L").replace("{RATE}", bidRateParts.rate).replace("{BIGFIGURE}", bidRateParts.big
figure).replace("{SMALLFIGURE}", bidRateParts.smallfigure);
this.setTickDirection(this.getBidCard(), fxRateFeedAppOb
j.bidTickDirection);
this.getBidCard().setText(bidHtml);
};
if(fxRateFeedAppObj.askTradingMode=="RFQ"){
this.setRfqText(this.getAskCard());
titleaskRate="";
}else{
var askRateParts = this.getRateParts(fxRateFeedAppObj.as
kRate,fxRateFeedAppObj.pointsDigit);
var askHtml = htmlStringSpot.replace("{DIRECTION}", "BUY
").replace("{RATE}", askRateParts.rate).replace("{BIGFIGURE}", askRateParts.bigf
igure).replace("{SMALLFIGURE}", askRateParts.smallfigure);
this.setTickDirection(this.getAskCard(), fxRateFeedAppOb
j.askTickDirection);
this.getAskCard().setText(askHtml);
};
if(this.up('streamingCard').collapsed){
var title=titleccy+" "+titlebidRate+titleaskRate;

this.up('streamingCard').setTitle(title);
}
},
updateSwapRate: function (fxRateFeedAppObj){
console.log("widget yet to be made");
},
setCcyPair : function(ccyPair){
this.ccyPair= ccyPair;
},

disableTrading: false,
sendBidRfq :function(){
if(this.disableTrading){
Ext.Msg.alert("Trade booking feature has been disabled f
or this release");
return;
}
else if(this.up('streamingCard')){
if(this.up('streamingCard').down('coretogglebutton').get
Value()==="Y"){
console.log("Send Bid Rfq");
var rfqObject = this.populateRfqObjectBid();
var win = Ext.widget('customerRfqRequesterPanel'
,{
rfqObject: rfqObject
});
win.show();
}
else{
Ext.Msg.alert('Error', 'You have disabled tradin
g for this Currency Pair');
}
}
},
sendAskRfq: function(){
if(this.disableTrading){
Ext.Msg.alert("Trade booking feature has been disabled f
or this release");
return;
}
else if(this.up('streamingCard')){
if(this.up('streamingCard').down('coretogglebutton').get
Value()==="Y"){
console.log("Send Ask Rfq");
var rfqObject = this.populateRfqObjectAsk();
var win = Ext.widget('customerRfqRequesterPanel'
,{
rfqObject: rfqObject
});
win.show();

}
else{
Ext.Msg.alert('Error', 'You have disabled tradin
g for this Currency Pair');
}
}
},
getBidCard: function(){
return this.down("[fmId='bidRateCard']");
},
getAskCard: function(){
return this.down("[fmId='askRateCard']");
},
items:[{
xtype : 'panel',
layout : 'vbox',
flex:1,
height:'100%',
defaults:{
margin:3
},
bodyCls: 'sell-siderate',
items:[{
xtype:'button',
fmId:'bidRateCard',
iconAlign : 'left',
flex : 3,
width: '100%',
listeners:{
click:function(){
var streamingCard = this.up('streamingC
ard');
streamingCard.fireEvent("bidClick", stre
amingCard);
}
}
}]
},{
xtype : 'panel',
layout : 'vbox',
flex:1,
height:'100%',
defaults:{
margin:3
},
bodyCls: 'buy-siderate',
items:[{
xtype:'button',
fmId:'askRateCard',
flex : 3,
width: '100%',
iconAlign : 'right',
listeners:{
click:function(){

var streamingCard = this.up('streamingC


ard');
streamingCard.fireEvent("askClick", stre
amingCard);
}
}
}]
}],
});
//for rates
function padWithZeros(number,n){
var strn = number.toString();
for(i=strn.length;i<n;i++){
strn=strn+"0";
}
return strn;
}
//for rates
function decimalLocation(number){
var strn = number.toString();
var i=0
for( i=0;i<strn.length;i++){
if(strn[i]==".") break;
}
return i;
}

You might also like