"undefined"==typeof BinaryExposureHandler&&(BinaryExposureHandler={}); (function(){function k(){MarketExposureObj.eventId=null;MarketExposureObj.marketId=null;MarketExposureObj.marketExposure=0;MarketExposureObj.betPricePls={};MarketExposureObj.betPriceExposures={};PriceProfitLossObj.price=null;PriceProfitLossObj.sideType=null;PriceProfitLossObj.equalGreaterThanPriceTotalPl=0;PriceProfitLossObj.lessThanPriceTotalPl=0}function l(g,h,a){var c=0,b=MarketExposureObj.betPriceExposures[a];null==b?(b=h,$j.each(MarketExposureObj.betPricePls,function(d,e){d=e.price;a!=d&&(b= a>d?MathUtil.decimal.add(b,e.equalGreaterThanPriceTotalPl):MathUtil.decimal.add(b,e.lessThanPriceTotalPl))})):b=MathUtil.decimal.add(b,h);MarketExposureObj.betPriceExposures[a]=b;c=c>b?b:c;$j.each(MarketExposureObj.betPriceExposures,function(d,e){a!=d&&(e=ae?e:c)});return c}MarketExposureObj={eventId:null,marketId:null,marketExposure:0,betPricePls:{},betPriceExposures:{}};PriceProfitLossObj={price:null, sideType:null,equalGreaterThanPriceTotalPl:0,lessThanPriceTotalPl:0};BinaryExposureHandler.getMarketExposure=function(){return JSON.parse(JSON.stringify(MarketExposureObj))};BinaryExposureHandler.setMarketExposure=function(g){k();MarketExposureObj=JSON.parse(JSON.stringify(g))};BinaryExposureHandler.initMarketInfo=function(g,h){k();MarketExposureObj.eventId=g;MarketExposureObj.marketId=h;MarketExposureObj.betPriceExposures[0]=0};BinaryExposureHandler.generateBetTicketObj=function(g,h,a,c,b,d){var e= MathUtil.decimal.multiply(1==d?-1:1,b);c=MathUtil.decimal.multiply(1==d?1:-1,MathUtil.decimal.multiply(MathUtil.decimal.divide(c,100),b));return{eventId:g,marketId:h,sideType:d,priceId:(1==d?1:-1)*a,price:a,lessThanPricePl:e,equalGreaterThanPricePl:c}};BinaryExposureHandler.calculateExposure=function(g){if(!$j.isArray(g))throw"betTickets must bet array type.[betTicketObj....]";$j.each(g,function(h,a){h=MarketExposureObj;var c=a.priceId;var b=a.lessThanPricePl,d=a.equalGreaterThanPricePl,e=a.price; a=a.sideType;var f=MarketExposureObj.betPricePls[c];$j.isEmptyObject(f)?(f=JSON.parse(JSON.stringify(PriceProfitLossObj)),f.price=e,f.sideType=a,f.lessThanPriceTotalPl=b,f.equalGreaterThanPriceTotalPl=d,MarketExposureObj.betPricePls[c]=f):(f.lessThanPriceTotalPl=MathUtil.decimal.add(f.lessThanPriceTotalPl,b),f.equalGreaterThanPriceTotalPl=MathUtil.decimal.add(f.equalGreaterThanPriceTotalPl,d));c=l(b,d,e);h.marketExposure=c})}})();